Skip to content

Instantly share code, notes, and snippets.

@janpauldahlke
Created August 24, 2021 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janpauldahlke/e92206928f278d4d5f634cb2ff7f4690 to your computer and use it in GitHub Desktop.
Save janpauldahlke/e92206928f278d4d5f634cb2ff7f4690 to your computer and use it in GitHub Desktop.
selectAllScopeCarePlans(scope: string): Observable<GroupedCarePlan> {
const result = this.selectAllScoped(scope).pipe(
distinctUntilChanged(),
first(),
//map by doNotPerform WI-7133
map((plans) => {
let groupedByPerform: GroupedCarePlan;
plans.map((plan) => {
//status active
if (!plan.activity[0]?.detail?.doNotPerform) {
groupedByPerform = {
plans: [...groupedByPerform?.plans, plan],
status: 'active'
};
} else {
groupedByPerform = {
plans: [...groupedByPerform?.plans, plan],
status: 'not-active',
};
}
});
return groupedByPerform;
}),
//map by date is valid WI-7133
map((plan: GroupedCarePlan) => {
let groupedByDate: GroupedCarePlan = {
plans: [],
};
plan.plans.map((p) => {
const { start, end } = p?.period;
//start < now past
if (moment(start).isBefore(Date.now())) {
//this is past
if (moment(end).isBefore(Date.now())) {
groupedByDate = {
plans: [...groupedByDate?.plans, p],
status: groupedByDate?.status,
tempus: 'past',
};
} else {
//is present since start < DateNow < end
groupedByDate = {
plans: [...groupedByDate.plans, p],
status: groupedByDate?.status,
tempus: 'present',
};
}
}
//future plans start && end > DateNow
else if (moment(start).isAfter(Date.now()) && moment(end).isAfter(Date.now())) {
groupedByDate = {
plans: [...groupedByDate?.plans, p],
status: groupedByDate?.status,
tempus: 'future',
};
}
});
return groupedByDate;
}),
tap(e => console.log('in tap', e))
);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment