@smile-cdr/fhirts 2.0.6 → 2.1.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.
- package/CHANGELOG.md +6 -0
- package/GETTINGSTARTED.md +40 -1
- package/dist/FHIR-R4/classes/bundle.d.ts +16 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/library/BundleUtils/BundleUtils.d.ts +16 -0
- package/dist/library/BundleUtils/BundleUtils.js +24 -0
- package/dist/library/BundleUtils/BundleUtils.spec.js +47 -0
- package/dist/library/{ResourceUtilities/ResourceUtilities.d.ts → ResourceUtils/ResourceUtils.d.ts} +14 -2
- package/dist/library/ResourceUtils/ResourceUtils.js +115 -0
- package/dist/library/{ResourceUtilities/ResourceUtilities.spec.js → ResourceUtils/ResourceUtils.spec.js} +72 -22
- package/package.json +1 -1
- package/src/FHIR-R4/classes/bundle.ts +16 -1
- package/src/index.ts +3 -3
- package/src/library/BundleUtils/BundleUtils.spec.ts +65 -0
- package/src/library/BundleUtils/BundleUtils.ts +26 -0
- package/src/library/{ResourceUtilities/ResourceUtilities.spec.ts → ResourceUtils/ResourceUtils.spec.ts} +96 -24
- package/src/library/ResourceUtils/ResourceUtils.ts +124 -0
- package/src/test-resources/CareTeam-R4.json +85 -0
- package/src/test-resources/Patient-R4.json +4 -0
- package/dist/library/BundleUtilities/BundleUtilities.d.ts +0 -10
- package/dist/library/BundleUtilities/BundleUtilities.js +0 -16
- package/dist/library/BundleUtilities/BundleUtilities.spec.js +0 -26
- package/dist/library/ResourceUtilities/ResourceUtilities.js +0 -51
- package/src/library/BundleUtilities/BundleUtilities.spec.ts +0 -28
- package/src/library/BundleUtilities/BundleUtilities.ts +0 -16
- package/src/library/ResourceUtilities/ResourceUtilities.ts +0 -52
- /package/dist/library/{BundleUtilities/BundleUtilities.spec.d.ts → BundleUtils/BundleUtils.spec.d.ts} +0 -0
- /package/dist/library/{ResourceUtilities/ResourceUtilities.spec.d.ts → ResourceUtils/ResourceUtils.spec.d.ts} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BundleUtils } from "./BundleUtils";
|
|
2
|
+
|
|
3
|
+
const inputPayload = require("./../../test-resources/Bundle-R4.json");
|
|
4
|
+
describe("BundleUtils", () => {
|
|
5
|
+
|
|
6
|
+
let bundleUtils = new BundleUtils();
|
|
7
|
+
|
|
8
|
+
describe("#getResources()", () => {
|
|
9
|
+
it("should return empty array if null is passed as bundle entries", () => {
|
|
10
|
+
// execute
|
|
11
|
+
const actual = bundleUtils.getResources(null, "Patient");
|
|
12
|
+
// validate
|
|
13
|
+
expect(actual.length).toEqual(0);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should return empty array if invalid resourceType is passed", () => {
|
|
17
|
+
// execute
|
|
18
|
+
const actual = bundleUtils.getResources(
|
|
19
|
+
inputPayload.entry,
|
|
20
|
+
"patient"
|
|
21
|
+
);
|
|
22
|
+
// validate
|
|
23
|
+
expect(actual.length).toEqual(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should return all matches array", () => {
|
|
27
|
+
// execute
|
|
28
|
+
const actual = bundleUtils.getResources(
|
|
29
|
+
inputPayload.entry,
|
|
30
|
+
"Claim"
|
|
31
|
+
);
|
|
32
|
+
// validate
|
|
33
|
+
expect(actual.length).toEqual(27);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("#getResource()", () => {
|
|
38
|
+
it("should return null if null is passed as bundle entries", () => {
|
|
39
|
+
// execute
|
|
40
|
+
const actual = bundleUtils.getResource(null, "123");
|
|
41
|
+
// validate
|
|
42
|
+
expect(actual).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should return undefined if resourceId is not found", () => {
|
|
46
|
+
// execute
|
|
47
|
+
const actual = bundleUtils.getResource(
|
|
48
|
+
inputPayload.entry,
|
|
49
|
+
"123"
|
|
50
|
+
);
|
|
51
|
+
// validate
|
|
52
|
+
expect(actual).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should return resource if resource is found", () => {
|
|
56
|
+
// execute
|
|
57
|
+
const actual = bundleUtils.getResource(
|
|
58
|
+
inputPayload.entry,
|
|
59
|
+
"ec0bb1b3-b229-36cf-7e34-3f5fec9d3afe"
|
|
60
|
+
);
|
|
61
|
+
// validate
|
|
62
|
+
expect(actual).not.toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class BundleUtils {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
|
|
6
|
+
* @param resourceTypeToFilter ResourceType to filter from bundle entries
|
|
7
|
+
* @returns array of resources
|
|
8
|
+
*/
|
|
9
|
+
getResources(bundleEntry: any[], resourceTypeToFilter: string): any[] {
|
|
10
|
+
return bundleEntry?.length ? bundleEntry.filter(x => x['resource']['resourceType'] === resourceTypeToFilter) : [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
|
|
16
|
+
* @param resourceId Resource ID to filter from bundle entries
|
|
17
|
+
* @returns single resource
|
|
18
|
+
*/
|
|
19
|
+
getResource(bundleEntry: any[], resourceId: string): any {
|
|
20
|
+
return bundleEntry?.length ? bundleEntry.find(x => x['resource']['id'] === resourceId) : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ResourceUtilities } from "./ResourceUtilities";
|
|
1
|
+
import { ResourceUtils } from "./ResourceUtils";
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
const patientPayload = require("./../../test-resources/Patient-R4.json");
|
|
4
|
+
const careTeamPayload = require("./../../test-resources/CareTeam-R4.json");
|
|
5
|
+
describe("ResourceUtils", () => {
|
|
6
|
+
|
|
7
|
+
let resourceUtils = new ResourceUtils();
|
|
6
8
|
|
|
7
9
|
describe("#getResourceProperty()", () => {
|
|
8
|
-
it(
|
|
10
|
+
it("should return property if property exists in valid inputJson", () => {
|
|
9
11
|
// execute
|
|
10
|
-
const actual =
|
|
12
|
+
const actual = resourceUtils.getResourceProperty(
|
|
13
|
+
patientPayload,
|
|
14
|
+
"deceasedBoolean"
|
|
15
|
+
);
|
|
11
16
|
// validate
|
|
12
17
|
expect(actual).toBeFalse();
|
|
13
18
|
});
|
|
14
19
|
|
|
15
|
-
it(
|
|
20
|
+
it("should return null if property exists in valid inputJson", () => {
|
|
16
21
|
// execute
|
|
17
|
-
const actual =
|
|
22
|
+
const actual = resourceUtils.getResourceProperty(
|
|
23
|
+
patientPayload,
|
|
24
|
+
"abcd"
|
|
25
|
+
);
|
|
18
26
|
// validate
|
|
19
27
|
expect(actual).toBeNull();
|
|
20
28
|
});
|
|
21
29
|
|
|
22
|
-
it(
|
|
30
|
+
it("should return null if invalid inputJson is passed", () => {
|
|
23
31
|
// setup
|
|
24
|
-
const inputPayload = [1,2];
|
|
32
|
+
const inputPayload = [1, 2];
|
|
25
33
|
// execute
|
|
26
|
-
const actual =
|
|
34
|
+
const actual = resourceUtils.getResourceProperty(
|
|
35
|
+
inputPayload,
|
|
36
|
+
"deceasedBoolean"
|
|
37
|
+
);
|
|
27
38
|
// validate
|
|
28
39
|
expect(actual).toBeNull();
|
|
29
40
|
});
|
|
@@ -47,7 +58,11 @@ describe("ResourceUtilities", () => {
|
|
|
47
58
|
// setup
|
|
48
59
|
const value = "abc";
|
|
49
60
|
// execute
|
|
50
|
-
const actual =
|
|
61
|
+
const actual = resourceUtils.getIdentifiersByProperty(
|
|
62
|
+
null,
|
|
63
|
+
"abc",
|
|
64
|
+
value
|
|
65
|
+
);
|
|
51
66
|
// validate
|
|
52
67
|
expect(actual.length).toEqual(0);
|
|
53
68
|
});
|
|
@@ -56,7 +71,7 @@ describe("ResourceUtilities", () => {
|
|
|
56
71
|
// setup
|
|
57
72
|
const value = "abc";
|
|
58
73
|
// execute
|
|
59
|
-
const actual =
|
|
74
|
+
const actual = resourceUtils.getIdentifiersByProperty(
|
|
60
75
|
identifierList,
|
|
61
76
|
"abc",
|
|
62
77
|
value
|
|
@@ -69,7 +84,7 @@ describe("ResourceUtilities", () => {
|
|
|
69
84
|
// setup
|
|
70
85
|
const systemUrl = "http://somesystem.com";
|
|
71
86
|
// execute
|
|
72
|
-
const actual =
|
|
87
|
+
const actual = resourceUtils.getIdentifiersByProperty(
|
|
73
88
|
identifierList,
|
|
74
89
|
"system",
|
|
75
90
|
systemUrl
|
|
@@ -82,7 +97,7 @@ describe("ResourceUtilities", () => {
|
|
|
82
97
|
// setup
|
|
83
98
|
const value = "abc";
|
|
84
99
|
// execute
|
|
85
|
-
const actual =
|
|
100
|
+
const actual = resourceUtils.getIdentifiersByProperty(
|
|
86
101
|
identifierList,
|
|
87
102
|
"value",
|
|
88
103
|
value
|
|
@@ -106,7 +121,7 @@ describe("ResourceUtilities", () => {
|
|
|
106
121
|
|
|
107
122
|
it("should return empty array if null is passed as extension list", () => {
|
|
108
123
|
// execute
|
|
109
|
-
const actual =
|
|
124
|
+
const actual = resourceUtils.getExtensionsByUrl(null, "url");
|
|
110
125
|
// validate
|
|
111
126
|
expect(actual.length).toEqual(0);
|
|
112
127
|
});
|
|
@@ -122,7 +137,7 @@ describe("ResourceUtilities", () => {
|
|
|
122
137
|
];
|
|
123
138
|
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
124
139
|
// execute
|
|
125
|
-
const actual =
|
|
140
|
+
const actual = resourceUtils.getExtensionsByUrl(
|
|
126
141
|
extensionListInvalid,
|
|
127
142
|
url
|
|
128
143
|
);
|
|
@@ -134,7 +149,7 @@ describe("ResourceUtilities", () => {
|
|
|
134
149
|
// setup
|
|
135
150
|
const url = "http://somesystem.com";
|
|
136
151
|
// execute
|
|
137
|
-
const actual =
|
|
152
|
+
const actual = resourceUtils.getExtensionsByUrl(extensionList, url);
|
|
138
153
|
// validate
|
|
139
154
|
expect(actual.length).toEqual(0);
|
|
140
155
|
});
|
|
@@ -143,7 +158,7 @@ describe("ResourceUtilities", () => {
|
|
|
143
158
|
// setup
|
|
144
159
|
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
145
160
|
// execute
|
|
146
|
-
const actual =
|
|
161
|
+
const actual = resourceUtils.getExtensionsByUrl(extensionList, url);
|
|
147
162
|
// validate
|
|
148
163
|
expect(actual.length).toEqual(1);
|
|
149
164
|
});
|
|
@@ -170,7 +185,7 @@ describe("ResourceUtilities", () => {
|
|
|
170
185
|
// setup
|
|
171
186
|
const value = "abc";
|
|
172
187
|
// execute
|
|
173
|
-
const actual =
|
|
188
|
+
const actual = resourceUtils.getCodingsByProperty(null, "abc", value);
|
|
174
189
|
// validate
|
|
175
190
|
expect(actual.length).toEqual(0);
|
|
176
191
|
});
|
|
@@ -179,7 +194,7 @@ describe("ResourceUtilities", () => {
|
|
|
179
194
|
// setup
|
|
180
195
|
const value = "abc";
|
|
181
196
|
// execute
|
|
182
|
-
const actual =
|
|
197
|
+
const actual = resourceUtils.getCodingsByProperty(
|
|
183
198
|
codingList,
|
|
184
199
|
"abc",
|
|
185
200
|
value
|
|
@@ -192,7 +207,7 @@ describe("ResourceUtilities", () => {
|
|
|
192
207
|
// setup
|
|
193
208
|
const systemUrl = "http://somesystem.com";
|
|
194
209
|
// execute
|
|
195
|
-
const actual =
|
|
210
|
+
const actual = resourceUtils.getCodingsByProperty(
|
|
196
211
|
codingList,
|
|
197
212
|
"system",
|
|
198
213
|
systemUrl
|
|
@@ -205,7 +220,7 @@ describe("ResourceUtilities", () => {
|
|
|
205
220
|
// setup
|
|
206
221
|
const value = "abc";
|
|
207
222
|
// execute
|
|
208
|
-
const actual =
|
|
223
|
+
const actual = resourceUtils.getCodingsByProperty(
|
|
209
224
|
codingList,
|
|
210
225
|
"code",
|
|
211
226
|
value
|
|
@@ -218,7 +233,7 @@ describe("ResourceUtilities", () => {
|
|
|
218
233
|
// setup
|
|
219
234
|
const value = false;
|
|
220
235
|
// execute
|
|
221
|
-
const actual =
|
|
236
|
+
const actual = resourceUtils.getCodingsByProperty(
|
|
222
237
|
codingList,
|
|
223
238
|
"userSelected",
|
|
224
239
|
value
|
|
@@ -227,4 +242,61 @@ describe("ResourceUtilities", () => {
|
|
|
227
242
|
expect(actual.length).toEqual(1);
|
|
228
243
|
});
|
|
229
244
|
});
|
|
245
|
+
|
|
246
|
+
describe("#getValuesAtResourcePath()", () => {
|
|
247
|
+
|
|
248
|
+
it("should return array with values if path exists for a top level element", () => {
|
|
249
|
+
// execute
|
|
250
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
|
|
251
|
+
// validate
|
|
252
|
+
expect(pathValues.length).toEqual(1);
|
|
253
|
+
expect(pathValues[0]).toEqual("male");
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("should return array with values if path exists for a deep array element", () => {
|
|
257
|
+
// execute
|
|
258
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.contact.relationship.coding.system");
|
|
259
|
+
// validate
|
|
260
|
+
expect(pathValues.length).toEqual(2);
|
|
261
|
+
expect(pathValues[0]).toEqual("http://terminology.hl7.org/CodeSystem/v2-0131");
|
|
262
|
+
expect(pathValues[1]).toEqual("http://terminology.hl7.org/CodeSystem/v2-0132");
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("should return array with values if path exists for a deep json element", () => {
|
|
266
|
+
// execute
|
|
267
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.maritalStatus.coding.system");
|
|
268
|
+
// validate
|
|
269
|
+
expect(pathValues.length).toEqual(1);
|
|
270
|
+
expect(pathValues[0]).toEqual("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("should return empty array if path does not exist", () => {
|
|
274
|
+
// execute
|
|
275
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.contact.relationship.coding.abcd");
|
|
276
|
+
// validate
|
|
277
|
+
expect(pathValues.length).toEqual(0);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe("#getAllResourceReferences()", () => {
|
|
282
|
+
|
|
283
|
+
it("should return array of all references in a resource when references found", () => {
|
|
284
|
+
// execute
|
|
285
|
+
const actual = resourceUtils.getAllReferencesFromResource(careTeamPayload);
|
|
286
|
+
// validate
|
|
287
|
+
expect(actual.length).toEqual(6);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should return empty array if references in a resource not found", () => {
|
|
291
|
+
// setup
|
|
292
|
+
const input = {
|
|
293
|
+
"resourceType": "Patient"
|
|
294
|
+
};
|
|
295
|
+
// execute
|
|
296
|
+
const actual = resourceUtils.getAllReferencesFromResource(input);
|
|
297
|
+
// validate
|
|
298
|
+
expect(actual.length).toEqual(0);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
});
|
|
230
302
|
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export class ResourceUtils {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param inputJson - valid json
|
|
5
|
+
* @param propertyName - top level property for resource
|
|
6
|
+
* @returns json property if it exists
|
|
7
|
+
* @limitation currently just supports get for top level property on resource
|
|
8
|
+
*/
|
|
9
|
+
getResourceProperty(inputJson: object, propertyName: string) {
|
|
10
|
+
let resourcePropertyValue = null;
|
|
11
|
+
if (inputJson.hasOwnProperty(propertyName)) {
|
|
12
|
+
resourcePropertyValue = inputJson[propertyName];
|
|
13
|
+
}
|
|
14
|
+
return resourcePropertyValue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param identifierList list of identifiers
|
|
20
|
+
* @param propertyToCompare identifier property to compare
|
|
21
|
+
* @param propertyValue value we want to compare against
|
|
22
|
+
* @returns array of matches
|
|
23
|
+
* @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
|
|
24
|
+
*/
|
|
25
|
+
getIdentifiersByProperty(
|
|
26
|
+
identifierList: any[],
|
|
27
|
+
propertyToCompare: string,
|
|
28
|
+
propertyValue: string
|
|
29
|
+
): any[] {
|
|
30
|
+
return identifierList?.length
|
|
31
|
+
? identifierList.filter((x) => x[propertyToCompare] === propertyValue)
|
|
32
|
+
: [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param extensionList list of extensions
|
|
38
|
+
* @param extensionUrl Extension.url to compare
|
|
39
|
+
* @returns array of matches
|
|
40
|
+
*/
|
|
41
|
+
getExtensionsByUrl(extensionList: any[], extensionUrl: string): any[] {
|
|
42
|
+
return extensionList?.length
|
|
43
|
+
? extensionList.filter((x) => x["url"] === extensionUrl)
|
|
44
|
+
: [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param codingList list of codings
|
|
50
|
+
* @param propertyToCompare coding property to compare
|
|
51
|
+
* @param propertyValue value we want to compare against string or boolean
|
|
52
|
+
* @returns array of matches
|
|
53
|
+
*/
|
|
54
|
+
getCodingsByProperty(
|
|
55
|
+
codingList: any[],
|
|
56
|
+
propertyToCompare: string,
|
|
57
|
+
propertyValue: string | boolean
|
|
58
|
+
): any[] {
|
|
59
|
+
return codingList?.length
|
|
60
|
+
? codingList.filter((x) => x[propertyToCompare] === propertyValue)
|
|
61
|
+
: [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param resource resource for which path needs to be validated
|
|
67
|
+
* @param elementPath path to validate in resource
|
|
68
|
+
* @returns array of elements found at the provided path
|
|
69
|
+
*/
|
|
70
|
+
getValuesAtResourcePath(resource: any, elementPath: string): any[] {
|
|
71
|
+
const pathSections = elementPath.split(".");
|
|
72
|
+
let resourcePathValue;
|
|
73
|
+
for (let index = 1; index < pathSections.length; index++) {
|
|
74
|
+
const subPaths = pathSections[index];
|
|
75
|
+
resourcePathValue = resourcePathValue ? resourcePathValue[subPaths] : resource[subPaths];
|
|
76
|
+
if (resourcePathValue) {
|
|
77
|
+
if (this.isPrimitive(resourcePathValue)) {
|
|
78
|
+
return [resourcePathValue];
|
|
79
|
+
} else if (Array.isArray(resourcePathValue) && resourcePathValue.length > 0) {
|
|
80
|
+
let resultSet = [];
|
|
81
|
+
for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
|
|
82
|
+
const subPathValue = resourcePathValue[subPathIndex];
|
|
83
|
+
resultSet.push(...this.getValuesAtResourcePath(subPathValue,
|
|
84
|
+
pathSections.slice(index).join(".")));
|
|
85
|
+
}
|
|
86
|
+
return resultSet;
|
|
87
|
+
} else if (typeof(resourcePathValue) === 'object') {
|
|
88
|
+
return this.getValuesAtResourcePath(resourcePathValue,
|
|
89
|
+
pathSections.slice(index).join("."));
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private isPrimitive(value: any) {
|
|
99
|
+
return typeof(value) === "boolean" || typeof(value) === "string";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param resource resource to pull out references from
|
|
104
|
+
* @returns array of references inside a resource
|
|
105
|
+
*/
|
|
106
|
+
getAllReferencesFromResource(resource: any): string[] {
|
|
107
|
+
const stringifiedResource = JSON.stringify(resource);
|
|
108
|
+
const referenceJsonString = '"reference":';
|
|
109
|
+
let references = [];
|
|
110
|
+
let cursor = stringifiedResource.indexOf(referenceJsonString, 0);
|
|
111
|
+
while (cursor > -1) {
|
|
112
|
+
const referenceStart = stringifiedResource.indexOf(referenceJsonString, cursor) + referenceJsonString.length;
|
|
113
|
+
const referenceEnd = stringifiedResource.indexOf('"', referenceStart + 1);
|
|
114
|
+
const reference = stringifiedResource.substring(referenceStart, referenceEnd);
|
|
115
|
+
// this means the reference ends started reading from start again
|
|
116
|
+
if(referenceEnd < cursor) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
references.push(reference);
|
|
120
|
+
cursor = referenceEnd;
|
|
121
|
+
}
|
|
122
|
+
return references;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"resourceType": "CareTeam",
|
|
3
|
+
"id": "example",
|
|
4
|
+
"text": {
|
|
5
|
+
"status": "generated",
|
|
6
|
+
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Care Team</div>"
|
|
7
|
+
},
|
|
8
|
+
"contained": [
|
|
9
|
+
{
|
|
10
|
+
"resourceType": "Practitioner",
|
|
11
|
+
"id": "pr1",
|
|
12
|
+
"name": [
|
|
13
|
+
{
|
|
14
|
+
"family": "Dietician",
|
|
15
|
+
"given": [
|
|
16
|
+
"Dorothy"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"identifier": [
|
|
23
|
+
{
|
|
24
|
+
"value": "12345"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"status": "active",
|
|
28
|
+
"category": [
|
|
29
|
+
{
|
|
30
|
+
"coding": [
|
|
31
|
+
{
|
|
32
|
+
"system": "http://loinc.org",
|
|
33
|
+
"code": "LA27976-2",
|
|
34
|
+
"display": "Encounter-focused care team"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"name": "Peter James Charlmers Care Plan for Inpatient Encounter",
|
|
40
|
+
"subject": {
|
|
41
|
+
"reference": "Patient/example",
|
|
42
|
+
"display": "Peter James Chalmers"
|
|
43
|
+
},
|
|
44
|
+
"encounter": {
|
|
45
|
+
"reference": "Encounter/example"
|
|
46
|
+
},
|
|
47
|
+
"period": {
|
|
48
|
+
"end": "2013-01-01"
|
|
49
|
+
},
|
|
50
|
+
"participant": [
|
|
51
|
+
{
|
|
52
|
+
"role": [
|
|
53
|
+
{
|
|
54
|
+
"text": "responsiblePerson"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"member": {
|
|
58
|
+
"reference": "Patient/example",
|
|
59
|
+
"display": "Peter James Chalmers"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"role": [
|
|
64
|
+
{
|
|
65
|
+
"text": "adviser"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"member": {
|
|
69
|
+
"reference": "#pr1",
|
|
70
|
+
"display": "Dorothy Dietition"
|
|
71
|
+
},
|
|
72
|
+
"onBehalfOf": {
|
|
73
|
+
"reference": "Organization/f001"
|
|
74
|
+
},
|
|
75
|
+
"period": {
|
|
76
|
+
"end": "2013-01-01"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"managingOrganization": [
|
|
81
|
+
{
|
|
82
|
+
"reference": "Organization/f001"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class BundleUtility {
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
|
|
5
|
-
* @param resourceTypeToFilter ResourceType to filter from bundle entries
|
|
6
|
-
* @returns array of resources
|
|
7
|
-
*/
|
|
8
|
-
getResourcesFromBundle(bundleEntry: any[], resourceTypeToFilter: string): any[];
|
|
9
|
-
}
|
|
10
|
-
export declare const BundleUtilities: BundleUtility;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BundleUtilities = exports.BundleUtility = void 0;
|
|
4
|
-
class BundleUtility {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
|
|
8
|
-
* @param resourceTypeToFilter ResourceType to filter from bundle entries
|
|
9
|
-
* @returns array of resources
|
|
10
|
-
*/
|
|
11
|
-
getResourcesFromBundle(bundleEntry, resourceTypeToFilter) {
|
|
12
|
-
return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.filter(x => x['resource']['resourceType'] === resourceTypeToFilter) : [];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.BundleUtility = BundleUtility;
|
|
16
|
-
exports.BundleUtilities = new BundleUtility();
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const BundleUtilities_1 = require("./BundleUtilities");
|
|
4
|
-
const inputPayload = require("./../../test-resources/Bundle-R4.json");
|
|
5
|
-
describe("BundleUtilities", () => {
|
|
6
|
-
describe("#getResourcesFromBundle()", () => {
|
|
7
|
-
it('should return empty array if null is passed as bundle entries', () => {
|
|
8
|
-
// execute
|
|
9
|
-
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(null, 'Patient');
|
|
10
|
-
// validate
|
|
11
|
-
expect(actual.length).toEqual(0);
|
|
12
|
-
});
|
|
13
|
-
it('should return empty array if invalid resourceType is passed', () => {
|
|
14
|
-
// execute
|
|
15
|
-
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'patient');
|
|
16
|
-
// validate
|
|
17
|
-
expect(actual.length).toEqual(0);
|
|
18
|
-
});
|
|
19
|
-
it('should return all matches array', () => {
|
|
20
|
-
// execute
|
|
21
|
-
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'Claim');
|
|
22
|
-
// validate
|
|
23
|
-
expect(actual.length).toEqual(27);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceUtilities = exports.ResourceUtility = void 0;
|
|
4
|
-
class ResourceUtility {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param inputJson - valid json
|
|
8
|
-
* @param propertyName - top level property for resource
|
|
9
|
-
* @returns json property if it exists
|
|
10
|
-
* @limitation currently just supports get for top level property on resource
|
|
11
|
-
*/
|
|
12
|
-
getResourceProperty(inputJson, propertyName) {
|
|
13
|
-
let resourcePropertyValue = null;
|
|
14
|
-
if (inputJson.hasOwnProperty(propertyName)) {
|
|
15
|
-
resourcePropertyValue = inputJson[propertyName];
|
|
16
|
-
}
|
|
17
|
-
return resourcePropertyValue;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param identifierList list of identifiers
|
|
22
|
-
* @param propertyToCompare identifier property to compare
|
|
23
|
-
* @param propertyValue value we want to compare against
|
|
24
|
-
* @returns array of matches
|
|
25
|
-
* @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
|
|
26
|
-
*/
|
|
27
|
-
getIdentifiersByProperty(identifierList, propertyToCompare, propertyValue) {
|
|
28
|
-
return (identifierList === null || identifierList === void 0 ? void 0 : identifierList.length) ? identifierList.filter(x => x[propertyToCompare] === propertyValue) : [];
|
|
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, extensionUrl) {
|
|
37
|
-
return (extensionList === null || extensionList === void 0 ? void 0 : extensionList.length) ? extensionList.filter(x => x['url'] === extensionUrl) : [];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param codingList list of codings
|
|
42
|
-
* @param propertyToCompare coding property to compare
|
|
43
|
-
* @param propertyValue value we want to compare against string or boolean
|
|
44
|
-
* @returns array of matches
|
|
45
|
-
*/
|
|
46
|
-
getCodingsByProperty(codingList, propertyToCompare, propertyValue) {
|
|
47
|
-
return (codingList === null || codingList === void 0 ? void 0 : codingList.length) ? codingList.filter(x => x[propertyToCompare] === propertyValue) : [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.ResourceUtility = ResourceUtility;
|
|
51
|
-
exports.ResourceUtilities = new ResourceUtility();
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BundleUtilities } from "./BundleUtilities";
|
|
2
|
-
|
|
3
|
-
const inputPayload = require("./../../test-resources/Bundle-R4.json");
|
|
4
|
-
describe("BundleUtilities", () => {
|
|
5
|
-
|
|
6
|
-
describe("#getResourcesFromBundle()", () => {
|
|
7
|
-
it('should return empty array if null is passed as bundle entries', () => {
|
|
8
|
-
// execute
|
|
9
|
-
const actual = BundleUtilities.getResourcesFromBundle(null, 'Patient');
|
|
10
|
-
// validate
|
|
11
|
-
expect(actual.length).toEqual(0);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should return empty array if invalid resourceType is passed', () => {
|
|
15
|
-
// execute
|
|
16
|
-
const actual = BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'patient');
|
|
17
|
-
// validate
|
|
18
|
-
expect(actual.length).toEqual(0);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should return all matches array', () => {
|
|
22
|
-
// execute
|
|
23
|
-
const actual = BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'Claim');
|
|
24
|
-
// validate
|
|
25
|
-
expect(actual.length).toEqual(27);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|