Render Expressions + Fix NPE rendering date with no value (only extension)

This commit is contained in:
Grahame Grieve 2021-11-16 17:22:30 +11:00
parent d483a7dbc3
commit 4cd0a3e56c
2 changed files with 40 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Expression;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.HumanName;
import org.hl7.fhir.r5.model.HumanName.NameUse;
@ -903,6 +904,36 @@ public class DataRenderer extends Renderer {
return s.toString();
}
protected void renderExpression(XhtmlNode x, Expression expr) {
// there's two parts: what the expression is, and how it's described.
// we start with what it is, and then how it's desceibed
if (expr.hasExpression()) {
XhtmlNode c = x;
if (expr.hasReference()) {
c = x.ah(expr.getReference());
}
if (expr.hasLanguage()) {
c = c.span(null, expr.getLanguage());
}
c.code().tx(expr.getExpression());
} else if (expr.hasReference()) {
x.ah(expr.getReference()).tx("source");
}
if (expr.hasName() || expr.hasDescription()) {
x.tx("(");
if (expr.hasName()) {
x.b().tx(expr.getName());
}
if (expr.hasDescription()) {
x.tx("\"");
x.tx(expr.getDescription());
x.tx("\"");
}
x.tx(")");
}
}
protected void renderContactPoint(XhtmlNode x, ContactPoint contact) {
if (contact != null) {
if (!contact.hasSystem()) {

View File

@ -33,6 +33,7 @@ import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Dosage;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Expression;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.HumanName;
import org.hl7.fhir.r5.model.IdType;
@ -291,7 +292,6 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
@ -308,9 +308,12 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
renderDateTime(x, e);
} else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.r5.model.DateType)
x.addText(((org.hl7.fhir.r5.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
else if (e instanceof org.hl7.fhir.r5.model.DateType) {
org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e);
if (((org.hl7.fhir.r5.model.DateType) e).hasValue()) {
x.addText(((org.hl7.fhir.r5.model.DateType) e).toHumanDisplay());
}
} 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) {
@ -347,6 +350,8 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
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 ContactDetail) {
ContactDetail cd = (ContactDetail) e;
if (cd.hasName()) {