Search in sources :

Example 11 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class UnflattenerTest method testUnflattenEpsiode.

@Test
public void testUnflattenEpsiode() {
    EpisodeOfCareComposition episode = buildEpisodeOfCareComposition();
    Unflattener cut = new Unflattener(new TestDataTemplateProvider());
    Composition actual = (Composition) cut.unflatten(episode);
    assertThat(actual).isNotNull();
    assertThat(actual.getContent()).size().isEqualTo(1);
    AdminEntry actualAdminEntry = (AdminEntry) actual.getContent().get(0);
    List<Object> identifiers = actualAdminEntry.itemsAtPath("/data[at0001]/items[at0002]/value");
    assertThat(identifiers).extracting(i -> ((DvIdentifier) i).getId()).containsExactlyInAnyOrder("123", "456");
    List<Object> uris = actualAdminEntry.itemsAtPath("/data[at0001]/items[at0013]/value");
    assertThat(uris).extracting(u -> ((DvURI) u).getValue()).containsExactlyInAnyOrder(URI.create("https://github.com/ehrbase"));
}
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) AdminEntry(com.nedap.archie.rm.composition.AdminEntry) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) DvURI(com.nedap.archie.rm.datavalues.DvURI) Test(org.junit.Test)

Example 12 with Composition

use of com.nedap.archie.rm.composition.Composition 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 13 with Composition

use of com.nedap.archie.rm.composition.Composition 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);
}
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) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) 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) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) 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) EhrbaseBloodPressureSimpleDeV0Composition(org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 14 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class NormalizerTest method normalize.

@Test
public void normalize() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
    OptSkeletonBuilder skeletonBuilder = new OptSkeletonBuilder();
    RMObject rmObject = skeletonBuilder.generate(template);
    Normalizer cut = new Normalizer();
    Composition actual = (Composition) cut.normalize(rmObject);
    assertThat(actual).isNotNull();
    assertThat(actual.getContent()).size().isEqualTo(0);
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) Normalizer(org.ehrbase.normalizer.Normalizer) OptSkeletonBuilder(org.ehrbase.building.OptSkeletonBuilder) RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Example 15 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class DefaultRestAqlEndpoint method extractValue.

private Object extractValue(String valueAsString, Class<?> aClass) throws com.fasterxml.jackson.core.JsonProcessingException {
    Object object;
    if (StringUtils.isBlank(valueAsString) || "null".equals(valueAsString)) {
        object = null;
    } else if (aClass.isAnnotationPresent(Entity.class)) {
        RMObject locatable = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
        object = new Flattener(defaultRestClient.getTemplateProvider()).flatten(locatable, aClass);
        if (locatable instanceof Composition) {
            Flattener.addVersion(object, new VersionUid(((Composition) locatable).getUid().getValue()));
        }
    } else if (EnumValueSet.class.isAssignableFrom(aClass)) {
        RMObject rmObject = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
        final String codeString;
        if (CodePhrase.class.isAssignableFrom(rmObject.getClass())) {
            codeString = ((CodePhrase) rmObject).getCodeString();
        } else {
            codeString = ((DvCodedText) rmObject).getDefiningCode().getCodeString();
        }
        object = Arrays.stream(aClass.getEnumConstants()).map(e -> (EnumValueSet) e).filter(e -> e.getCode().equals(codeString)).findAny().orElseThrow(() -> new ClientException(String.format("Unknown code %s for %s", codeString, aClass.getSimpleName())));
    } else {
        object = AQL_OBJECT_MAPPER.readValue(valueAsString, aClass);
    }
    return object;
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) Composition(com.nedap.archie.rm.composition.Composition) VersionUid(org.ehrbase.client.openehrclient.VersionUid) AqlField(org.ehrbase.client.aql.field.AqlField) HashMap(java.util.HashMap) ParameterValue(org.ehrbase.client.aql.parameter.ParameterValue) JsonParser(com.google.gson.JsonParser) StringUtils(org.apache.commons.lang3.StringUtils) EnumValueSet(org.ehrbase.client.classgenerator.EnumValueSet) TemporalAccessor(java.time.temporal.TemporalAccessor) ArrayList(java.util.ArrayList) EntityUtils(org.apache.http.util.EntityUtils) JsonElement(com.google.gson.JsonElement) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) AqlEndpoint(org.ehrbase.client.openehrclient.AqlEndpoint) OBJECT_MAPPER(org.ehrbase.client.openehrclient.defaultrestclient.DefaultRestClient.OBJECT_MAPPER) Map(java.util.Map) Flattener(org.ehrbase.client.flattener.Flattener) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ClientException(org.ehrbase.client.exception.ClientException) URI(java.net.URI) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ListSelectAqlField(org.ehrbase.client.aql.field.ListSelectAqlField) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContentType(org.apache.http.entity.ContentType) Version(com.fasterxml.jackson.core.Version) IOException(java.io.IOException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) JsonArray(com.google.gson.JsonArray) List(java.util.List) Record(org.ehrbase.client.aql.record.Record) Query(org.ehrbase.client.aql.query.Query) RMObject(com.nedap.archie.rm.RMObject) Entity(org.ehrbase.client.annotations.Entity) HttpResponse(org.apache.http.HttpResponse) RecordImp(org.ehrbase.client.aql.record.RecordImp) Collections(java.util.Collections) Entity(org.ehrbase.client.annotations.Entity) Composition(com.nedap.archie.rm.composition.Composition) VersionUid(org.ehrbase.client.openehrclient.VersionUid) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Flattener(org.ehrbase.client.flattener.Flattener) JsonObject(com.google.gson.JsonObject) RMObject(com.nedap.archie.rm.RMObject) ClientException(org.ehrbase.client.exception.ClientException) RMObject(com.nedap.archie.rm.RMObject)

Aggregations

Composition (com.nedap.archie.rm.composition.Composition)138 Test (org.junit.Test)103 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)66 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)53 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)30 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)29 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)28 IOException (java.io.IOException)21 List (java.util.List)21 CoronaAnamneseComposition (org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition)20 Tuple (org.assertj.core.groups.Tuple)19 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)19 StandardCharsets (java.nio.charset.StandardCharsets)18 IOUtils (org.apache.commons.io.IOUtils)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 EhrbaseMultiOccurrenceDeV1Composition (org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition)18 OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)18 EpisodeOfCareComposition (org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition)17 CompositionTestDataCanonicalXML (org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML)17 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)16