use of org.hl7.fhir.r4.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);
}
}
use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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());
}
}
}
use of org.hl7.fhir.r4.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);
}
}
}
Aggregations