Skip to content

Commit

Permalink
test: timeOfDay / patientInstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed Mar 25, 2024
1 parent ba03be1 commit 56d3012
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
34 changes: 34 additions & 0 deletions __tests__/fromDosageToText/patientInstruction.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 - patientInstruction", () => {
let dosageUtils: FhirDosageUtils;

beforeAll(async () => {
dosageUtils = await FhirDosageUtils.build({
displayOrder: ["patientInstruction"],
});
});

test("No patientInstruction", () => {
const dosage: Dosage = {
text: "no patientInstruction",
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("Simple case", () => {
const dosage: Dosage = {
patientInstruction: "patientInstruction",
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("patientInstruction");
});
});
64 changes: 64 additions & 0 deletions __tests__/fromDosageToText/timeOfDay.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 - timeOfDay", () => {
let dosageUtils: FhirDosageUtils;

beforeAll(async () => {
dosageUtils = await FhirDosageUtils.build({
displayOrder: ["timeOfDay"],
});
});

test("No timeOfDay", () => {
const dosage: Dosage = {
text: "no timeOfDay",
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("timeOfDay - empty", () => {
const dosage: Dosage = {
timing: {
repeat: {
timeOfDay: [],
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("");
});

test("timeOfDay - 1 item", () => {
const dosage: Dosage = {
timing: {
repeat: {
timeOfDay: ["15:00:00"],
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at 15:00");
});

test("timeOfDay - N+1 items", () => {
const dosage: Dosage = {
timing: {
repeat: {
timeOfDay: ["15:00:00", "12:12:12"],
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe("at 15:00 and 12:12:12");
});
});

0 comments on commit 56d3012

Please sign in to comment.