@smile-cdr/fhirts 1.5.0 → 2.0.0
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/.github/workflows/npm-publish.yml +4 -0
- package/.github/workflows/pr-build.yml +31 -0
- package/.nycrc +7 -0
- package/CHANGELOG.md +5 -0
- package/GETTINGSTARTED.md +40 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/library/BundleUtilities/BundleUtilities.d.ts +10 -0
- package/dist/library/BundleUtilities/BundleUtilities.js +16 -0
- package/dist/library/BundleUtilities/BundleUtilities.spec.d.ts +1 -0
- package/dist/library/BundleUtilities/BundleUtilities.spec.js +26 -0
- package/dist/library/ResourceUtilities/ResourceUtilities.d.ts +35 -0
- package/dist/library/ResourceUtilities/ResourceUtilities.js +51 -0
- package/dist/library/ResourceUtilities/ResourceUtilities.spec.d.ts +1 -0
- package/dist/library/ResourceUtilities/ResourceUtilities.spec.js +180 -0
- package/package.json +13 -2
- package/spec/support/jasmine.json +10 -0
- package/src/index.ts +3 -1
- package/src/library/BundleUtilities/BundleUtilities.spec.ts +29 -0
- package/src/library/BundleUtilities/BundleUtilities.ts +16 -0
- package/src/library/ResourceUtilities/ResourceUtilities.spec.ts +230 -0
- package/src/library/ResourceUtilities/ResourceUtilities.ts +52 -0
- package/src/test-resources/Bundle-R4.json +27472 -0
- package/src/test-resources/Patient-R4.json +125 -0
|
@@ -22,8 +22,12 @@ jobs:
|
|
|
22
22
|
registry-url: https://registry.npmjs.org
|
|
23
23
|
- name: Install Dependencies
|
|
24
24
|
run: npm install
|
|
25
|
+
- name: Run audit
|
|
26
|
+
run: npm run audit
|
|
25
27
|
- name: Compile Typescript
|
|
26
28
|
run: npm run-script build
|
|
29
|
+
- name: Run test with coverage
|
|
30
|
+
run: npm run-script coverage
|
|
27
31
|
- name: Publish to NPM
|
|
28
32
|
run: npm publish --access public
|
|
29
33
|
env:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Pull Request checks
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
paths-ignore:
|
|
11
|
+
- '**.md'
|
|
12
|
+
- '**.yml'
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build_and_test:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v2
|
|
19
|
+
- uses: actions/setup-node@v1
|
|
20
|
+
with:
|
|
21
|
+
node-version: 12
|
|
22
|
+
registry-url: https://registry.npmjs.org
|
|
23
|
+
- name: Install Dependencies
|
|
24
|
+
run: npm install
|
|
25
|
+
- name: Run audit
|
|
26
|
+
run: npm run audit
|
|
27
|
+
- name: Compile Typescript
|
|
28
|
+
run: npm run-script build
|
|
29
|
+
- name: Run test with coverage
|
|
30
|
+
run: npm run-script coverage
|
|
31
|
+
|
package/.nycrc
ADDED
package/CHANGELOG.md
CHANGED
package/GETTINGSTARTED.md
CHANGED
|
@@ -83,4 +83,43 @@ function getResourceType(resource:Resource){
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
```
|
|
86
|
-
If you try writing this out you will see that the variable `res` inside the `if` block is of type `CarePlan`. This was inferred automatically using the `if` condition (since as per the specification the only resources which can have `resourceType:"CarePlan"` are `CarePlan` resources).
|
|
86
|
+
If you try writing this out you will see that the variable `res` inside the `if` block is of type `CarePlan`. This was inferred automatically using the `if` condition (since as per the specification the only resources which can have `resourceType:"CarePlan"` are `CarePlan` resources).
|
|
87
|
+
|
|
88
|
+
## Utilities
|
|
89
|
+
|
|
90
|
+
- There are 2 new utilities available starting `v2.0.0`.
|
|
91
|
+
- BundleUtilities
|
|
92
|
+
- ResourceUtilities
|
|
93
|
+
- All of the above mentioned classes are currently in preliminary phase and will be refined in future as per needs.
|
|
94
|
+
- The above utlity classes include common functionalities used by front end applications using FHIR.
|
|
95
|
+
- All utilities functions are static right now, so, no need for instantiating classes. **Note: This is subject to change in future**
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
#### BundleUtilities usage
|
|
99
|
+
```js
|
|
100
|
+
import { BundleUtilities } from '@smilecdr/fhirts';
|
|
101
|
+
|
|
102
|
+
// returns list of Claim resources from Bundle.entry
|
|
103
|
+
const claimsList = BundleUtilities.getResourcesFromBundle(Bundle.entry, 'Claim');
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### ResourceUtilities usage
|
|
107
|
+
```js
|
|
108
|
+
import { ResourceUtilities } from '@smilecdr/fhirts';
|
|
109
|
+
|
|
110
|
+
// returns deserialized Patient resource
|
|
111
|
+
const deserializedPatientResource = ResourceUtilities.deserializeResource(jsonPatientPayload, new Patient());
|
|
112
|
+
|
|
113
|
+
// returns Patient.gender
|
|
114
|
+
const patientGender = ResourceUtilities.getResourceProperty(jsonPatientPayload, 'gender');
|
|
115
|
+
|
|
116
|
+
// returns all matching identifiers where Identifier.use = usual
|
|
117
|
+
const identifierFilter = ResourceUtilities.getIdentifiersByProperty(identifierList,"use","usual");
|
|
118
|
+
|
|
119
|
+
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
120
|
+
// returns all matching extensions where Extension.use = "http://ns.electronichealth.net.au/id/hi/ihi/1.0"
|
|
121
|
+
const extensionFilter = ResourceUtilities.getExtensionsByUrl(extensionList, url);
|
|
122
|
+
|
|
123
|
+
// returns all matching codings where Coding.code = "abc"
|
|
124
|
+
const codingFilter = ResourceUtilities.getCodingsByProperty(codingList,"code","abc");
|
|
125
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +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
|
-
|
|
5
|
+
import { ResourceUtilities } from './library/ResourceUtilities/ResourceUtilities';
|
|
6
|
+
import { BundleUtilities } from './library/BundleUtilities/BundleUtilities';
|
|
7
|
+
export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtilities, BundleUtilities };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dstu2 = exports.IfhirR4 = exports.fhirR3 = exports.fhirR4 = void 0;
|
|
3
|
+
exports.BundleUtilities = exports.ResourceUtilities = 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,3 +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; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class BundleUtility {
|
|
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
|
+
getResourcesFromBundle(bundleEntry: any[], resourceTypeToFilter: string): any[];
|
|
9
|
+
}
|
|
10
|
+
export declare const BundleUtilities: BundleUtility;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BundleUtilities = exports.BundleUtility = void 0;
|
|
4
|
+
class BundleUtility {
|
|
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
|
+
getResourcesFromBundle(bundleEntry, resourceTypeToFilter) {
|
|
12
|
+
return (bundleEntry === null || bundleEntry === void 0 ? void 0 : bundleEntry.length) ? bundleEntry.filter(x => x['resource']['resourceType'] === resourceTypeToFilter) : [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.BundleUtility = BundleUtility;
|
|
16
|
+
exports.BundleUtilities = new BundleUtility();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const BundleUtilities_1 = require("./BundleUtilities");
|
|
4
|
+
const inputPayload = require("./../../test-resources/Bundle-R4.json");
|
|
5
|
+
describe("BundleUtilities", () => {
|
|
6
|
+
describe("#getResourcesFromBundle()", () => {
|
|
7
|
+
it('should return empty array if null is passed as bundle entries', () => {
|
|
8
|
+
// execute
|
|
9
|
+
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(null, 'Patient');
|
|
10
|
+
// validate
|
|
11
|
+
expect(actual.length).toEqual(0);
|
|
12
|
+
});
|
|
13
|
+
it('should return empty array if invalid resourceType is passed', () => {
|
|
14
|
+
// execute
|
|
15
|
+
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'patient');
|
|
16
|
+
// validate
|
|
17
|
+
expect(actual.length).toEqual(0);
|
|
18
|
+
});
|
|
19
|
+
it('should return all matches array', () => {
|
|
20
|
+
// execute
|
|
21
|
+
const actual = BundleUtilities_1.BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'Claim');
|
|
22
|
+
// validate
|
|
23
|
+
expect(actual.length).toEqual(27);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class ResourceUtility {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param inputJson - valid json
|
|
5
|
+
* @param propertyName - top level property for resource
|
|
6
|
+
* @returns json property if it exists
|
|
7
|
+
* @limitation currently just supports get for top level property on resource
|
|
8
|
+
*/
|
|
9
|
+
getResourceProperty(inputJson: object, propertyName: string): any;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param identifierList list of identifiers
|
|
13
|
+
* @param propertyToCompare identifier property to compare
|
|
14
|
+
* @param propertyValue value we want to compare against
|
|
15
|
+
* @returns array of matches
|
|
16
|
+
* @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
|
|
17
|
+
*/
|
|
18
|
+
getIdentifiersByProperty(identifierList: any[], propertyToCompare: string, propertyValue: string): any[];
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param extensionList list of extensions
|
|
22
|
+
* @param extensionUrl Extension.url to compare
|
|
23
|
+
* @returns array of matches
|
|
24
|
+
*/
|
|
25
|
+
getExtensionsByUrl(extensionList: any[], extensionUrl: string): any[];
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param codingList list of codings
|
|
29
|
+
* @param propertyToCompare coding property to compare
|
|
30
|
+
* @param propertyValue value we want to compare against string or boolean
|
|
31
|
+
* @returns array of matches
|
|
32
|
+
*/
|
|
33
|
+
getCodingsByProperty(codingList: any[], propertyToCompare: string, propertyValue: string | boolean): any[];
|
|
34
|
+
}
|
|
35
|
+
export declare const ResourceUtilities: ResourceUtility;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceUtilities = exports.ResourceUtility = void 0;
|
|
4
|
+
class ResourceUtility {
|
|
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) ? identifierList.filter(x => x[propertyToCompare] === propertyValue) : [];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param extensionList list of extensions
|
|
33
|
+
* @param extensionUrl Extension.url to compare
|
|
34
|
+
* @returns array of matches
|
|
35
|
+
*/
|
|
36
|
+
getExtensionsByUrl(extensionList, extensionUrl) {
|
|
37
|
+
return (extensionList === null || extensionList === void 0 ? void 0 : extensionList.length) ? extensionList.filter(x => x['url'] === extensionUrl) : [];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param codingList list of codings
|
|
42
|
+
* @param propertyToCompare coding property to compare
|
|
43
|
+
* @param propertyValue value we want to compare against string or boolean
|
|
44
|
+
* @returns array of matches
|
|
45
|
+
*/
|
|
46
|
+
getCodingsByProperty(codingList, propertyToCompare, propertyValue) {
|
|
47
|
+
return (codingList === null || codingList === void 0 ? void 0 : codingList.length) ? codingList.filter(x => x[propertyToCompare] === propertyValue) : [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ResourceUtility = ResourceUtility;
|
|
51
|
+
exports.ResourceUtilities = new ResourceUtility();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
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", () => {
|
|
6
|
+
describe("#getResourceProperty()", () => {
|
|
7
|
+
it('should return property if property exists in valid inputJson', () => {
|
|
8
|
+
// execute
|
|
9
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
|
|
10
|
+
// validate
|
|
11
|
+
expect(actual).toBeFalse();
|
|
12
|
+
});
|
|
13
|
+
it('should return null if property exists in valid inputJson', () => {
|
|
14
|
+
// execute
|
|
15
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'abcd');
|
|
16
|
+
// validate
|
|
17
|
+
expect(actual).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
it('should return null if invalid inputJson is passed', () => {
|
|
20
|
+
// setup
|
|
21
|
+
const inputPayload = [1, 2];
|
|
22
|
+
// execute
|
|
23
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getResourceProperty(inputPayload, 'deceasedBoolean');
|
|
24
|
+
// validate
|
|
25
|
+
expect(actual).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe("#getIdentifiersByProperty()", () => {
|
|
29
|
+
const identifierList = [
|
|
30
|
+
{
|
|
31
|
+
use: "temp",
|
|
32
|
+
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
33
|
+
value: "abc",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
use: "usual",
|
|
37
|
+
system: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
|
|
38
|
+
value: "abc",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
it("should return empty array if null is passed as identifier list", () => {
|
|
42
|
+
// setup
|
|
43
|
+
const value = "abc";
|
|
44
|
+
// execute
|
|
45
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(null, "abc", value);
|
|
46
|
+
// validate
|
|
47
|
+
expect(actual.length).toEqual(0);
|
|
48
|
+
});
|
|
49
|
+
it("should return empty array if property not found", () => {
|
|
50
|
+
// setup
|
|
51
|
+
const value = "abc";
|
|
52
|
+
// execute
|
|
53
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "abc", value);
|
|
54
|
+
// validate
|
|
55
|
+
expect(actual.length).toEqual(0);
|
|
56
|
+
});
|
|
57
|
+
it("should return empty array if no matches found", () => {
|
|
58
|
+
// setup
|
|
59
|
+
const systemUrl = "http://somesystem.com";
|
|
60
|
+
// execute
|
|
61
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "system", systemUrl);
|
|
62
|
+
// validate
|
|
63
|
+
expect(actual.length).toEqual(0);
|
|
64
|
+
});
|
|
65
|
+
it("should return array with all matches", () => {
|
|
66
|
+
// setup
|
|
67
|
+
const value = "abc";
|
|
68
|
+
// execute
|
|
69
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getIdentifiersByProperty(identifierList, "value", value);
|
|
70
|
+
// validate
|
|
71
|
+
expect(actual.length).toEqual(2);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("#getExtensionsByUrl()", () => {
|
|
75
|
+
const extensionList = [
|
|
76
|
+
{
|
|
77
|
+
url: "http://hl7.org/fhir/sid/us-ssn",
|
|
78
|
+
valueBoolean: true,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
url: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
|
|
82
|
+
valueString: "abc",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
it("should return empty array if null is passed as extension list", () => {
|
|
86
|
+
// execute
|
|
87
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(null, "url");
|
|
88
|
+
// validate
|
|
89
|
+
expect(actual.length).toEqual(0);
|
|
90
|
+
});
|
|
91
|
+
it("should return empty array if invalid extension array passed", () => {
|
|
92
|
+
// setup
|
|
93
|
+
const extensionListInvalid = [
|
|
94
|
+
{
|
|
95
|
+
use: "temp",
|
|
96
|
+
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
97
|
+
value: "abc",
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
101
|
+
// execute
|
|
102
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionListInvalid, url);
|
|
103
|
+
// validate
|
|
104
|
+
expect(actual.length).toEqual(0);
|
|
105
|
+
});
|
|
106
|
+
it("should return empty array if no matches found", () => {
|
|
107
|
+
// setup
|
|
108
|
+
const url = "http://somesystem.com";
|
|
109
|
+
// execute
|
|
110
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionList, url);
|
|
111
|
+
// validate
|
|
112
|
+
expect(actual.length).toEqual(0);
|
|
113
|
+
});
|
|
114
|
+
it("should return array with all matches", () => {
|
|
115
|
+
// setup
|
|
116
|
+
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
117
|
+
// execute
|
|
118
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getExtensionsByUrl(extensionList, url);
|
|
119
|
+
// validate
|
|
120
|
+
expect(actual.length).toEqual(1);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("#getCodingsByProperty()", () => {
|
|
124
|
+
const codingList = [
|
|
125
|
+
{
|
|
126
|
+
version: "1.0",
|
|
127
|
+
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
128
|
+
code: "abc",
|
|
129
|
+
display: "abc",
|
|
130
|
+
userSelected: false,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
version: "1.1",
|
|
134
|
+
system: "http://ns.electronichealth.net.au/id/hi/ihi/1.0",
|
|
135
|
+
code: "abc",
|
|
136
|
+
display: "abc",
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
it("should return empty array if null is passed as coding list", () => {
|
|
140
|
+
// setup
|
|
141
|
+
const value = "abc";
|
|
142
|
+
// execute
|
|
143
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(null, "abc", value);
|
|
144
|
+
// validate
|
|
145
|
+
expect(actual.length).toEqual(0);
|
|
146
|
+
});
|
|
147
|
+
it("should return empty array if property not found", () => {
|
|
148
|
+
// setup
|
|
149
|
+
const value = "abc";
|
|
150
|
+
// execute
|
|
151
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "abc", value);
|
|
152
|
+
// validate
|
|
153
|
+
expect(actual.length).toEqual(0);
|
|
154
|
+
});
|
|
155
|
+
it("should return empty array if no matches found", () => {
|
|
156
|
+
// setup
|
|
157
|
+
const systemUrl = "http://somesystem.com";
|
|
158
|
+
// execute
|
|
159
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "system", systemUrl);
|
|
160
|
+
// validate
|
|
161
|
+
expect(actual.length).toEqual(0);
|
|
162
|
+
});
|
|
163
|
+
it("should return array with all matches for string values", () => {
|
|
164
|
+
// setup
|
|
165
|
+
const value = "abc";
|
|
166
|
+
// execute
|
|
167
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "code", value);
|
|
168
|
+
// validate
|
|
169
|
+
expect(actual.length).toEqual(2);
|
|
170
|
+
});
|
|
171
|
+
it("should return array with all matches for boolean values", () => {
|
|
172
|
+
// setup
|
|
173
|
+
const value = false;
|
|
174
|
+
// execute
|
|
175
|
+
const actual = ResourceUtilities_1.ResourceUtilities.getCodingsByProperty(codingList, "userSelected", value);
|
|
176
|
+
// validate
|
|
177
|
+
expect(actual.length).toEqual(1);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smile-cdr/fhirts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Fhir ts/js library for frontend apps",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"repository": "git://github.com/smilecdr/FHIR.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc"
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "ts-node --project ./tsconfig.json node_modules/jasmine/bin/jasmine --config=spec/support/jasmine.json",
|
|
12
|
+
"coverage": "nyc npm run test",
|
|
13
|
+
"audit": "better-npm-audit audit"
|
|
11
14
|
},
|
|
12
15
|
"devDependencies": {
|
|
16
|
+
"@types/jasmine": "^4.3.1",
|
|
17
|
+
"jasmine": "^4.5.0",
|
|
18
|
+
"ts-node": "^10.9.1",
|
|
13
19
|
"typescript": "^4.0.2"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@types/node": "^18.11.15",
|
|
23
|
+
"better-npm-audit": "^3.7.3",
|
|
24
|
+
"nyc": "^15.1.0"
|
|
14
25
|
}
|
|
15
26
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,5 +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
|
-
|
|
5
|
+
import { ResourceUtilities } from './library/ResourceUtilities/ResourceUtilities';
|
|
6
|
+
import { BundleUtilities } from './library/BundleUtilities/BundleUtilities';
|
|
7
|
+
export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtilities, BundleUtilities };
|
|
6
8
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Patient } from "../../FHIR-R4/classes/patient";
|
|
2
|
+
import { BundleUtilities } from "./BundleUtilities";
|
|
3
|
+
|
|
4
|
+
const inputPayload = require("./../../test-resources/Bundle-R4.json");
|
|
5
|
+
describe("BundleUtilities", () => {
|
|
6
|
+
|
|
7
|
+
describe("#getResourcesFromBundle()", () => {
|
|
8
|
+
it('should return empty array if null is passed as bundle entries', () => {
|
|
9
|
+
// execute
|
|
10
|
+
const actual = BundleUtilities.getResourcesFromBundle(null, 'Patient');
|
|
11
|
+
// validate
|
|
12
|
+
expect(actual.length).toEqual(0);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return empty array if invalid resourceType is passed', () => {
|
|
16
|
+
// execute
|
|
17
|
+
const actual = BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'patient');
|
|
18
|
+
// validate
|
|
19
|
+
expect(actual.length).toEqual(0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return all matches array', () => {
|
|
23
|
+
// execute
|
|
24
|
+
const actual = BundleUtilities.getResourcesFromBundle(inputPayload.entry, 'Claim');
|
|
25
|
+
// validate
|
|
26
|
+
expect(actual.length).toEqual(27);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class BundleUtility {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param bundleEntry Bundle.entry[] i.e. the bundle entries to filter
|
|
6
|
+
* @param resourceTypeToFilter ResourceType to filter from bundle entries
|
|
7
|
+
* @returns array of resources
|
|
8
|
+
*/
|
|
9
|
+
getResourcesFromBundle(bundleEntry: any[], resourceTypeToFilter: string): any[] {
|
|
10
|
+
return bundleEntry?.length ? bundleEntry.filter(x => x['resource']['resourceType'] === resourceTypeToFilter) : [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const BundleUtilities = new BundleUtility();
|
|
15
|
+
|
|
16
|
+
|