Search in sources :

Example 1 with DvQuantity

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)));
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LaborergebnisObservation(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.definition.LaborergebnisObservation) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) GrosseLangeObservation(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.definition.GrosseLangeObservation) Element(com.nedap.archie.rm.datastructures.Element) Duration(java.time.Duration) Locatable(com.nedap.archie.rm.archetyped.Locatable) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) URI(java.net.URI) ZoneOffset(java.time.ZoneOffset) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvQuantity(com.nedap.archie.rm.datavalues.quantity.DvQuantity) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PartySelf(com.nedap.archie.rm.generic.PartySelf) Tuple(org.assertj.core.groups.Tuple) KorpergrosseComposition(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.KorpergrosseComposition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvText(com.nedap.archie.rm.datavalues.DvText) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) Test(org.junit.Test) IOException(java.io.IOException) PointEvent(com.nedap.archie.rm.datastructures.PointEvent) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) IOUtils(org.apache.commons.io.IOUtils) KohlendioxidpartialdruckCluster(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.definition.KohlendioxidpartialdruckCluster) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) Observation(com.nedap.archie.rm.composition.Observation) List(java.util.List) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) OffsetDateTime(java.time.OffsetDateTime) BefundDerBlutgasanalyseComposition(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.BefundDerBlutgasanalyseComposition) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) TestData(org.ehrbase.client.TestData) IntervalEvent(com.nedap.archie.rm.datastructures.IntervalEvent) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) AdminEntry(com.nedap.archie.rm.composition.AdminEntry) DvURI(com.nedap.archie.rm.datavalues.DvURI) TestAllTypesEvaluation(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.definition.TestAllTypesEvaluation) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) Composition(com.nedap.archie.rm.composition.Composition) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) KorpergrosseComposition(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.KorpergrosseComposition) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) BefundDerBlutgasanalyseComposition(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.BefundDerBlutgasanalyseComposition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) IntervalEvent(com.nedap.archie.rm.datastructures.IntervalEvent) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) DvQuantity(com.nedap.archie.rm.datavalues.quantity.DvQuantity) PointEvent(com.nedap.archie.rm.datastructures.PointEvent) LaborergebnisObservation(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.definition.LaborergebnisObservation) GrosseLangeObservation(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.definition.GrosseLangeObservation) Observation(com.nedap.archie.rm.composition.Observation) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 2 with DvQuantity

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

Example 3 with DvQuantity

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]");
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) DvQuantity(com.nedap.archie.rm.datavalues.quantity.DvQuantity) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Test(org.junit.Test)

Example 4 with DvQuantity

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

Example 5 with DvQuantity

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);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LaborergebnisObservation(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.definition.LaborergebnisObservation) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) GrosseLangeObservation(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.definition.GrosseLangeObservation) Element(com.nedap.archie.rm.datastructures.Element) Duration(java.time.Duration) Locatable(com.nedap.archie.rm.archetyped.Locatable) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) URI(java.net.URI) ZoneOffset(java.time.ZoneOffset) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvQuantity(com.nedap.archie.rm.datavalues.quantity.DvQuantity) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PartySelf(com.nedap.archie.rm.generic.PartySelf) Tuple(org.assertj.core.groups.Tuple) KorpergrosseComposition(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.KorpergrosseComposition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvText(com.nedap.archie.rm.datavalues.DvText) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) Test(org.junit.Test) IOException(java.io.IOException) PointEvent(com.nedap.archie.rm.datastructures.PointEvent) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) IOUtils(org.apache.commons.io.IOUtils) KohlendioxidpartialdruckCluster(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.definition.KohlendioxidpartialdruckCluster) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) Observation(com.nedap.archie.rm.composition.Observation) List(java.util.List) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) OffsetDateTime(java.time.OffsetDateTime) BefundDerBlutgasanalyseComposition(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.BefundDerBlutgasanalyseComposition) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) TestData(org.ehrbase.client.TestData) IntervalEvent(com.nedap.archie.rm.datastructures.IntervalEvent) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) AdminEntry(com.nedap.archie.rm.composition.AdminEntry) DvURI(com.nedap.archie.rm.datavalues.DvURI) TestAllTypesEvaluation(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.definition.TestAllTypesEvaluation) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) Composition(com.nedap.archie.rm.composition.Composition) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) EhrbaseMultiOccurrenceDeV1Composition(org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition) KorpergrosseComposition(org.ehrbase.client.classgenerator.examples.korpergrossecomposition.KorpergrosseComposition) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) BefundDerBlutgasanalyseComposition(org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.BefundDerBlutgasanalyseComposition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.examples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition) Element(com.nedap.archie.rm.datastructures.Element) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) Test(org.junit.Test)

Aggregations

DvQuantity (com.nedap.archie.rm.datavalues.quantity.DvQuantity)10 Composition (com.nedap.archie.rm.composition.Composition)7 Test (org.junit.Test)6 Element (com.nedap.archie.rm.datastructures.Element)4 PointEvent (com.nedap.archie.rm.datastructures.PointEvent)4 DvText (com.nedap.archie.rm.datavalues.DvText)4 AlternativeEventsComposition (org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition)4 BefundDerBlutgasanalyseComposition (org.ehrbase.client.classgenerator.examples.befundderblutgasanalysecomposition.BefundDerBlutgasanalyseComposition)4 CoronaAnamneseComposition (org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition)4 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)4 EhrbaseMultiOccurrenceDeV1Composition (org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition)4 EpisodeOfCareComposition (org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition)4 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)4 Locatable (com.nedap.archie.rm.archetyped.Locatable)3 AdminEntry (com.nedap.archie.rm.composition.AdminEntry)3 Observation (com.nedap.archie.rm.composition.Observation)3 IntervalEvent (com.nedap.archie.rm.datastructures.IntervalEvent)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)3 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)3