-
Notifications
You must be signed in to change notification settings - Fork 18
/
service.bal
199 lines (170 loc) · 11.5 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
import ballerina/os;
import ballerinax/health.clients.fhir;
import ballerinax/health.fhir.r4.international401;
import ballerinax/health.fhirr4;
import ballerinax/health.fhir.r4;
import ballerina/http;
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);
public type Schedule international401:Schedule;
public type Slot international401:Slot;
public type Appointment international401:Appointment;
public type AppointmentResponse international401:AppointmentResponse;
public type ServiceRequest international401:ServiceRequest;
service / on new fhirr4:Listener(9090, scheduleApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Schedule/[string id](r4:FHIRContext fhirContext) returns Schedule|r4:FHIRError {
Schedule|error fhirInteractionResult = executeFhirInteraction("Schedule", fhirContext, id, (), international401:Schedule).ensureType(Schedule);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Schedule read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search for resources based on some filter criteria.
isolated resource function get fhir/r4/Schedule(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Schedule", fhirContext, (), (), international401:Schedule).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Schedule 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/Schedule(r4:FHIRContext fhirContext, international401:Schedule schedule) returns @http:Payload {mediaType: ["application/fhir+json"]} Schedule|r4:FHIRError {
Schedule|error fhirInteractionResult = executeFhirInteraction("Schedule", fhirContext, (), schedule, international401:Schedule).ensureType(Schedule);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Schedule create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9091, slotApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Slot/[string id](r4:FHIRContext fhirContext) returns Slot|r4:FHIRError {
Slot|error fhirInteractionResult = executeFhirInteraction("Slot", fhirContext, id, (), international401:Slot).ensureType(Slot);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Slot read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search for resources based on some filter criteria.
isolated resource function get fhir/r4/Slot(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Slot", fhirContext, (), (), international401:Slot).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Slot 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/Slot(r4:FHIRContext fhirContext, international401:Slot slot) returns @http:Payload {mediaType: ["application/fhir+json"]} Slot|r4:FHIRError {
Slot|error fhirInteractionResult = executeFhirInteraction("Slot", fhirContext, (), slot, international401:Slot).ensureType(Slot);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Slot create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9092, appointmentApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Appointment/[string id](r4:FHIRContext fhirContext) returns Appointment|r4:FHIRError {
Appointment|error fhirInteractionResult = executeFhirInteraction("Appointment", fhirContext, id, (), international401:Appointment).ensureType(Appointment);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Appointment read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search for resources based on some filter criteria.
isolated resource function get fhir/r4/Appointment(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Appointment", fhirContext, (), (), international401:Appointment).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Appointment 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/Appointment(r4:FHIRContext fhirContext, international401:Appointment appointment) returns @http:Payload {mediaType: ["application/fhir+json"]} Appointment|r4:FHIRError {
Appointment|error fhirInteractionResult = executeFhirInteraction("Appointment", fhirContext, (), appointment, international401:Appointment).ensureType(Appointment);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Appointment create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9093, appointmentResponseApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/AppointmentResponse/[string id](r4:FHIRContext fhirContext) returns AppointmentResponse|r4:FHIRError {
AppointmentResponse|error fhirInteractionResult = executeFhirInteraction("AppointmentResponse", fhirContext, id, (), international401:AppointmentResponse).ensureType(AppointmentResponse);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the AppointmentResponse read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search for resources based on some filter criteria.
isolated resource function get fhir/r4/AppointmentResponse(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("AppointmentResponse", fhirContext, (), (), international401:AppointmentResponse).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the AppointmentResponse 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/AppointmentResponse(r4:FHIRContext fhirContext, international401:AppointmentResponse appointmentResponse) returns @http:Payload {mediaType: ["application/fhir+json"]} AppointmentResponse|r4:FHIRError {
AppointmentResponse|error fhirInteractionResult = executeFhirInteraction("AppointmentResponse", fhirContext, (), appointmentResponse, international401:AppointmentResponse).ensureType(AppointmentResponse);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the AppointmentResponse create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9094, serviceRequestApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/ServiceRequest/[string id](r4:FHIRContext fhirContext) returns ServiceRequest|r4:FHIRError {
ServiceRequest|error fhirInteractionResult = executeFhirInteraction("ServiceRequest", fhirContext, id, (), international401:ServiceRequest).ensureType(ServiceRequest);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the ServiceRequest read interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
// Search for resources based on some filter criteria.
isolated resource function get fhir/r4/ServiceRequest(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("ServiceRequest", fhirContext, (), (), international401:ServiceRequest).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the ServiceRequest 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/ServiceRequest(r4:FHIRContext fhirContext, international401:ServiceRequest serviceRequest) returns @http:Payload {mediaType: ["application/fhir+json"]} ServiceRequest|r4:FHIRError {
ServiceRequest|error fhirInteractionResult = executeFhirInteraction("ServiceRequest", fhirContext, (), serviceRequest, international401:ServiceRequest).ensureType(ServiceRequest);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the ServiceRequest create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}