Search in sources :

Example 6 with DvDate

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDate in project openEHR_SDK by ehrbase.

the class CompareCanonicalDvDate method isExpectedEqualToCanonicalUsing.

public Object isExpectedEqualToCanonicalUsing(DvDate referenceDate) {
    // check each date/time part separately
    Format formatter = DateTimeFormatter.ISO_LOCAL_DATE.toFormat();
    DvDate actualDvDate = new DvDate(formatter.format(dvDate.getValue()));
    DvDate expectedDvDate = new DvDate(formatter.format(referenceDate.getValue()));
    // perform comparison of parts
    DatePartComparator.compare(actualDvDate, expectedDvDate);
    return null;
}
Also used : Format(java.text.Format) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate)

Example 7 with DvDate

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDate in project openEHR_SDK by ehrbase.

the class CompareCanonicalDvDateTime method isExpectedEqualToCanonicalUsing.

public Object isExpectedEqualToCanonicalUsing(DvDateTime referenceDateTime) {
    // check each date/time part separately
    Format formatter = DateTimeFormatter.ISO_LOCAL_DATE.toFormat();
    DvDate actualDvDate = new DvDate(formatter.format(dvDateTime.getValue()));
    DvDate expectedDvDate = new DvDate(formatter.format(referenceDateTime.getValue()));
    formatter = DateTimeFormatter.ISO_LOCAL_TIME.toFormat();
    DvTime actualDvTime = new DvTime(formatter.format(dvDateTime.getValue()));
    DvTime expectedDvTime = new DvTime(formatter.format(referenceDateTime.getValue()));
    ZoneOffset actualZoneOffset = ZoneOffset.from(dvDateTime.getValue());
    ZoneOffset expectedZoneOffset = ZoneOffset.from(referenceDateTime.getValue());
    // perform comparison of parts
    DatePartComparator.compare(actualDvDate, expectedDvDate);
    if (!compareDateOnly)
        TimePartComparator.compare(actualDvTime, expectedDvTime);
    ZoneOffsetPartComparator.compare(actualZoneOffset, expectedZoneOffset);
    return null;
}
Also used : Format(java.text.Format) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) DvTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvTime) ZoneOffset(java.time.ZoneOffset)

Example 8 with DvDate

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDate in project openEHR_SDK by ehrbase.

the class CompareCanonicalDvDateTimeTest method testComparatorDvDate.

@Test
public void testComparatorDvDate() {
    DvDate dvDate = (DvDate) toRmObject(jsonDvDateRef, DvDate.class);
    assertThat(new CompareCanonicalDvDate(dvDate).isExpectedEqualToCanonicalUsing(dvDate)).isNull();
}
Also used : DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) Test(org.junit.Test)

Example 9 with DvDate

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDate in project openEHR_SDK by ehrbase.

the class DvDateTimeAttributes method instanceFromValue.

public static DvDateTimeAttributes instanceFromValue(DvDateTime dvDateTime) {
    TemporalAccessor localDate;
    TemporalAccessor actual = dvDateTime.getValue();
    if (actual.isSupported(ChronoField.YEAR) && actual.isSupported(ChronoField.MONTH_OF_YEAR) && actual.isSupported(ChronoField.DAY_OF_MONTH))
        localDate = LocalDate.of(actual.get(ChronoField.YEAR), actual.get(ChronoField.MONTH_OF_YEAR), actual.get(ChronoField.DAY_OF_MONTH));
    else if (actual.isSupported(ChronoField.YEAR) && actual.isSupported(ChronoField.MONTH_OF_YEAR))
        localDate = YearMonth.of(actual.get(ChronoField.YEAR), actual.get(ChronoField.MONTH_OF_YEAR));
    else if (actual.isSupported(ChronoField.YEAR))
        localDate = Year.of(actual.get(ChronoField.YEAR));
    else
        throw new IllegalArgumentException("DvDateTime supplied is not valid:" + actual);
    DvTimeAttributes dvTimeAttributes = DvTimeAttributes.instanceFromValue(dvDateTime.getValue());
    DvDateAttributes dvDateAttributes = DvDateAttributes.instanceFromValue(new DvDate((Temporal) localDate));
    if (dvTimeAttributes == null) {
        dvDateTime = new DvDateTime(dvDateAttributes.getValueAsProvided());
    }
    return new DvDateTimeAttributes(dvDateTime, dvDateAttributes, dvTimeAttributes);
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) Temporal(java.time.temporal.Temporal) DvTimeAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.time.DvTimeAttributes) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) DvDateAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 10 with DvDate

use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDate in project openEHR_SDK by ehrbase.

the class DvDateValidatorTest method testValidate.

@Test
void testValidate() throws Exception {
    var node = parseNode("/webtemplate_nodes/dv_date.json");
    var result = validator.validate(new DvDate(LocalDate.now()), node);
    assertTrue(result.isEmpty());
}
Also used : DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) Test(org.junit.jupiter.api.Test)

Aggregations

DvDate (com.nedap.archie.rm.datavalues.quantity.datetime.DvDate)10 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 Format (java.text.Format)2 DvDateAttributes (org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes)2 StatusesTest (care.better.platform.web.template.StatusesTest)1 Composition (com.nedap.archie.rm.composition.Composition)1 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)1 DvDuration (com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration)1 DvTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvTime)1 YearMonth (java.time.YearMonth)1 ZoneOffset (java.time.ZoneOffset)1 Temporal (java.time.temporal.Temporal)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)1 DvTimeAttributes (org.ehrbase.serialisation.attributes.datavalues.datetime.time.DvTimeAttributes)1