Search in sources :

Example 36 with Timing

use of org.hl7.fhir.dstu2.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();
}
Also used : EventTiming(org.hl7.fhir.r5.model.Timing.EventTiming) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) BaseDateTimeType(org.hl7.fhir.r5.model.BaseDateTimeType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TimingRepeatComponent(org.hl7.fhir.r5.model.Timing.TimingRepeatComponent)

Example 37 with Timing

use of org.hl7.fhir.dstu2.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;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) Timing(org.hl7.fhir.r4.model.Timing)

Example 38 with Timing

use of org.hl7.fhir.dstu2.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);
}
Also used : TimeZone(java.util.TimeZone) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) Timing(org.hl7.fhir.r4.model.Timing) InstantType(org.hl7.fhir.r4.model.InstantType) Date(java.util.Date) Pair(org.javatuples.Pair)

Example 39 with Timing

use of org.hl7.fhir.dstu2.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;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Period(org.hl7.fhir.r4.model.Period) CodeType(org.hl7.fhir.r4.model.CodeType) List(java.util.List) ArrayList(java.util.ArrayList) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 40 with Timing

use of org.hl7.fhir.dstu2.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;
}
Also used : Instant(java.time.Instant) Duration(org.hl7.fhir.r4.model.Duration)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Timing (org.hl7.fhir.r4.model.Timing)11 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)10 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)8 Base64 (org.apache.commons.codec.binary.Base64)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Timing (org.hl7.fhir.dstu3.model.Timing)5 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)5 Reference (org.hl7.fhir.dstu3.model.Reference)4 EventTiming (org.hl7.fhir.dstu3.model.Timing.EventTiming)4 TimingRepeatComponent (org.hl7.fhir.dstu3.model.Timing.TimingRepeatComponent)4 BigDecimal (java.math.BigDecimal)3 Dosage (org.hl7.fhir.r4.model.Dosage)3 Period (org.hl7.fhir.r4.model.Period)3 Quantity (org.hl7.fhir.r4.model.Quantity)3 TimingRepeatComponent (org.hl7.fhir.r4.model.Timing.TimingRepeatComponent)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3