Search in sources :

Example 1 with FeederAuditAttributes

use of org.ehrbase.serialisation.attributes.FeederAuditAttributes 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)

Aggregations

JsonElement (com.google.gson.JsonElement)1 Composition (com.nedap.archie.rm.composition.Composition)1 Element (com.nedap.archie.rm.datastructures.Element)1 ItemTree (com.nedap.archie.rm.datastructures.ItemTree)1 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)1 Map (java.util.Map)1 FeederAuditAttributes (org.ehrbase.serialisation.attributes.FeederAuditAttributes)1 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)1 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)1 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)1 Test (org.junit.Test)1