Search in sources :

Example 1 with DvDateAttributes

use of org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes in project openEHR_SDK by ehrbase.

the class TemporalEncodingTest method testChronoFieldSupport2.

public void testChronoFieldSupport2() {
    YearMonth yearMonth = YearMonth.parse("2020-08");
    DvDate dvDate = new DvDate(yearMonth);
    // check supported ChronoField
    assertTrue(dvDate.getValue().isSupported(ChronoField.YEAR));
    assertTrue(dvDate.getValue().isSupported(ChronoField.MONTH_OF_YEAR));
    assertFalse(dvDate.getValue().isSupported(ChronoField.DAY_OF_MONTH));
    DvDateAttributes dvDateAttributes = DvDateAttributes.instanceFromValue(dvDate);
    assertTrue(dvDateAttributes.isRmDvDate());
    assertTrue(dvDateAttributes.isDateYYYYMM());
    assertFalse(dvDateAttributes.isDateYYYY());
    assertFalse(dvDateAttributes.isDateYYYYMMDD());
}
Also used : YearMonth(java.time.YearMonth) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) DvDateAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes)

Example 2 with DvDateAttributes

use of org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes in project openEHR_SDK by ehrbase.

the class DvDateAdapter method write.

@Override
public void write(JsonWriter writer, DvDate dvalue) throws IOException {
    if (dvalue == null) {
        writer.nullValue();
        return;
    }
    DvDateAttributes dvDateAttributes = DvDateAttributes.instanceFromValue(dvalue);
    if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
        writer.beginObject();
        writer.name(VALUE).value(dvDateAttributes.getValueAsProvided().toString());
        writer.name(EPOCH_OFFSET).value(dvDateAttributes.getTimeStamp());
        writer.endObject();
    } else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
        writer.beginObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
        writer.name(VALUE).value(dvalue.getValue().toString());
        writer.endObject();
    }
}
Also used : DvDateAttributes(org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase)

Example 3 with DvDateAttributes

use of org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes 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)

Aggregations

DvDateAttributes (org.ehrbase.serialisation.attributes.datavalues.datetime.date.DvDateAttributes)3 DvDate (com.nedap.archie.rm.datavalues.quantity.datetime.DvDate)2 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)1 YearMonth (java.time.YearMonth)1 Temporal (java.time.temporal.Temporal)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 DvTimeAttributes (org.ehrbase.serialisation.attributes.datavalues.datetime.time.DvTimeAttributes)1 ObjectSnakeCase (org.ehrbase.serialisation.util.ObjectSnakeCase)1