use of com.nedap.archie.rm.support.identification.ObjectVersionId 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);
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class FolderServiceImp method internalUpdate.
private Optional<FolderDto> internalUpdate(UUID ehrId, ObjectVersionId targetObjId, Folder objData, UUID systemId, UUID committerId, String description, UUID contribution) {
var timestamp = LocalDateTime.now();
// Check of there are name conflicts on each folder level
checkSiblingNameConflicts(objData);
// Get existing root folder
I_FolderAccess folderAccess = I_FolderAccess.getInstanceForExistingFolder(getDataAccess(), targetObjId);
// Set update data on root folder
FolderUtils.updateFolder(objData, folderAccess);
// Delete sub folders and all their sub folder, as well as their linked entities
if (contribution == null) {
folderAccess.getSubfoldersList().forEach((sf, sa) -> delete(ehrId, new ObjectVersionId(sf.toString()), systemId, committerId, description));
} else {
folderAccess.getSubfoldersList().forEach((sf, sa) -> delete(ehrId, new ObjectVersionId(sf.toString()), contribution));
}
// Clear sub folder list
folderAccess.getSubfoldersList().clear();
// Create FolderAccess instances for sub folders if there are any
if (objData.getFolders() != null && !objData.getFolders().isEmpty()) {
// Create new sub folders list
objData.getFolders().forEach(childFolder -> folderAccess.getSubfoldersList().put(UUID.randomUUID(), FolderAccess.buildNewFolderAccessHierarchy(getDataAccess(), childFolder, Timestamp.from(Instant.now()), ehrId, ((FolderAccess) folderAccess).getContributionAccess())));
}
// Send update to access layer which updates the hierarchy recursive
boolean success;
if (contribution == null) {
success = folderAccess.update(timestamp, systemId, committerId, description, ContributionChangeType.MODIFICATION);
} else {
success = folderAccess.update(timestamp, contribution);
}
if (success) {
return createDto(folderAccess, getLastVersionNumber(targetObjId), true);
} else {
return Optional.empty();
}
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class OpenehrCompositionController method deleteComposition.
@DeleteMapping("/{ehr_id}/composition/{preceding_version_uid}")
// checkAbacPre /-Post attributes (type, subject, payload, content type)
@PreAuthorize("checkAbacPre(@openehrCompositionController.COMPOSITION, " + "@ehrService.getSubjectExtRef(#ehrIdString), #precedingVersionUid, null)")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@Override
public ResponseEntity deleteComposition(@RequestHeader(value = "openEHR-VERSION", required = false) String openehrVersion, @RequestHeader(value = "openEHR-AUDIT_DETAILS", required = false) String openehrAuditDetails, @PathVariable(value = "ehr_id") String ehrIdString, @PathVariable(value = "preceding_version_uid") String precedingVersionUid, HttpServletRequest request) {
UUID ehrId = getEhrUuid(ehrIdString);
HttpHeaders headers = new HttpHeaders();
// check if this composition in given preceding version is available
compositionService.retrieve(extractVersionedObjectUidFromVersionUid(precedingVersionUid), 1).orElseThrow(() -> new ObjectNotFoundException("composition", "No EHR with the supplied ehr_id or no COMPOSITION with the supplied preceding_version_uid."));
// TODO check for ehr + composition match as well - wow to to that? should be part of deletion, according to openEHR platform spec --> postponed, see EHR-265
// TODO check if already deleted - how is that saved / retrievable? --> postponed, see EHR-264
/*if () {
throw new GeneralRequestProcessingException("The composition with preceding_version_uid is already deleted."); // exception is wired to 400 BAD_REQUEST
}*/
// prepare header data
String latestVersionId = extractVersionedObjectUidFromVersionUid(precedingVersionUid) + "::" + compositionService.getServerConfig().getNodename() + "::" + compositionService.getLastVersionNumber(extractVersionedObjectUidFromVersionUid(precedingVersionUid));
// TODO change to dynamic linking --> postponed, see EHR-230
URI uri = URI.create(this.encodePath(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId.toString() + "/composition/" + latestVersionId));
// If precedingVersionUid parameter doesn't match latest version
if (!compositionService.getLastVersionNumber(extractVersionedObjectUidFromVersionUid(precedingVersionUid)).equals(extractVersionFromVersionUid(precedingVersionUid))) {
// 409 is returned when supplied preceding_version_uid doesn’t match the latest version. Returns latest version in the Location and ETag headers.
headers.setLocation(uri);
headers.setETag("\"" + latestVersionId + "\"");
return ResponseEntity.status(HttpStatus.CONFLICT).headers(headers).build();
}
try {
// the actual deleting
// precedingVersionUid needs to be checked already
compositionService.delete(ehrId, new ObjectVersionId(precedingVersionUid));
headers.setLocation(uri);
headers.setETag("\"" + latestVersionId + "\"");
headers.setLastModified(ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).toInstant().toEpochMilli());
// Enriches request attributes with current compositionId for later audit processing
request.setAttribute(OpenEhrAuditInterceptor.EHR_ID_ATTRIBUTE, Collections.singleton(ehrId));
request.setAttribute(CompositionAuditInterceptor.COMPOSITION_ID_ATTRIBUTE, extractVersionedObjectUidFromVersionUid(precedingVersionUid));
return ResponseEntity.noContent().headers(headers).build();
} catch (ObjectNotFoundException e) {
// if composition not available at all --> 404
throw new ObjectNotFoundException("composition", "No EHR with the supplied ehr_id or no COMPOSITION with the supplied preceding_version_uid.");
} catch (Exception e) {
throw new InternalServerException("Deleting of composition failed", e);
}
}
Aggregations