-
Notifications
You must be signed in to change notification settings - Fork 5
/
OclFhirOrgConceptMapController.java
237 lines (217 loc) · 12.8 KB
/
OclFhirOrgConceptMapController.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
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.Collections;
import java.util.Optional;
import static org.openconceptlab.fhir.util.OclFhirConstants.*;
import static org.openconceptlab.fhir.util.OclFhirConstants.TRANSLATE;
import static org.openconceptlab.fhir.util.OclFhirUtil.*;
@RestController
@RequestMapping({"/orgs/{org}/ConceptMap"})
public class OclFhirOrgConceptMapController extends BaseOclFhirController {
public OclFhirOrgConceptMapController(CodeSystemResourceProvider codeSystemResourceProvider,
ValueSetResourceProvider valueSetResourceProvider,
OclFhirUtil oclFhirUtil) {
super(codeSystemResourceProvider, valueSetResourceProvider, oclFhirUtil);
}
/**
* Create {@link ConceptMap}
*
* @param org - the username
* @param conceptMap - the {@link ConceptMap} resource
* @return ResponseEntity
*/
@PostMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createConceptMapForOrg(@PathVariable(name = ORG) String org,
@RequestBody String conceptMap,
@RequestHeader(name = AUTHORIZATION) String auth) {
ConceptMap map = (ConceptMap) parser.parseResource(conceptMap);
Optional<Identifier> acsnOpt = hasAccessionIdentifier(Collections.singletonList(map.getIdentifier()));
ResponseEntity<String> response = validate(map.getIdElement().getIdPart(), acsnOpt, ORGS, org);
if (response != null) return response;
if (acsnOpt.isEmpty()) map.setIdentifier(
getIdentifier(ORGS, org, CONCEPTMAP, map.getIdElement().getIdPart(), map.getVersion())
);
performCreate(map, auth);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
/**
* Update {@link ConceptMap} version.
*
* @param id - the {@link ConceptMap} id
* @param version - the {@link ConceptMap} version
* @param org - the organization id
* @param conceptMap - the {@link ConceptMap} resource
* @return ResponseEntity
*/
@PutMapping(path = {"/{id}/version/{version}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> updateConceptMapForOrg(@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String version,
@PathVariable(name = ORG) String org,
@RequestBody String conceptMap,
@RequestHeader(name = AUTHORIZATION) String auth) {
if (!validateIfEditable(CONCEPTMAP, id, version, ORG, org))
return badRequest("The ConceptMap can not be edited.");
ConceptMap map = (ConceptMap) parser.parseResource(conceptMap);
IdType idType = new IdType(CONCEPTMAP, id, version);
performUpdate(map, auth, idType, formatOrg(org));
return ResponseEntity.status(HttpStatus.OK).build();
}
/**
* Delete {@link ConceptMap} version.
*
* @param id - the {@link ConceptMap} id
* @param version - the {@link ConceptMap} version
* @param org - the organization id
* @return ResponseEntity
*/
@DeleteMapping(path = {"/{id}/version/{version}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteConceptMapByOrg(@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String version,
@PathVariable(name = ORG) String org,
@RequestHeader(name = AUTHORIZATION) String auth) {
if (!validateIfEditable(CONCEPTMAP, id, version, ORG, org))
return badRequest("The ConceptMap can not be deleted.");
String url = oclFhirUtil.oclApiBaseUrl() + FS + ORGS + FS + org + FS + SOURCES + FS + id + FS + version + FS;
return performDeleteOclApi(url, auth);
}
/**
* Read {@link ConceptMap} by Id.
*
* @param org - the organization id
* @param id - the {@link ConceptMap} id
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getConceptMapByOrg(@PathVariable(name = ORG) String org,
@PathVariable(name = ID) String id,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
return handleSearchResource(ConceptMap.class, OWNER, formatOrg(org), ID, id, PAGE, page.orElse("1"),
OWNER_URL, getRequestUrl(request));
}
/**
* Read {@link ConceptMap} version.
*
* @param org - the organization id
* @param id - the {@link ConceptMap} id
* @param version - the {@link ConceptMap} version
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/version", "/{id}/version/{version}"},
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getConceptMapVersionsByOrg(@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(ConceptMap.class, OWNER, formatOrg(org), ID, id, VERSION, version.orElse(ALL),
PAGE, page.orElse("1"), OWNER_URL, getRequestUrl(request));
}
/**
* Read all {@link ConceptMap} of org.
*
* @param org - the organization id
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchConceptMapsByOrg(@PathVariable String org,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
return handleSearchResource(ConceptMap.class, OWNER, formatOrg(org), PAGE, page.orElse("1"),
OWNER_URL, getRequestUrl(request));
}
/**
* Perform {@link ConceptMap} $translate.
*
* @param org - the organization id
* @param conceptMapUrl - the {@link ConceptMap} url
* @param conceptMapVersion - the {@link ConceptMap} version
* @param system - the source {@link ConceptMap} url
* @param version - the source {@link ConceptMap} version
* @param code - the concept code that needs to be translated
* @param targetSystem - the target {@link ConceptMap} url
* @return ResponseEntity
*/
@GetMapping(path = {"/$translate"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> translateConceptMapByOrg(@PathVariable(name = ORG) String org,
@RequestParam(name = URL) String conceptMapUrl,
@RequestParam(name = CONCEPT_MAP_VERSION, required = false) String conceptMapVersion,
@RequestParam(name = SYSTEM) String system,
@RequestParam(name = VERSION, required = false) String version,
@RequestParam(name = CODE) String code,
@RequestParam(name = TARGET_SYSTEM, required = false) String targetSystem) {
Parameters parameters = conceptMapTranslateParameters(conceptMapUrl, conceptMapVersion, system, version, code,
targetSystem, formatOrg(org));
return handleFhirOperation(parameters, ConceptMap.class, TRANSLATE);
}
/**
* Perform {@link ConceptMap} $translate.
*
* @param org - the organization id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/$translate"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> translateConceptMapByOrg(@PathVariable(name = ORG) String org, @RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
return handleFhirOperation(params, ConceptMap.class, TRANSLATE);
}
/**
* Perform {@link ConceptMap} $translate.
*
* @param org - the organization id
* @param id - the {@link ConceptMap} id
* @param conceptMapUrl - the {@link ConceptMap} url
* @param conceptMapVersion - the {@link ConceptMap} version
* @param system - the source {@link ConceptMap} url
* @param version - the source {@link ConceptMap} version
* @param code - the concept code that needs to be translated
* @param targetSystem - the target {@link ConceptMap} url
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/$translate", "/{id}/version/{version}/$translate"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> translateConceptMapByOrgAndId(@PathVariable(name = ORG) String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestParam(name = URL, required = false) String conceptMapUrl,
@RequestParam(name = CONCEPT_MAP_VERSION, required = false) String conceptMapVersion,
@RequestParam(name = SYSTEM) String system,
@RequestParam(name = VERSION, required = false) String version,
@RequestParam(name = CODE) String code,
@RequestParam(name = TARGET_SYSTEM, required = false) String targetSystem) {
Parameters parameters = conceptMapTranslateParameters(conceptMapUrl, isValid(pathVersion) ? pathVersion : conceptMapVersion, system, version, code,
targetSystem, formatOrg(org));
return handleFhirOperation(parameters, ConceptMap.class, TRANSLATE, id);
}
/**
* Perform {@link ConceptMap} $translate.
*
* @param org - the organization id
* @param id - the {@link ConceptMap} id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/{id}/$translate", "/{id}/version/{version}/$translate"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> translateConceptMapByOrgAndId(@PathVariable(name = ORG) 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(CONCEPT_MAP_VERSION, pathVersion);
return handleFhirOperation(params, ConceptMap.class, TRANSLATE, id);
}
}