-
Notifications
You must be signed in to change notification settings - Fork 5
/
OclFhirOrgValueSetController.java
353 lines (329 loc) · 20.3 KB
/
OclFhirOrgValueSetController.java
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package org.openconceptlab.fhir.controller;
import org.hl7.fhir.r4.model.*;
import org.openconceptlab.fhir.provider.CodeSystemResourceProvider;
import org.openconceptlab.fhir.provider.ValueSetResourceProvider;
import org.openconceptlab.fhir.util.OclFhirUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
import static org.openconceptlab.fhir.util.OclFhirConstants.*;
import static org.openconceptlab.fhir.util.OclFhirConstants.EXPAND;
import static org.openconceptlab.fhir.util.OclFhirUtil.*;
import static org.openconceptlab.fhir.util.OclFhirUtil.newStringType;
@RestController
@RequestMapping({"/orgs/{org}/ValueSet"})
public class OclFhirOrgValueSetController extends BaseOclFhirController {
public OclFhirOrgValueSetController(CodeSystemResourceProvider codeSystemResourceProvider,
ValueSetResourceProvider valueSetResourceProvider,
OclFhirUtil oclFhirUtil) {
super(codeSystemResourceProvider, valueSetResourceProvider, oclFhirUtil);
}
/**
* Create {@link ValueSet}
*
* @param org - the organization id
* @param valueSet - the {@link ValueSet} resource
* @return ResponseEntity
*/
@PostMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createValueSetForOrg(@PathVariable(name = ORG) String org,
@RequestBody String valueSet,
@RequestHeader(name = AUTHORIZATION) String auth) {
ValueSet set = (ValueSet) parser.parseResource(valueSet);
Optional<Identifier> acsnOpt = hasAccessionIdentifier(set.getIdentifier());
ResponseEntity<String> response = validate(set.getIdElement().getIdPart(), acsnOpt, ORGS, org);
if (response != null) return response;
if (acsnOpt.isEmpty())
addIdentifier(set.getIdentifier(), ORGS, org, VALUESET, set.getIdElement().getIdPart(), set.getVersion());
performCreate(set, auth);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
/**
* Update {@link ValueSet} version.
*
* @param id - the {@link ValueSet} id
* @param version - the {@link ValueSet} version
* @param org - the organization id
* @param valueSet - the {@link ValueSet} resource
* @return ResponseEntity
*/
@PutMapping(path = {"/{id}/version/{version}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> updateValueSetForOrg(@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String version,
@PathVariable(name = ORG) String org,
@RequestBody String valueSet,
@RequestHeader(name = AUTHORIZATION) String auth) {
ValueSet set = (ValueSet) parser.parseResource(valueSet);
IdType idType = new IdType(VALUESET, id, version);
performUpdate(set, auth, idType, formatOrg(org));
return ResponseEntity.status(HttpStatus.OK).build();
}
/**
* Delete {@link ValueSet} version.
*
* @param id - the {@link ValueSet} id
* @param version - the {@link ValueSet} version
* @param org - the organization id
* @return ResponseEntity
*/
@DeleteMapping(path = {"/{id}/version/{version}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteValueSetByOrg(@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String version,
@PathVariable(name = ORG) String org,
@RequestHeader(name = AUTHORIZATION) String auth) {
String url = oclFhirUtil.oclApiBaseUrl() + FS + ORGS + FS + org + FS + COLLECTIONS + FS + id + FS + version + FS;
return performDeleteOclApi(url, auth);
}
/**
* Delete concepts from {@link ValueSet} version.
*
* @param id - the {@link ValueSet} id
* @param version - the {@link ValueSet} version
* @param conceptId - the concept code
* @param org - the organization id
* @return ResponseEntity
*/
@DeleteMapping(path = {"/{id}/version/{version}/concepts/{concept_id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteConceptInValueSetForOrg(@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String version,
@PathVariable(name = CONCEPT_ID) String conceptId,
@PathVariable(name = ORG) String org,
@RequestHeader(name = AUTHORIZATION) String auth) {
String url = oclFhirUtil.oclApiBaseUrl() + FS + ORGS + FS + org + FS + COLLECTIONS + FS + id + FS + version + FS + CONCEPTS + FS + conceptId + FS;
return performDeleteOclApi(url, auth);
}
/**
* Read {@link ValueSet} by Id.
*
* @param org - the organization id
* @param id - the {@link ValueSet} id
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getValueSetByOrg(@PathVariable String org,
@PathVariable String id,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
return handleSearchResource(ValueSet.class, OWNER, formatOrg(org), ID, id, PAGE, page.orElse("1"),
OWNER_URL, getRequestUrl(request));
}
/**
* Read {@link ValueSet} version.
*
* @param org - the organization id
* @param id - the {@link ValueSet} id
* @param version - the {@link ValueSet} version
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/version", "/{id}/version/{version}"},
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getValueSetVersionsByOrg(@PathVariable(name = ORG) String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) Optional<String> version,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
return handleSearchResource(ValueSet.class, OWNER, formatOrg(org), ID, id, VERSION, version.orElse(ALL),
PAGE, page.orElse("1"), OWNER_URL, getRequestUrl(request));
}
/**
* Read all {@link ValueSet} of org.
*
* @param org - the organization id
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchValueSetsByOrg(@PathVariable String org,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
return handleSearchResource(ValueSet.class, OWNER, formatOrg(org), PAGE, page.orElse("1"),
OWNER_URL, getRequestUrl(request));
}
/**
* Perform {@link ValueSet} $validate-code.
*
* @param org - the organization id
* @param url - the {@link ValueSet} url
* @param valueSetVersion - the {@link ValueSet} version
* @param code - the concept code
* @param system - the {@link CodeSystem} url
* @param systemVersion - the {@link CodeSystem} version
* @param display - the display
* @param displayLanguage - the display language
* @return ResponseEntity
*/
@GetMapping(path = {"/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByOrg(@PathVariable String org,
@RequestParam(name = URL) String url,
@RequestParam(name = VALUESET_VERSION, required = false) String valueSetVersion,
@RequestParam(name = CODE) String code,
@RequestParam(name = SYSTEM) String system,
@RequestParam(name = SYSTEM_VERSION, required = false) String systemVersion,
@RequestParam(name = DISPLAY, required = false) String display,
@RequestParam(name = DISP_LANG, required = false) String displayLanguage) {
Parameters parameters = valueSetVCParameters(url, EMPTY, valueSetVersion, code, system, systemVersion, display,
displayLanguage, formatOrg(org));
return handleFhirOperation(parameters, ValueSet.class, VALIDATE_CODE);
}
/**
* Perform {@link ValueSet} $validate-code.
*
* @param org - the organization id
* @param parameters - the input parameters
* @return
*/
@PostMapping(path = {"/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByOrg(@PathVariable String org, @RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
return handleFhirOperation(params, ValueSet.class, VALIDATE_CODE);
}
/**
* Perform {@link ValueSet} $expand.
*
* @param org - the organization id
* @param url - the {@link ValueSet} url
* @param valueSetVersion - the {@link ValueSet} version
* @param offset - the offset (for partial output)
* @param count - the count (for partial output)
* @param includeDesignations - flag to include/exclude designations
* @param includeDefinition - flag to include/exclude definition
* @param activeOnly - flag to include/exclude active concepts
* @param displayLanguage - the display language
* @param filter - the concept code filter
* @return
*/
@GetMapping(path = {"/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByOrg(@PathVariable String org,
@RequestParam(name = URL) String url,
@RequestParam(name = VALUESET_VERSION, required = false) String valueSetVersion,
@RequestParam(name = OFFSET, required = false, defaultValue = "0") Integer offset,
@RequestParam(name = COUNT, required = false, defaultValue = "100") Integer count,
@RequestParam(name = INCLUDE_DESIGNATIONS, defaultValue = "true") Boolean includeDesignations,
@RequestParam(name = INCLUDE_DEFINITION, defaultValue = "false") Boolean includeDefinition,
@RequestParam(name = ACTIVE_ONLY, defaultValue = "true") Boolean activeOnly,
@RequestParam(name = DISPLAY_LANGUAGE, required = false) String displayLanguage,
@RequestParam(name = FILTER, required = false) String filter) {
Parameters parameters = valueSetExpandParameters(url, valueSetVersion, offset, count, includeDesignations,
includeDefinition, activeOnly, displayLanguage, filter, formatOrg(org));
return handleFhirOperation(parameters, ValueSet.class, EXPAND);
}
/**
* Perform {@link ValueSet} $expand.
*
* @param org - the organization id
* @param parameters - the input paramters
* @return
*/
@PostMapping(path = {"/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByOrg(@PathVariable String org, @RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
return handleFhirOperation(params, ValueSet.class, EXPAND);
}
/**
* Perform {@link ValueSet} $validate-code.
*
* @param org - the organization id
* @param id - the {@link ValueSet} id
* @param url - the {@link ValueSet} url
* @param valueSetVersion - the {@link ValueSet} version
* @param code - the concept code
* @param system - the {@link CodeSystem} url
* @param systemVersion - the {@link CodeSystem} version
* @param display - the display
* @param displayLanguage - the display language
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/$validate-code", "/{id}/version/{version}/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestParam(name = URL, required = false) String url,
@RequestParam(name = VALUESET_VERSION, required = false) String valueSetVersion,
@RequestParam(name = CODE) String code,
@RequestParam(name = SYSTEM) String system,
@RequestParam(name = SYSTEM_VERSION, required = false) String systemVersion,
@RequestParam(name = DISPLAY, required = false) String display,
@RequestParam(name = DISP_LANG, required = false) String displayLanguage) {
Parameters parameters = valueSetVCParameters(url, EMPTY, isValid(pathVersion) ? pathVersion : valueSetVersion, code, system, systemVersion, display,
displayLanguage, formatOrg(org));
return handleFhirOperation(parameters, ValueSet.class, VALIDATE_CODE, id);
}
/**
* Perform {@link ValueSet} $validate-code.
*
* @param org - the organization id
* @param id - the {@link CodeSystem} id
* @param parameters - the input parameters
* @return
*/
@PostMapping(path = {"/{id}/$validate-code", "/{id}/version/{version}/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
if (isValid(pathVersion))
params.setParameter(VALUESET_VERSION, pathVersion);
return handleFhirOperation(params, ValueSet.class, VALIDATE_CODE, id);
}
/**
* Perform {@link ValueSet} $expand.
*
* @param org - the organization id
* @param id - the {@link ValueSet} id
* @param url - the {@link ValueSet} url
* @param valueSetVersion - the {@link ValueSet} version
* @param offset - the offset (for partial output)
* @param count - the count (for partial output)
* @param includeDesignations - flag to include/exclude designations
* @param includeDefinition - flag to include/exclude definition
* @param activeOnly - flag to include/exclude active concepts
* @param displayLanguage - the display language
* @param filter - the concept code filter
* @return
*/
@GetMapping(path = {"/{id}/$expand", "/{id}/version/{version}/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestParam(name = URL, required = false) String url,
@RequestParam(name = VALUESET_VERSION, required = false) String valueSetVersion,
@RequestParam(name = OFFSET, required = false, defaultValue = "0") Integer offset,
@RequestParam(name = COUNT, required = false, defaultValue = "100") Integer count,
@RequestParam(name = INCLUDE_DESIGNATIONS, defaultValue = "true") Boolean includeDesignations,
@RequestParam(name = INCLUDE_DEFINITION, defaultValue = "false") Boolean includeDefinition,
@RequestParam(name = ACTIVE_ONLY, defaultValue = "true") Boolean activeOnly,
@RequestParam(name = DISPLAY_LANGUAGE, required = false) String displayLanguage,
@RequestParam(name = FILTER, required = false) String filter) {
Parameters parameters = valueSetExpandParameters(url, isValid(pathVersion) ? pathVersion : valueSetVersion, offset, count, includeDesignations,
includeDefinition, activeOnly, displayLanguage, filter, formatOrg(org));
return handleFhirOperation(parameters, ValueSet.class, EXPAND, id);
}
/**
* Perform {@link ValueSet} $expand.
*
* @param org - the organization id
* @param id - the {@link ValueSet} id
* @param parameters - the input paramters
* @return
*/
@PostMapping(path = {"/{id}/$expand", "/{id}/version/{version}/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
if (isValid(pathVersion))
params.setParameter(VALUESET_VERSION, pathVersion);
return handleFhirOperation(params, ValueSet.class, EXPAND, id);
}
}