Search in sources :

Example 1 with CoverageRequirementRuleCriteria

use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria in project CRD by HL7-DaVinci.

the class FhirBundleProcessor method createCriteriaList.

private List<CoverageRequirementRuleCriteria> createCriteriaList(CodeableConcept codeableConcept, List<Reference> insurance, List<Organization> payorList) {
    try {
        List<Coding> codings = codeableConcept.getCoding();
        if (codings.size() > 0) {
            logger.info("r4/FhirBundleProcessor::createCriteriaList: code[0]: " + codings.get(0).getCode() + " - " + codings.get(0).getSystem());
        } else {
            logger.info("r4/FhirBundleProcessor::createCriteriaList: empty codes list!");
        }
        List<Organization> payors = new ArrayList<>();
        if (insurance != null) {
            List<Coverage> coverages = insurance.stream().map(reference -> (Coverage) reference.getResource()).collect(Collectors.toList());
            // Remove null coverages that may not have resolved.
            coverages = coverages.stream().filter(coverage -> coverage != null).collect(Collectors.toList());
            payors = Utilities.getPayors(coverages);
        } else if (payorList != null) {
            payors = payorList;
        }
        if (payors.size() > 0) {
            logger.info("r4/FhirBundleProcessor::createCriteriaList: payer[0]: " + payors.get(0).getName());
        } else {
            // default to CMS if no payer was provided
            logger.info("r4/FhirBundleProcessor::createCriteriaList: empty payers list, working around by adding CMS!");
            Organization org = new Organization().setName("Centers for Medicare and Medicaid Services");
            // how to get ID
            org.setId("75f39025-65db-43c8-9127-693cdf75e712");
            payors.add(org);
        // remove the exception to use CMS if no payer is provided
        // JIRA ticket https://jira.mitre.org/browse/DMEERX-894
        // throw new RequestIncompleteException("No Payer found in coverage resource, cannot find documentation.");
        }
        List<CoverageRequirementRuleCriteria> criteriaList = CoverageRequirementRuleCriteria.createQueriesFromR4(codings, payors);
        return criteriaList;
    } catch (RequestIncompleteException e) {
        // rethrow incomplete request exceptions
        throw e;
    } catch (Exception e) {
        // catch all remaining exceptions
        System.out.println(e);
        throw new RequestIncompleteException("Unable to parse list of codes, codesystems, and payors from a device request.");
    }
}
Also used : Logger(org.slf4j.Logger) CoverageRequirementRuleCriteria(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) LoggerFactory(org.slf4j.LoggerFactory) RuleMapping(org.hl7.davinci.endpoint.database.RuleMapping) CqlExecutionContextBuilder(org.hl7.davinci.endpoint.cql.r4.CqlExecutionContextBuilder) FileStore(org.hl7.davinci.endpoint.files.FileStore) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult) CqlRule(org.hl7.davinci.endpoint.cql.CqlRule) RequestIncompleteException(org.hl7.davinci.RequestIncompleteException) Utilities(org.hl7.davinci.r4.Utilities) CoverageRequirementRuleCriteria(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria) RequestIncompleteException(org.hl7.davinci.RequestIncompleteException) ArrayList(java.util.ArrayList) RequestIncompleteException(org.hl7.davinci.RequestIncompleteException)

Example 2 with CoverageRequirementRuleCriteria

use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria in project CRD by HL7-DaVinci.

the class RuleFinder method findRules.

/**
 * Find and retern the relevant coverage rules in the database.
 * @param criteria The search criteria object
 * @return List of matching RuleMapping entries
 */
public List<RuleMapping> findRules(CoverageRequirementRuleCriteria criteria) {
    logger.info("RuleFinder::findRules(" + criteria.getQueryString() + ")");
    List<RuleMapping> ruleList = new ArrayList<>();
    if (ruleMappingRepository == null) {
        logger.warn("RuleFinder::findRules: the ruleMappingRepository is null");
        return ruleList;
    }
    for (RuleMapping rule : ruleMappingRepository.findRules(criteria)) {
        ruleList.add(rule);
    }
    if (ruleList.size() == 0) {
        logger.info("RuleFinder::findRules() returned no results for query: " + criteria.toString());
    }
    return ruleList;
}
Also used : ArrayList(java.util.ArrayList) RuleMapping(org.hl7.davinci.endpoint.database.RuleMapping)

Example 3 with CoverageRequirementRuleCriteria

use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria in project CRD by HL7-DaVinci.

the class FhirBundleProcessor method buildExecutionContexts.

private void buildExecutionContexts(List<CoverageRequirementRuleCriteria> criteriaList, HashMap<String, Resource> cqlParams) {
    for (CoverageRequirementRuleCriteria criteria : criteriaList) {
        logger.info("FhirBundleProcessor::buildExecutionContexts() criteria: " + criteria.toString());
        List<RuleMapping> rules = fileStore.findRules(criteria);
        for (RuleMapping rule : rules) {
            CoverageRequirementRuleResult result = new CoverageRequirementRuleResult();
            result.setCriteria(criteria).setTopic(rule.getTopic());
            try {
                logger.info("FhirBundleProcessor::buildExecutionContexts() found rule topic: " + rule.getTopic());
                // get the CqlRule
                CqlRule cqlRule = fileStore.getCqlRule(rule.getTopic(), rule.getFhirVersion());
                result.setContext(CqlExecutionContextBuilder.getExecutionContext(cqlRule, cqlParams, baseUrl));
                results.add(result);
            } catch (Exception e) {
                logger.info("r4/FhirBundleProcessor::buildExecutionContexts: failed processing cql bundle: " + e.getMessage());
            }
        }
    }
}
Also used : CoverageRequirementRuleCriteria(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria) CqlRule(org.hl7.davinci.endpoint.cql.CqlRule) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult) RuleMapping(org.hl7.davinci.endpoint.database.RuleMapping) RequestIncompleteException(org.hl7.davinci.RequestIncompleteException)

Aggregations

RuleMapping (org.hl7.davinci.endpoint.database.RuleMapping)3 ArrayList (java.util.ArrayList)2 RequestIncompleteException (org.hl7.davinci.RequestIncompleteException)2 CqlRule (org.hl7.davinci.endpoint.cql.CqlRule)2 CoverageRequirementRuleCriteria (org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria)2 CoverageRequirementRuleResult (org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 CqlExecutionContextBuilder (org.hl7.davinci.endpoint.cql.r4.CqlExecutionContextBuilder)1 FileStore (org.hl7.davinci.endpoint.files.FileStore)1 Utilities (org.hl7.davinci.r4.Utilities)1 org.hl7.fhir.r4.model (org.hl7.fhir.r4.model)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1