Search in sources :

Example 21 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class R4FileSystemFhirTerminologyProviderTest method inOperationReturnsTrueWithCodeOnly.

@Test
public void inOperationReturnsTrueWithCodeOnly() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId(setId);
    Code code = new Code();
    code.setCode(TEST_CODE);
    boolean result = provider.in(code, info);
    assertTrue(result);
}
Also used : ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 22 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class R4FileSystemFhirTerminologyProviderTest method inOperationReturnsFalseWithBadCodeSystem.

@Test
public void inOperationReturnsFalseWithBadCodeSystem() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId(setId);
    Code code = new Code();
    code.setSystem("bad system");
    code.setCode(TEST_CODE);
    code.setDisplay(TEST_DISPLAY);
    boolean result = provider.in(code, info);
    assertFalse(result);
}
Also used : ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 23 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project CRD by HL7-DaVinci.

the class OrderSignService method executeCqlAndGetRelevantResults.

protected CqlResultsForCard executeCqlAndGetRelevantResults(Context context, String topic) {
    CqlResultsForCard results = new CqlResultsForCard();
    results.setRuleApplies((Boolean) evaluateStatement("RULE_APPLIES", context));
    if (!results.ruleApplies()) {
        logger.warn("rule does not apply");
        return results;
    }
    CoverageRequirements coverageRequirements = new CoverageRequirements();
    coverageRequirements.setApplies(true);
    String humanReadableTopic = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(topic), ' ');
    coverageRequirements.setInfoLink(evaluateStatement("RESULT_InfoLink", context).toString()).setPriorAuthRequired((Boolean) evaluateStatement("PRIORAUTH_REQUIRED", context)).setDocumentationRequired((Boolean) evaluateStatement("DOCUMENTATION_REQUIRED", context));
    // if prior auth, supercede the documentation required
    if (coverageRequirements.isPriorAuthRequired()) {
        logger.info("Prior Auth Required");
        coverageRequirements.setSummary(humanReadableTopic + ": Prior Authorization required.").setDetails("Prior Authorization required, follow the attached link for information.");
        // check if prior auth is automatically approved
        if (evaluateStatement("APPROVE_PRIORAUTH", context) != null) {
            coverageRequirements.setPriorAuthApproved((Boolean) evaluateStatement("APPROVE_PRIORAUTH", context));
            if (coverageRequirements.isPriorAuthApproved()) {
                coverageRequirements.generatePriorAuthId();
                logger.info("Prior Auth Approved: " + coverageRequirements.getPriorAuthId());
                coverageRequirements.setSummary(humanReadableTopic + ": Prior Authorization approved.").setDetails("Prior Authorization approved, ID is " + coverageRequirements.getPriorAuthId());
            }
        }
    } else if (coverageRequirements.isDocumentationRequired()) {
        logger.info("Documentation Required");
        coverageRequirements.setSummary(humanReadableTopic + ": Documentation Required.").setDetails("Documentation Required, please complete form via Smart App link.");
    } else {
        logger.info("No Prior Auth or Documentation Required");
        coverageRequirements.setSummary(humanReadableTopic + ": No Prior Authorization required.").setDetails("No Prior Authorization required for " + humanReadableTopic + ".");
    }
    if (evaluateStatement("RESULT_requestId", context) != null) {
        results.setRequest((IBaseResource) evaluateStatement("RESULT_requestId", context));
        coverageRequirements.setRequestId(JSONObject.escape(fhirComponents.getFhirContext().newJsonParser().encodeResourceToString(results.getRequest())));
    }
    // setup the alternative therapy information
    AlternativeTherapy alternativeTherapy = new AlternativeTherapy();
    alternativeTherapy.setApplies(false);
    if (evaluateStatement("RESULT_dispense", context) != null) {
        results.setRequest((IBaseResource) evaluateStatement("RESULT_dispense", context));
        coverageRequirements.setRequestId(JSONObject.escape(fhirComponents.getFhirContext().newJsonParser().encodeResourceToString(results.getRequest())));
        // only display the dispense form for MedicationDispense request
        try {
            if (evaluateStatement("RESULT_QuestionnaireDispenseUri", context) != null) {
                coverageRequirements.setQuestionnaireDispenseUri(evaluateStatement("RESULT_QuestionnaireDispenseUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No Dispense questionnaire defined");
        }
    } else // not a MedicationDispense
    {
        if (evaluateStatement("RESULT_QuestionnaireOrderUri", context) != null) {
            coverageRequirements.setQuestionnaireOrderUri(evaluateStatement("RESULT_QuestionnaireOrderUri", context).toString());
        }
        try {
            if (evaluateStatement("RESULT_QuestionnaireFaceToFaceUri", context) != null) {
                coverageRequirements.setQuestionnaireFaceToFaceUri(evaluateStatement("RESULT_QuestionnaireFaceToFaceUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No face to face questionnaire defined");
        }
        try {
            if (evaluateStatement("RESULT_QuestionnaireLabUri", context) != null) {
                coverageRequirements.setQuestionnaireLabUri(evaluateStatement("RESULT_QuestionnaireLabUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No Lab questionnaire defined");
        }
        try {
            if (evaluateStatement("RESULT_QuestionnaireProgressNoteUri", context) != null) {
                coverageRequirements.setQuestionnaireProgressNoteUri(evaluateStatement("RESULT_QuestionnaireProgressNoteUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No Progress note questionnaire defined");
        }
        try {
            if (evaluateStatement("RESULT_QuestionnairePlanOfCareUri", context) != null) {
                coverageRequirements.setQuestionnairePlanOfCareUri(evaluateStatement("RESULT_QuestionnairePlanOfCareUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No plan of care questionnaire defined");
        }
        try {
            if (evaluateStatement("RESULT_QuestionnairePARequestUri", context) != null) {
                coverageRequirements.setQuestionnairePARequestUri(evaluateStatement("RESULT_QuestionnairePARequestUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No PA Request questionnaire defined");
        }
        try {
            if (evaluateStatement("RESULT_QuestionnaireAdditionalUri", context) != null) {
                coverageRequirements.setQuestionnaireAdditionalUri(evaluateStatement("RESULT_QuestionnaireAdditionalUri", context).toString());
            }
        } catch (Exception e) {
            logger.info("-- No additional questionnaire defined");
        }
        // process the alternative therapies
        try {
            if (evaluateStatement("ALTERNATIVE_THERAPY", context) != null) {
                Object ac = evaluateStatement("ALTERNATIVE_THERAPY", context);
                Code code = (Code) ac;
                logger.info("alternate therapy suggested: " + code.getDisplay() + " (" + code.getCode() + " / " + ShortNameMaps.CODE_SYSTEM_SHORT_NAME_TO_FULL_NAME.inverse().get(code.getSystem()).toUpperCase() + ")");
                alternativeTherapy.setApplies(true).setCode(code.getCode()).setSystem(code.getSystem()).setDisplay(code.getDisplay());
            }
        } catch (Exception e) {
            logger.info("-- No alternative therapy defined");
        }
    }
    results.setCoverageRequirements(coverageRequirements);
    results.setAlternativeTherapy(alternativeTherapy);
    // add empty drug interaction
    DrugInteraction drugInteraction = new DrugInteraction();
    drugInteraction.setApplies(false);
    results.setDrugInteraction(drugInteraction);
    return results;
}
Also used : CqlResultsForCard(org.hl7.davinci.endpoint.components.CardBuilder.CqlResultsForCard) AlternativeTherapy(org.cdshooks.AlternativeTherapy) DrugInteraction(org.cdshooks.DrugInteraction) CoverageRequirements(org.cdshooks.CoverageRequirements) JSONObject(org.json.simple.JSONObject) Code(org.opencds.cqf.cql.engine.runtime.Code) RequestIncompleteException(org.hl7.davinci.RequestIncompleteException)

Example 24 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProvider method expand.

/**
 * This is a small patch to the OSS implementation to use a GET request vs. a
 * POST request with { "resource": "Parameters" } as the body in order to bypass
 * IBM FHIR failing to parse the empty parameters object.
 */
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    if (resolveByUrl(valueSet) == null) {
        return Collections.emptyList();
    }
    Parameters respParam = fhirClient.operation().onInstance(new IdType("ValueSet", valueSet.getId())).named("expand").withNoParameters(Parameters.class).useHttpGet().execute();
    ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
    List<Code> codes = new ArrayList<>();
    for (ValueSet.ValueSetExpansionContainsComponent codeInfo : expanded.getExpansion().getContains()) {
        Code nextCode = new Code().withCode(codeInfo.getCode()).withSystem(codeInfo.getSystem()).withVersion(codeInfo.getVersion()).withDisplay(codeInfo.getDisplay());
        codes.add(nextCode);
    }
    return codes;
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r4.model.ValueSet) Code(org.opencds.cqf.cql.engine.runtime.Code) IdType(org.hl7.fhir.r4.model.IdType)

Example 25 with Code

use of org.opencds.cqf.cql.engine.runtime.Code in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluationTest method testPopulateSex_badCodeString.

@Test
public void testPopulateSex_badCodeString() {
    Code badCode = getMaleCode();
    badCode.setCode(null);
    Map<String, Map<String, Integer>> sdeAccumulators = getSexSDEAccumulatorsWithCode(badCode);
    assertTrue(sdeAccumulators.isEmpty());
}
Also used : Code(org.opencds.cqf.cql.engine.runtime.Code) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Code (org.opencds.cqf.cql.engine.runtime.Code)45 Test (org.junit.Test)35 ValueSetInfo (org.opencds.cqf.cql.engine.terminology.ValueSetInfo)17 Parameters (org.hl7.fhir.r4.model.Parameters)6 HashMap (java.util.HashMap)5 Metadata (org.apache.spark.sql.types.Metadata)4 ValueSet (org.hl7.fhir.r4.model.ValueSet)4 BaseSparkTest (com.ibm.cohort.cql.spark.BaseSparkTest)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 MetadataBuilder (org.apache.spark.sql.types.MetadataBuilder)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 CodeSystemInfo (org.opencds.cqf.cql.engine.terminology.CodeSystemInfo)3 DataRow (com.ibm.cohort.datarow.model.DataRow)2 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 ConfigurationException (ca.uhn.fhir.context.ConfigurationException)1 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 CodeKey (com.ibm.cohort.datarow.model.CodeKey)1 SimpleDataRow (com.ibm.cohort.datarow.model.SimpleDataRow)1