Search in sources :

Example 31 with Observation

use of org.hl7.fhir.r5.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);
}
Also used : SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Observation(org.hl7.fhir.r4.model.Observation) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) DaoIntegrationTest(org.opencds.cqf.ruler.test.DaoIntegrationTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with Observation

use of org.hl7.fhir.r5.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;
}
Also used : IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle)

Example 33 with Observation

use of org.hl7.fhir.r5.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;
}
Also used : HashMap(java.util.HashMap) Coding(org.hl7.fhir.dstu3.model.Coding) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Observation(org.hl7.fhir.dstu3.model.Observation) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 34 with Observation

use of org.hl7.fhir.r5.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;
}
Also used : HashMap(java.util.HashMap) Coding(org.hl7.fhir.r4.model.Coding) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Observation(org.hl7.fhir.r4.model.Observation) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 35 with Observation

use of org.hl7.fhir.r5.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());
    }
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 Test (org.junit.jupiter.api.Test)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Observation (org.hl7.fhir.dstu3.model.Observation)94 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 ArrayList (java.util.ArrayList)62 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)53 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)47 Coding (org.hl7.fhir.r4.model.Coding)46 Reference (org.hl7.fhir.r4.model.Reference)41 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)37 TokenParam (ca.uhn.fhir.rest.param.TokenParam)37 Date (java.util.Date)34 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32