Skip to content

Commit a673c16

Browse files
Update: [AEA-5781] - adds messages and fallback title to bubble up to UI (#1371)
## Summary - Routine Change <img width="1759" height="1007" alt="image" src="https://github.com/user-attachments/assets/f990c0f7-8beb-4035-9bcd-69f49188a3dd" />
1 parent b89fcc1 commit a673c16

File tree

5 files changed

+74
-13
lines changed

5 files changed

+74
-13
lines changed

packages/cpt-ui/src/constants/ui-strings/PrescriptionMessage.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,33 @@ export const PRESCRIPTION_MESSAGES: Record<string, string> = {
1111
"admin-action-updated": "An action update has been made by an EPS Prescription Tracker system administrator",
1212
"prescription-reset": "Dispenser has requested to reset the prescription",
1313
"prescription-cancelled": "This prescription or item was cancelled",
14-
"prescription-marked-for-cancellation": "This prescription has a pending cancellation, but the prescription or items on it have not been cancelled as it has been downloaded by a dispenser",
15-
"subsequent-cancellation": "This prescription or item was cancelled as the prescription was returned or the items to be cancelled were recorded as 'Not Dispensed'",
14+
15+
"prescription-marked-for-cancellation":
16+
"This prescription has a pending cancellation, but the prescription or items on it have not been cancelled as it has been downloaded by a dispenser",
17+
18+
"subsequent-cancellation":
19+
"This prescription or item was cancelled as the prescription was returned or the items to be cancelled were recorded as 'Not Dispensed'",
1620
"dispense-history-rebuilt": "Dispenser has corrected the prescription's dispensing history",
1721
"urgent-batch-updated": "Updated by Urgent Admin Batch worker at NHS England (an internal EPS system event)",
1822
"routine-batch-updated": "Updated by Routine Admin Batch worker at NHS England (an internal EPS system event)",
1923
"non-urgent-batch-updated": "Updated by Non-Urgent Admin Batch worker at NHS England (an internal EPS system event)",
2024
"document-batch-updated": "Updated by Document Batch worker at NHS England (an internal EPS system event)",
21-
"item-partially-collected": "The item has been partially collected or received by the patient, in less quantity than was requested by prescriber"
25+
26+
"prescription-not-cancelled-dispensed":
27+
"A prescriber requested to cancel this prescription or item, but it has already been dispensed",
28+
"prescription-expired":
29+
"This prescription or item has expired, so it cannot be cancelled",
30+
"prescription-already-cancelled":
31+
"A prescriber requested to cancel this prescription or item, but it had been cancelled already",
32+
"prescription-cancellation-requested-other":
33+
"This prescription or item is pending cancellation requested by a different prescriber",
34+
"prescription-not-cancelled-not-dispensed":
35+
"This prescription or item was marked as 'Not dispensed' by the dispenser, so it cannot be cancelled by the prescriber",
36+
"prescription-or-item-not-found":
37+
"Information about this prescription or item cannot be found",
38+
"cancel-request-invalid":
39+
"This cancellation request has not been processed because the prescriber did not give enough information",
40+
41+
"item-partially-collected":
42+
"The item has been partially collected or received by the patient, in less quantity than was requested by prescriber"
2243
}

packages/prescriptionDetailsLambda/src/services/prescriptionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,5 @@ export async function processPrescriptionRequest(
127127
issueNumber
128128
})
129129

130-
return mergePrescriptionDetails(apigeeResponse.data, doHSData, odsCodes)
130+
return mergePrescriptionDetails(apigeeResponse.data, doHSData, odsCodes, logger)
131131
}

packages/prescriptionDetailsLambda/src/utils/fhirMappers.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {MedicationDispense, MedicationRequest, Patient} from "fhir/r4"
22
import {ItemDetails, PatientDetails} from "@cpt-ui-common/common-types"
33
import {findExtensionByKey, getBooleanFromNestedExtension, getCodeFromNestedExtension} from "./extensionUtils"
4+
import {Logger} from "@aws-lambda-powertools/logger"
45

56
/**
67
* Maps message history titles names to semantic message codes
78
*/
8-
export const mapMessageHistoryTitleToMessageCode = (title: string): string => {
9+
export const mapMessageHistoryTitleToMessageCode = (title: string, logger?: Logger): string => {
910
const titleToCodeMap: Record<string, string> = {
1011
"Prescription upload successful": "prescription-uploaded",
1112
"Release Request successful": "release-requested",
@@ -17,9 +18,37 @@ export const mapMessageHistoryTitleToMessageCode = (title: string): string => {
1718
"Administrative update successful": "admin-updated",
1819
"Administrative Action Update Successful": "admin-action-updated",
1920
"Prescription Reset request successful": "prescription-reset",
21+
"Prescription/Item was cancelled": "prescription-cancelled",
2022
"Prescription/item was cancelled": "prescription-cancelled",
23+
24+
"Prescription/item was not cancelled. With dispenser. Marked for cancellation":
25+
"prescription-marked-for-cancellation",
2126
"Prescription/item was not cancelled. With dispenser active. Marked for cancellation":
2227
"prescription-marked-for-cancellation",
28+
29+
"Prescription or item was not cancelled. Prescription has been dispensed.":
30+
"prescription-not-cancelled-dispensed",
31+
32+
"Prescription or item had expired.": "prescription-expired",
33+
34+
"Prescription or item had already been cancelled.": "prescription-already-cancelled",
35+
36+
"Prescription or item cancellation requested by another prescriber.":
37+
"prescription-cancellation-requested-other",
38+
39+
"Prescription or item was not cancelled. Prescription has been not dispensed.":
40+
"prescription-not-cancelled-not-dispensed",
41+
42+
"Prescription or item not found.": "prescription-or-item-not-found",
43+
"Unable to process message due to invalid information within the cancel request.":
44+
"cancel-request-invalid",
45+
// eslint-disable-next-line max-len
46+
"The item has been partially collected / received by the patient in a less quantity than was requested by the prescriber.":
47+
"item-partially-collected",
48+
// eslint-disable-next-line max-len
49+
"The item has been partially collected or received by the patient, in less quantity than was requested by prescriber.":
50+
"item-partially-collected",
51+
2352
"Subsequent cancellation": "subsequent-cancellation",
2453
"Rebuild Dispense History successful": "dispense-history-rebuilt",
2554
"Updated by Urgent Admin Batch worker": "urgent-batch-updated",
@@ -28,7 +57,15 @@ export const mapMessageHistoryTitleToMessageCode = (title: string): string => {
2857
"Updated by Document Batch worker": "document-batch-updated"
2958
}
3059

31-
return titleToCodeMap[title]
60+
const mapped = titleToCodeMap[title]
61+
62+
if (!mapped) {
63+
logger?.warn("missing mapping for Spine message title", {missingTitle: title})
64+
// fallback: show raw Spine message in UI
65+
return title
66+
}
67+
68+
return mapped
3269
}
3370

3471
/**

packages/prescriptionDetailsLambda/src/utils/responseMapper.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
PrescriptionDetailsResponse
2929
} from "@cpt-ui-common/common-types"
3030
import {DoHSOrg} from "@cpt-ui-common/doHSClient"
31+
import {Logger} from "@aws-lambda-powertools/logger"
3132

3233
/**
3334
* Extracts a specific resource type from the FHIR Bundle
@@ -85,7 +86,8 @@ const extractMessageHistory = (
8586
requestGroup: RequestGroup,
8687
doHSData: DoHSData,
8788
medicationRequests: Array<MedicationRequest>,
88-
medicationDispenses: Array<MedicationDispense>
89+
medicationDispenses: Array<MedicationDispense>,
90+
logger?: Logger
8991
): Array<MessageHistory> => {
9092
// find the specific "Prescription status transitions" action
9193
const historyAction = requestGroup.action?.find(action =>
@@ -102,7 +104,7 @@ const extractMessageHistory = (
102104

103105
const orgODS = action.participant![0].extension![0].valueReference!.identifier!.value!
104106
const messageCodeDisplayName = action.title!
105-
const messageCode = mapMessageHistoryTitleToMessageCode(messageCodeDisplayName)
107+
const messageCode = mapMessageHistoryTitleToMessageCode(messageCodeDisplayName, logger)
106108

107109
let orgName: string | undefined = undefined
108110

@@ -173,7 +175,8 @@ export const mergePrescriptionDetails = (
173175
prescribingOrganization,
174176
nominatedPerformer,
175177
dispensingOrganization
176-
}: PrescriptionOdsCodes
178+
}: PrescriptionOdsCodes,
179+
logger?: Logger
177180
): PrescriptionDetailsResponse => {
178181
// Extract resources from bundle
179182
const requestGroup = extractResourcesFromBundle<RequestGroup>(bundle, "RequestGroup")[0]
@@ -214,7 +217,7 @@ export const mergePrescriptionDetails = (
214217
// extract and format all the data
215218
const patientDetails = extractPatientDetails(patient)
216219
const items = extractItems(medicationRequests, medicationDispenses)
217-
const messageHistory = extractMessageHistory(requestGroup, doHSData, medicationRequests, medicationDispenses)
220+
const messageHistory = extractMessageHistory(requestGroup, doHSData, medicationRequests, medicationDispenses, logger)
218221

219222
// TODO: extract NHS App status from dispensing information extension
220223
// const dispensingInfoExt = findExtensionByKey(dispense.extension, "DISPENSING_INFORMATION")

packages/prescriptionDetailsLambda/tests/test_fhirMapper.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ describe("mapMessageHistoryTitleToMessageCode", () => {
1919
})
2020

2121
it("should return undefined for unrecognized message titles", () => {
22-
expect(mapMessageHistoryTitleToMessageCode("Unknown Message")).toBeUndefined()
23-
expect(mapMessageHistoryTitleToMessageCode("")).toBeUndefined()
22+
expect(mapMessageHistoryTitleToMessageCode("Unknown Message")).toBe("Unknown Message")
23+
expect(mapMessageHistoryTitleToMessageCode("")).toBe("")
2424
})
2525

2626
it("should handle undefined message titles gracefully", () => {
27-
expect(mapMessageHistoryTitleToMessageCode("")).toBeUndefined()
27+
expect(mapMessageHistoryTitleToMessageCode("")).toBe("")
2828
})
2929
})
3030

0 commit comments

Comments
 (0)