diff --git a/__tests__/fromDosageToText/rateQuantity.test.tsx b/__tests__/fromDosageToText/rateQuantity.test.tsx new file mode 100644 index 00000000..8af2902e --- /dev/null +++ b/__tests__/fromDosageToText/rateQuantity.test.tsx @@ -0,0 +1,50 @@ +// For typings autocomplete whatever your IDE +import { expect, test, describe } from "@jest/globals"; +import FhirDosageUtils from "../../src/index"; + +// types +import type { Dosage } from "fhir/r4"; + +describe("fromDosageToText - rateQuantity", () => { + let dosageUtils: FhirDosageUtils; + + beforeAll(async () => { + dosageUtils = await FhirDosageUtils.build({ + displayOrder: ["rateQuantity"], + }); + }); + + test("No rateQuantity", () => { + const dosage: Dosage = { + text: "no rateQuantity", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("Empty", () => { + const dosage: Dosage = { + doseAndRate: [], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("Simple case", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateQuantity: { + value: 3, + unit: "pills", + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 3 pills"); + }); +}); diff --git a/__tests__/fromDosageToText/rateRange.test.tsx b/__tests__/fromDosageToText/rateRange.test.tsx new file mode 100644 index 00000000..0b89f983 --- /dev/null +++ b/__tests__/fromDosageToText/rateRange.test.tsx @@ -0,0 +1,83 @@ +// For typings autocomplete whatever your IDE +import { expect, test, describe } from "@jest/globals"; +import FhirDosageUtils from "../../src/index"; + +// types +import type { Dosage } from "fhir/r4"; + +describe("fromDosageToText - rateRange", () => { + let dosageUtils: FhirDosageUtils; + + beforeAll(async () => { + dosageUtils = await FhirDosageUtils.build({ + displayOrder: ["rateRange"], + }); + }); + + test("No rateRange", () => { + const dosage: Dosage = { + text: "no rateRange", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("high and low", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRange: { + low: { + value: 3, + unit: "pills", + }, + high: { + value: 5, + unit: "pills", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 3 to 5 pills"); + }); + + test("high only", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRange: { + high: { + value: 5, + unit: "pills", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 5 pills"); + }); + + test("low only", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRange: { + low: { + value: 3, + unit: "pills", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 3 pills"); + }); +}); diff --git a/__tests__/fromDosageToText/rateRatio.test.tsx b/__tests__/fromDosageToText/rateRatio.test.tsx new file mode 100644 index 00000000..eca68a03 --- /dev/null +++ b/__tests__/fromDosageToText/rateRatio.test.tsx @@ -0,0 +1,86 @@ +// For typings autocomplete whatever your IDE +import { expect, test, describe } from "@jest/globals"; +import FhirDosageUtils from "../../src/index"; + +// types +import type { Dosage } from "fhir/r4"; + +describe("fromDosageToText - rateRatio", () => { + let dosageUtils: FhirDosageUtils; + + beforeAll(async () => { + dosageUtils = await FhirDosageUtils.build({ + displayOrder: ["rateRatio"], + }); + }); + + test("No rateRatio", () => { + const dosage: Dosage = { + text: "no rateRatio", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("numerator and denominator", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRatio: { + numerator: { + value: 3, + unit: "pills", + }, + denominator: { + value: 5, + unit: "hours", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 3 pills every 5 hours"); + }); + + test("no numerator", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRatio: { + denominator: { + value: 5, + unit: "hours", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 1 every 5 hours"); + }); + + test("no denominator value", () => { + const dosage: Dosage = { + doseAndRate: [ + { + rateRatio: { + numerator: { + value: 3, + unit: "pills", + }, + denominator: { + unit: "hour", + }, + }, + }, + ], + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at a rate of 3 pills per hour"); + }); +});