Search in sources :

Example 11 with Endpoint

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");
}
Also used : Endpoint(org.hl7.fhir.dstu3.model.Endpoint) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Resource(org.hl7.fhir.dstu3.model.Resource) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 12 with Endpoint

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;
}
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 13 with Endpoint

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;
}
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 14 with Endpoint

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);
}
Also used : Endpoint(org.hl7.fhir.r4.model.Endpoint) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Resource(org.hl7.fhir.r4.model.Resource) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 15 with Endpoint

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);
}
Also used : Endpoint(org.hl7.fhir.r4.model.Endpoint) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Resource(org.hl7.fhir.r4.model.Resource) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Aggregations

Test (org.junit.jupiter.api.Test)36 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)21 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)18 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)16 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)15 Endpoint (org.hl7.fhir.r4.model.Endpoint)15 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 Bundle (org.hl7.fhir.r4.model.Bundle)12 Organization (org.hl7.fhir.dstu3.model.Organization)11 Resource (org.hl7.fhir.r4.model.Resource)10 Resource (org.hl7.fhir.dstu3.model.Resource)9 Operation (ca.uhn.fhir.rest.annotation.Operation)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Description (ca.uhn.fhir.model.api.annotation.Description)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 ArrayList (java.util.ArrayList)6