From 67bfbc5ce9340401e780088b4c63d1c6398fca4c Mon Sep 17 00:00:00 2001 From: Saningo Lekalantula Date: Sun, 21 Jul 2024 14:17:02 +0300 Subject: [PATCH] POC:799 Update Group Status for OTZ Clubs from 3 to 6 months (#1760) Co-authored-by: Alfred Mutai <124869802+Alfred-Mutai@users.noreply.github.com> --- src/app/models/group.model.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/models/group.model.ts b/src/app/models/group.model.ts index eaecc745a..c4e729881 100644 --- a/src/app/models/group.model.ts +++ b/src/app/models/group.model.ts @@ -39,17 +39,27 @@ export class Group extends BaseModel { @serializable() public get status() { - const lastMeetingDate = this.getLatestMeetingDate( - this._openmrsModel.cohortVisits - ); - // if last meeting date is more than 3 months ago, group is inactive + let lastMeetingDate: any; + + if (this._openmrsModel.cohortVisits.length > 0) { + lastMeetingDate = this.getLatestMeetingDate( + this._openmrsModel.cohortVisits + ); + } else { + lastMeetingDate = new Date(this._openmrsModel.startDate); + } + + // if last meeting date is more than 6 months ago, group is inactive if (lastMeetingDate) { const today = new Date(); - const threeMonthsAgo = new Date(today.setMonth(today.getMonth() - 3)); - if (lastMeetingDate < threeMonthsAgo) { + const sixMonthsAgo = new Date(); + sixMonthsAgo.setMonth(today.getMonth() - 6); + + if (lastMeetingDate <= sixMonthsAgo) { return 'Inactive'; } } + return this._openmrsModel.endDate ? 'Disbanded' : 'Active'; }