Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#641 perform codesystem operations by id and…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
harpatel1 committed Mar 18, 2021
1 parent 36e5569 commit dc87a5e
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 51 deletions.
Expand Up @@ -91,6 +91,21 @@ protected ResponseEntity<String> handleFhirOperation(Parameters parameters, Clas
}
}

protected ResponseEntity<String> handleFhirOperation(Parameters parameters, Class<? extends Resource> type,
String operation, String id) {
try {
return ResponseEntity.ok(oclFhirUtil.getResourceAsString(performFhirOperation(parameters, type, operation, id)));
} catch (BaseServerResponseException e) {
log.error("BaseServerResponseException - " + e.getMessage());
log.error("BaseServerResponseException - " + e);
return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBody());
} catch (Exception e) {
log.error("Exception - " + e.getMessage());
log.error("Exception - " + e);
return badRequest(e.getMessage());
}
}

protected String searchResource(final Class<? extends MetadataResource> resourceClass, final String... filters) {
IQuery q = oclFhirUtil.getClient().search().forResource(resourceClass);
if (filters.length % 2 == 0) {
Expand All @@ -108,6 +123,17 @@ protected String searchResource(final Class<? extends MetadataResource> resource
return oclFhirUtil.getResourceAsString(bundle);
}

protected Parameters performFhirOperation(Parameters parameters, Class<? extends Resource> type, String operation,
String resourceId) {
return oclFhirUtil.getClient()
.operation()
.onType(type)
.named(operation)
.withParameters(parameters)
.withAdditionalHeader(RESOURCE_ID, resourceId)
.execute();
}

protected Parameters performFhirOperation(Parameters parameters, Class<? extends Resource> type, String operation) {
return oclFhirUtil.getClient()
.operation()
Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.hl7.fhir.r4.model.Parameters;
import org.openconceptlab.fhir.provider.CodeSystemResourceProvider;
import org.openconceptlab.fhir.provider.ValueSetResourceProvider;
import org.openconceptlab.fhir.util.OclFhirConstants;
import org.openconceptlab.fhir.util.OclFhirUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -235,6 +236,94 @@ public ResponseEntity<String> validateCodeSystemsByOrg(@PathVariable String org,
return handleFhirOperation(params, CodeSystem.class, VALIDATE_CODE);
}

/**
* Perform {@link CodeSystem} $lookup.
*
* @param org - the organization id
* @param id - the {@link CodeSystem} id
* @param system - the {@link CodeSystem} url
* @param code - the concept code
* @param version - the {@link CodeSystem} version
* @param displayLanguage - the display language
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/$lookup", "/{id}/version/{version}/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestParam(name = SYSTEM, required = false) 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, isValid(pathVersion) ? pathVersion : version, displayLanguage, formatOrg(org));
return handleFhirOperation(parameters, CodeSystem.class, LOOKUP, id);
}

/**
* Perform {@link CodeSystem} $lookup.
*
* @param org - the organization id
* @param id - the {@link CodeSystem} id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/{id}/$lookup", "/{id}/version/{version}/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByOrgAndId(@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(VERSION, pathVersion);
return handleFhirOperation(params, CodeSystem.class, LOOKUP, id);
}

/**
* Perform {@link CodeSystem} $validate-code.
*
* @param org - the organization id
* @param id - the {@link CodeSystem} id
* @param url - the {@link CodeSystem} url
* @param code - the concept code
* @param version - the {@link CodeSystem} version
* @param display - the concept 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> validateCodeSystemsByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String pathVersion,
@RequestParam(name = URL, required = false) 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, isValid(pathVersion) ? pathVersion : version, display, displayLanguage, formatOrg(org));
return handleFhirOperation(parameters, CodeSystem.class, VALIDATE_CODE, id);
}

/**
* Perform {@link CodeSystem} $validate-code.
*
* @param org - the organization id
* @param id - the {@link CodeSystem} id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/{id}/$validate-code", "/{id}/version/{version}/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateCodeSystemsByOrgAndId(@PathVariable String org,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String pathVersion,
@RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatOrg(org)));
if (isValid(pathVersion))
params.setParameter(VERSION, pathVersion);
return handleFhirOperation(params, CodeSystem.class, VALIDATE_CODE, id);
}

}


Expand Up @@ -235,5 +235,93 @@ public ResponseEntity<String> validateCodeSystemsByUser(@PathVariable String use
return handleFhirOperation(params, CodeSystem.class, VALIDATE_CODE);
}

/**
* Perform {@link CodeSystem} $lookup.
*
* @param user - the username
* @param id - the {@link CodeSystem} id
* @param system - the {@link CodeSystem} url
* @param code - the concept code
* @param version - the {@link CodeSystem} version
* @param displayLanguage - the display language
* @return ResponseEntity
*/
@GetMapping(path = {"/{id}/$lookup", "/{id}/version/{version}/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByUserAndId(@PathVariable String user,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION, required = false) String pathVersion,
@RequestParam(name = SYSTEM, required = false) 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, isValid(pathVersion) ? pathVersion : version, displayLanguage, formatUser(user));
return handleFhirOperation(parameters, CodeSystem.class, LOOKUP, id);
}

/**
* Perform {@link CodeSystem} $lookup.
*
* @param user - the username
* @param id - the {@link CodeSystem} id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/{id}/$lookup", "/{id}/version/{version}/$lookup"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> lookUpCodeSystemsByUserAndId(@PathVariable String user,
@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(formatUser(user)));
if (isValid(pathVersion))
params.setParameter(VERSION, pathVersion);
return handleFhirOperation(params, CodeSystem.class, LOOKUP, id);
}

/**
* Perform {@link CodeSystem} $validate-code.
*
* @param user - the username
* @param id - the {@link CodeSystem} id
* @param url - the {@link CodeSystem} url
* @param code - the concept code
* @param version - the {@link CodeSystem} version
* @param display - the concept 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> validateCodeSystemsByUserAndId(@PathVariable String user,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String pathVersion,
@RequestParam(name = URL, required = false) 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, isValid(pathVersion) ? pathVersion : version, display, displayLanguage, formatUser(user));
return handleFhirOperation(parameters, CodeSystem.class, VALIDATE_CODE, id);
}

/**
* Perform {@link CodeSystem} $validate-code.
*
* @param user - the username
* @param id - the {@link CodeSystem} id
* @param parameters - the input parameters
* @return ResponseEntity
*/
@PostMapping(path = {"/{id}/$validate-code", "/{id}/version/{version}/$validate-code"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> validateCodeSystemsByUserAndId(@PathVariable String user,
@PathVariable(name = ID) String id,
@PathVariable(name = VERSION) String pathVersion,
@RequestBody String parameters) {
Parameters params = (Parameters) getResource(parameters);
params.addParameter().setName(OWNER).setValue(newStringType(formatUser(user)));
if (isValid(pathVersion))
params.setParameter(VERSION, pathVersion);
return handleFhirOperation(params, CodeSystem.class, VALIDATE_CODE, id);
}

}

0 comments on commit dc87a5e

Please sign in to comment.