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;
}
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;
}
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);
}
Aggregations