Handle all initial value types when rendering Questionnaires

This commit is contained in:
Grahame Grieve 2023-12-13 09:08:32 -05:00
parent 34416b8708
commit 46e063cc87
3 changed files with 106 additions and 5 deletions

View File

@ -749,7 +749,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
}
private void renderReference(XhtmlNode x, Reference ref) {
protected void renderReference(XhtmlNode x, Reference ref) {
if (ref.hasDisplay()) {
x.tx(ref.getDisplay());
} else if (ref.hasReference()) {
@ -1199,7 +1199,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
}
private String displayIdentifier(Identifier ii) {
protected String displayIdentifier(Identifier ii) {
String s = Utilities.noString(ii.getValue()) ? "?ngen-9?" : ii.getValue();
NamingSystem ns = context.getContext().getNSUrlMap().get(ii.getSystem());
if (ns != null) {
@ -1528,6 +1528,11 @@ public class DataRenderer extends Renderer implements CodeResolver {
}
}
protected void renderQuantity(HierarchicalTableGenerator gen, List<Piece> pieces, Quantity q, boolean showCodeDetails) {
pieces.add(gen.new Piece(null, displayQuantity(q), null));
}
public String displayRange(Range q) {
if (!q.hasLow() && !q.hasHigh())
return "?";

View File

@ -350,8 +350,14 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
defn.getPieces().add(gen.new Piece(null, " = ", null));
if (v.getValue().isPrimitive()) {
defn.getPieces().add(gen.new Piece(null, v.getValue().primitiveValue(), null));
} else {
} else if (v.hasValueCoding()) {
renderCoding(gen, defn.getPieces(), v.getValueCoding());
} else if (v.hasValueQuantity()) {
renderQuantity(gen, defn.getPieces(), v.getValueQuantity(), false);
} else if (v.hasValueReference()) {
renderReference(q, gen, defn.getPieces(), v.getValueReference(), true);
} else if (v.hasValueAttachment()) {
// renderAttachment(gen, defn.getPieces(), v.getValueAttachment());
}
}
}
@ -528,8 +534,14 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
defn.getPieces().add(gen.new Piece(null, " = ", null));
if (v.getValue().isPrimitive()) {
defn.getPieces().add(gen.new Piece(null, v.getValue().primitiveValue(), null));
} else {
} else if (v.hasValueCoding()) {
renderCoding(gen, defn.getPieces(), v.getValueCoding());
} else if (v.hasValueQuantity()) {
renderQuantity(gen, defn.getPieces(), v.getValueQuantity(), false);
} else if (v.hasValueReference()) {
renderReference(q, gen, defn.getPieces(), v.getValueReference(), false);
// } else if (v.hasValueAttachment()) {
// renderAttachment(gen, defn.getPieces(), v.getValueAttachment());
}
}
}
@ -759,8 +771,14 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
if (first) first = false; else vi.tx(", ");
if (v.getValue().isPrimitive()) {
vi.tx(v.getValue().primitiveValue());
} else {
} else if (v.hasValueCoding()) {
renderCoding(vi, v.getValueCoding(), true);
} else if (v.hasValueReference()) {
renderReference(vi, v.getValueReference());
} else if (v.hasValueQuantity()) {
renderQuantity(vi, v.getValueQuantity());
// } else if (v.hasValueAttachment()) {
// renderAttachment(vi, v.getValueAttachment());
}
}
}

View File

@ -39,8 +39,10 @@ import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece;
public abstract class ResourceRenderer extends DataRenderer {
@ -216,6 +218,82 @@ public abstract class ResourceRenderer extends DataRenderer {
public void renderReference(ResourceWrapper rw, XhtmlNode x, Reference r) throws UnsupportedEncodingException, IOException {
renderReference(rw, x, r, true);
}
public void renderReference(Resource res, HierarchicalTableGenerator gen, List<Piece> pieces, Reference r, boolean allowLinks) throws UnsupportedEncodingException, IOException {
if (r == null) {
pieces.add(gen.new Piece(null, "null!", null));
return;
}
ResourceWrapper rw = new ResourceWrapperDirect(this.context, res);
ResourceWithReference tr = null;
String link = null;
StringBuilder text = new StringBuilder();
if (r.hasReferenceElement() && allowLinks) {
tr = resolveReference(rw, r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null) {
link = tr.getReference();
} else if (r.getReference().contains("?")) {
text.append("Conditional Reference: ");
} else {
link = r.getReference();
}
}
}
if (tr != null && tr.getReference() != null && tr.getReference().startsWith("#")) {
text.append("See above (");
}
// what to display: if text is provided, then that. if the reference was resolved, then show the name, or the generated narrative
String display = r.hasDisplayElement() ? r.getDisplay() : null;
String name = tr != null && tr.getResource() != null ? tr.getResource().getNameFromResource() : null;
if (display == null && (tr == null || tr.getResource() == null)) {
if (!Utilities.noString(r.getReference())) {
text.append(r.getReference());
} else if (r.hasIdentifier()) {
text.append(displayIdentifier(r.getIdentifier()));
} else {
text.append("??");
}
} else if (context.isTechnicalMode()) {
text.append(r.getReference());
if (display != null) {
text.append(": "+display);
}
if ((tr == null || (tr.getReference() != null && !tr.getReference().startsWith("#"))) && name != null) {
text.append(" \""+name+"\"");
}
if (r.hasExtension(ToolingExtensions.EXT_TARGET_ID) || r.hasExtension(ToolingExtensions.EXT_TARGET_PATH)) {
text.append("(");
for (Extension ex : r.getExtensionsByUrl(ToolingExtensions.EXT_TARGET_ID)) {
if (ex.hasValue()) {
text.append(", ");
text.append("#"+ex.getValue().primitiveValue());
}
}
for (Extension ex : r.getExtensionsByUrl(ToolingExtensions.EXT_TARGET_PATH)) {
if (ex.hasValue()) {
text.append(", ");
text.append("/#"+ex.getValue().primitiveValue());
}
}
text.append(")");
}
} else {
if (display != null) {
text.append(display);
} else if (name != null) {
text.append(name);
} else {
text.append(". Description: (todo)");
}
}
if (tr != null && tr.getReference() != null && tr.getReference().startsWith("#")) {
text.append(")");
}
pieces.add(gen.new Piece(link,text.toString(), null));
}
public void renderReference(ResourceWrapper rw, XhtmlNode x, Reference r, boolean allowLinks) throws UnsupportedEncodingException, IOException {
if (r == null) {