use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class ContributionServiceImp method processMetadataVersion.
/**
* Helper to process versions from a contribution, which do not have the optional "data" attribute and therefore are called metadata versions.
* @param ehrId ID of given EHR scope
* @param contributionId Top level contribution this version is part of
* @param version The version wrapper object
*/
private void processMetadataVersion(UUID ehrId, UUID contributionId, Version version) {
// access audit and extract method, e.g. CREATION
I_ConceptAccess.ContributionChangeType changeType = I_ConceptAccess.ContributionChangeType.valueOf(version.getCommitAudit().getChangeType().getValue().toUpperCase());
switch(changeType) {
case DELETED:
// deleting an object without knowing which type it is requires checking of type, here with nested try-catch blocks
UUID objectUid = getVersionedUidFromVersion(version);
try {
// throw exception to signal no matching composition was found
CompositionDto compo = compositionService.retrieve(objectUid, null).orElseThrow(Exception::new);
String actualPreceding = getAndCheckActualPreceding(version);
compositionService.delete(ehrId, new ObjectVersionId(actualPreceding), contributionId);
} catch (Exception e) {
// given version ID is not of type composition - ignoring the exception because it is expected possible outcome
try {
// TODO-396: add folder handling
} catch (Exception ee) {
// given version ID is not of type folder - ignoring the exception because it is expected possible outcome
// current end of going through supported types - last step is checking for EHR_STATUS and throwing specific error
ehrService.getEhrStatus(ehrId).ifPresent(st -> {
if (st.getUid().equals(version.getPrecedingVersionUid()))
throw new InvalidApiParameterException("Invalid change type. EHR_STATUS can't be deleted.");
});
// TODO: type is technically wrong, if more than one type gets tested
throw new ObjectNotFoundException(Composition.class.getName(), "Couldn't find object matching id: " + objectUid);
}
}
break;
// TODO
case SYNTHESIS:
// TODO
case UNKNOWN:
// not expected in a metadata version (i.e. without payload)
case CREATION:
// not expected in a metadata version (i.e. without payload)
case MODIFICATION:
// not expected in a metadata version (i.e. without payload)
case AMENDMENT:
default:
throw new UnexpectedSwitchCaseException(changeType);
}
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class ContributionServiceImp method processCompositionVersion.
/**
* Helper function to process a version of composition type
* @param ehrId ID of given EHR scope
* @param contributionId Top level contribution this version is part of
* @param version The version wrapper object
* @param versionRmObject The actual composition payload
* @throws IllegalArgumentException when input is missing precedingVersionUid in case of modification
*/
private void processCompositionVersion(UUID ehrId, UUID contributionId, Version version, Composition versionRmObject) {
// access audit and extract method, e.g. CREATION
I_ConceptAccess.ContributionChangeType changeType = I_ConceptAccess.ContributionChangeType.valueOf(version.getCommitAudit().getChangeType().getValue().toUpperCase());
// evaluate and check contribution rules
checkContributionRules(version, changeType);
switch(changeType) {
case CREATION:
// call creation of a new composition with given input
compositionService.create(ehrId, versionRmObject, contributionId);
break;
// triggers the same processing as modification // TODO-396: so far so good, but should use the type "AMENDMENT" for audit in access layer
case AMENDMENT:
case MODIFICATION:
String actualPreceding = getAndCheckActualPreceding(version);
// call modification of the given composition
compositionService.update(ehrId, new ObjectVersionId(actualPreceding), versionRmObject, contributionId);
break;
case // case of deletion change type, but request also has payload (TODO: should that be even allowed? specification-wise it's not forbidden)
DELETED:
String actualPreceding2 = getAndCheckActualPreceding(version);
compositionService.delete(ehrId, new ObjectVersionId(actualPreceding2), contributionId);
break;
// TODO
case SYNTHESIS:
// TODO
case UNKNOWN:
default:
// TODO keep as long as above has TODOs. Check of valid change type is done in checkContributionRules
throw new UnexpectedSwitchCaseException(changeType);
}
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class EhrServiceImp method revisionHistoryItemFromEhrStatus.
private RevisionHistoryItem revisionHistoryItemFromEhrStatus(OriginalVersion<EhrStatus> ehrStatus, int version) {
String statusId = ehrStatus.getUid().getValue().split("::")[0];
ObjectVersionId objectVersionId = new ObjectVersionId(statusId + "::" + getServerConfig().getNodename() + "::" + version);
// Note: is List but only has more than one item when there are contributions regarding this object of change type attestation
List<AuditDetails> auditDetailsList = new ArrayList<>();
// retrieving the audits
auditDetailsList.add(ehrStatus.getCommitAudit());
// add retrieval of attestations, if there are any
if (ehrStatus.getAttestations() != null) {
for (Attestation a : ehrStatus.getAttestations()) {
AuditDetails newAudit = new AuditDetails(a.getSystemId(), a.getCommitter(), a.getTimeCommitted(), a.getChangeType(), a.getDescription());
auditDetailsList.add(newAudit);
}
}
return new RevisionHistoryItem(objectVersionId, auditDetailsList);
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class FolderServiceImp method internalCreate.
private Optional<FolderDto> internalCreate(UUID ehrId, Folder objData, UUID systemId, UUID committerId, String description, UUID contribution) {
I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrId);
if (ehrAccess == null) {
throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrId.toString());
}
// Check of there are name conflicts on each folder level
checkSiblingNameConflicts(objData);
// Save current time which will be used as transaction time
Timestamp currentTimeStamp = Timestamp.from(Instant.now());
// Contribution handling - create new one or retrieve existing, if ID is given
I_ContributionAccess contributionAccess;
if (contribution == null) {
contributionAccess = I_ContributionAccess.getInstance(getDataAccess(), ehrId);
} else {
contributionAccess = I_ContributionAccess.retrieveInstance(getDataAccess(), contribution);
// Copy values from contribution to folder's audit
systemId = contributionAccess.getAuditsSystemId();
committerId = contributionAccess.getAuditsCommitter();
description = contributionAccess.getAuditsDescription();
}
if (systemId == null || committerId == null) {
throw new InternalServerException("Error on contribution handling for folder creation.");
}
// Get first FolderAccess instance
I_FolderAccess folderAccess = FolderAccess.buildNewFolderAccessHierarchy(getDataAccess(), objData, currentTimeStamp, ehrId, contributionAccess);
ObjectVersionId folderId;
if (contribution == null) {
folderId = new ObjectVersionId(folderAccess.commit(LocalDateTime.now(), systemId, committerId, description).toString() + "::" + getServerConfig().getNodename() + "::1");
} else {
folderId = new ObjectVersionId((folderAccess.commit(LocalDateTime.now(), contribution).toString() + "::" + getServerConfig().getNodename() + "::1"));
}
// Save root directory id to ehr entry
// TODO: Refactor to use UID
ehrAccess.setDirectory(FolderUtils.extractUuidFromObjectVersionId(folderId));
ehrAccess.update(getUserUuid(), getSystemUuid(), null, null, ContributionChangeType.MODIFICATION, EhrServiceImp.DESCRIPTION);
return get(folderId, null);
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class CompositionAccess method retrieveCompositionsInContribution.
public static Map<ObjectVersionId, I_CompositionAccess> retrieveCompositionsInContribution(I_DomainAccess domainAccess, UUID contribution, String node) {
// Set, because of unique values
Set<UUID> compositions = new HashSet<>();
// add all compositions having a link to given contribution
domainAccess.getContext().select(COMPOSITION.ID).from(COMPOSITION).where(COMPOSITION.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> compositions.add(rec.value1()));
// and older versions or deleted ones, too
domainAccess.getContext().select(COMPOSITION_HISTORY.ID).from(COMPOSITION_HISTORY).where(COMPOSITION_HISTORY.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> compositions.add(rec.value1()));
// get whole "version map" of each matching composition and do fine-grain check for matching contribution
// precondition: each UUID in `compositions` set is unique, so for each the "version map" is only created once below
// (meta: can't do that as jooq query, because the specific version number isn't stored in DB)
Map<ObjectVersionId, I_CompositionAccess> resultMap = new HashMap<>();
for (UUID compositionId : compositions) {
Map<Integer, I_CompositionAccess> map = getVersionMapOfComposition(domainAccess, compositionId);
// fine-grained contribution ID check
map.forEach((k, v) -> {
if (v.getContributionId().equals(contribution)) {
resultMap.put(new ObjectVersionId(compositionId.toString(), node, k.toString()), v);
}
});
}
return resultMap;
}
Aggregations