improvements to data types rendering based on new test cases (URLs, Money, Markdown)
This commit is contained in:
parent
0a8334e543
commit
9b3adb9883
|
@ -2,6 +2,9 @@ package org.hl7.fhir.r5.renderers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Currency;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hl7.fhir.exceptions.DefinitionException;
|
import org.hl7.fhir.exceptions.DefinitionException;
|
||||||
|
@ -33,8 +36,11 @@ import org.hl7.fhir.r5.model.Expression;
|
||||||
import org.hl7.fhir.r5.model.Extension;
|
import org.hl7.fhir.r5.model.Extension;
|
||||||
import org.hl7.fhir.r5.model.HumanName;
|
import org.hl7.fhir.r5.model.HumanName;
|
||||||
import org.hl7.fhir.r5.model.HumanName.NameUse;
|
import org.hl7.fhir.r5.model.HumanName.NameUse;
|
||||||
|
import org.hl7.fhir.r5.model.IdType;
|
||||||
import org.hl7.fhir.r5.model.Identifier;
|
import org.hl7.fhir.r5.model.Identifier;
|
||||||
import org.hl7.fhir.r5.model.InstantType;
|
import org.hl7.fhir.r5.model.InstantType;
|
||||||
|
import org.hl7.fhir.r5.model.MarkdownType;
|
||||||
|
import org.hl7.fhir.r5.model.Money;
|
||||||
import org.hl7.fhir.r5.model.Period;
|
import org.hl7.fhir.r5.model.Period;
|
||||||
import org.hl7.fhir.r5.model.PrimitiveType;
|
import org.hl7.fhir.r5.model.PrimitiveType;
|
||||||
import org.hl7.fhir.r5.model.Quantity;
|
import org.hl7.fhir.r5.model.Quantity;
|
||||||
|
@ -384,7 +390,7 @@ public class DataRenderer extends Renderer {
|
||||||
return "to do";
|
return "to do";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(XhtmlNode x, BaseWrapper type) {
|
public void render(XhtmlNode x, BaseWrapper type) throws FHIRFormatError, DefinitionException, IOException {
|
||||||
Base base = null;
|
Base base = null;
|
||||||
try {
|
try {
|
||||||
base = type.getBase();
|
base = type.getBase();
|
||||||
|
@ -399,7 +405,7 @@ public class DataRenderer extends Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderBase(XhtmlNode x, Base b) {
|
public void renderBase(XhtmlNode x, Base b) throws FHIRFormatError, DefinitionException, IOException {
|
||||||
if (b instanceof DataType) {
|
if (b instanceof DataType) {
|
||||||
render(x, (DataType) b);
|
render(x, (DataType) b);
|
||||||
} else {
|
} else {
|
||||||
|
@ -407,7 +413,7 @@ public class DataRenderer extends Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(XhtmlNode x, DataType type) {
|
public void render(XhtmlNode x, DataType type) throws FHIRFormatError, DefinitionException, IOException {
|
||||||
if (type instanceof DateTimeType) {
|
if (type instanceof DateTimeType) {
|
||||||
renderDateTime(x, (DateTimeType) type);
|
renderDateTime(x, (DateTimeType) type);
|
||||||
} else if (type instanceof UriType) {
|
} else if (type instanceof UriType) {
|
||||||
|
@ -424,6 +430,10 @@ public class DataRenderer extends Renderer {
|
||||||
renderHumanName(x, (HumanName) type);
|
renderHumanName(x, (HumanName) type);
|
||||||
} else if (type instanceof Address) {
|
} else if (type instanceof Address) {
|
||||||
renderAddress(x, (Address) type);
|
renderAddress(x, (Address) type);
|
||||||
|
} else if (type instanceof Expression) {
|
||||||
|
renderExpression(x, (Expression) type);
|
||||||
|
} else if (type instanceof Money) {
|
||||||
|
renderMoney(x, (Money) type);
|
||||||
} else if (type instanceof ContactPoint) {
|
} else if (type instanceof ContactPoint) {
|
||||||
renderContactPoint(x, (ContactPoint) type);
|
renderContactPoint(x, (ContactPoint) type);
|
||||||
} else if (type instanceof Quantity) {
|
} else if (type instanceof Quantity) {
|
||||||
|
@ -440,6 +450,8 @@ public class DataRenderer extends Renderer {
|
||||||
renderReference(x, (Reference) type);
|
renderReference(x, (Reference) type);
|
||||||
} else if (type instanceof InstantType) {
|
} else if (type instanceof InstantType) {
|
||||||
x.tx(((InstantType) type).toHumanDisplay());
|
x.tx(((InstantType) type).toHumanDisplay());
|
||||||
|
} else if (type instanceof MarkdownType) {
|
||||||
|
addMarkdown(x, ((MarkdownType) type).asStringValue());
|
||||||
} else if (type instanceof BaseDateTimeType) {
|
} else if (type instanceof BaseDateTimeType) {
|
||||||
x.tx(((BaseDateTimeType) type).toHumanDisplay());
|
x.tx(((BaseDateTimeType) type).toHumanDisplay());
|
||||||
} else if (type.isPrimitive()) {
|
} else if (type.isPrimitive()) {
|
||||||
|
@ -475,8 +487,10 @@ public class DataRenderer extends Renderer {
|
||||||
protected void renderUri(XhtmlNode x, UriType uri) {
|
protected void renderUri(XhtmlNode x, UriType uri) {
|
||||||
if (uri.getValue().startsWith("mailto:")) {
|
if (uri.getValue().startsWith("mailto:")) {
|
||||||
x.ah(uri.getValue()).addText(uri.getValue().substring(7));
|
x.ah(uri.getValue()).addText(uri.getValue().substring(7));
|
||||||
} else {
|
} else if (Utilities.isAbsoluteUrlLinkable(uri.getValue()) && !(uri instanceof IdType)) {
|
||||||
x.ah(uri.getValue()).addText(uri.getValue());
|
x.ah(uri.getValue()).addText(uri.getValue());
|
||||||
|
} else {
|
||||||
|
x.addText(uri.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,6 +918,27 @@ public class DataRenderer extends Renderer {
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getLocalizedBigDecimalValue(BigDecimal input, Currency c) {
|
||||||
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(context.getLocale());
|
||||||
|
numberFormat.setGroupingUsed(true);
|
||||||
|
numberFormat.setMaximumFractionDigits(c.getDefaultFractionDigits());
|
||||||
|
numberFormat.setMinimumFractionDigits(c.getDefaultFractionDigits());
|
||||||
|
return numberFormat.format(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void renderMoney(XhtmlNode x, Money money) {
|
||||||
|
Currency c = Currency.getInstance(money.getCurrency());
|
||||||
|
if (c != null) {
|
||||||
|
XhtmlNode s = x.span(null, c.getDisplayName());
|
||||||
|
s.tx(c.getSymbol());
|
||||||
|
s.tx(getLocalizedBigDecimalValue(money.getValue(), c));
|
||||||
|
x.tx(" ("+c.getCurrencyCode()+")");
|
||||||
|
} else {
|
||||||
|
x.tx(money.getCurrency());
|
||||||
|
x.tx(money.getValue().toPlainString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void renderExpression(XhtmlNode x, Expression expr) {
|
protected void renderExpression(XhtmlNode x, Expression expr) {
|
||||||
// there's two parts: what the expression is, and how it's described.
|
// 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
|
// we start with what it is, and then how it's desceibed
|
||||||
|
@ -1089,7 +1124,7 @@ public class DataRenderer extends Renderer {
|
||||||
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
|
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderDataRequirement(XhtmlNode x, DataRequirement dr) {
|
public void renderDataRequirement(XhtmlNode x, DataRequirement dr) throws FHIRFormatError, DefinitionException, IOException {
|
||||||
XhtmlNode tbl = x.table("grid");
|
XhtmlNode tbl = x.table("grid");
|
||||||
XhtmlNode tr = tbl.tr();
|
XhtmlNode tr = tbl.tr();
|
||||||
XhtmlNode td = tr.td().colspan("2");
|
XhtmlNode td = tr.td().colspan("2");
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.hl7.fhir.r5.model.IdType;
|
||||||
import org.hl7.fhir.r5.model.Identifier;
|
import org.hl7.fhir.r5.model.Identifier;
|
||||||
import org.hl7.fhir.r5.model.InstantType;
|
import org.hl7.fhir.r5.model.InstantType;
|
||||||
import org.hl7.fhir.r5.model.Meta;
|
import org.hl7.fhir.r5.model.Meta;
|
||||||
|
import org.hl7.fhir.r5.model.Money;
|
||||||
import org.hl7.fhir.r5.model.Narrative;
|
import org.hl7.fhir.r5.model.Narrative;
|
||||||
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
|
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
|
||||||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||||
|
@ -352,6 +353,8 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
||||||
renderContactPoint(x, (ContactPoint) e);
|
renderContactPoint(x, (ContactPoint) e);
|
||||||
} else if (e instanceof Expression) {
|
} else if (e instanceof Expression) {
|
||||||
renderExpression(x, (Expression) e);
|
renderExpression(x, (Expression) e);
|
||||||
|
} else if (e instanceof Money) {
|
||||||
|
renderMoney(x, (Money) e);
|
||||||
} else if (e instanceof ContactDetail) {
|
} else if (e instanceof ContactDetail) {
|
||||||
ContactDetail cd = (ContactDetail) e;
|
ContactDetail cd = (ContactDetail) e;
|
||||||
if (cd.hasName()) {
|
if (cd.hasName()) {
|
||||||
|
|
Loading…
Reference in New Issue