@smile-cdr/fhirts 2.2.4 → 2.2.5

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,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.5
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 array.
6
+
3
7
  ## 2.2.4
4
8
 
5
9
  ### Updates (R3)
package/GETTINGSTARTED.md CHANGED
@@ -12,8 +12,8 @@
12
12
  - [Utilities](#utilities)
13
13
  - [PatchUtils](#patchutils)
14
14
  - [QueryBuilder](#querybuilder)
15
- - [BundleUtils](#bundleutilities)
16
- - [ResourceUtils](#resourceutilities)
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.getResourcesFromBundle(Bundle.entry, 'Claim');
151
+ const claimsList = bundleUtils.getResources(Bundle.entry, 'Claim');
152
152
  // returns a single resource with ID 123 from Bundle.entry
153
- const resource = bundleUtils.getResourceFromBundle(Bundle.entry, '123');
153
+ const resource = bundleUtils.getResource(Bundle.entry, '123');
154
154
  ```
155
155
 
156
156
  #### ResourceUtils
@@ -72,7 +72,7 @@ class ResourceUtils {
72
72
  let resultSet = [];
73
73
  for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
74
74
  const subPathValue = resourcePathValue[subPathIndex];
75
- if (this.isPrimitive(subPathValue)) {
75
+ if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
76
76
  resultSet.push(subPathValue);
77
77
  }
78
78
  else {
@@ -190,6 +190,28 @@ 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 a array", () => {
194
+ // setup
195
+ const expected = [
196
+ {
197
+ use: "usual",
198
+ family: "van de Heuvel",
199
+ given: ["Pieter", "Peter"],
200
+ suffix: ["MSc"],
201
+ },
202
+ {
203
+ use: "usual",
204
+ family: "van de Heuvel",
205
+ given: ["Pieter"],
206
+ suffix: ["MSc"],
207
+ },
208
+ ];
209
+ // execute
210
+ const actual = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name");
211
+ // validate
212
+ expect(actual.length).toEqual(2);
213
+ expect(actual).toEqual(expected);
214
+ });
193
215
  it("should return array with values for a array under object", () => {
194
216
  // execute
195
217
  const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "description": "Fhir ts/js library for frontend apps",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -255,6 +255,32 @@ 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 a array", () => {
259
+ // setup
260
+ const expected = [
261
+ {
262
+ use: "usual",
263
+ family: "van de Heuvel",
264
+ given: ["Pieter", "Peter"],
265
+ suffix: ["MSc"],
266
+ },
267
+ {
268
+ use: "usual",
269
+ family: "van de Heuvel",
270
+ given: ["Pieter"],
271
+ suffix: ["MSc"],
272
+ },
273
+ ];
274
+ // execute
275
+ const actual = resourceUtils.getValuesAtResourcePath(
276
+ patientPayload,
277
+ "Patient.name"
278
+ );
279
+ // validate
280
+ expect(actual.length).toEqual(2);
281
+ expect(actual).toEqual(expected);
282
+ });
283
+
258
284
  it("should return array with values for a array under object", () => {
259
285
  // execute
260
286
  const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
@@ -82,9 +82,10 @@ export class ResourceUtils {
82
82
  let resultSet = [];
83
83
  for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
84
84
  const subPathValue = resourcePathValue[subPathIndex];
85
- if (this.isPrimitive(subPathValue)) {
85
+ if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
86
86
  resultSet.push(subPathValue);
87
- } else {
87
+ }
88
+ else {
88
89
  resultSet.push(...this.getValuesAtResourcePath(subPathValue,
89
90
  pathSections.slice(index).join(".")));
90
91
  }