diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf4aef..306a9db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.1.1 + +* Fix issue with `BundleUtils.getResourceFromBundle` not being able get the values inside nested array under array of objects. + +## 2.1.0 + +* Remove static classes for `BundleUtilities` & `ResourceUtilities` to non static classes `BundleUtils` & `ResourceUtils.` + ## 2.0.7 ### Updates (R4) diff --git a/GETTINGSTARTED.md b/GETTINGSTARTED.md index 782c275..bb8a6e0 100644 --- a/GETTINGSTARTED.md +++ b/GETTINGSTARTED.md @@ -97,7 +97,7 @@ If you try writing this out you will see that the variable `resource` inside the ### `v2.1.0` #### BundleUtils usage ```js -import { BundleUtils } from '@smilecdr/fhirts'; +import { BundleUtils } from '@smile-cdr/fhirts'; const bundleUtils = new BundleUtils(); // returns arrayof Claim resources from Bundle.entry @@ -108,7 +108,7 @@ const resource = bundleUtils.getResourceFromBundle(Bundle.entry, '123'); #### ResourceUtils usage ```js -import { ResourceUtils } from '@smilecdr/fhirts'; +import { ResourceUtils } from '@smile-cdr/fhirts'; const resourceUtils = new ResourceUtils(); // returns deserialized Patient resource const deserializedPatientResource = resourceUtils.deserializeResource(jsonPatientPayload, new Patient()); @@ -136,7 +136,7 @@ const references = resourceUtils.getAllReferencesFromResource(resourcePayload); ### `v2.0.0` #### BundleUtilities usage ```js -import { BundleUtilities } from '@smilecdr/fhirts'; +import { BundleUtilities } from '@smile-cdr/fhirts'; // returns arrayof Claim resources from Bundle.entry const claimsList = BundleUtilities.getResourcesFromBundle(Bundle.entry, 'Claim'); @@ -144,7 +144,7 @@ const claimsList = BundleUtilities.getResourcesFromBundle(Bundle.entry, 'Claim') #### ResourceUtilities usage ```js -import { ResourceUtilities } from '@smilecdr/fhirts'; +import { ResourceUtilities } from '@smile-cdr/fhirts'; // returns deserialized Patient resource const deserializedPatientResource = ResourceUtilities.deserializeResource(jsonPatientPayload, new Patient()); diff --git a/package.json b/package.json index ca6618c..979e35f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@smile-cdr/fhirts", - "version": "2.1.0", + "version": "2.1.1", "description": "Fhir ts/js library for frontend apps", "license": "Apache-2.0", "main": "dist/index.js", diff --git a/src/library/ResourceUtils/ResourceUtils.spec.ts b/src/library/ResourceUtils/ResourceUtils.spec.ts index f201593..1eb6878 100644 --- a/src/library/ResourceUtils/ResourceUtils.spec.ts +++ b/src/library/ResourceUtils/ResourceUtils.spec.ts @@ -253,6 +253,16 @@ describe("ResourceUtils", () => { expect(pathValues[0]).toEqual("male"); }); + it("should return array with values for a array under object", () => { + // execute + const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given"); + // validate + expect(pathValues.length).toEqual(3); + expect(pathValues[0]).toEqual("Pieter"); + expect(pathValues[1]).toEqual("Peter"); + expect(pathValues[2]).toEqual("Pieter"); + }); + it("should return array with values if path exists for a deep array element", () => { // execute const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.contact.relationship.coding.system"); diff --git a/src/library/ResourceUtils/ResourceUtils.ts b/src/library/ResourceUtils/ResourceUtils.ts index c952e6d..9367d00 100644 --- a/src/library/ResourceUtils/ResourceUtils.ts +++ b/src/library/ResourceUtils/ResourceUtils.ts @@ -80,8 +80,12 @@ export class ResourceUtils { let resultSet = []; for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) { const subPathValue = resourcePathValue[subPathIndex]; - resultSet.push(...this.getValuesAtResourcePath(subPathValue, - pathSections.slice(index).join("."))); + if(this.isPrimitive(subPathValue)) { + resultSet.push(subPathValue); + } else { + resultSet.push(...this.getValuesAtResourcePath(subPathValue, + pathSections.slice(index).join("."))); + } } return resultSet; } else if (typeof(resourcePathValue) === 'object') { diff --git a/src/test-resources/Patient-R4.json b/src/test-resources/Patient-R4.json index 9b05896..8f8d93a 100644 --- a/src/test-resources/Patient-R4.json +++ b/src/test-resources/Patient-R4.json @@ -22,7 +22,8 @@ "use": "usual", "family": "van de Heuvel", "given": [ - "Pieter" + "Pieter", + "Peter" ], "suffix": [ "MSc"