use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project openEHR_SDK by ehrbase.
the class HistoryPostprocessor method process.
/**
* {@inheritDoc}
*/
@Override
public void process(String term, History rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
setValue(term + PATH_DIVIDER + "history_origin", null, values, s -> {
if (s != null) {
rmObject.setOrigin(new DvDateTime(s));
}
}, String.class, consumedPaths);
if (rmObject.getOrigin() == null || rmObject.getOrigin().getValue() == null) {
Optional<TemporalAccessor> first = ((History<ItemStructure>) rmObject).getEvents().stream().map(Event::getTime).filter(Objects::nonNull).map(DvDateTime::getValue).filter(Objects::nonNull).sorted().findFirst();
first.ifPresent(temporalAccessor -> ((History<ItemStructure>) rmObject).setOrigin(new DvDateTime(temporalAccessor)));
}
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime 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);
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project openEHR_SDK by ehrbase.
the class FeederAudiDetailsStdConfig method buildChildValues.
@Override
public /**
* {@inheritDoc}
*/
Map<String, Object> buildChildValues(String currentTerm, FeederAuditDetails rmObject, Context<Map<String, Object>> context) {
Map<String, Object> result = new HashMap<>();
addValue(result, currentTerm, "time", Optional.ofNullable(rmObject.getTime()).map(DvDateTime::getValue).orElse(null));
addValue(result, currentTerm, "system_id", rmObject.getSystemId());
addValue(result, currentTerm, "version_id", rmObject.getVersionId());
if (rmObject.getLocation() != null) {
StdConfig stdConfig = findStdConfig(rmObject.getLocation().getClass());
result.putAll(stdConfig.buildChildValues(currentTerm + "/location", rmObject.getLocation(), context));
}
if (rmObject.getProvider() != null) {
StdConfig stdConfig = findStdConfig(rmObject.getProvider().getClass());
result.putAll(stdConfig.buildChildValues(currentTerm + "/provider", rmObject.getProvider(), context));
}
if (rmObject.getSubject() != null) {
StdConfig stdConfig = findStdConfig(rmObject.getSubject().getClass());
result.putAll(stdConfig.buildChildValues(currentTerm + "/subject", rmObject.getSubject(), context));
}
return result;
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project openEHR_SDK by ehrbase.
the class CanonicalJsonMarshallingTest method MarshalDvDateTime.
// check that dot is not converted into a comma!
@Test
public void MarshalDvDateTime() {
DvDateTime dvDateTime = new DvDateTime("2021-10-01T10:32:51.543+07:00");
CanonicalJson cut = new CanonicalJson();
String actual = cut.marshal(dvDateTime);
assertThat(actual).isEqualToIgnoringWhitespace("{" + " \"_type\" : \"DV_DATE_TIME\"," + " \"value\" : \"2021-10-01T10:32:51.543+07:00\"" + "}");
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime in project openEHR_SDK by ehrbase.
the class DBEncodeTest method testDBDecodeDvIntervalCompositeClass.
@Test
public void testDBDecodeDvIntervalCompositeClass() throws Exception {
String db_encoded = IOUtils.resourceToString("/composition/canonical_json/composition_with_dvinterval_composite.json", UTF_8);
assertNotNull(db_encoded);
JsonElement converted = new LightRawJsonEncoder(db_encoded).encodeContentAsJson(null);
// see if this can be interpreted by Archie
Composition composition = new CanonicalJson().unmarshal(converted.toString(), Composition.class);
// hack the composition to figure out what is the format of DvInterval...
((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setLower(new DvDateTime("2019-11-22T00:00+01:00"));
((DvInterval) ((Element) ((AdminEntry) composition.getContent().get(0)).getData().getItems().get(0)).getValue()).setUpper(new DvDateTime("2019-12-22T00:00+01:00"));
assertNotNull(composition);
String toJson = new CanonicalJson().marshal(composition);
String interpreted = new CanonicalXML().marshal(composition);
assertNotNull(interpreted);
}
Aggregations