Search in sources :

Example 26 with DateType

use of org.hl7.fhir.dstu2.model.DateType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcToday.

private List<Base> funcToday(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    result.add(new DateType(new Date(), TemporalPrecisionEnum.DAY));
    return result;
}
Also used : ArrayList(java.util.ArrayList) DateType(org.hl7.fhir.r4b.model.DateType) Base(org.hl7.fhir.r4b.model.Base) Date(java.util.Date)

Example 27 with DateType

use of org.hl7.fhir.dstu2.model.DateType 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();
    }
}
Also used : BaseDateTimeType(org.hl7.fhir.r4b.model.BaseDateTimeType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) DateType(org.hl7.fhir.r4b.model.DateType) BaseDateTimeType(org.hl7.fhir.r4b.model.BaseDateTimeType) TimeType(org.hl7.fhir.r4b.model.TimeType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType)

Example 28 with DateType

use of org.hl7.fhir.dstu2.model.DateType in project org.hl7.fhir.core by hapifhir.

the class DateTypeNullTest method copy.

@Test
@DisplayName("Test null value copy()")
void copy() {
    DateType nullDate = new DateType();
    DateType copyDate = nullDate.copy();
    Assertions.assertNull(copyDate.getValue());
}
Also used : DateType(org.hl7.fhir.r4b.model.DateType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with DateType

use of org.hl7.fhir.dstu2.model.DateType in project org.hl7.fhir.core by hapifhir.

the class DateTypeNullTest method testToString.

@Test
@DisplayName("Test null value toString()")
void testToString() {
    DateType nullDate = new DateType();
    System.out.println("Value -> " + nullDate);
}
Also used : DateType(org.hl7.fhir.r4b.model.DateType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 30 with DateType

use of org.hl7.fhir.dstu2.model.DateType in project org.hl7.fhir.core by hapifhir.

the class DateTypeNullTest method equalsDeep.

@Test
@DisplayName("Test null value equalsDeep()")
void equalsDeep() {
    DateType nullDate = new DateType();
    DateType validDate = new DateType("1969-07-20");
    Assertions.assertFalse(nullDate.equalsDeep(validDate));
}
Also used : DateType(org.hl7.fhir.r4b.model.DateType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DateType (org.hl7.fhir.r4.model.DateType)36 Test (org.junit.jupiter.api.Test)21 Date (java.util.Date)17 Coding (org.hl7.fhir.r4.model.Coding)15 Test (org.junit.Test)11 SupportingInformationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent)10 DateType (org.hl7.fhir.r4b.model.DateType)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ArrayList (java.util.ArrayList)8 DateType (org.hl7.fhir.r5.model.DateType)8 DateType (org.hl7.fhir.dstu3.model.DateType)7 Extension (org.hl7.fhir.r4.model.Extension)6 Calendar (java.util.Calendar)5 DisplayName (org.junit.jupiter.api.DisplayName)5 InvalidRifValueException (gov.cms.bfd.model.rif.parse.InvalidRifValueException)4 DateType (org.hl7.fhir.dstu2016may.model.DateType)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 Patient (org.hl7.fhir.r4.model.Patient)4 Reference (org.hl7.fhir.r4.model.Reference)4