use of com.nedap.archie.rm.datavalues.quantity.DvQuantity in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflattenAltEvent.
@Test
public void testUnflattenAltEvent() {
AlternativeEventsComposition alternativeEventsComposition = buildAlternativeEventsComposition();
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
Composition actual = (Composition) cut.unflatten(alternativeEventsComposition);
assertThat(actual).isNotNull();
assertThat(actual.getContent()).size().isEqualTo(1);
Observation actualObservation = (Observation) actual.getContent().get(0);
assertThat(actualObservation.getData().getEvents()).size().isEqualTo(3);
assertThat(actualObservation.getData().getEvents()).extracting(e -> (Class) e.getClass()).containsExactlyInAnyOrder(PointEvent.class, PointEvent.class, IntervalEvent.class);
List<PointEvent> pointEvents = actualObservation.getData().getEvents().stream().filter(e -> PointEvent.class.isAssignableFrom(e.getClass())).map(e -> (PointEvent) e).collect(Collectors.toList());
assertThat(pointEvents).extracting(p -> p.getTime().getValue(), p -> ((DvQuantity) ((Element) p.getData().getItems().get(0)).getValue()).getMagnitude(), p -> ((DvQuantity) ((Element) p.getData().getItems().get(0)).getValue()).getUnits()).containsExactlyInAnyOrder(new Tuple(OffsetDateTime.of(1990, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC), 30d, "kg"), new Tuple(OffsetDateTime.of(2013, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC), 55d, "kg"));
List<IntervalEvent> intervalEvents = actualObservation.getData().getEvents().stream().filter(e -> IntervalEvent.class.isAssignableFrom(e.getClass())).map(e -> (IntervalEvent) e).collect(Collectors.toList());
assertThat(intervalEvents).extracting(p -> p.getTime().getValue(), p -> ((DvQuantity) ((Element) p.getData().getItems().get(0)).getValue()).getMagnitude(), p -> ((DvQuantity) ((Element) p.getData().getItems().get(0)).getValue()).getUnits(), p -> p.getMathFunction().getValue(), p -> p.getWidth().getValue()).containsExactlyInAnyOrder(new Tuple(OffsetDateTime.of(2015, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC), 60d, "kg", "mean", Duration.ofDays(30)));
}
use of com.nedap.archie.rm.datavalues.quantity.DvQuantity in project openEHR_SDK by ehrbase.
the class StatusesTestOverwrite method quantity.
@Override
@Test
public void quantity() 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/quantity|unit", "m", "test_statuses/test_statuses:0/quantity|magnitude", 1, "test_statuses/test_statuses:0/quantity|normal_status", "L", "test_statuses/test_statuses:0/quantity|magnitude_status", ">=", "test_statuses/test_statuses:0/quantity|accuracy", 10.0, "test_statuses/test_statuses:0/quantity|accuracy_is_percent", true);
RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
DvQuantity rmObject = (DvQuantity) composition.itemAtPath("/content[openEHR-EHR-OBSERVATION.test_statuses.v0]/data[at0001]/events[at0002]/data[at0003]/items[at0010]/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/quantity|normal_status", "L").containsEntry("test_statuses/test_statuses:0/quantity|magnitude_status", ">=").containsEntry("test_statuses/test_statuses:0/quantity|accuracy", 10.0).containsEntry("test_statuses/test_statuses:0/quantity|accuracy_is_percent", true);
}
use of com.nedap.archie.rm.datavalues.quantity.DvQuantity in project openEHR_SDK by ehrbase.
the class FlatJsonUnmarshallerTest method unmarshalAllTypes.
@Test
public void unmarshalAllTypes() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
WebTemplate webTemplate = new OPTParser(template).parse();
FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
String flat = IOUtils.toString(CompositionTestDataSimSDTJson.ALL_TYPES.getStream(), StandardCharsets.UTF_8);
Composition actual = cut.unmarshal(flat, webTemplate);
assertThat(actual).isNotNull();
// Choice Node was correctly parsed
Object choice = actual.itemAtPath("/content[openEHR-EHR-EVALUATION.test_all_types.v1]/data[at0001]/items[at0009]/value");
assertThat(choice).isNotNull();
assertThat(choice.getClass()).isEqualTo(DvQuantity.class);
assertThat(((DvQuantity) choice).getMagnitude()).isEqualTo(148.01210165023804d);
assertThat(((DvQuantity) choice).getUnits()).isEqualTo("mm[H20]");
}
use of com.nedap.archie.rm.datavalues.quantity.DvQuantity in project openEHR_SDK by ehrbase.
the class DvQuantityValidatorTest method testValidate.
@Test
void testValidate() throws Exception {
var node = parseNode("/webtemplate_nodes/dv_quantity.json");
var result = validator.validate(new DvQuantity("kg", 100.0, 1L), node);
assertTrue(result.isEmpty());
}
use of com.nedap.archie.rm.datavalues.quantity.DvQuantity in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflatten.
@Test
public void testUnflatten() {
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
BloodpressureListDe dto = buildExampleBloodpressureListDe();
Composition rmObject = (Composition) cut.unflatten(dto);
assertThat(rmObject).isNotNull();
assertThat(rmObject.itemAtPath("/context/start_time/value")).isEqualTo(dto.getStartTime());
List<Object> observationList = rmObject.itemsAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]");
assertThat(observationList).size().isEqualTo(2);
List<Double> systolischValues = observationList.stream().map(o -> (Observation) o).map(o -> (Element) o.itemAtPath("/data[at0001]/events[at0002]/data[at0003]/items[at0004]")).map(e -> (DvQuantity) e.getValue()).map(DvQuantity::getMagnitude).collect(Collectors.toList());
assertThat(systolischValues).containsExactlyInAnyOrder(12d, 22d);
}
Aggregations