@smile-cdr/fhirts 2.2.6 → 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 CHANGED
@@ -1,10 +1,17 @@
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
+
7
+ ## 2.2.7
8
+
9
+ * Added `BundleUtils.getResourceByFullUrl` to get a resource by its full url from a bundle.
10
+
3
11
  ## 2.2.6
4
12
 
5
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.
6
14
 
7
-
8
15
  ## 2.2.5
9
16
 
10
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.
package/GETTINGSTARTED.md CHANGED
@@ -151,6 +151,8 @@ const bundleUtils = new BundleUtils();
151
151
  const claimsList = bundleUtils.getResources(Bundle.entry, 'Claim');
152
152
  // returns a single resource with ID 123 from Bundle.entry
153
153
  const resource = bundleUtils.getResource(Bundle.entry, '123');
154
+ // returns a single resource with full url 123 from Bundle.entry
155
+ const resource = bundleUtils.getResourceByFullUrl(Bundle.entry, 'http://server-host/fhir/Patient/123');
154
156
  ```
155
157
 
156
158
  #### ResourceUtils
@@ -13,4 +13,11 @@ export declare class BundleUtils {
13
13
  * @returns single resource
14
14
  */
15
15
  getResource(bundleEntry: any[], resourceId: string): any;
16
+ /**
17
+ *
18
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
19
+ * @param fullUrl Full Url to filter from bundle entries
20
+ * @returns single resource
21
+ */
22
+ getResourceByFullUrl(bundleEntry: any[], fullUrl: string): any;
16
23
  }
@@ -20,5 +20,14 @@ class BundleUtils {
20
20
  getResource(bundleEntry, resourceId) {
21
21
  return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.find(x => x['resource']['id'] === resourceId) : null;
22
22
  }
23
+ /**
24
+ *
25
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
26
+ * @param fullUrl Full Url to filter from bundle entries
27
+ * @returns single resource
28
+ */
29
+ getResourceByFullUrl(bundleEntry, fullUrl) {
30
+ return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.find(x => x['fullUrl'] === fullUrl) : null;
31
+ }
23
32
  }
24
33
  exports.BundleUtils = BundleUtils;
@@ -41,7 +41,27 @@ describe("BundleUtils", () => {
41
41
  // execute
42
42
  const actual = bundleUtils.getResource(inputPayload.entry, "ec0bb1b3-b229-36cf-7e34-3f5fec9d3afe");
43
43
  // validate
44
- expect(actual).not.toBeNull();
44
+ expect(actual).not.toBeUndefined();
45
+ });
46
+ });
47
+ describe("#getResourceByFullUrl()", () => {
48
+ it("should return null if null is passed as bundle entries", () => {
49
+ // execute
50
+ const actual = bundleUtils.getResourceByFullUrl(null, "123");
51
+ // validate
52
+ expect(actual).toBeNull();
53
+ });
54
+ it("should return undefined if fullUrl is not found", () => {
55
+ // execute
56
+ const actual = bundleUtils.getResourceByFullUrl(inputPayload.entry, "123");
57
+ // validate
58
+ expect(actual).toBeUndefined();
59
+ });
60
+ it("should return resource if resource is found", () => {
61
+ // execute
62
+ const actual = bundleUtils.getResourceByFullUrl(inputPayload.entry, "urn:uuid:7c52dd91-73f8-83e1-cab2-2ffdd7a34601");
63
+ // validate
64
+ expect(actual).not.toBeUndefined();
45
65
  });
46
66
  });
47
67
  });
@@ -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.getValuesAtResourcePath(subPathValue, pathSections.slice(index).join(".")));
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.getValuesAtResourcePath(resourcePathValue, pathSections.slice(index).join("."));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "Fhir ts/js library for frontend apps",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -59,7 +59,36 @@ describe("BundleUtils", () => {
59
59
  "ec0bb1b3-b229-36cf-7e34-3f5fec9d3afe"
60
60
  );
61
61
  // validate
62
- expect(actual).not.toBeNull();
62
+ expect(actual).not.toBeUndefined();
63
63
  });
64
64
  });
65
+
66
+ describe("#getResourceByFullUrl()", () => {
67
+ it("should return null if null is passed as bundle entries", () => {
68
+ // execute
69
+ const actual = bundleUtils.getResourceByFullUrl(null, "123");
70
+ // validate
71
+ expect(actual).toBeNull();
72
+ });
73
+
74
+ it("should return undefined if fullUrl is not found", () => {
75
+ // execute
76
+ const actual = bundleUtils.getResourceByFullUrl(
77
+ inputPayload.entry,
78
+ "123"
79
+ );
80
+ // validate
81
+ expect(actual).toBeUndefined();
82
+ });
83
+
84
+ it("should return resource if resource is found", () => {
85
+ // execute
86
+ const actual = bundleUtils.getResourceByFullUrl(
87
+ inputPayload.entry,
88
+ "urn:uuid:7c52dd91-73f8-83e1-cab2-2ffdd7a34601"
89
+ );
90
+ // validate
91
+ expect(actual).not.toBeUndefined();
92
+ });
93
+ })
65
94
  });
@@ -20,6 +20,15 @@ export class BundleUtils {
20
20
  return bundleEntry?.length ? bundleEntry.find(x => x['resource']['id'] === resourceId) : null;
21
21
  }
22
22
 
23
+ /**
24
+ *
25
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
26
+ * @param fullUrl Full Url to filter from bundle entries
27
+ * @returns single resource
28
+ */
29
+ getResourceByFullUrl(bundleEntry: any[], fullUrl: string): any {
30
+ return bundleEntry?.length ? bundleEntry.find(x => x['fullUrl'] === fullUrl) : null;
31
+ }
23
32
  }
24
33
 
25
34
 
@@ -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.getValuesAtResourcePath(subPathValue,
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.getValuesAtResourcePath(resourcePathValue,
96
- pathSections.slice(index).join("."));
99
+ return this.getValuesAtResourcePathInner(resourcePathValue, pathSections.slice(index));
97
100
  }
98
101
  } else {
99
102
  break;