Skip to content

Commit

Permalink
fill out edit induction status page, move managed by CPD logic to person
Browse files Browse the repository at this point in the history
  • Loading branch information
CathLass committed Dec 17, 2024
1 parent c3e30cc commit 5d58704
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ public static bool ValidateInductionData(
return true;
}

public bool InductionStatusManagedByCpd(DateOnly? now)
{
var sevenYearsAgo = now?.AddYears(-7);
return InductionCompletedDate is not null
&& InductionCompletedDate < sevenYearsAgo;
}

private static void AssertInductionChangeIsValid(
InductionStatus status,
DateOnly? startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class EditInductionState : IRegisterJourney
requestDataKeys: ["personId"],
appendUniqueKey: true);

public string? PersonName { get; set; }
public InductionStatus InductionStatus { get; set; }
public DateOnly? StartDate { get; set; }
public DateOnly? CompletedDate { get; set; }
Expand All @@ -28,6 +29,7 @@ public async Task EnsureInitializedAsync(TrsDbContext dbContext, Guid personId,
var person = await dbContext.Persons
.SingleAsync(q => q.PersonId == personId);
InductionStatus = person!.InductionStatus;
PersonName = person.LastName;
if (JourneyStartPage == null)
{
JourneyStartPage = startPage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page "/persons/{PersonId}/edit-induction/status"
@model TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInduction.StatusModel
@{
ViewBag.Title = "Edit status: " + Model.InductionStatus.GetName();
ViewBag.Title = "What is their induction status?";
}

@section BeforeContent {
Expand All @@ -12,7 +12,17 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<span class="govuk-caption-l">Induction - @Model.PersonName</span>
<form data-testid="submit-form" action="@LinkGenerator.InductionEditStatus(Model.PersonId, Model.JourneyInstance!.InstanceId)" method="post">
<govuk-radios asp-for="InductionStatus">
<govuk-radios-fieldset>
<govuk-radios-fieldset-legend class="govuk-fieldset__legend--m" />
@foreach (var inductionStatus in InductionStatusRegistry.All)
{
<govuk-radios-item value="@inductionStatus">@inductionStatus.Name</govuk-radios-item>
}
</govuk-radios-fieldset>
</govuk-radios>
<input type="hidden" name="InductionStatus" value="@Model.InductionStatus" />
<div class="govuk-button-group">
<govuk-button type="submit" data-testid="continue-button">Continue</govuk-button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using TeachingRecordSystem.Core.DataStore.Postgres;
Expand All @@ -10,7 +11,10 @@ public class StatusModel : CommonJourneyPage
protected TrsDbContext _dbContext;

[BindProperty]
[Display(Name = "Select a status")]
[Required(ErrorMessage = "Select a status")]
public InductionStatus InductionStatus { get; set; }
public string? PersonName { get; set; }

public InductionJourneyPage NextPage
{
Expand All @@ -34,6 +38,7 @@ public StatusModel(TrsLinkGenerator linkGenerator, TrsDbContext dbContext) : bas
public void OnGet()
{
InductionStatus = JourneyInstance!.State.InductionStatus;
PersonName = JourneyInstance!.State.PersonName;
}

public async Task<IActionResult> OnPostAsync()
Expand All @@ -53,6 +58,10 @@ public async Task<IActionResult> OnPostAsync()
public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
await JourneyInstance!.State.EnsureInitializedAsync(_dbContext, PersonId, InductionJourneyPage.Status);
var personInfo = context.HttpContext.GetCurrentPersonFeature();

PersonId = personInfo.PersonId;
PersonName = personInfo.Name;

await next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,12 @@ public async Task OnGetAsync()
StartDate = person!.InductionStartDate;
CompletionDate = person!.InductionCompletedDate;
ExemptionReasons = person!.InductionExemptionReasons;
_statusIsManagedByCpd = StatusManagedByCpdRule(person!.CpdInductionStatus, person.CpdInductionCompletedDate);
_statusIsManagedByCpd = person.InductionStatusManagedByCpd(clock.Today);
_teacherHoldsQualifiedTeacherStatus = TeacherHoldsQualifiedTeacherStatusRule(result?.Contact.dfeta_QTSDate);
}

private bool TeacherHoldsQualifiedTeacherStatusRule(DateTime? qtsDate)
{
return qtsDate is null;
}

private bool StatusManagedByCpdRule(InductionStatus? status, DateOnly? inductionCompletedDate)
{
var sevenYearsAgo = clock.Today.AddYears(-7);
return status is not null
&& inductionCompletedDate is not null
&& inductionCompletedDate < sevenYearsAgo;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using TeachingRecordSystem.Core.DataStore.Postgres.Models;
using TeachingRecordSystem.Core.Dqt;

namespace TeachingRecordSystem.Core.Tests.DataStore.Postgres.Models;

Expand Down Expand Up @@ -228,4 +229,33 @@ public void TrySetWelshInductionStatus_StatusIsAtLowerPriorityStatus_UpdatesStat
Assert.Equal(expectedStatus, person.InductionStatus);
Assert.Equal(expectedExemptionReasons, person.InductionExemptionReasons);
}

[Theory]
[InlineData(-3, false)]
[InlineData(-7, true)]
public void InductionManagedByCpd_ReturnsTrue(int yearsSinceCompleted, bool expected)
{
// CML TODO figure out the date-time types
// Arrange
var dateTimeCompleted = Clock.UtcNow.AddYears(yearsSinceCompleted).AddDays(-1);
var dateCompleted = dateTimeCompleted.ToDateOnlyWithDqtBstFix(true);
var person = new Person
{
PersonId = Guid.NewGuid(),
CreatedOn = dateTimeCompleted,
UpdatedOn = dateTimeCompleted,
Trn = "1234567",
FirstName = "Joe",
MiddleName = "",
LastName = "Bloggs",
DateOfBirth = new(1990, 1, 1),
};
person.SetInductionStatus(InductionStatus.Passed, dateCompleted, dateCompleted, InductionExemptionReasons.None, SystemUser.SystemUserId, Clock.UtcNow, out _);

// Act
var result = person.InductionStatusManagedByCpd(Clock.UtcNow.ToDateOnlyWithDqtBstFix(true));

// Assert
Assert.Equal(expected,result);
}
}

0 comments on commit 5d58704

Please sign in to comment.