Search in sources :

Example 46 with QuestionnaireItemComponent

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

the class QuestionnaireRenderer method renderOptions.

private void renderOptions(List<QuestionnaireItemComponent> items, XhtmlNode x) {
    for (QuestionnaireItemComponent i : items) {
        renderItemOptions(x, i);
        renderOptions(i.getItem(), x);
    }
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)

Example 47 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent 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 48 with QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent 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 QuestionnaireItemComponent

use of org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent 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)

Example 50 with QuestionnaireItemComponent

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

the class QuestionnaireValueSetProcessor method findAndReplaceValueSetReferences.

/**
 * Recursively visits every questionnaire item and replaces every `answerValueSet` that isn't a local
 * hash (#) reference into a local reference. This fills the valueSetMap with the loaded valuesets.
 *
 * @param itemComponents The item components to visit.
 * @param valueSetMap A mapping of ValueSet urls to loaded valuesets that should be filled as references are found.
 * @param fileStore The file store that is used to load valuesets from.
 * @param baseUrl The base url of the server from the request. Used to identify local valuesets.
 */
private void findAndReplaceValueSetReferences(List<QuestionnaireItemComponent> itemComponents, Map<String, ValueSet> valueSetMap, FileStore fileStore, String baseUrl) {
    for (QuestionnaireItemComponent itemComponent : itemComponents) {
        // If there is an answerValueSet field we need to do some work on this item
        if (itemComponent.hasAnswerValueSet()) {
            // Only look for a valueset to embed if it does not appear to be a hash reference
            if (!itemComponent.getAnswerValueSet().startsWith("#")) {
                logger.info("answerValueSet found with url - " + itemComponent.getAnswerValueSet());
                String valueSetId = findAndLoadValueSet(itemComponent.getAnswerValueSet(), valueSetMap, fileStore, baseUrl);
                if (valueSetId != null) {
                    itemComponent.getAnswerValueSet();
                    itemComponent.setAnswerValueSet("#" + valueSetId);
                    logger.info("answerValueSet replaced with  - " + itemComponent.getAnswerValueSet());
                } else {
                    logger.warn("Referenced ValueSet: " + itemComponent.getAnswerValueSet() + " was not found.");
                }
            }
        }
        // Recurse down into child items.
        if (itemComponent.hasItem()) {
            findAndReplaceValueSetReferences(itemComponent.getItem(), valueSetMap, fileStore, baseUrl);
        }
    }
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)

Aggregations

ArrayList (java.util.ArrayList)32 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)16 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)15 QuestionnaireItemComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)11 Element (org.hl7.fhir.r5.elementmodel.Element)9 NodeStack (org.hl7.fhir.validation.instance.utils.NodeStack)9 QuestionnaireItemComponent (org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent)7 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)7 QuestionnaireResponse (org.hl7.fhir.r4b.model.QuestionnaireResponse)7 QuestionnaireItemAnswerOptionComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemAnswerOptionComponent)7 QuestionnaireResponse (org.hl7.fhir.r5.model.QuestionnaireResponse)7 QuestionnaireItemComponent (org.hl7.fhir.dstu2016may.model.Questionnaire.QuestionnaireItemComponent)6 ValueSet (org.hl7.fhir.r4b.model.ValueSet)6 ValueSet (org.hl7.fhir.r5.model.ValueSet)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)6 QuestionnaireResponse (org.hl7.fhir.dstu2016may.model.QuestionnaireResponse)5 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5