@claudebernard/fhir-mapper
Version:
A simple FHIR / BCB resource mapper to help stay interoperable while still using the Claude Bernard intelligence
328 lines (313 loc) • 14.2 kB
TypeScript
import { Dosage, Bundle } from 'fhir/r5';
import { CBPatient } from '@claudebernard/types';
interface BCBPosologieStructuree2 {
adequationUP?: number | null;
codeDuree1?: number | null;
codeDuree2?: number | null;
codeDuree3?: number | null;
codeIndication?: string | null;
codeMoment?: number | null;
codeNature?: number | null;
codePar?: string | null;
codeProfil?: number | null;
codeSpecifPrise1?: number | null;
codeSpecifPrise2?: number | null;
codeTerrain?: number | null;
codeUnitePrise?: number | null;
codeVoie?: number | null;
coeffMoment?: number | null;
combien1?: number | null;
combien2?: number | null;
idProduit?: number | null;
implicite?: number | null;
libDuree1?: string | null;
libDuree2?: string | null;
libDuree3?: string | null;
libIndication?: string | null;
libSpecifPrise1?: string | null;
libUnitePrise?: string | null;
libVoie?: string | null;
libellePosologie?: string | null;
maximum?: number | null;
maximumPoids?: number | null;
nbUnites?: number | null;
noPosologie?: number | null;
parKilo?: number | null;
pendant1?: number | null;
pendant2?: number | null;
quantite1?: number | null;
quantite2?: number | null;
tousLes?: number | null;
}
/**
* CB Posology Bean interface representing posology information
* Converted from Java PosologyBean class to TypeScript interface
*/
interface CBPosologyBean {
adequacy?: number;
biologicalCriterion?: string;
biologicalValue?: string;
byCode?: string;
code?: number;
comment?: string;
decodedPosology?: string;
duration1Code?: number;
duration1Label?: string;
duration1PluralLabel?: string;
duration2Code?: number;
duration2Label?: string;
duration2PluralLabel?: string;
duration3Code?: number;
duration3Label?: string;
duration3PluralLabel?: string;
during1?: number;
during2?: number;
every?: number;
howMuch1?: number;
howMuch2?: number;
implicit?: number;
indicationCode?: string;
indicationLabel?: string;
intakeHours?: string;
intakeSpecification1Code?: number;
intakeSpecification1Label?: string;
intakeSpecification2Code?: number;
intakeSpecification2Label?: string;
intakeUnitCode?: number;
intakeUnitLabel?: string;
maximum?: number;
momentCode?: number;
momentCoeff?: number;
momentLabel?: string;
numberOfUnits?: number;
patientGround?: string;
patientGroundAge1?: string;
patientGroundAge2?: string;
patientGroundCode?: number;
patientGroundLabel?: string;
patientGroundWeight1?: number;
patientGroundWeight2?: number;
patientPosology?: number;
perKilo?: number;
posologyLabel?: string;
productId?: number;
profilCode?: number;
profilLabel?: string;
quantity1?: number;
quantity2?: number;
routeCode?: number;
routeLabel?: string;
typeCode?: number;
typeLabel?: string;
weightMaximum?: number;
}
type MappingError = {
field: string;
message: string;
};
interface MappingResponse<T = unknown> {
result: T | undefined;
errors?: MappingError[];
}
type SimpleCodification = {
type?: string;
code: string;
label: string;
};
type Coding = {
system?: string;
code?: string;
display?: string;
};
type CodificationFunction = ((coding: Coding | undefined) => SimpleCodification[] | Promise<SimpleCodification[]>) | undefined;
declare function fhirToBcb$2(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
declare function mapToBcb(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
declare function bcbToFhir$2(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Dosage>[];
declare function mapToFhir(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Dosage>[];
/**
* Converts FHIR Dosage instructions to CB Posology Bean format.
* Uses the existing fhirToBcb function and then converts BCB to CB format.
* @param dosageInstructions Array of FHIR Dosage resources
* @param indicationMapper Optional mapper function for indication codes
* @param routeMapper Optional mapper function for route codes
* @param intakeMapper Optional mapper function for intake codes
* @returns Promise of array of CB Posology Beans with mapping responses
*/
declare function fhirToCb$1(dosageInstructions: Dosage[], indicationMapper?: CodificationFunction, routeMapper?: CodificationFunction, intakeMapper?: CodificationFunction): Promise<MappingResponse<CBPosologyBean>[]>;
/**
* Converts CB Posology Bean format to FHIR Dosage instructions.
* Converts CB to BCB format first, then uses existing bcbToFhir function.
* @param cbPosologies Array of CB Posology Beans
* @returns Array of FHIR Dosage resources with mapping responses
*/
declare function cbToFhir$1(cbPosologies: CBPosologyBean[]): MappingResponse<Dosage>[];
declare const dosageMapper_d_mapToBcb: typeof mapToBcb;
declare const dosageMapper_d_mapToFhir: typeof mapToFhir;
declare namespace dosageMapper_d {
export {
bcbToFhir$2 as bcbToFhir,
cbToFhir$1 as cbToFhir,
fhirToBcb$2 as fhirToBcb,
fhirToCb$1 as fhirToCb,
dosageMapper_d_mapToBcb as mapToBcb,
dosageMapper_d_mapToFhir as mapToFhir,
};
}
interface BCBPatient {
lstIdComposantAllergie: number[];
lstPathologiesCIM10: string[];
lstPathologiesAMM: string[];
age: number;
poids: number;
taille: number;
grossesse: number;
allaitement: number;
sexe: string;
clairanceCreatinine: number;
creatininemieMol: number;
creatininemieMg: number;
insuffisanceHepatique: string;
}
declare function bcbToFhir$1(bcbPatient: BCBPatient): MappingResponse<Bundle>;
declare function fhirToBcb$1(fhirBundle: Bundle, allergiesMapper?: CodificationFunction, snomedPathologiesMapper?: CodificationFunction): Promise<MappingResponse<BCBPatient>>;
declare function cbToFhir(cbPatient: CBPatient): MappingResponse<Bundle>;
declare function fhirToCb(fhirBundle: Bundle, allergiesMapper?: CodificationFunction, snomedPathologiesMapper?: CodificationFunction): Promise<MappingResponse<CBPatient>>;
declare const patientMapper_d_cbToFhir: typeof cbToFhir;
declare const patientMapper_d_fhirToCb: typeof fhirToCb;
declare namespace patientMapper_d {
export {
bcbToFhir$1 as bcbToFhir,
patientMapper_d_cbToFhir as cbToFhir,
fhirToBcb$1 as fhirToBcb,
patientMapper_d_fhirToCb as fhirToCb,
};
}
/**
* Generate a hash-based ID for a medication based on its codes
*/
declare const generateMedicationId: (codes: string[], system: string) => string;
/**
* Extracts a list of codes from a Bundle containing Medication resources based on the specified system.
* @param bundle Bundle containing Medication resources to extract codes from
* @param system The coding system to filter by
* @returns List of codes that match the specified system
*/
declare function extractCodesFromMedications(bundle: Bundle, system: string): string[];
/**
* Extracts a list of bcb-code strings from a Bundle containing Medication resources.
* Only codes with system "https://platform.claudebernard.fr/fhir/CodeSystem/bcb-code" are included.
* @param bundle Bundle containing Medication resources
* @returns List of BCB codes
*/
declare function extractBcbCodesFromMedications(bundle: Bundle): string[];
/**
* Extracts a list of cip13-code strings from a Bundle containing Medication resources.
* Only codes with system "http://terminology.hl7.org/CodeSystem/cip13-code" are included.
* @param bundle Bundle containing Medication resources
* @returns List of CIP13 codes
*/
declare function extractCIP13CodesFromMedications(bundle: Bundle): string[];
/**
* Extracts a list of cis-code strings from a Bundle containing Medication resources.
* Only codes with system "http://terminology.hl7.org/CodeSystem/cis-code" are included.
* @param bundle Bundle containing Medication resources
* @returns List of CIS codes
*/
declare function extractCISCodesFromMedications(bundle: Bundle): string[];
/**
* Creates a Bundle containing Medication resources from a list of bcb-code strings.
* Each Medication will have a CodeableConcept with a Coding for the bcb-code system.
* @param bcbCodes List of BCB codes to convert to Medication resources
* @returns MappingResponse containing a Bundle with Medication resources
*/
declare function createMedicationsFromBcbCodes(bcbCodes: string[]): MappingResponse<Bundle>;
/**
* Creates a Bundle containing Medication resources from a list of CIP13 codes.
* Each Medication will have a CodeableConcept with a Coding for the CIP13 system.
* @param cip13Codes List of CIP13 codes to convert to Medication resources
* @returns MappingResponse containing a Bundle with Medication resources
*/
declare function createMedicationsFromCIP13Codes(cip13Codes: string[]): MappingResponse<Bundle>;
/**
* Creates a Bundle containing Medication resources from a list of CIS codes.
* Each Medication will have a CodeableConcept with a Coding for the CIS system.
* @param cisCodes List of CIS codes to convert to Medication resources
* @returns MappingResponse containing a Bundle with Medication resources
*/
declare function createMedicationsFromCISCodes(cisCodes: string[]): MappingResponse<Bundle>;
declare const medicationMapper_d_createMedicationsFromBcbCodes: typeof createMedicationsFromBcbCodes;
declare const medicationMapper_d_createMedicationsFromCIP13Codes: typeof createMedicationsFromCIP13Codes;
declare const medicationMapper_d_createMedicationsFromCISCodes: typeof createMedicationsFromCISCodes;
declare const medicationMapper_d_extractBcbCodesFromMedications: typeof extractBcbCodesFromMedications;
declare const medicationMapper_d_extractCIP13CodesFromMedications: typeof extractCIP13CodesFromMedications;
declare const medicationMapper_d_extractCISCodesFromMedications: typeof extractCISCodesFromMedications;
declare const medicationMapper_d_extractCodesFromMedications: typeof extractCodesFromMedications;
declare const medicationMapper_d_generateMedicationId: typeof generateMedicationId;
declare namespace medicationMapper_d {
export {
medicationMapper_d_createMedicationsFromBcbCodes as createMedicationsFromBcbCodes,
medicationMapper_d_createMedicationsFromCIP13Codes as createMedicationsFromCIP13Codes,
medicationMapper_d_createMedicationsFromCISCodes as createMedicationsFromCISCodes,
medicationMapper_d_extractBcbCodesFromMedications as extractBcbCodesFromMedications,
medicationMapper_d_extractCIP13CodesFromMedications as extractCIP13CodesFromMedications,
medicationMapper_d_extractCISCodesFromMedications as extractCISCodesFromMedications,
medicationMapper_d_extractCodesFromMedications as extractCodesFromMedications,
medicationMapper_d_generateMedicationId as generateMedicationId,
};
}
/**
* Generate a hash-based ID for a medication request based on its key properties
*/
declare const generateMedicationRequestId: (medicationCode?: string, patientId?: string) => string;
/**
* Converts dosage instructions from MedicationRequest resources in a Bundle to BCB format.
* Uses the dosage-mapper for dosageInstruction field conversion.
* @param bundle Bundle containing MedicationRequest resources
* @returns Array of BCB dosage instructions from all MedicationRequest resources
*/
declare function fhirToBcb(bundle: Bundle): Promise<MappingResponse<BCBPosologieStructuree2>[]>;
/**
* Creates a Bundle containing MedicationRequest resources from BCB dosage data.
* Uses the dosage-mapper for converting BCB dosage to FHIR dosage instructions.
* @param bcbDosages Array of BCB dosage data
* @returns MappingResponse containing a Bundle with MedicationRequest resources
*/
declare function bcbToFhir(bcbDosages: BCBPosologieStructuree2[]): MappingResponse<Bundle>;
/**
* Extracts medication codes from MedicationRequest resources in a Bundle.
* @param bundle Bundle containing MedicationRequest resources
* @returns Array of medication codes
*/
declare function extractMedicationCodes(bundle: Bundle): string[];
/**
* Extracts patient references from MedicationRequest resources in a Bundle.
* @param bundle Bundle containing MedicationRequest resources
* @returns Array of patient references
*/
declare function extractPatientReferences(bundle: Bundle): string[];
declare const medicationRequestMapper_d_bcbToFhir: typeof bcbToFhir;
declare const medicationRequestMapper_d_extractMedicationCodes: typeof extractMedicationCodes;
declare const medicationRequestMapper_d_extractPatientReferences: typeof extractPatientReferences;
declare const medicationRequestMapper_d_fhirToBcb: typeof fhirToBcb;
declare const medicationRequestMapper_d_generateMedicationRequestId: typeof generateMedicationRequestId;
declare namespace medicationRequestMapper_d {
export {
medicationRequestMapper_d_bcbToFhir as bcbToFhir,
medicationRequestMapper_d_extractMedicationCodes as extractMedicationCodes,
medicationRequestMapper_d_extractPatientReferences as extractPatientReferences,
medicationRequestMapper_d_fhirToBcb as fhirToBcb,
medicationRequestMapper_d_generateMedicationRequestId as generateMedicationRequestId,
};
}
/**
* Simple hash function compatible with both Node.js and browser environments
* This replaces the Node.js crypto module to avoid browser compatibility issues
*/
declare const simpleHash: (str: string) => string;
/**
* Generate a deterministic 8-character hash from input data
* Compatible with browser and Node.js environments
*/
declare const generateHash: (data: any) => string;
export { dosageMapper_d as dosageMapper, generateHash, medicationMapper_d as medicationMapper, medicationRequestMapper_d as medicationRequestMapper, patientMapper_d as patientMapper, simpleHash };
export type { CodificationFunction, Coding, MappingError, MappingResponse, SimpleCodification };