diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java index 527099bb6..83d2f9ba9 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/ProfileDrivenRenderer.java @@ -366,137 +366,160 @@ public class ProfileDrivenRenderer extends ResourceRenderer { x = renderCommentsSpan(x, e); } - if (e instanceof StringType) - x.addText(((StringType) e).getValue()); - else if (e instanceof CodeType) - x.addText(((CodeType) e).getValue()); - else if (e instanceof IdType) - x.addText(((IdType) e).getValue()); - else if (e instanceof Extension) - return; - else if (e instanceof InstantType) - x.addText(((InstantType) e).toHumanDisplay()); - else if (e instanceof DateTimeType) { - renderDateTime(x, e); - } else if (e instanceof Base64BinaryType) { - Base64BinaryType b64 = (Base64BinaryType) e; - x.addText("(base64 data - "+(b64.getValue() == null ? "0" : b64.getValue().length)+" bytes)"); - } else if (e instanceof org.hl7.fhir.r5.model.DateType) { - org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e); - renderDate(x, dt); - } else if (e instanceof Enumeration) { - Object ev = ((Enumeration) e).getValue(); - x.addText(ev == null ? "" : ev.toString()); // todo: look up a display name if there is one - } else if (e instanceof BooleanType) { - x.addText(((BooleanType) e).getValue().toString()); - } else if (e instanceof CodeableConcept) { - renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails); - } else if (e instanceof Coding) { - renderCoding(x, (Coding) e, showCodeDetails); - } else if (e instanceof CodeableReference) { - renderCodeableReference(x, (CodeableReference) e, showCodeDetails); - } else if (e instanceof Annotation) { - renderAnnotation(x, (Annotation) e); - } else if (e instanceof Identifier) { - renderIdentifier(x, (Identifier) e); - } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) { - if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) { - x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue())); - } else { - x.addText("??"); - } - } else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) { - if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) { - x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue())); - } else { - x.addText("??"); - } - } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) { - x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString()); - } else if (e instanceof HumanName) { - renderHumanName(x, (HumanName) e); - } else if (e instanceof SampledData) { - renderSampledData(x, (SampledData) e); - } else if (e instanceof Address) { - renderAddress(x, (Address) e); - } else if (e instanceof ContactPoint) { - renderContactPoint(x, (ContactPoint) e); - } else if (e instanceof Expression) { - renderExpression(x, (Expression) e); - } else if (e instanceof Money) { - renderMoney(x, (Money) e); - } else if (e instanceof ContactDetail) { - ContactDetail cd = (ContactDetail) e; - if (cd.hasName()) { - x.tx(cd.getName()+": "); - } - boolean first = true; - for (ContactPoint c : cd.getTelecom()) { - if (first) first = false; else x.tx(","); - renderContactPoint(x, c); - } - } else if (e instanceof UriType) { - renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResource() != null ? rcontext.getResource().getId() : null, res.getResource()); - } else if (e instanceof Timing) { - renderTiming(x, (Timing) e); - } else if (e instanceof Range) { - renderRange(x, (Range) e); - } else if (e instanceof Quantity) { - renderQuantity(x, (Quantity) e, showCodeDetails); - } else if (e instanceof Ratio) { - renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails); - x.tx("/"); - renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails); - } else if (e instanceof Period) { - Period p = (Period) e; - renderPeriod(x, p); - } else if (e instanceof Reference) { - Reference r = (Reference) e; - if (r.getReference() != null && r.getReference().contains("#")) { - if (containedIds.contains(r.getReference().substring(1))) { - x.ah(r.getReference()).tx("See "+r.getReference()); - } else { - // in this case, we render the resource in line - ResourceWrapper rw = null; - for (ResourceWrapper t : res.getContained()) { - if (r.getReference().substring(1).equals(t.getId())) { - rw = t; - } - } - if (rw == null) { - renderReference(res, x, r); - } else { - String ref = context.getResolver() != null ?context.getResolver().urlForContained(context, res.fhirType(), res.getId(), rw.fhirType(), rw.getId()) : null; - if (ref == null) { - x.an(rw.getId()); - RenderingContext ctxtc = context.copy(); - ctxtc.setAddGeneratedNarrativeHeader(false); - ctxtc.setContained(true); - ResourceRenderer rr = RendererFactory.factory(rw, ctxtc); - rr.setRcontext(new ResourceContext(rcontext, rw)); - rr.render(parent.blockquote(), rw); - } else { - x.ah(ref).tx("See "+rw.fhirType()); - } - } + if (e instanceof PrimitiveType) { + PrimitiveType p = (PrimitiveType) e; + if (!p.hasValue()) { + if (p.hasExtension(ToolingExtensions.EXT_DAR)) { + x.tx("Absent because : "); + x.code().tx(p.getExtensionString(ToolingExtensions.EXT_DAR)); + } else if (p.hasExtension(ToolingExtensions.EXT_NF)) { + x.tx("Null because: "); + x.code().tx(p.getExtensionString(ToolingExtensions.EXT_NF)); + } else if (p.hasExtension(ToolingExtensions.EXT_OT)) { + x.code().tx("Text: "); + x.tx(p.getExtensionString(ToolingExtensions.EXT_OT)); + } else if (p.hasExtension(ToolingExtensions.EXT_CQF_EXP)) { + x.code().tx("Value calculated by: "); + Expression exp = p.getExtensionByUrl(ToolingExtensions.EXT_CQF_EXP).getValueExpression(); + x.tx(p.getExtensionString(ToolingExtensions.EXT_OT)); + renderExpression(x, exp); + } else { + x.addText("??"); } - } else { - renderReference(res, x, r); + } else if (e instanceof StringType) + x.addText(((StringType) e).getValue()); + else if (e instanceof CodeType) + x.addText(((CodeType) e).getValue()); + else if (e instanceof IdType) + x.addText(((IdType) e).getValue()); + else if (e instanceof InstantType) + x.addText(((InstantType) e).toHumanDisplay()); + else if (e instanceof DateTimeType) { + renderDateTime(x, e); + } else if (e instanceof Base64BinaryType) { + Base64BinaryType b64 = (Base64BinaryType) e; + x.addText("(base64 data - "+(b64.getValue() == null ? "0" : b64.getValue().length)+" bytes)"); + } else if (e instanceof org.hl7.fhir.r5.model.DateType) { + org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e); + renderDate(x, dt); + } else if (e instanceof Enumeration) { + Object ev = ((Enumeration) e).getValue(); + x.addText(ev == null ? "" : ev.toString()); // todo: look up a display name if there is one + } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) { + if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) { + x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue())); + } else { + x.addText("??"); + } + } else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) { + if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) { + x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue())); + } else { + x.addText("??"); + } + } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) { + x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString()); + } else if (e instanceof UriType) { + renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResource() != null ? rcontext.getResource().getId() : null, res.getResource()); + } else if (e instanceof BooleanType) { + x.addText(((BooleanType) e).getValue().toString()); + } else { // e instanceof PrimitiveType + x.tx(((PrimitiveType) e).primitiveValue()); + } + } else { + if (e instanceof Extension) { + return; + } else if (e instanceof CodeableConcept) { + renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails); + } else if (e instanceof Coding) { + renderCoding(x, (Coding) e, showCodeDetails); + } else if (e instanceof CodeableReference) { + renderCodeableReference(x, (CodeableReference) e, showCodeDetails); + } else if (e instanceof Annotation) { + renderAnnotation(x, (Annotation) e); + } else if (e instanceof Identifier) { + renderIdentifier(x, (Identifier) e); + } else if (e instanceof HumanName) { + renderHumanName(x, (HumanName) e); + } else if (e instanceof SampledData) { + renderSampledData(x, (SampledData) e); + } else if (e instanceof Address) { + renderAddress(x, (Address) e); + } else if (e instanceof ContactPoint) { + renderContactPoint(x, (ContactPoint) e); + } else if (e instanceof Expression) { + renderExpression(x, (Expression) e); + } else if (e instanceof Money) { + renderMoney(x, (Money) e); + } else if (e instanceof ContactDetail) { + ContactDetail cd = (ContactDetail) e; + if (cd.hasName()) { + x.tx(cd.getName()+": "); + } + boolean first = true; + for (ContactPoint c : cd.getTelecom()) { + if (first) first = false; else x.tx(","); + renderContactPoint(x, c); + } + } else if (e instanceof Timing) { + renderTiming(x, (Timing) e); + } else if (e instanceof Range) { + renderRange(x, (Range) e); + } else if (e instanceof Quantity) { + renderQuantity(x, (Quantity) e, showCodeDetails); + } else if (e instanceof Ratio) { + renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails); + x.tx("/"); + renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails); + } else if (e instanceof Period) { + Period p = (Period) e; + renderPeriod(x, p); + } else if (e instanceof Reference) { + Reference r = (Reference) e; + if (r.getReference() != null && r.getReference().contains("#")) { + if (containedIds.contains(r.getReference().substring(1))) { + x.ah(r.getReference()).tx("See "+r.getReference()); + } else { + // in this case, we render the resource in line + ResourceWrapper rw = null; + for (ResourceWrapper t : res.getContained()) { + if (r.getReference().substring(1).equals(t.getId())) { + rw = t; + } + } + if (rw == null) { + renderReference(res, x, r); + } else { + String ref = context.getResolver() != null ?context.getResolver().urlForContained(context, res.fhirType(), res.getId(), rw.fhirType(), rw.getId()) : null; + if (ref == null) { + x.an(rw.getId()); + RenderingContext ctxtc = context.copy(); + ctxtc.setAddGeneratedNarrativeHeader(false); + ctxtc.setContained(true); + ResourceRenderer rr = RendererFactory.factory(rw, ctxtc); + rr.setRcontext(new ResourceContext(rcontext, rw)); + rr.render(parent.blockquote(), rw); + } else { + x.ah(ref).tx("See "+rw.fhirType()); + } + } + } + } else { + renderReference(res, x, r); + } + } else if (e instanceof Resource) { + return; + } else if (e instanceof DataRequirement) { + DataRequirement p = (DataRequirement) e; + renderDataRequirement(x, p); + } else if (e instanceof UsageContext) { + UsageContext p = (UsageContext) e; + renderUsageContext(x, p); + } else if (e instanceof ElementDefinition) { + x.tx("todo-bundle"); + } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta) && !(e instanceof ProductShelfLife) && !(e instanceof RelatedArtifact)) { + throw new NotImplementedException("type "+e.fhirType()+" not handled. This may be due to unresolved inter-version compatibility issues"); } - } else if (e instanceof Resource) { - return; - } else if (e instanceof DataRequirement) { - DataRequirement p = (DataRequirement) e; - renderDataRequirement(x, p); - } else if (e instanceof UsageContext) { - UsageContext p = (UsageContext) e; - renderUsageContext(x, p); - } else if (e instanceof PrimitiveType) { - x.tx(((PrimitiveType) e).primitiveValue()); - } else if (e instanceof ElementDefinition) { - x.tx("todo-bundle"); - } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta) && !(e instanceof ProductShelfLife) && !(e instanceof RelatedArtifact)) { - throw new NotImplementedException("type "+e.fhirType()+" not handled. This may be due to unresolved inter-version compatibility issues"); } }