use of org.hl7.fhir.r4b.model.Observation in project cqf-ruler by DBCG.
the class SubmitDataProviderIT method testSubmitData.
@Test
public void testSubmitData() {
// Create a MR and a resource
MeasureReport mr = newResource(MeasureReport.class, "test-mr");
Observation obs = newResource(Observation.class, "test-obs");
// Submit it
mySubmitDataProvider.submitData(new SystemRequestDetails(), new IdType("Measure", "test-m"), mr, Lists.newArrayList(obs));
// Check if they made it to the db
Observation savedObs = read(obs.getIdElement());
assertNotNull(savedObs);
MeasureReport savedMr = read(mr.getIdElement());
assertNotNull(savedMr);
}
use of org.hl7.fhir.r4b.model.Observation in project cqf-ruler by DBCG.
the class ExtractProvider method sendObservationBundle.
private Bundle sendObservationBundle(Bundle observationsBundle) throws IllegalArgumentException {
String url = mySdcProperties.getExtract().getEndpoint();
if (null == url || url.length() < 1) {
throw new IllegalArgumentException("Unable to transmit observation bundle. No observation.endpoint defined in sdc properties.");
}
String user = mySdcProperties.getExtract().getUsername();
String password = mySdcProperties.getExtract().getPassword();
IGenericClient client = Clients.forUrl(myFhirContext, url);
Clients.registerBasicAuth(client, user, password);
Bundle outcomeBundle = client.transaction().withBundle(observationsBundle).execute();
return outcomeBundle;
}
use of org.hl7.fhir.r4b.model.Observation 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.r4b.model.Observation 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.r4b.model.Observation in project cqf-ruler by DBCG.
the class ExtractProviderIT method testExtract.
@Test
public void testExtract() throws IOException, URISyntaxException {
String examplePatient = "example_patient.json";
String exampleQuestionnaire = "questionnaire_1559.json";
String exampleQR = "questionnaire_response_1558.json";
loadResource(examplePatient);
loadResource(exampleQuestionnaire);
QuestionnaireResponse questionnaireResponse = (QuestionnaireResponse) loadResource(exampleQR);
Parameters params = new Parameters();
params.addParameter().setName("questionnaireResponse").setResource(questionnaireResponse);
Bundle actual = getClient().operation().onType(QuestionnaireResponse.class).named("$extract").withParameters(params).returnResourceType(Bundle.class).execute();
assertNotNull(actual);
// Expecting one observation per item
assertEquals(5, actual.getEntry().size());
// Ensure the Observations were saved to the local server
for (Bundle.BundleEntryComponent bec : actual.getEntry()) {
assertEquals("201 Created", bec.getResponse().getStatus());
}
}
Aggregations