Search in sources :

Example 31 with Composition

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

the class FlatJsonMarshallerTest method toFlatJsonAllTypes.

@Test
public void toFlatJsonAllTypes() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.ALL_TYPES.getStream()).getTemplate();
    Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.ALL_TYPES.getStream(), StandardCharsets.UTF_8), Composition.class);
    FlatJsonMarshaller cut = new FlatJsonMarshaller();
    String actual = cut.toFlatJson(composition, new OPTParser(template).parse());
    assertThat(actual).isNotNull();
    String expected = IOUtils.toString(CompositionTestDataSimSDTJson.ALL_TYPES.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    checkErrors(errors, new String[] { "Missing path: test_all_types/test_all_types:0/identifier|id, value: 55175056", "Missing path: test_all_types/test_all_types:0/proportion_any|type, value: 1", "Missing path: test_all_types/test_all_types:0/proportion_any|precision, value: 1", "Missing path: test_all_types/test_all_types:0/duration_any, value: P1Y2M10DT2H30M", "Missing path: test_all_types/test_all_types2:0/uri, value: www.iana.org" }, new String[] { "Extra path: test_all_types/test_all_types:0/duration_any, value: PT30M", "Extra path: test_all_types/test_all_types:0/identifier, value: 55175056", "Extra path: test_all_types/test_all_types:0/proportion_any|type, value: 1.0" });
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Test(org.junit.Test)

Example 32 with Composition

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

Example 33 with Composition

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

the class RawJsonTest method marshallEmptyState.

@Test
public void marshallEmptyState() throws Exception {
    String json = IOUtils.toString(CompositionTestDataCanonicalJson.GECCO_LABORBEFUND.getStream(), UTF_8);
    Composition composition = new CanonicalJson().unmarshal(json, Composition.class);
    RawJson rawJson = new RawJson();
    String actual = rawJson.marshal(composition);
    assertThat(actual).isNotNull();
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) ItemStruktureTestDataCanonicalJson(org.ehrbase.test_data.item_structure.ItemStruktureTestDataCanonicalJson) Test(org.junit.Test)

Example 34 with Composition

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

the class FlatJsonTest method check.

private void check(String templateId, CompositionTestDataSimSDTJson testData, String[] expectedMissing, String[] expectedExtra) throws IOException {
    RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
    String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    Composition unmarshal = cut.unmarshal(flat);
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(unmarshal).isNotNull();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
    softAssertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider) List(java.util.List) FlatJsonMarshallerTest.compere(org.ehrbase.serialisation.flatencoding.std.marshal.FlatJsonMarshallerTest.compere) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator)

Example 35 with Composition

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

the class FlatJsonTest method roundTripRaw.

@Test
public void roundTripRaw() throws IOException {
    CompositionTestDataSimSDTJson testData = CompositionTestDataSimSDTJson.CORONA_WITH_RAW;
    String templateId = "Corona_Anamnese";
    RMDataFormat cut = new FlatJasonProvider(templateProvider).buildFlatJson(FlatFormat.SIM_SDT, templateId);
    String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    Composition unmarshal = cut.unmarshal(flat);
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(unmarshal).isNotNull();
    RMObjectValidator rmObjectValidator = new RMObjectValidator(ArchieRMInfoLookup.getInstance(), s -> null);
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal)).filteredOn(m -> !m.getMessage().contains("Inv_null_flavour_indicated")).containsExactlyInAnyOrder();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder();
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder();
    softAssertions.assertAll();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) OperationalTemplateTestData(org.ehrbase.test_data.operationaltemplate.OperationalTemplateTestData) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) TestDataTemplateProvider(org.ehrbase.serialisation.templateprovider.TestDataTemplateProvider) List(java.util.List) FlatJsonMarshallerTest.compere(org.ehrbase.serialisation.flatencoding.std.marshal.FlatJsonMarshallerTest.compere) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) RMObjectValidator(com.nedap.archie.rmobjectvalidator.RMObjectValidator) CompositionTestDataSimSDTJson(org.ehrbase.test_data.composition.CompositionTestDataSimSDTJson) Test(org.junit.Test)

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