Skip to content

Commit

Permalink
test: rateQuantity / rateRange / rateRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed Mar 25, 2024
1 parent fa883d5 commit ba03be1
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 0 deletions.
50 changes: 50 additions & 0 deletions __tests__/fromDosageToText/rateQuantity.test.tsx
Original file line number Diff line number Diff line change
@@ -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");
});
});
83 changes: 83 additions & 0 deletions __tests__/fromDosageToText/rateRange.test.tsx
Original file line number Diff line number Diff line change
@@ -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");
});
});
86 changes: 86 additions & 0 deletions __tests__/fromDosageToText/rateRatio.test.tsx
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit ba03be1

Please sign in to comment.