Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource util bug fix #70

Merged
merged 8 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions GETTINGSTARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down Expand Up @@ -136,15 +136,15 @@ 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');
```

#### 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());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/library/ResourceUtils/ResourceUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 6 additions & 2 deletions src/library/ResourceUtils/ResourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 2 additions & 1 deletion src/test-resources/Patient-R4.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"use": "usual",
"family": "van de Heuvel",
"given": [
"Pieter"
"Pieter",
"Peter"
],
"suffix": [
"MSc"
Expand Down
Loading