@smile-cdr/fhirts 2.0.7 → 2.1.1

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/GETTINGSTARTED.md +42 -3
  3. package/dist/index.d.ts +3 -3
  4. package/dist/index.js +5 -5
  5. package/dist/library/BundleUtils/BundleUtils.d.ts +16 -0
  6. package/dist/library/BundleUtils/BundleUtils.js +24 -0
  7. package/dist/library/BundleUtils/BundleUtils.spec.js +47 -0
  8. package/dist/library/{ResourceUtilities/ResourceUtilities.d.ts → ResourceUtils/ResourceUtils.d.ts} +14 -2
  9. package/dist/library/ResourceUtils/ResourceUtils.js +120 -0
  10. package/dist/library/{ResourceUtilities/ResourceUtilities.spec.js → ResourceUtils/ResourceUtils.spec.js} +81 -22
  11. package/package.json +1 -1
  12. package/src/index.ts +3 -3
  13. package/src/library/BundleUtils/BundleUtils.spec.ts +65 -0
  14. package/src/library/BundleUtils/BundleUtils.ts +26 -0
  15. package/src/library/{ResourceUtilities/ResourceUtilities.spec.ts → ResourceUtils/ResourceUtils.spec.ts} +106 -24
  16. package/src/library/ResourceUtils/ResourceUtils.ts +128 -0
  17. package/src/test-resources/CareTeam-R4.json +85 -0
  18. package/src/test-resources/Patient-R4.json +6 -1
  19. package/dist/library/BundleUtilities/BundleUtilities.d.ts +0 -10
  20. package/dist/library/BundleUtilities/BundleUtilities.js +0 -16
  21. package/dist/library/BundleUtilities/BundleUtilities.spec.js +0 -26
  22. package/dist/library/ResourceUtilities/ResourceUtilities.js +0 -51
  23. package/src/library/BundleUtilities/BundleUtilities.spec.ts +0 -28
  24. package/src/library/BundleUtilities/BundleUtilities.ts +0 -16
  25. package/src/library/ResourceUtilities/ResourceUtilities.ts +0 -52
  26. /package/dist/library/{BundleUtilities/BundleUtilities.spec.d.ts → BundleUtils/BundleUtils.spec.d.ts} +0 -0
  27. /package/dist/library/{ResourceUtilities/ResourceUtilities.spec.d.ts → ResourceUtils/ResourceUtils.spec.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.1
4
+
5
+ * Fix issue with `BundleUtils.getResourceFromBundle` not being able get the values inside nested array under array of objects.
6
+
7
+ ## 2.1.0
8
+
9
+ * Remove static classes for `BundleUtilities` & `ResourceUtilities` to non static classes `BundleUtils` & `ResourceUtils.`
10
+
3
11
  ## 2.0.7
4
12
 
5
13
  ### Updates (R4)
package/GETTINGSTARTED.md CHANGED
@@ -94,18 +94,57 @@ If you try writing this out you will see that the variable `resource` inside the
94
94
  - The above utlity classes include common functionalities used by front end applications using FHIR.
95
95
  - All utilities functions are static right now, so, no need for instantiating classes. **Note: This is subject to change in future**
96
96
 
97
+ ### `v2.1.0`
98
+ #### BundleUtils usage
99
+ ```js
100
+ import { BundleUtils } from '@smile-cdr/fhirts';
101
+
102
+ const bundleUtils = new BundleUtils();
103
+ // returns arrayof Claim resources from Bundle.entry
104
+ const claimsList = bundleUtils.getResourcesFromBundle(Bundle.entry, 'Claim');
105
+ // returns a single resource with ID 123 from Bundle.entry
106
+ const resource = bundleUtils.getResourceFromBundle(Bundle.entry, '123');
107
+ ```
108
+
109
+ #### ResourceUtils usage
110
+ ```js
111
+ import { ResourceUtils } from '@smile-cdr/fhirts';
112
+ const resourceUtils = new ResourceUtils();
113
+ // returns deserialized Patient resource
114
+ const deserializedPatientResource = resourceUtils.deserializeResource(jsonPatientPayload, new Patient());
115
+
116
+ // returns Patient.gender
117
+ const patientGender = resourceUtils.getResourceProperty(jsonPatientPayload, 'gender');
118
+
119
+ // returns all matching identifiers where Identifier.use = usual
120
+ const identifierFilter = resourceUtils.getIdentifiersByProperty(identifierList,"use","usual");
121
+
122
+ const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
123
+ // returns all matching extensions where Extension.use = "http://ns.electronichealth.net.au/id/hi/ihi/1.0"
124
+ const extensionFilter = resourceUtils.getExtensionsByUrl(extensionList, url);
125
+
126
+ // returns all matching codings where Coding.code = "abc"
127
+ const codingFilter = resourceUtils.getCodingsByProperty(codingList,"code","abc");
128
+ // returns array of elements found at provided path and returns empty array if no values found
129
+ const values = resourceUtils.getValuesAtResourcePath(jsonPatientPayload, "Patient.contact.relationship.coding.system");
130
+ // returns array of references found in a resource
131
+ const references = resourceUtils.getAllReferencesFromResource(resourcePayload);
132
+ ```
133
+
134
+
97
135
 
136
+ ### `v2.0.0`
98
137
  #### BundleUtilities usage
99
138
  ```js
100
- import { BundleUtilities } from '@smilecdr/fhirts';
139
+ import { BundleUtilities } from '@smile-cdr/fhirts';
101
140
 
102
- // returns list of Claim resources from Bundle.entry
141
+ // returns arrayof Claim resources from Bundle.entry
103
142
  const claimsList = BundleUtilities.getResourcesFromBundle(Bundle.entry, 'Claim');
104
143
  ```
105
144
 
106
145
  #### ResourceUtilities usage
107
146
  ```js
108
- import { ResourceUtilities } from '@smilecdr/fhirts';
147
+ import { ResourceUtilities } from '@smile-cdr/fhirts';
109
148
 
110
149
  // returns deserialized Patient resource
111
150
  const deserializedPatientResource = ResourceUtilities.deserializeResource(jsonPatientPayload, new Patient());
package/dist/index.d.ts CHANGED
@@ -2,6 +2,6 @@ import * as fhirR4 from './FHIR-R4/classes/models-r4';
2
2
  import * as IfhirR4 from './FHIR-R4/interfaces/IModel';
3
3
  import * as fhirR3 from './FHIR-R3';
4
4
  import * as dstu2 from './FHIR-DSTU2';
5
- import { ResourceUtilities } from './library/ResourceUtilities/ResourceUtilities';
6
- import { BundleUtilities } from './library/BundleUtilities/BundleUtilities';
7
- export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtilities, BundleUtilities };
5
+ import { ResourceUtils } from './library/ResourceUtils/ResourceUtils';
6
+ import { BundleUtils } from './library/BundleUtils/BundleUtils';
7
+ export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BundleUtilities = exports.ResourceUtilities = exports.dstu2 = exports.IfhirR4 = exports.fhirR3 = exports.fhirR4 = void 0;
3
+ exports.BundleUtils = exports.ResourceUtils = exports.dstu2 = exports.IfhirR4 = exports.fhirR3 = exports.fhirR4 = void 0;
4
4
  const fhirR4 = require("./FHIR-R4/classes/models-r4");
5
5
  exports.fhirR4 = fhirR4;
6
6
  const IfhirR4 = require("./FHIR-R4/interfaces/IModel");
@@ -9,7 +9,7 @@ const fhirR3 = require("./FHIR-R3");
9
9
  exports.fhirR3 = fhirR3;
10
10
  const dstu2 = require("./FHIR-DSTU2");
11
11
  exports.dstu2 = dstu2;
12
- const ResourceUtilities_1 = require("./library/ResourceUtilities/ResourceUtilities");
13
- Object.defineProperty(exports, "ResourceUtilities", { enumerable: true, get: function () { return ResourceUtilities_1.ResourceUtilities; } });
14
- const BundleUtilities_1 = require("./library/BundleUtilities/BundleUtilities");
15
- Object.defineProperty(exports, "BundleUtilities", { enumerable: true, get: function () { return BundleUtilities_1.BundleUtilities; } });
12
+ const ResourceUtils_1 = require("./library/ResourceUtils/ResourceUtils");
13
+ Object.defineProperty(exports, "ResourceUtils", { enumerable: true, get: function () { return ResourceUtils_1.ResourceUtils; } });
14
+ const BundleUtils_1 = require("./library/BundleUtils/BundleUtils");
15
+ Object.defineProperty(exports, "BundleUtils", { enumerable: true, get: function () { return BundleUtils_1.BundleUtils; } });
@@ -0,0 +1,16 @@
1
+ export declare class BundleUtils {
2
+ /**
3
+ *
4
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
5
+ * @param resourceTypeToFilter ResourceType to filter from bundle entries
6
+ * @returns array of resources
7
+ */
8
+ getResources(bundleEntry: any[], resourceTypeToFilter: string): any[];
9
+ /**
10
+ *
11
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
12
+ * @param resourceId Resource ID to filter from bundle entries
13
+ * @returns single resource
14
+ */
15
+ getResource(bundleEntry: any[], resourceId: string): any;
16
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BundleUtils = void 0;
4
+ class BundleUtils {
5
+ /**
6
+ *
7
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
8
+ * @param resourceTypeToFilter ResourceType to filter from bundle entries
9
+ * @returns array of resources
10
+ */
11
+ getResources(bundleEntry, resourceTypeToFilter) {
12
+ return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.filter(x => x['resource']['resourceType'] === resourceTypeToFilter) : [];
13
+ }
14
+ /**
15
+ *
16
+ * @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
17
+ * @param resourceId Resource ID to filter from bundle entries
18
+ * @returns single resource
19
+ */
20
+ getResource(bundleEntry, resourceId) {
21
+ return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.find(x => x['resource']['id'] === resourceId) : null;
22
+ }
23
+ }
24
+ exports.BundleUtils = BundleUtils;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const BundleUtils_1 = require("./BundleUtils");
4
+ const inputPayload = require("./../../test-resources/Bundle-R4.json");
5
+ describe("BundleUtils", () => {
6
+ let bundleUtils = new BundleUtils_1.BundleUtils();
7
+ describe("#getResources()", () => {
8
+ it("should return empty array if null is passed as bundle entries", () => {
9
+ // execute
10
+ const actual = bundleUtils.getResources(null, "Patient");
11
+ // validate
12
+ expect(actual.length).toEqual(0);
13
+ });
14
+ it("should return empty array if invalid resourceType is passed", () => {
15
+ // execute
16
+ const actual = bundleUtils.getResources(inputPayload.entry, "patient");
17
+ // validate
18
+ expect(actual.length).toEqual(0);
19
+ });
20
+ it("should return all matches array", () => {
21
+ // execute
22
+ const actual = bundleUtils.getResources(inputPayload.entry, "Claim");
23
+ // validate
24
+ expect(actual.length).toEqual(27);
25
+ });
26
+ });
27
+ describe("#getResource()", () => {
28
+ it("should return null if null is passed as bundle entries", () => {
29
+ // execute
30
+ const actual = bundleUtils.getResource(null, "123");
31
+ // validate
32
+ expect(actual).toBeNull();
33
+ });
34
+ it("should return undefined if resourceId is not found", () => {
35
+ // execute
36
+ const actual = bundleUtils.getResource(inputPayload.entry, "123");
37
+ // validate
38
+ expect(actual).toBeUndefined();
39
+ });
40
+ it("should return resource if resource is found", () => {
41
+ // execute
42
+ const actual = bundleUtils.getResource(inputPayload.entry, "ec0bb1b3-b229-36cf-7e34-3f5fec9d3afe");
43
+ // validate
44
+ expect(actual).not.toBeNull();
45
+ });
46
+ });
47
+ });
@@ -1,4 +1,4 @@
1
- export declare class ResourceUtility {
1
+ export declare class ResourceUtils {
2
2
  /**
3
3
  *
4
4
  * @param inputJson - valid json
@@ -31,5 +31,17 @@ export declare class ResourceUtility {
31
31
  * @returns array of matches
32
32
  */
33
33
  getCodingsByProperty(codingList: any[], propertyToCompare: string, propertyValue: string | boolean): any[];
34
+ /**
35
+ *
36
+ * @param resource resource for which path needs to be validated
37
+ * @param elementPath path to validate in resource
38
+ * @returns array of elements found at the provided path
39
+ */
40
+ getValuesAtResourcePath(resource: any, elementPath: string): any[];
41
+ private isPrimitive;
42
+ /**
43
+ * @param resource resource to pull out references from
44
+ * @returns array of references inside a resource
45
+ */
46
+ getAllReferencesFromResource(resource: any): string[];
34
47
  }
35
- export declare const ResourceUtilities: ResourceUtility;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResourceUtils = void 0;
4
+ class ResourceUtils {
5
+ /**
6
+ *
7
+ * @param inputJson - valid json
8
+ * @param propertyName - top level property for resource
9
+ * @returns json property if it exists
10
+ * @limitation currently just supports get for top level property on resource
11
+ */
12
+ getResourceProperty(inputJson, propertyName) {
13
+ let resourcePropertyValue = null;
14
+ if (inputJson.hasOwnProperty(propertyName)) {
15
+ resourcePropertyValue = inputJson[propertyName];
16
+ }
17
+ return resourcePropertyValue;
18
+ }
19
+ /**
20
+ *
21
+ * @param identifierList list of identifiers
22
+ * @param propertyToCompare identifier property to compare
23
+ * @param propertyValue value we want to compare against
24
+ * @returns array of matches
25
+ * @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
26
+ */
27
+ getIdentifiersByProperty(identifierList, propertyToCompare, propertyValue) {
28
+ return (identifierList === null || identifierList === void 0 ? void 0 : identifierList.length)
29
+ ? identifierList.filter((x) => x[propertyToCompare] === propertyValue)
30
+ : [];
31
+ }
32
+ /**
33
+ *
34
+ * @param extensionList list of extensions
35
+ * @param extensionUrl Extension.url to compare
36
+ * @returns array of matches
37
+ */
38
+ getExtensionsByUrl(extensionList, extensionUrl) {
39
+ return (extensionList === null || extensionList === void 0 ? void 0 : extensionList.length)
40
+ ? extensionList.filter((x) => x["url"] === extensionUrl)
41
+ : [];
42
+ }
43
+ /**
44
+ *
45
+ * @param codingList list of codings
46
+ * @param propertyToCompare coding property to compare
47
+ * @param propertyValue value we want to compare against string or boolean
48
+ * @returns array of matches
49
+ */
50
+ getCodingsByProperty(codingList, propertyToCompare, propertyValue) {
51
+ return (codingList === null || codingList === void 0 ? void 0 : codingList.length)
52
+ ? codingList.filter((x) => x[propertyToCompare] === propertyValue)
53
+ : [];
54
+ }
55
+ /**
56
+ *
57
+ * @param resource resource for which path needs to be validated
58
+ * @param elementPath path to validate in resource
59
+ * @returns array of elements found at the provided path
60
+ */
61
+ getValuesAtResourcePath(resource, elementPath) {
62
+ const pathSections = elementPath.split(".");
63
+ let resourcePathValue;
64
+ for (let index = 1; index < pathSections.length; index++) {
65
+ const subPaths = pathSections[index];
66
+ resourcePathValue = resourcePathValue ? resourcePathValue[subPaths] : resource[subPaths];
67
+ if (resourcePathValue) {
68
+ if (this.isPrimitive(resourcePathValue)) {
69
+ return [resourcePathValue];
70
+ }
71
+ else if (Array.isArray(resourcePathValue) && resourcePathValue.length > 0) {
72
+ let resultSet = [];
73
+ for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
74
+ const subPathValue = resourcePathValue[subPathIndex];
75
+ if (this.isPrimitive(subPathValue)) {
76
+ resultSet.push(subPathValue);
77
+ }
78
+ else {
79
+ resultSet.push(...this.getValuesAtResourcePath(subPathValue, pathSections.slice(index).join(".")));
80
+ }
81
+ }
82
+ return resultSet;
83
+ }
84
+ else if (typeof (resourcePathValue) === 'object') {
85
+ return this.getValuesAtResourcePath(resourcePathValue, pathSections.slice(index).join("."));
86
+ }
87
+ }
88
+ else {
89
+ break;
90
+ }
91
+ }
92
+ return [];
93
+ }
94
+ isPrimitive(value) {
95
+ return typeof (value) === "boolean" || typeof (value) === "string";
96
+ }
97
+ /**
98
+ * @param resource resource to pull out references from
99
+ * @returns array of references inside a resource
100
+ */
101
+ getAllReferencesFromResource(resource) {
102
+ const stringifiedResource = JSON.stringify(resource);
103
+ const referenceJsonString = '"reference":';
104
+ let references = [];
105
+ let cursor = stringifiedResource.indexOf(referenceJsonString, 0);
106
+ while (cursor > -1) {
107
+ const referenceStart = stringifiedResource.indexOf(referenceJsonString, cursor) + referenceJsonString.length;
108
+ const referenceEnd = stringifiedResource.indexOf('"', referenceStart + 1);
109
+ const reference = stringifiedResource.substring(referenceStart, referenceEnd);
110
+ // this means the reference ends started reading from start again
111
+ if (referenceEnd < cursor) {
112
+ break;
113
+ }
114
+ references.push(reference);
115
+ cursor = referenceEnd;
116
+ }
117
+ return references;
118
+ }
119
+ }
120
+ exports.ResourceUtils = ResourceUtils;
@@ -1,26 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const ResourceUtilities_1 = require("./ResourceUtilities");
4
- const inputPayload = require("./../../test-resources/Patient-R4.json");
5
- describe("ResourceUtilities", () => {
3
+ const ResourceUtils_1 = require("./ResourceUtils");
4
+ const patientPayload = require("./../../test-resources/Patient-R4.json");
5
+ const careTeamPayload = require("./../../test-resources/CareTeam-R4.json");
6
+ describe("ResourceUtils", () => {
7
+ let resourceUtils = new ResourceUtils_1.ResourceUtils();
6
8
  describe("#getResourceProperty()", () => {
7
- it('should return property if property exists in valid inputJson', () => {
9
+ it("should return property if property exists in valid inputJson", () => {
8
10
  // execute
9
- const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
11
+ const actual = resourceUtils.getResourceProperty(patientPayload, "deceasedBoolean");
10
12
  // validate
11
13
  expect(actual).toBeFalse();
12
14
  });
13
- it('should return null if property exists in valid inputJson', () => {
15
+ it("should return null if property exists in valid inputJson", () => {
14
16
  // execute
15
- const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'abcd');
17
+ const actual = resourceUtils.getResourceProperty(patientPayload, "abcd");
16
18
  // validate
17
19
  expect(actual).toBeNull();
18
20
  });
19
- it('should return null if invalid inputJson is passed', () => {
21
+ it("should return null if invalid inputJson is passed", () => {
20
22
  // setup
21
23
  const inputPayload = [1, 2];
22
24
  // execute
23
- const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
25
+ const actual = resourceUtils.getResourceProperty(inputPayload, "deceasedBoolean");
24
26
  // validate
25
27
  expect(actual).toBeNull();
26
28
  });
@@ -42,7 +44,7 @@ describe("ResourceUtilities", () => {
42
44
  // setup
43
45
  const value = "abc";
44
46
  // execute
45
- const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(null, "abc", value);
47
+ const actual = resourceUtils.getIdentifiersByProperty(null, "abc", value);
46
48
  // validate
47
49
  expect(actual.length).toEqual(0);
48
50
  });
@@ -50,7 +52,7 @@ describe("ResourceUtilities", () => {
50
52
  // setup
51
53
  const value = "abc";
52
54
  // execute
53
- const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "abc", value);
55
+ const actual = resourceUtils.getIdentifiersByProperty(identifierList, "abc", value);
54
56
  // validate
55
57
  expect(actual.length).toEqual(0);
56
58
  });
@@ -58,7 +60,7 @@ describe("ResourceUtilities", () => {
58
60
  // setup
59
61
  const systemUrl = "http://somesystem.com";
60
62
  // execute
61
- const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "system", systemUrl);
63
+ const actual = resourceUtils.getIdentifiersByProperty(identifierList, "system", systemUrl);
62
64
  // validate
63
65
  expect(actual.length).toEqual(0);
64
66
  });
@@ -66,7 +68,7 @@ describe("ResourceUtilities", () => {
66
68
  // setup
67
69
  const value = "abc";
68
70
  // execute
69
- const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "value", value);
71
+ const actual = resourceUtils.getIdentifiersByProperty(identifierList, "value", value);
70
72
  // validate
71
73
  expect(actual.length).toEqual(2);
72
74
  });
@@ -84,7 +86,7 @@ describe("ResourceUtilities", () => {
84
86
  ];
85
87
  it("should return empty array if null is passed as extension list", () => {
86
88
  // execute
87
- const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(null, "url");
89
+ const actual = resourceUtils.getExtensionsByUrl(null, "url");
88
90
  // validate
89
91
  expect(actual.length).toEqual(0);
90
92
  });
@@ -99,7 +101,7 @@ describe("ResourceUtilities", () => {
99
101
  ];
100
102
  const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
101
103
  // execute
102
- const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionListInvalid, url);
104
+ const actual = resourceUtils.getExtensionsByUrl(extensionListInvalid, url);
103
105
  // validate
104
106
  expect(actual.length).toEqual(0);
105
107
  });
@@ -107,7 +109,7 @@ describe("ResourceUtilities", () => {
107
109
  // setup
108
110
  const url = "http://somesystem.com";
109
111
  // execute
110
- const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionList, url);
112
+ const actual = resourceUtils.getExtensionsByUrl(extensionList, url);
111
113
  // validate
112
114
  expect(actual.length).toEqual(0);
113
115
  });
@@ -115,7 +117,7 @@ describe("ResourceUtilities", () => {
115
117
  // setup
116
118
  const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
117
119
  // execute
118
- const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionList, url);
120
+ const actual = resourceUtils.getExtensionsByUrl(extensionList, url);
119
121
  // validate
120
122
  expect(actual.length).toEqual(1);
121
123
  });
@@ -140,7 +142,7 @@ describe("ResourceUtilities", () => {
140
142
  // setup
141
143
  const value = "abc";
142
144
  // execute
143
- const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(null, "abc", value);
145
+ const actual = resourceUtils.getCodingsByProperty(null, "abc", value);
144
146
  // validate
145
147
  expect(actual.length).toEqual(0);
146
148
  });
@@ -148,7 +150,7 @@ describe("ResourceUtilities", () => {
148
150
  // setup
149
151
  const value = "abc";
150
152
  // execute
151
- const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "abc", value);
153
+ const actual = resourceUtils.getCodingsByProperty(codingList, "abc", value);
152
154
  // validate
153
155
  expect(actual.length).toEqual(0);
154
156
  });
@@ -156,7 +158,7 @@ describe("ResourceUtilities", () => {
156
158
  // setup
157
159
  const systemUrl = "http://somesystem.com";
158
160
  // execute
159
- const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "system", systemUrl);
161
+ const actual = resourceUtils.getCodingsByProperty(codingList, "system", systemUrl);
160
162
  // validate
161
163
  expect(actual.length).toEqual(0);
162
164
  });
@@ -164,7 +166,7 @@ describe("ResourceUtilities", () => {
164
166
  // setup
165
167
  const value = "abc";
166
168
  // execute
167
- const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "code", value);
169
+ const actual = resourceUtils.getCodingsByProperty(codingList, "code", value);
168
170
  // validate
169
171
  expect(actual.length).toEqual(2);
170
172
  });
@@ -172,9 +174,66 @@ describe("ResourceUtilities", () => {
172
174
  // setup
173
175
  const value = false;
174
176
  // execute
175
- const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "userSelected", value);
177
+ const actual = resourceUtils.getCodingsByProperty(codingList, "userSelected", value);
176
178
  // validate
177
179
  expect(actual.length).toEqual(1);
178
180
  });
179
181
  });
182
+ describe("#getValuesAtResourcePath()", () => {
183
+ it("should return array with values if path exists for a top level element", () => {
184
+ // execute
185
+ const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
186
+ // validate
187
+ expect(pathValues.length).toEqual(1);
188
+ expect(pathValues[0]).toEqual("male");
189
+ });
190
+ it("should return array with values for a array under object", () => {
191
+ // execute
192
+ const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
193
+ // validate
194
+ expect(pathValues.length).toEqual(3);
195
+ expect(pathValues[0]).toEqual("Pieter");
196
+ expect(pathValues[1]).toEqual("Peter");
197
+ expect(pathValues[2]).toEqual("Pieter");
198
+ });
199
+ it("should return array with values if path exists for a deep array element", () => {
200
+ // execute
201
+ const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.contact.relationship.coding.system");
202
+ // validate
203
+ expect(pathValues.length).toEqual(2);
204
+ expect(pathValues[0]).toEqual("http://terminology.hl7.org/CodeSystem/v2-0131");
205
+ expect(pathValues[1]).toEqual("http://terminology.hl7.org/CodeSystem/v2-0132");
206
+ });
207
+ it("should return array with values if path exists for a deep json element", () => {
208
+ // execute
209
+ const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.maritalStatus.coding.system");
210
+ // validate
211
+ expect(pathValues.length).toEqual(1);
212
+ expect(pathValues[0]).toEqual("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus");
213
+ });
214
+ it("should return empty array if path does not exist", () => {
215
+ // execute
216
+ const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.contact.relationship.coding.abcd");
217
+ // validate
218
+ expect(pathValues.length).toEqual(0);
219
+ });
220
+ });
221
+ describe("#getAllResourceReferences()", () => {
222
+ it("should return array of all references in a resource when references found", () => {
223
+ // execute
224
+ const actual = resourceUtils.getAllReferencesFromResource(careTeamPayload);
225
+ // validate
226
+ expect(actual.length).toEqual(6);
227
+ });
228
+ it("should return empty array if references in a resource not found", () => {
229
+ // setup
230
+ const input = {
231
+ "resourceType": "Patient"
232
+ };
233
+ // execute
234
+ const actual = resourceUtils.getAllReferencesFromResource(input);
235
+ // validate
236
+ expect(actual.length).toEqual(0);
237
+ });
238
+ });
180
239
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.0.7",
3
+ "version": "2.1.1",
4
4
  "description": "Fhir ts/js library for frontend apps",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import * as fhirR4 from './FHIR-R4/classes/models-r4';
2
2
  import * as IfhirR4 from './FHIR-R4/interfaces/IModel';
3
3
  import * as fhirR3 from './FHIR-R3';
4
4
  import * as dstu2 from './FHIR-DSTU2';
5
- import { ResourceUtilities } from './library/ResourceUtilities/ResourceUtilities';
6
- import { BundleUtilities } from './library/BundleUtilities/BundleUtilities';
7
- export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtilities, BundleUtilities };
5
+ import { ResourceUtils } from './library/ResourceUtils/ResourceUtils';
6
+ import { BundleUtils } from './library/BundleUtils/BundleUtils';
7
+ export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils };
8
8
 
@@ -0,0 +1,65 @@
1
+ import { BundleUtils } from "./BundleUtils";
2
+
3
+ const inputPayload = require("./../../test-resources/Bundle-R4.json");
4
+ describe("BundleUtils", () => {
5
+
6
+ let bundleUtils = new BundleUtils();
7
+
8
+ describe("#getResources()", () => {
9
+ it("should return empty array if null is passed as bundle entries", () => {
10
+ // execute
11
+ const actual = bundleUtils.getResources(null, "Patient");
12
+ // validate
13
+ expect(actual.length).toEqual(0);
14
+ });
15
+
16
+ it("should return empty array if invalid resourceType is passed", () => {
17
+ // execute
18
+ const actual = bundleUtils.getResources(
19
+ inputPayload.entry,
20
+ "patient"
21
+ );
22
+ // validate
23
+ expect(actual.length).toEqual(0);
24
+ });
25
+
26
+ it("should return all matches array", () => {
27
+ // execute
28
+ const actual = bundleUtils.getResources(
29
+ inputPayload.entry,
30
+ "Claim"
31
+ );
32
+ // validate
33
+ expect(actual.length).toEqual(27);
34
+ });
35
+ });
36
+
37
+ describe("#getResource()", () => {
38
+ it("should return null if null is passed as bundle entries", () => {
39
+ // execute
40
+ const actual = bundleUtils.getResource(null, "123");
41
+ // validate
42
+ expect(actual).toBeNull();
43
+ });
44
+
45
+ it("should return undefined if resourceId is not found", () => {
46
+ // execute
47
+ const actual = bundleUtils.getResource(
48
+ inputPayload.entry,
49
+ "123"
50
+ );
51
+ // validate
52
+ expect(actual).toBeUndefined();
53
+ });
54
+
55
+ it("should return resource if resource is found", () => {
56
+ // execute
57
+ const actual = bundleUtils.getResource(
58
+ inputPayload.entry,
59
+ "ec0bb1b3-b229-36cf-7e34-3f5fec9d3afe"
60
+ );
61
+ // validate
62
+ expect(actual).not.toBeNull();
63
+ });
64
+ });
65
+ });