Skip to content

Commit

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

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

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

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

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

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

test("1 item", () => {
const dosage: Dosage = {
timing: {
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: {
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"],
displayOrder: ["extension", "timingExtension"],
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"],
displayOrder: ["extension", "timingExtension"],
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 @@ -159,6 +159,10 @@ export enum DisplayOrderEnum {
* Display "extension"
*/
extension = "extension",
/**
* Display "timing.extension"
*/
timingExtension = "timingExtension",
}

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 @@ -85,6 +85,11 @@ const displayOrders = {
}),
text: ({ dos }) => dos.text,
timeOfDay: (input) => transformTimeOfDayToText(input),
timingExtension: ({ dos, config }) =>
config.fromExtensionsToString({
language: config.language,
extensions: dos.timing?.extension,
}),
} satisfies Record<DisplayOrder, ResultFct>;

type fromDisplayOrderToResultFct = DisplayOrderParams & {
Expand Down

0 comments on commit 6ffbb55

Please sign in to comment.