use of org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition 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 org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition in project openEHR_SDK by ehrbase.
the class FlattenerTest method testFlattenAltEvents.
@Test
public void testFlattenAltEvents() {
Composition composition = (Composition) new Unflattener(new TestDataTemplateProvider()).unflatten(buildAlternativeEventsComposition());
Flattener cut = new Flattener(new TestDataTemplateProvider());
AlternativeEventsComposition actual = cut.flatten(composition, AlternativeEventsComposition.class);
assertThat(actual).isNotNull();
assertThat(actual.getKorpergewicht()).size().isEqualTo(1);
KorpergewichtBirthEnPointEvent birthEn = actual.getKorpergewicht().get(0).getBirthEn();
assertThat(birthEn.getTimeValue()).isEqualTo(OffsetDateTime.of(1990, 11, 2, 12, 0, 0, 0, ZoneOffset.UTC));
assertThat(birthEn.getGewichtMagnitude()).isEqualTo(30d);
assertThat(birthEn.getGewichtUnits()).isEqualTo("kg");
List<KorpergewichtAnyEventEnPointEvent> eventEnPointEvents = actual.getKorpergewicht().get(0).getAnyEventEn().stream().filter(e -> KorpergewichtAnyEventEnPointEvent.class.isAssignableFrom(e.getClass())).map(e -> (KorpergewichtAnyEventEnPointEvent) e).collect(Collectors.toList());
assertThat(eventEnPointEvents).size().isEqualTo(1);
assertThat(eventEnPointEvents.get(0).getTimeValue()).isEqualTo(OffsetDateTime.of(2013, 11, 2, 12, 0, 0, 0, ZoneOffset.UTC));
assertThat(eventEnPointEvents.get(0).getGewichtMagnitude()).isEqualTo(55d);
assertThat(eventEnPointEvents.get(0).getGewichtUnits()).isEqualTo("kg");
List<KorpergewichtAnyEventEnIntervalEvent> anyEventEnIntervalEvents = actual.getKorpergewicht().get(0).getAnyEventEn().stream().filter(e -> KorpergewichtAnyEventEnIntervalEvent.class.isAssignableFrom(e.getClass())).map(e -> (KorpergewichtAnyEventEnIntervalEvent) e).collect(Collectors.toList());
assertThat(eventEnPointEvents).size().isEqualTo(1);
assertThat(anyEventEnIntervalEvents.get(0).getTimeValue()).isEqualTo(OffsetDateTime.of(2015, 11, 2, 12, 0, 0, 0, ZoneOffset.UTC));
assertThat(anyEventEnIntervalEvents.get(0).getGewichtMagnitude()).isEqualTo(60d);
assertThat(anyEventEnIntervalEvents.get(0).getGewichtUnits()).isEqualTo("kg");
assertThat(anyEventEnIntervalEvents.get(0).getMathFunctionDefiningCode()).isEqualTo(MathFunction.MEAN);
assertThat(anyEventEnIntervalEvents.get(0).getWidthValue()).isEqualTo(Duration.ofDays(30));
}
use of org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition in project openEHR_SDK by ehrbase.
the class DefaultRestVersionedCompositionEndpointIT method testFindVersionAtTime.
@Test
public void testFindVersionAtTime() {
ehrId = openEhrClient.ehrEndpoint().createEhr();
LocalDateTime versionAtTime;
Optional<OriginalVersion<AlternativeEventsComposition>> result;
// Before
versionAtTime = LocalDateTime.now();
AlternativeEventsComposition composition1 = TestData.buildAlternativeEventsComposition();
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition1);
result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition1.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
Assert.assertTrue(result.isEmpty());
// Between
AlternativeEventsComposition composition2 = TestData.buildAlternativeEventsComposition();
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
VersionUid v2 = openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2).getVersionUid();
versionAtTime = LocalDateTime.now();
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition2.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
Assert.assertTrue(result.isPresent());
Assert.assertEquals(v2.toString(), result.get().getUid().getValue());
// Last
AlternativeEventsComposition composition3 = TestData.buildAlternativeEventsComposition();
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
versionAtTime = LocalDateTime.now();
result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition3.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
Assert.assertTrue(result.isPresent());
Assert.assertEquals(composition3.getVersionUid().toString(), result.get().getUid().getValue());
}
use of org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition in project openEHR_SDK by ehrbase.
the class TestData method buildAlternativeEventsComposition.
public static AlternativeEventsComposition buildAlternativeEventsComposition() {
AlternativeEventsComposition alternativeEventsComposition = new AlternativeEventsComposition();
alternativeEventsComposition.setStartTimeValue(OffsetDateTime.of(2010, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC));
alternativeEventsComposition.setComposer(new PartyIdentified(null, "Test", null));
alternativeEventsComposition.setLanguage(Language.EN);
alternativeEventsComposition.setTerritory(Territory.DE);
alternativeEventsComposition.setCategoryDefiningCode(Category.EVENT);
alternativeEventsComposition.setSettingDefiningCode(Setting.COMPLEMENTARY_HEALTH_CARE);
alternativeEventsComposition.setKorpergewicht(new ArrayList<>());
KorpergewichtObservation korpergewichtObservation = new KorpergewichtObservation();
korpergewichtObservation.setLanguage(Language.EN);
korpergewichtObservation.setSubject(new PartySelf());
korpergewichtObservation.setOriginValue(OffsetDateTime.of(1990, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC));
alternativeEventsComposition.getKorpergewicht().add(korpergewichtObservation);
KorpergewichtBirthEnPointEvent birthEnEvent = new KorpergewichtBirthEnPointEvent();
birthEnEvent.setGewichtMagnitude(30d);
birthEnEvent.setGewichtUnits("kg");
birthEnEvent.setTimeValue(OffsetDateTime.of(1990, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC));
korpergewichtObservation.setBirthEn(birthEnEvent);
korpergewichtObservation.setAnyEventEn(new ArrayList<>());
KorpergewichtAnyEventEnPointEvent pointEvent = new KorpergewichtAnyEventEnPointEvent();
pointEvent.setGewichtMagnitude(55d);
pointEvent.setGewichtUnits("kg");
pointEvent.setTimeValue(OffsetDateTime.of(2013, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC));
korpergewichtObservation.getAnyEventEn().add(pointEvent);
KorpergewichtAnyEventEnIntervalEvent intervalEvent = new KorpergewichtAnyEventEnIntervalEvent();
intervalEvent.setGewichtMagnitude(60d);
intervalEvent.setGewichtUnits("kg");
intervalEvent.setTimeValue(OffsetDateTime.of(2015, 11, 02, 12, 00, 00, 00, ZoneOffset.UTC));
intervalEvent.setWidthValue(Duration.ofDays(30));
intervalEvent.setMathFunctionDefiningCode(MathFunction.MEAN);
korpergewichtObservation.getAnyEventEn().add(intervalEvent);
return alternativeEventsComposition;
}
Aggregations