-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathextension-profile.test.ts
More file actions
85 lines (73 loc) · 3.76 KB
/
extension-profile.test.ts
File metadata and controls
85 lines (73 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* FHIR R4 Extension Profile Tests
*
* Tests generated extension profile classes: static factory methods and resource wrapping.
*/
import { expect, test } from "bun:test";
import type { HumanName } from "./fhir-types/hl7-fhir-r4-core/HumanName";
import type { Patient } from "./fhir-types/hl7-fhir-r4-core/Patient";
import { birthPlaceProfile } from "./fhir-types/hl7-fhir-r4-core/profiles/Extension_birthPlace";
import { birthTimeProfile } from "./fhir-types/hl7-fhir-r4-core/profiles/Extension_birthTime";
import { nationalityProfile } from "./fhir-types/hl7-fhir-r4-core/profiles/Extension_nationality";
import { own_prefixProfile } from "./fhir-types/hl7-fhir-r4-core/profiles/Extension_own_prefix";
test("Patient with extensions built from profiles", () => {
const name: HumanName = {
family: "van Beethoven",
_family: {
extension: [own_prefixProfile.createResource({ valueString: "van" })],
},
given: ["Ludwig"],
};
const patient: Patient = {
resourceType: "Patient",
extension: [birthPlaceProfile.createResource({ valueAddress: { city: "Bonn", country: "DE" } })],
birthDate: "1770-12-17",
_birthDate: {
extension: [birthTimeProfile.createResource({ valueDateTime: "1770-12-17T12:00:00+01:00" })],
},
name: [name],
};
expect(patient).toMatchSnapshot();
});
test("apply() wraps existing resource", () => {
const ext = birthPlaceProfile.createResource({ valueAddress: { city: "Boston" } });
const profile = birthPlaceProfile.apply(ext);
expect(profile.toResource()).toBe(ext);
});
test("createResource() sets url and required value (Address)", () => {
const resource = birthPlaceProfile.createResource({ valueAddress: { city: "Boston", country: "US" } });
expect(resource.url).toBe("http://hl7.org/fhir/StructureDefinition/patient-birthPlace");
expect(resource.valueAddress).toEqual({ city: "Boston", country: "US" });
});
test("createResource() sets url and required value (string)", () => {
const resource = own_prefixProfile.createResource({ valueString: "van" });
expect(resource.url).toBe("http://hl7.org/fhir/StructureDefinition/humanname-own-prefix");
expect(resource.valueString).toBe("van");
});
test("createResource() sets url and required value (dateTime)", () => {
const resource = birthTimeProfile.createResource({ valueDateTime: "1990-03-15T08:22:00-05:00" });
expect(resource.url).toBe("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
expect(resource.valueDateTime).toBe("1990-03-15T08:22:00-05:00");
});
test("createResource() with no required params sets only url", () => {
const resource = nationalityProfile.createResource();
expect(resource.url).toBe("http://hl7.org/fhir/StructureDefinition/patient-nationality");
});
test("create() returns profile wrapping new resource", () => {
const profile = birthPlaceProfile.create({ valueAddress: { city: "Vienna" } });
const resource = profile.toResource();
expect(resource.url).toBe("http://hl7.org/fhir/StructureDefinition/patient-birthPlace");
expect(resource.valueAddress).toEqual({ city: "Vienna" });
});
test("create() with no required params", () => {
const profile = nationalityProfile.create();
expect(profile.toResource().url).toBe("http://hl7.org/fhir/StructureDefinition/patient-nationality");
});
test("is() matches extensions by url", () => {
const ext = birthPlaceProfile.createResource({ valueAddress: { city: "Bonn" } });
expect(birthPlaceProfile.is(ext)).toBe(true);
expect(birthTimeProfile.is(ext)).toBe(false);
expect(birthPlaceProfile.is({ url: "http://example.com/other" })).toBe(false);
expect(birthPlaceProfile.is(null)).toBe(false);
expect(birthPlaceProfile.is("not an object")).toBe(false);
});