@smile-cdr/fhirts 2.2.4 → 2.2.6
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 +9 -0
- package/GETTINGSTARTED.md +6 -6
- package/dist/library/ResourceUtils/ResourceUtils.js +2 -2
- package/dist/library/ResourceUtils/ResourceUtils.spec.js +41 -0
- package/package.json +1 -1
- package/src/library/ResourceUtils/ResourceUtils.spec.ts +49 -0
- package/src/library/ResourceUtils/ResourceUtils.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.6
|
|
4
|
+
|
|
5
|
+
* Fixed issue with `ResourceUtils.getValuesAtResourcePath` not being able to get an array with values if path exists for a top level element and is an object.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## 2.2.5
|
|
9
|
+
|
|
10
|
+
* Fixed issue with `ResourceUtils.getValuesAtResourcePath` not being able to get an array with values if path exists for a top level element and is an array.
|
|
11
|
+
|
|
3
12
|
## 2.2.4
|
|
4
13
|
|
|
5
14
|
### Updates (R3)
|
package/GETTINGSTARTED.md
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
- [Utilities](#utilities)
|
|
13
13
|
- [PatchUtils](#patchutils)
|
|
14
14
|
- [QueryBuilder](#querybuilder)
|
|
15
|
-
- [BundleUtils](#
|
|
16
|
-
- [ResourceUtils](#
|
|
15
|
+
- [BundleUtils](#bundleutils)
|
|
16
|
+
- [ResourceUtils](#resourceutils)
|
|
17
17
|
- [Bundle Utilities (static BundleUtils)](#bundleutilities)
|
|
18
18
|
- [Resource Utilities (static ResourceUtils)](#resourceutilities)
|
|
19
19
|
|
|
@@ -88,7 +88,7 @@ Read more about resource narrowing here : https://www.typescriptlang.org/docs/ha
|
|
|
88
88
|
- All of the above mentioned classes are currently in preliminary phase and will be refined in future as per needs.
|
|
89
89
|
- The above utlity classes include common functionalities used by front end applications using FHIR.
|
|
90
90
|
|
|
91
|
-
#### PatchUtils
|
|
91
|
+
#### PatchUtils
|
|
92
92
|
- Published in `v2.2.0`.
|
|
93
93
|
- Example usage demonstrated below.
|
|
94
94
|
```js
|
|
@@ -118,7 +118,7 @@ console.log(patchParameters)
|
|
|
118
118
|
}
|
|
119
119
|
]
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
*/
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
#### QueryBuilder
|
|
@@ -148,9 +148,9 @@ import { BundleUtils } from '@smile-cdr/fhirts';
|
|
|
148
148
|
|
|
149
149
|
const bundleUtils = new BundleUtils();
|
|
150
150
|
// returns arrayof Claim resources from Bundle.entry
|
|
151
|
-
const claimsList = bundleUtils.
|
|
151
|
+
const claimsList = bundleUtils.getResources(Bundle.entry, 'Claim');
|
|
152
152
|
// returns a single resource with ID 123 from Bundle.entry
|
|
153
|
-
const resource = bundleUtils.
|
|
153
|
+
const resource = bundleUtils.getResource(Bundle.entry, '123');
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
#### ResourceUtils
|
|
@@ -65,8 +65,8 @@ class ResourceUtils {
|
|
|
65
65
|
const subPaths = pathSections[index];
|
|
66
66
|
resourcePathValue = resourcePathValue ? resourcePathValue[subPaths] : resource[subPaths];
|
|
67
67
|
if (resourcePathValue) {
|
|
68
|
-
if (this.isPrimitive(resourcePathValue)) {
|
|
69
|
-
return [resourcePathValue];
|
|
68
|
+
if (this.isPrimitive(resourcePathValue) || pathSections.length === 2) {
|
|
69
|
+
return Array.isArray(resourcePathValue) ? [...resourcePathValue] : [resourcePathValue];
|
|
70
70
|
}
|
|
71
71
|
else if (Array.isArray(resourcePathValue) && resourcePathValue.length > 0) {
|
|
72
72
|
let resultSet = [];
|
|
@@ -190,6 +190,47 @@ describe("ResourceUtils", () => {
|
|
|
190
190
|
expect(pathValues.length).toEqual(1);
|
|
191
191
|
expect(pathValues[0]).toEqual("male");
|
|
192
192
|
});
|
|
193
|
+
it('should return array with values if path exists for a top level element and is an object', () => {
|
|
194
|
+
const expected = [
|
|
195
|
+
{
|
|
196
|
+
coding: [
|
|
197
|
+
{
|
|
198
|
+
system: "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus",
|
|
199
|
+
code: "M",
|
|
200
|
+
display: "Married"
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
text: "Getrouwd",
|
|
204
|
+
}
|
|
205
|
+
];
|
|
206
|
+
// execute
|
|
207
|
+
const actual = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.maritalStatus");
|
|
208
|
+
// validate
|
|
209
|
+
expect(actual.length).toEqual(1);
|
|
210
|
+
expect(actual).toEqual(expected);
|
|
211
|
+
});
|
|
212
|
+
it("should return array with values if path exists for a top level element and is an array", () => {
|
|
213
|
+
// setup
|
|
214
|
+
const expected = [
|
|
215
|
+
{
|
|
216
|
+
use: "usual",
|
|
217
|
+
family: "van de Heuvel",
|
|
218
|
+
given: ["Pieter", "Peter"],
|
|
219
|
+
suffix: ["MSc"],
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
use: "usual",
|
|
223
|
+
family: "van de Heuvel",
|
|
224
|
+
given: ["Pieter"],
|
|
225
|
+
suffix: ["MSc"],
|
|
226
|
+
},
|
|
227
|
+
];
|
|
228
|
+
// execute
|
|
229
|
+
const actual = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name");
|
|
230
|
+
// validate
|
|
231
|
+
expect(actual.length).toEqual(2);
|
|
232
|
+
expect(actual).toEqual(expected);
|
|
233
|
+
});
|
|
193
234
|
it("should return array with values for a array under object", () => {
|
|
194
235
|
// execute
|
|
195
236
|
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
|
package/package.json
CHANGED
|
@@ -255,6 +255,55 @@ describe("ResourceUtils", () => {
|
|
|
255
255
|
expect(pathValues[0]).toEqual("male");
|
|
256
256
|
});
|
|
257
257
|
|
|
258
|
+
it('should return array with values if path exists for a top level element and is an object', () => {
|
|
259
|
+
const expected = [
|
|
260
|
+
{
|
|
261
|
+
coding: [
|
|
262
|
+
{
|
|
263
|
+
system: "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus",
|
|
264
|
+
code: "M",
|
|
265
|
+
display: "Married"
|
|
266
|
+
}
|
|
267
|
+
],
|
|
268
|
+
text: "Getrouwd",
|
|
269
|
+
}
|
|
270
|
+
];
|
|
271
|
+
// execute
|
|
272
|
+
const actual = resourceUtils.getValuesAtResourcePath(
|
|
273
|
+
patientPayload,
|
|
274
|
+
"Patient.maritalStatus"
|
|
275
|
+
);
|
|
276
|
+
// validate
|
|
277
|
+
expect(actual.length).toEqual(1);
|
|
278
|
+
expect(actual).toEqual(expected);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("should return array with values if path exists for a top level element and is an array", () => {
|
|
282
|
+
// setup
|
|
283
|
+
const expected = [
|
|
284
|
+
{
|
|
285
|
+
use: "usual",
|
|
286
|
+
family: "van de Heuvel",
|
|
287
|
+
given: ["Pieter", "Peter"],
|
|
288
|
+
suffix: ["MSc"],
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
use: "usual",
|
|
292
|
+
family: "van de Heuvel",
|
|
293
|
+
given: ["Pieter"],
|
|
294
|
+
suffix: ["MSc"],
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
// execute
|
|
298
|
+
const actual = resourceUtils.getValuesAtResourcePath(
|
|
299
|
+
patientPayload,
|
|
300
|
+
"Patient.name"
|
|
301
|
+
);
|
|
302
|
+
// validate
|
|
303
|
+
expect(actual.length).toEqual(2);
|
|
304
|
+
expect(actual).toEqual(expected);
|
|
305
|
+
});
|
|
306
|
+
|
|
258
307
|
it("should return array with values for a array under object", () => {
|
|
259
308
|
// execute
|
|
260
309
|
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
|
|
@@ -76,15 +76,16 @@ export class ResourceUtils {
|
|
|
76
76
|
const subPaths = pathSections[index];
|
|
77
77
|
resourcePathValue = resourcePathValue ? resourcePathValue[subPaths] : resource[subPaths];
|
|
78
78
|
if (resourcePathValue) {
|
|
79
|
-
if (this.isPrimitive(resourcePathValue)) {
|
|
80
|
-
return [resourcePathValue];
|
|
79
|
+
if (this.isPrimitive(resourcePathValue) || pathSections.length === 2) {
|
|
80
|
+
return Array.isArray(resourcePathValue) ? [...resourcePathValue] : [resourcePathValue];
|
|
81
81
|
} else if (Array.isArray(resourcePathValue) && resourcePathValue.length > 0) {
|
|
82
82
|
let resultSet = [];
|
|
83
83
|
for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
|
|
84
84
|
const subPathValue = resourcePathValue[subPathIndex];
|
|
85
85
|
if (this.isPrimitive(subPathValue)) {
|
|
86
86
|
resultSet.push(subPathValue);
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
88
89
|
resultSet.push(...this.getValuesAtResourcePath(subPathValue,
|
|
89
90
|
pathSections.slice(index).join(".")));
|
|
90
91
|
}
|