Search in sources :

Example 16 with ObjectRef

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

the class FolderHistoryAccess method parseObjectRefRecordIntoObjectRef.

/**
 * Transforms a ObjectRef DB record into a Reference Model object.
 *
 * @param objectRefRecord
 * @param domainAccess
 * @return the reference model object.
 */
private static ObjectRef parseObjectRefRecordIntoObjectRef(ObjectRefRecord objectRefRecord, I_DomainAccess domainAccess) {
    ObjectRef result = new ObjectRef();
    ObjectRefId oref = new FolderHistoryAccess(domainAccess).new ObjectRefId(objectRefRecord.getId().toString());
    result.setId(oref);
    result.setType(objectRefRecord.getType());
    result.setNamespace(objectRefRecord.getIdNamespace());
    return result;
}
Also used : ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Example 17 with ObjectRef

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

Example 18 with ObjectRef

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

the class EhrServiceImp method getEhrStatusAtVersion.

@Override
public Optional<OriginalVersion<EhrStatus>> getEhrStatusAtVersion(UUID ehrUuid, UUID versionedObjectUid, int version) {
    // pre-step: check for valid ehrId
    if (!hasEhr(ehrUuid)) {
        throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrUuid.toString());
    }
    if ((version == 0) || (I_StatusAccess.getLatestVersionNumber(getDataAccess(), versionedObjectUid) < version)) {
        throw new ObjectNotFoundException("versioned_ehr_status", "No VERSIONED_EHR_STATUS with given version: " + version);
    }
    I_StatusAccess statusAccess = I_StatusAccess.getVersionMapOfStatus(getDataAccess(), versionedObjectUid).get(version);
    ObjectVersionId versionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + version);
    // TODO: once lifecycle state is supported, get it here dynamically
    DvCodedText lifecycleState = new DvCodedText("complete", new CodePhrase("532"));
    AuditDetails commitAudit = statusAccess.getAuditDetailsAccess().getAsAuditDetails();
    ObjectRef<HierObjectId> contribution = new ObjectRef<>(new HierObjectId(statusAccess.getStatusRecord().getInContribution().toString()), "openehr", "contribution");
    List<UUID> attestationIdList = I_AttestationAccess.retrieveListOfAttestationsByRef(getDataAccess(), statusAccess.getStatusRecord().getAttestationRef());
    // as default, gets content if available in the following lines
    List<Attestation> attestations = null;
    if (!attestationIdList.isEmpty()) {
        attestations = new ArrayList<>();
        for (UUID id : attestationIdList) {
            I_AttestationAccess a = new AttestationAccess(getDataAccess()).retrieveInstance(id);
            attestations.add(a.getAsAttestation());
        }
    }
    ObjectVersionId precedingVersionId = null;
    // check if there is a preceding version and set it, if available
    if (version > 1) {
        // in the current scope version is an int and therefore: preceding = current - 1
        precedingVersionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + (version - 1));
    }
    OriginalVersion<EhrStatus> versionStatus = new OriginalVersion<>(versionId, precedingVersionId, statusAccess.getStatus(), lifecycleState, commitAudit, contribution, null, null, attestations);
    return Optional.of(versionStatus);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) AttestationAccess(org.ehrbase.dao.access.jooq.AttestationAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

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