Skip to content

Commit

Permalink
POC:799 Update Group Status for OTZ Clubs from 3 to 6 months (#1760)
Browse files Browse the repository at this point in the history
Co-authored-by: Alfred Mutai <[email protected]>
  • Loading branch information
sainingo and Alfred-Mutai authored Jul 21, 2024
1 parent 2ec29c4 commit 67bfbc5
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/app/models/group.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down

0 comments on commit 67bfbc5

Please sign in to comment.