Skip to content

Commit

Permalink
validates status
Browse files Browse the repository at this point in the history
  • Loading branch information
JackSpagnoliNHS committed Aug 27, 2024
1 parent 527b1b7 commit 21b4ff0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
18 changes: 15 additions & 3 deletions packages/updatePrescriptionStatus/src/validation/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const PRESCRIPTION_ID_CODESYSTEM =
export const STATUS_CODESYSTEM =
"https://fhir.nhs.uk/CodeSystem/task-businessStatus-nppt"

const VALID_STATUSES = ["completed", "in-progress"]

const COMPLETED_ONLY_BUSINESS_STATUSES = [
"collected",
"not dispensed",
Expand All @@ -37,9 +39,11 @@ const IN_PROGRESS_ONLY_BUSINESS_STATUSES = [
]
const AGNOSTIC_BUSINESS_STATUSES = ["ready to dispatch", "ready to collect"]

export const BUSINESS_STATUSES = COMPLETED_ONLY_BUSINESS_STATUSES.concat(
IN_PROGRESS_ONLY_BUSINESS_STATUSES
).concat(AGNOSTIC_BUSINESS_STATUSES)
export const BUSINESS_STATUSES = [
...COMPLETED_ONLY_BUSINESS_STATUSES,
...IN_PROGRESS_ONLY_BUSINESS_STATUSES,
...AGNOSTIC_BUSINESS_STATUSES
]
const VALID_COMPLETED_STATUSES = COMPLETED_ONLY_BUSINESS_STATUSES.concat(
AGNOSTIC_BUSINESS_STATUSES
)
Expand Down Expand Up @@ -163,6 +167,13 @@ export function codeSystems(task: Task): string | undefined {
}
}

export function status(task: Task): string | undefined {
const status = task.status
if (!VALID_STATUSES.includes(status)) {
return `Unsupported Task.status '${status}'.`
}
}

export function businessStatus(task: Task): string | undefined {
const code: string = task.businessStatus!.coding![0].code!
if (!BUSINESS_STATUSES.includes(code.toLowerCase())) {
Expand Down Expand Up @@ -200,6 +211,7 @@ export function taskStatusAgainstBusinessStatus(

export function taskContent(task: Task): Array<string> {
const contentValidations: Array<TaskValidation> = [
status,
businessStatus,
lastModified,
nhsNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
ValidationOutcome,
validateContent,
entryContent,
nhsNumberRange
nhsNumberRange,
status
} from "../../src/validation/content"

import {generateInvalidNhsNumbers, generateValidNhsNumbers} from "../utils/nhsNumber"
Expand Down Expand Up @@ -261,6 +262,35 @@ describe("Unit tests for validation of NHS number range", () => {
})
})

describe("Unit tests for validation of status", () => {
it.each([
{
updateStatus: "completed",
expected: undefined,
scenarioDescription:
"When status is 'completed', should return undefined."
},
{
updateStatus: "in-progress",
expected: undefined,
scenarioDescription:
"When status is 'in-progress', should return undefined."
},
{
updateStatus: "rejected",
expected: "Unsupported Task.status 'rejected'.",
scenarioDescription:
"When status is unsupported, should return expected issue."
}
])("$scenarioDescription", async ({updateStatus, expected}) => {
const task = {status: updateStatus}

const actual = status(task as Task)

expect(actual).toEqual(expected)
})
})

describe("Unit tests for validation of status against business status", () => {
describe("When task status is 'completed'", () => {
it.each([
Expand Down

0 comments on commit 21b4ff0

Please sign in to comment.