diff --git a/src/components/MessagingView.tsx b/src/components/MessagingView.tsx index cd767bd..91c841b 100644 --- a/src/components/MessagingView.tsx +++ b/src/components/MessagingView.tsx @@ -155,7 +155,7 @@ export default class MessagingView extends React.Component< this.setState({ messagesLoading: true }); const carePlanIds = context.allCarePlans?.map((item) => item.id); - + this.loadFailedCommunications(); this.getCommunications(context.client, carePlanIds, url) .then( (result: Communication[]) => { @@ -296,6 +296,63 @@ export default class MessagingView extends React.Component< ); } + loadFailedCommunications() { + // @ts-ignore + let client: Client = this.context.client; + //@ts-ignore + let existingCarePlan: CarePlan = this.context.currentCarePlan; + //@ts-ignore + let patient: Patient = this.context.patient; + + const today = new Date(); + const todayDateString = [ + today.toLocaleString("default", { year: "numeric" }), + today.toLocaleString("default", { month: "2-digit" }), + today.toLocaleString("default", { day: "2-digit" }), + ].join("-"); + + // Search only for manually sent messages + let params = new URLSearchParams({ + recipient: `Patient/${patient.id}`, + category: IsaccMessageCategory.isaccManuallySentMessage.code, + "based-on": existingCarePlan.reference, + _sort: "occurrence", + occurrence: `ge${todayDateString}`, + _count: "100", + }).toString(); + const requestURL = `/CommunicationRequest?${params}`; + let failedCommunicationRequests: CommunicationRequest[] = []; + getFhirData(client, requestURL).then( + (bundle: Bundle) => { + if (bundle.type === "searchset") { + if (bundle.entry) { + failedCommunicationRequests = bundle.entry.map((e: IBundle_Entry) => { + if (e.resource.resourceType !== "CommunicationRequest" || e.resource.status == "active") { + return null; + } else { + console.log("CommunicationRequests loaded:", e); + return CommunicationRequest.from(e.resource); + } + }); + // Iterate overall all failed CRs, initializing them as communications + // and appending them to list of failed communications + failedCommunicationRequests.forEach((failedCommunicationRequest) => { + let failedCommunication = Communication.from(failedCommunicationRequest); + failedCommunication.status = failedCommunicationRequest.status === "on-hold" ? "on-hold" : "not-done"; + this.state.communications.unshift(failedCommunication); + }); + } + } + }, + (reason: any) => { + console.log( + "Unable to load failed Communication resources for the patient. ", + reason + ); + } + ); + } + render(): React.ReactNode { if (!this.state) return ; @@ -1353,7 +1410,16 @@ export default class MessagingView extends React.Component< let timestamp = null; let delivered = true; - + let unsubscribed = false; + let error = false; + if (isNonSmsMessage && message.status == "on-hold") + { + // Message failed due to being unsubscribed + unsubscribed = true; + } else if (isNonSmsMessage && message.status == "not-done"){ + // Message failed due to unaccounted for error + error = true; + } if (!isNonSmsMessage && message.sent) { timestamp = MessagingView.displayDateTime(message.sent); } else { @@ -1378,6 +1444,8 @@ export default class MessagingView extends React.Component< delivered, isNonSmsMessage && incoming, isNonSmsMessage && !incoming, + unsubscribed, + error, isComment ); let priority = message.priority; @@ -1594,6 +1662,8 @@ export default class MessagingView extends React.Component< pending: grey[700], nonSMSReceived: teal[50], nonSMSSent: "#c9e4f7", + unsubscribed: "#D4D4D4", + error: "#FFFFFF", comment: grey[300], }; @@ -1603,6 +1673,8 @@ export default class MessagingView extends React.Component< delivered: boolean, nonSMSReceived: boolean, nonSMSSent: boolean, + unsubscribed: boolean, + error: boolean, comment: boolean ): object { if (comment) @@ -1613,6 +1685,22 @@ export default class MessagingView extends React.Component< boxShadow: `1px 1px 2px ${grey[700]}`, borderBottomRightRadius: "72px 4px", }; + if (unsubscribed) + return { + backgroundColor: MessagingView.colorsByType["unsubscribed"], + borderRadius: 0, + color: "#000", + boxShadow: `1px 1px 2px orange`, + borderBottomRightRadius: "72px 4px", + }; + if (error) + return { + backgroundColor: MessagingView.colorsByType["error"], + borderRadius: 0, + color: "#000", + boxShadow: `1px 1px 2px red`, + borderBottomRightRadius: "72px 4px", + }; if (nonSMSReceived) return { backgroundColor: MessagingView.colorsByType["nonSMSReceived"], diff --git a/src/model/CarePlan.ts b/src/model/CarePlan.ts index d361d63..342e46d 100644 --- a/src/model/CarePlan.ts +++ b/src/model/CarePlan.ts @@ -105,12 +105,12 @@ export default class CarePlan implements ICarePlan { getActiveCommunicationRequests() { return this.communicationRequests?.filter( - (message: CommunicationRequest) => message.status !== "revoked" + (message: CommunicationRequest) => message.status == "active" ) } private updateActivityAttr() { - this.activity = this.communicationRequests.filter((req: CommunicationRequest) => req.status !== 'revoked').map((req: CommunicationRequest) => CarePlanActivity.withReference(req.reference)); + this.activity = this.communicationRequests.filter((req: CommunicationRequest) => req.status == 'active').map((req: CommunicationRequest) => CarePlanActivity.withReference(req.reference)); } addCommunicationRequest(communicationRequest: CommunicationRequest) {