Skip to content

Commit

Permalink
Enrollment client - remove next message date/time extension when null
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen authored and Amy Chen committed Nov 14, 2023
1 parent fc495ef commit d65a628
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/components/ScheduleSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -721,30 +721,39 @@ export default class ScheduleSetup extends React.Component<
console.log("CommunicationRequest updated:", v);
}
);
const activeScheduledCommunicationRequests = updatedCommunicationRequests
.filter(
(ucr : CommunicationRequest) =>
ucr.status === "active" &&
CommunicationRequest.isScheduledOutgoingMessage(ucr)
)
.sort((a, b) => {
let d1 = a.occurrenceDateTime;
let d2 = b.occurrenceDateTime;
const t1 = d1 ? new Date(d1).getTime() : 0;
const t2 = d2 ? new Date(d2).getTime() : 0;
return t1 - t2;
});
const activeScheduledCommunicationRequests =
updatedCommunicationRequests
.filter(
(ucr: CommunicationRequest) =>
ucr.status === "active" &&
CommunicationRequest.isScheduledOutgoingMessage(ucr)
)
.sort((a, b) => {
let d1 = a.occurrenceDateTime;
let d2 = b.occurrenceDateTime;
const t1 = d1 ? new Date(d1).getTime() : 0;
const t2 = d2 ? new Date(d2).getTime() : 0;
return t1 - t2;
});

// console.log("next ", activeCommunicationRequests[0].occurrenceDateTime)
// add next scheduled message date/time extension
patient.nextScheduledMessageDateTime =
activeScheduledCommunicationRequests.length
? activeScheduledCommunicationRequests[0]?.occurrenceDateTime
: null;
if (patient.nextScheduledMessageDateTime) {
activeScheduledCommunicationRequests.length
? activeScheduledCommunicationRequests[0]
?.occurrenceDateTime
: null; // set next scheduled message date/time to null if there is no active communicationRequest
client
// @ts-ignore
client.update(patient).then(() => this.onSaved(savedCarePlan));
} else this.onSaved(savedCarePlan);
.update(patient)
.then(() => this.onSaved(savedCarePlan))
.catch((e) => {
this.showSnackbar(
"warning",
`Issue encountered updating patient's next scheduled message date/time. See console for detail.`
);
this.onSaved(savedCarePlan)
});
}
);
},
Expand Down
6 changes: 6 additions & 0 deletions src/model/Patient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ export default class Patient implements IPatient {

set nextScheduledMessageDateTime(value: string) {
if (!value) {
if (this.extension) {
// if next scheduled message date time is null then removed the extension
this.extension = this.extension?.filter(
(i: IExtension) => i.url !== ExtensionUrl.nextScheduledgMessageDateTimeUrl
);
}
return;
}
if (!this.extension) {
Expand Down

0 comments on commit d65a628

Please sign in to comment.