-
Notifications
You must be signed in to change notification settings - Fork 18
/
service.bal
165 lines (141 loc) · 9.71 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
import ballerinax/health.clients.fhir;
import ballerina/os;
import ballerinax/health.fhirr4;
import ballerinax/health.fhir.r4.uscore501 as uscore;
import ballerinax/health.fhir.r4;
import ballerinax/health.fhir.r4.international401;
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 Medication uscore:USCoreMedicationProfile;
public type Immunization uscore:USCoreImmunizationProfile;
public type MedicationRequest uscore:USCoreMedicationRequestProfile;
public type MedicationStatement international401:MedicationStatement;
service / on new fhirr4:Listener(9090, medicationApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Medication/[string id](r4:FHIRContext fhirContext) returns Medication|r4:FHIRError {
Medication|error fhirInteractionResult = executeFhirInteraction("Medication", fhirContext, id, (), uscore:USCoreMedicationProfile).ensureType(Medication);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/Medication(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Medication", fhirContext, (), (), uscore:USCoreMedicationProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/Medication(r4:FHIRContext fhirContext, uscore:USCoreMedicationProfile medication) returns @http:Payload {mediaType: ["application/fhir+json"]} Medication|r4:FHIRError {
Medication|error fhirInteractionResult = executeFhirInteraction("Medication", fhirContext, (), medication, uscore:USCoreMedicationProfile).ensureType(Medication);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9091, immunizationApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/Immunication/[string id](r4:FHIRContext fhirContext) returns Immunization|r4:FHIRError {
Immunization|error fhirInteractionResult = executeFhirInteraction("Immunization", fhirContext, id, (), uscore:USCoreImmunizationProfile).ensureType(Immunization);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/Immunization(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("Immunization", fhirContext, (), (), uscore:USCoreImmunizationProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/Immunization(r4:FHIRContext fhirContext, uscore:USCoreImmunizationProfile immunization) returns @http:Payload {mediaType: ["application/fhir+json"]} Immunization|r4:FHIRError {
Immunization|error fhirInteractionResult = executeFhirInteraction("Immunization", fhirContext, (), immunization, uscore:USCoreImmunizationProfile).ensureType(Immunization);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9092, medicationrequestApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/MedicationRequest/[string id](r4:FHIRContext fhirContext) returns MedicationRequest|r4:FHIRError {
MedicationRequest|error fhirInteractionResult = executeFhirInteraction("MedicationRequest", fhirContext, id, (), uscore:USCoreMedicationRequestProfile).ensureType(MedicationRequest);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/MedicationRequest(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("MedicationRequest", fhirContext, (), (), uscore:USCoreMedicationRequestProfile).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/MedicationRequest(r4:FHIRContext fhirContext, uscore:USCoreMedicationRequestProfile medicationRequest) returns @http:Payload {mediaType: ["application/fhir+json"]} MedicationRequest|r4:FHIRError {
MedicationRequest|error fhirInteractionResult = executeFhirInteraction("MedicationRequest", fhirContext, (), medicationRequest, uscore:USCoreMedicationRequestProfile).ensureType(MedicationRequest);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}
service / on new fhirr4:Listener(9093, medicationstatementApiConfig) {
// Read the current state of the resource.
isolated resource function get fhir/r4/MedicationStatement/[string id](r4:FHIRContext fhirContext) returns MedicationStatement|r4:FHIRError {
MedicationStatement|error fhirInteractionResult = executeFhirInteraction("MedicationStatement", fhirContext, id, (), international401:MedicationStatement).ensureType(MedicationStatement);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/MedicationStatement(r4:FHIRContext fhirContext) returns @http:Payload {mediaType: ["application/fhir+json"]} r4:Bundle|r4:FHIRError {
r4:Bundle|error fhirInteractionResult = executeFhirInteraction("MedicationStatement", fhirContext, (), (), international401:MedicationStatement).ensureType(r4:Bundle);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation 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/MedicationStatement(r4:FHIRContext fhirContext, international401:MedicationStatement medicationStatement) returns @http:Payload {mediaType: ["application/fhir+json"]} MedicationStatement|r4:FHIRError {
MedicationStatement|error fhirInteractionResult = executeFhirInteraction("MedicationStatement", fhirContext, (), medicationStatement, international401:MedicationStatement).ensureType(MedicationStatement);
if fhirInteractionResult is error {
return r4:createFHIRError("Error occurred while executing the Observation create interaction.", r4:CODE_SEVERITY_ERROR,
r4:TRANSIENT_EXCEPTION, cause = fhirInteractionResult);
}
return fhirInteractionResult;
}
}