Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: [AEA-4190] - Reject Scottish and NI NHS numbers #515

Merged
merged 7 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"python.analysis.extraPaths": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": false,
"pylint.enabled": false,
originalphil marked this conversation as resolved.
Show resolved Hide resolved
"python.linting.flake8Enabled": true,
"python.linting.enabled": true, // required to format on save
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint",
Expand Down
18 changes: 18 additions & 0 deletions .vscode/eps-prescription-status-update-api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@
"Codeable",
"codeinline",
"codesystem",
"cpsu",
"dbaeumer",
"devcontainer",
"direnv",
"eamodio",
"eps-prescription-status-update-api",
"esbuild",
"excelviewer",
"fhir",
"Formik",
"Fulfillment",
Expand All @@ -78,34 +83,47 @@
"Helpdesk",
"homecare",
"HSCN",
"kohler",
"liter",
"mermade",
"milliliter",
"mkhl",
"nHSCHI",
"NHSD",
"nhsdlogin",
"NHSE",
"nhslogin",
"NOSONAR",
"OIDC",
"openapi",
"orta",
"Orthoptist",
"Payor",
"pino",
"pollable",
"powertools",
"pratica",
"Prosthetist",
"pylint",
"pytest",
"querystring",
"reingest",
"reingested",
"Reingestion",
"rvest",
"serialisation",
"shellcheck",
"smartcard",
"smartcards",
"Snomed",
"sourcetype",
"timonwong",
"Truststore",
"URID",
"URPID",
"uuidv4",
"vars",
"venv",
"versionable",
"whens"
],
Expand Down
30 changes: 30 additions & 0 deletions packages/updatePrescriptionStatus/src/validation/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ export function nhsNumber(task: Task): string | undefined {
return validateNhsNumber(nhsNumber) ? undefined : message
}

export function nhsNumberRange(task: Task): string | undefined {
type Range = {low: number; high: number; description?: string}

const validRanges: Array<Range> = [
{low: 3_113_000_000, high: 3_200_000_000},
{low: 4_000_000_000, high: 4_999_999_999},
{low: 6_000_000_000, high: 7_999_999_999}
]

const nhsNumber = Number(task.for!.identifier!.value)
for (const range of validRanges) {
if (range.low <= nhsNumber && nhsNumber <= range.high) {
return undefined
}
}

const invalidRanges: Array<Range> = [
{low: 101_000_000, high: 3_112_999_999, description: "Scottish"},
{low: 3_200_000_001, high: 3_999_999_999, description: "Northern Irish"}
]

for (const range of invalidRanges) {
if (range.low <= nhsNumber && nhsNumber <= range.high) {
return `NHS number is in the ${range.description} range.`
}
}

return "NHS number is not in a known, valid range."
}

export function resourceType(task: Task): string | undefined {
const message = "Resource's resourceType is not 'Task'."
const isTask = task.resourceType === "Task"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
validateEntry,
ValidationOutcome,
validateContent,
entryContent
entryContent,
nhsNumberRange
} from "../../src/validation/content"

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

describe("Unit tests for validation of NHS number range", () => {
it.each([
{
nhsNumbers: ["0101000000", "3112999999"],
expected: "NHS number is in the Scottish range.",
scenarioDescription: "When NHS number is in the Scottish range, should return expected issue."
},
{
nhsNumbers: ["3200000001", "3999999999"],
expected: "NHS number is in the Northern Irish range.",
scenarioDescription: "When NHS number is in the Northern Irish range, should return expected issue."
},
{
nhsNumbers: ["3113000000", "3200000000", "4000000000", "4999999999", "6000000000", "7999999999"],
expected: undefined,
scenarioDescription: "When NHS number is in the NHSE range."
}
])("$scenarioDescription", async ({nhsNumbers, expected}) => {
for (const _nhsNumber of nhsNumbers) {
const task = {for: {identifier: {value: _nhsNumber}}}

const actual = nhsNumberRange(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