Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#643 perform conceptmap operations by id and…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
harpatel1 committed Mar 23, 2021
1 parent 1cace00 commit 54da106
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 13 deletions.
Expand Up @@ -6,7 +6,6 @@
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 @@ -38,7 +37,7 @@ public OclFhirOrgCodeSystemController(CodeSystemResourceProvider codeSystemResou
* @param codeSystem - the {@link CodeSystem} resource
* @return ResponseEntity
*/
@PostMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createCodeSystemForOrg(@PathVariable(name = ORG) String org,
@RequestBody String codeSystem,
@RequestHeader(name = AUTHORIZATION) String auth) {
Expand Down Expand Up @@ -158,7 +157,7 @@ public ResponseEntity<String> getCodeSystemVersionsByOrg(@PathVariable(name = OR
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchCodeSystemsByOrg(@PathVariable String org,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
Expand Down
@@ -1,7 +1,6 @@
package org.openconceptlab.fhir.controller;

import org.hl7.fhir.r4.model.*;
import org.openconceptlab.fhir.model.Concept;
import org.openconceptlab.fhir.provider.CodeSystemResourceProvider;
import org.openconceptlab.fhir.provider.ValueSetResourceProvider;
import org.openconceptlab.fhir.util.OclFhirUtil;
Expand Down Expand Up @@ -35,7 +34,7 @@ public OclFhirOrgConceptMapController(CodeSystemResourceProvider codeSystemResou
* @param conceptMap - the {@link ConceptMap} resource
* @return ResponseEntity
*/
@PostMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createConceptMapForOrg(@PathVariable(name = ORG) String org,
@RequestBody String conceptMap,
@RequestHeader(name = AUTHORIZATION) String auth) {
Expand Down Expand Up @@ -137,7 +136,7 @@ public ResponseEntity<String> getConceptMapVersionsByOrg(@PathVariable(name = OR
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchConceptMapsByOrg(@PathVariable String org,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
Expand Down Expand Up @@ -184,6 +183,55 @@ public ResponseEntity<String> translateConceptMapByOrg(@PathVariable(name = 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);
}

}



Expand Up @@ -34,7 +34,7 @@ public OclFhirOrgValueSetController(CodeSystemResourceProvider codeSystemResourc
* @param valueSet - the {@link ValueSet} resource
* @return ResponseEntity
*/
@PostMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@PostMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> createValueSetForOrg(@PathVariable(name = ORG) String org,
@RequestBody String valueSet,
@RequestHeader(name = AUTHORIZATION) String auth) {
Expand Down Expand Up @@ -150,7 +150,7 @@ public ResponseEntity<String> getValueSetVersionsByOrg(@PathVariable(name = ORG)
* @param page - the page number
* @return ResponseEntity
*/
@GetMapping(path = {"/"}, produces = {MediaType.APPLICATION_JSON_VALUE})
@GetMapping(path = {"/", ""}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> searchValueSetsByOrg(@PathVariable String org,
@RequestParam(name = PAGE, required = false) Optional<String> page,
HttpServletRequest request) {
Expand Down
Expand Up @@ -186,5 +186,53 @@ public ResponseEntity<String> translateConceptMapByUser(@PathVariable(name = USE
return handleFhirOperation(params, ConceptMap.class, TRANSLATE);
}

/**
* Perform {@link ConceptMap} $translate.
*
* @param user - the username
* @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> translateConceptMapByUserAndId(@PathVariable(name = USER) String user,
@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, formatUser(user));
return handleFhirOperation(parameters, ConceptMap.class, TRANSLATE, id);
}

/**
* Perform {@link ConceptMap} $translate.
*
* @param user - the username
* @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> translateConceptMapByUserAndId(@PathVariable(name = USER) 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(CONCEPT_MAP_VERSION, pathVersion);
return handleFhirOperation(params, ConceptMap.class, TRANSLATE, id);
}

}

Expand Up @@ -5,6 +5,7 @@
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand Down Expand Up @@ -183,20 +184,45 @@ public Parameters conceptMapTranslate(@OperationParam(name = URL, min = 1, type
@OperationParam(name = CODE, min = 1, type = CodeType.class) CodeType sourceCode,
@OperationParam(name = CODING, type = Coding.class) Coding coding,
@OperationParam(name = TARGET_SYSTEM, type = UriType.class) UriType targetSystem,
@OperationParam(name = OWNER, type = StringType.class) StringType owner) {
@OperationParam(name = OWNER, type = StringType.class) StringType owner,
RequestDetails requestDetails) {

// $translate by id
String id = requestDetails.getHeader(RESOURCE_ID);
if (isValid(id) && isValid(owner)) {
if (coding != null) {
sourceCode = new CodeType(coding.getCode());
if (!isValid(conceptMapVersion))
sourceVersion = new StringType(coding.getVersion());
}
validate(sourceCode, sourceSystem);
List<Source> conceptMaps = getSourceByOwnerAndIdAndVersion(newStringType(id), owner, conceptMapVersion, publicAccess);
if (conceptMaps.isEmpty()) throw new ResourceNotFoundException(notFound(CodeSystem.class, owner, newStringType(id), conceptMapVersion));
return conceptMapConverter.translate(conceptMaps.get(0), sourceSystem, sourceVersion, sourceCode, targetSystem, publicAccess);
}
// $translate by url
if (coding != null) {
sourceSystem = new UriType(coding.getSystem());
sourceCode = new CodeType(coding.getCode());
sourceVersion = new StringType(coding.getVersion());
}
if (!isValid(conceptMapUrl) || !isValid(sourceCode) || !isValid(sourceSystem)) {
String msg = "Could not perform ConceptMap $translate operation, the url, code and system parameters are required.";
throw new InvalidRequestException(msg);
}
validate(conceptMapUrl, sourceCode, sourceSystem);
Source conceptMap = isValid(owner) ? oclFhirUtil.getSourceByOwnerAndUrl(owner, newStringType(conceptMapUrl), conceptMapVersion, publicAccess) :
getSourceByUrl(newStringType(conceptMapUrl), conceptMapVersion, publicAccess).get(0);
return conceptMapConverter.translate(conceptMap, sourceSystem, sourceVersion, sourceCode, targetSystem, publicAccess);
}

private void validate(UriType conceptMapUrl, CodeType sourceCode, UriType sourceSystem) {
if (!isValid(conceptMapUrl))
throw new InvalidRequestException("Could not perform ConceptMap $translate operation, the url parameter is required.");
validate(sourceCode, sourceSystem);
}

private void validate(CodeType sourceCode, UriType sourceSystem) {
if (!isValid(sourceCode) || !isValid(sourceSystem)) {
String msg = "Could not perform ConceptMap $translate operation, the code and system parameters are required.";
throw new InvalidRequestException(msg);
}
}

}

0 comments on commit 54da106

Please sign in to comment.