Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { RouteUtils } from '@lib/utils/route-utils.class';
import { AdjudicationRoutes } from '@adjudication/adjudication.routes';

@Component({
selector: 'app-enrollee-access-term-enrolment',
templateUrl: './enrollee-access-term-enrolment.component.html',
styleUrls: ['./enrollee-access-term-enrolment.component.scss'],
standalone: false
selector: 'app-enrollee-access-term-enrolment',
templateUrl: './enrollee-access-term-enrolment.component.html',
styleUrls: ['./enrollee-access-term-enrolment.component.scss'],
standalone: false
})
export class EnrolleeAccessTermEnrolmentComponent extends AbstractComponent implements OnInit {
public busy: Subscription;
Expand All @@ -39,8 +39,8 @@ export class EnrolleeAccessTermEnrolmentComponent extends AbstractComponent impl

public ngOnInit() {
const enrolleeId = this.route.snapshot.params.id;
const accessTermId = this.route.snapshot.params.aid;
this.busy = this.adjudicationResource.getSubmissionForAgreement(enrolleeId, accessTermId)
const submissionId = this.route.snapshot.params.aid;
this.busy = this.adjudicationResource.getSubmissionForAgreement(enrolleeId, submissionId)
.subscribe((enrolmentSubmission: HttpEnrolleeSubmission) =>
this.enrolmentSubmission = this.enrolleeSubmissionAdapterResponse(enrolmentSubmission)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
isCurrent: enrolmentCard.isCurrent && !isUnderAdjudication(enrollee),
submittedDate: enrolmentCard.submissionCreatedDate,
acceptedDate: enrolmentCard.agreementAcceptedDate,
approvedDate: enrolmentCard.enrolmentApprovedDate,
agreementType: enrolmentCard.agreementType,
remoteAccess: enrolmentCard.requestedRemoteAccess,
enrolmentRoute: [enrolmentCard.agreementId, AdjudicationRoutes.ENROLLEE_ACCESS_TERM_ENROLMENT],
enrolmentRoute: [enrolmentCard.submissionId, AdjudicationRoutes.ENROLLEE_ACCESS_TERM_ENROLMENT],
toaRoute: [enrolmentCard.agreementId, AdjudicationRoutes.ENROLLEE_ACCESS_TERM],
isLast: last
}">
Expand All @@ -49,6 +51,8 @@
let-isCurrent="isCurrent"
let-submittedDate="submittedDate"
let-acceptedDate="acceptedDate"
let-approvedDate="approvedDate"
let-agreementType="agreementType"
let-remoteAccess="remoteAccess"
let-enrolmentRoute="enrolmentRoute"
let-toaRoute="toaRoute"
Expand All @@ -61,19 +65,25 @@
to mat-card-title not allowing the use of flexbox
-->
<div class="card-title">
<small>Submitted {{ submittedDate | formatDate: 'MMMM Do YYYY' }}</small>
<small>Enrolment submitted on {{ submittedDate | formatDate: 'MMMM Do YYYY' }}</small>
<small *ngIf="isCurrent">CURRENT</small>
</div>

<p class="text-muted">
<ng-container *ngIf="toaRoute; else current">
This PRIME enrolment was approved on {{ acceptedDate | formatDate: 'MMMM Do YYYY' }}
<p>
<ng-container *ngIf="approvedDate; else current">
{{ 'This PRIME enrolment was approved on ' + (approvedDate | formatDate: 'MMMM Do YYYY') }}
</ng-container>
<ng-template #current>
Enrollee edited and submitted an Enrolment, but has not signed the Terms of Access
This PRIME enrolment was not approved
</ng-template>
</p>

<ng-container *ngIf="approvedDate">
<p>
TOA assigned - {{ agreementType }}
{{ acceptedDate ? ', TOA was accepted on ' + (acceptedDate | formatDate: 'MMMM Do YYYY') :
', TOA was not accepted' }}
</p>
</ng-container>
<div *ngIf="remoteAccess"
class="card-title">
User Requested Remote Access
Expand All @@ -82,10 +92,10 @@
<mat-card-actions>
<button mat-button
color="primary"
[routerLink]="enrolmentRoute">View Enrolment</button>
[routerLink]="enrolmentRoute">View Enrolment Detail</button>
<button mat-button
color="primary"
[disabled]="!acceptedDate"
*ngIf="acceptedDate"
[routerLink]="toaRoute">View Terms of Access</button>
</mat-card-actions>
</mat-card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface EnrolmentCard {
agreementId: number;
submissionId: number;
agreementType: string;
agreementAcceptedDate: string;
enrolmentApprovedDate: string;
requestedRemoteAccess: boolean;
submissionCreatedDate: string;
isCurrent: boolean;
Expand Down
52 changes: 30 additions & 22 deletions prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Prime.Models.Api;
using Prime.ViewModels;
using Prime.Services.Razor;
using System.Linq;
using System;

namespace Prime.Controllers
{
Expand Down Expand Up @@ -124,7 +126,7 @@
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ApiMessageResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResultResponse<IEnumerable<EnrolmentCardViewModel>>), StatusCodes.Status200OK)]
public async Task<ActionResult> GetEnrolleeEnrolmentCards(int enrolleeId, [FromQuery] AgreementFilters filters)

Check failure on line 129 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ6Pu0j92Ak3xlgmIlFC&open=AZ6Pu0j92Ak3xlgmIlFC&pullRequest=2859
{
var record = await _enrolleeService.GetPermissionsRecordAsync(enrolleeId);
if (record == null)
Expand All @@ -137,22 +139,34 @@
}

var enrolmentCards = new List<EnrolmentCardViewModel>();

var submissions = await _enrolleeSubmissionService.GetEnrolleeSubmissionsAsync(enrolleeId);
var agreements = await _enrolleeAgreementService.GetEnrolleeAgreementsAsync(enrolleeId, filters);
var lastSubmissionDate = null as DateTimeOffset?;

foreach (var agreement in agreements)
{
var submission = await _enrolleeSubmissionService.GetEnrolleeSubmissionBeforeDateAsync(enrolleeId, agreement.AcceptedDate.Value);
var currentSubmission = submissions.First();

var card = new EnrolmentCardViewModel
foreach (var submission in submissions)
{
//filter the submission that within the year selected
if (submission.CreatedDate.Year == filters.YearAccepted || filters.YearAccepted == null)
{
AgreementId = agreement.Id,
AgreementAcceptedDate = agreement.AcceptedDate,
Submission = submission,
IsCurrent = agreement.IsCurrent
};

enrolmentCards.Add(card);
//find the agreement that created after the submission and before the next submission (if exists)
var agreement = agreements.Where(a => submission.CreatedDate <= a.CreatedDate &&

Check warning on line 154 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Drop 'Where' and move the condition into the 'FirstOrDefault'.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ6Pu0j92Ak3xlgmIlFD&open=AZ6Pu0j92Ak3xlgmIlFD&pullRequest=2859
(lastSubmissionDate == null || a.CreatedDate < lastSubmissionDate)).FirstOrDefault();
var card = new EnrolmentCardViewModel
{
AgreementId = agreement != null ? agreement.Id : 0,
AgreementType = agreement != null ? agreement.AgreementVersion.AccessType : null,
AgreementAcceptedDate = agreement != null ? agreement.AcceptedDate : null,
EnrolmentApprovedDate = agreement != null ? agreement.CreatedDate : null,
Submission = submission,
SubmissionId = submission.Id,
IsCurrent = currentSubmission.Id == submission.Id
};

enrolmentCards.Add(card);
lastSubmissionDate = submission.CreatedDate;
}
}

if (User.IsAdministrant())
Expand Down Expand Up @@ -206,14 +220,14 @@
/// Get the submission for a given agreement.
/// </summary>
/// <param name="enrolleeId"></param>
/// <param name="agreementId"></param>

Check warning on line 223 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View workflow job for this annotation

GitHub Actions / test-backend (8.0)

XML comment has a param tag for 'agreementId', but there is no parameter by that name

Check warning on line 223 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View workflow job for this annotation

GitHub Actions / test-backend (8.0)

XML comment has a param tag for 'agreementId', but there is no parameter by that name
[HttpGet("{enrolleeId}/agreements/{agreementId}/submission", Name = nameof(GetSubmissionForAgreement))]
[HttpGet("{enrolleeId}/agreements/{submissionId}/submission", Name = nameof(GetSubmissionForAgreement))]
[ProducesResponseType(typeof(ApiMessageResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ApiMessageResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ApiResultResponse<Submission>), StatusCodes.Status200OK)]
public async Task<ActionResult> GetSubmissionForAgreement(int enrolleeId, int agreementId)
public async Task<ActionResult> GetSubmissionForAgreement(int enrolleeId, int submissionId)

Check warning on line 230 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View workflow job for this annotation

GitHub Actions / test-backend (8.0)

Parameter 'submissionId' has no matching param tag in the XML comment for 'EnrolleeAgreementsController.GetSubmissionForAgreement(int, int)' (but other parameters do)

Check warning on line 230 in prime-dotnet-webapi/Controllers/EnrolleeAgreementsController.cs

View workflow job for this annotation

GitHub Actions / test-backend (8.0)

Parameter 'submissionId' has no matching param tag in the XML comment for 'EnrolleeAgreementsController.GetSubmissionForAgreement(int, int)' (but other parameters do)
{
var record = await _enrolleeService.GetPermissionsRecordAsync(enrolleeId);
if (record == null)
Expand All @@ -225,16 +239,10 @@
return Forbid();
}

Agreement agreement = await _enrolleeAgreementService.GetEnrolleeAgreementAsync(enrolleeId, agreementId);
if (agreement == null || agreement.AcceptedDate == null)
{
return NotFound($"Accepted Agreement not found with id {agreementId} for enrollee with id {enrolleeId}");
}

var enrolleeSubmission = await _enrolleeSubmissionService.GetEnrolleeSubmissionBeforeDateAsync(enrolleeId, agreement.AcceptedDate.Value);
var enrolleeSubmission = await _enrolleeSubmissionService.GetEnrolleeSubmissionAsync(submissionId);
if (enrolleeSubmission == null)
{
return NotFound($"No enrolment submissions were found for Agreement with id {agreementId} for enrollee with id {enrolleeId}.");
return NotFound($"No enrolment submissions were found for Submission with id {submissionId} for enrollee with id {enrolleeId}.");
}

if (User.IsAdministrant())
Expand Down
1 change: 1 addition & 0 deletions prime-dotnet-webapi/Services/EnrolleeAgreementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async Task<IEnumerable<Agreement>> GetEnrolleeAgreementsAsync(int enrolle
var agreements = await _context.Agreements
.AsNoTracking()
.Include(at => at.SignedAgreement)
.Include(at => at.AgreementVersion)
.Where(at => at.EnrolleeId == enrolleeId)
.OrderByDescending(at => at.CreatedDate)
.If(filters.OnlyLatest, q => q.Take(1))
Expand Down
1 change: 1 addition & 0 deletions prime-dotnet-webapi/Services/EnrolleeSubmissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public async Task<IEnumerable<Submission>> GetEnrolleeSubmissionsAsync(int enrol
{
return await _context.Submissions
.Where(epv => epv.EnrolleeId == enrolleeId)
.OrderByDescending(epv => epv.CreatedDate)
.ToListAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ namespace Prime.ViewModels
public class EnrolmentCardViewModel
{
public int AgreementId { get; set; }
public int SubmissionId { get; set; }
public string AgreementType { get; set; }

public DateTimeOffset? AgreementAcceptedDate { get; set; }

public DateTimeOffset? EnrolmentApprovedDate { get; set; }

public bool IsCurrent { get; set; }

[JsonIgnore]
public Submission Submission { get; set; }


public bool RequestedRemoteAccess
{
get
Expand Down
Loading