-
Notifications
You must be signed in to change notification settings - Fork 18
/
service.bal
286 lines (246 loc) · 16.8 KB
/
service.bal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). All Rights Reserved.
// This software is the property of WSO2 LLC. and its suppliers, if any.
// Dissemination of any information or reproduction of any material contained
// herein is strictly forbidden, unless permitted by WSO2 in accordance with
// the WSO2 Software License available at: https://wso2.com/licenses/eula/3.2
// For specific language governing the permissions and limitations under
// this license, please see the license as well as any agreement you’ve
// entered into with WSO2 governing the purchase of this software and any
// associated services.
//
// This file is auto-generated by WSO2 Healthcare Team for managing utility functions.
// Developers are allowed modify this file as per the requirement.
import ballerina/http;
import ballerinax/health.fhir.r4;
import ballerinax/health.fhirr4;
import ballerinax/health.fhir.r4.uscore501 as uscore;
import ballerina/os;
import ballerinax/health.fhir.r4.international401 as international;
import ballerinax/health.clients.fhir;
configurable string base = os:getEnv("EPIC_FHIR_SERVER_URL");
configurable string tokenUrl = os:getEnv("EPIC_FHIR_SERVER_TOKEN_URL");
configurable string clientId = os:getEnv("EPIC_FHIR_APP_CLIENT_ID");
configurable string keyFile = os:getEnv("EPIC_FHIR_APP_PRIVATE_KEY_FILE");
fhir:FHIRConnectorConfig epicConfig = {
baseURL: base,
mimeType: fhir:FHIR_JSON,
authConfig: {
clientId: clientId,
tokenEndpoint: tokenUrl,
keyFile: keyFile
}
};
final fhir:FHIRConnector fhirConnectorObj = check new (epicConfig);
# Generic type to wrap all implemented profiles.
# Add required profile types here.
# public type Patient r4:Patient|<other_Patient_Profile>;
public type Patient uscore:USCorePatientProfile;
public type Organization uscore:USCoreOrganizationProfile;
public type Practitioner uscore:USCorePractitionerProfile;
public type PractitionerRole uscore:USCorePractitionerRoleProfile;
public type Encounter uscore:USCoreEncounterProfile;
public type Location uscore:USCoreLocation;
public type RelatedPerson international:RelatedPerson;
service / on new fhirr4:Listener(9090, patientApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Patient/[string id](r4:FHIRContext fhirContext) returns Patient|r4:FHIRError {
Patient|error fhirInteractionResult = executeFhirInteraction("Patient", fhirContext, id, (), uscore:USCorePatientProfile).ensureType(Patient);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Patient read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/Patient(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Patient", fhirContext, (), (), uscore:USCorePatientProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Patient search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/Patient(r4:FHIRContext fhirContext, uscore:USCorePatientProfile payload) returns @http:Payload {mediaType: ["application/fhir+json"]} Patient|r4:FHIRError {
Patient|error fhirInteractionResult = executeFhirInteraction("Patient", fhirContext, (), payload, uscore:USCorePatientProfile).ensureType(Patient);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Patient create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9091, organizationApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Organization/[string id](r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} Organization|r4:FHIRError {
Organization|error fhirInteractionResult = executeFhirInteraction("Organization", fhirContext, id, (), uscore:USCoreOrganizationProfile).ensureType(Organization);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Organization read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/Organization(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Organization", fhirContext, (), (), uscore:USCoreOrganizationProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Organization search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/Organization(r4:FHIRContext fhirContext, uscore:USCoreOrganizationProfile payload) returns @http:Payload {mediaType: ["application/fhir+json"]} Organization|r4:FHIRError {
Organization|error fhirInteractionResult = executeFhirInteraction("Organization", fhirContext, (), payload, uscore:USCoreOrganizationProfile).ensureType(Organization);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Organization create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9092, practitionerApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Practitioner/[string id](r4:FHIRContext fhirContext) returns Practitioner|r4:FHIRError {
Practitioner|error fhirInteractionResult = executeFhirInteraction("Practitioner", fhirContext, id, (), uscore:USCorePractitionerProfile).ensureType(Practitioner);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Practitioner read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/Practitioner(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Practitioner", fhirContext, (), (), uscore:USCorePractitionerProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Practitioner search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/Practitioner(r4:FHIRContext fhirContext, uscore:USCorePractitionerProfile payload) returns @http:Payload {mediaType: ["application/fhir+json"]} Practitioner|r4:FHIRError {
Practitioner|error fhirInteractionResult = executeFhirInteraction("Practitioner", fhirContext, (), payload, uscore:USCorePractitionerProfile).ensureType(Practitioner);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Practitioner create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9093, practitionerRoleApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/PractitionerRole/[string id](r4:FHIRContext fhirContext) returns PractitionerRole|r4:FHIRError {
PractitionerRole|error fhirInteractionResult = executeFhirInteraction("PractitionerRole", fhirContext, id, (), uscore:USCorePractitionerRoleProfile).ensureType(PractitionerRole);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the PractitionerRole read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/PractitionerRole(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("PractitionerRole", fhirContext, (), (), uscore:USCorePractitionerRoleProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the PractitionerRole search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/PractitionerRole(r4:FHIRContext fhirContext, uscore:USCorePractitionerRoleProfile payload) returns @http:Payload {mediaType: ["application/fhir+json"]} PractitionerRole|r4:FHIRError {
PractitionerRole|error fhirInteractionResult = executeFhirInteraction("PractitionerRole", fhirContext, (), payload, uscore:USCorePractitionerRoleProfile).ensureType(PractitionerRole);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the PractitionerRole create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9094, encounterApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Encounter/[string id](r4:FHIRContext fhirContext) returns Encounter|r4:FHIRError {
Encounter|error fhirInteractionResult = executeFhirInteraction("Encounter", fhirContext, id, (), uscore:USCoreEncounterProfile).ensureType(Encounter);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Encounter read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/Encounter(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Encounter", fhirContext, (), (), uscore:USCoreEncounterProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Encounter search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/Encounter(r4:FHIRContext fhirContext, uscore:USCoreEncounterProfile payload) returns @http:Payload {mediaType: ["application/fhir+json"]} Encounter|r4:FHIRError {
Encounter|error fhirInteractionResult = executeFhirInteraction("Encounter", fhirContext, (), payload, uscore:USCoreEncounterProfile).ensureType(Encounter);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Encounter create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9095, locationApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Location/[string id](r4:FHIRContext fhirContext) returns Location|r4:FHIRError {
Location|error fhirInteractionResult = executeFhirInteraction("Location", fhirContext, id, (), uscore:USCoreLocation).ensureType(Location);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Location read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/Location(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Location", fhirContext, (), (), uscore:USCoreLocation).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Location search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/Location(r4:FHIRContext fhirContext, uscore:USCoreLocation payload) returns @http:Payload {mediaType: ["application/fhir+json"]} Location|r4:FHIRError {
Location|error fhirInteractionResult = executeFhirInteraction("Location", fhirContext, (), payload, uscore:USCoreLocation).ensureType(Location);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Location create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9096, relatedPersonApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/RelatedPerson/[string id](r4:FHIRContext fhirContext) returns RelatedPerson|r4:FHIRError {
RelatedPerson|error fhirInteractionResult = executeFhirInteraction("RelatedPerson", fhirContext, id, (), international:RelatedPerson).ensureType(RelatedPerson);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the RelatedPerson read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search the resource type based on some filter criteria.
isolated resource function get fhir/r4/RelatedPerson(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("RelatedPerson", fhirContext, (), (), international:RelatedPerson).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the RelatedPerson search interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Create a new resource with a server assigned id.
isolated resource function post fhir/r4/RelatedPerson(r4:FHIRContext fhirContext, international:RelatedPerson payload) returns @http:Payload {mediaType: ["application/fhir+json"]} RelatedPerson|r4:FHIRError {
RelatedPerson|error fhirInteractionResult = executeFhirInteraction("RelatedPerson", fhirContext, (), payload, international:RelatedPerson).ensureType(RelatedPerson);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the RelatedPerson create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}