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

Cfodev 748 #299

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 19 additions & 4 deletions src/Application/Features/QualityAssurance/Commands/ArchiveCase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cfo.Cats.Application.Common.Security;
using Cfo.Cats.Application.Common.Validators;
using Cfo.Cats.Application.SecurityConstants;

namespace Cfo.Cats.Application.Features.QualityAssurance.Commands;
Expand All @@ -9,21 +10,24 @@ public static class ArchiveCase
public class Command : IRequest<Result>
{
public required string ParticipantId { get; set; }

[Description("Reason for Archive")] public ArchiveReason ArchiveReason { get; set; } = ArchiveReason.CaseloadTooHigh;
[Description("Justification for Archive")] public string? Justification { get; set; }
}

public class Handler(IUnitOfWork unitOfWork) : IRequestHandler<Command, Result>
{
public async Task<Result> Handle(Command request, CancellationToken cancellationToken)
{
var participant = await unitOfWork.DbContext.Participants.FindAsync(request.ParticipantId);
participant!.Archive(request.ArchiveReason,request.Justification);
participant!.TransitionTo(EnrolmentStatus.ArchivedStatus);

// ReSharper disable once MethodHasAsyncOverload
return Result.Success();
}
}

public class A_ParticipantMustExistValidator : AbstractValidator<SubmitToProviderQa.Command>
public class A_ParticipantMustExistValidator : AbstractValidator<SubmitToProviderQa.Command>
{
private readonly IUnitOfWork _unitOfWork;
public A_ParticipantMustExistValidator(IUnitOfWork unitOfWork)
Expand All @@ -41,6 +45,17 @@ public A_ParticipantMustExistValidator(IUnitOfWork unitOfWork)
private async Task<bool> MustExist(string identifier, CancellationToken cancellationToken)
=> await _unitOfWork.DbContext.Participants.AnyAsync(e => e.Id == identifier, cancellationToken);
}



public class Validator : AbstractValidator<Command>
{
public Validator()
{
RuleFor(c => c.Justification)
.NotEmpty()
.When(c => c.ArchiveReason.RequiresJustification)
.WithMessage("You must provide a justification for the selected Archive reason")
.Matches(ValidationConstants.Notes)
.WithMessage(string.Format(ValidationConstants.NotesMessage, "Justification"));
}
}
}
26 changes: 26 additions & 0 deletions src/Domain/Common/Enums/ArchiveReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Ardalis.SmartEnum;

namespace Cfo.Cats.Domain.Common.Enums;

public sealed class ArchiveReason : SmartEnum<ArchiveReason>
{
public static readonly ArchiveReason CaseloadTooHigh = new("Caseload for this location is too high", 0, false);
public static readonly ArchiveReason Deceased = new("Deceased", 1, false);
public static readonly ArchiveReason LicenceEnd = new("Licence end date reached", 2, false);
public static readonly ArchiveReason MovedOutsideProviderArea = new("Moved outside of provider delivery catchment area", 3, false);
public static readonly ArchiveReason MovedToNonCFO = new("Moved to non-CFO location", 4, false);
public static readonly ArchiveReason NoFurtherSupport = new("No further support required", 5, false);
public static readonly ArchiveReason NoRightToLiveWork = new("No supporting right to live / work documentation", 6, false);
public static readonly ArchiveReason NoWishToParticipate = new("Participant has stated they do not wish to participate", 7, false);
public static readonly ArchiveReason NoLongerEngaging = new("Participant is no longer engaging with provision", 8, false);
public static readonly ArchiveReason PersonalCircumstances = new("Personal circumstances", 9, false);
public static readonly ArchiveReason Other = new("Other", 10, true);

public bool RequiresJustification { get; }

private ArchiveReason(string name, int value, bool requiresJustification)
: base(name, value)
{
RequiresJustification = requiresJustification;
}
}
21 changes: 21 additions & 0 deletions src/Domain/Entities/Participants/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public static Participant CreateFrom(
/// </summary>
public string? EnrolmentLocationJustification { get; private set; }

/// <summary>
/// The justifcation for Archiving participant
/// </summary>
public string? ArchiveJustification { get; private set; }

public ArchiveReason? ArchiveReason{ get; private set; }

public string? AssessmentJustification { get; private set; }

public string? RegistrationDetailsJson { get; private set; }
Expand Down Expand Up @@ -319,4 +326,18 @@ public Participant SetRiskDue(DateTime riskDueDate)
RiskDue = riskDueDate;
return this;
}

/// <summary>
/// Archives the participant
/// </summary>
/// <param name="archiveReason"></param>
/// <param name="justificationReason"></param>
/// <returns></returns>
public Participant Archive(ArchiveReason archiveReason, string? justificationReason)
{
ArchiveJustification = justificationReason;
ArchiveReason = archiveReason;

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public void Configure(EntityTypeBuilder<Participant> builder)
cs => cs!.Value,
cs => ConsentStatus.FromValue(cs));

builder.Property(e => e.ArchiveReason)
.HasConversion(
ar => ar!.Value,
ar => ArchiveReason.FromValue(ar));

builder.Property(p => p.ArchiveJustification)
.HasMaxLength(ValidationConstants.NotesLength);

builder.HasOne(e => e.CurrentLocation)
.WithMany()
.HasForeignKey("_currentLocationId")
Expand Down
Loading
Loading