use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult 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;
}
use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult in project CRD by HL7-DaVinci.
the class CdsService method handleRequest.
/**
* Performs generic operations for incoming requests of any type.
*
* @param request the generically typed incoming request
* @return The response from the server
*/
public CdsResponse handleRequest(@Valid @RequestBody requestTypeT request, URL applicationBaseUrl) {
// create the RequestLog
RequestLog requestLog = new RequestLog(request, new Date().getTime(), this.fhirComponents.getFhirVersion().toString(), this.id, requestService, 5);
// Parsed request
requestLog.advanceTimeline(requestService);
PrefetchHydrator prefetchHydrator = new PrefetchHydrator(this, request, this.fhirComponents);
prefetchHydrator.hydrate();
// hydrated
requestLog.advanceTimeline(requestService);
// Attempt a Query Batch Request to backfill missing attributes.
if (myConfig.isQueryBatchRequest()) {
QueryBatchRequest qbr = new QueryBatchRequest(this.fhirComponents);
this.attempQueryBatchRequest(request, qbr);
}
logger.info("***** ***** request from requestLog: " + requestLog.toString());
CdsResponse response = new CdsResponse();
Gson gson = new Gson();
final String jsonObject = gson.toJson(request.getPrefetch());
logger.info("Final populated CRDPrefetch: " + jsonObject);
// CQL Fetched
List<CoverageRequirementRuleResult> lookupResults;
try {
lookupResults = this.createCqlExecutionContexts(request, fileStore, applicationBaseUrl.toString() + "/");
requestLog.advanceTimeline(requestService);
} catch (RequestIncompleteException e) {
logger.warn("RequestIncompleteException " + request);
logger.warn(e.getMessage() + "; summary card sent to client");
response.addCard(CardBuilder.summaryCard(CardTypes.COVERAGE, e.getMessage()));
requestLog.setCardListFromCards(response.getCards());
requestLog.setResults(e.getMessage());
requestService.edit(requestLog);
return response;
}
// process the extension for the configuration
// load hook configuration with default values
Configuration hookConfiguration = new Configuration();
Extension extension = request.getExtension();
if (extension != null) {
if (extension.getConfiguration() != null) {
hookConfiguration = extension.getConfiguration();
}
}
boolean errorCardOnEmpty = !(request instanceof OrderSelectRequest);
// no error cards on empty when order-select request
boolean foundApplicableRule = false;
for (CoverageRequirementRuleResult lookupResult : lookupResults) {
requestLog.addTopic(requestService, lookupResult.getTopic());
CqlResultsForCard results = executeCqlAndGetRelevantResults(lookupResult.getContext(), lookupResult.getTopic());
CoverageRequirements coverageRequirements = results.getCoverageRequirements();
if (results.ruleApplies()) {
foundApplicableRule = true;
if (results.getCoverageRequirements().getApplies()) {
// if prior auth already approved
if (coverageRequirements.isPriorAuthApproved()) {
response.addCard(CardBuilder.priorAuthCard(results, results.getRequest(), fhirComponents, coverageRequirements.getPriorAuthId(), request.getContext().getPatientId(), lookupResult.getCriteria().getPayorId(), request.getContext().getUserId(), applicationBaseUrl.toString() + "/fhir/" + fhirComponents.getFhirVersion().toString(), fhirResourceRepository));
} else if (coverageRequirements.isDocumentationRequired() || coverageRequirements.isPriorAuthRequired()) {
if (StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireOrderUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireFaceToFaceUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireLabUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireProgressNoteUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnairePARequestUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnairePlanOfCareUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireDispenseUri()) || StringUtils.isNotEmpty(coverageRequirements.getQuestionnaireAdditionalUri())) {
List<Link> smartAppLinks = createQuestionnaireLinks(request, applicationBaseUrl, lookupResult, results);
if (coverageRequirements.isPriorAuthRequired()) {
Card card = CardBuilder.transform(CardTypes.PRIOR_AUTH, results, smartAppLinks);
card.addSuggestionsItem(CardBuilder.createSuggestionWithNote(card, results.getRequest(), fhirComponents, "Save Update To EHR", "Update original " + results.getRequest().fhirType() + " to add note", true, CoverageGuidance.ADMIN));
response.addCard(card);
} else if (coverageRequirements.isDocumentationRequired()) {
Card card = CardBuilder.transform(CardTypes.DTR_CLIN, results, smartAppLinks);
card.addSuggestionsItem(CardBuilder.createSuggestionWithNote(card, results.getRequest(), fhirComponents, "Save Update To EHR", "Update original " + results.getRequest().fhirType() + " to add note", true, CoverageGuidance.CLINICAL));
response.addCard(card);
}
// add a card for an alternative therapy if there is one
if (results.getAlternativeTherapy().getApplies() && hookConfiguration.getAlternativeTherapy()) {
try {
response.addCard(CardBuilder.alternativeTherapyCard(results.getAlternativeTherapy(), results.getRequest(), fhirComponents));
} catch (RuntimeException e) {
logger.warn("Failed to process alternative therapy: " + e.getMessage());
}
}
} else {
logger.warn("Unspecified Questionnaire URI; summary card sent to client");
response.addCard(CardBuilder.transform(CardTypes.COVERAGE, results));
}
} else {
// no prior auth or documentation required
logger.info("Add the no doc or prior auth required card");
Card card = CardBuilder.transform(CardTypes.COVERAGE, results);
card.addSuggestionsItem(CardBuilder.createSuggestionWithNote(card, results.getRequest(), fhirComponents, "Save Update To EHR", "Update original " + results.getRequest().fhirType() + " to add note", true, CoverageGuidance.COVERED));
card.setSelectionBehavior(Card.SelectionBehaviorEnum.ANY);
response.addCard(card);
}
}
// apply the DrugInteractions
if (results.getDrugInteraction().getApplies()) {
response.addCard(CardBuilder.drugInteractionCard(results.getDrugInteraction(), results.getRequest()));
}
}
}
// CQL Executed
requestLog.advanceTimeline(requestService);
if (errorCardOnEmpty) {
if (!foundApplicableRule) {
String msg = "No documentation rules found";
logger.warn(msg + "; summary card sent to client");
response.addCard(CardBuilder.summaryCard(CardTypes.COVERAGE, msg));
}
CardBuilder.errorCardIfNonePresent(CardTypes.COVERAGE, response);
}
// Ading card to requestLog
requestLog.setCardListFromCards(response.getCards());
requestService.edit(requestLog);
return response;
}
use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult 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());
}
}
}
}
use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult 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;
}
use of org.hl7.davinci.endpoint.rules.CoverageRequirementRuleResult 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;
}
Aggregations