@smile-cdr/fhirts 2.2.7 → 2.2.8
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 +4 -1
- package/dist/library/ResourceUtils/ResourceUtils.d.ts +1 -0
- package/dist/library/ResourceUtils/ResourceUtils.js +8 -3
- package/dist/library/ResourceUtils/ResourceUtils.spec.js +6 -0
- package/package.json +1 -1
- package/src/library/ResourceUtils/ResourceUtils.spec.ts +7 -0
- package/src/library/ResourceUtils/ResourceUtils.ts +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.8
|
|
4
|
+
|
|
5
|
+
* Fixed issue with `ResourceUtils.getValuesAtResourcePath` not checking if the root of the path matches the resource type.
|
|
6
|
+
|
|
3
7
|
## 2.2.7
|
|
4
8
|
|
|
5
9
|
* Added `BundleUtils.getResourceByFullUrl` to get a resource by its full url from a bundle.
|
|
@@ -8,7 +12,6 @@
|
|
|
8
12
|
|
|
9
13
|
* 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.
|
|
10
14
|
|
|
11
|
-
|
|
12
15
|
## 2.2.5
|
|
13
16
|
|
|
14
17
|
* 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.
|
|
@@ -39,6 +39,7 @@ export declare class ResourceUtils {
|
|
|
39
39
|
* @returns array of elements found at the provided path
|
|
40
40
|
*/
|
|
41
41
|
getValuesAtResourcePath(resource: any, elementPath: string): any[];
|
|
42
|
+
private getValuesAtResourcePathInner;
|
|
42
43
|
private isPrimitive;
|
|
43
44
|
/**
|
|
44
45
|
* @param resource resource to pull out references from
|
|
@@ -59,7 +59,12 @@ class ResourceUtils {
|
|
|
59
59
|
* @returns array of elements found at the provided path
|
|
60
60
|
*/
|
|
61
61
|
getValuesAtResourcePath(resource, elementPath) {
|
|
62
|
-
const pathSections = elementPath.split(
|
|
62
|
+
const pathSections = elementPath.split('.');
|
|
63
|
+
if (!resource || (resource.resourceType !== pathSections[0]))
|
|
64
|
+
return [];
|
|
65
|
+
return this.getValuesAtResourcePathInner(resource, pathSections);
|
|
66
|
+
}
|
|
67
|
+
getValuesAtResourcePathInner(resource, pathSections) {
|
|
63
68
|
let resourcePathValue;
|
|
64
69
|
for (let index = 1; index < pathSections.length; index++) {
|
|
65
70
|
const subPaths = pathSections[index];
|
|
@@ -76,13 +81,13 @@ class ResourceUtils {
|
|
|
76
81
|
resultSet.push(subPathValue);
|
|
77
82
|
}
|
|
78
83
|
else {
|
|
79
|
-
resultSet.push(...this.
|
|
84
|
+
resultSet.push(...this.getValuesAtResourcePathInner(subPathValue, pathSections.slice(index)));
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
return resultSet;
|
|
83
88
|
}
|
|
84
89
|
else if (typeof (resourcePathValue) === 'object') {
|
|
85
|
-
return this.
|
|
90
|
+
return this.getValuesAtResourcePathInner(resourcePathValue, pathSections.slice(index));
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
else {
|
|
@@ -183,6 +183,12 @@ describe("ResourceUtils", () => {
|
|
|
183
183
|
});
|
|
184
184
|
});
|
|
185
185
|
describe("#getValuesAtResourcePath()", () => {
|
|
186
|
+
it("should return empty array if the root of the path path does not match the resource type", () => {
|
|
187
|
+
// execute
|
|
188
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Practitioner.name.given");
|
|
189
|
+
// validate
|
|
190
|
+
expect(pathValues.length).toEqual(0);
|
|
191
|
+
});
|
|
186
192
|
it("should return array with values if path exists for a top level element", () => {
|
|
187
193
|
// execute
|
|
188
194
|
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
|
package/package.json
CHANGED
|
@@ -247,6 +247,13 @@ describe("ResourceUtils", () => {
|
|
|
247
247
|
|
|
248
248
|
describe("#getValuesAtResourcePath()", () => {
|
|
249
249
|
|
|
250
|
+
it("should return empty array if the root of the path path does not match the resource type", () => {
|
|
251
|
+
// execute
|
|
252
|
+
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Practitioner.name.given");
|
|
253
|
+
// validate
|
|
254
|
+
expect(pathValues.length).toEqual(0);
|
|
255
|
+
});
|
|
256
|
+
|
|
250
257
|
it("should return array with values if path exists for a top level element", () => {
|
|
251
258
|
// execute
|
|
252
259
|
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
|
|
@@ -70,7 +70,12 @@ export class ResourceUtils {
|
|
|
70
70
|
* @returns array of elements found at the provided path
|
|
71
71
|
*/
|
|
72
72
|
getValuesAtResourcePath(resource: any, elementPath: string): any[] {
|
|
73
|
-
const pathSections = elementPath.split(
|
|
73
|
+
const pathSections = elementPath.split('.');
|
|
74
|
+
if (!resource || (resource.resourceType !== pathSections[0])) return [];
|
|
75
|
+
return this.getValuesAtResourcePathInner(resource, pathSections);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private getValuesAtResourcePathInner(resource: any, pathSections: string[]): any[] {
|
|
74
79
|
let resourcePathValue;
|
|
75
80
|
for (let index = 1; index < pathSections.length; index++) {
|
|
76
81
|
const subPaths = pathSections[index];
|
|
@@ -86,14 +91,12 @@ export class ResourceUtils {
|
|
|
86
91
|
resultSet.push(subPathValue);
|
|
87
92
|
}
|
|
88
93
|
else {
|
|
89
|
-
resultSet.push(...this.
|
|
90
|
-
pathSections.slice(index).join(".")));
|
|
94
|
+
resultSet.push(...this.getValuesAtResourcePathInner(subPathValue, pathSections.slice(index)));
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
return resultSet;
|
|
94
98
|
} else if (typeof (resourcePathValue) === 'object') {
|
|
95
|
-
return this.
|
|
96
|
-
pathSections.slice(index).join("."));
|
|
99
|
+
return this.getValuesAtResourcePathInner(resourcePathValue, pathSections.slice(index));
|
|
97
100
|
}
|
|
98
101
|
} else {
|
|
99
102
|
break;
|