use of com.nedap.archie.rm.composition.Observation 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.composition.Observation in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflattenEhrbaseBloodPressureSimpleDeV0.
@Test
public void testUnflattenEhrbaseBloodPressureSimpleDeV0() {
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
EhrbaseBloodPressureSimpleDeV0Composition dto = buildEhrbaseBloodPressureSimpleDeV0();
Composition rmObject = (Composition) cut.unflatten(dto);
assertThat(rmObject).isNotNull();
assertThat(rmObject.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getFunction().getValue()).containsExactlyInAnyOrder(new Tuple("Test", "Pos1"), new Tuple("Test2", "Pos2"));
assertThat(rmObject.getLanguage()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("de", "ISO_639-1");
assertThat(rmObject.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("ehrbase_blood_pressure_simple.de.v0");
assertThat(rmObject.itemAtPath("/context/start_time/value")).isEqualTo(dto.getStartTimeValue());
List<Object> observationList = rmObject.itemsAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]");
assertThat(observationList).size().isEqualTo(1);
Observation observation = (Observation) observationList.get(0);
DvCodedText expected = new DvCodedText("Fifth sound", new CodePhrase(new TerminologyId("local"), "at1012"));
assertThat(observation.itemAtPath("/protocol[at0011]/items[at1010]/value")).isEqualTo(expected);
assertThat(observation.getSubject()).isNotNull().extracting(Object::getClass).isEqualTo(PartySelf.class);
}
use of com.nedap.archie.rm.composition.Observation in project openEHR_SDK by ehrbase.
the class DefaultValuesTest method unmarshal.
@Test
public void unmarshal() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
WebTemplate webTemplate = new OPTParser(template).parse();
FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA_WITH_CONTEXT.getStream(), StandardCharsets.UTF_8);
Composition actual = cut.unmarshal(flat, webTemplate);
assertThat(actual).isNotNull();
assertThat(actual.getCategory()).isNotNull();
assertThat(actual.getCategory().getValue()).isEqualTo("event");
assertThat(actual.getLanguage()).isNotNull();
assertThat(actual.getLanguage().getCodeString()).isEqualTo(Language.DE.getCode());
assertThat(actual.getComposer()).isNotNull();
assertThat(actual.getComposer()).getClass().isAssignableFrom(PartyIdentified.class);
assertThat(((PartyIdentified) actual.getComposer()).getName()).isEqualTo("Silvia Blake");
assertThat(actual.getComposer().getExternalRef().getNamespace()).isEqualTo("HOSPITAL-NS");
assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getScheme()).isEqualTo("HOSPITAL-NS");
assertThat(((GenericId) actual.getComposer().getExternalRef().getId()).getValue()).isEqualTo("123");
assertThat(actual.getContext().getHealthCareFacility().getName()).isEqualTo("Hospital");
assertThat(actual.getContext().getStartTime()).isNotNull();
assertThat(actual.getContext().getStartTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(actual.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
Observation observation = actual.getContent().stream().filter(c -> Observation.class.isAssignableFrom(c.getClass())).map(Observation.class::cast).findAny().orElse(null);
assertThat(observation).isNotNull();
assertThat(observation.getData()).isNotNull();
assertThat(observation.getData().getOrigin().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(observation.getData().getEvents().get(0).getTime().getValue()).isEqualTo(OffsetDateTime.of(2021, 4, 1, 12, 40, 31, 418954000, ZoneOffset.ofHours(2)));
assertThat(observation.getOtherParticipations()).extracting(p -> p.getFunction().getValue(), p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getPerformer().getExternalRef().getNamespace()).containsExactlyInAnyOrder(new Tuple("requester", "Dr. Marcus Johnson", "HOSPITAL-NS"), new Tuple("performer", "Lara Markham", "HOSPITAL-NS"));
assertThat(observation.getOtherParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer())).flatExtracting(p -> p.getIdentifiers()).extracting(DvIdentifier::getAssigner, DvIdentifier::getId, DvIdentifier::getIssuer, DvIdentifier::getType).containsExactlyInAnyOrder(new Tuple("assigner1", "id1", "issuer1", "PERSON"), new Tuple("assigner2", "id2", "issuer2", "PERSON"), new Tuple("assigner3", "id3", "issuer3", "PERSON"), new Tuple("assigner4", "id4", "issuer4", "PERSON"));
assertThat(observation.getWorkflowId()).isNotNull();
assertThat(observation.getWorkflowId().getNamespace()).isEqualTo("HOSPITAL-NS");
assertThat(observation.getWorkflowId().getId().getValue()).isEqualTo("567");
assertThat(observation.getWorkflowId().getType()).isEqualTo("ORGANISATION");
}
use of com.nedap.archie.rm.composition.Observation in project openEHR_SDK by ehrbase.
the class FlatJsonUnmarshallerTest method unmarshal.
@Test
public void unmarshal() throws IOException, XmlException {
OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
WebTemplate webTemplate = new OPTParser(template).parse();
FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
Composition actual = cut.unmarshal(flat, webTemplate);
assertThat(actual).isNotNull();
Observation observation = (Observation) actual.itemAtPath("/content[openEHR-EHR-OBSERVATION.story.v1]");
assertThat(observation.getData().getOrigin().getValue()).hasToString("2020-05-11T22:53:12.039139+02:00");
assertThat(observation.getSubject()).isNotNull();
assertThat(observation.getSubject().getClass()).isEqualTo(PartySelf.class);
}
use of com.nedap.archie.rm.composition.Observation 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