Search in sources :

Example 11 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef 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 12 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef in project openEHR_SDK by ehrbase.

the class CanonicalJsonMarshallingTest method marshallEhr.

@Test
public void marshallEhr() {
    List<ObjectRef<? extends ObjectId>> compositions = new ArrayList<>();
    compositions.add(new ObjectRef<>(new HierObjectId("COMPOSITION"), "local", "b5c4aaed-2adc-4c56-9005-e21ff3cca62a::local.ehrbase.org::2"));
    List<ObjectRef<? extends ObjectId>> contributions = new ArrayList<>();
    contributions.add(new ObjectRef<>(new HierObjectId("COMPOSITION"), "local", "b5c4aaed-2adc-4c56-9005-e21ff3cca62a::local.ehrbase.org::2"));
    List<ObjectRef<? extends ObjectId>> folders = new ArrayList<>();
    folders.add(new ObjectRef<>(new HierObjectId("COMPOSITION"), "local", "b5c4aaed-2adc-4c56-9005-e21ff3cca62a::local.ehrbase.org::2"));
    Ehr expected = new Ehr();
    expected.setCompositions(compositions);
    expected.setContributions(contributions);
    expected.setFolders(folders);
    CanonicalJson cut = new CanonicalJson();
    String json = cut.marshal(expected);
    Ehr actual = cut.unmarshal(json, Ehr.class);
    Assert.assertEquals(actual, expected);
}
Also used : ObjectId(com.nedap.archie.rm.support.identification.ObjectId) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) ArrayList(java.util.ArrayList) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) Ehr(com.nedap.archie.rm.ehr.Ehr) Test(org.junit.Test)

Example 13 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef in project openEHR_SDK by ehrbase.

the class CanonicalJsonMarshallingTest method marshallContribution.

@Test
public void marshallContribution() {
    List<ObjectRef<? extends ObjectId>> versions = new ArrayList<>();
    versions.add(new ObjectRef<>(new HierObjectId("COMPOSITION"), "local", "b5c4aaed-2adc-4c56-9005-e21ff3cca62a::local.ehrbase.org::2"));
    Contribution expected = new Contribution();
    expected.setUid(new HierObjectId("bbf60d27-9200-4995-a950-279f889d1050"));
    expected.setVersions(versions);
    CanonicalJson cut = new CanonicalJson();
    String json = cut.marshal(expected);
    Contribution actual = cut.unmarshal(json, Contribution.class);
    Assert.assertEquals(actual, expected);
}
Also used : ObjectId(com.nedap.archie.rm.support.identification.ObjectId) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) ArrayList(java.util.ArrayList) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) Contribution(com.nedap.archie.rm.changecontrol.Contribution) Test(org.junit.Test)

Example 14 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef in project ehrbase by ehrbase.

the class FolderAccess method saveFolderItems.

private void saveFolderItems(final UUID folderId, final UUID old_contribution, final UUID new_contribution, final Timestamp transactionTime, DSLContext context) {
    for (ObjectRef or : this.getItems()) {
        // insert in object_ref
        ObjectRefRecord orr = new ObjectRefRecord(or.getNamespace(), or.getType(), UUID.fromString(or.getId().getValue()), new_contribution, transactionTime, folderRecord.getSysPeriod());
        context.attach(orr);
        orr.store();
        // insert in folder_item
        FolderItemsRecord fir = new FolderItemsRecord(folderId, UUID.fromString(or.getId().getValue()), new_contribution, transactionTime, folderRecord.getSysPeriod());
        context.attach(fir);
        fir.store();
    }
}
Also used : ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) FolderItemsRecord(org.ehrbase.jooq.pg.tables.records.FolderItemsRecord) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Example 15 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef in project ehrbase by ehrbase.

the class FolderAccess method retrieveItemsByFolderAndContributionId.

/**
 * Retrieves a list containing the items as ObjectRefs of the folder corresponding to the id
 * provided.
 *
 * @param folderId        of the FOLDER that the items correspond to.
 * @param in_contribution contribution that establishes the reference between a FOLDER and its
 *                        item.
 * @param domainAccess    connection DB data.
 * @return
 */
private static List<ObjectRef<?>> retrieveItemsByFolderAndContributionId(UUID folderId, UUID in_contribution, I_DomainAccess domainAccess) {
    Result<Record> retrievedRecords = domainAccess.getContext().with("folderItemsSelect").as(select(FOLDER_ITEMS.OBJECT_REF_ID.as("object_ref_id"), FOLDER_ITEMS.IN_CONTRIBUTION.as("item_in_contribution")).from(FOLDER_ITEMS).where(FOLDER_ITEMS.FOLDER_ID.eq(folderId))).select().from(OBJECT_REF, table(name("folderItemsSelect"))).where(field(name("object_ref_id"), FOLDER_ITEMS.OBJECT_REF_ID.getType()).eq(OBJECT_REF.ID).and(field(name("item_in_contribution"), FOLDER_ITEMS.IN_CONTRIBUTION.getType()).eq(OBJECT_REF.IN_CONTRIBUTION))).fetch();
    List<ObjectRef<?>> result = new ArrayList<>();
    for (Record recordRecord : retrievedRecords) {
        Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID> recordParam = (Record8<String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>, UUID, UUID>) recordRecord;
        ObjectRefRecord objectRef = new ObjectRefRecord();
        objectRef.setIdNamespace(recordParam.value1());
        objectRef.setType(recordParam.value2());
        objectRef.setId(recordParam.value3());
        objectRef.setInContribution(recordParam.value4());
        objectRef.setSysTransaction(recordParam.value5());
        objectRef.setSysPeriod(new SysPeriodBinder().converter().from(recordParam.value6()));
        objectRef.setId(recordParam.value7());
        result.add(parseObjectRefRecordIntoObjectRef(objectRef, domainAccess));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) AbstractMap(java.util.AbstractMap) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) OffsetDateTime(java.time.OffsetDateTime) Record8(org.jooq.Record8) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) FolderHistoryRecord(org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord) ContributionRecord(org.ehrbase.jooq.pg.tables.records.ContributionRecord) Record(org.jooq.Record) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) FolderHierarchyRecord(org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord) FolderItemsRecord(org.ehrbase.jooq.pg.tables.records.FolderItemsRecord) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) SysPeriodBinder(org.ehrbase.jooq.binding.SysPeriodBinder)

Aggregations

ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)18 GenericId (com.nedap.archie.rm.support.identification.GenericId)7 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)7 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)5 OffsetDateTime (java.time.OffsetDateTime)5 Map (java.util.Map)5 UUID (java.util.UUID)5 Test (org.junit.Test)5 Composition (com.nedap.archie.rm.composition.Composition)4 Entry (com.nedap.archie.rm.composition.Entry)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 ArrayList (java.util.ArrayList)4 WorkflowIdTest (care.better.platform.web.template.WorkflowIdTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Section (com.nedap.archie.rm.composition.Section)3 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)3 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)3 ZoneId (java.time.ZoneId)3 ZonedDateTime (java.time.ZonedDateTime)3