⚡ Quick Start
Getting started with
fhir-dosage-utils
Installation
Install fhir-dosage-utils
using your desired package manager :
- npm
- Yarn
- pnpm
npm install fhir-dosage-utils
yarn add fhir-dosage-utils
pnpm add fhir-dosage-utils
Usage
main.js
import { FhirDosageUtils } from "fhir-dosage-utils";
// See https://jy95.github.io/fhir-dosage-utils/api/interface/Config for more info about config
const config = {
language: "en",
};
// A FHIR Dosage example
const dosage = {
timing: {
repeat: {
frequency: 1,
period: 8,
periodUnit: "h",
},
},
};
// Prepare utility class
let dosageUtils = await FhirDosageUtils.build(config);
// 1. You can turn dosage(s) to text
// display "1 time every 8 hours"
console.log(dosageUtils.fromDosageToText(dosage));
console.log(dosageUtils.fromMultipleDosageToText([dosage]));
// 2. You can extract part(s) of dosage, to your liking
// display "every 8 hours"
console.log(
dosageUtils.getFields(dosage, "periodPeriodMax" /*, other parameters*/),
);
// 3. You can detect if Dosage objects contains only "sequential" instructions
// display "true"
console.log(dosageUtils.containsOnlySequentialInstructions([dosage]));
// 4. Turn this array of Dosage objects into a data structure useful to handle "sequential" and "concurrent" instructions (cf. "sequence" property).
// Display "[ [dosage] ]"
console.log(dosageUtils.groupBySequence([dosage]));
// ... And many things
// Read https://jy95.github.io/fhir-dosage-utils/api/class/FhirDosageUtils for more info
Output examples
tip
We have many examples available on documentation . Check them to see lib in action 😉