npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@claudebernard/fhir-mapper

v2.2.1

Published

A simple FHIR / BCB resource mapper to help stay interoperable while still using the Claude Bernard intelligence

Readme

@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 as long as the codification mappers you provide don't call any APIs.

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[] | Promise<SimpleCodification[]>) | undefined;

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

The CodificationFunction type expects a fhir r5 Coding resource as input and must return an array of SimpleCodification objects (or a Promise resolving to such an array). This allows you to use either synchronous or asynchronous logic (e.g., API calls) in your codification mappers. If your codification will map to a single value, return a single-element array. If no mapping is found, return an empty array.

Note: All mapping functions that accept a CodificationFunction (such as fhirToBcb, fhirToCb etc.) are now asynchronous and must be called with await or handled as Promises, even if your mappers are synchronous.

Dependencies

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

Peer Dependencies

The library uses the @claudebernard/types lib for common object structures used by other Claude Bernard tools and apps.

Installation

npm install --save @claudebernard/fhir-mapper

Mappers list

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

Mappers details

Dosage mapper : functions

- fhirToBcb

async function fhirToBcb(
    dosageInstructions: Dosage[],
    indicationMapper?: CodificationFunction,
    routeMapper?: CodificationFunction,
    intakeMapper?: CodificationFunction
): Promise<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 = [];

// synchronous codification mapper
const routeMapper = (coding : Coding) => {
    // some logic implemented by yourself ...
    return {
        code : routeCode,
        label : routeLabel
    }
}

// asynchronous codification mapper
const indicationMapper = async (coding: Coding) => {
    // await someApiCall(coding)
    return {
        code: routeCode,
        label: routeLabel
    }
}

// ...

const bcbDosages = await dosageMapper.fhirToBcb(fhirDosages, indicationMapper, 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);

// ...

- fhirToCb

async function fhirToCb(dosageInstructions: Dosage[]): Promise<MappingResponse<CBPosologyBean>[]> {}

Converts FHIR Dosage instructions to CB (Claude Bernard) Posology Bean format. This function uses the existing fhirToBcb conversion and then transforms the result to CB format.

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

const fhirDosages = /* array of FHIR Dosage instructions */;
const cbResults = await dosageMapper.fhirToCb(fhirDosages);

cbResults.forEach(response => {
    if (response.result) {
        console.log(response.result.posologyLabel);
    }
});

- cbToFhir

function cbToFhir(cbPosologies: CBPosologyBean[]): MappingResponse<Dosage>[] {}

Converts CB Posology Bean format to FHIR Dosage instructions. This function transforms CB format to BCB format and then uses the existing bcbToFhir conversion.

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

const cbPosologies = /* array of CBPosologyBean */;
const fhirResults = dosageMapper.cbToFhir(cbPosologies);

fhirResults.forEach(response => {
    if (response.result) {
        console.log(response.result.text);
    }
});

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.

  • https://platform.claudebernard.fr/fhir/ImplementationGuides/ValueSet/routes
  • https://platform.claudebernard.fr/fhir/ImplementationGuides/ValueSet/intake-units
  • https://platform.claudebernard.fr/fhir/ImplementationGuides/ValueSet/indications
  • https://platform.claudebernard.fr/fhir/ImplementationGuides/ValueSet/amm

Patient mapper : functions

- fhirToBcb

async function fhirToBcb(
  fhirPatient: BundleEntry[],
  allergiesMapper?: CodificationFunction,
  snomedPathologiesMapper?: CodificationFunction,
): Promise<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 logic implemented by yourself ...
    return [
        {
            code : allergyCode,
            label : allergyLabel
        }
    ];
}

const snomedPathologiesMapper = async (coding : Coding) => {
    // await someApiCall(coding)
    return [
        {
            code : pathologyCode,
            label : pathologyLabel
        }
    ];
}

// ...

const bcbPatient = await 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

async function fhirTocb(
  fhirPatient: BundleEntry[],
  allergiesMapper?: CodificationFunction,
  snomedPathologiesMapper?: CodificationFunction,
): Promise<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 = await 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);

// ...

Medication mapper : functions

The medication mapper provides utilities for creating and extracting medication codes from FHIR Bundle resources. It supports BCB codes, CIP13 codes, and CIS codes.

- createMedicationsFromBcbCodes

function createMedicationsFromBcbCodes(codes: string[]): MappingResponse<Bundle> {}

Creates a FHIR Bundle containing Medication resources from BCB codes.

Usage
import { medicationMapper } from '@claudebernard/fhir-mapper';

const bcbCodes = ['BCB001', 'BCB002', 'BCB003'];
const response = medicationMapper.createMedicationsFromBcbCodes(bcbCodes);

if (response.result) {
    // Bundle with Medication resources
    console.log(response.result.entry?.length); // 3 medications
}

- createMedicationsFromCIP13Codes / createMedicationsFromCISCodes

function createMedicationsFromCIP13Codes(codes: string[]): MappingResponse<Bundle> {}
function createMedicationsFromCISCodes(codes: string[]): MappingResponse<Bundle> {}

Similar functions for creating medications from CIP13 and CIS codes respectively.

- extractBcbCodesFromMedications / extractCIP13CodesFromMedications / extractCISCodesFromMedications

function extractBcbCodesFromMedications(bundle: Bundle): string[] {}
function extractCIP13CodesFromMedications(bundle: Bundle): string[] {}
function extractCISCodesFromMedications(bundle: Bundle): string[] {}

Extract specific types of medication codes from a FHIR Bundle containing Medication resources.

Usage
import { medicationMapper } from '@claudebernard/fhir-mapper';

const bundle = /* your FHIR Bundle */;
const bcbCodes = medicationMapper.extractBcbCodesFromMedications(bundle);
const cip13Codes = medicationMapper.extractCIP13CodesFromMedications(bundle);

MedicationRequest mapper : functions

The medication request mapper handles conversion of dosage instructions between FHIR MedicationRequest resources and BCB format, focusing purely on dosage conversion.

- fhirToBcb

async function fhirToBcb(bundle: Bundle): Promise<MappingResponse<BCBPosologieStructuree2>[]> {}

Extracts and converts dosage instructions from MedicationRequest resources in a Bundle to BCB format using the dosage-mapper.

Usage
import { medicationRequestMapper } from '@claudebernard/fhir-mapper';

const bundle = /* FHIR Bundle with MedicationRequest resources */;
const bcbDosages = await medicationRequestMapper.fhirToBcb(bundle);

// Array of BCB dosage mapping responses
bcbDosages.forEach(response => {
    if (response.result) {
        console.log(response.result.libellePosologie);
    }
});

- bcbToFhir

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

Creates a FHIR Bundle with a MedicationRequest resource containing the converted dosage instructions from BCB format.

Usage
import { medicationRequestMapper } from '@claudebernard/fhir-mapper';

const bcbDosages = /* array of BCBPosologieStructuree2 */;
const response = medicationRequestMapper.bcbToFhir(bcbDosages);

if (response.result) {
    // Bundle with MedicationRequest containing converted dosage instructions
    const medReq = response.result.entry?.[0]?.resource as MedicationRequest;
    console.log(medReq.dosageInstruction?.length);
}

Browser support

  • [x] Chrome
  • [x] Firefox
  • [x] Safari
  • [x] Microsoft Edge

License

Copyright of Cegedim. See LICENSE for details.