Search in sources :

Example 1 with FhirBundleProcessor

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor 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 FhirBundleProcessor

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor in project CRD by HL7-DaVinci.

the class OrderSelectService method createCqlExecutionContexts.

@Override
public List<CoverageRequirementRuleResult> createCqlExecutionContexts(OrderSelectRequest orderSelectRequest, FileStore fileStore, String baseUrl) {
    List<String> selections = Arrays.asList(orderSelectRequest.getContext().getSelections());
    FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl, selections);
    CrdPrefetch prefetch = orderSelectRequest.getPrefetch();
    fhirBundleProcessor.processOrderSelectMedicationStatements(prefetch.getMedicationRequestBundle(), prefetch.getMedicationStatementBundle());
    List<CoverageRequirementRuleResult> results = fhirBundleProcessor.getResults();
    if (results.isEmpty()) {
        throw RequestIncompleteException.NoSupportedBundlesFound();
    }
    return results;
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)

Example 3 with FhirBundleProcessor

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor 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)

Example 4 with FhirBundleProcessor

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor in project CRD by HL7-DaVinci.

the class OrderSignService method createCqlExecutionContexts.

@Override
public List<CoverageRequirementRuleResult> createCqlExecutionContexts(OrderSignRequest orderSignRequest, FileStore fileStore, String baseUrl) {
    FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl);
    CrdPrefetch prefetch = orderSignRequest.getPrefetch();
    fhirBundleProcessor.processDeviceRequests(prefetch.getDeviceRequestBundle());
    fhirBundleProcessor.processMedicationRequests(prefetch.getMedicationRequestBundle());
    fhirBundleProcessor.processServiceRequests(prefetch.getServiceRequestBundle());
    fhirBundleProcessor.processMedicationDispenses(prefetch.getMedicationDispenseBundle());
    List<CoverageRequirementRuleResult> results = fhirBundleProcessor.getResults();
    if (results.isEmpty()) {
        throw RequestIncompleteException.NoSupportedBundlesFound();
    }
    return results;
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)

Example 5 with FhirBundleProcessor

use of org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor in project CRD by HL7-DaVinci.

the class QuestionnairePackageOperation method createTopicList.

private List<String> createTopicList(FhirBundleProcessor fhirBundleProcessor) {
    List<String> topics = new ArrayList<>();
    List<CoverageRequirementRuleResult> results = fhirBundleProcessor.getResults();
    for (CoverageRequirementRuleResult result : results) {
        // add topic to the list if not already contained
        if (!topics.contains(result.getTopic())) {
            topics.add(result.getTopic());
        }
    }
    return topics;
}
Also used : ArrayList(java.util.ArrayList) CoverageRequirementRuleResult(org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)

Aggregations

CoverageRequirementRuleResult (org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult)5 ArrayList (java.util.ArrayList)3 RequestIncompleteException (org.hl7.davinci.RequestIncompleteException)2 CqlRule (org.hl7.davinci.endpoint.cql.CqlRule)2 RuleMapping (org.hl7.davinci.endpoint.database.RuleMapping)2 CoverageRequirementRuleCriteria (org.hl7.davinci.endpoint.rules.CoverageRequirementRuleCriteria)2 CrdPrefetch (org.hl7.davinci.r4.crdhook.CrdPrefetch)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 DataFormatException (ca.uhn.fhir.parser.DataFormatException)1 IParser (ca.uhn.fhir.parser.IParser)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FhirBundleProcessor (org.hl7.davinci.endpoint.cdshooks.services.crd.r4.FhirBundleProcessor)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 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 org.hl7.fhir.r4.model (org.hl7.fhir.r4.model)1 Bundle (org.hl7.fhir.r4.model.Bundle)1