use of org.hl7.fhir.r4.model.Timing 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();
}
use of org.hl7.fhir.r4.model.Timing in project eCRNow by drajer-health.
the class CdaFhirUtilities method getXmlForTypeForValueIvlTsEffectiveTime.
public static String getXmlForTypeForValueIvlTsEffectiveTime(String elName, Type dt) {
String val = "";
if (dt != null) {
if (dt instanceof DateTimeType) {
DateTimeType d = (DateTimeType) dt;
val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
} else if (dt instanceof Period) {
Period pt = (Period) dt;
val += getPeriodXml(pt, elName);
} else if (dt instanceof Timing) {
Timing t = (Timing) (dt);
if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
logger.debug("Found the bounds element for creating xml");
}
}
logger.debug("Printing the class name {}", dt.getClass());
return val;
}
return val;
}
use of org.hl7.fhir.r4.model.Timing in project eCRNow by drajer-health.
the class CdaFhirUtilities method getActualDate.
public static Pair<Date, TimeZone> getActualDate(Type dt) {
Date d = null;
TimeZone t = null;
if (dt instanceof DateTimeType) {
DateTimeType d1 = (DateTimeType) dt;
d = d1.getValue();
t = d1.getTimeZone();
} else if (dt instanceof Period) {
logger.debug("Found an instance of period");
Period d1 = (Period) dt;
if (d1.getStartElement() != null) {
d = d1.getStart();
t = d1.getStartElement().getTimeZone();
} else if (d1.getEndElement() != null) {
d = d1.getEnd();
t = d1.getEndElement().getTimeZone();
}
} else if (dt instanceof InstantType) {
InstantType d1 = (InstantType) dt;
d = d1.getValue();
t = d1.getTimeZone();
} else if (dt instanceof Timing) {
logger.debug(" Found an instance of timing ");
Timing tmg = (Timing) (dt);
if (tmg.getRepeat() != null && tmg.getRepeat().getBounds() != null) {
logger.debug(" Found the bounds element ");
return getActualDate(tmg.getRepeat().getBounds());
}
}
return new Pair<>(d, t);
}
use of org.hl7.fhir.r4.model.Timing in project eCRNow by drajer-health.
the class CdaFhirUtilities method getXmlForType.
public static String getXmlForType(Type dt, String elName, Boolean valFlag) {
String val = "";
if (dt != null) {
if (dt instanceof Coding) {
Coding cd = (Coding) dt;
List<Coding> cds = new ArrayList<>();
cds.add(cd);
if (!valFlag)
val += getCodingXml(cds, elName, "");
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof CodeableConcept) {
CodeableConcept cd = (CodeableConcept) dt;
List<Coding> cds = cd.getCoding();
if (!valFlag)
val += getCodingXml(cds, elName, "");
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof Quantity) {
Quantity qt = (Quantity) dt;
val += getQuantityXml(qt, elName, valFlag);
} else if (dt instanceof DateTimeType) {
DateTimeType d = (DateTimeType) dt;
val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
} else if (dt instanceof Period) {
Period pt = (Period) dt;
val += getPeriodXml(pt, elName);
} else if (dt instanceof Timing) {
Timing t = (Timing) (dt);
if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
logger.debug("Found the bounds element for creating xml");
String v = getXmlForType(t.getRepeat().getBounds(), elName, valFlag);
val += v;
}
} else if (dt instanceof CodeType) {
CodeType cd = (CodeType) dt;
if (!valFlag)
val += CdaGeneratorUtils.getXmlForCD(elName, cd.getCode());
else
val += CdaGeneratorUtils.getXmlForValueString(cd.getCode());
} else if (dt instanceof StringType) {
StringType st = (StringType) dt;
if (!valFlag)
val += CdaGeneratorUtils.getXmlForText(elName, st.getValue());
else
val += CdaGeneratorUtils.getXmlForValueString(st.getValue());
}
logger.debug("Printing the class name {}", dt.getClass());
return val;
}
if (!valFlag)
val += CdaGeneratorUtils.getNFXMLForElement(elName, CdaGeneratorConstants.NF_NI);
else
val += CdaGeneratorUtils.getNFXmlForValueString(CdaGeneratorConstants.NF_NI);
return val;
}
use of org.hl7.fhir.r4.model.Timing in project eCRNow by drajer-health.
the class ApplicationUtils method convertTimingScheduleToInstant.
public static Instant convertTimingScheduleToInstant(TimingSchedule ts, Date timeRef) {
Instant t = null;
Duration d = new Duration();
if (ts.getDurationUnit() != null) {
logger.debug("Found Duration for Timing Schedule");
logger.debug(" Duration before conversion = {}", ts.getDuration());
logger.debug(" Duration Unit = {}", ts.getDurationUnit());
d.setValue(ts.getDuration());
d.setUnit(ts.getDurationUnit().toCode());
logger.debug(" Duration during conversion = {}", d.getValue());
logger.debug(" Duration Unit = {}", d.getUnit());
} else if (ts.getFrequencyPeriodUnit() != null) {
logger.debug("Found Frequency for Timing Schedule ");
d.setValue(ts.getFrequencyPeriod());
d.setUnit(ts.getFrequencyPeriodUnit().toCode());
} else {
d.setValue(0);
d.setUnit("s");
}
t = convertDurationToInstant(d);
return t;
}
Aggregations