Search in sources :

Example 1 with ObjectRefRecord

use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord 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 2 with ObjectRefRecord

use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord 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)

Example 3 with ObjectRefRecord

use of org.ehrbase.jooq.pg.tables.records.ObjectRefRecord in project ehrbase by ehrbase.

the class FolderHistoryAccess 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) {
    Table<?> table_items_and_objref = table(select(FOLDER_ITEMS.FOLDER_ID, FOLDER_ITEMS.OBJECT_REF_ID.as("item_object_ref_id"), FOLDER_ITEMS.IN_CONTRIBUTION.as("item_in_contribution"), FOLDER_ITEMS.SYS_TRANSACTION, FOLDER_ITEMS.SYS_PERIOD, OBJECT_REF.ID_NAMESPACE, OBJECT_REF.TYPE, OBJECT_REF.ID.as("obj_ref_id"), OBJECT_REF.IN_CONTRIBUTION.as("obj_ref_in_cont"), OBJECT_REF.SYS_TRANSACTION.as("objRefSysTran"), OBJECT_REF.SYS_PERIOD.as("oref_sysperiod")).from(FOLDER_ITEMS).leftJoin(OBJECT_REF).on(FOLDER_ITEMS.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS.IN_CONTRIBUTION.eq(in_contribution).and(OBJECT_REF.ID.eq(FOLDER_ITEMS.OBJECT_REF_ID).and(OBJECT_REF.IN_CONTRIBUTION.eq(FOLDER_ITEMS.IN_CONTRIBUTION))))).where(FOLDER_ITEMS.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS.IN_CONTRIBUTION.eq(in_contribution))));
    Table<?> table_items_and_objref_hist = table(select(FOLDER_ITEMS_HISTORY.FOLDER_ID, FOLDER_ITEMS_HISTORY.OBJECT_REF_ID.as("item_object_ref_id"), FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.as("item_in_contribution"), FOLDER_ITEMS_HISTORY.SYS_TRANSACTION, FOLDER_ITEMS_HISTORY.SYS_PERIOD, OBJECT_REF_HISTORY.ID_NAMESPACE, OBJECT_REF_HISTORY.TYPE, OBJECT_REF_HISTORY.ID.as("obj_ref_id"), OBJECT_REF_HISTORY.IN_CONTRIBUTION.as("obj_ref_in_cont"), OBJECT_REF_HISTORY.SYS_TRANSACTION.as("objRefSysTran"), OBJECT_REF_HISTORY.SYS_PERIOD.as("oref_sysperiod")).from(FOLDER_ITEMS_HISTORY).leftJoin(OBJECT_REF_HISTORY).on(FOLDER_ITEMS_HISTORY.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.eq(in_contribution).and(OBJECT_REF_HISTORY.ID.eq(FOLDER_ITEMS_HISTORY.OBJECT_REF_ID).and(OBJECT_REF_HISTORY.IN_CONTRIBUTION.eq(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION))))).where(FOLDER_ITEMS_HISTORY.FOLDER_ID.eq(folderId).and(FOLDER_ITEMS_HISTORY.IN_CONTRIBUTION.eq(in_contribution))));
    Table<?> table_all_items_and_objref = table(select().from(table_items_and_objref).union(select().from(table_items_and_objref_hist)));
    Result<Record> retrievedRecords = domainAccess.getContext().select().from(table_all_items_and_objref).fetch();
    List<ObjectRef<?>> result = new ArrayList<>();
    for (Record recordRecord : retrievedRecords) {
        Record11<UUID, UUID, UUID, Timestamp, Timestamp, String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>> recordParam = (Record11<UUID, UUID, UUID, Timestamp, Timestamp, String, String, UUID, UUID, Timestamp, AbstractMap.SimpleEntry<OffsetDateTime, OffsetDateTime>>) recordRecord;
        ObjectRefRecord objectRef = new ObjectRefRecord();
        objectRef.setIdNamespace(recordParam.value6());
        objectRef.setType(recordParam.value7());
        objectRef.setId(recordParam.value8());
        objectRef.setInContribution(recordParam.value9());
        objectRef.setSysTransaction(recordParam.value10());
        objectRef.setSysPeriod(recordParam.value11());
        objectRef.setId(recordParam.value8());
        result.add(parseObjectRefRecordIntoObjectRef(objectRef, domainAccess));
    }
    return result;
}
Also used : Record11(org.jooq.Record11) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) AbstractMap(java.util.AbstractMap) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) OffsetDateTime(java.time.OffsetDateTime) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) Record(org.jooq.Record) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID)

Aggregations

ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)3 ObjectRefRecord (org.ehrbase.jooq.pg.tables.records.ObjectRefRecord)3 Timestamp (java.sql.Timestamp)2 OffsetDateTime (java.time.OffsetDateTime)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 FolderItemsRecord (org.ehrbase.jooq.pg.tables.records.FolderItemsRecord)2 FolderRecord (org.ehrbase.jooq.pg.tables.records.FolderRecord)2 Record (org.jooq.Record)2 SysPeriodBinder (org.ehrbase.jooq.binding.SysPeriodBinder)1 ContributionRecord (org.ehrbase.jooq.pg.tables.records.ContributionRecord)1 FolderHierarchyRecord (org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord)1 FolderHistoryRecord (org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord)1 Record11 (org.jooq.Record11)1 Record8 (org.jooq.Record8)1