Skip to content

Commit e0c7fb9

Browse files
committed
fix: post dated inclusions subsequently revoked
1 parent 7c245e9 commit e0c7fb9

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

packages/gsul/src/getStatusUpdates.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,20 @@ export const filterOutFutureReduceToLatestUpdates = (
8181
})
8282

8383
// flatten both regular and post-dated updates into single array
84+
// but exclude post-dated updates if they have been revoked by a subsequent regular update
8485
const uniqueItems: Array<itemType> = []
8586
Object.values(itemGroups).forEach(group => {
8687
if (group.regular) uniqueItems.push(group.regular)
87-
if (group.postDated) uniqueItems.push(group.postDated)
88+
if (group.postDated) {
89+
// Only include post-dated update if there's no regular update that came after it was set
90+
const postDatedSetTime = Date.parse(group.postDated.postDatedLastModifiedSetAt)
91+
const regularUpdateTime = group.regular ? Date.parse(group.regular.lastUpdateDateTime) : 0
92+
93+
// If the regular update came after the post-dated was set, it revokes the post-dated update
94+
if (!group.regular || regularUpdateTime <= postDatedSetTime) {
95+
uniqueItems.push(group.postDated)
96+
}
97+
}
8898
})
8999

90100
const result: outputPrescriptionType = {

packages/gsul/tests/testBuildResult.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,41 @@ const scenarios: Array<scenariosType> = [
267267
onboarded: false,
268268
items: []
269269
}
270+
},
271+
{
272+
scenarioDescription: "should return With pharmacy when RTC has been revoked",
273+
currentTime: new Date("2025-12-11T12:00:00Z").getTime(),
274+
inputPrescriptions: {
275+
prescriptionID: "abc",
276+
odsCode: "123"
277+
},
278+
queryResults: [
279+
{
280+
itemId: "item_1",
281+
latestStatus: "Ready to collect",
282+
isTerminalState: false,
283+
lastUpdateDateTime: "2025-12-11T10:00:00Z",
284+
postDatedLastModifiedSetAt: "2025-12-10T10:00:00Z"
285+
},
286+
{
287+
itemId: "item_1",
288+
latestStatus: "With pharmacy",
289+
isTerminalState: false,
290+
lastUpdateDateTime: "2025-12-10T11:00:00Z"
291+
}
292+
],
293+
expectedResult: {
294+
prescriptionID: "abc",
295+
onboarded: true,
296+
items: [
297+
{
298+
itemId: "item_1",
299+
latestStatus: "With pharmacy",
300+
isTerminalState: false,
301+
lastUpdateDateTime: "2025-12-10T11:00:00Z"
302+
}
303+
]
304+
}
270305
}
271306
]
272307
describe("Unit tests for buildResults", () => {

0 commit comments

Comments
 (0)