@smile-cdr/fhirts 2.2.5 → 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 CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## 2.2.5
4
9
 
5
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.
@@ -65,14 +65,14 @@ 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 = [];
73
73
  for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
74
74
  const subPathValue = resourcePathValue[subPathIndex];
75
- if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
75
+ if (this.isPrimitive(subPathValue)) {
76
76
  resultSet.push(subPathValue);
77
77
  }
78
78
  else {
@@ -190,7 +190,26 @@ 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", () => {
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", () => {
194
213
  // setup
195
214
  const expected = [
196
215
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "Fhir ts/js library for frontend apps",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -255,7 +255,30 @@ 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", () => {
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", () => {
259
282
  // setup
260
283
  const expected = [
261
284
  {
@@ -76,13 +76,13 @@ 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
- if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
85
+ if (this.isPrimitive(subPathValue)) {
86
86
  resultSet.push(subPathValue);
87
87
  }
88
88
  else {