use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method processDateConstant.
private Base processDateConstant(Object appInfo, String value, ExpressionNode expr) throws PathEngineException {
String date = null;
String time = null;
String tz = null;
TemporalPrecisionEnum temp = null;
if (value.startsWith("T")) {
time = value.substring(1);
} else if (!value.contains("T")) {
date = value;
} else {
String[] p = value.split("T");
date = p[0];
if (p.length > 1) {
time = p[1];
}
}
if (time != null) {
int i = time.indexOf("-");
if (i == -1) {
i = time.indexOf("+");
}
if (i == -1) {
i = time.indexOf("Z");
}
if (i > -1) {
tz = time.substring(i);
time = time.substring(0, i);
}
if (time.length() == 2) {
time = time + ":00:00";
temp = TemporalPrecisionEnum.MINUTE;
} else if (time.length() == 5) {
temp = TemporalPrecisionEnum.MINUTE;
time = time + ":00";
} else if (time.contains(".")) {
temp = TemporalPrecisionEnum.MILLI;
} else {
temp = TemporalPrecisionEnum.SECOND;
}
}
if (date == null) {
if (tz != null) {
throw makeException(expr, I18nConstants.FHIRPATH_UNKNOWN_CONTEXT, value);
} else {
TimeType tt = new TimeType(time);
tt.setPrecision(temp);
return tt.noExtensions();
}
} else if (time != null) {
DateTimeType dt = new DateTimeType(date + "T" + time + (tz == null ? "" : tz));
dt.setPrecision(temp);
return dt.noExtensions();
} else {
return new DateType(date).noExtensions();
}
}
use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.
the class DateTimeTypeNullTest method equalsDeep.
@Test
@DisplayName("Test null value equalsDeep()")
void equalsDeep() {
DateTimeType nullDateTime = new DateTimeType();
DateTimeType validDateTime = new DateTimeType("1969-07-20");
Assertions.assertFalse(nullDateTime.equalsDeep(validDateTime));
}
use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.
the class ProfileDrivenRenderer method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
if (ew == null)
return;
Base e = ew.getBase();
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)
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);
renderDate(x, dt);
} else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} 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.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
} 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 {
x.an(rw.getId());
ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
rr.render(parent.blockquote(), rw);
}
}
} 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 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)) {
throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
}
}
use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method renderDateTime.
public void renderDateTime(XhtmlNode x, String s) {
if (s != null) {
DateTimeType dt = new DateTimeType(s);
x.addText(displayDateTime(dt));
}
}
use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method displayTiming.
private String displayTiming(Timing s) throws FHIRException {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (s.hasCode())
b.append("Code: " + displayCodeableConcept(s.getCode()));
if (s.getEvent().size() > 0) {
CommaSeparatedStringBuilder c = new CommaSeparatedStringBuilder();
for (DateTimeType p : s.getEvent()) {
if (p.hasValue()) {
c.append(displayDateTime(p));
} else if (!renderExpression(c, p)) {
c.append("??");
}
}
b.append("Events: " + c.toString());
}
if (s.hasRepeat()) {
TimingRepeatComponent rep = s.getRepeat();
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasStart())
b.append("Starting " + displayDateTime(rep.getBoundsPeriod().getStartElement()));
if (rep.hasCount())
b.append("Count " + Integer.toString(rep.getCount()) + " times");
if (rep.hasDuration())
b.append("Duration " + rep.getDuration().toPlainString() + displayTimeUnits(rep.getPeriodUnit()));
if (rep.hasWhen()) {
String st = "";
if (rep.hasOffset()) {
st = Integer.toString(rep.getOffset()) + "min ";
}
b.append("Do " + st);
for (Enumeration<EventTiming> wh : rep.getWhen()) b.append(displayEventCode(wh.getValue()));
} else {
String st = "";
if (!rep.hasFrequency() || (!rep.hasFrequencyMax() && rep.getFrequency() == 1))
st = "Once";
else {
st = Integer.toString(rep.getFrequency());
if (rep.hasFrequencyMax())
st = st + "-" + Integer.toString(rep.getFrequency());
}
if (rep.hasPeriod()) {
st = st + " per " + rep.getPeriod().toPlainString();
if (rep.hasPeriodMax())
st = st + "-" + rep.getPeriodMax().toPlainString();
st = st + " " + displayTimeUnits(rep.getPeriodUnit());
}
b.append("Do " + st);
}
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasEnd())
b.append("Until " + displayDateTime(rep.getBoundsPeriod().getEndElement()));
}
return b.toString();
}
Aggregations