Search in sources :

Example 91 with Composition

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

the class WorkflowIdTestOverwrite method workflowIdInCtx.

@Override
@Test
public void workflowIdInCtx() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.opt");
    Map<String, Object> flatComposition = ImmutableMap.<String, Object>builder().put("ctx/language", "sl").put("ctx/territory", "SI").put("ctx/composer_name", "Composer").put("ctx/id_scheme", "ispek").put("ctx/id_namespace", "ispek").put("ctx/end_time", "2016-01-01T12:30:30Z").put("ctx/work_flow_id|id", "wf_id").put("ctx/work_flow_id|namespace", "wf_ns").put("ctx/work_flow_id|id_scheme", "wf_scheme").put("ctx/work_flow_id|type", "wf_type").put("vitals/vitals/haemoglobin_a1c/any_event/test_status|terminology", "local").put("vitals/vitals/haemoglobin_a1c/any_event/test_status|code", "at0037").build();
    RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
    Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
    Entry contentItem = (Entry) ((Section) composition.getContent().get(0)).getItems().get(0);
    ObjectRef<? extends ObjectId> workflowId = contentItem.getWorkflowId();
    assertThat(workflowId).isNotNull();
    assertThat(workflowId.getId()).hasSameClassAs(new GenericId()).extracting(ObjectId::getValue, i -> ((GenericId) i).getScheme()).containsExactly("wf_id", "wf_scheme");
    assertThat(workflowId.getNamespace()).isEqualTo("wf_ns");
    assertThat(workflowId.getType()).isEqualTo("wf_type");
    Map<String, Object> map = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
    assertThat(map).containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id", "wf_id").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id_scheme", "wf_scheme").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|type", "wf_type").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|namespace", "wf_ns");
}
Also used : Entry(com.nedap.archie.rm.composition.Entry) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Composition(com.nedap.archie.rm.composition.Composition) ImmutableMap(com.google.common.collect.ImmutableMap) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) Section(com.nedap.archie.rm.composition.Section) ZoneId(java.time.ZoneId) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest) OffsetDateTime(java.time.OffsetDateTime) Helper.getFlatJson(org.ehrbase.conformance_test.extern.Helper.getFlatJson) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) GenericId(com.nedap.archie.rm.support.identification.GenericId) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) Composition(com.nedap.archie.rm.composition.Composition) Entry(com.nedap.archie.rm.composition.Entry) GenericId(com.nedap.archie.rm.support.identification.GenericId) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) Section(com.nedap.archie.rm.composition.Section) Test(org.junit.Test) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest)

Example 92 with Composition

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

the class WorkflowIdTestOverwrite method workflowIdDirect.

@Override
@Test
public void workflowIdDirect() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.opt");
    OffsetDateTime dateTime = ZonedDateTime.of(2015, 1, 1, 10, 31, 16, 0, ZoneId.systemDefault()).toOffsetDateTime();
    Map<String, Object> flatComposition = ImmutableMap.<String, Object>builder().put("ctx/language", "sl").put("ctx/territory", "SI").put("ctx/composer_name", "Composer").put("ctx/id_scheme", "ispek").put("ctx/id_namespace", "ispek").put("ctx/end_time", "2016-01-01T12:30:30Z").put("vitals/vitals/haemoglobin_a1c/history_origin", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(dateTime)).put("vitals/vitals/haemoglobin_a1c/any_event/test_status|terminology", "local").put("vitals/vitals/haemoglobin_a1c/any_event/test_status|code", "at0037").put("vitals/vitals/haemoglobin_a1c/_work_flow_id|id", "1").put("vitals/vitals/haemoglobin_a1c/_work_flow_id|id_scheme", "x").put("vitals/vitals/haemoglobin_a1c/_work_flow_id|namespace", "y").put("vitals/vitals/haemoglobin_a1c/_work_flow_id|type", "wf").build();
    RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
    Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
    Entry contentItem = (Entry) ((Section) composition.getContent().get(0)).getItems().get(0);
    ObjectRef<? extends ObjectId> workflowId = contentItem.getWorkflowId();
    assertThat(workflowId).isNotNull();
    assertThat(workflowId.getId()).hasSameClassAs(new GenericId()).extracting(ObjectId::getValue, i -> ((GenericId) i).getScheme()).containsExactly("1", "x");
    assertThat(workflowId.getNamespace()).isEqualTo("y");
    assertThat(workflowId.getType()).isEqualTo("wf");
    Map<String, Object> map = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
    assertThat(map).containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id", "1").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id_scheme", "x").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|type", "wf").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|namespace", "y");
}
Also used : Entry(com.nedap.archie.rm.composition.Entry) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Composition(com.nedap.archie.rm.composition.Composition) ImmutableMap(com.google.common.collect.ImmutableMap) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) Section(com.nedap.archie.rm.composition.Section) ZoneId(java.time.ZoneId) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest) OffsetDateTime(java.time.OffsetDateTime) Helper.getFlatJson(org.ehrbase.conformance_test.extern.Helper.getFlatJson) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) GenericId(com.nedap.archie.rm.support.identification.GenericId) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) Composition(com.nedap.archie.rm.composition.Composition) Entry(com.nedap.archie.rm.composition.Entry) GenericId(com.nedap.archie.rm.support.identification.GenericId) OffsetDateTime(java.time.OffsetDateTime) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) Section(com.nedap.archie.rm.composition.Section) Test(org.junit.Test) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest)

Example 93 with Composition

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

the class WorkflowIdTestOverwrite method workflowIdInCtxAndDirect.

@Override
@Test
public void workflowIdInCtxAndDirect() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.opt");
    Map<String, Object> flatComposition = ImmutableMap.<String, Object>builder().put("ctx/language", "sl").put("ctx/territory", "SI").put("ctx/composer_name", "Composer").put("ctx/id_scheme", "ispek").put("ctx/id_namespace", "ispek").put("ctx/end_time", "2016-01-01T12:30:30Z").put("ctx/work_flow_id|id", "wf_id").put("ctx/work_flow_id|namespace", "wf_ns").put("ctx/work_flow_id|id_scheme", "wf_scheme").put("ctx/work_flow_id|type", "wf_type").put("vitals/vitals/haemoglobin_a1c/any_event/test_status|terminology", "local").put("vitals/vitals/haemoglobin_a1c/any_event/test_status|code", "at0037").put("vitals/vitals/haemoglobin_a1c:1/any_event/test_status|terminology", "local").put("vitals/vitals/haemoglobin_a1c:1/any_event/test_status|code", "at0037").put("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|id", "1").put("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|id_scheme", "x").put("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|namespace", "y").put("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|type", "wf").build();
    RMDataFormat flatJson = getFlatJson(template, FlatFormat.SIM_SDT);
    Composition composition = flatJson.unmarshal(OBJECT_MAPPER.writeValueAsString(flatComposition));
    Entry contentItem1 = (Entry) ((Section) composition.getContent().get(0)).getItems().get(0);
    ObjectRef<? extends ObjectId> workflowId1 = contentItem1.getWorkflowId();
    assertThat(workflowId1).isNotNull();
    assertThat(workflowId1.getId()).hasSameClassAs(new GenericId()).extracting(ObjectId::getValue, i -> ((GenericId) i).getScheme()).containsExactly("wf_id", "wf_scheme");
    assertThat(workflowId1.getNamespace()).isEqualTo("wf_ns");
    assertThat(workflowId1.getType()).isEqualTo("wf_type");
    Entry contentItem2 = (Entry) ((Section) composition.getContent().get(0)).getItems().get(1);
    ObjectRef<? extends ObjectId> workflowId2 = contentItem2.getWorkflowId();
    assertThat(workflowId2).isNotNull();
    assertThat(workflowId2.getId()).hasSameClassAs(new GenericId()).extracting(ObjectId::getValue, i -> ((GenericId) i).getScheme()).containsExactly("1", "x");
    assertThat(workflowId2.getNamespace()).isEqualTo("y");
    assertThat(workflowId2.getType()).isEqualTo("wf");
    Map<String, Object> map = OBJECT_MAPPER.readValue(flatJson.marshal(composition), Map.class);
    assertThat(map).containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id", "wf_id").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|id_scheme", "wf_scheme").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|type", "wf_type").containsEntry("vitals/vitals/haemoglobin_a1c:0/_work_flow_id|namespace", "wf_ns").containsEntry("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|id", "1").containsEntry("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|id_scheme", "x").containsEntry("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|type", "wf").containsEntry("vitals/vitals/haemoglobin_a1c:1/_work_flow_id|namespace", "y");
}
Also used : Entry(com.nedap.archie.rm.composition.Entry) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Composition(com.nedap.archie.rm.composition.Composition) ImmutableMap(com.google.common.collect.ImmutableMap) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) Section(com.nedap.archie.rm.composition.Section) ZoneId(java.time.ZoneId) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest) OffsetDateTime(java.time.OffsetDateTime) Helper.getFlatJson(org.ehrbase.conformance_test.extern.Helper.getFlatJson) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) GenericId(com.nedap.archie.rm.support.identification.GenericId) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) Composition(com.nedap.archie.rm.composition.Composition) Entry(com.nedap.archie.rm.composition.Entry) GenericId(com.nedap.archie.rm.support.identification.GenericId) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) Section(com.nedap.archie.rm.composition.Section) Test(org.junit.Test) WorkflowIdTest(care.better.platform.web.template.WorkflowIdTest)

Example 94 with Composition

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

the class FlatConformanceTest method testRoundTrip.

@ParameterizedTest
@MethodSource("testRoundTripArguments")
void testRoundTrip(CompositionTestDataConformanceSDTJson testData, String[] expectedMissing, String[] expectedExtra, String[] expectedValidationErrorPath) throws IOException {
    String templateId = testData.getTemplate().getTemplateId();
    RMDataFormat cut = new FlatJasonProvider(TEMPLATE_PROVIDER).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();
    CompositionValidator rmObjectValidator = new CompositionValidator();
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal, TEMPLATE_PROVIDER.buildIntrospect(templateId).orElseThrow())).filteredOn(d -> !ArrayUtils.contains(expectedValidationErrorPath, d.getAqlPath())).isEmpty();
    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 : Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) CompositionValidator(org.ehrbase.validation.CompositionValidator) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) IOUtils(org.apache.commons.io.IOUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) CompositionTestDataConformanceSDTJson(org.ehrbase.test_data.composition.CompositionTestDataConformanceSDTJson) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) TestDataTemplateProvider(org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) CompositionValidator(org.ehrbase.validation.CompositionValidator) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 95 with Composition

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

the class WalkerTest method testClone.

@Test
public void testClone() throws IOException, XmlException {
    OPERATIONALTEMPLATE template = TemplateDocument.Factory.parse(OperationalTemplateTestData.CORONA_ANAMNESE.getStream()).getTemplate();
    WebTemplate webTemplate = new OPTParser(template).parse();
    FilteredWebTemplate filteredWebTemplate = new Filter().filter(webTemplate);
    assertThat(filteredWebTemplate).isNotNull();
    FlatJsonUnmarshaller cut = new FlatJsonUnmarshaller();
    String flat = IOUtils.toString(CompositionTestDataSimSDTJson.CORONA.getStream(), StandardCharsets.UTF_8);
    Composition actual = cut.unmarshal(flat, webTemplate);
    assertThat(actual).isNotNull();
    FilteredWebTemplate filteredWebTemplateAfter = new Filter().filter(webTemplate);
    assertThat(filteredWebTemplateAfter).isNotNull();
}
Also used : OPERATIONALTEMPLATE(org.openehr.schemas.v1.OPERATIONALTEMPLATE) Composition(com.nedap.archie.rm.composition.Composition) FilteredWebTemplate(org.ehrbase.webtemplate.model.FilteredWebTemplate) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) FilteredWebTemplate(org.ehrbase.webtemplate.model.FilteredWebTemplate) OPTParser(org.ehrbase.webtemplate.parser.OPTParser) Filter(org.ehrbase.webtemplate.filter.Filter) FlatJsonUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.FlatJsonUnmarshaller) 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