Skip to content

Commit

Permalink
PRIME-2670 Fix HA Site status filtering (#2455)
Browse files Browse the repository at this point in the history
* initial commit

* fix PR issues

* fix PR issues

---------

Co-authored-by: Alan Leung <[email protected]>
  • Loading branch information
bergomi02 and neophyte57 authored Feb 29, 2024
1 parent 784c971 commit 262cf3b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
4 changes: 3 additions & 1 deletion prime-angular-frontend/src/app/lib/enums/site-status.enum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export enum SiteStatusType {
EDITABLE = 1,
IN_REVIEW = 2,
LOCKED = 3
LOCKED = 3,
EDITABLE_NOT_APPROVED = 4,
FLAGGED = 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export class SearchHAFormComponent implements OnInit {
this.siteStatuses = new Array<Config<number>>();

const inReviewStatus = new Config<number>(SiteStatusType.IN_REVIEW, 'In Review');
const editableStatus = new Config<number>(SiteStatusType.EDITABLE, 'Editable');
const lockedStatus = new Config<number>(SiteStatusType.LOCKED, 'Locked');
const editableStatus = new Config<number>(SiteStatusType.EDITABLE, 'Editable - approved');
const editableNotApprovedStatus = new Config<number>(SiteStatusType.EDITABLE_NOT_APPROVED, 'Editable - not approved');
const flaggedStatus = new Config<number>(SiteStatusType.FLAGGED, 'Flagged');

this.siteStatuses.push(inReviewStatus, editableStatus, lockedStatus);
this.siteStatuses.push(editableNotApprovedStatus, inReviewStatus, editableStatus, flaggedStatus);

this.careTypes = this.configService.careTypes;
this.vendors = this.configService.vendors
Expand Down
6 changes: 5 additions & 1 deletion prime-dotnet-webapi/Models/Statuses/SiteStatusType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ public enum SiteStatusType
{
Editable = 1,
InReview = 2,
Locked = 3
Locked = 3,

//the status types below is used for filtering
EditableNotApproved = 4,
Flagged = 5
}
}
24 changes: 22 additions & 2 deletions prime-dotnet-webapi/Services/HealthAuthoritySiteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ public async Task<IEnumerable<HealthAuthoritySiteAdminListViewModel>> GetSitesAs
{
searchOptions ??= new HealthAuthoritySiteSearchOptions();

int? statusId = null;
bool flagged = false;
if (searchOptions.StatusId.HasValue)
{
if (searchOptions.StatusId == (int)SiteStatusType.Flagged)
{
flagged = true;
}
else
{
statusId = searchOptions.StatusId == (int)SiteStatusType.EditableNotApproved ?
(int)SiteStatusType.Editable : searchOptions.StatusId;
}
}

var query = _context.HealthAuthoritySites
.AsNoTracking()
.If(!string.IsNullOrWhiteSpace(searchOptions.TextSearch),
Expand All @@ -104,9 +119,14 @@ public async Task<IEnumerable<HealthAuthoritySiteAdminListViewModel>> GetSitesAs
s => s.HealthAuthorityCareType.CareType)
.Containing(searchOptions.TextSearch)
)
.If(searchOptions.StatusId.HasValue,
.If(statusId.HasValue,
q => q.Where(s => (int)s.SiteStatuses.OrderByDescending(ss => ss.StatusDate)
.FirstOrDefault().StatusType == searchOptions.StatusId))
.FirstOrDefault().StatusType == statusId &&
((searchOptions.StatusId == (int)SiteStatusType.Editable && s.ApprovedDate.HasValue) ||
(searchOptions.StatusId == (int)SiteStatusType.EditableNotApproved && !s.ApprovedDate.HasValue) ||
searchOptions.StatusId == (int)SiteStatusType.InReview ||
searchOptions.StatusId == (int)SiteStatusType.Locked)))
.If(flagged, q => q.Where(s => s.Flagged))
.If(!string.IsNullOrWhiteSpace(searchOptions.AdminUserName),
q => q.Where(s => s.Adjudicator.Username == searchOptions.AdminUserName))
.If(searchOptions.VendorId.HasValue,
Expand Down

0 comments on commit 262cf3b

Please sign in to comment.