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());
}
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();
}
}
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);
}
Aggregations