@smile-cdr/fhirts 2.1.1 → 2.2.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 +1 -1
- package/CHANGELOG.md +9 -0
- package/dist/FHIR-DSTU2.d.ts +22 -22
- package/dist/FHIR-R3.d.ts +21 -22
- package/dist/FHIR-R4/classes/extension.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/library/QueryBuilder/QueryBuilder.d.ts +59 -0
- package/dist/library/QueryBuilder/QueryBuilder.js +112 -0
- package/dist/library/QueryBuilder/QueryBuilder.spec.d.ts +1 -0
- package/dist/library/QueryBuilder/QueryBuilder.spec.js +135 -0
- package/dist/library/ResourceUtils/ResourceUtils.d.ts +4 -3
- package/dist/library/ResourceUtils/ResourceUtils.spec.js +10 -7
- package/dist/library/constants.d.ts +4 -0
- package/dist/library/constants.js +8 -0
- package/dist/library/dataTypes.d.ts +10 -0
- package/dist/library/dataTypes.js +2 -0
- package/package.json +4 -6
- package/src/FHIR-DSTU2.ts +23 -23
- package/src/FHIR-R3.ts +58 -59
- package/src/FHIR-R4/classes/extension.ts +2 -2
- package/src/index.ts +2 -1
- package/src/library/QueryBuilder/QueryBuilder.spec.ts +149 -0
- package/src/library/QueryBuilder/QueryBuilder.ts +119 -0
- package/src/library/ResourceUtils/ResourceUtils.spec.ts +13 -11
- package/src/library/ResourceUtils/ResourceUtils.ts +25 -23
- package/src/library/constants.ts +4 -0
- package/src/library/dataTypes.ts +10 -0
package/src/FHIR-DSTU2.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* This is base class from which other elements are derived */
|
|
2
2
|
export class FHIRElement {
|
|
3
|
-
id
|
|
4
|
-
extension
|
|
3
|
+
id?: string;
|
|
4
|
+
extension?: Extension[];
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export class BackboneElement extends FHIRElement {
|
|
@@ -22,7 +22,7 @@ export class Id {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export class DomainResource
|
|
25
|
+
export class DomainResource {
|
|
26
26
|
text: Narrative;
|
|
27
27
|
contained: Resource[];
|
|
28
28
|
extension: Extension[];
|
|
@@ -56,12 +56,12 @@ export class CodeableConcept extends FHIRElement {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export class Identifier extends FHIRElement {
|
|
59
|
-
use
|
|
60
|
-
type
|
|
61
|
-
system
|
|
62
|
-
value
|
|
63
|
-
period
|
|
64
|
-
assigner
|
|
59
|
+
use?: string;
|
|
60
|
+
type?: CodeableConcept;
|
|
61
|
+
system?: string;
|
|
62
|
+
value?: string;
|
|
63
|
+
period?: Period;
|
|
64
|
+
assigner?: Reference;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export class Reference extends FHIRElement {
|
|
@@ -83,25 +83,25 @@ export class HumanName extends FHIRElement {
|
|
|
83
83
|
|
|
84
84
|
export class Extension {
|
|
85
85
|
url: string;
|
|
86
|
-
valueString
|
|
87
|
-
valueCode
|
|
88
|
-
valueAddress
|
|
86
|
+
valueString?: string;
|
|
87
|
+
valueCode?: string;
|
|
88
|
+
valueAddress?: Address;
|
|
89
89
|
valueBoolean?: boolean;
|
|
90
|
-
valueHumanName
|
|
91
|
-
valueReference
|
|
92
|
-
valueDate
|
|
93
|
-
valueIdentifier
|
|
90
|
+
valueHumanName?: HumanName;
|
|
91
|
+
valueReference?: Reference;
|
|
92
|
+
valueDate?: Date;
|
|
93
|
+
valueIdentifier?: string;
|
|
94
94
|
valueDecimal?: number;
|
|
95
|
-
valueInteger
|
|
96
|
-
valuePeriod
|
|
95
|
+
valueInteger?: number;
|
|
96
|
+
valuePeriod?: Period;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
export class Coding extends FHIRElement {
|
|
100
|
-
system
|
|
101
|
-
version
|
|
102
|
-
code
|
|
103
|
-
display
|
|
104
|
-
userSelected
|
|
100
|
+
system?: string;
|
|
101
|
+
version?: string;
|
|
102
|
+
code?: string;
|
|
103
|
+
display?: string;
|
|
104
|
+
userSelected?: boolean;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export class Period extends FHIRElement {
|
package/src/FHIR-R3.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* This is base class from which other elements are derived */
|
|
2
2
|
export class FHIRElement {
|
|
3
|
-
id
|
|
4
|
-
extension
|
|
3
|
+
id?: string;
|
|
4
|
+
extension?: Extension[];
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export class BackboneElement extends FHIRElement {
|
|
@@ -9,7 +9,7 @@ export class BackboneElement extends FHIRElement {
|
|
|
9
9
|
}
|
|
10
10
|
/* FHIR classes used in resources */
|
|
11
11
|
|
|
12
|
-
export class DomainResource
|
|
12
|
+
export class DomainResource {
|
|
13
13
|
text: Narrative;
|
|
14
14
|
contained: Resource[];
|
|
15
15
|
extension: Extension[];
|
|
@@ -60,13 +60,12 @@ export class Code extends FHIRElement {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export class Coding extends FHIRElement {
|
|
63
|
-
system
|
|
64
|
-
version
|
|
63
|
+
system?: string;
|
|
64
|
+
version?: string;
|
|
65
65
|
// should be of type Code
|
|
66
|
-
code
|
|
67
|
-
display
|
|
68
|
-
userSelected
|
|
69
|
-
value: string;
|
|
66
|
+
code?: string;
|
|
67
|
+
display?: string;
|
|
68
|
+
userSelected?: boolean;
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
export class DoseCoding extends FHIRElement {
|
|
@@ -87,16 +86,16 @@ export class HumanName extends FHIRElement {
|
|
|
87
86
|
|
|
88
87
|
export class Extension {
|
|
89
88
|
url: string;
|
|
90
|
-
valueString
|
|
91
|
-
valueCode
|
|
92
|
-
valueAddress
|
|
89
|
+
valueString?: string;
|
|
90
|
+
valueCode?: string;
|
|
91
|
+
valueAddress?: Address;
|
|
93
92
|
valueBoolean?: boolean;
|
|
94
|
-
valueHumanName
|
|
95
|
-
valueReference
|
|
96
|
-
valueDate
|
|
97
|
-
valueIdentifier
|
|
93
|
+
valueHumanName?: HumanName;
|
|
94
|
+
valueReference?: Reference;
|
|
95
|
+
valueDate?: Date;
|
|
96
|
+
valueIdentifier?: string;
|
|
98
97
|
valueDecimal?: number;
|
|
99
|
-
valueInteger
|
|
98
|
+
valueInteger?: number;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
export class Address extends FHIRElement {
|
|
@@ -256,12 +255,12 @@ export class Reference extends FHIRElement {
|
|
|
256
255
|
}
|
|
257
256
|
|
|
258
257
|
export class Identifier extends FHIRElement {
|
|
259
|
-
use
|
|
260
|
-
type
|
|
261
|
-
system
|
|
262
|
-
value
|
|
263
|
-
period
|
|
264
|
-
assigner
|
|
258
|
+
use?: string;
|
|
259
|
+
type?: CodeableConcept;
|
|
260
|
+
system?: string;
|
|
261
|
+
value?: string;
|
|
262
|
+
period?: Period;
|
|
263
|
+
assigner?: Reference;
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
export class Payload extends BackboneElement {
|
|
@@ -815,48 +814,48 @@ export class Encounter extends BaseResource {
|
|
|
815
814
|
identifier: Identifier[];
|
|
816
815
|
status: 'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
|
|
817
816
|
statusHistory: {
|
|
818
|
-
status:'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
|
|
817
|
+
status: 'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
|
|
819
818
|
period: Period;
|
|
820
819
|
}[];
|
|
821
|
-
class:Coding;
|
|
822
|
-
classHistory:{
|
|
823
|
-
class:Coding;
|
|
824
|
-
period:Period;
|
|
820
|
+
class: Coding;
|
|
821
|
+
classHistory: {
|
|
822
|
+
class: Coding;
|
|
823
|
+
period: Period;
|
|
825
824
|
}[];
|
|
826
|
-
type:CodeableConcept[];
|
|
827
|
-
priority:CodeableConcept;
|
|
825
|
+
type: CodeableConcept[];
|
|
826
|
+
priority: CodeableConcept;
|
|
828
827
|
episodeOfCare: Reference[];
|
|
829
828
|
subject: Reference;
|
|
830
|
-
incomingReferral:Reference[];
|
|
829
|
+
incomingReferral: Reference[];
|
|
831
830
|
participant: EncounterParticipant[];
|
|
832
|
-
appointment:Reference;
|
|
833
|
-
period:Period;
|
|
834
|
-
length:Quantity;
|
|
835
|
-
reason:CodeableConcept[];
|
|
836
|
-
diagnosis:{
|
|
837
|
-
condition:Reference;
|
|
838
|
-
role:CodeableConcept;
|
|
839
|
-
rank:number
|
|
831
|
+
appointment: Reference;
|
|
832
|
+
period: Period;
|
|
833
|
+
length: Quantity;
|
|
834
|
+
reason: CodeableConcept[];
|
|
835
|
+
diagnosis: {
|
|
836
|
+
condition: Reference;
|
|
837
|
+
role: CodeableConcept;
|
|
838
|
+
rank: number
|
|
840
839
|
}[];
|
|
841
|
-
account:Reference[];
|
|
842
|
-
hospitalization:{
|
|
843
|
-
preAdmissionIdentifer:Identifier;
|
|
844
|
-
origin:Reference;
|
|
845
|
-
admitSource:CodeableConcept;
|
|
846
|
-
reAdmission:CodeableConcept;
|
|
847
|
-
dietPreference:CodeableConcept[];
|
|
848
|
-
specialCourtesy:CodeableConcept[];
|
|
849
|
-
specialArrangement:CodeableConcept[];
|
|
850
|
-
destination:Reference;
|
|
851
|
-
dischargeDiposition:CodeableConcept;
|
|
840
|
+
account: Reference[];
|
|
841
|
+
hospitalization: {
|
|
842
|
+
preAdmissionIdentifer: Identifier;
|
|
843
|
+
origin: Reference;
|
|
844
|
+
admitSource: CodeableConcept;
|
|
845
|
+
reAdmission: CodeableConcept;
|
|
846
|
+
dietPreference: CodeableConcept[];
|
|
847
|
+
specialCourtesy: CodeableConcept[];
|
|
848
|
+
specialArrangement: CodeableConcept[];
|
|
849
|
+
destination: Reference;
|
|
850
|
+
dischargeDiposition: CodeableConcept;
|
|
852
851
|
};
|
|
853
|
-
location:{
|
|
854
|
-
location:Reference;
|
|
852
|
+
location: {
|
|
853
|
+
location: Reference;
|
|
855
854
|
status: 'planned' | 'active' | 'reserved' | 'completed';
|
|
856
855
|
period: Period
|
|
857
856
|
}[];
|
|
858
|
-
serviceProvider:Reference;
|
|
859
|
-
partOf:Reference;
|
|
857
|
+
serviceProvider: Reference;
|
|
858
|
+
partOf: Reference;
|
|
860
859
|
}
|
|
861
860
|
|
|
862
861
|
export class CareTeamParticipant extends BackboneElement {
|
|
@@ -1283,11 +1282,11 @@ export class AllergyIntoleranceReaction extends BackboneElement {
|
|
|
1283
1282
|
}
|
|
1284
1283
|
|
|
1285
1284
|
export class Age extends FHIRElement {
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1285
|
+
value: number;
|
|
1286
|
+
comparator: '<' | '<=' | '>=' | '>';
|
|
1287
|
+
unit: string;
|
|
1288
|
+
system: string;
|
|
1289
|
+
code: Code;
|
|
1291
1290
|
}
|
|
1292
1291
|
|
|
1293
1292
|
export class ValueSet extends BaseResource {
|
|
@@ -45,7 +45,7 @@ import { UsageContext } from './usageContext';
|
|
|
45
45
|
/**
|
|
46
46
|
* Optional Extension Element - found in all resources.
|
|
47
47
|
*/
|
|
48
|
-
export class Extension {
|
|
48
|
+
export class Extension {
|
|
49
49
|
/**
|
|
50
50
|
* Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.
|
|
51
51
|
*/
|
|
@@ -57,7 +57,7 @@ export class Extension {
|
|
|
57
57
|
/**
|
|
58
58
|
* Source of the definition for the extension code - a logical name or a URL.
|
|
59
59
|
*/
|
|
60
|
-
url
|
|
60
|
+
url: Uri;
|
|
61
61
|
/**
|
|
62
62
|
* Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).
|
|
63
63
|
*/
|
package/src/index.ts
CHANGED
|
@@ -4,5 +4,6 @@ import * as fhirR3 from './FHIR-R3';
|
|
|
4
4
|
import * as dstu2 from './FHIR-DSTU2';
|
|
5
5
|
import { ResourceUtils } from './library/ResourceUtils/ResourceUtils';
|
|
6
6
|
import { BundleUtils } from './library/BundleUtils/BundleUtils';
|
|
7
|
-
|
|
7
|
+
import { QueryBuilder } from './library/QueryBuilder/QueryBuilder';
|
|
8
|
+
export { fhirR4, fhirR3, IfhirR4, dstu2, ResourceUtils, BundleUtils, QueryBuilder };
|
|
8
9
|
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { SORT_ORDER } from "../constants";
|
|
2
|
+
import { QueryBuilder } from "./QueryBuilder";
|
|
3
|
+
|
|
4
|
+
describe("QueryBuilder", () => {
|
|
5
|
+
|
|
6
|
+
let queryBuilder: QueryBuilder;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
queryBuilder = new QueryBuilder();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('setBaseResource() should set base resource and getBaseResource() should return correct base resource', () => {
|
|
13
|
+
// setup
|
|
14
|
+
const expected: String = "Patient";
|
|
15
|
+
// execute
|
|
16
|
+
queryBuilder.setBaseResource(expected);
|
|
17
|
+
// validate
|
|
18
|
+
expect(queryBuilder.getBaseResource()).toEqual(expected);
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('include() should make query for _include', () => {
|
|
22
|
+
// setup
|
|
23
|
+
const expected: String = "Patient?_include=Patient%3Aorganization"
|
|
24
|
+
// execute
|
|
25
|
+
queryBuilder.setBaseResource("Patient").include("organization");
|
|
26
|
+
// validate
|
|
27
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('include() should make query for multiple _include', () => {
|
|
31
|
+
// setup
|
|
32
|
+
const expected: String = "Patient?_include=Patient%3Aorganization&_include=Patient%3Alink"
|
|
33
|
+
// execute
|
|
34
|
+
queryBuilder.setBaseResource("Patient")
|
|
35
|
+
.include("organization")
|
|
36
|
+
.include("link");
|
|
37
|
+
// validate
|
|
38
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('revinclude() should make query for _revinclude', () => {
|
|
42
|
+
// setup
|
|
43
|
+
const expected: String = "MedicationRequest?_revinclude=CarePlan%3Aactivity-reference"
|
|
44
|
+
// execute
|
|
45
|
+
queryBuilder.setBaseResource("MedicationRequest")
|
|
46
|
+
.revinclude("CarePlan", "activity-reference");
|
|
47
|
+
// validate
|
|
48
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('revinclude() should make query for multiple _revinclude', () => {
|
|
52
|
+
// setup
|
|
53
|
+
const expected: String = "MedicationRequest?_revinclude=CarePlan%3Aactivity-reference&_revinclude=Observation%3Abased-on"
|
|
54
|
+
// execute
|
|
55
|
+
queryBuilder.setBaseResource("MedicationRequest")
|
|
56
|
+
.revinclude("CarePlan", "activity-reference")
|
|
57
|
+
.revinclude("Observation", "based-on");
|
|
58
|
+
// validate
|
|
59
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('include() and revinclude() should make query for _include & _revinclude', () => {
|
|
63
|
+
// setup
|
|
64
|
+
const expected: String = "MedicationRequest?_revinclude=CarePlan%3Aactivity-reference&_include=MedicationRequest%3Aencounter"
|
|
65
|
+
// execute
|
|
66
|
+
queryBuilder.setBaseResource("MedicationRequest")
|
|
67
|
+
.revinclude("CarePlan", "activity-reference")
|
|
68
|
+
.include("encounter");
|
|
69
|
+
// validate
|
|
70
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('includeAll() should make query for _include all', () => {
|
|
74
|
+
// setup
|
|
75
|
+
const expected: String = "MedicationRequest?_include=*"
|
|
76
|
+
// execute
|
|
77
|
+
queryBuilder.setBaseResource("MedicationRequest").includeAll();
|
|
78
|
+
// validate
|
|
79
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('revincludeAll() should make query for _revinclude all', () => {
|
|
83
|
+
// setup
|
|
84
|
+
const expected: String = "MedicationRequest?_revinclude=*"
|
|
85
|
+
// execute
|
|
86
|
+
queryBuilder.setBaseResource("MedicationRequest").revincludeAll();
|
|
87
|
+
// validate
|
|
88
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('includeAll() & revincludeAll() should make query for _include all & _revinclude all', () => {
|
|
92
|
+
// setup
|
|
93
|
+
const expected: String = "MedicationRequest?_revinclude=*&_include=*"
|
|
94
|
+
// execute
|
|
95
|
+
queryBuilder.setBaseResource("MedicationRequest")
|
|
96
|
+
.revincludeAll()
|
|
97
|
+
.includeAll();
|
|
98
|
+
// validate
|
|
99
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('sort() should make query for _sort', () => {
|
|
103
|
+
// setup
|
|
104
|
+
const expected: String = "Observation?_sort=status%2C-date"
|
|
105
|
+
// execute
|
|
106
|
+
queryBuilder.setBaseResource("Observation")
|
|
107
|
+
.sort("status", SORT_ORDER.ASCENDING)
|
|
108
|
+
.sort("date", SORT_ORDER.DESCENDING);
|
|
109
|
+
// validate
|
|
110
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('sort(), include() and revincludeAll() should make query for _sort, _include & _revinclude', () => {
|
|
114
|
+
// setup
|
|
115
|
+
const expected: String = "Observation?_revinclude=*&_include=Observation%3Abased-on&_sort=status"
|
|
116
|
+
// execute
|
|
117
|
+
queryBuilder.setBaseResource("Observation")
|
|
118
|
+
.revincludeAll()
|
|
119
|
+
.include("based-on")
|
|
120
|
+
.sort("status", SORT_ORDER.ASCENDING);
|
|
121
|
+
// validate
|
|
122
|
+
expect(queryBuilder.getCompleteUrl()).toEqual(expected);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('resetQuery() should reset query', () => {
|
|
126
|
+
// setup
|
|
127
|
+
const expected: String = ""
|
|
128
|
+
queryBuilder.setBaseResource("Observation")
|
|
129
|
+
.revincludeAll()
|
|
130
|
+
.include("based-on")
|
|
131
|
+
.sort("status", SORT_ORDER.ASCENDING);
|
|
132
|
+
// execute
|
|
133
|
+
queryBuilder.resetQuery();
|
|
134
|
+
// validate
|
|
135
|
+
expect(queryBuilder.getBaseResource()).toEqual(expected);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('getCompleteUrlDecoded() should get uri decoded query', () => {
|
|
139
|
+
// setup
|
|
140
|
+
const expected: String = "Observation?_revinclude=*&_include=Observation:based-on&_sort=status"
|
|
141
|
+
// execute
|
|
142
|
+
queryBuilder.setBaseResource("Observation")
|
|
143
|
+
.revincludeAll()
|
|
144
|
+
.include("based-on")
|
|
145
|
+
.sort("status", SORT_ORDER.ASCENDING);
|
|
146
|
+
// validate
|
|
147
|
+
expect(queryBuilder.getCompleteUrlDecoded()).toEqual(expected);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { SORT_ORDER } from "../constants";
|
|
2
|
+
|
|
3
|
+
export class QueryBuilder {
|
|
4
|
+
|
|
5
|
+
readonly REV_INCLUDE_KEYWORD = "_revinclude";
|
|
6
|
+
readonly INCLUDE_KEYWORD = "_include";
|
|
7
|
+
readonly SORT_KEYWORD = "_sort";
|
|
8
|
+
readonly WILDCARD_ASTERIK = "*";
|
|
9
|
+
readonly EQUALS = "=";
|
|
10
|
+
readonly COLON = ":";
|
|
11
|
+
readonly QUERY_DELIMETER = "&";
|
|
12
|
+
readonly COMMA = ",";
|
|
13
|
+
private baseResource: String = "";
|
|
14
|
+
private singularQueries: String[] = [];
|
|
15
|
+
private sortQueries: String[] = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns base resource for the query
|
|
19
|
+
*/
|
|
20
|
+
getBaseResource(): String {
|
|
21
|
+
return this.baseResource;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param resourceType Base ResourceType for the query
|
|
26
|
+
* sets base resource type for the query
|
|
27
|
+
* i.e. which resource the query will performed for
|
|
28
|
+
*/
|
|
29
|
+
setBaseResource(resourceType: String) {
|
|
30
|
+
this.baseResource = resourceType;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param searchParameter SearchParameter reference to targeted resource
|
|
36
|
+
*/
|
|
37
|
+
include(searchParameter: String) {
|
|
38
|
+
this.singularQueries.push(this.INCLUDE_KEYWORD + this.EQUALS + encodeURIComponent(this.baseResource + this.COLON + searchParameter));
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param resourceType Source ResourceType
|
|
44
|
+
* @param searchParameter SearchParameter reference from target resource to baseResource
|
|
45
|
+
*/
|
|
46
|
+
revinclude(resourceType: String, searchParameter: String) {
|
|
47
|
+
this.singularQueries.push(this.REV_INCLUDE_KEYWORD + this.EQUALS + encodeURIComponent(resourceType + this.COLON + searchParameter));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* _include all references in query
|
|
53
|
+
*/
|
|
54
|
+
includeAll() {
|
|
55
|
+
this.singularQueries.push(this.INCLUDE_KEYWORD + this.EQUALS + this.WILDCARD_ASTERIK);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* _revinclude all references in query
|
|
61
|
+
*/
|
|
62
|
+
revincludeAll() {
|
|
63
|
+
this.singularQueries.push(this.REV_INCLUDE_KEYWORD + this.EQUALS + this.WILDCARD_ASTERIK);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param searchParameter search parameter for the element to sort on
|
|
69
|
+
* @param sortOrder ASCENDING or DESCENDING
|
|
70
|
+
*/
|
|
71
|
+
sort(searchParameter: String, sortOrder: SORT_ORDER) {
|
|
72
|
+
if(sortOrder === SORT_ORDER.ASCENDING) {
|
|
73
|
+
this.sortQueries.push(searchParameter);
|
|
74
|
+
} else {
|
|
75
|
+
this.sortQueries.push("-" + searchParameter);
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Resets queries to it empty state
|
|
82
|
+
*/
|
|
83
|
+
resetQuery() {
|
|
84
|
+
this.sortQueries = [];
|
|
85
|
+
this.singularQueries = [];
|
|
86
|
+
this.baseResource = "";
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @returns complete generated query with encoded parameter values
|
|
92
|
+
*/
|
|
93
|
+
getCompleteUrl(): String {
|
|
94
|
+
let completeUrl = this.baseResource + "?";
|
|
95
|
+
const singularQueriesLength = this.singularQueries.length;
|
|
96
|
+
if(singularQueriesLength > 0) {
|
|
97
|
+
completeUrl += this.singularQueries.join(this.QUERY_DELIMETER);
|
|
98
|
+
}
|
|
99
|
+
completeUrl += this.createSortQuery(singularQueriesLength);
|
|
100
|
+
return completeUrl;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @returns complete generated query with decoded parameter values
|
|
105
|
+
*/
|
|
106
|
+
getCompleteUrlDecoded(): String {
|
|
107
|
+
return decodeURIComponent(this.getCompleteUrl().toString());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private createSortQuery(singularQueriesLength: number): String {
|
|
111
|
+
let sortQuery = "";
|
|
112
|
+
const sortDelimeter = singularQueriesLength > 0 ? this.QUERY_DELIMETER : "";
|
|
113
|
+
if(this.sortQueries.length > 0) {
|
|
114
|
+
sortQuery += sortDelimeter + this.SORT_KEYWORD + this.EQUALS + encodeURIComponent(this.sortQueries.join(this.COMMA));
|
|
115
|
+
}
|
|
116
|
+
return sortQuery;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ResourceUtils } from "./ResourceUtils";
|
|
2
|
+
import { Coding, Extension, Identifier, } from "../dataTypes";
|
|
2
3
|
|
|
3
4
|
const patientPayload = require("./../../test-resources/Patient-R4.json");
|
|
4
5
|
const careTeamPayload = require("./../../test-resources/CareTeam-R4.json");
|
|
@@ -41,7 +42,7 @@ describe("ResourceUtils", () => {
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
describe("#getIdentifiersByProperty()", () => {
|
|
44
|
-
const identifierList = [
|
|
45
|
+
const identifierList: Identifier[] = [
|
|
45
46
|
{
|
|
46
47
|
use: "temp",
|
|
47
48
|
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
@@ -56,11 +57,11 @@ describe("ResourceUtils", () => {
|
|
|
56
57
|
|
|
57
58
|
it("should return empty array if null is passed as identifier list", () => {
|
|
58
59
|
// setup
|
|
59
|
-
const value = "
|
|
60
|
+
const value = "shouldBeIgnored";
|
|
60
61
|
// execute
|
|
61
62
|
const actual = resourceUtils.getIdentifiersByProperty(
|
|
62
63
|
null,
|
|
63
|
-
"
|
|
64
|
+
"id",
|
|
64
65
|
value
|
|
65
66
|
);
|
|
66
67
|
// validate
|
|
@@ -73,7 +74,7 @@ describe("ResourceUtils", () => {
|
|
|
73
74
|
// execute
|
|
74
75
|
const actual = resourceUtils.getIdentifiersByProperty(
|
|
75
76
|
identifierList,
|
|
76
|
-
"
|
|
77
|
+
"extension", // no extensions in test data
|
|
77
78
|
value
|
|
78
79
|
);
|
|
79
80
|
// validate
|
|
@@ -108,7 +109,7 @@ describe("ResourceUtils", () => {
|
|
|
108
109
|
});
|
|
109
110
|
|
|
110
111
|
describe("#getExtensionsByUrl()", () => {
|
|
111
|
-
const extensionList = [
|
|
112
|
+
const extensionList: Extension[] = [
|
|
112
113
|
{
|
|
113
114
|
url: "http://hl7.org/fhir/sid/us-ssn",
|
|
114
115
|
valueBoolean: true,
|
|
@@ -130,11 +131,12 @@ describe("ResourceUtils", () => {
|
|
|
130
131
|
// setup
|
|
131
132
|
const extensionListInvalid = [
|
|
132
133
|
{
|
|
134
|
+
// @ts-ignore
|
|
133
135
|
use: "temp",
|
|
134
136
|
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
135
137
|
value: "abc",
|
|
136
138
|
},
|
|
137
|
-
];
|
|
139
|
+
] as Extension[]; // disabling compiler warning for the test
|
|
138
140
|
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
|
|
139
141
|
// execute
|
|
140
142
|
const actual = resourceUtils.getExtensionsByUrl(
|
|
@@ -165,7 +167,7 @@ describe("ResourceUtils", () => {
|
|
|
165
167
|
});
|
|
166
168
|
|
|
167
169
|
describe("#getCodingsByProperty()", () => {
|
|
168
|
-
const codingList = [
|
|
170
|
+
const codingList: Coding[] = [
|
|
169
171
|
{
|
|
170
172
|
version: "1.0",
|
|
171
173
|
system: "http://hl7.org/fhir/sid/us-ssn",
|
|
@@ -183,9 +185,9 @@ describe("ResourceUtils", () => {
|
|
|
183
185
|
|
|
184
186
|
it("should return empty array if null is passed as coding list", () => {
|
|
185
187
|
// setup
|
|
186
|
-
const value = "
|
|
188
|
+
const value = "shouldBeIgnored";
|
|
187
189
|
// execute
|
|
188
|
-
const actual = resourceUtils.getCodingsByProperty(null, "
|
|
190
|
+
const actual = resourceUtils.getCodingsByProperty(null, "extension", value);
|
|
189
191
|
// validate
|
|
190
192
|
expect(actual.length).toEqual(0);
|
|
191
193
|
});
|
|
@@ -196,7 +198,7 @@ describe("ResourceUtils", () => {
|
|
|
196
198
|
// execute
|
|
197
199
|
const actual = resourceUtils.getCodingsByProperty(
|
|
198
200
|
codingList,
|
|
199
|
-
"
|
|
201
|
+
"id", // expect no ID in codingList
|
|
200
202
|
value
|
|
201
203
|
);
|
|
202
204
|
// validate
|
|
@@ -244,7 +246,7 @@ describe("ResourceUtils", () => {
|
|
|
244
246
|
});
|
|
245
247
|
|
|
246
248
|
describe("#getValuesAtResourcePath()", () => {
|
|
247
|
-
|
|
249
|
+
|
|
248
250
|
it("should return array with values if path exists for a top level element", () => {
|
|
249
251
|
// execute
|
|
250
252
|
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
|