Skip to content

Commit

Permalink
Fix: [AEA-4142] - 'Ready to collect' cannot be used with 'completed' …
Browse files Browse the repository at this point in the history
…status (#414)

## Summary

- Routine Change

### Details

Updates business status logic to allow 'Ready to collect' business
status to be used with 'completed' status
  • Loading branch information
JackSpagnoliNHS authored Jun 20, 2024
1 parent ab2fa7e commit a2276dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
34 changes: 22 additions & 12 deletions packages/updatePrescriptionStatus/src/validation/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export const ODS_CODE_CODESYSTEM = "https://fhir.nhs.uk/Id/ods-organization-code
export const PRESCRIPTION_ID_CODESYSTEM = "https://fhir.nhs.uk/Id/prescription-order-number"
export const STATUS_CODESYSTEM = "https://fhir.nhs.uk/CodeSystem/task-businessStatus-nppt"

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

export const IN_PROGRESS_BUSINESS_STATUSES = [
const COMPLETED_ONLY_BUSINESS_STATUSES = ["collected", "not dispensed", "dispatched"]
const IN_PROGRESS_ONLY_BUSINESS_STATUSES = [
"with pharmacy",
"with pharmacy - preparing remainder",
"ready to collect",
"ready to collect - partial"
]
const AGNOSTIC_BUSINESS_STATUSES = ["ready to dispatch", "ready to dispatch - partial", "ready to collect"]

export const BUSINESS_STATUSES = COMPLETED_BUSINESS_STATUSES.concat(IN_PROGRESS_BUSINESS_STATUSES, [
"ready to dispatch",
"ready to dispatch - partial"
])
export const BUSINESS_STATUSES = COMPLETED_ONLY_BUSINESS_STATUSES.concat(IN_PROGRESS_ONLY_BUSINESS_STATUSES).concat(
AGNOSTIC_BUSINESS_STATUSES
)
const VALID_COMPLETED_STATUSES = COMPLETED_ONLY_BUSINESS_STATUSES.concat(AGNOSTIC_BUSINESS_STATUSES)
const VALID_IN_PROGRESS_STATUSES = IN_PROGRESS_ONLY_BUSINESS_STATUSES.concat(AGNOSTIC_BUSINESS_STATUSES)

export function transactionBundle(body: any): boolean {
return body.resourceType === "Bundle" && body.type === "transaction"
Expand Down Expand Up @@ -112,13 +112,23 @@ export function statuses(task: Task): string | undefined {
const status = task.status
const businessStatus: string = task.businessStatus!.coding![0].code!
const lowercaseCode = businessStatus.toLowerCase()
if (status === "completed" && IN_PROGRESS_BUSINESS_STATUSES.includes(lowercaseCode)) {

const validStatus = BUSINESS_STATUSES.includes(lowercaseCode)
if (!validStatus) {
return `Unsupported Task.businessStatus '${businessStatus}'.`
}

const validCompleteStatus = VALID_COMPLETED_STATUSES.includes(lowercaseCode)
if (status === "completed" && !validCompleteStatus) {
return `Task.status field set to '${status}' but Task.businessStatus value of '${businessStatus}' requires follow up action.`
} else if (status === "in-progress" && COMPLETED_BUSINESS_STATUSES.includes(lowercaseCode)) {
}

const validInProgressStatus = VALID_IN_PROGRESS_STATUSES.includes(lowercaseCode)
if (status === "in-progress" && !validInProgressStatus) {
return `Task.status field set to '${status}' but Task.businessStatus value of '${businessStatus}' has no possible follow up action.`
} else if (!BUSINESS_STATUSES.includes(lowercaseCode)) {
return `Unsupported Task.businessStatus '${businessStatus}'.`
}

return undefined
}

export function taskContent(task: Task): Array<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ describe("Unit tests for validation of status against business status", () => {
it.each([
{isValid: false, businessStatus: "With Pharmacy"},
{isValid: false, businessStatus: "With Pharmacy - preparing remainder"},
{isValid: false, businessStatus: "Ready to collect"},
{isValid: false, businessStatus: "ReAdY tO cOlLeCt"},
{isValid: false, businessStatus: "Ready to collect - partial"},
{isValid: false, businessStatus: "rEaDy To ColLEcT - pArtIAl"},
{isValid: true, businessStatus: "Ready to collect"},
{isValid: true, businessStatus: "ReAdY tO cOlLeCt"},
{isValid: true, businessStatus: "Collected"},
{isValid: true, businessStatus: "Not dispensed"},
{isValid: true, businessStatus: "Dispatched"},
Expand Down

0 comments on commit a2276dc

Please sign in to comment.