@smile-cdr/fhirts 1.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,230 @@
1
+ import { Patient } from "../../FHIR-R4/classes/patient";
2
+ import { ResourceUtilities } from "./ResourceUtilities";
3
+
4
+ const inputPayload = require("./../../test-resources/Patient-R4.json");
5
+ describe("ResourceUtilities", () => {
6
+
7
+ describe("#getResourceProperty()", () => {
8
+ it('should return property if property exists in valid inputJson', () => {
9
+ // execute
10
+ const actual = ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
11
+ // validate
12
+ expect(actual).toBeFalse();
13
+ });
14
+
15
+ it('should return null if property exists in valid inputJson', () => {
16
+ // execute
17
+ const actual = ResourceUtilities.getResourceProperty(inputPayload, 'abcd');
18
+ // validate
19
+ expect(actual).toBeNull();
20
+ });
21
+
22
+ it('should return null if invalid inputJson is passed', () => {
23
+ // setup
24
+ const inputPayload = [1,2];
25
+ // execute
26
+ const actual = ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
27
+ // validate
28
+ expect(actual).toBeNull();
29
+ });
30
+ });
31
+
32
+ describe("#getIdentifiersByProperty()", () => {
33
+ const identifierList = [
34
+ {
35
+ use: "temp",
36
+ system: "http://hl7.org/fhir/sid/us-ssn",
37
+ value: "abc",
38
+ },
39
+ {
40
+ use: "usual",
41
+ system: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
42
+ value: "abc",
43
+ },
44
+ ];
45
+
46
+ it("should return empty array if null is passed as identifier list", () => {
47
+ // setup
48
+ const value = "abc";
49
+ // execute
50
+ const actual = ResourceUtilities.getIdentifiersByProperty(null, "abc", value);
51
+ // validate
52
+ expect(actual.length).toEqual(0);
53
+ });
54
+
55
+ it("should return empty array if property not found", () => {
56
+ // setup
57
+ const value = "abc";
58
+ // execute
59
+ const actual = ResourceUtilities.getIdentifiersByProperty(
60
+ identifierList,
61
+ "abc",
62
+ value
63
+ );
64
+ // validate
65
+ expect(actual.length).toEqual(0);
66
+ });
67
+
68
+ it("should return empty array if no matches found", () => {
69
+ // setup
70
+ const systemUrl = "http://somesystem.com";
71
+ // execute
72
+ const actual = ResourceUtilities.getIdentifiersByProperty(
73
+ identifierList,
74
+ "system",
75
+ systemUrl
76
+ );
77
+ // validate
78
+ expect(actual.length).toEqual(0);
79
+ });
80
+
81
+ it("should return array with all matches", () => {
82
+ // setup
83
+ const value = "abc";
84
+ // execute
85
+ const actual = ResourceUtilities.getIdentifiersByProperty(
86
+ identifierList,
87
+ "value",
88
+ value
89
+ );
90
+ // validate
91
+ expect(actual.length).toEqual(2);
92
+ });
93
+ });
94
+
95
+ describe("#getExtensionsByUrl()", () => {
96
+ const extensionList = [
97
+ {
98
+ url: "http://hl7.org/fhir/sid/us-ssn",
99
+ valueBoolean: true,
100
+ },
101
+ {
102
+ url: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
103
+ valueString: "abc",
104
+ },
105
+ ];
106
+
107
+ it("should return empty array if null is passed as extension list", () => {
108
+ // execute
109
+ const actual = ResourceUtilities.getExtensionsByUrl(null, "url");
110
+ // validate
111
+ expect(actual.length).toEqual(0);
112
+ });
113
+
114
+ it("should return empty array if invalid extension array passed", () => {
115
+ // setup
116
+ const extensionListInvalid = [
117
+ {
118
+ use: "temp",
119
+ system: "http://hl7.org/fhir/sid/us-ssn",
120
+ value: "abc",
121
+ },
122
+ ];
123
+ const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
124
+ // execute
125
+ const actual = ResourceUtilities.getExtensionsByUrl(
126
+ extensionListInvalid,
127
+ url
128
+ );
129
+ // validate
130
+ expect(actual.length).toEqual(0);
131
+ });
132
+
133
+ it("should return empty array if no matches found", () => {
134
+ // setup
135
+ const url = "http://somesystem.com";
136
+ // execute
137
+ const actual = ResourceUtilities.getExtensionsByUrl(extensionList, url);
138
+ // validate
139
+ expect(actual.length).toEqual(0);
140
+ });
141
+
142
+ it("should return array with all matches", () => {
143
+ // setup
144
+ const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
145
+ // execute
146
+ const actual = ResourceUtilities.getExtensionsByUrl(extensionList, url);
147
+ // validate
148
+ expect(actual.length).toEqual(1);
149
+ });
150
+ });
151
+
152
+ describe("#getCodingsByProperty()", () => {
153
+ const codingList = [
154
+ {
155
+ version: "1.0",
156
+ system: "http://hl7.org/fhir/sid/us-ssn",
157
+ code: "abc",
158
+ display: "abc",
159
+ userSelected: false,
160
+ },
161
+ {
162
+ version: "1.1",
163
+ system: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
164
+ code: "abc",
165
+ display: "abc",
166
+ },
167
+ ];
168
+
169
+ it("should return empty array if null is passed as coding list", () => {
170
+ // setup
171
+ const value = "abc";
172
+ // execute
173
+ const actual = ResourceUtilities.getCodingsByProperty(null, "abc", value);
174
+ // validate
175
+ expect(actual.length).toEqual(0);
176
+ });
177
+
178
+ it("should return empty array if property not found", () => {
179
+ // setup
180
+ const value = "abc";
181
+ // execute
182
+ const actual = ResourceUtilities.getCodingsByProperty(
183
+ codingList,
184
+ "abc",
185
+ value
186
+ );
187
+ // validate
188
+ expect(actual.length).toEqual(0);
189
+ });
190
+
191
+ it("should return empty array if no matches found", () => {
192
+ // setup
193
+ const systemUrl = "http://somesystem.com";
194
+ // execute
195
+ const actual = ResourceUtilities.getCodingsByProperty(
196
+ codingList,
197
+ "system",
198
+ systemUrl
199
+ );
200
+ // validate
201
+ expect(actual.length).toEqual(0);
202
+ });
203
+
204
+ it("should return array with all matches for string values", () => {
205
+ // setup
206
+ const value = "abc";
207
+ // execute
208
+ const actual = ResourceUtilities.getCodingsByProperty(
209
+ codingList,
210
+ "code",
211
+ value
212
+ );
213
+ // validate
214
+ expect(actual.length).toEqual(2);
215
+ });
216
+
217
+ it("should return array with all matches for boolean values", () => {
218
+ // setup
219
+ const value = false;
220
+ // execute
221
+ const actual = ResourceUtilities.getCodingsByProperty(
222
+ codingList,
223
+ "userSelected",
224
+ value
225
+ );
226
+ // validate
227
+ expect(actual.length).toEqual(1);
228
+ });
229
+ });
230
+ });
@@ -0,0 +1,52 @@
1
+ export class ResourceUtility {
2
+
3
+ /**
4
+ *
5
+ * @param inputJson - valid json
6
+ * @param propertyName - top level property for resource
7
+ * @returns json property if it exists
8
+ * @limitation currently just supports get for top level property on resource
9
+ */
10
+ getResourceProperty(inputJson: object, propertyName: string) {
11
+ let resourcePropertyValue = null;
12
+ if (inputJson.hasOwnProperty(propertyName)) {
13
+ resourcePropertyValue = inputJson[propertyName];
14
+ }
15
+ return resourcePropertyValue;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param identifierList list of identifiers
21
+ * @param propertyToCompare identifier property to compare
22
+ * @param propertyValue value we want to compare against
23
+ * @returns array of matches
24
+ * @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
25
+ */
26
+ getIdentifiersByProperty(identifierList: any[], propertyToCompare: string, propertyValue: string): any[] {
27
+ return identifierList?.length ? identifierList.filter(x => x[propertyToCompare] === propertyValue): [];
28
+ }
29
+
30
+ /**
31
+ *
32
+ * @param extensionList list of extensions
33
+ * @param extensionUrl Extension.url to compare
34
+ * @returns array of matches
35
+ */
36
+ getExtensionsByUrl(extensionList: any[], extensionUrl: string): any[] {
37
+ return extensionList?.length ? extensionList.filter(x => x['url'] === extensionUrl) : [];
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @param codingList list of codings
43
+ * @param propertyToCompare coding property to compare
44
+ * @param propertyValue value we want to compare against string or boolean
45
+ * @returns array of matches
46
+ */
47
+ getCodingsByProperty(codingList: any[], propertyToCompare: string, propertyValue: string | boolean): any[] {
48
+ return codingList?.length ? codingList.filter(x => x[propertyToCompare] === propertyValue) : [];
49
+ }
50
+ }
51
+
52
+ export const ResourceUtilities = new ResourceUtility();