-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from DBCG/conceptMap
Concept map
- Loading branch information
Showing
8 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
dstu3/src/main/java/org/opencds/cqf/dstu3/providers/ObservationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.opencds.cqf.dstu3.providers; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.rest.annotation.Operation; | ||
import ca.uhn.fhir.rest.annotation.OperationParam; | ||
import ca.uhn.fhir.rest.client.api.IGenericClient; | ||
import ca.uhn.fhir.util.BundleUtil; | ||
import org.hl7.fhir.dstu3.model.Bundle; | ||
import org.hl7.fhir.dstu3.model.Coding; | ||
import org.hl7.fhir.dstu3.model.ConceptMap; | ||
import org.hl7.fhir.dstu3.model.Observation; | ||
import org.opencds.cqf.common.config.HapiProperties; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.opencds.cqf.common.helpers.ClientHelper.getClient; | ||
|
||
public class ObservationProvider { | ||
|
||
private FhirContext fhirContext; | ||
|
||
public ObservationProvider(FhirContext fhirContext){ | ||
this.fhirContext = fhirContext; | ||
} | ||
|
||
@Operation(name = "$transform", idempotent = false, type = Observation.class) | ||
public Bundle transformObservations( | ||
@OperationParam(name = "observations") Bundle observationsBundle, | ||
@OperationParam(name = "conceptMapURL") String conceptMapURL | ||
) { | ||
if(null == observationsBundle) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. No Observation bundle passed in."); | ||
} | ||
if(null == conceptMapURL) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. No concept map url specified."); | ||
} | ||
IGenericClient client = getClient(fhirContext, conceptMapURL, HapiProperties.getObservationTransformUsername(), HapiProperties.getObservationTransformPassword() ); | ||
ConceptMap transformConceptMap = client.read().resource(ConceptMap.class).withUrl (conceptMapURL).execute(); | ||
if(null == transformConceptMap) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. Unable to get concept map."); | ||
} | ||
List<Observation> observations = BundleUtil.toListOfResources(fhirContext, observationsBundle).stream() | ||
.filter(resource -> resource instanceof Observation) | ||
.map(Observation.class::cast) | ||
.collect(Collectors.toList()); | ||
/** | ||
* TODO - There must be a more efficient way to loop through this, but so far I have not come up with it. | ||
*/ | ||
transformConceptMap.getGroup().forEach(group -> { | ||
HashMap<String, ConceptMap.TargetElementComponent> codeMappings = new HashMap<>(); | ||
String targetSystem = group.getTarget(); | ||
group.getElement().forEach(codeElement -> { | ||
codeMappings.put(codeElement.getCode(), codeElement.getTarget().get(0)); | ||
}); | ||
observations.forEach(observation -> { | ||
if(observation.getValue().fhirType().equalsIgnoreCase("codeableconcept")){ | ||
String obsValueCode = observation.getValueCodeableConcept().getCoding().get(0).getCode(); | ||
if(obsValueCode != null) { | ||
if (codeMappings.get(observation.getValueCodeableConcept().getCoding().get(0).getCode()) != null) { | ||
if (HapiProperties.getObservationTransformReplaceCode()) { | ||
observation.getValueCodeableConcept().getCoding().get(0).setCode(codeMappings.get(obsValueCode).getCode()); | ||
observation.getValueCodeableConcept().getCoding().get(0).setDisplay(codeMappings.get(obsValueCode).getDisplay()); | ||
observation.getValueCodeableConcept().getCoding().get(0).setSystem(targetSystem); | ||
} else { | ||
Coding newCoding = new Coding(); | ||
newCoding.setSystem(targetSystem); | ||
newCoding.setCode(codeMappings.get(obsValueCode).getCode()); | ||
newCoding.setDisplay(codeMappings.get(obsValueCode).getDisplay()); | ||
observation.getValueCodeableConcept().getCoding().add(newCoding); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
return observationsBundle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
r4/src/main/java/org/opencds/cqf/r4/providers/ObservationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.opencds.cqf.r4.providers; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.rest.annotation.Operation; | ||
import ca.uhn.fhir.rest.annotation.OperationParam; | ||
import ca.uhn.fhir.rest.client.api.IGenericClient; | ||
import ca.uhn.fhir.util.BundleUtil; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.Coding; | ||
import org.hl7.fhir.r4.model.ConceptMap; | ||
import org.hl7.fhir.r4.model.Observation; | ||
import org.opencds.cqf.common.config.HapiProperties; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.opencds.cqf.common.helpers.ClientHelper.getClient; | ||
|
||
public class ObservationProvider { | ||
|
||
private FhirContext fhirContext; | ||
|
||
public ObservationProvider(FhirContext fhirContext){ | ||
this.fhirContext = fhirContext; | ||
} | ||
|
||
@Operation(name = "$transform", idempotent = false, type = Observation.class) | ||
public Bundle transformObservations( | ||
@OperationParam(name = "observations") Bundle observationsBundle, | ||
@OperationParam(name = "conceptMapURL") String conceptMapURL | ||
) { | ||
if(null == observationsBundle) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. No Observation bundle passed in."); | ||
} | ||
if(null == conceptMapURL) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. No concept map url specified."); | ||
} | ||
IGenericClient client = getClient(fhirContext, conceptMapURL, HapiProperties.getObservationTransformUsername(), HapiProperties.getObservationTransformPassword() ); | ||
ConceptMap transformConceptMap = client.read().resource(ConceptMap.class).withUrl (conceptMapURL).execute(); | ||
if(null == transformConceptMap) { | ||
throw new IllegalArgumentException("Unable to perform operation Observation$transform. Unable to get concept map."); | ||
} | ||
List<Observation> observations = BundleUtil.toListOfResources(fhirContext, observationsBundle).stream() | ||
.filter(resource -> resource instanceof Observation) | ||
.map(Observation.class::cast) | ||
.collect(Collectors.toList()); | ||
/** | ||
* TODO - There must be a more efficient way to loop through this, but so far I have not come up with it. | ||
*/ | ||
transformConceptMap.getGroup().forEach(group -> { | ||
HashMap<String, ConceptMap.TargetElementComponent> codeMappings = new HashMap<>(); | ||
String targetSystem = group.getTarget(); | ||
group.getElement().forEach(codeElement -> { | ||
codeMappings.put(codeElement.getCode(), codeElement.getTarget().get(0)); | ||
}); | ||
observations.forEach(observation -> { | ||
if(observation.getValue().fhirType().equalsIgnoreCase("codeableconcept")){ | ||
String obsValueCode = observation.getValueCodeableConcept().getCoding().get(0).getCode(); | ||
if(obsValueCode != null) { | ||
if (codeMappings.get(observation.getValueCodeableConcept().getCoding().get(0).getCode()) != null) { | ||
if (HapiProperties.getObservationTransformReplaceCode()) { | ||
observation.getValueCodeableConcept().getCoding().get(0).setCode(codeMappings.get(obsValueCode).getCode()); | ||
observation.getValueCodeableConcept().getCoding().get(0).setDisplay(codeMappings.get(obsValueCode).getDisplay()); | ||
observation.getValueCodeableConcept().getCoding().get(0).setSystem(targetSystem); | ||
} else { | ||
Coding newCoding = new Coding(); | ||
newCoding.setSystem(targetSystem); | ||
newCoding.setCode(codeMappings.get(obsValueCode).getCode()); | ||
newCoding.setDisplay(codeMappings.get(obsValueCode).getDisplay()); | ||
observation.getValueCodeableConcept().getCoding().add(newCoding); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
return observationsBundle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters