@smile-cdr/fhirts 2.2.1 → 2.2.3

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.2
4
+
5
+ * Added `PatchUtils` for generating Parameters resource for `FHIR Patch`.
6
+
3
7
  ## 2.2.1
4
8
 
5
9
  * Added resource definitions for FHIR R5.
package/GETTINGSTARTED.md CHANGED
@@ -1,13 +1,5 @@
1
1
  # Getting Started
2
2
 
3
- ## Installing FHIR.ts
4
-
5
- Navigate to your project and install the library using `npm`
6
-
7
- ```shell
8
- $ npm i @smile-cdr/fhirts
9
- ```
10
-
11
3
  ## Setting Up Your First FHIR Resource
12
4
 
13
5
  FHIR.ts offers both classes & interfaces for various FHIR resources - which one(s) you choose to use will depend on what your use case is.
package/README.md CHANGED
@@ -4,16 +4,23 @@
4
4
 
5
5
  ## About
6
6
 
7
- FHIR.ts is a library that aims to assist web developers building FHIR applications by providing a set of classes & interfaces that match the resources outlined in the [FHIR spec](https://www.hl7.org/fhir/)
7
+ `FHIR.ts` is a library that aims to assist web developers building FHIR applications by providing a set of utility methods as well as classes & interfaces that match the resources outlined in the [FHIR spec](https://www.hl7.org/fhir/).
8
8
 
9
9
  The following library contains classes and interfaces for [FHIR](https://www.hl7.org/fhir/) versions.
10
10
 
11
11
  * R3 is intended for projects using FHIR [R3](https://www.hl7.org/fhir/stu3/).
12
- * R4 is intended for projects using FHIR [R4](http://hl7.org/fhir/index.html). The definitions are generated using [Swagger Codegen](https://github.com/swagger-api/swagger-codegen).
12
+ * R4 is intended for projects using FHIR [R4](https://hl7.org/fhir/R4/). The definitions are generated using [Swagger Codegen](https://github.com/swagger-api/swagger-codegen).
13
+ * R5 is intended for projects using FHIR. [R5](https://hl7.org/fhir/R5/). The definitions are generated using [Swagger Codegen](https://github.com/swagger-api/swagger-codegen)
13
14
 
14
15
 
15
16
  **Note**: This library does not include all FHIR TypeScript definitions for R3. The idea is to collaborate and expand this library.
16
17
 
18
+ #### Table of Contents
19
+
20
+ - [Installation](#installation)
21
+ - [Contribute](#contribute)
22
+ - [File a bug](#file-a-bug)
23
+
17
24
  ## Installation
18
25
 
19
26
  Using npm:
@@ -21,17 +28,28 @@ Using npm:
21
28
  $ npm i @smile-cdr/fhirts
22
29
  ```
23
30
 
31
+ Using yarn:
32
+ ```shell
33
+ $ yarn add @smile-cdr/fhirts
34
+ ```
35
+
24
36
  ## Usage
25
37
 
26
38
  Checkout the [Getting Started section](GETTINGSTARTED.md) for how to use the library.
27
39
 
28
- ## Dev Process
40
+ ## Contribute
29
41
 
30
- 1. Create an issue.
42
+ 1. Create an [issue](https://github.com/smilecdr/FHIR.ts/issues) and attach appropriate labels.
31
43
  2. Create a branch related to the issue.
32
- 3. Make necessary changes and upgrade library version in `package.json` file. This is a must as npm doesn't allow publish on same version.
44
+ 3. Make necessary changes and upgrade library version in `package.json` file. This is a must as currently we don't have a CI job which can override a package with same version. doesn't allow publish on same version.
33
45
  4. Push changes & create a Pull Request.
46
+ 5. Get reviewed and merged !!!
47
+
48
+
49
+ ## File a bug
34
50
 
51
+ 1. Create an [issue](https://github.com/smilecdr/FHIR.ts/issues) and attach appropriate labels.
52
+ 2. The issue will be prioritized and worked on.
35
53
 
36
54
 
37
55
 
package/dist/index.d.ts CHANGED
@@ -6,4 +6,6 @@ import * as dstu2 from './FHIR-DSTU2';
6
6
  import { ResourceUtils } from './library/ResourceUtils/ResourceUtils';
7
7
  import { BundleUtils } from './library/BundleUtils/BundleUtils';
8
8
  import { QueryBuilder } from './library/QueryBuilder/QueryBuilder';
9
- export { fhirR5, fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils, QueryBuilder };
9
+ import { PatchUtils } from './library/PatchUtils/PatchUtils';
10
+ import * as fhirtsConstants from './library/constants';
11
+ export { fhirR5, fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils, QueryBuilder, PatchUtils, fhirtsConstants };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryBuilder = exports.BundleUtils = exports.ResourceUtils = exports.dstu2 = exports.IfhirR4 = exports.fhirR3 = exports.fhirR4 = exports.fhirR5 = void 0;
3
+ exports.fhirtsConstants = exports.PatchUtils = exports.QueryBuilder = exports.BundleUtils = exports.ResourceUtils = exports.dstu2 = exports.IfhirR4 = exports.fhirR3 = exports.fhirR4 = exports.fhirR5 = void 0;
4
4
  const fhirR5 = require("./FHIR-R5/models");
5
5
  exports.fhirR5 = fhirR5;
6
6
  const fhirR4 = require("./FHIR-R4/classes/models-r4");
@@ -17,3 +17,7 @@ const BundleUtils_1 = require("./library/BundleUtils/BundleUtils");
17
17
  Object.defineProperty(exports, "BundleUtils", { enumerable: true, get: function () { return BundleUtils_1.BundleUtils; } });
18
18
  const QueryBuilder_1 = require("./library/QueryBuilder/QueryBuilder");
19
19
  Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return QueryBuilder_1.QueryBuilder; } });
20
+ const PatchUtils_1 = require("./library/PatchUtils/PatchUtils");
21
+ Object.defineProperty(exports, "PatchUtils", { enumerable: true, get: function () { return PatchUtils_1.PatchUtils; } });
22
+ const fhirtsConstants = require("./library/constants");
23
+ exports.fhirtsConstants = fhirtsConstants;
@@ -0,0 +1,72 @@
1
+ import { PATCH_DATATYPE, PatchAddValueParams, PatchAddBackboneElementParams } from "../constants";
2
+ /**
3
+ * This a simple utility to create Parameters resource for FHIR patch operation
4
+ * https://www.hl7.org/fhir/fhirpatch.html
5
+ */
6
+ export declare class PatchUtils {
7
+ private REPLACE_OPERATION_NAME;
8
+ private DELETE_OPERATION_NAME;
9
+ private MOVE_OPERATION_NAME;
10
+ private ADD_OPERATION_NAME;
11
+ private INSERT_OPERATION_NAME;
12
+ private readonly PARAMETER_PROPERTY_NAME;
13
+ private baseParameters;
14
+ /**
15
+ *
16
+ * @param path the path to replace value of
17
+ * @param value the value to replace with
18
+ * @param valueDataType the data type of value
19
+ * @returns Parameters resource for FHIR patch replace operation
20
+ */
21
+ createReplaceParameters(path: string, value: any, valueDataType: PATCH_DATATYPE): this;
22
+ /**
23
+ *
24
+ * @param path the path to delete value of
25
+ * @returns Parameters resource for FHIR patch delete operation
26
+ */
27
+ createDeleteParameters(path: string): this;
28
+ /**
29
+ *
30
+ * @param path the path to property where the index of items needs to be changed
31
+ * @param source the index to move
32
+ * @param destination the index where the value will be moved
33
+ * @returns Parameters resource for FHIR patch move operation
34
+ */
35
+ createMoveParameters(path: string, source: number, destination: number): this;
36
+ /**
37
+ * @param path the path at which to add the content
38
+ * @param name name of the property to add
39
+ * @param patchAddValueParams the value to replace with & the data type of value
40
+ * @returns Parameters resource for FHIR patch add operation
41
+ */
42
+ createAddParameters(path: string, name: string, patchAddValueParams: PatchAddValueParams): this;
43
+ /**
44
+ *
45
+ * @param path the path at which to add the content
46
+ * @param name name of the property to add
47
+ * @param patchAddValueParams the value to replace with, the data type of value & the backbone element property
48
+ * @returns
49
+ */
50
+ createAddParametersForBackboneElement(path: string, name: string, patchAddValueParams: PatchAddBackboneElementParams[]): this;
51
+ /**
52
+ *
53
+ * @param path the path at which to insert the value
54
+ * @param value the value to insert
55
+ * @param valueDataType the datatype of the value
56
+ * @param index the index at which the value should be inserted
57
+ * @returns Parameters resource for FHIR patch insert operation
58
+ */
59
+ createInsertParameters(path: string, value: any, valueDataType: PATCH_DATATYPE, index: number): this;
60
+ /**
61
+ * @returns the parameters resource created for FHIR PATCH operation
62
+ */
63
+ getPatchParameters(): {
64
+ resourceType: string;
65
+ parameter: any[];
66
+ };
67
+ /**
68
+ * Resets the parameter property in PATCH parameters resource
69
+ */
70
+ resetPatchParameters(): this;
71
+ private getCommonAddParameters;
72
+ }
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PatchUtils = void 0;
4
+ /**
5
+ * This a simple utility to create Parameters resource for FHIR patch operation
6
+ * https://www.hl7.org/fhir/fhirpatch.html
7
+ */
8
+ class PatchUtils {
9
+ constructor() {
10
+ this.REPLACE_OPERATION_NAME = "replace";
11
+ this.DELETE_OPERATION_NAME = "delete";
12
+ this.MOVE_OPERATION_NAME = "move";
13
+ this.ADD_OPERATION_NAME = "add";
14
+ this.INSERT_OPERATION_NAME = "insert";
15
+ this.PARAMETER_PROPERTY_NAME = "parameter";
16
+ this.baseParameters = {
17
+ resourceType: "Parameters",
18
+ parameter: [],
19
+ };
20
+ }
21
+ /**
22
+ *
23
+ * @param path the path to replace value of
24
+ * @param value the value to replace with
25
+ * @param valueDataType the data type of value
26
+ * @returns Parameters resource for FHIR patch replace operation
27
+ */
28
+ createReplaceParameters(path, value, valueDataType) {
29
+ const replaceParameters = {
30
+ name: "operation",
31
+ part: [
32
+ {
33
+ name: "type",
34
+ valueCode: this.REPLACE_OPERATION_NAME,
35
+ },
36
+ {
37
+ name: "path",
38
+ valueString: path,
39
+ },
40
+ {
41
+ name: "value",
42
+ [valueDataType]: value,
43
+ },
44
+ ],
45
+ };
46
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(replaceParameters);
47
+ return this;
48
+ }
49
+ /**
50
+ *
51
+ * @param path the path to delete value of
52
+ * @returns Parameters resource for FHIR patch delete operation
53
+ */
54
+ createDeleteParameters(path) {
55
+ const deleteParameters = {
56
+ name: "operation",
57
+ part: [
58
+ {
59
+ name: "type",
60
+ valueCode: this.DELETE_OPERATION_NAME,
61
+ },
62
+ {
63
+ name: "path",
64
+ valueString: path,
65
+ },
66
+ ],
67
+ };
68
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(deleteParameters);
69
+ return this;
70
+ }
71
+ /**
72
+ *
73
+ * @param path the path to property where the index of items needs to be changed
74
+ * @param source the index to move
75
+ * @param destination the index where the value will be moved
76
+ * @returns Parameters resource for FHIR patch move operation
77
+ */
78
+ createMoveParameters(path, source, destination) {
79
+ const moveParameters = {
80
+ name: "operation",
81
+ part: [
82
+ {
83
+ name: "type",
84
+ valueCode: this.MOVE_OPERATION_NAME,
85
+ },
86
+ {
87
+ name: "path",
88
+ valueString: path,
89
+ },
90
+ {
91
+ name: "source",
92
+ valueInteger: source,
93
+ },
94
+ {
95
+ name: "destination",
96
+ valueInteger: destination,
97
+ },
98
+ ],
99
+ };
100
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(moveParameters);
101
+ return this;
102
+ }
103
+ /**
104
+ * @param path the path at which to add the content
105
+ * @param name name of the property to add
106
+ * @param patchAddValueParams the value to replace with & the data type of value
107
+ * @returns Parameters resource for FHIR patch add operation
108
+ */
109
+ createAddParameters(path, name, patchAddValueParams) {
110
+ const addParameters = {
111
+ name: "operation",
112
+ part: [
113
+ ...this.getCommonAddParameters(path, name),
114
+ {
115
+ name: "value",
116
+ [patchAddValueParams.valueDataType]: patchAddValueParams.value,
117
+ },
118
+ ],
119
+ };
120
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(addParameters);
121
+ return this;
122
+ }
123
+ /**
124
+ *
125
+ * @param path the path at which to add the content
126
+ * @param name name of the property to add
127
+ * @param patchAddValueParams the value to replace with, the data type of value & the backbone element property
128
+ * @returns
129
+ */
130
+ createAddParametersForBackboneElement(path, name, patchAddValueParams) {
131
+ const parts = [];
132
+ patchAddValueParams.forEach((x) => {
133
+ parts.push({
134
+ name: x.backBoneElementProperty,
135
+ [x.valueDataType]: x.value,
136
+ });
137
+ });
138
+ const addParameters = {
139
+ name: "operation",
140
+ part: [
141
+ ...this.getCommonAddParameters(path, name),
142
+ {
143
+ name: "value",
144
+ part: parts,
145
+ },
146
+ ],
147
+ };
148
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(addParameters);
149
+ return this;
150
+ }
151
+ /**
152
+ *
153
+ * @param path the path at which to insert the value
154
+ * @param value the value to insert
155
+ * @param valueDataType the datatype of the value
156
+ * @param index the index at which the value should be inserted
157
+ * @returns Parameters resource for FHIR patch insert operation
158
+ */
159
+ createInsertParameters(path, value, valueDataType, index) {
160
+ const insertParameters = {
161
+ name: "operation",
162
+ part: [
163
+ {
164
+ name: "type",
165
+ valueCode: this.INSERT_OPERATION_NAME,
166
+ },
167
+ {
168
+ name: "path",
169
+ valueString: path,
170
+ },
171
+ {
172
+ name: "index",
173
+ valueInteger: index,
174
+ },
175
+ {
176
+ name: "value",
177
+ [valueDataType]: value,
178
+ },
179
+ ],
180
+ };
181
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(insertParameters);
182
+ return this;
183
+ }
184
+ /**
185
+ * @returns the parameters resource created for FHIR PATCH operation
186
+ */
187
+ getPatchParameters() {
188
+ return this.baseParameters;
189
+ }
190
+ /**
191
+ * Resets the parameter property in PATCH parameters resource
192
+ */
193
+ resetPatchParameters() {
194
+ this.baseParameters.parameter = [];
195
+ return this;
196
+ }
197
+ getCommonAddParameters(path, name) {
198
+ return [
199
+ {
200
+ name: "type",
201
+ valueCode: this.ADD_OPERATION_NAME,
202
+ },
203
+ {
204
+ name: "path",
205
+ valueString: path,
206
+ },
207
+ {
208
+ name: "name",
209
+ valueString: name,
210
+ },
211
+ ];
212
+ }
213
+ }
214
+ exports.PatchUtils = PatchUtils;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const PatchUtils_1 = require("./PatchUtils");
5
+ describe("PatchUtils", () => {
6
+ let patchUtils;
7
+ beforeEach(() => {
8
+ patchUtils = new PatchUtils_1.PatchUtils();
9
+ });
10
+ it('createReplaceParameters() should create Parameters for FHIR patch replace operation', () => {
11
+ // setup
12
+ const expected = {
13
+ "resourceType": "Parameters",
14
+ "parameter": [{
15
+ "name": "operation",
16
+ "part": [{
17
+ "name": "type",
18
+ "valueCode": "replace"
19
+ }, {
20
+ "name": "path",
21
+ "valueString": "Patient.birthDate"
22
+ }, {
23
+ "name": "value",
24
+ "valueDate": "1930-01-01"
25
+ }]
26
+ }]
27
+ };
28
+ // execute
29
+ const actual = patchUtils.createReplaceParameters("Patient.birthDate", "1930-01-01", constants_1.PATCH_DATATYPE.DATE);
30
+ // validate
31
+ expect(actual.getPatchParameters()).toEqual(expected);
32
+ });
33
+ it('createDeleteParameters() should create Parameters for FHIR patch delete operation', () => {
34
+ // setup
35
+ const expected = {
36
+ "resourceType": "Parameters",
37
+ "parameter": [{
38
+ "name": "operation",
39
+ "part": [{
40
+ "name": "type",
41
+ "valueCode": "delete"
42
+ }, {
43
+ "name": "path",
44
+ "valueString": "Patient.status"
45
+ }]
46
+ }]
47
+ };
48
+ // execute
49
+ const actual = patchUtils.createDeleteParameters("Patient.status");
50
+ // validate
51
+ expect(actual.getPatchParameters()).toEqual(expected);
52
+ });
53
+ it('createMoveParameters() should create Parameters for FHIR patch move operation', () => {
54
+ // setup
55
+ const expected = {
56
+ "resourceType": "Parameters",
57
+ "parameter": [{
58
+ "name": "operation",
59
+ "part": [{
60
+ "name": "type",
61
+ "valueCode": "move"
62
+ }, {
63
+ "name": "path",
64
+ "valueString": "Patient.identifier"
65
+ }, {
66
+ "name": "source",
67
+ "valueInteger": 0
68
+ }, {
69
+ "name": "destination",
70
+ "valueInteger": 1
71
+ }]
72
+ }]
73
+ };
74
+ // execute
75
+ const actual = patchUtils.createMoveParameters("Patient.identifier", 0, 1);
76
+ // validate
77
+ expect(actual.getPatchParameters()).toEqual(expected);
78
+ });
79
+ it('createAddParameters() should create Parameters for FHIR patch add operation', () => {
80
+ // setup
81
+ const expected = {
82
+ "resourceType": "Parameters",
83
+ "parameter": [{
84
+ "name": "operation",
85
+ "part": [{
86
+ "name": "type",
87
+ "valueCode": "add"
88
+ }, {
89
+ "name": "path",
90
+ "valueString": "Patient"
91
+ }, {
92
+ "name": "name",
93
+ "valueString": "birthDate"
94
+ }, {
95
+ "name": "value",
96
+ "valueDate": "1930-01-01"
97
+ }]
98
+ }]
99
+ };
100
+ const params = {
101
+ "value": "1930-01-01",
102
+ "valueDataType": constants_1.PATCH_DATATYPE.DATE
103
+ };
104
+ // execute
105
+ const actual = patchUtils.createAddParameters("Patient", "birthDate", params);
106
+ // validate
107
+ expect(actual.getPatchParameters()).toEqual(expected);
108
+ });
109
+ it('createAddParametersForBackboneElement() should create Parameters for FHIR patch add operation', () => {
110
+ // setup
111
+ const expected = {
112
+ "resourceType": "Parameters",
113
+ "parameter": [
114
+ {
115
+ "name": "operation",
116
+ "part": [
117
+ {
118
+ "name": "type",
119
+ "valueCode": "add"
120
+ },
121
+ {
122
+ "name": "path",
123
+ "valueString": "Patient"
124
+ },
125
+ {
126
+ "name": "name",
127
+ "valueString": "contact"
128
+ },
129
+ {
130
+ "name": "value",
131
+ "part": [
132
+ {
133
+ "name": "address",
134
+ "valueAddress": {
135
+ "use": "work"
136
+ }
137
+ },
138
+ {
139
+ "name": "name",
140
+ "valueHumanName": {
141
+ "use": "official"
142
+ }
143
+ }
144
+ ]
145
+ }
146
+ ]
147
+ },
148
+ ]
149
+ };
150
+ const params = [{
151
+ "value": {
152
+ "use": "work"
153
+ },
154
+ "valueDataType": constants_1.PATCH_DATATYPE.ADDRESS,
155
+ "backBoneElementProperty": "address"
156
+ }, {
157
+ "value": {
158
+ "use": "official"
159
+ },
160
+ "valueDataType": constants_1.PATCH_DATATYPE.HUMAN_NAME,
161
+ "backBoneElementProperty": "name"
162
+ }];
163
+ // execute
164
+ const actual = patchUtils.createAddParametersForBackboneElement("Patient", "contact", params);
165
+ // validate
166
+ expect(actual.getPatchParameters()).toEqual(expected);
167
+ });
168
+ it('createInsertParameters() should create Parameters for FHIR patch add operation', () => {
169
+ // setup
170
+ const identifier = {
171
+ "system": "http://some-system.com",
172
+ "value": "someValue"
173
+ };
174
+ const expected = {
175
+ "resourceType": "Parameters",
176
+ "parameter": [{
177
+ "name": "operation",
178
+ "part": [{
179
+ "name": "type",
180
+ "valueCode": "insert"
181
+ }, {
182
+ "name": "path",
183
+ "valueString": "Patient.identifier"
184
+ }, {
185
+ "name": "index",
186
+ "valueInteger": 1
187
+ }, {
188
+ "name": "value",
189
+ "valueIdentifier": identifier
190
+ }]
191
+ }]
192
+ };
193
+ // execute
194
+ const actual = patchUtils.createInsertParameters("Patient.identifier", identifier, constants_1.PATCH_DATATYPE.IDENTIFIER, 1);
195
+ // validate
196
+ expect(actual.getPatchParameters()).toEqual(expected);
197
+ });
198
+ it('resetPatchParameters() should reset Parameter property inside Parameters resource for PATCH operation', () => {
199
+ // setup
200
+ // validate delete params are present
201
+ expect(patchUtils.createDeleteParameters("Patient.status").getPatchParameters().parameter).toHaveSize(1);
202
+ // execute
203
+ const actual = patchUtils.resetPatchParameters().getPatchParameters();
204
+ // validate
205
+ expect(actual.parameter).toHaveSize(0);
206
+ });
207
+ });
@@ -1,4 +1,4 @@
1
- import { Coding, CodingKeys, Extension, Identifier, IdentifierKeys } from "../dataTypes";
1
+ import { CodingKeys, IdentifierKeys } from "../dataTypes";
2
2
  export declare class ResourceUtils {
3
3
  /**
4
4
  *
@@ -16,14 +16,14 @@ export declare class ResourceUtils {
16
16
  * @returns array of matches
17
17
  * @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
18
18
  */
19
- getIdentifiersByProperty(identifierList: Identifier[], propertyToCompare: IdentifierKeys, propertyValue: Identifier[IdentifierKeys]): Identifier[];
19
+ getIdentifiersByProperty(identifierList: any[], propertyToCompare: IdentifierKeys, propertyValue: any[IdentifierKeys]): any[];
20
20
  /**
21
21
  *
22
22
  * @param extensionList list of extensions
23
23
  * @param extensionUrl Extension.url to compare
24
24
  * @returns array of matches
25
25
  */
26
- getExtensionsByUrl(extensionList: Extension[], extensionUrl: string): Extension[];
26
+ getExtensionsByUrl(extensionList: any[], extensionUrl: string): any[];
27
27
  /**
28
28
  *
29
29
  * @param codingList list of codings
@@ -31,7 +31,7 @@ export declare class ResourceUtils {
31
31
  * @param propertyValue value we want to compare against string or boolean
32
32
  * @returns array of matches
33
33
  */
34
- getCodingsByProperty(codingList: Coding[], propertyToCompare: CodingKeys, propertyValue: Coding[CodingKeys]): Coding[];
34
+ getCodingsByProperty(codingList: any[], propertyToCompare: CodingKeys, propertyValue: any[CodingKeys]): any[];
35
35
  /**
36
36
  *
37
37
  * @param resource resource for which path needs to be validated
@@ -2,3 +2,23 @@ export declare enum SORT_ORDER {
2
2
  ASCENDING = 0,
3
3
  DESCENDING = 1
4
4
  }
5
+ export declare enum PATCH_DATATYPE {
6
+ CODE = "valueCode",
7
+ DATE = "valueDate",
8
+ DATE_TIME = "valueDateTime",
9
+ BOOLEAN = "valueBoolean",
10
+ CODEABLE_CONCEPT = "valueCodeableConcept",
11
+ CODING = "valueCoding",
12
+ IDENTIFIER = "valueIdentifier",
13
+ HUMAN_NAME = "valueHumanName",
14
+ STRING = "valueString",
15
+ ADDRESS = "valueAddress",
16
+ REFERENCE = "valueReference"
17
+ }
18
+ export interface PatchAddValueParams {
19
+ value: any;
20
+ valueDataType: PATCH_DATATYPE;
21
+ }
22
+ export interface PatchAddBackboneElementParams extends PatchAddValueParams {
23
+ backBoneElementProperty: string;
24
+ }
@@ -1,8 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SORT_ORDER = void 0;
3
+ exports.PATCH_DATATYPE = exports.SORT_ORDER = void 0;
4
4
  var SORT_ORDER;
5
5
  (function (SORT_ORDER) {
6
6
  SORT_ORDER[SORT_ORDER["ASCENDING"] = 0] = "ASCENDING";
7
7
  SORT_ORDER[SORT_ORDER["DESCENDING"] = 1] = "DESCENDING";
8
8
  })(SORT_ORDER = exports.SORT_ORDER || (exports.SORT_ORDER = {}));
9
+ var PATCH_DATATYPE;
10
+ (function (PATCH_DATATYPE) {
11
+ PATCH_DATATYPE["CODE"] = "valueCode";
12
+ PATCH_DATATYPE["DATE"] = "valueDate";
13
+ PATCH_DATATYPE["DATE_TIME"] = "valueDateTime";
14
+ PATCH_DATATYPE["BOOLEAN"] = "valueBoolean";
15
+ PATCH_DATATYPE["CODEABLE_CONCEPT"] = "valueCodeableConcept";
16
+ PATCH_DATATYPE["CODING"] = "valueCoding";
17
+ PATCH_DATATYPE["IDENTIFIER"] = "valueIdentifier";
18
+ PATCH_DATATYPE["HUMAN_NAME"] = "valueHumanName";
19
+ PATCH_DATATYPE["STRING"] = "valueString";
20
+ PATCH_DATATYPE["ADDRESS"] = "valueAddress";
21
+ PATCH_DATATYPE["REFERENCE"] = "valueReference";
22
+ })(PATCH_DATATYPE = exports.PATCH_DATATYPE || (exports.PATCH_DATATYPE = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
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
@@ -6,4 +6,6 @@ import * as dstu2 from './FHIR-DSTU2';
6
6
  import { ResourceUtils } from './library/ResourceUtils/ResourceUtils';
7
7
  import { BundleUtils } from './library/BundleUtils/BundleUtils';
8
8
  import { QueryBuilder } from './library/QueryBuilder/QueryBuilder';
9
- export { fhirR5, fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils, QueryBuilder };
9
+ import { PatchUtils } from './library/PatchUtils/PatchUtils';
10
+ import * as fhirtsConstants from './library/constants';
11
+ export { fhirR5, fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils, QueryBuilder, PatchUtils, fhirtsConstants};
@@ -0,0 +1,215 @@
1
+ import { PATCH_DATATYPE, PatchAddValueParams, PatchAddBackboneElementParams } from "../constants";
2
+ import { PatchUtils } from "./PatchUtils";
3
+ describe("PatchUtils", () => {
4
+
5
+ let patchUtils: PatchUtils;
6
+
7
+ beforeEach(() => {
8
+ patchUtils = new PatchUtils();
9
+ });
10
+
11
+ it('createReplaceParameters() should create Parameters for FHIR patch replace operation', () => {
12
+ // setup
13
+ const expected = {
14
+ "resourceType": "Parameters",
15
+ "parameter": [ {
16
+ "name": "operation",
17
+ "part": [ {
18
+ "name": "type",
19
+ "valueCode": "replace"
20
+ }, {
21
+ "name": "path",
22
+ "valueString": "Patient.birthDate"
23
+ }, {
24
+ "name": "value",
25
+ "valueDate": "1930-01-01"
26
+ } ]
27
+ } ]
28
+ };
29
+ // execute
30
+ const actual = patchUtils.createReplaceParameters("Patient.birthDate", "1930-01-01", PATCH_DATATYPE.DATE);
31
+ // validate
32
+ expect(actual.getPatchParameters()).toEqual(expected);
33
+ });
34
+
35
+ it('createDeleteParameters() should create Parameters for FHIR patch delete operation', () => {
36
+ // setup
37
+ const expected = {
38
+ "resourceType": "Parameters",
39
+ "parameter": [ {
40
+ "name": "operation",
41
+ "part": [ {
42
+ "name": "type",
43
+ "valueCode": "delete"
44
+ }, {
45
+ "name": "path",
46
+ "valueString": "Patient.status"
47
+ }]
48
+ } ]
49
+ };
50
+ // execute
51
+ const actual = patchUtils.createDeleteParameters("Patient.status");
52
+ // validate
53
+ expect(actual.getPatchParameters()).toEqual(expected);
54
+ });
55
+
56
+ it('createMoveParameters() should create Parameters for FHIR patch move operation', () => {
57
+ // setup
58
+ const expected = {
59
+ "resourceType": "Parameters",
60
+ "parameter": [ {
61
+ "name": "operation",
62
+ "part": [ {
63
+ "name": "type",
64
+ "valueCode": "move"
65
+ }, {
66
+ "name": "path",
67
+ "valueString": "Patient.identifier"
68
+ }, {
69
+ "name": "source",
70
+ "valueInteger": 0
71
+ }, {
72
+ "name": "destination",
73
+ "valueInteger": 1
74
+ }]
75
+ } ]
76
+ };
77
+ // execute
78
+ const actual = patchUtils.createMoveParameters("Patient.identifier", 0, 1);
79
+ // validate
80
+ expect(actual.getPatchParameters()).toEqual(expected);
81
+ });
82
+
83
+ it('createAddParameters() should create Parameters for FHIR patch add operation', () => {
84
+ // setup
85
+ const expected = {
86
+ "resourceType": "Parameters",
87
+ "parameter": [ {
88
+ "name": "operation",
89
+ "part": [ {
90
+ "name": "type",
91
+ "valueCode": "add"
92
+ }, {
93
+ "name": "path",
94
+ "valueString": "Patient"
95
+ }, {
96
+ "name": "name",
97
+ "valueString": "birthDate"
98
+ }, {
99
+ "name": "value",
100
+ "valueDate": "1930-01-01"
101
+ }]
102
+ } ]
103
+ };
104
+ const params: PatchAddValueParams = {
105
+ "value": "1930-01-01",
106
+ "valueDataType": PATCH_DATATYPE.DATE
107
+ };
108
+ // execute
109
+ const actual = patchUtils.createAddParameters("Patient", "birthDate", params);
110
+ // validate
111
+ expect(actual.getPatchParameters()).toEqual(expected);
112
+ });
113
+
114
+ it('createAddParametersForBackboneElement() should create Parameters for FHIR patch add operation', () => {
115
+ // setup
116
+ const expected = {
117
+ "resourceType": "Parameters",
118
+ "parameter": [
119
+ {
120
+ "name": "operation",
121
+ "part": [
122
+ {
123
+ "name": "type",
124
+ "valueCode": "add"
125
+ },
126
+ {
127
+ "name": "path",
128
+ "valueString": "Patient"
129
+ },
130
+ {
131
+ "name": "name",
132
+ "valueString": "contact"
133
+ },
134
+ {
135
+ "name": "value",
136
+ "part": [
137
+ {
138
+ "name": "address",
139
+ "valueAddress": {
140
+ "use": "work"
141
+ }
142
+ },
143
+ {
144
+ "name": "name",
145
+ "valueHumanName": {
146
+ "use": "official"
147
+ }
148
+ }
149
+ ]
150
+ }
151
+ ]
152
+ },
153
+ ]
154
+ };
155
+ const params: PatchAddBackboneElementParams[] = [{
156
+ "value": {
157
+ "use": "work"
158
+ },
159
+ "valueDataType": PATCH_DATATYPE.ADDRESS,
160
+ "backBoneElementProperty": "address"
161
+ }, {
162
+ "value": {
163
+ "use": "official"
164
+ },
165
+ "valueDataType": PATCH_DATATYPE.HUMAN_NAME,
166
+ "backBoneElementProperty": "name"
167
+ }]
168
+ // execute
169
+ const actual = patchUtils.createAddParametersForBackboneElement("Patient", "contact", params);
170
+ // validate
171
+ expect(actual.getPatchParameters()).toEqual(expected);
172
+ });
173
+
174
+ it('createInsertParameters() should create Parameters for FHIR patch add operation', () => {
175
+ // setup
176
+ const identifier = {
177
+ "system": "http://some-system.com",
178
+ "value": "someValue"
179
+ }
180
+ const expected = {
181
+ "resourceType": "Parameters",
182
+ "parameter": [ {
183
+ "name": "operation",
184
+ "part": [ {
185
+ "name": "type",
186
+ "valueCode": "insert"
187
+ }, {
188
+ "name": "path",
189
+ "valueString": "Patient.identifier"
190
+ }, {
191
+ "name": "index",
192
+ "valueInteger": 1
193
+ }, {
194
+ "name": "value",
195
+ "valueIdentifier": identifier
196
+ }]
197
+ } ]
198
+ };
199
+ // execute
200
+ const actual = patchUtils.createInsertParameters("Patient.identifier", identifier, PATCH_DATATYPE.IDENTIFIER, 1);
201
+ // validate
202
+ expect(actual.getPatchParameters()).toEqual(expected);
203
+ });
204
+
205
+ it('resetPatchParameters() should reset Parameter property inside Parameters resource for PATCH operation', () => {
206
+ // setup
207
+ // validate delete params are present
208
+ expect(patchUtils.createDeleteParameters("Patient.status").getPatchParameters().parameter).toHaveSize(1);
209
+ // execute
210
+ const actual = patchUtils.resetPatchParameters().getPatchParameters();
211
+ // validate
212
+ expect(actual.parameter).toHaveSize(0);
213
+ });
214
+
215
+ });
@@ -0,0 +1,236 @@
1
+ import { PATCH_DATATYPE, PatchAddValueParams, PatchAddBackboneElementParams } from "../constants";
2
+
3
+ /**
4
+ * This a simple utility to create Parameters resource for FHIR patch operation
5
+ * https://www.hl7.org/fhir/fhirpatch.html
6
+ */
7
+ export class PatchUtils {
8
+ private REPLACE_OPERATION_NAME = "replace";
9
+ private DELETE_OPERATION_NAME = "delete";
10
+ private MOVE_OPERATION_NAME = "move";
11
+ private ADD_OPERATION_NAME = "add";
12
+ private INSERT_OPERATION_NAME = "insert";
13
+ private readonly PARAMETER_PROPERTY_NAME = "parameter";
14
+ private baseParameters = {
15
+ resourceType: "Parameters",
16
+ parameter: [],
17
+ };
18
+
19
+ /**
20
+ *
21
+ * @param path the path to replace value of
22
+ * @param value the value to replace with
23
+ * @param valueDataType the data type of value
24
+ * @returns Parameters resource for FHIR patch replace operation
25
+ */
26
+ createReplaceParameters(
27
+ path: string,
28
+ value: any,
29
+ valueDataType: PATCH_DATATYPE
30
+ ) {
31
+ const replaceParameters = {
32
+ name: "operation",
33
+ part: [
34
+ {
35
+ name: "type",
36
+ valueCode: this.REPLACE_OPERATION_NAME,
37
+ },
38
+ {
39
+ name: "path",
40
+ valueString: path,
41
+ },
42
+ {
43
+ name: "value",
44
+ [valueDataType]: value,
45
+ },
46
+ ],
47
+ };
48
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(replaceParameters);
49
+ return this;
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param path the path to delete value of
55
+ * @returns Parameters resource for FHIR patch delete operation
56
+ */
57
+ createDeleteParameters(path: string) {
58
+ const deleteParameters = {
59
+ name: "operation",
60
+ part: [
61
+ {
62
+ name: "type",
63
+ valueCode: this.DELETE_OPERATION_NAME,
64
+ },
65
+ {
66
+ name: "path",
67
+ valueString: path,
68
+ },
69
+ ],
70
+ };
71
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(deleteParameters);
72
+ return this;
73
+ }
74
+
75
+ /**
76
+ *
77
+ * @param path the path to property where the index of items needs to be changed
78
+ * @param source the index to move
79
+ * @param destination the index where the value will be moved
80
+ * @returns Parameters resource for FHIR patch move operation
81
+ */
82
+ createMoveParameters(path: string, source: number, destination: number) {
83
+ const moveParameters = {
84
+ name: "operation",
85
+ part: [
86
+ {
87
+ name: "type",
88
+ valueCode: this.MOVE_OPERATION_NAME,
89
+ },
90
+ {
91
+ name: "path",
92
+ valueString: path,
93
+ },
94
+ {
95
+ name: "source",
96
+ valueInteger: source,
97
+ },
98
+ {
99
+ name: "destination",
100
+ valueInteger: destination,
101
+ },
102
+ ],
103
+ };
104
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(moveParameters);
105
+ return this;
106
+ }
107
+
108
+ /**
109
+ * @param path the path at which to add the content
110
+ * @param name name of the property to add
111
+ * @param patchAddValueParams the value to replace with & the data type of value
112
+ * @returns Parameters resource for FHIR patch add operation
113
+ */
114
+ createAddParameters(
115
+ path: string,
116
+ name: string,
117
+ patchAddValueParams: PatchAddValueParams
118
+ ) {
119
+ const addParameters = {
120
+ name: "operation",
121
+ part: [
122
+ ...this.getCommonAddParameters(path, name),
123
+ {
124
+ name: "value",
125
+ [patchAddValueParams.valueDataType]: patchAddValueParams.value,
126
+ },
127
+ ],
128
+ };
129
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(addParameters);
130
+ return this;
131
+ }
132
+
133
+ /**
134
+ *
135
+ * @param path the path at which to add the content
136
+ * @param name name of the property to add
137
+ * @param patchAddValueParams the value to replace with, the data type of value & the backbone element property
138
+ * @returns
139
+ */
140
+ createAddParametersForBackboneElement(
141
+ path: string,
142
+ name: string,
143
+ patchAddValueParams: PatchAddBackboneElementParams[]
144
+ ) {
145
+ const parts = [];
146
+ patchAddValueParams.forEach((x) => {
147
+ parts.push({
148
+ name: x.backBoneElementProperty,
149
+ [x.valueDataType]: x.value,
150
+ });
151
+ });
152
+ const addParameters = {
153
+ name: "operation",
154
+ part: [
155
+ ...this.getCommonAddParameters(path, name),
156
+ {
157
+ name: "value",
158
+ part: parts,
159
+ },
160
+ ],
161
+ };
162
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(addParameters);
163
+ return this;
164
+ }
165
+
166
+ /**
167
+ *
168
+ * @param path the path at which to insert the value
169
+ * @param value the value to insert
170
+ * @param valueDataType the datatype of the value
171
+ * @param index the index at which the value should be inserted
172
+ * @returns Parameters resource for FHIR patch insert operation
173
+ */
174
+ createInsertParameters(
175
+ path: string,
176
+ value: any,
177
+ valueDataType: PATCH_DATATYPE,
178
+ index: number
179
+ ) {
180
+ const insertParameters = {
181
+ name: "operation",
182
+ part: [
183
+ {
184
+ name: "type",
185
+ valueCode: this.INSERT_OPERATION_NAME,
186
+ },
187
+ {
188
+ name: "path",
189
+ valueString: path,
190
+ },
191
+ {
192
+ name: "index",
193
+ valueInteger: index,
194
+ },
195
+ {
196
+ name: "value",
197
+ [valueDataType]: value,
198
+ },
199
+ ],
200
+ };
201
+ this.baseParameters[this.PARAMETER_PROPERTY_NAME].push(insertParameters);
202
+ return this;
203
+ }
204
+
205
+ /**
206
+ * @returns the parameters resource created for FHIR PATCH operation
207
+ */
208
+ getPatchParameters() {
209
+ return this.baseParameters;
210
+ }
211
+
212
+ /**
213
+ * Resets the parameter property in PATCH parameters resource
214
+ */
215
+ resetPatchParameters() {
216
+ this.baseParameters.parameter = [];
217
+ return this;
218
+ }
219
+
220
+ private getCommonAddParameters(path: string, name: string) {
221
+ return [
222
+ {
223
+ name: "type",
224
+ valueCode: this.ADD_OPERATION_NAME,
225
+ },
226
+ {
227
+ name: "path",
228
+ valueString: path,
229
+ },
230
+ {
231
+ name: "name",
232
+ valueString: name,
233
+ },
234
+ ];
235
+ }
236
+ }
@@ -1,4 +1,4 @@
1
- import { Coding, CodingKeys, Extension, Identifier, IdentifierKeys } from "../dataTypes";
1
+ import { CodingKeys, IdentifierKeys } from "../dataTypes";
2
2
 
3
3
  export class ResourceUtils {
4
4
  /**
@@ -25,10 +25,10 @@ export class ResourceUtils {
25
25
  * @limitations currently does not work with identifier.type, identifier.period & identifier.assigner
26
26
  */
27
27
  getIdentifiersByProperty(
28
- identifierList: Identifier[],
28
+ identifierList: any[],
29
29
  propertyToCompare: IdentifierKeys,
30
- propertyValue: Identifier[IdentifierKeys]
31
- ): Identifier[] {
30
+ propertyValue: any[IdentifierKeys]
31
+ ): any[] {
32
32
  return identifierList?.length
33
33
  ? identifierList.filter((x) => x[propertyToCompare] === propertyValue)
34
34
  : [];
@@ -40,7 +40,7 @@ export class ResourceUtils {
40
40
  * @param extensionUrl Extension.url to compare
41
41
  * @returns array of matches
42
42
  */
43
- getExtensionsByUrl(extensionList: Extension[], extensionUrl: string): Extension[] {
43
+ getExtensionsByUrl(extensionList: any[], extensionUrl: string): any[] {
44
44
  return extensionList?.length
45
45
  ? extensionList.filter((x) => x["url"] === extensionUrl)
46
46
  : [];
@@ -54,10 +54,10 @@ export class ResourceUtils {
54
54
  * @returns array of matches
55
55
  */
56
56
  getCodingsByProperty(
57
- codingList: Coding[],
57
+ codingList: any[],
58
58
  propertyToCompare: CodingKeys,
59
- propertyValue: Coding[CodingKeys]
60
- ): Coding[] {
59
+ propertyValue: any[CodingKeys]
60
+ ): any[] {
61
61
  return codingList?.length
62
62
  ? codingList.filter((x) => x[propertyToCompare] === propertyValue)
63
63
  : [];
@@ -1,4 +1,27 @@
1
1
  export enum SORT_ORDER {
2
2
  ASCENDING,
3
3
  DESCENDING
4
+ }
5
+
6
+ export enum PATCH_DATATYPE {
7
+ CODE = "valueCode",
8
+ DATE = "valueDate",
9
+ DATE_TIME = "valueDateTime",
10
+ BOOLEAN = "valueBoolean",
11
+ CODEABLE_CONCEPT = "valueCodeableConcept",
12
+ CODING = "valueCoding",
13
+ IDENTIFIER = "valueIdentifier",
14
+ HUMAN_NAME = "valueHumanName",
15
+ STRING = "valueString",
16
+ ADDRESS = "valueAddress",
17
+ REFERENCE = "valueReference"
18
+ }
19
+
20
+ export interface PatchAddValueParams {
21
+ value: any;
22
+ valueDataType: PATCH_DATATYPE;
23
+ }
24
+
25
+ export interface PatchAddBackboneElementParams extends PatchAddValueParams {
26
+ backBoneElementProperty: string;
4
27
  }