@claudebernard/node-fhir-mapper 2.2.0 → 2.3.1

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.
package/README.md CHANGED
@@ -51,6 +51,7 @@ Below the list of all mappers currently comprised in this library :
51
51
  - A [**Patient**](https://www.hl7.org/fhir/patient.html#Patient) mapper exported as _patientMapper_.
52
52
  - A [**Medication**](https://www.hl7.org/fhir/medication.html#Medication) mapper exported as _medicationMapper_.
53
53
  - A [**MedicationRequest**](https://www.hl7.org/fhir/medicationrequest.html#MedicationRequest) mapper exported as _medicationRequestMapper_.
54
+ - A [**MedicationStatement**](https://www.hl7.org/fhir/medicationstatement.html#MedicationStatement) mapper exported as _medicationStatementMapper_ (read-only, FHIR → BCB direction only).
54
55
 
55
56
  ## Mappers details
56
57
 
@@ -546,6 +547,68 @@ if (response.result) {
546
547
  }
547
548
  ```
548
549
 
550
+ ### MedicationStatement mapper : functions
551
+
552
+ The medication statement mapper handles conversion of dosage from FHIR MedicationStatement resources to BCB format, focusing purely on dosage conversion.
553
+
554
+ **Read-only.** Unlike the MedicationRequest mapper, this mapper only supports the FHIR → BCB
555
+ reading direction. `MedicationStatement` represents patient-reported automédication (medication
556
+ the patient reports taking on their own initiative, as opposed to a prescriber's order) : this
557
+ library only ever receives such data from an incoming FHIR Bundle, it never constructs a
558
+ `MedicationStatement` as output. There is therefore no `bcbToFhir`, `fhirToCb`, or `cbToFhir`
559
+ function on this mapper.
560
+
561
+ Also note the field name difference from MedicationRequest : FHIR R5 keeps the dosage instructions
562
+ of a MedicationStatement in its **`dosage`** field, not `dosageInstruction`.
563
+
564
+ #### - fhirToBcb
565
+
566
+ ```ts
567
+ async function fhirToBcb(
568
+ bundle: Bundle,
569
+ indicationMapper?: CodificationFunction,
570
+ routeMapper?: CodificationFunction,
571
+ intakeMapper?: CodificationFunction
572
+ ): Promise<MappingResponse<BCBPosologieStructuree2>[]> {}
573
+ ```
574
+
575
+ Extracts and converts the `dosage` field of MedicationStatement resources in a Bundle to BCB format using the dosage-mapper. The 3 optional **CodificationFunction** parameters are forwarded unchanged to the dosage-mapper, exactly as they are for `medicationRequestMapper.fhirToBcb`.
576
+
577
+ ##### Usage
578
+
579
+ ```ts
580
+ import { medicationStatementMapper } from '@claudebernard/fhir-mapper';
581
+
582
+ const bundle = /* FHIR Bundle with MedicationStatement resources */;
583
+ const bcbDosages = await medicationStatementMapper.fhirToBcb(bundle);
584
+
585
+ // Array of BCB dosage mapping responses
586
+ bcbDosages.forEach(response => {
587
+ if (response.result) {
588
+ console.log(response.result.libellePosologie);
589
+ }
590
+ });
591
+ ```
592
+
593
+ #### - extractMedicationCodes / extractSubjectReferences
594
+
595
+ ```ts
596
+ function extractMedicationCodes(bundle: Bundle): string[] {}
597
+ function extractSubjectReferences(bundle: Bundle): string[] {}
598
+ ```
599
+
600
+ Extract, respectively, the medication codes and the subject references carried by the MedicationStatement resources of a Bundle.
601
+
602
+ ##### Usage
603
+
604
+ ```ts
605
+ import { medicationStatementMapper } from '@claudebernard/fhir-mapper';
606
+
607
+ const bundle = /* FHIR Bundle with MedicationStatement resources */;
608
+ const medicationCodes = medicationStatementMapper.extractMedicationCodes(bundle);
609
+ const subjectReferences = medicationStatementMapper.extractSubjectReferences(bundle);
610
+ ```
611
+
549
612
  ## Browser support
550
613
  - [x] Chrome
551
614
  - [x] Firefox
package/dist/index.d.ts CHANGED
@@ -124,7 +124,7 @@ type Coding = {
124
124
  };
125
125
  type CodificationFunction = ((coding: Coding | undefined) => SimpleCodification[] | Promise<SimpleCodification[]>) | undefined;
126
126
 
127
- declare function fhirToBcb$2(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
127
+ declare function fhirToBcb$3(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
128
128
  declare function mapToBcb(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
129
129
  declare function bcbToFhir$2(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Dosage>[];
130
130
  declare function mapToFhir(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Dosage>[];
@@ -152,7 +152,7 @@ declare namespace dosageMapper_d {
152
152
  export {
153
153
  bcbToFhir$2 as bcbToFhir,
154
154
  cbToFhir$1 as cbToFhir,
155
- fhirToBcb$2 as fhirToBcb,
155
+ fhirToBcb$3 as fhirToBcb,
156
156
  fhirToCb$1 as fhirToCb,
157
157
  dosageMapper_d_mapToBcb as mapToBcb,
158
158
  dosageMapper_d_mapToFhir as mapToFhir,
@@ -176,7 +176,7 @@ interface BCBPatient {
176
176
  }
177
177
 
178
178
  declare function bcbToFhir$1(bcbPatient: BCBPatient): MappingResponse<Bundle>;
179
- declare function fhirToBcb$1(fhirBundle: Bundle, allergiesMapper?: CodificationFunction, snomedPathologiesMapper?: CodificationFunction): Promise<MappingResponse<BCBPatient>>;
179
+ declare function fhirToBcb$2(fhirBundle: Bundle, allergiesMapper?: CodificationFunction, snomedPathologiesMapper?: CodificationFunction): Promise<MappingResponse<BCBPatient>>;
180
180
  declare function cbToFhir(cbPatient: CBPatient): MappingResponse<Bundle>;
181
181
  declare function fhirToCb(fhirBundle: Bundle, allergiesMapper?: CodificationFunction, snomedPathologiesMapper?: CodificationFunction): Promise<MappingResponse<CBPatient>>;
182
182
 
@@ -186,7 +186,7 @@ declare namespace patientMapper_d {
186
186
  export {
187
187
  bcbToFhir$1 as bcbToFhir,
188
188
  patientMapper_d_cbToFhir as cbToFhir,
189
- fhirToBcb$1 as fhirToBcb,
189
+ fhirToBcb$2 as fhirToBcb,
190
190
  patientMapper_d_fhirToCb as fhirToCb,
191
191
  };
192
192
  }
@@ -322,7 +322,7 @@ declare const generateMedicationRequestId: (medicationCode?: string, patientId?:
322
322
  * @param bundle Bundle containing MedicationRequest resources
323
323
  * @returns Array of BCB dosage instructions from all MedicationRequest resources
324
324
  */
325
- declare function fhirToBcb(bundle: Bundle): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
325
+ declare function fhirToBcb$1(bundle: Bundle): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
326
326
  /**
327
327
  * Creates a Bundle containing MedicationRequest resources from BCB dosage data.
328
328
  * Uses the dosage-mapper for converting BCB dosage to FHIR dosage instructions.
@@ -335,7 +335,7 @@ declare function bcbToFhir(bcbDosages: BCBPosologieStructuree2[]): MappingRespon
335
335
  * @param bundle Bundle containing MedicationRequest resources
336
336
  * @returns Array of medication codes
337
337
  */
338
- declare function extractMedicationCodes(bundle: Bundle): string[];
338
+ declare function extractMedicationCodes$1(bundle: Bundle): string[];
339
339
  /**
340
340
  * Extracts patient references from MedicationRequest resources in a Bundle.
341
341
  * @param bundle Bundle containing MedicationRequest resources
@@ -344,20 +344,57 @@ declare function extractMedicationCodes(bundle: Bundle): string[];
344
344
  declare function extractPatientReferences(bundle: Bundle): string[];
345
345
 
346
346
  declare const medicationRequestMapper_d_bcbToFhir: typeof bcbToFhir;
347
- declare const medicationRequestMapper_d_extractMedicationCodes: typeof extractMedicationCodes;
348
347
  declare const medicationRequestMapper_d_extractPatientReferences: typeof extractPatientReferences;
349
- declare const medicationRequestMapper_d_fhirToBcb: typeof fhirToBcb;
350
348
  declare const medicationRequestMapper_d_generateMedicationRequestId: typeof generateMedicationRequestId;
351
349
  declare namespace medicationRequestMapper_d {
352
350
  export {
353
351
  medicationRequestMapper_d_bcbToFhir as bcbToFhir,
354
- medicationRequestMapper_d_extractMedicationCodes as extractMedicationCodes,
352
+ extractMedicationCodes$1 as extractMedicationCodes,
355
353
  medicationRequestMapper_d_extractPatientReferences as extractPatientReferences,
356
- medicationRequestMapper_d_fhirToBcb as fhirToBcb,
354
+ fhirToBcb$1 as fhirToBcb,
357
355
  medicationRequestMapper_d_generateMedicationRequestId as generateMedicationRequestId,
358
356
  };
359
357
  }
360
358
 
359
+ /**
360
+ * Converts dosage instructions from MedicationStatement resources in a Bundle to BCB format.
361
+ * Uses the dosage-mapper for `dosage` field conversion (the FHIR R5 field name on
362
+ * MedicationStatement, distinct from MedicationRequest.dosageInstruction).
363
+ *
364
+ * Read-only: MedicationStatement represents patient-reported automédication, which this
365
+ * library only ever receives, never constructs. There is intentionally no `bcbToFhir`,
366
+ * `fhirToCb`, or `cbToFhir` counterpart in this module.
367
+ * @param bundle Bundle containing MedicationStatement resources
368
+ * @param indicationMapper Optional codification mapper for the dosage's indication field
369
+ * @param routeMapper Optional codification mapper for the dosage's route field
370
+ * @param intakeMapper Optional codification mapper for the dosage's intake unit field
371
+ * @returns Array of BCB dosage instructions from all MedicationStatement resources
372
+ */
373
+ declare function fhirToBcb(bundle: Bundle, indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
374
+ /**
375
+ * Extracts medication codes from MedicationStatement resources in a Bundle.
376
+ * @param bundle Bundle containing MedicationStatement resources
377
+ * @returns Array of medication codes
378
+ */
379
+ declare function extractMedicationCodes(bundle: Bundle): string[];
380
+ /**
381
+ * Extracts subject references from MedicationStatement resources in a Bundle.
382
+ * @param bundle Bundle containing MedicationStatement resources
383
+ * @returns Array of subject references
384
+ */
385
+ declare function extractSubjectReferences(bundle: Bundle): string[];
386
+
387
+ declare const medicationStatementMapper_d_extractMedicationCodes: typeof extractMedicationCodes;
388
+ declare const medicationStatementMapper_d_extractSubjectReferences: typeof extractSubjectReferences;
389
+ declare const medicationStatementMapper_d_fhirToBcb: typeof fhirToBcb;
390
+ declare namespace medicationStatementMapper_d {
391
+ export {
392
+ medicationStatementMapper_d_extractMedicationCodes as extractMedicationCodes,
393
+ medicationStatementMapper_d_extractSubjectReferences as extractSubjectReferences,
394
+ medicationStatementMapper_d_fhirToBcb as fhirToBcb,
395
+ };
396
+ }
397
+
361
398
  /**
362
399
  * Simple hash function compatible with both Node.js and browser environments
363
400
  * This replaces the Node.js crypto module to avoid browser compatibility issues
@@ -376,5 +413,5 @@ declare const generateHash: (data: any) => string;
376
413
  */
377
414
  declare const generateUuidV4: () => string;
378
415
 
379
- export { dosageMapper_d as dosageMapper, generateHash, generateUuidV4, medicationMapper_d as medicationMapper, medicationRequestMapper_d as medicationRequestMapper, patientMapper_d as patientMapper, simpleHash };
416
+ export { dosageMapper_d as dosageMapper, generateHash, generateUuidV4, medicationMapper_d as medicationMapper, medicationRequestMapper_d as medicationRequestMapper, medicationStatementMapper_d as medicationStatementMapper, patientMapper_d as patientMapper, simpleHash };
380
417
  export type { CodificationFunction, Coding, MappingError, MappingResponse, SimpleCodification };
package/dist/index.js CHANGED
@@ -309,7 +309,7 @@ async function handleCodifications(dosage, indicationMapper, routeMapper, intake
309
309
  }
310
310
 
311
311
  // adding this function to support new naming convention without breaking changes
312
- async function fhirToBcb$2(dosageInstructions, indicationMapper, routeMapper, intakeMapper) {
312
+ async function fhirToBcb$3(dosageInstructions, indicationMapper, routeMapper, intakeMapper) {
313
313
  return await mapToBcb(dosageInstructions, indicationMapper, routeMapper, intakeMapper);
314
314
  }
315
315
  async function mapToBcb(dosageInstructions, indicationMapper, routeMapper, intakeMapper) {
@@ -474,7 +474,7 @@ function wrapMaybeAsync$1(fn) {
474
474
  */
475
475
  async function fhirToCb$1(dosageInstructions, indicationMapper, routeMapper, intakeMapper) {
476
476
  // First convert FHIR to BCB using existing function
477
- const bcbResults = await fhirToBcb$2(dosageInstructions, indicationMapper, routeMapper, intakeMapper);
477
+ const bcbResults = await fhirToBcb$3(dosageInstructions, indicationMapper, routeMapper, intakeMapper);
478
478
  // Convert each BCB result to CB format
479
479
  const cbResults = [];
480
480
  for (const bcbResult of bcbResults) {
@@ -545,7 +545,7 @@ var dosageMapper = /*#__PURE__*/Object.freeze({
545
545
  __proto__: null,
546
546
  bcbToFhir: bcbToFhir$2,
547
547
  cbToFhir: cbToFhir$1,
548
- fhirToBcb: fhirToBcb$2,
548
+ fhirToBcb: fhirToBcb$3,
549
549
  fhirToCb: fhirToCb$1,
550
550
  mapToBcb: mapToBcb,
551
551
  mapToFhir: mapToFhir
@@ -1306,7 +1306,7 @@ const patientToFhir = (patientData) => {
1306
1306
  function bcbToFhir$1(bcbPatient) {
1307
1307
  return patientToFhir(convertPatient(bcbPatient));
1308
1308
  }
1309
- async function fhirToBcb$1(fhirBundle, allergiesMapper, snomedPathologiesMapper) {
1309
+ async function fhirToBcb$2(fhirBundle, allergiesMapper, snomedPathologiesMapper) {
1310
1310
  if (!fhirBundle || !fhirBundle.entry || fhirBundle.entry.length === 0) {
1311
1311
  return {
1312
1312
  result: undefined,
@@ -1402,7 +1402,7 @@ var patientMapper = /*#__PURE__*/Object.freeze({
1402
1402
  __proto__: null,
1403
1403
  bcbToFhir: bcbToFhir$1,
1404
1404
  cbToFhir: cbToFhir,
1405
- fhirToBcb: fhirToBcb$1,
1405
+ fhirToBcb: fhirToBcb$2,
1406
1406
  fhirToCb: fhirToCb
1407
1407
  });
1408
1408
 
@@ -1760,7 +1760,7 @@ const generateMedicationRequestId = (medicationCode, patientId) => {
1760
1760
  * @param bundle Bundle containing MedicationRequest resources
1761
1761
  * @returns Array of BCB dosage instructions from all MedicationRequest resources
1762
1762
  */
1763
- async function fhirToBcb(bundle) {
1763
+ async function fhirToBcb$1(bundle) {
1764
1764
  const results = [];
1765
1765
  if (!bundle.entry) {
1766
1766
  return [{
@@ -1774,7 +1774,7 @@ async function fhirToBcb(bundle) {
1774
1774
  // Convert dosage instructions using the dosage-mapper
1775
1775
  if (medicationRequest.dosageInstruction && medicationRequest.dosageInstruction.length > 0) {
1776
1776
  try {
1777
- const dosageResults = await fhirToBcb$2(medicationRequest.dosageInstruction);
1777
+ const dosageResults = await fhirToBcb$3(medicationRequest.dosageInstruction);
1778
1778
  results.push(...dosageResults);
1779
1779
  }
1780
1780
  catch (error) {
@@ -1858,7 +1858,7 @@ function bcbToFhir(bcbDosages) {
1858
1858
  * @param bundle Bundle containing MedicationRequest resources
1859
1859
  * @returns Array of medication codes
1860
1860
  */
1861
- function extractMedicationCodes(bundle) {
1861
+ function extractMedicationCodes$1(bundle) {
1862
1862
  const codes = [];
1863
1863
  if (!bundle.entry) {
1864
1864
  return codes;
@@ -1899,11 +1899,106 @@ function extractPatientReferences(bundle) {
1899
1899
  var medicationRequestMapper = /*#__PURE__*/Object.freeze({
1900
1900
  __proto__: null,
1901
1901
  bcbToFhir: bcbToFhir,
1902
- extractMedicationCodes: extractMedicationCodes,
1902
+ extractMedicationCodes: extractMedicationCodes$1,
1903
1903
  extractPatientReferences: extractPatientReferences,
1904
- fhirToBcb: fhirToBcb,
1904
+ fhirToBcb: fhirToBcb$1,
1905
1905
  generateMedicationRequestId: generateMedicationRequestId
1906
1906
  });
1907
1907
 
1908
- export { dosageMapper, generateHash, generateUuidV4, medicationMapper, medicationRequestMapper, patientMapper, simpleHash };
1908
+ /**
1909
+ * Converts dosage instructions from MedicationStatement resources in a Bundle to BCB format.
1910
+ * Uses the dosage-mapper for `dosage` field conversion (the FHIR R5 field name on
1911
+ * MedicationStatement, distinct from MedicationRequest.dosageInstruction).
1912
+ *
1913
+ * Read-only: MedicationStatement represents patient-reported automédication, which this
1914
+ * library only ever receives, never constructs. There is intentionally no `bcbToFhir`,
1915
+ * `fhirToCb`, or `cbToFhir` counterpart in this module.
1916
+ * @param bundle Bundle containing MedicationStatement resources
1917
+ * @param indicationMapper Optional codification mapper for the dosage's indication field
1918
+ * @param routeMapper Optional codification mapper for the dosage's route field
1919
+ * @param intakeMapper Optional codification mapper for the dosage's intake unit field
1920
+ * @returns Array of BCB dosage instructions from all MedicationStatement resources
1921
+ */
1922
+ async function fhirToBcb(bundle, indicationMapper, routeMapper, intakeMapper) {
1923
+ const results = [];
1924
+ if (!bundle.entry) {
1925
+ return [{
1926
+ result: undefined,
1927
+ errors: [{ field: 'bundle.entry', message: 'Bundle has no entries' }]
1928
+ }];
1929
+ }
1930
+ for (const entry of bundle.entry) {
1931
+ if (entry.resource?.resourceType === 'MedicationStatement') {
1932
+ const medicationStatement = entry.resource;
1933
+ // Convert dosage using the dosage-mapper
1934
+ if (medicationStatement.dosage && medicationStatement.dosage.length > 0) {
1935
+ try {
1936
+ const dosageResults = await fhirToBcb$3(medicationStatement.dosage, indicationMapper, routeMapper, intakeMapper);
1937
+ results.push(...dosageResults);
1938
+ }
1939
+ catch (error) {
1940
+ results.push({
1941
+ result: undefined,
1942
+ errors: [{
1943
+ field: 'dosage',
1944
+ message: `Error converting dosage: ${error}`
1945
+ }]
1946
+ });
1947
+ }
1948
+ }
1949
+ }
1950
+ }
1951
+ return results;
1952
+ }
1953
+ /**
1954
+ * Extracts medication codes from MedicationStatement resources in a Bundle.
1955
+ * @param bundle Bundle containing MedicationStatement resources
1956
+ * @returns Array of medication codes
1957
+ */
1958
+ function extractMedicationCodes(bundle) {
1959
+ const codes = [];
1960
+ if (!bundle.entry) {
1961
+ return codes;
1962
+ }
1963
+ for (const entry of bundle.entry) {
1964
+ if (entry.resource?.resourceType === 'MedicationStatement') {
1965
+ const medicationStatement = entry.resource;
1966
+ const medicationCode = medicationStatement.medication?.concept?.coding?.[0]?.code;
1967
+ if (medicationCode) {
1968
+ codes.push(medicationCode);
1969
+ }
1970
+ }
1971
+ }
1972
+ return codes;
1973
+ }
1974
+ /**
1975
+ * Extracts subject references from MedicationStatement resources in a Bundle.
1976
+ * @param bundle Bundle containing MedicationStatement resources
1977
+ * @returns Array of subject references
1978
+ */
1979
+ function extractSubjectReferences(bundle) {
1980
+ const references = [];
1981
+ if (!bundle.entry) {
1982
+ return references;
1983
+ }
1984
+ for (const entry of bundle.entry) {
1985
+ if (entry.resource?.resourceType === 'MedicationStatement') {
1986
+ const medicationStatement = entry.resource;
1987
+ const subjectReference = medicationStatement.subject?.reference;
1988
+ if (subjectReference) {
1989
+ references.push(subjectReference);
1990
+ }
1991
+ }
1992
+ }
1993
+ return references;
1994
+ }
1995
+
1996
+ var medicationStatementMapper = /*#__PURE__*/Object.freeze({
1997
+ __proto__: null,
1998
+ extractMedicationCodes: extractMedicationCodes,
1999
+ extractSubjectReferences: extractSubjectReferences,
2000
+ fhirToBcb: fhirToBcb
2001
+ });
2002
+
2003
+ export { dosageMapper, generateHash, generateUuidV4, medicationMapper, medicationRequestMapper, medicationStatementMapper, patientMapper, simpleHash };
1909
2004
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claudebernard/node-fhir-mapper",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "A simple FHIR / BCB resource mapper to help stay interoperable while still using the Claude Bernard intelligence",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",