Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a case when multiple location changes doesn't result in the right due dates #803

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,8 @@ DateOnly today
.Where(missingDueDate =>
!fva.ExemptedRequirements.Any(exempted =>
exempted.RequirementName == monitoringRequirement.ActionName
&& (
!exempted.DueDate.HasValue
|| exempted.DueDate == missingDueDate
)
&& (
exempted.ExemptionExpiresAt == null
|| exempted.ExemptionExpiresAt > today
)
&& (!exempted.DueDate.HasValue || exempted.DueDate == missingDueDate)
&& (exempted.ExemptionExpiresAt == null || exempted.ExemptionExpiresAt > today)
)
)
.Select(missingDueDate => new MissingArrangementRequirement(
Expand Down Expand Up @@ -366,10 +360,7 @@ DateOnly today
!iva.ExemptedRequirements.Any(exempted =>
exempted.RequirementName == monitoringRequirement.ActionName
&& (!exempted.DueDate.HasValue || exempted.DueDate == missingDueDate)
&& (
exempted.ExemptionExpiresAt == null
|| exempted.ExemptionExpiresAt > today
)
&& (exempted.ExemptionExpiresAt == null || exempted.ExemptionExpiresAt > today)
)
)
.Select(missingDueDate => new MissingArrangementRequirement(
Expand Down Expand Up @@ -528,29 +519,38 @@ ImmutableList<DateOnly> completionDates

private static IEnumerable<DateRange<Guid>> GenerateDateRanges(ImmutableList<ChildLocation> childLocations)
{
DateOnly? startDate = null;
Guid? tag = null;
(DateOnly, Guid)? entry = null;
LarsKemmann marked this conversation as resolved.
Show resolved Hide resolved

foreach (var childLocation in childLocations)
{
if (!startDate.HasValue && !childLocation.Paused)
if (!entry.HasValue && !childLocation.Paused)
{
entry = (childLocation.Date, childLocation.ChildLocationFamilyId);
continue;
}

if (entry.HasValue && !childLocation.Paused)
{
startDate = childLocation.Date;
tag = childLocation.ChildLocationFamilyId;
yield return new DateRange<Guid>(
entry.Value.Item1,
childLocation.Date.AddDays(-1),
LarsKemmann marked this conversation as resolved.
Show resolved Hide resolved
entry.Value.Item2
);
entry = (childLocation.Date, childLocation.ChildLocationFamilyId);
continue;
}

if (startDate.HasValue && tag.HasValue && childLocation.Paused)
if (entry.HasValue && childLocation.Paused)
{
yield return new DateRange<Guid>(startDate.Value, childLocation.Date, tag.Value);
startDate = null;
yield return new DateRange<Guid>(entry.Value.Item1, childLocation.Date, entry.Value.Item2);
entry = null;
continue;
}
}

if (startDate.HasValue && tag.HasValue)
if (entry.HasValue)
{
yield return new DateRange<Guid>(startDate.Value, tag.Value);
yield return new DateRange<Guid>(entry.Value.Item1, entry.Value.Item2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,102 +16,142 @@ public void CreateTimelineWithOneGap()
{
var result = ReferralCalculations.CreateChildLocationBasedTimeline(
H.ChildLocationHistory(
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25)
).ToImmutableList()
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25)
)
.ToImmutableList()
);

AssertEx.SequenceIs(result, new DateOnlyTimeline([
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 20)),
DateOnly.FromDateTime(H.DateTime(1, 25))
AssertEx.SequenceIs(
result,
new DateOnlyTimeline(
[
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 20)),
DateOnly.FromDateTime(H.DateTime(1, 25))
),
]
)
]));
);
}

[TestMethod]
public void CreateTimelineWithTwoGaps()
{
var result = ReferralCalculations.CreateChildLocationBasedTimeline(
H.ChildLocationHistory(
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25),
(H.Id('2'), ChildLocationPlan.DaytimeChildCare, 1, 30),
(Guid.Empty, ChildLocationPlan.WithParent, 2, 5)
).ToImmutableList()
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25),
(H.Id('2'), ChildLocationPlan.DaytimeChildCare, 1, 30),
(Guid.Empty, ChildLocationPlan.WithParent, 2, 5)
)
.ToImmutableList()
);

AssertEx.SequenceIs(result, new DateOnlyTimeline([
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 20)),
DateOnly.FromDateTime(H.DateTime(1, 25))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 30)),
DateOnly.FromDateTime(H.DateTime(2, 5))
AssertEx.SequenceIs(
result,
new DateOnlyTimeline(
[
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 20)),
DateOnly.FromDateTime(H.DateTime(1, 25))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 30)),
DateOnly.FromDateTime(H.DateTime(2, 5))
),
]
)
]));
);
}

[TestMethod]
public void CreateTimelineWithTwoGapsFilteredByFamilyId()
{
var result = ReferralCalculations.CreateChildLocationBasedTimeline(
H.ChildLocationHistory(
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25),
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 30),
(Guid.Empty, ChildLocationPlan.WithParent, 2, 5)
).ToImmutableList(),
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 25),
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 30),
(Guid.Empty, ChildLocationPlan.WithParent, 2, 5)
)
.ToImmutableList(),
filterToFamilyId: H.Id('0')
);

AssertEx.SequenceIs(result, new DateOnlyTimeline([
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 30)),
DateOnly.FromDateTime(H.DateTime(2, 5))
AssertEx.SequenceIs(
result,
new DateOnlyTimeline(
[
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 30)),
DateOnly.FromDateTime(H.DateTime(2, 5))
),
]
)
]));
);
}

[TestMethod]
public void CreateTimelineChildWithParentAtEnd()
{
var result = ReferralCalculations.CreateChildLocationBasedTimeline(
H.ChildLocationHistory(
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 20)
).ToImmutableList()
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(Guid.Empty, ChildLocationPlan.WithParent, 1, 12),
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 20)
)
.ToImmutableList()
);

AssertEx.SequenceIs(result, new DateOnlyTimeline([
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 20))
AssertEx.SequenceIs(
result,
new DateOnlyTimeline(
[
new DateRange(
DateOnly.FromDateTime(H.DateTime(1, 1)),
DateOnly.FromDateTime(H.DateTime(1, 12))
),
new DateRange(DateOnly.FromDateTime(H.DateTime(1, 20))),
]
)
]));
);
}

[TestMethod]
public void CreateTimelineFilteredByFamilyIdNoPauses()
PabloDinella marked this conversation as resolved.
Show resolved Hide resolved
{
var result = ReferralCalculations.CreateChildLocationBasedTimeline(
H.ChildLocationHistory(
(H.Id('0'), ChildLocationPlan.DaytimeChildCare, 1, 1),
(H.Id('1'), ChildLocationPlan.DaytimeChildCare, 1, 20)
)
.ToImmutableList(),
H.Id('1')
);

AssertEx.SequenceIs(
result,
new DateOnlyTimeline([new DateRange(DateOnly.FromDateTime(H.DateTime(1, 20)))])
);
}
}
}
}
Loading