Skip to content

Commit 6d53ab1

Browse files
authored
New: [AEA-6061] - Support Optum post dated prescription updates (#2559)
## Summary - ✨ New Feature ### Details - Support batch processors' post dated prescription updates
1 parent 01bdad0 commit 6d53ab1

6 files changed

Lines changed: 91 additions & 8 deletions

File tree

packages/common/commonTypes/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export interface PSUDataItem {
1111
TerminalStatus: string
1212
ApplicationName: string
1313
ExpiryTime: number
14+
// (Optional, legacy batch-processors only) Indicates that {@link LastModified} is postdated;
15+
// contains the ISO 8601 timestamp when the postdated update was set.
16+
PostDatedLastModifiedSetAt?: string
1417
}
1518

1619
export interface NotifyDataItem {

packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ export function buildDataItems(
384384
ExpiryTime: (Math.floor(+new Date() / 1000) + TTL_DELTA)
385385
}
386386

387+
if (task.meta?.lastUpdated) {
388+
(dataItem as any).PostDatedLastModifiedSetAt = task.meta.lastUpdated
389+
}
390+
387391
dataItems.push(dataItem)
388392
}
389393
return dataItems

packages/updatePrescriptionStatus/src/validation/content.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,30 @@ export function entryContent(entry: BundleEntry): Array<string> {
6363
}
6464

6565
export function lastModified(task: Task): string | undefined {
66-
const today = new Date()
6766
const lastModified = new Date(task.lastModified!)
67+
return isPastDate(lastModified, "lastModified")
68+
}
6869

69-
if (isNaN(lastModified.getTime())) {
70-
return "Date format provided for lastModified is invalid."
70+
function isPastDate(date: Date, fieldName: string): string | undefined {
71+
if (isNaN(date.getTime())) {
72+
return `Date format provided for ${fieldName} is invalid.`
7173
}
7274

73-
if (lastModified.valueOf() - today.valueOf() > ONE_DAY_IN_MS) {
74-
return "Invalid last modified value provided."
75+
const today = new Date()
76+
if (date.valueOf() - today.valueOf() > ONE_DAY_IN_MS) {
77+
return `Invalid ${fieldName} value provided.`
7578
}
7679
}
7780

81+
export function metaLastUpdated(task: Task): string | undefined {
82+
if (!task.meta?.lastUpdated) {
83+
return undefined
84+
}
85+
86+
const parsed = new Date(task.meta.lastUpdated)
87+
return isPastDate(parsed, "meta.lastUpdated")
88+
}
89+
7890
export function prescriptionID(task: Task): string | undefined {
7991
const message = "Prescription ID is invalid."
8092
const prescriptionID = task.basedOn?.[0].identifier?.value
@@ -183,6 +195,7 @@ export function taskContent(task: Task): Array<string> {
183195
status,
184196
businessStatus,
185197
lastModified,
198+
metaLastUpdated,
186199
nhsNumber,
187200
prescriptionID,
188201
resourceType,

packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,21 @@ describe("buildDataItems", () => {
287287

288288
expect(dataItems[0].ExpiryTime).toBeGreaterThan(expectedExpiryTime)
289289
})
290+
291+
it("should include PostDatedLastModifiedSetAt in data item when meta.lastUpdated is defined", () => {
292+
const task = validTask()
293+
const lastUpdated = new Date(DEFAULT_DATE.valueOf() - (24 * 60 * 60 * 1000)).toISOString()
294+
task.meta = {
295+
lastUpdated: lastUpdated
296+
}
297+
298+
const requestEntry: BundleEntry = {
299+
resource: task,
300+
fullUrl: ""
301+
}
302+
303+
const dataItems = buildDataItems([requestEntry], "", "")
304+
const first: any = dataItems[0]
305+
expect(first.PostDatedLastModifiedSetAt).toEqual(lastUpdated)
306+
})
290307
})

packages/updatePrescriptionStatus/tests/validation/testRequestContentValidation.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
businessStatus,
1212
codeSystems,
1313
lastModified,
14+
metaLastUpdated,
1415
nhsNumber,
1516
ONE_DAY_IN_MS,
1617
prescriptionID,
@@ -150,7 +151,7 @@ describe("Unit tests for validation of lastModified", () => {
150151
)
151152
const task = {lastModified: futureDate.toISOString()}
152153

153-
const expected = "Invalid last modified value provided."
154+
const expected = "Invalid lastModified value provided."
154155

155156
const actual = lastModified(task as Task)
156157

@@ -176,6 +177,51 @@ describe("Unit tests for validation of lastModified", () => {
176177
})
177178
})
178179

180+
describe("Unit tests for validation of metaLastUpdated", () => {
181+
beforeEach(() => {
182+
jest.useFakeTimers().setSystemTime(DEFAULT_DATE)
183+
})
184+
185+
it("When meta.lastUpdated is over a day in the future, should return expected issue.", async () => {
186+
const futureDate = new Date(
187+
DEFAULT_DATE.valueOf() + (ONE_DAY_IN_MS + 1000)
188+
)
189+
const task = {meta: {lastUpdated: futureDate.toISOString()}}
190+
191+
const expected = "Invalid meta.lastUpdated value provided."
192+
193+
const actual = metaLastUpdated(task as Task)
194+
195+
expect(actual).toEqual(expected)
196+
})
197+
198+
it("When meta.lastUpdated date format is invalid, should return expected issue.", async () => {
199+
const task = {meta: {lastUpdated: "invalid date"}}
200+
201+
const expected = "Date format provided for meta.lastUpdated is invalid."
202+
203+
const actual = metaLastUpdated(task as Task)
204+
205+
expect(actual).toEqual(expected)
206+
})
207+
208+
it("When meta.lastUpdated is valid and not in the future, should return undefined.", async () => {
209+
const task = {meta: {lastUpdated: DEFAULT_DATE.toISOString()}}
210+
211+
const actual = metaLastUpdated(task as Task)
212+
213+
expect(actual).toEqual(undefined)
214+
})
215+
216+
it("When meta.lastUpdated is not present, should return undefined.", async () => {
217+
const task = {}
218+
219+
const actual = metaLastUpdated(task as Task)
220+
221+
expect(actual).toEqual(undefined)
222+
})
223+
})
224+
179225
describe("Unit tests for validation of prescription ID", () => {
180226
it.each([
181227
{

packages/updatePrescriptionStatus/tests/validation/testRequestValidationViaHandler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("Integration tests for validation via updatePrescriptionStatus handler"
5555
const event: APIGatewayProxyEvent = generateMockEvent(body)
5656

5757
const expected = bundleWrap([
58-
badRequest("Invalid last modified value provided.", FULL_URL_0),
58+
badRequest("Invalid lastModified value provided.", FULL_URL_0),
5959
accepted(FULL_URL_1)
6060
])
6161

@@ -77,7 +77,7 @@ describe("Integration tests for validation via updatePrescriptionStatus handler"
7777
const event: APIGatewayProxyEvent = generateMockEvent(body)
7878

7979
const expected = bundleWrap([
80-
badRequest("Invalid last modified value provided.", FULL_URL_0),
80+
badRequest("Invalid lastModified value provided.", FULL_URL_0),
8181
badRequest("Missing required field(s) - FullUrl, PrescriptionID.")
8282
])
8383

0 commit comments

Comments
 (0)