@smile-cdr/fhirts 2.2.1 → 2.2.2
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 +4 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/library/PatchUtils/PatchUtils.d.ts +72 -0
- package/dist/library/PatchUtils/PatchUtils.js +214 -0
- package/dist/library/PatchUtils/PatchUtils.spec.d.ts +1 -0
- package/dist/library/PatchUtils/PatchUtils.spec.js +207 -0
- package/dist/library/constants.d.ts +20 -0
- package/dist/library/constants.js +15 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/library/PatchUtils/PatchUtils.spec.ts +215 -0
- package/src/library/PatchUtils/PatchUtils.ts +236 -0
- package/src/library/constants.ts +23 -0
package/CHANGELOG.md
CHANGED
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
|
-
|
|
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
|
+
});
|
|
@@ -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
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
|
-
|
|
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
|
+
}
|
package/src/library/constants.ts
CHANGED
|
@@ -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
|
}
|