Skip to content

Commit

Permalink
Add the logic and tests for the terminal status completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-szlapa committed May 29, 2024
1 parent da95a92 commit 861b275
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
}
],
"status": "in-progress",
"status": "completed",
"businessStatus": {
"coding": [
{
Expand Down
47 changes: 28 additions & 19 deletions packages/updatePrescriptionStatus/src/validation/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export const BUSINESS_STATUSES = [
"not dispensed"
]

export const COMPLETED_BUSINESS_STATUSES = ["collected", "not dispensed", "dispatched"]

export const IN_PROGRESS_BUSINESS_STATUSES = [
"with pharmacy",
"with pharmacy - preparing remainder",
"ready to collect",
"ready to collect - partial"
]

export function transactionBundle(body: any): boolean {
return body.resourceType === "Bundle" && body.type === "transaction"
}
Expand Down Expand Up @@ -113,25 +122,25 @@ export function businessStatus(task: Task): string | undefined {

export function statuses(task: Task): string | undefined {
const status = task.status
if (status === "completed") {
const businessStatus: CodeableConcept | undefined = task.businessStatus
if (businessStatus) {
const coding: Coding = businessStatus.coding![0]
const code = coding.code

const patientActionRequiredStatuses = [
"with pharmacy",
"with pharmacy - preparing remainder",
"ready to collect",
"ready to collect - partial",
"ready to dispatch",
"ready to dispatch - partial"
]

if (code && patientActionRequiredStatuses.includes(code.toLowerCase())) {
return "Completed state indicated for a prescription status requiring patient action."
}
}
const businessStatus: CodeableConcept | undefined = task.businessStatus

if (!businessStatus) {
return
}

const coding: Coding = businessStatus.coding![0]
const code = coding.code

if (!code) {
return
}

const lowercaseCode = code.toLowerCase()

if (status === "completed" && IN_PROGRESS_BUSINESS_STATUSES.includes(lowercaseCode)) {
return "Completed state indicated for a prescription status requiring patient action."
} else if (status === "in-progress" && COMPLETED_BUSINESS_STATUSES.includes(lowercaseCode)) {
return "In-progress state indicated for a prescription status that should be completed."
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/updatePrescriptionStatus/tests/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const TASK_VALUES = [
odsCode: "C9Z1O",
lineItemID: "6989b7bd-8db6-428c-a593-4022e3044c00",
id: TASK_ID_0,
status: "in-progress",
status: "completed",
businessStatus: "Dispatched",
lastModified: "2023-09-11T10:11:12Z"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,35 @@ describe("Unit tests for validation of status against business status", () => {
),
generateTestCase(
"completed",
"Ready to dispatch",
"Completed state indicated for a prescription status requiring patient action."
),
generateTestCase(
"completed",
"Ready to dispatch - partial",
"Completed state indicated for a prescription status requiring patient action."
),
generateTestCase(
"completed",
"rEaDy To DisPAtCh - pArtIAl",
"rEaDy To ColLEcT - pArtIAl",
"Completed state indicated for a prescription status requiring patient action."
),
generateTestCase("in-progress", "With Pharmacy", undefined),
generateTestCase("in-progress", "With Pharmacy - preparing remainder", undefined),
generateTestCase("in-progress", "Ready to collect", undefined),
generateTestCase("in-progress", "Ready to collect - partial", undefined),
generateTestCase(
"in-progress",
"Collected",
"In-progress state indicated for a prescription status that should be completed."
),
generateTestCase(
"in-progress",
"Not dispensed",
"In-progress state indicated for a prescription status that should be completed."
),
generateTestCase(
"in-progress",
"Dispatched",
"In-progress state indicated for a prescription status that should be completed."
),
generateTestCase("completed", "Collected", undefined),
generateTestCase("completed", "Not dispensed", undefined),
generateTestCase("completed", "Dispatched", undefined),
generateTestCase("in-progress", "Ready to dispatch", undefined),
generateTestCase("in-progress", "Ready to dispatch - partial", undefined)
generateTestCase("in-progress", "Ready to dispatch - partial", undefined),
generateTestCase("completed", "Ready to dispatch", undefined),
generateTestCase("completed", "Ready to dispatch - partial", undefined)
]
it.each(testCases)(
"When status is '$taskStatus' and business status is '$businessStatus', should return expected issue.",
Expand Down

0 comments on commit 861b275

Please sign in to comment.