Search in sources :

Example 51 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class CodeSystemUpdateProvider method updateCodeSystems.

/**
 * Update existing {@link CodeSystem CodeSystems} with the codes in all
 * {@link ValueSet ValueSet} resources.
 * System level CodeSystem update operation
 *
 * @return FHIR {@link OperationOutcome OperationOutcome} detailing the success
 *         or failure of the
 *         operation
 */
@Description(shortDefinition = "$updateCodeSystems", value = "Update existing CodeSystems with the codes in all ValueSet resources. System level CodeSystem update operation", example = "$updateCodeSystems")
@Operation(name = "$updateCodeSystems", idempotent = true)
public OperationOutcome updateCodeSystems() {
    IBundleProvider valuesets = this.myValueSetDaoDSTU3.search(SearchParameterMap.newSynchronous());
    List<ValueSet> valueSets = valuesets.getAllResources().stream().map(x -> (ValueSet) x).collect(Collectors.toList());
    OperationOutcome outcome = this.performCodeSystemUpdate(valueSets);
    OperationOutcome response = new OperationOutcome();
    if (outcome.hasIssue()) {
        for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue()) {
            response.addIssue(issue);
        }
    }
    return response;
}
Also used : IIdType(org.hl7.fhir.instance.model.api.IIdType) IdParam(ca.uhn.fhir.rest.annotation.IdParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Description(ca.uhn.fhir.model.api.annotation.Description) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Operation(ca.uhn.fhir.rest.annotation.Operation) Enumerations(org.hl7.fhir.dstu3.model.Enumerations) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) Ids(org.opencds.cqf.ruler.utility.Ids) ArrayList(java.util.ArrayList) OperationProvider(org.opencds.cqf.ruler.api.OperationProvider) HashSet(java.util.HashSet) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) Map(java.util.Map) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) SearchParameterMap(ca.uhn.fhir.jpa.searchparam.SearchParameterMap) Set(java.util.Set) UriParam(ca.uhn.fhir.rest.param.UriParam) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) IFhirResourceDaoCodeSystem(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem) Collections(java.util.Collections) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IFhirResourceDaoValueSet(ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoValueSet) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 52 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class CacheValueSetsProvider method cacheValuesets.

/**
 * Using basic authentication this {@link Operation Operation} will update
 * any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
 * provided.
 * Any Valuesets that require expansion will be expanded.
 *
 * @param details    the {@link RequestDetails RequestDetails}
 * @param endpointId the {@link Endpoint Endpoint} id
 * @param valuesets  the {@link StringAndListParam list} of {@link ValueSet
 *                   Valueset} ids
 * @param userName   the userName
 * @param password   the password
 * @return the {@link OperationOutcome OperationOutcome} or the resulting
 *         {@link Bundle Bundle}
 */
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
    Endpoint endpoint = null;
    try {
        endpoint = this.endpointDao.read(endpointId);
        if (endpoint == null) {
            return createErrorOutcome("Could not find Endpoint/" + endpointId);
        }
    } catch (Exception e) {
        return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
    }
    IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
    if (userName != null || password != null) {
        if (userName == null) {
            return createErrorOutcome("Password was provided, but not a user name.");
        } else if (password == null) {
            return createErrorOutcome("User name was provided, but not a password.");
        }
        BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
        client.registerInterceptor(basicAuth);
    // TODO - more advanced security like bearer tokens, etc...
    }
    try {
        Bundle bundleToPost = new Bundle();
        for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
            for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
                bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
            }
        }
        return (Resource) systemDao.transaction(details, bundleToPost);
    } catch (Exception e) {
        return createErrorOutcome(e.getMessage());
    }
}
Also used : Endpoint(org.hl7.fhir.r4.model.Endpoint) BasicAuthInterceptor(ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 53 with Operation

use of org.hl7.fhir.utilities.graphql.Operation in project cqf-ruler by DBCG.

the class ExtractProvider method extractObservationFromQuestionnaireResponse.

@Operation(name = "$extract", idempotent = false, type = QuestionnaireResponse.class)
public Bundle extractObservationFromQuestionnaireResponse(@OperationParam(name = "questionnaireResponse") QuestionnaireResponse questionnaireResponse) {
    if (questionnaireResponse == null) {
        throw new IllegalArgumentException("Unable to perform operation $extract.  The QuestionnaireResponse was null");
    }
    Bundle observationsFromQuestionnaireResponse = createObservationBundle(questionnaireResponse);
    sendObservationBundle(observationsFromQuestionnaireResponse);
    return observationsFromQuestionnaireResponse;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 54 with Operation

use of org.hl7.fhir.utilities.graphql.Operation 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 55 with Operation

use of org.hl7.fhir.utilities.graphql.Operation 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)

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)72 Test (org.junit.jupiter.api.Test)69 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)63 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)63 StringType (org.hl7.fhir.r4.model.StringType)62 ArrayList (java.util.ArrayList)60 IOException (java.io.IOException)54 List (java.util.List)54 Bundle (org.hl7.fhir.r4.model.Bundle)53 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)52 Collectors (java.util.stream.Collectors)51 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)50 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)48 FileOutputStream (java.io.FileOutputStream)47 Collections (java.util.Collections)47 Optional (java.util.Optional)47 File (java.io.File)46 Arrays (java.util.Arrays)46 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)45 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)45