1.1.2 • Published 12 months ago

@claudebernard/fhir-mapper v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

@claudebernard/fhir-mapper

This library will be composed of several bidirectional mapping entities between Claude Bernard (alias BCB) interfaces and FHIR specifications.

Each mapper will contain at the very least a fhirToBcb and a bcbToFhir functions, will return a MappingResponse object and is expected to work offline.

interface MappingResponse<T = unknown> {
    result: T | undefined;
    errors?: MappingError[];
}
type MappingError = {
    field: string;
    message: string;
}

Some of those mappers can accept optional CodificationFunction parameters which are meant to provide a way for the user to be able to choose how the mapping between a fhir resource's Coding field and the corresponding Claude Bernard class codification property is done.

Of course, if the value of the respective fields is not provided or if they use the Claude Bernard codification already, those parameters should be omitted.

CodificationFunction type :

type CodificationFunction = ((coding : Coding) => SimpleCodification) | undefined;

type SimpleCodification = {
    code: string;
    label: string;
};

The CodificationFunction type expects a fhir r5 Coding resource as input and a SimpleCodification object as output.

Dependencies

The library uses the @types/fhir lib to gain access to fhir r5 official objects and methods.

Installation

npm install --save @claudebernard/fhir-mapper

Mappers list

Below the list of all mappers currently comprised in this library :

  • A Dosage mapper exported as dosageMapper.
  • A Patient mapper exported as patientMapper.

Mappers details

Dosage mapper : functions

- fhirToBcb

function fhirToBcb(
    dosageInstructions: Dosage[],
    indicationMapper?: CodificationFunction,
    routeMapper?: CodificationFunction,
    intakeMapper?: CodificationFunction
) : MappingResponse<BCBPosologieStructuree2>[] {} 

The function takes 4 parameters :

  • 1 mandatory parameter 'dosageInstructions' which will be the fhir r5 Dosage resources that need to be mapped.
  • 3 optional parameters of type CodificationFunction.

Those optional parameters are meant to be used to map fhir (asNeededFor, route, doseAndRate) fields to (codeIndication, codeVoie, codeUnitePrise) BCBPosologieStructuree2 class properties.

Usage
import { dosageMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const fhirDosages = [];
const routeMapper = (coding : Coding) => {
    // some api call or logic implemented by yourself ...
    return {
        code : routeCode,
        label : routeLabel
    }
}

// ...

const bcbDosages = dosageMapper.fhirToBcb(fhirDosages, undefined, routeMapper, undefined);

// ...

- bcbToFhir

function bcbToFhir(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Dosage>[] {} 

This function takes only one parameter, an array of BCBPosologieStructuree2 objects and returns a MappingResponse containing the corresponding fhir Dosage resources.

It will for now by default keep the Claude Bernard codification for the Coding fields in the output fhir Dosage resources.

Usage
import { dosageMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const bcbDosages = [];

// ...

const fhirDosages = dosageMapper.bcbToFhir(bcbDosages);

// ...

Dosage mapper : current limitations

Even though the mapper works and allows us to transform Dosage resources in Claude Bernard resources, there are some caveats : - some fields are currently unmapped due to a lack of overlap between the two structures.

  • some fields are only partially mapped due to the fact that on one side (fhir) they are arrays and on the other (claude bernard), they are unitary values.

Claude Bernard codifications

Below is listed the different Claude Bernard coding systems or valuesets that will be used internally by the mappers.

Patient mapper : functions

- fhirToBcb

function fhirToBcb(
  fhirPatient: BundleEntry[],
  allergiesMapper?: CodificationFunction,
  snomedPathologiesMapper?: CodificationFunction,
): MappingResponse<BCBPatient> {}

The function takes 3 parameters :

  • 1 mandatory parameter 'fhirPatient' which will be an array of r5 BundleEntry resources that need to be mapped.
  • 2 optional parameters of type CodificationFunction.

Those optional parameters are meant to be used to map fhir (Condition.code.coding, AllergyIntolerance.code.coding) fields to (lstPathologiesAMM, lstIdComposantAllergie) BCBPatient class properties.

Usage
import { patientMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const fhirPatient = [];
const allergiesMapper = (coding : Coding) => {
    // some api call or logic implemented by yourself ...
    return {
        code : allergyCode,
        label : allergyLabel
    }
}

const snomedPathologiesMapper = (coding : Coding) => {
    // some api call or logic implemented by yourself ...
    return {
        code : pathologyCode,
        label : pathologyLabel
    }
}

// ...

const bcbPatient = patientMapper.fhirToBcb(fhirPatient, allergiesMapper, snomedPathologiesMapper);

// ...

- bcbToFhir

function bcbToFhir(
  bcbPatient: BCBPatient,
): MappingResponse<BundleEntry[]> {}

The function takes 1 parameter of type BCBPatient and returns a MappingResponse containing the an array of the corresponding fhir BundleEntry resources.

Usage
import { patientMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const bcbPatient = [];

// ...

const fhirPatient = patientMapper.bcbToFhir(bcbPatient);

// ...

- fhirTocb

function fhirTocb(
  fhirPatient: BundleEntry[],
  allergiesMapper?: CodificationFunction,
  snomedPathologiesMapper?: CodificationFunction,
): MappingResponse<BCBPatient> {}

The function takes 3 parameters :

  • 1 mandatory parameter 'fhirPatient' which will be an array of r5 BundleEntry resources that need to be mapped.
  • 2 optional parameters of type CodificationFunction.

Those optional parameters are meant to be used to map fhir (Condition.code.coding, AllergyIntolerance.code.coding) fields to (lstPathologiesAMM, lstIdComposantAllergie) CBPatient class properties.

Usage
import { patientMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const fhirPatient = [];
const allergiesMapper = (coding : Coding) => {
    // some api call or logic implemented by yourself ...
    return {
        code : allergyCode,
        label : allergyLabel
    }
}

const snomedPathologiesMapper = (coding : Coding) => {
    // some api call or logic implemented by yourself ...
    return {
        code : pathologyCode,
        label : pathologyLabel
    }
}

// ...

const cbPatient = patientMapper.fhirTocb(fhirPatient, allergiesMapper, snomedPathologiesMapper);

// ...

- cbToFhir

function cbToFhir(
  cbPatient: CBPatient,
): MappingResponse<BundleEntry[]> {}

The function takes 1 parameter of type BCBPatient and returns a MappingResponse containing the an array of the corresponding fhir BundleEntry resources.

Usage
import { patientMapper } from '@claudebernard/fhir-mapper';
// other imports ... 

const cbPatient = [];

// ...

const fhirPatient = patientMapper.cbToFhir(cbPatient);

// ...

Browser support

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

License

Copyright of Cegedim. See LICENSE for details.

1.1.2

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago