Search in sources :

Example 46 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireRenderer method renderDefns.

private boolean renderDefns(XhtmlNode x, Questionnaire q) throws IOException {
    XhtmlNode tbl = x.table("dict");
    boolean ext = false;
    ext = renderRootDefinition(tbl, q, new ArrayList<>()) || ext;
    for (QuestionnaireItemComponent qi : q.getItem()) {
        ext = renderDefinition(tbl, q, qi, new ArrayList<>()) || ext;
    }
    return ext;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 47 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project fhir-bridge by ehrbase.

the class ProvideQuestionnaireResponseTransactionIT method provideQuestionnaireResponseConditionalUpdate.

@Test
void provideQuestionnaireResponseConditionalUpdate() throws IOException {
    MethodOutcome outcome;
    outcome = create("QuestionnaireResponse/transactions/provide-questionnaire-response-create.json");
    IIdType id = outcome.getId();
    outcome = update("QuestionnaireResponse/transactions/provide-questionnaire-response-update.json", "QuestionnaireResponse?_id=" + id.getIdPart() + "&patient.identifier=" + PATIENT_ID);
    Assertions.assertEquals(id.getIdPart(), outcome.getId().getIdPart());
    Assertions.assertEquals(id.getVersionIdPartAsLong() + 1, outcome.getId().getVersionIdPartAsLong());
    QuestionnaireResponse questionnaireResponse = (QuestionnaireResponse) outcome.getResource();
    Assertions.assertEquals(PATIENT_ID, questionnaireResponse.getSubject().getIdentifier().getValue());
    Assertions.assertEquals(QuestionnaireResponse.QuestionnaireResponseStatus.AMENDED, questionnaireResponse.getStatus());
}
Also used : MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) IIdType(org.hl7.fhir.instance.model.api.IIdType) Test(org.junit.jupiter.api.Test)

Example 48 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project pathling by aehrc.

the class TestData method newQuestionnaire.

/**
 * Returns a FHIR Questionnaire resource for testing purposes.
 */
public static Questionnaire newQuestionnaire() {
    final Questionnaire questionnaire = new Questionnaire();
    questionnaire.setId("Questionnaire/1");
    final QuestionnaireItemComponent item = questionnaire.addItem();
    item.addEnableWhen().setAnswer(new DecimalType(TEST_VERY_SMALL_DECIMAL_SCALE_6));
    item.addInitial().setValue(new DecimalType(TEST_VERY_BIG_DECIMAL));
    // This nested item will be discarded on import, as we currently skip recursive elements.
    final QuestionnaireItemComponent nestedItem = item.addItem();
    nestedItem.addInitial().setValue(new DecimalType(TEST_SMALL_DECIMAL));
    return questionnaire;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)

Example 49 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire 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 50 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project CRD by HL7-DaVinci.

the class QuestionnaireEmbeddedCQLProcessor method findAndReplaceEmbeddedCql.

private void findAndReplaceEmbeddedCql(List<QuestionnaireItemComponent> itemComponents) {
    for (QuestionnaireItemComponent itemComponent : itemComponents) {
        if (hasEmbeddedCql(itemComponent)) {
            List<Extension> extensionList = itemComponent.getExtension();
            for (int i = 0; i < extensionList.size(); i++) {
                Extension extension = extensionList.get(i);
                if (extension.getUrl().equals("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
                    Expression expression = (Expression) extension.getValue();
                    if (expression.getLanguage().equals("text/cql")) {
                        String expressionString = expression.getExpression();
                        // regex for \"library\".statement
                        final String libraryRefRegex = "^\"[a-zA-Z0-9]+\".[a-zA-Z0-9]+$";
                        final Pattern pattern = Pattern.compile(libraryRefRegex, Pattern.MULTILINE);
                        // cql-execution library to throw error if it is invalid
                        if (!pattern.matcher(expressionString).find()) {
                            String cqlExpression = String.format(CQL_DEFINE_LINKID_PATTERN, itemComponent.getLinkId(), expressionString);
                            String elm = null;
                            try {
                                elm = CqlExecution.translateToElm(cqlExpression, this);
                            // logger.info("converted elm: " + elm);
                            } catch (Exception e) {
                                logger.error("Failed to convert inline CQL to elm. For linkId " + itemComponent.getLinkId());
                            }
                            if (elm != null) {
                                expression.setExpression(elm);
                                expression.setLanguage("application/elm+json");
                            }
                        }
                    }
                }
            }
        }
        if (itemComponent.hasItem()) {
            findAndReplaceEmbeddedCql(itemComponent.getItem());
        }
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Pattern(java.util.regex.Pattern) QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent) Expression(org.hl7.fhir.r4.model.Expression)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)18 ArrayList (java.util.ArrayList)15 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)12 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)11 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)11 File (java.io.File)10 TextFile (org.hl7.fhir.utilities.TextFile)10 Test (org.junit.jupiter.api.Test)10 FileOutputStream (java.io.FileOutputStream)9 Questionnaire (org.hl7.fhir.dstu3.model.Questionnaire)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 QuestionnaireItemComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)8 IOException (java.io.IOException)7 Bundle (org.hl7.fhir.r4.model.Bundle)7 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 FileNotFoundException (java.io.FileNotFoundException)6 Extension (org.hl7.fhir.r4.model.Extension)6