This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: mask nric * fix: lint * chore: code review * chore: reuse existing types Co-authored-by: Kyle Huang Junyuan <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,382 additions
and
1,298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { R4 } from "@ahryman40k/ts-fhir-types"; | ||
import { fhirBundleV1, Patient } from "../types"; | ||
import { maskNricInFhirBundleV1, maskNricInFhirBundle } from "./maskNricFin"; | ||
import pdtUnwrappedSampleV1 from "../../test/fixtures/v1/example_healthcert_with_nric_unwrapped.json"; | ||
import pdtUnwrappedSampleV2 from "../../test/fixtures/v2/pdt_pcr_with_nric_unwrapped.json"; | ||
|
||
describe("test maskNricFinInPlace function", () => { | ||
it("nric should be masked for V1 Healthcert", () => { | ||
const { fhirBundle } = pdtUnwrappedSampleV1; | ||
|
||
const maskedFhirBundle = maskNricInFhirBundleV1(fhirBundle as any); | ||
const patient = (maskedFhirBundle as fhirBundleV1).entry.find( | ||
(entry) => entry.resourceType === "Patient" | ||
); | ||
const nricIdentifier = (patient as Patient).identifier.find( | ||
(i) => i.type !== "PPN" && i.type.text.toUpperCase() === "NRIC" | ||
); | ||
|
||
expect(fhirBundle).not.toEqual(maskNricInFhirBundle); | ||
expect(nricIdentifier?.value).toStrictEqual("S****989Z"); | ||
}); | ||
|
||
it("nric should be masked for V2 Healthcert", () => { | ||
const { fhirBundle } = pdtUnwrappedSampleV2; | ||
|
||
const maskedFhirBundle = maskNricInFhirBundle(fhirBundle as any); | ||
const patient = (maskedFhirBundle as R4.IBundle).entry?.find( | ||
(entry: any) => entry?.resource?.resourceType === "Patient" | ||
)?.resource as R4.IPatient; | ||
const nricIdentifier = patient.identifier?.find( | ||
(i) => i.id?.toUpperCase() === "NRIC-FIN" | ||
); | ||
|
||
expect(fhirBundle).not.toEqual(maskNricInFhirBundle); | ||
expect(nricIdentifier?.value).toStrictEqual("S****989Z"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { R4 } from "@ahryman40k/ts-fhir-types"; | ||
import { fhirBundleV1, Patient, PDTHealthCertV2 } from "../types"; | ||
|
||
// Get the reference to the nested nric identifier object | ||
// mask the value in place | ||
|
||
const maskNric = (nric: string) => `${nric[0]}****${nric.slice(5)}`; | ||
|
||
/** | ||
* @deprecated This function should be removed when PDT HealthCert v1.0 is deprecated. | ||
*/ | ||
export const maskNricInFhirBundleV1 = ( | ||
fhirBundle: fhirBundleV1 | R4.IBundle | ||
) => { | ||
const patient = (fhirBundle as fhirBundleV1).entry.find( | ||
(entry) => entry.resourceType === "Patient" | ||
); | ||
const nricIdentifier = (patient as Patient).identifier.find( | ||
(i) => i.type !== "PPN" && i.type.text.toUpperCase() === "NRIC" | ||
); | ||
|
||
// Mask NRIC by reference | ||
if (nricIdentifier?.value) | ||
nricIdentifier.value = maskNric(nricIdentifier.value); | ||
|
||
return fhirBundle; | ||
}; | ||
|
||
export const maskNricInFhirBundle = ( | ||
fhirBundle: PDTHealthCertV2["fhirBundle"] | ||
) => { | ||
// PDTHealthCertV2["fhirBundle"] and R4.IBundle can be used interchangeably | ||
const patient = (fhirBundle as R4.IBundle).entry?.find( | ||
(entry: any) => entry?.resource?.resourceType === "Patient" | ||
)?.resource as R4.IPatient; | ||
const nricIdentifier = patient.identifier?.find( | ||
(i) => i.id?.toUpperCase() === "NRIC-FIN" | ||
); | ||
|
||
// Mask NRIC by reference | ||
if (nricIdentifier?.value) | ||
nricIdentifier.value = maskNric(nricIdentifier.value); | ||
|
||
return fhirBundle; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
926 changes: 463 additions & 463 deletions
926
src/models/notarizedHealthCert/createNotarizedHealthCert/createUnwrappedHealthCert.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,658 changes: 829 additions & 829 deletions
1,658
src/models/notarizedHealthCertV2/createNotarizedHealthCert/createUnwrappedHealthCert.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters