Search in sources :

Example 1 with Precision

use of org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.Precision in project MobileAccessGateway by i4mi.

the class BaseQueryResponseConverter method transformToDate.

/**
 * XDS Timestamp -> FHIR Date
 * @param timestamp
 * @return
 */
public DateType transformToDate(Timestamp timestamp) {
    if (timestamp == null)
        return null;
    Date date = Date.from(timestamp.getDateTime().toInstant());
    Precision precision = timestamp.getPrecision();
    TemporalPrecisionEnum fhirPrecision;
    switch(precision) {
        case YEAR:
            fhirPrecision = TemporalPrecisionEnum.YEAR;
            break;
        case DAY:
            fhirPrecision = TemporalPrecisionEnum.DAY;
            break;
        // case SECOND: fhirPrecision = TemporalPrecisionEnum.SECOND;break;
        default:
            fhirPrecision = TemporalPrecisionEnum.DAY;
            break;
    }
    return new DateType(date, fhirPrecision);
}
Also used : Precision(org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.Precision) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) DateType(org.hl7.fhir.r4.model.DateType) Date(java.util.Date)

Example 2 with Precision

use of org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.Precision in project MobileAccessGateway by i4mi.

the class BaseQueryResponseConverter method transform.

/**
 * XDS timestamp -> FHIR DateTime
 * @param timestamp
 * @return
 */
public DateTimeType transform(Timestamp timestamp) {
    if (timestamp == null)
        return null;
    Date date = Date.from(timestamp.getDateTime().toInstant());
    Precision precision = timestamp.getPrecision();
    TemporalPrecisionEnum fhirPrecision;
    switch(precision) {
        case YEAR:
            fhirPrecision = TemporalPrecisionEnum.YEAR;
            break;
        case DAY:
            fhirPrecision = TemporalPrecisionEnum.DAY;
            break;
        // There is no mapping for HOUR; MINUTE is not accepted
        case HOUR:
            fhirPrecision = TemporalPrecisionEnum.SECOND;
            break;
        case MINUTE:
            fhirPrecision = TemporalPrecisionEnum.SECOND;
            break;
        case SECOND:
            fhirPrecision = TemporalPrecisionEnum.SECOND;
            break;
        default:
            fhirPrecision = TemporalPrecisionEnum.MILLI;
            break;
    }
    return new DateTimeType(date, fhirPrecision);
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Precision(org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.Precision) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Date(java.util.Date)

Aggregations

TemporalPrecisionEnum (ca.uhn.fhir.model.api.TemporalPrecisionEnum)2 Date (java.util.Date)2 Precision (org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.Precision)2 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 DateType (org.hl7.fhir.r4.model.DateType)1