use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration in project openEHR_SDK by ehrbase.
the class StatusesTestOverwrite method dateTime.
@Override
@Test
public void dateTime() throws Exception {
String template = this.getFileContent("/res/test_statuses.opt");
Map<String, Object> flatComposition = Map.of("ctx/language", "sl", "ctx/territory", "SI", "ctx/composer_name", "George Orwell", "test_statuses/test_statuses:0/datetime", "2017-10-01T13:20:00Z", "test_statuses/test_statuses:0/datetime|normal_status", "L", "test_statuses/test_statuses:0/datetime|magnitude_status", ">=", "test_statuses/test_statuses:0/datetime/_accuracy", "P1Y");
RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
DvDateTime rmObject = (DvDateTime) composition.itemAtPath("/content[openEHR-EHR-OBSERVATION.test_statuses.v0]/data[at0001]/events[at0002]/data[at0003]/items[at0013]/value");
assertThat(rmObject.getNormalStatus()).isNotNull();
assertThat(rmObject.getNormalStatus().getTerminologyId().getValue()).isEqualTo("openehr_normal_statuses");
assertThat(rmObject.getNormalStatus().getCodeString()).isEqualTo("L");
assertThat(rmObject.getMagnitudeStatus()).isEqualTo(">=");
assertThat(rmObject.getAccuracy()).isNotNull().extracting(DvDuration::getValue).extracting(Object::toString).isEqualTo("P1Y");
Map<String, Object> value = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
assertThat(value).containsEntry("test_statuses/test_statuses:0/datetime|normal_status", "L").containsEntry("test_statuses/test_statuses:0/datetime|magnitude_status", ">=").containsEntry("test_statuses/test_statuses:0/datetime/_accuracy", "P1Y");
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration in project openEHR_SDK by ehrbase.
the class StatusesTestOverwrite method date.
@Override
@Test
public void date() throws Exception {
String template = this.getFileContent("/res/test_statuses.opt");
Map<String, Object> flatComposition = Map.of("ctx/language", "sl", "ctx/territory", "SI", "ctx/composer_name", "George Orwell", "test_statuses/test_statuses:0/date", "2017-10-01", "test_statuses/test_statuses:0/date|normal_status", "L", "test_statuses/test_statuses:0/date|magnitude_status", ">=", "test_statuses/test_statuses:0/date/_accuracy", "P1Y");
RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
DvDate rmObject = (DvDate) composition.itemAtPath("/content[openEHR-EHR-OBSERVATION.test_statuses.v0]/data[at0001]/events[at0002]/data[at0003]/items[at0011]/value");
assertThat(rmObject.getNormalStatus()).isNotNull();
assertThat(rmObject.getNormalStatus().getTerminologyId().getValue()).isEqualTo("openehr_normal_statuses");
assertThat(rmObject.getNormalStatus().getCodeString()).isEqualTo("L");
assertThat(rmObject.getMagnitudeStatus()).isEqualTo(">=");
assertThat(rmObject.getAccuracy()).isNotNull().extracting(DvDuration::getValue).extracting(Object::toString).isEqualTo("P1Y");
Map<String, Object> value = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
assertThat(value).containsEntry("test_statuses/test_statuses:0/date|normal_status", "L").containsEntry("test_statuses/test_statuses:0/date|magnitude_status", ">=").containsEntry("test_statuses/test_statuses:0/date/_accuracy", "P1Y");
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration in project openEHR_SDK by ehrbase.
the class StatusesTestOverwrite method duration.
@Override
@Test
public void duration() throws Exception {
String template = this.getFileContent("/res/test_statuses.opt");
Map<String, Object> flatComposition = Map.of("ctx/language", "sl", "ctx/territory", "SI", "ctx/id_scheme", "ispek", "ctx/id_namespace", "ispek", "ctx/composer_name", "George Orwell", "test_statuses/test_statuses:0/duration", "P1Y", "test_statuses/test_statuses:0/duration|normal_status", "L", "test_statuses/test_statuses:0/duration|magnitude_status", ">=", "test_statuses/test_statuses:0/duration|accuracy", 10.0, "test_statuses/test_statuses:0/duration|accuracy_is_percent", true);
RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
DvDuration rmObject = (DvDuration) composition.itemAtPath("/content[openEHR-EHR-OBSERVATION.test_statuses.v0]/data[at0001]/events[at0002]/data[at0003]/items[at0009]/value");
assertThat(rmObject.getNormalStatus()).isNotNull();
assertThat(rmObject.getNormalStatus().getTerminologyId().getValue()).isEqualTo("openehr_normal_statuses");
assertThat(rmObject.getNormalStatus().getCodeString()).isEqualTo("L");
assertThat(rmObject.getMagnitudeStatus()).isEqualTo(">=");
assertThat(rmObject.getAccuracy()).isEqualTo(10);
assertThat(rmObject.getAccuracyIsPercent()).isTrue();
Map<String, Object> value = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
assertThat(value).containsEntry("test_statuses/test_statuses:0/duration|normal_status", "L").containsEntry("test_statuses/test_statuses:0/duration|magnitude_status", ">=").containsEntry("test_statuses/test_statuses:0/duration|accuracy", 10.0).containsEntry("test_statuses/test_statuses:0/duration|accuracy_is_percent", true);
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration in project openEHR_SDK by ehrbase.
the class DvDurationRMUnmarshaller method handle.
@Override
public void handle(String currentTerm, DvDuration rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, null, currentValues, s -> {
if (s != null) {
rmObject.setValue(DateTimeParsers.parseDurationValue(s));
}
}, String.class, consumedPaths);
if (rmObject.getValue() == null) {
Period year = Period.ofYears(getDurationComponent(currentTerm, currentValues, consumedPaths, "year"));
Period month = Period.ofMonths(getDurationComponent(currentTerm, currentValues, consumedPaths, "month"));
Period week = Period.ofWeeks(getDurationComponent(currentTerm, currentValues, consumedPaths, "week"));
Period day = Period.ofDays(getDurationComponent(currentTerm, currentValues, consumedPaths, "day"));
Period totalPeriod = Period.from(year).plus(month).plus(week).plus(day);
Duration hour = Duration.ofHours(getDurationComponent(currentTerm, currentValues, consumedPaths, "hour"));
Duration minute = Duration.ofHours(getDurationComponent(currentTerm, currentValues, consumedPaths, "minute"));
Duration second = Duration.ofHours(getDurationComponent(currentTerm, currentValues, consumedPaths, "second"));
Duration totalDuration = Duration.from(hour).plus(minute).plus(second);
rmObject.setValue(PeriodDuration.of(totalPeriod, totalDuration));
}
}
use of com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration in project openEHR_SDK by ehrbase.
the class DvDurationValidatorTest method testValidate_Duration.
@Test
void testValidate_Duration() throws Exception {
var node = parseNode("/webtemplate_nodes/dv_duration_duration.json");
var result = validator.validate(new DvDuration("PT10H20M10S"), node);
assertTrue(result.isEmpty());
result = validator.validate(new DvDuration("PT20H45M45S"), node);
assertFalse(result.isEmpty());
}
Aggregations