@claudebernard/web-component-fhir-utils 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { BundleEntry, MedicationRequest } from "fhir/r5";
|
|
2
2
|
import { PriorPrescriptionReason } from "../constants/prior-prescription.const";
|
|
3
|
+
/**
|
|
4
|
+
* Builds the `priorPrescription` field housing both the link back to the previous
|
|
5
|
+
* MedicationRequest and the `prior-prescription-reason` extension recording why it was
|
|
6
|
+
* superseded/modified. The single home for this shape, so consumers linking to an already-existing
|
|
7
|
+
* `priorPrescription.reference` (e.g. updating a MedicationRequest in place instead of superseding
|
|
8
|
+
* it again) stay in sync with `supersedeMedicationRequest` below.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildPriorPrescription(reference: string, reason: PriorPrescriptionReason): NonNullable<MedicationRequest["priorPrescription"]>;
|
|
3
11
|
/**
|
|
4
12
|
* Checks whether a MedicationRequest is the result of a supersession for a
|
|
5
13
|
* given reason (e.g. a dosage override, or a therapeutic-alternative swap),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supersede-resource.d.ts","sourceRoot":"","sources":["../../src/bundle/supersede-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAiC,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAG/G;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACvD,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACnC,MAAM,EAAE,uBAAuB,GAC9B,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"supersede-resource.d.ts","sourceRoot":"","sources":["../../src/bundle/supersede-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAiC,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAG/G;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,GAAG,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAK9I;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACvD,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACnC,MAAM,EAAE,uBAAuB,GAC9B,WAAW,EAAE,CAmBf"}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { PRIOR_PRESCRIPTION_REASON_URL } from "../constants/prior-prescription.const";
|
|
2
2
|
import { createBundleEntry } from "./create-transaction-bundle";
|
|
3
|
+
/**
|
|
4
|
+
* Builds the `priorPrescription` field housing both the link back to the previous
|
|
5
|
+
* MedicationRequest and the `prior-prescription-reason` extension recording why it was
|
|
6
|
+
* superseded/modified. The single home for this shape, so consumers linking to an already-existing
|
|
7
|
+
* `priorPrescription.reference` (e.g. updating a MedicationRequest in place instead of superseding
|
|
8
|
+
* it again) stay in sync with `supersedeMedicationRequest` below.
|
|
9
|
+
*/
|
|
10
|
+
export function buildPriorPrescription(reference, reason) {
|
|
11
|
+
return {
|
|
12
|
+
reference,
|
|
13
|
+
extension: [{ url: PRIOR_PRESCRIPTION_REASON_URL, valueCode: reason }],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
3
16
|
/**
|
|
4
17
|
* Checks whether a MedicationRequest is the result of a supersession for a
|
|
5
18
|
* given reason (e.g. a dosage override, or a therapeutic-alternative swap),
|
|
@@ -28,10 +41,7 @@ export function supersedeMedicationRequest(original, changes, reason) {
|
|
|
28
41
|
...changes,
|
|
29
42
|
id: crypto.randomUUID(),
|
|
30
43
|
status: "active",
|
|
31
|
-
priorPrescription: {
|
|
32
|
-
reference: `MedicationRequest/${original.id}`,
|
|
33
|
-
extension: [{ url: PRIOR_PRESCRIPTION_REASON_URL, valueCode: reason }],
|
|
34
|
-
},
|
|
44
|
+
priorPrescription: buildPriorPrescription(`MedicationRequest/${original.id}`, reason),
|
|
35
45
|
};
|
|
36
46
|
return [
|
|
37
47
|
createBundleEntry(onHoldOriginal, "PUT"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supersede-resource.js","sourceRoot":"","sources":["../../src/bundle/supersede-resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAA2B,MAAM,uCAAuC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,iBAAuD,EACvD,MAA+B;IAE/B,MAAM,SAAS,GAAG,iBAAiB,EAAE,iBAAiB,EAAE,SAAS,EAAE,IAAI,CACrE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,6BAA6B,CACjD,CAAC;IACF,OAAO,SAAS,EAAE,SAAS,KAAK,MAAM,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAA2B,EAC3B,OAAmC,EACnC,MAA+B;IAE/B,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC5F,CAAC;IAED,MAAM,cAAc,GAAsB,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,SA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E,MAAM,CAAC,UAAU,EAAE;QACvB,MAAM,EAAE,QAAQ;QAChB,iBAAiB,EAAE,sBAAsB,CAAC,qBAAqB,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC;KACtF,CAAC;IAEF,OAAO;QACL,iBAAiB,CAAC,cAAc,EAAE,KAAK,CAAC;QACxC,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleEntry, MedicationRequest } from \"fhir/r5\";\nimport { PRIOR_PRESCRIPTION_REASON_URL, PriorPrescriptionReason } from \"../constants/prior-prescription.const\";\nimport { createBundleEntry } from \"./create-transaction-bundle\";\n\n/**\n * Builds the `priorPrescription` field housing both the link back to the previous\n * MedicationRequest and the `prior-prescription-reason` extension recording why it was\n * superseded/modified. The single home for this shape, so consumers linking to an already-existing\n * `priorPrescription.reference` (e.g. updating a MedicationRequest in place instead of superseding\n * it again) stay in sync with `supersedeMedicationRequest` below.\n */\nexport function buildPriorPrescription(reference: string, reason: PriorPrescriptionReason): NonNullable<MedicationRequest[\"priorPrescription\"]> {\n return {\n reference,\n extension: [{ url: PRIOR_PRESCRIPTION_REASON_URL, valueCode: reason }],\n };\n}\n\n/**\n * Checks whether a MedicationRequest is the result of a supersession for a\n * given reason (e.g. a dosage override, or a therapeutic-alternative swap),\n * as tagged by `supersedeMedicationRequest`.\n */\nexport function hasPriorPrescriptionReason(\n medicationRequest: MedicationRequest | null | undefined,\n reason: PriorPrescriptionReason,\n): boolean {\n const extension = medicationRequest?.priorPrescription?.extension?.find(\n ext => ext.url === PRIOR_PRESCRIPTION_REASON_URL,\n );\n return extension?.valueCode === reason;\n}\n\n/**\n * Standard house pattern for representing \"this MedicationRequest replaces\n * that one\" as a transaction Bundle diff: the original is put `on-hold` via\n * PUT, and a new `active` MedicationRequest is created via POST, linked back\n * through `priorPrescription` and tagged with why via the\n * `prior-prescription-reason` extension.\n *\n * Returns the two entries ready to hand to `createTransactionBundle`.\n */\nexport function supersedeMedicationRequest(\n original: MedicationRequest,\n changes: Partial<MedicationRequest>,\n reason: PriorPrescriptionReason,\n): BundleEntry[] {\n if (!original.id) {\n throw new Error(\"supersedeMedicationRequest: original MedicationRequest must have an id\");\n }\n\n const onHoldOriginal: MedicationRequest = { ...original, status: \"on-hold\" };\n\n const superseding: MedicationRequest = {\n ...structuredClone(original),\n ...changes,\n id: crypto.randomUUID(),\n status: \"active\",\n priorPrescription: buildPriorPrescription(`MedicationRequest/${original.id}`, reason),\n };\n\n return [\n createBundleEntry(onHoldOriginal, \"PUT\"),\n createBundleEntry(superseding, \"POST\"),\n ];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claudebernard/web-component-fhir-utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Shared FHIR Bundle utilities (collection/transaction bundles, prior-prescription linking) for Claude Bernard web components and their integrators.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|