-
Notifications
You must be signed in to change notification settings - Fork 5
/
OclFhirUserController.java
185 lines (161 loc) · 12.2 KB
/
OclFhirUserController.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
package org.openconceptlab.fhir.controller;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.ValueSet;
import org.openconceptlab.fhir.util.OclFhirUtil;
import org.openconceptlab.fhir.provider.CodeSystemResourceProvider;
import org.openconceptlab.fhir.provider.ValueSetResourceProvider;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
import static org.openconceptlab.fhir.util.OclFhirUtil.*;
import static org.openconceptlab.fhir.util.OclFhirConstants.*;
import static org.openconceptlab.fhir.util.OclFhirConstants.CODESYSTEM;
@RestController
@RequestMapping({"/users"})
public class OclFhirUserController extends BaseOclFhirController{
public OclFhirUserController(CodeSystemResourceProvider codeSystemResourceProvider,
ValueSetResourceProvider valueSetResourceProvider,
OclFhirUtil oclFhirUtil) {
super(codeSystemResourceProvider, valueSetResourceProvider, oclFhirUtil);
}
@PostMapping(path = {"/{user}/CodeSystem"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createCodeSystemForUser(@PathVariable(name = USER) String user,
@RequestBody String codeSystem,
@RequestHeader(name = AUTHORIZATION) String auth) {
try {
CodeSystem system = (CodeSystem) parser.parseResource(codeSystem);
Optional<Identifier> acsnOpt = hasAccessionIdentifier(system.getIdentifier());
ResponseEntity<String> response = validate(user, system, acsnOpt, USERS, user);
if (response != null) return response;
if (acsnOpt.isEmpty()) addIdentifier(system.getIdentifier(), USERS, user, CODESYSTEM, system.getId());
performCreate(system, auth);
return ResponseEntity.status(HttpStatus.CREATED).build();
} catch (BaseServerResponseException e) {
return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBody());
} catch (Exception e) {
return badRequest();
}
}
@GetMapping(path = {"/{user}/CodeSystem/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getCodeSystemByUser(@PathVariable String user,
@PathVariable String id,
@RequestParam(name = PAGE, required = false) String page) {
if (isValid(page))
return handleSearchResource(CodeSystem.class, OWNER, formatUser(user), ID, id, PAGE, page);
return handleSearchResource(CodeSystem.class, OWNER, formatUser(user), ID, id);
}
@GetMapping(path = {"/{user}/CodeSystem/{id}/version",
"/{user}/CodeSystem/{id}/version/{version}"},
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getCodeSystemVersionsByUser(@PathVariable(name = USER) String user,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) Optional<String> version,
@RequestParam(name = PAGE, required = false) String page) {
if (isValid(page))
return handleSearchResource(CodeSystem.class, OWNER, formatUser(user), ID, id, VERSION, version.orElse(ALL), PAGE, page);
return handleSearchResource(CodeSystem.class, OWNER, formatUser(user), ID, id, VERSION, version.orElse(ALL));
}
@GetMapping(path = {"/{user}/CodeSystem"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchCodeSystemsByUser(@PathVariable String user) {
return handleSearchResource(CodeSystem.class, OWNER, formatUser(user));
}
@GetMapping(path = {"/{user}/CodeSystem/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByUser(@PathVariable String user,
@RequestParam(name = SYSTEM) String system,
@RequestParam(name = CODE) String code,
@RequestParam(name = VERSION, required = false) String version,
@RequestParam(name = DISP_LANG, required = false) String displayLanguage) {
Parameters parameters = lookupParameters(system, code, version, displayLanguage, formatUser(user));
return handleFhirOperation(parameters, CodeSystem.class, LOOKUP);
}
@PostMapping(path = {"/{user}/CodeSystem/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByUser(@PathVariable String user, @RequestBody String parameters){
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatUser(user)));
return handleFhirOperation(params, CodeSystem.class, LOOKUP);
}
@GetMapping(path = {"/{user}/CodeSystem/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateCodeSystemsByUser(@PathVariable String user,
@RequestParam(name = URL) String url,
@RequestParam(name = CODE) String code,
@RequestParam(name = VERSION, required = false) String version,
@RequestParam(name = DISPLAY, required = false) String display,
@RequestParam(name = DISP_LANG, required = false) String displayLanguage) {
Parameters parameters = codeSystemVCParameters(url, code, version, display, displayLanguage, formatUser(user));
return handleFhirOperation(parameters, CodeSystem.class, VALIDATE_CODE);
}
@PostMapping(path = {"/{user}/CodeSystem/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateCodeSystemsByUser(@PathVariable String user, @RequestBody String parameters){
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatUser(user)));
return handleFhirOperation(params, CodeSystem.class, VALIDATE_CODE);
}
@GetMapping(path = {"/{user}/ValueSet/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getValueSetByUser(@PathVariable String user,
@PathVariable String id,
@RequestParam(name = PAGE, required = false) String page) {
if (isValid(page))
return handleSearchResource(ValueSet.class, OWNER, formatUser(user), ID, id, PAGE, page);
return handleSearchResource(ValueSet.class, OWNER, formatUser(user), ID, id);
}
@GetMapping(path = {"/{user}/ValueSet/{id}/version",
"/{user}/ValueSet/{id}/version/{version}"},
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getValueSetVersionsByUser(@PathVariable(name = USER) String user,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) Optional<String> version,
@RequestParam(name = PAGE, required = false) String page) {
if (isValid(page))
return handleSearchResource(ValueSet.class, OWNER, formatUser(user), ID, id, VERSION, version.orElse(ALL), PAGE, page);
return handleSearchResource(ValueSet.class, OWNER, formatUser(user), ID, id, VERSION, version.orElse(ALL));
}
@GetMapping(path = {"/{user}/ValueSet"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchValueSetsByUser(@PathVariable String user) {
return handleSearchResource(ValueSet.class, OWNER, formatUser(user));
}
@GetMapping(path = {"/{user}/ValueSet/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByUser(@PathVariable String user,
@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, formatUser(user));
return handleFhirOperation(parameters, ValueSet.class, VALIDATE_CODE);
}
@PostMapping(path = {"/{user}/ValueSet/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateValueSetByUser(@PathVariable String user, @RequestBody String parameters){
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatUser(user)));
return handleFhirOperation(params, ValueSet.class, VALIDATE_CODE);
}
@GetMapping(path = {"/{user}/ValueSet/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByUser(@PathVariable String user,
@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, formatUser(user));
return handleFhirOperation(parameters, ValueSet.class, EXPAND);
}
@PostMapping(path = {"/{user}/ValueSet/$expand"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> expandValueSetByUser(@PathVariable String user, @RequestBody String parameters){
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatUser(user)));
return handleFhirOperation(params, ValueSet.class, EXPAND);
}
}