Search in sources :

Example 1 with ItemTree

use of com.nedap.archie.rm.datastructures.ItemTree in project openEHR_SDK by ehrbase.

the class DBEncodeTest method compositionEncodingFeederAuditDetails.

@Test
public void compositionEncodingFeederAuditDetails() throws Exception {
    String value = IOUtils.toString(CompositionTestDataCanonicalJson.FEEDER_AUDIT_DETAILS.getStream(), UTF_8);
    CanonicalJson cut = new CanonicalJson();
    Composition composition = cut.unmarshal(value, Composition.class);
    // check compo
    assertNotNull(composition);
    assertNotNull(composition.getFeederAudit().getFeederSystemAudit());
    // other details
    assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
    assertEquals("family group", composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getName().getValue());
    assertTrue(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails() instanceof ItemTree);
    assertEquals(1, composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().size());
    assertTrue(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().get(0) instanceof Element);
    assertTrue(((Element) composition.getFeederAudit().getFeederSystemAudit().getOtherDetails().getItems().get(0)).getValue() instanceof DvIdentifier);
    // version id
    assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getVersionId());
    assertEquals("final", composition.getFeederAudit().getFeederSystemAudit().getVersionId());
    // DB encode other details
    CompositionSerializer compositionSerializerRawJson = new CompositionSerializer();
    String dbEncoded = compositionSerializerRawJson.dbEncode(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
    assertNotNull(dbEncoded);
    // Convert encoded string into map to write to DB
    Map<String, Object> asMap = new LightRawJsonEncoder(dbEncoded).encodeOtherDetailsAsMap();
    assertNotNull(asMap);
    assertEquals(4, asMap.size());
    assertNotNull(asMap.get("/items[at0001]"));
    // Attribute mapping and correct archetype node id path in naming
    Map<String, Object> map = new FeederAuditAttributes(composition.getFeederAudit()).toMap();
    assertNotNull(map);
    assertNotNull(map.get("feeder_system_audit"));
    Map<String, Object> feederMap = (Map) map.get("feeder_system_audit");
    assertNotNull(feederMap);
    assertNotNull(feederMap.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]"));
    assertEquals(4, ((Map<String, Object>) feederMap.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]")).size());
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) Element(com.nedap.archie.rm.datastructures.Element) JsonElement(com.google.gson.JsonElement) ItemTree(com.nedap.archie.rm.datastructures.ItemTree) FeederAuditAttributes(org.ehrbase.serialisation.attributes.FeederAuditAttributes) Map(java.util.Map) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) Test(org.junit.Test)

Example 2 with ItemTree

use of com.nedap.archie.rm.datastructures.ItemTree in project openEHR_SDK by ehrbase.

the class RawJsonTest method testUnmarshalItemStructure.

@Test
public void testUnmarshalItemStructure() throws IOException {
    String value = IOUtils.toString(ItemStruktureTestDataCanonicalJson.SIMPLE_EHR_OTHER_Details.getStream(), UTF_8);
    CanonicalJson canonicalJson = new CanonicalJson();
    ItemTree itemTree = canonicalJson.unmarshal(value, ItemTree.class);
    RawJson cut = new RawJson();
    String marshal = cut.marshal(itemTree);
    ItemTree actual = cut.unmarshal(marshal, ItemTree.class);
    assertThat(actual).isNotNull();
    assertThat(actual.getItems()).size().isEqualTo(3);
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) ItemStruktureTestDataCanonicalJson(org.ehrbase.test_data.item_structure.ItemStruktureTestDataCanonicalJson) ItemTree(com.nedap.archie.rm.datastructures.ItemTree) Test(org.junit.Test)

Example 3 with ItemTree

use of com.nedap.archie.rm.datastructures.ItemTree in project openEHR_SDK by ehrbase.

the class CanonicalJsonMarshallingTest method UnmarshalItemTree.

@Test
public void UnmarshalItemTree() throws IOException {
    String value = new String(Files.readAllBytes(Paths.get("src/test/resources/sample_data/item_tree_with_multimedia.json")));
    CanonicalJson cut = new CanonicalJson();
    ItemTree itemTree = cut.unmarshal(value, ItemTree.class);
    assertNotNull(itemTree);
}
Also used : ItemTree(com.nedap.archie.rm.datastructures.ItemTree) Test(org.junit.Test)

Example 4 with ItemTree

use of com.nedap.archie.rm.datastructures.ItemTree in project openEHR_SDK by ehrbase.

the class CanonicalJsonMarshallingTest method MarshalEmptyContent.

@Test
public void MarshalEmptyContent() {
    ItemTree itemTree = new ItemTree();
    itemTree.setNameAsString("test");
    CanonicalJson cut = new CanonicalJson();
    String actual = cut.marshal(itemTree);
    assertThat(actual).isEqualToIgnoringWhitespace("{\n" + "  \"_type\" : \"ITEM_TREE\",\n" + "  \"name\" : {\n" + "    \"_type\" : \"DV_TEXT\",\n" + "    \"value\" : \"test\"\n" + "  }\n" + "}");
}
Also used : ItemTree(com.nedap.archie.rm.datastructures.ItemTree) Test(org.junit.Test)

Example 5 with ItemTree

use of com.nedap.archie.rm.datastructures.ItemTree in project openEHR_SDK by ehrbase.

the class ItemStructureVisitorTest method ehrVisitorTest.

@Test
public void ehrVisitorTest() throws Throwable {
    String value = IOUtils.toString(ItemStruktureTestDataCanonicalJson.SIMPLE_EHR_OTHER_Details.getStream(), UTF_8);
    RMJacksonConfiguration configuration = new RMJacksonConfiguration();
    configuration.setTypePropertyName("_type");
    ObjectMapper objectMapper = JacksonUtil.getObjectMapper(configuration);
    ItemTree otherDetails = objectMapper.readValue(value, ItemTree.class);
    EhrStatus ehrStatus = new EhrStatus("ehr_status", new DvText("ehr_status"), new PartySelf(new PartyRef()), true, true, otherDetails);
    itemStructureVisitor.validate(ehrStatus);
    assertEquals(3, itemStructureVisitor.getElementOccurrences());
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) ItemTree(com.nedap.archie.rm.datastructures.ItemTree) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RMJacksonConfiguration(com.nedap.archie.json.RMJacksonConfiguration) DvText(com.nedap.archie.rm.datavalues.DvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) Test(org.junit.Test)

Aggregations

ItemTree (com.nedap.archie.rm.datastructures.ItemTree)5 Test (org.junit.Test)5 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)2 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonElement (com.google.gson.JsonElement)1 RMJacksonConfiguration (com.nedap.archie.json.RMJacksonConfiguration)1 Composition (com.nedap.archie.rm.composition.Composition)1 Element (com.nedap.archie.rm.datastructures.Element)1 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)1 DvText (com.nedap.archie.rm.datavalues.DvText)1 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)1 PartySelf (com.nedap.archie.rm.generic.PartySelf)1 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)1 Map (java.util.Map)1 FeederAuditAttributes (org.ehrbase.serialisation.attributes.FeederAuditAttributes)1 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)1 ItemStruktureTestDataCanonicalJson (org.ehrbase.test_data.item_structure.ItemStruktureTestDataCanonicalJson)1