use of com.nedap.archie.rm.datastructures.Element 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.datastructures.Element in project openEHR_SDK by ehrbase.
the class DBEncodeTest method compositionEncodingFeederAuditDetails.
@Test
public void compositionEncodingFeederAuditDetails() throws Exception {
String value = IOUtils.toString(CompositionTestDataCanonicalJson.FEEDER_AUDIT_DETAILS.getStream(), UTF_8);
CanonicalJson cut = new CanonicalJson();
Composition composition = cut.unmarshal(value, Composition.class);
// check compo
assertNotNull(composition);
assertNotNull(composition.getFeederAudit().getFeederSystemAudit());
// other details
assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
assertEquals("family group", composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getName().getValue());
assertTrue(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails() instanceof ItemTree);
assertEquals(1, composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().size());
assertTrue(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().get(0) instanceof Element);
assertTrue(((Element) composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().get(0)).getValue() instanceof DvIdentifier);
// version id
assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getVersionId());
assertEquals("final", composition.getFeederAudit().getFeederSystemAudit().getVersionId());
// DB encode other details
CompositionSerializer compositionSerializerRawJson = new CompositionSerializer();
String dbEncoded = compositionSerializerRawJson.dbEncode(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
assertNotNull(dbEncoded);
// Convert encoded string into map to write to DB
Map<String, Object> asMap = new LightRawJsonEncoder(dbEncoded).encodeOtherDetailsAsMap();
assertNotNull(asMap);
assertEquals(4, asMap.size());
assertNotNull(asMap.get("/items[at0001]"));
// Attribute mapping and correct archetype node id path in naming
Map<String, Object> map = new FeederAuditAttributes(composition.getFeederAudit()).toMap();
assertNotNull(map);
assertNotNull(map.get("feeder_system_audit"));
Map<String, Object> feederMap = (Map) map.get("feeder_system_audit");
assertNotNull(feederMap);
assertNotNull(feederMap.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]"));
assertEquals(4, ((Map<String, Object>) feederMap.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]")).size());
}
use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.
the class NullFlavorTestOverwritten method nullFlavourMapBuild.
@Test
public void nullFlavourMapBuild() throws Exception {
String template = this.getFileContent("/res/Demo Vitals.xml");
String json = this.getFileContent("/res/NullFlavor4.json");
Composition unmarshal = getFlatJson(template, FlatFormat.SIM_SDT).unmarshal(json);
assertThat(unmarshal).isNotNull();
Element element1 = (Element) unmarshal.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.lab_test-hba1c.v1,2]/data/events[at0003]/data/items[at0.63]").get(0);
assertThat(element1.getValue()).isNull();
assertThat(element1.getNullFlavour()).isEqualTo(NullFlavour.NO_INFORMATION.toCodedText());
}
use of com.nedap.archie.rm.datastructures.Element in project openEHR_SDK by ehrbase.
the class ItemExtractor method invoke.
public ItemExtractor invoke() {
relativeAql = StringUtils.removeEnd(StringUtils.removeStart(childNode.getAqlPath(), currentNode.getAqlPath()), "/");
FlatPath childPath = new FlatPath(relativeAql);
parentAql = StringUtils.removeEnd(childPath.format(false), childPath.format(false).substring(childPath.format(false).lastIndexOf("/")));
if (StringUtils.isBlank(parentAql)) {
parentAql = "/";
}
if (currentRM instanceof Pathable) {
try {
child = ((Pathable) currentRM).itemsAtPath(childPath.format(false));
if (child == null || ((List) child).isEmpty()) {
child = ((Pathable) currentRM).itemAtPath(childPath.format(false));
}
} catch (RuntimeException e) {
child = null;
}
parent = ((Pathable) currentRM).itemAtPath(parentAql);
} else if (currentRM instanceof DvInterval) {
if (relativeAql.contains("upper_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isUpperIncluded());
} else if (relativeAql.contains("lower_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isLowerIncluded());
} else if (relativeAql.contains("lower")) {
child = ((DvInterval<?>) currentRM).getLower();
} else if (relativeAql.contains("upper")) {
child = ((DvInterval<?>) currentRM).getUpper();
}
parent = currentRM;
} else {
throw new SdkException(String.format("Can not extract from class %s", currentRM.getClass().getSimpleName()));
}
if (StringUtils.isNotBlank(childPath.findOtherPredicate("name/value")) && child instanceof List && Locatable.class.isAssignableFrom(Walker.ARCHIE_RM_INFO_LOOKUP.getClass(childNode.getRmType()))) {
child = ((List) child).stream().filter(c -> childPath.findOtherPredicate("name/value").equals(((Locatable) c).getNameAsString())).collect(Collectors.toList());
// if name not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if (isChoice && child instanceof List) {
child = ((List) child).stream().filter(c -> Walker.ARCHIE_RM_INFO_LOOKUP.getTypeInfo(c.getClass()).getRmName().equals(childNode.getRmType())).collect(Collectors.toList());
// if rmType not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if ((childNode.getMax() == 1 || currentNode.getRmType().equals(RmConstants.ELEMENT)) && child instanceof List) {
if (((List<?>) child).isEmpty()) {
child = null;
} else {
child = ((List) child).get(0);
}
}
if (child instanceof Element && !childNode.getRmType().equals(RmConstants.ELEMENT)) {
child = ((Element) child).getValue();
}
return this;
}
use of com.nedap.archie.rm.datastructures.Element 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