use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class CacheValueSetsProviderIT method testCacheValueSetsValueSetDNE.
@Test
public void testCacheValueSetsValueSetDNE() throws Exception {
Endpoint endpoint = uploadLocalServerEndpoint();
StringAndListParam stringAndListParam = new StringAndListParam();
stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", Arrays.asList(QualifiedParamList.singleton("dne")));
RequestDetails details = Mockito.mock(RequestDetails.class);
Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null);
validateOutcome(outcomeResource, "HTTP 404 : Resource ValueSet/" + "dne" + " is not known");
}
use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class TransformProvider method transformObservations.
@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.");
}
String replaceCode = mySdcProperties.getTransform().getReplaceCode();
// String username = mySdcProperties.getTransform().getUsername();
// String password = mySdcProperties.getTransform().getPassword();
String endpoint = mySdcProperties.getTransform().getEndpoint();
IGenericClient client = Clients.forUrl(fhirContext, endpoint);
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 && codeMappings.get(observation.getValueCodeableConcept().getCoding().get(0).getCode()) != null) {
if (replaceCode != null) {
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;
}
use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class TransformProvider method transformObservations.
@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.");
}
String replaceCode = mySdcProperties.getTransform().getReplaceCode();
// String username = mySdcProperties.getTransform().getUsername();
// String password = mySdcProperties.getTransform().getPassword();
String endpoint = mySdcProperties.getTransform().getEndpoint();
IGenericClient client = Clients.forUrl(fhirContext, endpoint);
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 && codeMappings.get(observation.getValueCodeableConcept().getCoding().get(0).getCode()) != null) {
if (replaceCode != null) {
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;
}
use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class CacheValueSetsProviderIT method testCacheValueSetsAuthenticationErrorUsername.
@Test
public void testCacheValueSetsAuthenticationErrorUsername() throws Exception {
Endpoint endpoint = uploadLocalServerEndpoint();
StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json");
RequestDetails details = Mockito.mock(RequestDetails.class);
Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, "username", null);
String detailMessage = "User name was provided, but not a password.";
validateOutcome(outcomeResource, detailMessage);
}
use of org.hl7.fhir.r4.model.Endpoint in project cqf-ruler by DBCG.
the class CacheValueSetsProviderIT method testCacheValueSetsEndpointDNE.
@Test
public void testCacheValueSetsEndpointDNE() throws Exception {
Endpoint endpoint = new Endpoint();
endpoint.setId(new IdType("localhost"));
StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json");
RequestDetails details = Mockito.mock(RequestDetails.class);
Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null);
String detailMessage = "Could not find Endpoint/" + endpoint.getIdElement().getIdPart();
validateOutcome(outcomeResource, detailMessage);
}
Aggregations