Search in sources :

Example 1 with DvDuration

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");
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) DvDuration(com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test) StatusesTest(care.better.platform.web.template.StatusesTest)

Example 2 with DvDuration

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");
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) DvDate(com.nedap.archie.rm.datavalues.quantity.datetime.DvDate) DvDuration(com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration) Test(org.junit.Test) StatusesTest(care.better.platform.web.template.StatusesTest)

Example 3 with DvDuration

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);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) DvDuration(com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration) Test(org.junit.Test) StatusesTest(care.better.platform.web.template.StatusesTest)

Example 4 with DvDuration

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));
    }
}
Also used : Period(java.time.Period) DvDuration(com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration) Duration(java.time.Duration) PeriodDuration(org.threeten.extra.PeriodDuration)

Example 5 with DvDuration

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());
}
Also used : DvDuration(com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration) Test(org.junit.jupiter.api.Test)

Aggregations

DvDuration (com.nedap.archie.rm.datavalues.quantity.datetime.DvDuration)10 Test (org.junit.Test)5 StatusesTest (care.better.platform.web.template.StatusesTest)4 Composition (com.nedap.archie.rm.composition.Composition)4 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)4 Test (org.junit.jupiter.api.Test)3 DvDate (com.nedap.archie.rm.datavalues.quantity.datetime.DvDate)1 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)1 DvTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvTime)1 Duration (java.time.Duration)1 Period (java.time.Period)1 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)1 PeriodDuration (org.threeten.extra.PeriodDuration)1