Rendering improvements: partial dates, questionnaire links, and patient renderer
This commit is contained in:
parent
76ed4abba7
commit
fb1a08dca8
|
@ -1,5 +1,9 @@
|
|||
package org.hl7.fhir.r5.renderers;
|
||||
|
||||
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
|
||||
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
|
||||
import static java.time.temporal.ChronoField.YEAR;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -9,8 +13,12 @@ import java.text.SimpleDateFormat;
|
|||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.chrono.IsoChronology;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.time.format.ResolverStyle;
|
||||
import java.time.format.SignStyle;
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
@ -39,6 +47,7 @@ import org.hl7.fhir.r5.model.DataRequirement.SortDirection;
|
|||
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.DateType;
|
||||
import org.hl7.fhir.r5.model.Enumeration;
|
||||
import org.hl7.fhir.r5.model.Expression;
|
||||
import org.hl7.fhir.r5.model.Extension;
|
||||
|
@ -413,15 +422,8 @@ public class DataRenderer extends Renderer {
|
|||
// mode - if rendering mode is technical, format defaults to XML format
|
||||
// locale - otherwise, format defaults to SHORT for the Locale (which defaults to default Locale)
|
||||
if (isOnlyDate(type.getPrecision())) {
|
||||
DateTimeFormatter fmt = context.getDateFormat();
|
||||
if (fmt == null) {
|
||||
if (context.isTechnicalMode()) {
|
||||
fmt = DateTimeFormatter.ISO_DATE;
|
||||
} else {
|
||||
fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(context.getLocale());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DateTimeFormatter fmt = getDateFormatForPrecision(type);
|
||||
LocalDate date = LocalDate.of(type.getYear(), type.getMonth()+1, type.getDay());
|
||||
return fmt.format(date);
|
||||
}
|
||||
|
@ -440,6 +442,43 @@ public class DataRenderer extends Renderer {
|
|||
zdt = zdt.withZoneSameInstant(zone);
|
||||
}
|
||||
return fmt.format(zdt);
|
||||
}
|
||||
|
||||
private DateTimeFormatter getDateFormatForPrecision(BaseDateTimeType type) {
|
||||
DateTimeFormatter fmt = getContextDateFormat(type);
|
||||
if (fmt != null) {
|
||||
return fmt;
|
||||
}
|
||||
if (context.isTechnicalMode()) {
|
||||
switch (type.getPrecision()) {
|
||||
case YEAR:
|
||||
return new DateTimeFormatterBuilder().appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD).toFormatter();
|
||||
case MONTH:
|
||||
return new DateTimeFormatterBuilder().appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD).appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).toFormatter();
|
||||
default:
|
||||
return DateTimeFormatter.ISO_DATE;
|
||||
}
|
||||
} else {
|
||||
switch (type.getPrecision()) {
|
||||
case YEAR:
|
||||
return DateTimeFormatter.ofPattern("uuuu");
|
||||
case MONTH:
|
||||
return DateTimeFormatter.ofPattern("MMM uuuu");
|
||||
default:
|
||||
return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(context.getLocale());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DateTimeFormatter getContextDateFormat(BaseDateTimeType type) {
|
||||
switch (type.getPrecision()) {
|
||||
case YEAR:
|
||||
return context.getDateYearFormat();
|
||||
case MONTH:
|
||||
return context.getDateYearMonthFormat();
|
||||
default:
|
||||
return context.getDateFormat();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOnlyDate(TemporalPrecisionEnum temporalPrecisionEnum) {
|
||||
|
@ -533,6 +572,12 @@ public class DataRenderer extends Renderer {
|
|||
}
|
||||
}
|
||||
|
||||
public void renderDate(XhtmlNode x, Base e) {
|
||||
if (e.hasPrimitiveValue()) {
|
||||
x.addText(displayDateTime((DateType) e));
|
||||
}
|
||||
}
|
||||
|
||||
public void renderDateTime(XhtmlNode x, String s) {
|
||||
if (s != null) {
|
||||
DateTimeType dt = new DateTimeType(s);
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.poi.hssf.record.chart.DatRecord;
|
||||
import org.hl7.fhir.exceptions.DefinitionException;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
import org.hl7.fhir.r5.model.DateType;
|
||||
import org.hl7.fhir.r5.model.DomainResource;
|
||||
|
@ -219,5 +221,7 @@ public class PatientRenderer extends ResourceRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
//// public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException {
|
||||
// }
|
||||
}
|
|
@ -312,9 +312,7 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
|
|||
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
|
||||
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());
|
||||
}
|
||||
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
|
||||
|
|
|
@ -712,7 +712,7 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
|
|||
XhtmlNode ans = item(ul, "Answers");
|
||||
if (!Utilities.noString(i.getAnswerValueSet()) && i.getAnswerValueSet().startsWith("#")) {
|
||||
ValueSet vs = (ValueSet) q.getContained(i.getAnswerValueSet().substring(1));
|
||||
if (vs == null) {
|
||||
if (vs == null || !vs.hasUserData("path")) {
|
||||
ans.tx(i.getAnswerValueSet());
|
||||
} else {
|
||||
ans.ah(vs.getUserString("path")).tx(vs.present());
|
||||
|
|
|
@ -114,6 +114,9 @@ public class RendererFactory {
|
|||
if ("Library".equals(resource.getName())) {
|
||||
return new LibraryRenderer(context);
|
||||
}
|
||||
if ("Patient".equals(resource.getName())) {
|
||||
return new PatientRenderer(context);
|
||||
}
|
||||
if ("DiagnosticReport".equals(resource.getName())) {
|
||||
return new DiagnosticReportRenderer(context);
|
||||
}
|
||||
|
|
|
@ -127,6 +127,8 @@ public class RenderingContext {
|
|||
private ZoneId timeZoneId;
|
||||
private DateTimeFormatter dateTimeFormat;
|
||||
private DateTimeFormatter dateFormat;
|
||||
private DateTimeFormatter dateYearFormat;
|
||||
private DateTimeFormatter dateYearMonthFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -359,7 +361,16 @@ public class RenderingContext {
|
|||
res.definitionsTarget = definitionsTarget;
|
||||
res.destDir = destDir;
|
||||
res.addGeneratedNarrativeHeader = addGeneratedNarrativeHeader;
|
||||
|
||||
res.questionnaireMode = questionnaireMode;
|
||||
res.header = header;
|
||||
res.selfLink = selfLink;
|
||||
res.inlineGraphics = inlineGraphics;
|
||||
res.timeZoneId = timeZoneId;
|
||||
res.dateTimeFormat = dateTimeFormat;
|
||||
res.dateFormat = dateFormat;
|
||||
res.dateYearFormat = dateYearFormat;
|
||||
res.dateYearMonthFormat = dateYearMonthFormat;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -514,6 +525,30 @@ public class RenderingContext {
|
|||
this.dateFormat = DateTimeFormatter.ofPattern(dateFormat);
|
||||
}
|
||||
|
||||
public DateTimeFormatter getDateYearFormat() {
|
||||
return dateYearFormat;
|
||||
}
|
||||
|
||||
public void setDateYearFormat(DateTimeFormatter dateYearFormat) {
|
||||
this.dateYearFormat = dateYearFormat;
|
||||
}
|
||||
|
||||
public void setDateYearFormatString(String dateYearFormat) {
|
||||
this.dateYearFormat = DateTimeFormatter.ofPattern(dateYearFormat);
|
||||
}
|
||||
|
||||
public DateTimeFormatter getDateYearMonthFormat() {
|
||||
return dateYearMonthFormat;
|
||||
}
|
||||
|
||||
public void setDateYearMonthFormat(DateTimeFormatter dateYearMonthFormat) {
|
||||
this.dateYearMonthFormat = dateYearMonthFormat;
|
||||
}
|
||||
|
||||
public void setDateYearMonthFormatString(String dateYearMonthFormat) {
|
||||
this.dateYearMonthFormat = DateTimeFormatter.ofPattern(dateYearMonthFormat);
|
||||
}
|
||||
|
||||
public ResourceRendererMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
|
|
@ -111,15 +111,7 @@ public class NarrativeGenerationTests {
|
|||
List<Arguments> objects = new ArrayList<>();
|
||||
while (test != null && test.getNodeName().equals("test")) {
|
||||
TestDetails t = new TestDetails(test);
|
||||
if (t.getId().equals("sdc")) {
|
||||
if (SystemUtils.OS_NAME.contains(WINDOWS)) {
|
||||
objects.add(Arguments.of(t.getId(), t));
|
||||
} else {
|
||||
System.out.println("sdc test not being adding because the current OS will not pass the test...");
|
||||
}
|
||||
} else {
|
||||
objects.add(Arguments.of(t.getId(), t));
|
||||
}
|
||||
objects.add(Arguments.of(t.getId(), t));
|
||||
test = XMLUtil.getNextSibling(test);
|
||||
}
|
||||
return objects.stream();
|
||||
|
|
Loading…
Reference in New Issue