diff --git a/.releaserc b/.releaserc index 3579347b..d0556066 100644 --- a/.releaserc +++ b/.releaserc @@ -1,3 +1,7 @@ { - "branches": ["main", {"name": "beta", "prerelease": true}, {"name": "alpha", "prerelease": true}] + "branches": [ + "main", + {"name": "beta", "prerelease": true}, + {"name": "alpha", "prerelease": true} + ] } \ No newline at end of file diff --git a/__tests__/api.test.tsx b/__tests__/api.test.tsx index 0028eada..acbc6946 100644 --- a/__tests__/api.test.tsx +++ b/__tests__/api.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../src/index"; +import { FhirDosageUtils } from "../src/index"; import type { Dosage } from "fhir/r4"; @@ -30,8 +30,8 @@ describe("API scenarios", () => { }, }; - let language1 = dosagesEn.getLanguage(); - let language2 = dosagesFr.getLanguage(); + let language1 = dosagesEn.getProperty("language"); + let language2 = dosagesFr.getProperty("language"); let result1 = dosagesEn.fromDosageToText(dosage); let result2 = dosagesFr.fromDosageToText(dosage); @@ -51,10 +51,10 @@ describe("API scenarios", () => { text: "Test string", }; - let order1 = dosagesEn.getDisplayOrder(); + let order1 = dosagesEn.getProperty("displayOrder"); let result1 = dosagesEn.fromDosageToText(dosage); - dosagesEn.changeDisplayOrder(["text"]); - let order2 = dosagesEn.getDisplayOrder(); + dosagesEn.setProperty("displayOrder", ["text"]); + let order2 = dosagesEn.getProperty("displayOrder"); let result2 = dosagesEn.fromDosageToText(dosage); expect(order1).not.toBe(order2); expect(result1).not.toBe(result2); @@ -78,21 +78,21 @@ describe("API scenarios", () => { }); test("changeDisplaySeparator must be applied", async () => { - let sep1 = dosagesEn.getDisplaySeparator(); - dosagesEn.changeDisplaySeparator(" | "); - let sep2 = dosagesEn.getDisplaySeparator(); + let sep1 = dosagesEn.getProperty("displaySeparator"); + dosagesEn.setProperty("displaySeparator", " | "); + let sep2 = dosagesEn.getProperty("displaySeparator"); expect(sep1).not.toBe(sep2); }); test("changeDateTimeFormatOptions must be applied", async () => { - let opts1 = dosagesEn.getDateTimeFormatOptions(); - dosagesEn.changeDateTimeFormatOptions({ + let opts1 = dosagesEn.getProperty("dateTimeFormatOptions"); + dosagesEn.setProperty("dateTimeFormatOptions", { day: "2-digit", hour: "numeric", minute: "numeric", second: "2-digit", }); - let opts2 = dosagesEn.getDateTimeFormatOptions(); + let opts2 = dosagesEn.getProperty("dateTimeFormatOptions"); expect(opts1).not.toBe(opts2); }); }); diff --git a/__tests__/corner_cases.test.tsx b/__tests__/corner_cases.test.tsx index 2ba7f0bd..ec8012cd 100644 --- a/__tests__/corner_cases.test.tsx +++ b/__tests__/corner_cases.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../src/index"; +import { FhirDosageUtils } from "../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/additionalInstruction.test.tsx b/__tests__/fromDosageToText/additionalInstruction.test.tsx index 571117d3..9cd160f9 100644 --- a/__tests__/fromDosageToText/additionalInstruction.test.tsx +++ b/__tests__/fromDosageToText/additionalInstruction.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/asNeeded.test.tsx b/__tests__/fromDosageToText/asNeeded.test.tsx index c2fe548d..1ea0dd07 100644 --- a/__tests__/fromDosageToText/asNeeded.test.tsx +++ b/__tests__/fromDosageToText/asNeeded.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage as DosageR4 } from "fhir/r4"; import type { Dosage as DosageR5 } from "fhir/r5"; diff --git a/__tests__/fromDosageToText/boundsDuration.test.tsx b/__tests__/fromDosageToText/boundsDuration.test.tsx index 0aba18e9..e4a792fc 100644 --- a/__tests__/fromDosageToText/boundsDuration.test.tsx +++ b/__tests__/fromDosageToText/boundsDuration.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/boundsPeriod.test.tsx b/__tests__/fromDosageToText/boundsPeriod.test.tsx index cd6ac65c..f64c1d02 100644 --- a/__tests__/fromDosageToText/boundsPeriod.test.tsx +++ b/__tests__/fromDosageToText/boundsPeriod.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/boundsRange.test.tsx b/__tests__/fromDosageToText/boundsRange.test.tsx index af86f5e5..f8415629 100644 --- a/__tests__/fromDosageToText/boundsRange.test.tsx +++ b/__tests__/fromDosageToText/boundsRange.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/code.test.tsx b/__tests__/fromDosageToText/code.test.tsx index 887ebba1..37270f77 100644 --- a/__tests__/fromDosageToText/code.test.tsx +++ b/__tests__/fromDosageToText/code.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/countCountMax.test.tsx b/__tests__/fromDosageToText/countCountMax.test.tsx index 0e73298c..00602b91 100644 --- a/__tests__/fromDosageToText/countCountMax.test.tsx +++ b/__tests__/fromDosageToText/countCountMax.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/dayOfWeek.test.tsx b/__tests__/fromDosageToText/dayOfWeek.test.tsx index 11365148..4636b981 100644 --- a/__tests__/fromDosageToText/dayOfWeek.test.tsx +++ b/__tests__/fromDosageToText/dayOfWeek.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/doseQuantity.test.tsx b/__tests__/fromDosageToText/doseQuantity.test.tsx index a9705e50..8e3b1d67 100644 --- a/__tests__/fromDosageToText/doseQuantity.test.tsx +++ b/__tests__/fromDosageToText/doseQuantity.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/doseRange.test.tsx b/__tests__/fromDosageToText/doseRange.test.tsx index 63c60098..178a1081 100644 --- a/__tests__/fromDosageToText/doseRange.test.tsx +++ b/__tests__/fromDosageToText/doseRange.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/durationDurationMax.test.tsx b/__tests__/fromDosageToText/durationDurationMax.test.tsx index 0cb8d1ad..e6ab7246 100644 --- a/__tests__/fromDosageToText/durationDurationMax.test.tsx +++ b/__tests__/fromDosageToText/durationDurationMax.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/event.test.tsx b/__tests__/fromDosageToText/event.test.tsx index 79b8dd54..edcd9ae4 100644 --- a/__tests__/fromDosageToText/event.test.tsx +++ b/__tests__/fromDosageToText/event.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; // For the WHY, consult this // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format#avoid_comparing_formatted_date_values_to_static_values diff --git a/__tests__/fromDosageToText/extension.test.tsx b/__tests__/fromDosageToText/extension.test.tsx index b86d8f02..5e1461fe 100644 --- a/__tests__/fromDosageToText/extension.test.tsx +++ b/__tests__/fromDosageToText/extension.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/frequencyFrequencyMax.test.tsx b/__tests__/fromDosageToText/frequencyFrequencyMax.test.tsx index 0d91be44..6415e107 100644 --- a/__tests__/fromDosageToText/frequencyFrequencyMax.test.tsx +++ b/__tests__/fromDosageToText/frequencyFrequencyMax.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/frequencyFrequencyMaxPeriodPeriodMax.test.tsx b/__tests__/fromDosageToText/frequencyFrequencyMaxPeriodPeriodMax.test.tsx index f6a8e784..b5bc361e 100644 --- a/__tests__/fromDosageToText/frequencyFrequencyMaxPeriodPeriodMax.test.tsx +++ b/__tests__/fromDosageToText/frequencyFrequencyMaxPeriodPeriodMax.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/maxDosePerAdministration.test.tsx b/__tests__/fromDosageToText/maxDosePerAdministration.test.tsx index 371627c0..84f7a41e 100644 --- a/__tests__/fromDosageToText/maxDosePerAdministration.test.tsx +++ b/__tests__/fromDosageToText/maxDosePerAdministration.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/maxDosePerLifetime.test.tsx b/__tests__/fromDosageToText/maxDosePerLifetime.test.tsx index 783c1a89..7faa1441 100644 --- a/__tests__/fromDosageToText/maxDosePerLifetime.test.tsx +++ b/__tests__/fromDosageToText/maxDosePerLifetime.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/maxDosePerPeriod.test.tsx b/__tests__/fromDosageToText/maxDosePerPeriod.test.tsx index 40a7604e..ed253862 100644 --- a/__tests__/fromDosageToText/maxDosePerPeriod.test.tsx +++ b/__tests__/fromDosageToText/maxDosePerPeriod.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage as DosageR4 } from "fhir/r4"; import type { Dosage as DosageR5 } from "fhir/r5"; diff --git a/__tests__/fromDosageToText/method.test.tsx b/__tests__/fromDosageToText/method.test.tsx index e788d3fe..053dd059 100644 --- a/__tests__/fromDosageToText/method.test.tsx +++ b/__tests__/fromDosageToText/method.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/modifierExtension.test.tsx b/__tests__/fromDosageToText/modifierExtension.test.tsx index 7689b0e5..27997436 100644 --- a/__tests__/fromDosageToText/modifierExtension.test.tsx +++ b/__tests__/fromDosageToText/modifierExtension.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/offsetWhen.test.tsx b/__tests__/fromDosageToText/offsetWhen.test.tsx index dfa44a53..1227f0c4 100644 --- a/__tests__/fromDosageToText/offsetWhen.test.tsx +++ b/__tests__/fromDosageToText/offsetWhen.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/patientInstruction.test.tsx b/__tests__/fromDosageToText/patientInstruction.test.tsx index 1b81b58e..8ec26ba3 100644 --- a/__tests__/fromDosageToText/patientInstruction.test.tsx +++ b/__tests__/fromDosageToText/patientInstruction.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/periodPeriodMax.test.tsx b/__tests__/fromDosageToText/periodPeriodMax.test.tsx index 6ca70551..cf595759 100644 --- a/__tests__/fromDosageToText/periodPeriodMax.test.tsx +++ b/__tests__/fromDosageToText/periodPeriodMax.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/rateQuantity.test.tsx b/__tests__/fromDosageToText/rateQuantity.test.tsx index d7f11a3c..bf354f6e 100644 --- a/__tests__/fromDosageToText/rateQuantity.test.tsx +++ b/__tests__/fromDosageToText/rateQuantity.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/rateRange.test.tsx b/__tests__/fromDosageToText/rateRange.test.tsx index 12fe9bb5..f12230f9 100644 --- a/__tests__/fromDosageToText/rateRange.test.tsx +++ b/__tests__/fromDosageToText/rateRange.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/rateRatio.test.tsx b/__tests__/fromDosageToText/rateRatio.test.tsx index a35e488d..605fb28d 100644 --- a/__tests__/fromDosageToText/rateRatio.test.tsx +++ b/__tests__/fromDosageToText/rateRatio.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/route.test.tsx b/__tests__/fromDosageToText/route.test.tsx index 43ede624..6c626d11 100644 --- a/__tests__/fromDosageToText/route.test.tsx +++ b/__tests__/fromDosageToText/route.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/site.test.tsx b/__tests__/fromDosageToText/site.test.tsx index 64c61f0b..107648cc 100644 --- a/__tests__/fromDosageToText/site.test.tsx +++ b/__tests__/fromDosageToText/site.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/text.test.tsx b/__tests__/fromDosageToText/text.test.tsx index bb8f3772..efd0e201 100644 --- a/__tests__/fromDosageToText/text.test.tsx +++ b/__tests__/fromDosageToText/text.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/timeOfDay.test.tsx b/__tests__/fromDosageToText/timeOfDay.test.tsx index 591073e9..68fc0a67 100644 --- a/__tests__/fromDosageToText/timeOfDay.test.tsx +++ b/__tests__/fromDosageToText/timeOfDay.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/timingExtension.test.tsx b/__tests__/fromDosageToText/timingExtension.test.tsx index 79eb4a15..adc46eb6 100644 --- a/__tests__/fromDosageToText/timingExtension.test.tsx +++ b/__tests__/fromDosageToText/timingExtension.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/timingModifierExtension.test.tsx b/__tests__/fromDosageToText/timingModifierExtension.test.tsx index 5a1f9726..fc37e6ff 100644 --- a/__tests__/fromDosageToText/timingModifierExtension.test.tsx +++ b/__tests__/fromDosageToText/timingModifierExtension.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromDosageToText/timingRepeatExtension.test.tsx b/__tests__/fromDosageToText/timingRepeatExtension.test.tsx index bc94e95e..4f20d5da 100644 --- a/__tests__/fromDosageToText/timingRepeatExtension.test.tsx +++ b/__tests__/fromDosageToText/timingRepeatExtension.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../../src/index"; +import { FhirDosageUtils } from "../../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/fromMultipleDosageToText.test.tsx b/__tests__/fromMultipleDosageToText.test.tsx index 0af5c232..dd5b7e9f 100644 --- a/__tests__/fromMultipleDosageToText.test.tsx +++ b/__tests__/fromMultipleDosageToText.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../src/index"; +import { FhirDosageUtils } from "../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/__tests__/timing.test.tsx b/__tests__/timing.test.tsx index fbb1ec92..f6befa2c 100644 --- a/__tests__/timing.test.tsx +++ b/__tests__/timing.test.tsx @@ -1,6 +1,6 @@ // For typings autocomplete whatever your IDE import { expect, test, describe } from "@jest/globals"; -import FhirDosageUtils from "../src/index"; +import { FhirDosageUtils } from "../src/index"; import type { Dosage } from "fhir/r4"; diff --git a/documentation/docs/custom/fromFHIRQuantityUnitToString.mdx b/documentation/docs/custom/fromFHIRQuantityUnitToString.mdx index 1076d656..1d2040c2 100644 --- a/documentation/docs/custom/fromFHIRQuantityUnitToString.mdx +++ b/documentation/docs/custom/fromFHIRQuantityUnitToString.mdx @@ -44,11 +44,11 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Possible cases in production : +Possible cases in production : 1. SNOMED CT - http://snomed.info/sct 2. UCUM - http://unitsofmeasure.org -3. Other Code System than SNOMED CT / UCUM, such as LOINC - http://loinc.org/ +3. Other Code System than SNOMED CT / UCUM, such as LOINC - http://loinc.org/ 4. (Local) Value Set, e.g. https://www.ehealth.fgov.be/standards/fhir/core/ValueSet/be-cd-administration-unit 5. Hardcoded unit without any system @@ -60,4 +60,4 @@ To support them all in your `fromFHIRQuantityUnitToString` implementation, here - Extensions put on [Quantity](https://build.fhir.org/datatypes.html#Quantity), depending of your implementation guide - ... -::: \ No newline at end of file +::: diff --git a/documentation/docs/faq.mdx b/documentation/docs/faq.mdx index 46719508..dbfc9e10 100644 --- a/documentation/docs/faq.mdx +++ b/documentation/docs/faq.mdx @@ -24,7 +24,8 @@ The library was built with that in mind. Read more [here](demo/custom). | Version | FHIR | | -------------------- | ----------- | -| `>= 1.0.0` (current) | `R4 and R5` | +| `>= 2.0.0` (current) | `R4 and R5` | +| `>= 1.0.0` | `R4 and R5` | diff --git a/documentation/docs/quick-start.mdx b/documentation/docs/quick-start.mdx index 23fc8f45..a98229b2 100644 --- a/documentation/docs/quick-start.mdx +++ b/documentation/docs/quick-start.mdx @@ -19,9 +19,9 @@ npm install fhir-dosage-utils ## Usage ```jsx title="main.js" -import FhirDosageUtils from "fhir-dosage-utils"; +import { FhirDosageUtils } from "fhir-dosage-utils"; -// See https://jy95.github.io/fhir-dosage-utils/api/interface/Params for more info about config +// See https://jy95.github.io/fhir-dosage-utils/api/interface/Config for more info about config const config = { language: "en", }; @@ -60,7 +60,7 @@ console.log(dosageUtils.containsOnlySequentialInstructions([dosage])); console.log(dosageUtils.groupBySequence([dosage])); // ... And many things -// Read https://jy95.github.io/fhir-dosage-utils/api/class/default for more info +// Read https://jy95.github.io/fhir-dosage-utils/api/class/FhirDosageUtils for more info ``` ## Output examples diff --git a/documentation/docs/specs/additionalInstruction/multiple_items.mdx b/documentation/docs/specs/additionalInstruction/multiple_items.mdx index 0ddc4308..4382dac8 100644 --- a/documentation/docs/specs/additionalInstruction/multiple_items.mdx +++ b/documentation/docs/specs/additionalInstruction/multiple_items.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/additionalInstruction/single_item.mdx b/documentation/docs/specs/additionalInstruction/single_item.mdx index a331e37b..d0119b0f 100644 --- a/documentation/docs/specs/additionalInstruction/single_item.mdx +++ b/documentation/docs/specs/additionalInstruction/single_item.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/asNeeded/asNeededCodeableConcept.mdx b/documentation/docs/specs/asNeeded/asNeededCodeableConcept.mdx index 464889b8..6ea16796 100644 --- a/documentation/docs/specs/asNeeded/asNeededCodeableConcept.mdx +++ b/documentation/docs/specs/asNeeded/asNeededCodeableConcept.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/asNeeded/asNeededFor.mdx b/documentation/docs/specs/asNeeded/asNeededFor.mdx index 6595424e..8bc94a33 100644 --- a/documentation/docs/specs/asNeeded/asNeededFor.mdx +++ b/documentation/docs/specs/asNeeded/asNeededFor.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/boundsDuration/boundsDuration.mdx b/documentation/docs/specs/boundsDuration/boundsDuration.mdx index e4d24bab..777e46c7 100644 --- a/documentation/docs/specs/boundsDuration/boundsDuration.mdx +++ b/documentation/docs/specs/boundsDuration/boundsDuration.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/boundsRange/high_only.mdx b/documentation/docs/specs/boundsRange/high_only.mdx index 6f7b027c..ef96e971 100644 --- a/documentation/docs/specs/boundsRange/high_only.mdx +++ b/documentation/docs/specs/boundsRange/high_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/boundsRange/low_and_high.mdx b/documentation/docs/specs/boundsRange/low_and_high.mdx index 7ee2cca6..cc64415c 100644 --- a/documentation/docs/specs/boundsRange/low_and_high.mdx +++ b/documentation/docs/specs/boundsRange/low_and_high.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/boundsRange/low_only.mdx b/documentation/docs/specs/boundsRange/low_only.mdx index 12cde978..10069177 100644 --- a/documentation/docs/specs/boundsRange/low_only.mdx +++ b/documentation/docs/specs/boundsRange/low_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/code/code.mdx b/documentation/docs/specs/code/code.mdx index 9ab66310..174e3952 100644 --- a/documentation/docs/specs/code/code.mdx +++ b/documentation/docs/specs/code/code.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/doseQuantity/doseQuantity.mdx b/documentation/docs/specs/doseQuantity/doseQuantity.mdx index bdce0c73..2312dad3 100644 --- a/documentation/docs/specs/doseQuantity/doseQuantity.mdx +++ b/documentation/docs/specs/doseQuantity/doseQuantity.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/doseRange/high_only.mdx b/documentation/docs/specs/doseRange/high_only.mdx index d5124a3d..7c12b0ac 100644 --- a/documentation/docs/specs/doseRange/high_only.mdx +++ b/documentation/docs/specs/doseRange/high_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/doseRange/low_and_high.mdx b/documentation/docs/specs/doseRange/low_and_high.mdx index 06801899..2756cfc9 100644 --- a/documentation/docs/specs/doseRange/low_and_high.mdx +++ b/documentation/docs/specs/doseRange/low_and_high.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/doseRange/low_only.mdx b/documentation/docs/specs/doseRange/low_only.mdx index 41eebbc6..1f479079 100644 --- a/documentation/docs/specs/doseRange/low_only.mdx +++ b/documentation/docs/specs/doseRange/low_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/event/multiple_items.mdx b/documentation/docs/specs/event/multiple_items.mdx index d787ec7e..b25d1837 100644 --- a/documentation/docs/specs/event/multiple_items.mdx +++ b/documentation/docs/specs/event/multiple_items.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [dateTimeFormatOptions](/api/interface/Params) option to fit your needs +Don't forget you can use [dateTimeFormatOptions](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/event/single_item.mdx b/documentation/docs/specs/event/single_item.mdx index f9c0ab7f..7b5125c4 100644 --- a/documentation/docs/specs/event/single_item.mdx +++ b/documentation/docs/specs/event/single_item.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [dateTimeFormatOptions](/api/interface/Params) option to fit your needs +Don't forget you can use [dateTimeFormatOptions](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/maxDosePerAdministration/maxDosePerAdministration.mdx b/documentation/docs/specs/maxDosePerAdministration/maxDosePerAdministration.mdx index 43c68c7a..c066a065 100644 --- a/documentation/docs/specs/maxDosePerAdministration/maxDosePerAdministration.mdx +++ b/documentation/docs/specs/maxDosePerAdministration/maxDosePerAdministration.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/maxDosePerLifetime/maxDosePerLifetime.mdx b/documentation/docs/specs/maxDosePerLifetime/maxDosePerLifetime.mdx index f89c781f..afd4196d 100644 --- a/documentation/docs/specs/maxDosePerLifetime/maxDosePerLifetime.mdx +++ b/documentation/docs/specs/maxDosePerLifetime/maxDosePerLifetime.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/maxDosePerPeriod/r4.mdx b/documentation/docs/specs/maxDosePerPeriod/r4.mdx index 97518a50..54bc59a9 100644 --- a/documentation/docs/specs/maxDosePerPeriod/r4.mdx +++ b/documentation/docs/specs/maxDosePerPeriod/r4.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/maxDosePerPeriod/r5.mdx b/documentation/docs/specs/maxDosePerPeriod/r5.mdx index 200fd8ea..543ae396 100644 --- a/documentation/docs/specs/maxDosePerPeriod/r5.mdx +++ b/documentation/docs/specs/maxDosePerPeriod/r5.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/method/method.mdx b/documentation/docs/specs/method/method.mdx index b753b2e0..a001876e 100644 --- a/documentation/docs/specs/method/method.mdx +++ b/documentation/docs/specs/method/method.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/rateQuantity/rateQuantity.mdx b/documentation/docs/specs/rateQuantity/rateQuantity.mdx index b11f0cfd..a574e236 100644 --- a/documentation/docs/specs/rateQuantity/rateQuantity.mdx +++ b/documentation/docs/specs/rateQuantity/rateQuantity.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/rateRange/high_only.mdx b/documentation/docs/specs/rateRange/high_only.mdx index a048781f..1f5319b7 100644 --- a/documentation/docs/specs/rateRange/high_only.mdx +++ b/documentation/docs/specs/rateRange/high_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/rateRange/low_and_high.mdx b/documentation/docs/specs/rateRange/low_and_high.mdx index 22fb1989..b0becd71 100644 --- a/documentation/docs/specs/rateRange/low_and_high.mdx +++ b/documentation/docs/specs/rateRange/low_and_high.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/rateRange/low_only.mdx b/documentation/docs/specs/rateRange/low_only.mdx index 530ad16b..5a7f5fc7 100644 --- a/documentation/docs/specs/rateRange/low_only.mdx +++ b/documentation/docs/specs/rateRange/low_only.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/rateRatio/rateRatio.mdx b/documentation/docs/specs/rateRatio/rateRatio.mdx index 74c60a02..1bed3ad1 100644 --- a/documentation/docs/specs/rateRatio/rateRatio.mdx +++ b/documentation/docs/specs/rateRatio/rateRatio.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromFHIRQuantityUnitToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/route/route.mdx b/documentation/docs/specs/route/route.mdx index 76b02564..bef10bf8 100644 --- a/documentation/docs/specs/route/route.mdx +++ b/documentation/docs/specs/route/route.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/docs/specs/site/site.mdx b/documentation/docs/specs/site/site.mdx index 91035d95..7e3e3a48 100644 --- a/documentation/docs/specs/site/site.mdx +++ b/documentation/docs/specs/site/site.mdx @@ -20,6 +20,6 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; :::tip -Don't forget you can use [fromCodeableConceptToString](/api/interface/Params) option to fit your needs +Don't forget you can use [fromCodeableConceptToString](/api/interface/Config) option to fit your needs ::: diff --git a/documentation/src/components/multiple_dosage_to_text.tsx b/documentation/src/components/multiple_dosage_to_text.tsx index 87b00f91..d730d925 100644 --- a/documentation/src/components/multiple_dosage_to_text.tsx +++ b/documentation/src/components/multiple_dosage_to_text.tsx @@ -1,12 +1,12 @@ import React, { useState, useEffect } from "react"; -import FhirDosageUtils from "fhir-dosage-utils"; +import { FhirDosageUtils } from "fhir-dosage-utils"; import { decode } from "html-entities"; import CodeBlock from "@theme/CodeBlock"; // Types import type { Dosage as DosageR4 } from "fhir/r4"; import type { Dosage as DosageR5 } from "fhir/r5"; -import type { Params as Config, I18InitOptions } from "fhir-dosage-utils"; +import type { Config, I18InitOptions } from "fhir-dosage-utils"; type Dosage = DosageR4 | DosageR5; // For the WHY, consult this @@ -31,7 +31,10 @@ export default function MultipleDosagesToText({ // Set up instance useEffect(() => { async function initializeDosageUtils() { - const utils = await FhirDosageUtils.build(config, i18nConfig); + const utils = await FhirDosageUtils.build({ + ...config, + i18nConfig: i18nConfig, + }); setDosageUtils(utils); } diff --git a/documentation/src/components/single_dosage_to_text.tsx b/documentation/src/components/single_dosage_to_text.tsx index f12f6f63..7be1f1f5 100644 --- a/documentation/src/components/single_dosage_to_text.tsx +++ b/documentation/src/components/single_dosage_to_text.tsx @@ -1,12 +1,12 @@ import React, { useState, useEffect } from "react"; -import FhirDosageUtils from "fhir-dosage-utils"; +import { FhirDosageUtils } from "fhir-dosage-utils"; import { decode } from "html-entities"; import CodeBlock from "@theme/CodeBlock"; // Types import type { Dosage as DosageR4 } from "fhir/r4"; import type { Dosage as DosageR5 } from "fhir/r5"; -import type { Params as Config, I18InitOptions } from "fhir-dosage-utils"; +import type { Config, I18InitOptions } from "fhir-dosage-utils"; type Dosage = DosageR4 | DosageR5; // For the WHY, consult this @@ -31,7 +31,10 @@ export default function SingleDosageToText({ // Set up instance useEffect(() => { async function initializeDosageUtils() { - const utils = await FhirDosageUtils.build(config, i18nConfig); + const utils = await FhirDosageUtils.build({ + ...config, + i18nConfig: i18nConfig, + }); setDosageUtils(utils); } diff --git a/src/api.ts b/src/api.ts index ea8a894b..2c035465 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,86 +1,67 @@ -import { Configurator } from "./classes/Configurator"; +import i18next from "i18next"; +import ChainedBackend from "i18next-chained-backend"; +import { defaultAttributes } from "./configurator"; +import { Utils } from "./dosageUtils"; import { fromDisplayOrderToResult } from "./utils/fromDisplayOrderToResult"; import { fromListToString } from "./utils/fromListToString"; import { isNotUndefined } from "./internal/undefinedChecks"; -import type { - Params, - Dosage, - DisplayOrder, - I18InitOptions, - NamespacesLocale, -} from "./types"; - -import resourcesToBackend from "i18next-resources-to-backend"; -const defaultI18NConfig: I18InitOptions = { - backend: { - backends: [ - resourcesToBackend( - async (lng: string, ns: NamespacesLocale) => - import(`./locales/${lng}/${ns}.json`), - ), - ], - }, -}; - -export class FhirDosageUtils extends Configurator { - /** - * Factory to create a fine-tuned instance of the utility class - */ - static async build( - userConfig?: Params, - i18nConfig: I18InitOptions = defaultI18NConfig, - ) { - const instance = new FhirDosageUtils(userConfig, i18nConfig); - await instance.init(); - return instance; +import type { I18N, Dosage, DisplayOrder, Config } from "./types"; +type PropertyKey = keyof Config; +type SettableProperties = Exclude; + +export class FhirDosageUtils extends Utils { + protected config: Config; + protected i18nInstance: I18N; + + protected constructor(config: Partial) { + super(); + this.config = { + ...defaultAttributes, + ...config, + }; + this.i18nInstance = i18next.createInstance(); } - /** - * Does this array of Dosage objects contains only "sequential" instructions ? - */ - containsOnlySequentialInstructions(dosages: Dosage[]): boolean { - let sequencesNumbers = dosages - .map((d) => d.sequence) - .filter(isNotUndefined); - - let encounteredSequenceNumbers = new Set(sequencesNumbers); - - return ( - encounteredSequenceNumbers.size === 0 || - encounteredSequenceNumbers.size === dosages.length - ); + protected async init() { + return await this.i18nInstance.use(ChainedBackend).init({ + fallbackLng: "en", + lng: this.config.language, + ns: [ + "common", + "daysOfWeek", + "eventTiming", + "unitsOfTime", + "quantityComparator", + ], + defaultNS: "common", + ...this.config.i18nConfig, + }); } - /** - * Turn this array of Dosage objects into a data structure useful to handle "sequential" and "concurrent" instructions (cf. "sequence" property). - * @returns {Dosage[][]} - A two-dimensional array where each inner array contains Dosage objects belonging to the same sequence numberr. - */ - groupBySequence(dosages: Dosage[]) { - let groups: Record = {}; - let sequences = new Set(); - - for (let idx = 0; idx < dosages.length; idx++) { - const dosage = dosages[idx]; - - let sequenceNr = dosage.sequence || idx + 1; - let localGroup = groups[sequenceNr] || []; + static async build(config: Partial = {}) { + const instance = new FhirDosageUtils(config); + await instance.init(); + return instance; + } - localGroup.push(dosage); - groups[sequenceNr] = localGroup; + getProperty(key: T): Config[T] { + return this.config[key]; + } - sequences.add(sequenceNr); - } + setProperty( + key: T, + value: Config[T], + ): undefined { + this.config[key] = value; + } - // By using the Set values, we are sure it is returned in the way Dosages were written - return Array.from(sequences, (sequence) => groups[sequence]); + async changeLanguage(lng: string) { + this.config["language"] = lng; + return this.i18nInstance.changeLanguage(lng); } - /** - * From a single dosage, extract specific field(s) requested by user. - * Some use cases could request to split part of the object for given needs (quantity and timing separately) - */ getFields(dos: Dosage, ...order: DisplayOrder[]): string { let parts = order .map((entry) => @@ -96,41 +77,39 @@ export class FhirDosageUtils extends Configurator { return parts.join(this.config.displaySeparator); } - /** - * Turn a FHIR Dosage object into text - */ fromDosageToText(dos: Dosage): string { let order = this.config.displayOrder; return this.getFields(dos, ...order); } - /** - * Turn multiple FHIR Dosage objects into text - */ fromMultipleDosageToText(dosages: Dosage[]): string { - const hasOnlySequentialInstructions = - this.containsOnlySequentialInstructions(dosages); - - if (hasOnlySequentialInstructions) { - const dosagesAsText = dosages.map((d) => this.fromDosageToText(d)); - return fromListToString(this.i18nInstance, dosagesAsText, "then"); + if (this.containsOnlySequentialInstructions(dosages)) { + return this.convertSequentialDosagesToText(dosages); } + return this.convertGroupedDosagesToText(dosages); + } - let sortedDosages = this.groupBySequence(dosages); - - let sequentialInstructions: string[] = sortedDosages.map( - (concurrentInstructions) => { - let concurrentInstructionsAsString = concurrentInstructions.map( - (dosage) => this.fromDosageToText(dosage), - ); - return fromListToString( - this.i18nInstance, - concurrentInstructionsAsString, - "and", - ); - }, + private convertSequentialDosagesToText(dosages: Dosage[]): string { + const dosagesAsText = dosages.map((d) => this.fromDosageToText(d)); + return fromListToString(this.i18nInstance, dosagesAsText, "then"); + } + + private convertConcurrentDosagesToText(dosages: Dosage[]): string { + const concurrentInstructionsAsString = dosages.map((d) => + this.fromDosageToText(d), + ); + return fromListToString( + this.i18nInstance, + concurrentInstructionsAsString, + "and", ); + } + private convertGroupedDosagesToText(dosages: Dosage[]): string { + const sortedDosages = this.groupBySequence(dosages); + const sequentialInstructions = sortedDosages.map((d) => + this.convertConcurrentDosagesToText(d), + ); return fromListToString(this.i18nInstance, sequentialInstructions, "then"); } } diff --git a/src/classes/Configurator.ts b/src/classes/Configurator.ts deleted file mode 100644 index 557527d1..00000000 --- a/src/classes/Configurator.ts +++ /dev/null @@ -1,122 +0,0 @@ -import i18next from "i18next"; -import ChainedBackend from "i18next-chained-backend"; - -import { defaultAttributes } from "../internal/defaultAttributes"; - -import type { - Config, - DisplayOrder, - I18N, - Params, - InitOptions, - I18InitOptions, -} from "../types"; - -export class Configurator { - // User Configuration - protected config: Config; - // i18next config - protected i18nConfig: InitOptions; - // i18next instance - // When multiple instances of the class are used, they must act independantly regardless of the others - protected i18nInstance: I18N; - - protected constructor(userConfig?: Params, i18nConfig?: I18InitOptions) { - this.config = { - ...defaultAttributes, - ...userConfig, - }; - this.i18nConfig = { - fallbackLng: "en", - lng: this.config.language, - ns: [ - "common", - "daysOfWeek", - "eventTiming", - "unitsOfTime", - "quantityComparator", - ], - defaultNS: "common", - ...i18nConfig, - }; - this.i18nInstance = i18next.createInstance(); - } - - /** - * To init i18next properly according requested criteria - */ - protected async init() { - // You should wait for init to complete (wait for the callback or promise resolution) - // before using the t function! - return await this.i18nInstance.use(ChainedBackend).init(this.i18nConfig); - } - - /** - * To change language - */ - async changeLanguage(lng: string) { - this.config = { - ...this.config, - language: lng, - }; - return this.i18nInstance.changeLanguage(lng); - } - - /** - * Get current language - */ - getLanguage() { - return this.config.language; - } - - /** - * To change display order - */ - changeDisplayOrder(order: DisplayOrder[]) { - this.config = { - ...this.config, - displayOrder: order, - }; - } - - /** - * Get display order - */ - getDisplayOrder() { - return this.config.displayOrder; - } - - /** - * Get display separator - */ - getDisplaySeparator() { - return this.config.displaySeparator; - } - - /** - * Set display separator - */ - changeDisplaySeparator(sep: string) { - this.config = { - ...this.config, - displaySeparator: sep, - }; - } - - /** - * Get date time format options - */ - getDateTimeFormatOptions() { - return this.config.dateTimeFormatOptions; - } - - /** - * Set date time format options - */ - changeDateTimeFormatOptions(opts: Intl.DateTimeFormatOptions) { - this.config = { - ...this.config, - dateTimeFormatOptions: opts, - }; - } -} diff --git a/src/configurator.ts b/src/configurator.ts new file mode 100644 index 00000000..77ed8456 --- /dev/null +++ b/src/configurator.ts @@ -0,0 +1,112 @@ +import resourcesToBackend from "i18next-resources-to-backend"; + +import { defaultFromFHIRQuantityUnitToString } from "./utils/fromFHIRQuantityUnitToString"; +import { defaultFromCodeableConceptToString } from "./utils/fromCodeableConceptToString"; +import { defaultFromExtensionsToString } from "./utils/fromExtensionsToString"; + +import type { FromFHIRQuantityUnitToStringFct } from "./utils/fromFHIRQuantityUnitToString"; +import type { FromCodeableConceptToStringFct } from "./utils/fromCodeableConceptToString"; +import type { FromExtensionsToStringFct } from "./utils/fromExtensionsToString"; + +import type { DisplayOrder, I18InitOptions, NamespacesLocale } from "./types"; + +export interface Config { + /** + * BCP 47 language code to setup the library with + * @defaultValue "en" (English) + * @see [FAQ](https://jy95.github.io/fhir-dosage-utils/docs/faq) for the built-in languages + * @see [I18next documentation](https://www.i18next.com/how-to/faq#how-should-the-language-codes-be-formatted) for the reasons behind BCP 47 + */ + language: string; + /** + * Function to turn a quantity unit (e.g UCUM "ml") into a string for humans (e.g "militier") + * The choice to handle plural form or not is thus under the hands of people ;) + * @see [defaultFromFHIRQuantityUnitToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromFHIRQuantityUnitToString.ts) for default implementation + * @see [FHIR definition of Quantity](https://build.fhir.org/datatypes.html#Quantity) for more info about the type itself + */ + fromFHIRQuantityUnitToString: FromFHIRQuantityUnitToStringFct; + /** + * Function to turn a codeable concept (e.g SNOMED CT "311504000") into a string for humans (e.g "With or after food") + * The choice to handle extension, local valueset, ... is thus under the hands of people ;) + * @see [defaultFromCodeableConceptToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromCodeableConceptToString.ts) for default implementation + * @see [FHIR definition of CodeableConcept](https://build.fhir.org/datatypes.html#CodeableConcept) for more info about the type itself + */ + fromCodeableConceptToString: FromCodeableConceptToStringFct; + /** + * Function to turn extension(s) into a string for humans. + * The choice to handle national extensions, ... is thus under the hands of people ;) + * @see [defaultFromExtensionsToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromExtensionsToString.ts) for default implementation + * @see [FHIR definition of Extension](https://build.fhir.org/extensibility.html#Extension) for more info about the type itself + */ + fromExtensionsToString: FromExtensionsToStringFct; + /** + * Control the display order used by the algorithm + * Useful when you want to turn on / off some specific rules for some reason + * @defaultValue ["method", "doseQuantity", "doseRange", "rateRatio", "rateQuantity", "rateRange", "durationDurationMax", "frequencyFrequencyMaxPeriodPeriodMax", "offsetWhen", "dayOfWeek", "timeOfDay", "route", "site", "asNeeded", "boundsDuration", "boundsPeriod", "boundsRange", "countCountMax", "event", "code", "maxDosePerPeriod", "maxDosePerAdministration", "maxDosePerLifetime", "additionalInstruction", "patientInstruction"] + * @see [DisplayOrderEnum](../enum/DisplayOrderEnum) for more info + */ + displayOrder: DisplayOrder[]; + /** + * Override separator between each part of "Dosage" + * @defaultValue " - " + */ + displaySeparator: string; + /** + * To control the formatting of dateTime objects. + * If not provided, will use the defaults according locale e.g. "20/01/2024" + * @defaultValue {} + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options + */ + dateTimeFormatOptions: Intl.DateTimeFormatOptions; + /** + * I18next config + * @see https://www.i18next.com/overview/configuration-options + */ + i18nConfig: I18InitOptions; +} + +export const defaultAttributes: Config = { + language: "en", + fromFHIRQuantityUnitToString: defaultFromFHIRQuantityUnitToString, + fromCodeableConceptToString: defaultFromCodeableConceptToString, + fromExtensionsToString: defaultFromExtensionsToString, + displayOrder: [ + "method", + "doseQuantity", + "doseRange", + "rateRatio", + "rateQuantity", + "rateRange", + "durationDurationMax", + "frequencyFrequencyMaxPeriodPeriodMax", + "offsetWhen", + "dayOfWeek", + "timeOfDay", + "route", + "site", + "asNeeded", + "boundsDuration", + "boundsPeriod", + "boundsRange", + "countCountMax", + "event", + "code", + "maxDosePerPeriod", + "maxDosePerAdministration", + "maxDosePerLifetime", + "additionalInstruction", + "patientInstruction", + ] as DisplayOrder[], + displaySeparator: " - ", + dateTimeFormatOptions: {}, + i18nConfig: { + backend: { + backends: [ + resourcesToBackend( + async (lng: string, ns: NamespacesLocale) => + import(`./locales/${lng}/${ns}.json`), + ), + ], + }, + }, +}; diff --git a/src/dosageUtils.ts b/src/dosageUtils.ts new file mode 100644 index 00000000..f797ed97 --- /dev/null +++ b/src/dosageUtils.ts @@ -0,0 +1,31 @@ +import { isNotUndefined } from "./internal/undefinedChecks"; +import type { Dosage } from "./types"; + +export class Utils { + containsOnlySequentialInstructions(dosages: Dosage[]): boolean { + let sequencesNumbers = dosages + .map((d) => d.sequence) + .filter(isNotUndefined); + + let encounteredSequenceNumbers = new Set(sequencesNumbers); + return [0, dosages.length].includes(encounteredSequenceNumbers.size); + } + + groupBySequence(dosages: Dosage[]) { + let sequences = new Set(); + let sequencesMap = new Map(); + + for (let dosage of dosages) { + let sequenceNr = dosage.sequence; + let localGroup = sequencesMap.get(sequenceNr) ?? []; + localGroup.push(dosage); + sequencesMap.set(sequenceNr, localGroup); + sequences.add(sequenceNr); + } + + return Array.from( + sequences, + (sequence) => sequencesMap.get(sequence) as Dosage[], + ); + } +} diff --git a/src/index.ts b/src/index.ts index c0c4e7c7..b34f138f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,5 @@ -import { FhirDosageUtils } from "./api"; -import type { Params, DisplayOrderEnum, I18InitOptions } from "./types"; +// Export utility class +export { FhirDosageUtils } from "./api"; -// Default export to make it user-friendly -export default FhirDosageUtils; - -// Export config type as that it can be used in client codes as well -export type { Params, DisplayOrderEnum, I18InitOptions }; +// Export types as it can be used in client codes +export type { Config, DisplayOrderEnum, I18InitOptions } from "./types"; diff --git a/src/internal/defaultAttributes.ts b/src/internal/defaultAttributes.ts deleted file mode 100644 index 4d60dfe8..00000000 --- a/src/internal/defaultAttributes.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { Config } from "../types"; - -import { defaultFromFHIRQuantityUnitToString } from "../utils/fromFHIRQuantityUnitToString"; -import { defaultFromCodeableConceptToString } from "../utils/fromCodeableConceptToString"; -import { defaultFromExtensionsToString } from "../utils/fromExtensionsToString"; - -export const defaultAttributes: Config = { - language: "en", - fromFHIRQuantityUnitToString: defaultFromFHIRQuantityUnitToString, - fromCodeableConceptToString: defaultFromCodeableConceptToString, - fromExtensionsToString: defaultFromExtensionsToString, - displayOrder: [ - "method", - "doseQuantity", - "doseRange", - "rateRatio", - "rateQuantity", - "rateRange", - "durationDurationMax", - "frequencyFrequencyMaxPeriodPeriodMax", - "offsetWhen", - "dayOfWeek", - "timeOfDay", - "route", - "site", - "asNeeded", - "boundsDuration", - "boundsPeriod", - "boundsRange", - "countCountMax", - "event", - "code", - "maxDosePerPeriod", - "maxDosePerAdministration", - "maxDosePerLifetime", - "additionalInstruction", - "patientInstruction", - ], - displaySeparator: " - ", - dateTimeFormatOptions: {}, -}; diff --git a/src/internal/extractMatchingDoseAndRateFirstEntry.ts b/src/internal/extractMatchingDoseAndRateFirstEntry.ts index 954861a6..1607f7ce 100644 --- a/src/internal/extractMatchingDoseAndRateFirstEntry.ts +++ b/src/internal/extractMatchingDoseAndRateFirstEntry.ts @@ -11,7 +11,6 @@ export function extractMatchingDoseAndRateFirstEntry( return undefined; } - // Find the first entry that match criteria let doseAndRate = dos.doseAndRate.find((s) => isNotUndefined(s[key])); if (!isNotUndefined(doseAndRate)) { diff --git a/src/translators/maxDosePerPeriod.ts b/src/translators/maxDosePerPeriod.ts index cc262b02..793ffdf1 100644 --- a/src/translators/maxDosePerPeriod.ts +++ b/src/translators/maxDosePerPeriod.ts @@ -16,21 +16,17 @@ export function transformMaxDosePerPeriodToText({ const maxDosePerPeriod = dos.maxDosePerPeriod; // In R4, it was a single object / In R5, it is an array - // So better to have a generic approach const values = Array.isArray(maxDosePerPeriod) ? maxDosePerPeriod : [maxDosePerPeriod]; - // Only consider not empty array if (values.length === 0) { return undefined; } // Periods are expressed as ratio (like rateRatio) const valuesAsString = values - .map((period) => { - return fromRatioToString({ config, i18next, ratio: period }); - }) + .map((period) => fromRatioToString({ config, i18next, ratio: period })) .filter(isNotUndefined) as string[]; const maxDosePerPeriodText = fromListToString(i18next, valuesAsString); diff --git a/src/translators/offsetWhen.ts b/src/translators/offsetWhen.ts index b5ab5497..d97f99a6 100644 --- a/src/translators/offsetWhen.ts +++ b/src/translators/offsetWhen.ts @@ -54,12 +54,10 @@ function transformOffset(i18next: I18N, offset?: number): string | undefined { let order = ["d", "h", "min"] as (keyof typeof time)[]; return order + .filter((unit) => time[unit] > 0) .map((unit) => - time[unit] > 0 - ? i18next.t(`unitsOfTime:withCount.${unit}`, { count: time[unit] }) - : undefined, + i18next.t(`unitsOfTime:withCount.${unit}`, { count: time[unit] }), ) - .filter(isNotUndefined) .join(" "); } diff --git a/src/types.ts b/src/types.ts index 4615f3ed..16d1cbff 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type { FromFHIRQuantityUnitToStringFct } from "./utils/fromFHIRQuantityUnitToString"; import type { FromCodeableConceptToStringFct } from "./utils/fromCodeableConceptToString"; -import type { FromExtensionsToStringFct } from "./utils/fromExtensionsToString"; +import type { Config } from "./configurator"; import type { i18n as I18N, InitOptions } from "i18next"; @@ -27,6 +27,7 @@ import type { TimingRepeat as TimingRepeatR5, } from "fhir/r5"; +export type { Config }; export type Dosage = DosageR4 | DosageR5; export type CodeableConcept = CodeableConceptR4 | CodeableConceptR5; export type Quantity = QuantityR4 | QuantityR5; @@ -185,73 +186,18 @@ export type NamespacesLocale = | "eventTiming" | "unitsOfTime"; -export interface Params { - /** - * BCP 47 language code to setup the library with - * @defaultValue "en" (English) - * @see [FAQ](https://jy95.github.io/fhir-dosage-utils/docs/faq) for the built-in languages - * @see [I18next documentation](https://www.i18next.com/how-to/faq#how-should-the-language-codes-be-formatted) for the reasons behind BCP 47 - */ - language?: string; - /** - * Function to turn a quantity unit (e.g UCUM "ml") into a string for humans (e.g "militier") - * The choice to handle plural form or not is thus under the hands of people ;) - * @see [defaultFromFHIRQuantityUnitToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromFHIRQuantityUnitToString.ts) for default implementation - * @see [FHIR definition of Quantity](https://build.fhir.org/datatypes.html#Quantity) for more info about the type itself - */ - fromFHIRQuantityUnitToString?: FromFHIRQuantityUnitToStringFct; - /** - * Function to turn a codeable concept (e.g SNOMED CT "311504000") into a string for humans (e.g "With or after food") - * The choice to handle extension, local valueset, ... is thus under the hands of people ;) - * @see [defaultFromCodeableConceptToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromCodeableConceptToString.ts) for default implementation - * @see [FHIR definition of CodeableConcept](https://build.fhir.org/datatypes.html#CodeableConcept) for more info about the type itself - */ - fromCodeableConceptToString?: FromCodeableConceptToStringFct; - /** - * Function to turn extension(s) into a string for humans. - * The choice to handle national extensions, ... is thus under the hands of people ;) - * @see [defaultFromExtensionsToString](https://github.com/jy95/fhir-dosage-utils/blob/main/src/utils/fromExtensionsToString.ts) for default implementation - * @see [FHIR definition of Extension](https://build.fhir.org/extensibility.html#Extension) for more info about the type itself - */ - fromExtensionsToString?: FromExtensionsToStringFct; - /** - * Control the display order used by the algorithm - * Useful when you want to turn on / off some specific rules for some reason - * @defaultValue ["method", "doseQuantity", "doseRange", "rateRatio", "rateQuantity", "rateRange", "durationDurationMax", "frequencyFrequencyMaxPeriodPeriodMax", "offsetWhen", "dayOfWeek", "timeOfDay", "route", "site", "asNeeded", "boundsDuration", "boundsPeriod", "boundsRange", "countCountMax", "event", "code", "maxDosePerPeriod", "maxDosePerAdministration", "maxDosePerLifetime", "additionalInstruction", "patientInstruction"] - * @see [DisplayOrderEnum](../enum/DisplayOrderEnum) for more info - */ - displayOrder?: DisplayOrder[]; - /** - * Override separator between each part of "Dosage" - * @defaultValue " - " - */ - displaySeparator?: string; - /** - * To control the formatting of dateTime objects. - * If not provided, will use the defaults according locale e.g. "20/01/2024" - * @defaultValue {} - * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options - */ - dateTimeFormatOptions?: Intl.DateTimeFormatOptions; -} - -// Config requires all parameter to be set -export type Config = Required; - -// Types for translations functions -export type DisplayOrderParams = { - dos: Dosage; - config: Config; - i18next: I18N; -}; -export type { I18N, InitOptions }; /** * Options for the i18next instances * @see https://www.i18next.com/overview/configuration-options for more info */ export type I18InitOptions = Exclude; -// Types for translation functions +export type { I18N, InitOptions }; +export type DisplayOrderParams = { + dos: Dosage; + config: Config; + i18next: I18N; +}; export type RangeParams = { range: Range; config: Config; diff --git a/src/utils/formatDatetimes.ts b/src/utils/formatDatetimes.ts index cb2f37b5..28b5a8a0 100644 --- a/src/utils/formatDatetimes.ts +++ b/src/utils/formatDatetimes.ts @@ -95,10 +95,8 @@ function fromDateToMappedDate(datetime: string): MappedDate { }; } -/** - * Generic function to map datetimes to user friendly date - * e.g. from 2018, 1973-06, 1905-08-23, 2015-02-07T13:28:17-05:00 or 2017-01-01T00:00:00.000Z - */ +// Generic function to map datetimes to user friendly date +// e.g. from 2018, 1973-06, 1905-08-23, 2015-02-07T13:28:17-05:00 or 2017-01-01T00:00:00.000Z export function formatDatetimes({ config, datetimes }: Args): string[] { const entries = datetimes.map(fromDateToMappedDate); diff --git a/src/utils/fromExtensionsToString.ts b/src/utils/fromExtensionsToString.ts index a3179162..169f99de 100644 --- a/src/utils/fromExtensionsToString.ts +++ b/src/utils/fromExtensionsToString.ts @@ -2,9 +2,6 @@ import { isArrayEmpty } from "../internal/isEmptyArray"; import type { Extension } from "../types"; -/** - * Function to turn extensions into a string for humans. - */ export type FromExtensionsToStringArgs = { language: string; extensions?: Extension[]; @@ -19,8 +16,5 @@ export function defaultFromExtensionsToString({ if (isArrayEmpty(extensions)) { return undefined; } - - // KIS implementation : print it as provided, without doing anything - // Extensions have so many cases btw, that having a basic function does the trick return extensions.map((extension) => JSON.stringify(extension)).join(" "); } diff --git a/src/utils/fromQuantityToString.ts b/src/utils/fromQuantityToString.ts index 8177bc7f..c6497364 100644 --- a/src/utils/fromQuantityToString.ts +++ b/src/utils/fromQuantityToString.ts @@ -29,6 +29,5 @@ export function fromQuantityToString({ } let comparatorString = i18next.t(`quantityComparator:${comparatorCode}`); - return `${comparatorString} ${quantityString}`; }