Skip to content

Commit

Permalink
Merge pull request #46 from jy95/timingRepeatExtension
Browse files Browse the repository at this point in the history
feat: timingRepeatExtension
  • Loading branch information
jy95 authored Apr 27, 2024
2 parents 6ffbb55 + cef3344 commit e19ff21
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
84 changes: 84 additions & 0 deletions __tests__/fromDosageToText/timingRepeatExtension.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 - timingRepeatExtension", () => {
let dosageUtils: FhirDosageUtils;

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

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

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

test("Empty", () => {
const dosage: Dosage = {
timing: {
repeat: {
extension: [],
},
},
};

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

test("1 item", () => {
const dosage: Dosage = {
timing: {
repeat: {
extension: [
{
url: "https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverride",
valueBoolean: true,
},
],
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe(
'{"url":"https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverride","valueBoolean":true}',
);
});

test("N+1 items", () => {
const dosage: Dosage = {
timing: {
repeat: {
extension: [
{
url: "https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverride",
valueBoolean: true,
},
{
url: "https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverrideReason",
valueCodeableConcept: {
text: "Respect my authority ! - Eric Cartman",
},
},
],
},
},
};

let result = dosageUtils.fromDosageToText(dosage);
expect(result).toBe(
'{"url":"https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverride","valueBoolean":true} {"url":"https://www.ehealth.fgov.be/standards/fhir/medication/StructureDefinition/DosageOverrideReason","valueCodeableConcept":{"text":"Respect my authority ! - Eric Cartman"}}',
);
});
});
4 changes: 2 additions & 2 deletions documentation/docs/custom/fromExtensionsToString.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text";
<SingleDosageToText
dosage={Schema}
config={{
displayOrder: ["extension", "timingExtension"],
displayOrder: ["extension", "timingExtension", "timingRepeatExtension"],
fromExtensionsToString: ({extensions, language}) => {
// If no extensions, skip it
if (extensions === undefined || extensions.length === 0) {
Expand Down Expand Up @@ -46,7 +46,7 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text";
<TabItem value="config" label="Configuration">
```js
{
displayOrder: ["extension", "timingExtension"],
displayOrder: ["extension", "timingExtension", "timingRepeatExtension"],
fromExtensionsToString: ({extensions, language}) => {
// If no extensions, skip it
if (extensions === undefined || extensions.length === 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export enum DisplayOrderEnum {
* Display "timing.extension"
*/
timingExtension = "timingExtension",
/**
* Display "timing.repeat.extension"
*/
timingRepeatExtension = "timingRepeatExtension",
}

export type DisplayOrder = keyof typeof DisplayOrderEnum;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/fromDisplayOrderToResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ const displayOrders = {
language: config.language,
extensions: dos.timing?.extension,
}),
timingRepeatExtension: ({ dos, config }) =>
config.fromExtensionsToString({
language: config.language,
extensions: dos.timing?.repeat?.extension,
}),
} satisfies Record<DisplayOrder, ResultFct>;

type fromDisplayOrderToResultFct = DisplayOrderParams & {
Expand Down

0 comments on commit e19ff21

Please sign in to comment.