use of org.hl7.fhir.r5.model.Questionnaire in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderTreeItem.
private boolean renderTreeItem(HierarchicalTableGenerator gen, List<Row> rows, Questionnaire q, QuestionnaireItemComponent i, boolean hasFlags) throws IOException {
Row r = gen.new Row();
rows.add(r);
boolean hasExt = false;
r.setIcon("icon-q-" + i.getType().toCode().toLowerCase() + ".png", i.getType().getDisplay());
r.getCells().add(gen.new Cell(null, context.getDefinitionsTarget() == null ? "" : context.getDefinitionsTarget() + "#item." + i.getLinkId(), i.getLinkId(), null, null));
String txt = (i.hasPrefix() ? i.getPrefix() + ". " : "") + i.getText();
r.getCells().add(gen.new Cell(null, null, txt, null, null));
r.getCells().add(gen.new Cell(null, null, (i.getRequired() ? "1" : "0") + ".." + (i.getRepeats() ? "*" : "1"), null, null));
if (i.getTypeElement().hasExtension(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL)) {
String t = i.getTypeElement().getExtensionString(EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL);
r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + t, t, null, null));
} else {
r.getCells().add(gen.new Cell(null, context.getSpecificationLink() + "codesystem-item-type.html#item-type-" + i.getType().toCode(), i.getType().toCode(), null, null));
}
if (hasFlags) {
// flags:
Cell flags = gen.new Cell();
r.getCells().add(flags);
if (i.getReadOnly()) {
flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecificationLink(), "questionnaire-definitions.html#Questionnaire.item.readOnly"), null, "Is Readonly").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-readonly.png"))));
}
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-isSubject.html"), null, "Can change the subject of the questionnaire").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-subject.png"))));
}
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-hidden.html"), null, "Is a hidden item").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-hidden.png"))));
}
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-optionalDisplay.html"), null, "Is optional to display").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-optional.png"))));
}
if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationLinkPeriod")) {
flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-observationLinkPeriod"), null, "Is linked to an observation").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-observation.png"))));
}
if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation")) {
String code = ToolingExtensions.readStringExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-choiceOrientation");
flags.addPiece(gen.new Piece(getSpecLink("extension-questionnaire-choiceorientation.html"), null, "Orientation: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
}
if (i.hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory")) {
CodeableConcept cc = i.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory").getValueCodeableConcept();
String code = cc.getCode("http://hl7.org/fhir/questionnaire-display-category");
flags.addPiece(gen.new Piece(getSDCLink("StructureDefinition-sdc-questionnaire-displayCategory"), null, "Category: " + code).addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getLocalPrefix(), "icon-qi-" + code + ".png"))));
}
}
Cell defn = gen.new Cell();
r.getCells().add(defn);
if (i.hasMaxLength()) {
defn.getPieces().add(gen.new Piece(null, "Max Length: ", null));
defn.getPieces().add(gen.new Piece(null, Integer.toString(i.getMaxLength()), null));
}
if (i.hasDefinition()) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
defn.getPieces().add(gen.new Piece(null, "Definition: ", null));
genDefinitionLink(gen, i, defn);
}
if (i.hasEnableWhen()) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
Piece p = gen.new Piece(null, "Enable When: ", null);
defn.getPieces().add(p);
if (i.getEnableWhen().size() == 0) {
XhtmlNode x = new XhtmlNode(NodeType.Element, "span");
p.getChildren().add(x);
renderEnableWhen(x, i.getEnableWhenFirstRep());
} else {
XhtmlNode x = new XhtmlNode(NodeType.Element, "ul");
p.getChildren().add(x);
for (QuestionnaireItemEnableWhenComponent qi : i.getEnableWhen()) {
renderEnableWhen(x.li(), qi);
}
}
}
if (i.hasAnswerValueSet()) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
defn.getPieces().add(gen.new Piece(null, "Value Set: ", null));
if (!Utilities.noString(i.getAnswerValueSet()) && i.getAnswerValueSet().startsWith("#")) {
ValueSet vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1));
if (vs == null) {
defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
} else {
defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
}
} else {
ValueSet vs = context.getWorker().fetchResource(ValueSet.class, i.getAnswerValueSet());
if (vs == null || !vs.hasUserData("path")) {
defn.getPieces().add(gen.new Piece(null, i.getAnswerValueSet(), null));
} else {
defn.getPieces().add(gen.new Piece(vs.getUserString("path"), vs.present(), null));
}
}
}
if (i.hasAnswerOption()) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
defn.getPieces().add(gen.new Piece(null, "Options: ", null));
if (context.getDefinitionsTarget() == null) {
// if we don't have a definitions target, we'll add them below.
defn.getPieces().add(gen.new Piece("#opt-item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
} else {
defn.getPieces().add(gen.new Piece(context.getDefinitionsTarget() + "#item." + i.getLinkId(), Integer.toString(i.getAnswerOption().size()) + " " + Utilities.pluralize("option", i.getAnswerOption().size()), null));
}
}
if (i.hasInitial()) {
for (QuestionnaireItemInitialComponent v : i.getInitial()) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
defn.getPieces().add(gen.new Piece(null, "Initial Value: ", null));
defn.getPieces().add(gen.new Piece(null, v.getValue().fhirType(), null));
defn.getPieces().add(gen.new Piece(null, " = ", null));
if (v.getValue().isPrimitive()) {
defn.getPieces().add(gen.new Piece(null, v.getValue().primitiveValue(), null));
} else {
renderCoding(gen, defn.getPieces(), v.getValueCoding());
}
}
}
if (i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression") || i.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
if (!defn.getPieces().isEmpty())
defn.addPiece(gen.new Piece("br"));
defn.getPieces().add(gen.new Piece(null, "Expressions: ", null));
Piece p = gen.new Piece("ul");
defn.getPieces().add(p);
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
addExpression(p, e.getValueExpression(), "Initial Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression");
}
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression")) {
addExpression(p, e.getValueExpression(), "Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-contextExpression");
}
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext")) {
addExpression(p, e.getValueExpression(), "Item Context", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-itemContext");
}
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression")) {
addExpression(p, e.getValueExpression(), "Enable When", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression");
}
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression")) {
addExpression(p, e.getValueExpression(), "Calculated Value", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression");
}
for (Extension e : i.getExtensionsByUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression")) {
addExpression(p, e.getValueExpression(), "Candidates", "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-candidateExpression");
}
}
for (QuestionnaireItemComponent c : i.getItem()) {
hasExt = renderTreeItem(gen, r.getSubRows(), q, c, hasFlags) || hasExt;
}
return hasExt;
}
use of org.hl7.fhir.r5.model.Questionnaire in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireRenderer method renderLinks.
private boolean renderLinks(XhtmlNode x, Questionnaire q) {
x.para().tx("Try this questionnaire out:");
XhtmlNode ul = x.ul();
ul.li().ah("http://todo.nlm.gov/path?mode=ig&src=" + Utilities.pathURL(context.getSelfLink(), "package.tgz") + "&q=" + q.getId() + ".json").tx("NLM Forms Library");
return false;
}
use of org.hl7.fhir.r5.model.Questionnaire in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method validateQuestionannaireItem.
private void validateQuestionannaireItem(List<ValidationMessage> errors, Element element, Element questionnaire, NodeStack stack, List<Element> parents) {
List<Element> list = getItems(element);
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
NodeStack ns = stack.push(e, i, e.getProperty().getDefinition(), e.getProperty().getDefinition());
validateQuestionnaireElement(errors, ns, questionnaire, e, parents);
List<Element> np = new ArrayList<Element>();
np.add(e);
np.addAll(parents);
validateQuestionannaireItem(errors, e, questionnaire, ns, np);
}
}
use of org.hl7.fhir.r5.model.Questionnaire in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireValidator method validateQuestionannaireResponse.
public void validateQuestionannaireResponse(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element element, NodeStack stack) throws FHIRException {
if (questionnaireMode == QuestionnaireMode.NONE) {
return;
}
Element q = element.getNamedChild("questionnaire");
String questionnaire = null;
if (q != null) {
/*
* q.getValue() is correct for R4 content, but we'll also accept the second
* option just in case we're validating raw STU3 content. Being lenient here
* isn't the end of the world since if someone is actually doing the reference
* wrong in R4 content it'll get flagged elsewhere by the validator too
*/
if (isNotBlank(q.getValue())) {
questionnaire = q.getValue();
} else if (isNotBlank(q.getChildValue("reference"))) {
questionnaire = q.getChildValue("reference");
}
}
boolean ok = questionnaireMode == QuestionnaireMode.REQUIRED ? rule(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), questionnaire != null, I18nConstants.QUESTIONNAIRE_QR_Q_NONE) : hint(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), questionnaire != null, I18nConstants.QUESTIONNAIRE_QR_Q_NONE);
if (ok) {
QuestionnaireWithContext qsrc = null;
if (questionnaire.startsWith("#")) {
qsrc = QuestionnaireWithContext.fromContainedResource(stack.getLiteralPath(), element, (Questionnaire) loadContainedResource(errors, stack.getLiteralPath(), element, questionnaire.substring(1), Questionnaire.class));
} else {
qsrc = QuestionnaireWithContext.fromQuestionnaire(context.fetchResource(Questionnaire.class, questionnaire));
}
if (questionnaireMode == QuestionnaireMode.REQUIRED) {
ok = rule(errors, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);
} else if (questionnaire.startsWith("http://example.org")) {
ok = hint(errors, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);
} else {
ok = warning(errors, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);
}
if (ok) {
boolean inProgress = "in-progress".equals(element.getNamedChildValue("status"));
validateQuestionannaireResponseItems(hostContext, qsrc, qsrc.q().getItem(), errors, element, stack, inProgress, element, new QStack(qsrc, element));
}
}
}
use of org.hl7.fhir.r5.model.Questionnaire in project org.hl7.fhir.core by hapifhir.
the class Tester method main.
public static void main(String[] args) throws Exception {
IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
int t = 0;
int ok = 0;
for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
// if (f.equals("account-questionnaire.xml")) {
System.out.print("convert " + f);
// Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
// new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
// String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
// String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
t++;
if (src.equals(tgt)) {
System.out.println(".. ok");
ok++;
} else
System.out.println(".. fail");
}
// }
}
System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
Aggregations