Search in sources :

Example 1 with Section

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

the class DBEncodeTest method testDBEncodeDecodeInstruction.

@Test
public void testDBEncodeDecodeInstruction() throws IOException {
    Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.NESTED_EN_V1.getStream(), UTF_8), Composition.class);
    CompositionSerializer compositionSerializer = new CompositionSerializer();
    String encoded = compositionSerializer.dbEncode(composition);
    Assert.assertTrue(encoded.contains(CompositionSerializer.TAG_EXPIRY_TIME));
    String json = new LightRawJsonEncoder(encoded).encodeCompositionAsString();
    Composition result = new CanonicalJson().unmarshal(json, Composition.class);
    DvDateTime expiryTime = ((Instruction) ((Section) result.getContent().get(0)).getItems().get(0)).getExpiryTime();
    Assert.assertNotNull(expiryTime);
    Assert.assertEquals(OffsetDateTime.parse("2021-05-18T13:13:09.780+03:00"), expiryTime.getValue());
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) Instruction(com.nedap.archie.rm.composition.Instruction) Section(com.nedap.archie.rm.composition.Section) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) Test(org.junit.Test)

Example 2 with Section

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

the class DBEncodeTest method testDBDecodeIssue350.

@Test
public void testDBDecodeIssue350() throws Exception {
    String db_encoded = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/bug350_missing_data.json")));
    assertNotNull(db_encoded);
    // see if this can be interpreted by Archie
    Composition object = new RawJson().unmarshal(db_encoded, Composition.class);
    assertEquals(8, ((Section) object.itemsAtPath("/content[openEHR-EHR-SECTION.respect_headings.v0]").get(0)).getItems().size());
    String interpreted = new CanonicalXML().marshal(object);
    assertNotNull(interpreted);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CanonicalXML(org.ehrbase.serialisation.xmlencoding.CanonicalXML) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) Section(com.nedap.archie.rm.composition.Section) Test(org.junit.Test)

Example 3 with Section

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

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

use of com.nedap.archie.rm.composition.Section 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)

Aggregations

Section (com.nedap.archie.rm.composition.Section)6 Composition (com.nedap.archie.rm.composition.Composition)5 Test (org.junit.Test)5 WorkflowIdTest (care.better.platform.web.template.WorkflowIdTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Entry (com.nedap.archie.rm.composition.Entry)3 GenericId (com.nedap.archie.rm.support.identification.GenericId)3 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)3 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)3 OffsetDateTime (java.time.OffsetDateTime)3 ZoneId (java.time.ZoneId)3 ZonedDateTime (java.time.ZonedDateTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 Map (java.util.Map)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Helper.getFlatJson (org.ehrbase.conformance_test.extern.Helper.getFlatJson)3 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)3 FlatFormat (org.ehrbase.serialisation.flatencoding.FlatFormat)3 Instruction (com.nedap.archie.rm.composition.Instruction)2