Search in sources :

Example 26 with ObjectVersionId

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

Example 27 with ObjectVersionId

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();
    }
}
Also used : I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId)

Example 28 with ObjectVersionId

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) InternalServerException(org.ehrbase.api.exception.InternalServerException) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) StructuredString(org.ehrbase.response.ehrscape.StructuredString) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) URI(java.net.URI) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) PreconditionFailedException(org.ehrbase.api.exception.PreconditionFailedException) InternalServerException(org.ehrbase.api.exception.InternalServerException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)28 UUID (java.util.UUID)17 InternalServerException (org.ehrbase.api.exception.InternalServerException)9 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)7 Composition (com.nedap.archie.rm.composition.Composition)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)5 I_FolderAccess (org.ehrbase.dao.access.interfaces.I_FolderAccess)5 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 HashSet (java.util.HashSet)4 CompositionDto (org.ehrbase.response.ehrscape.CompositionDto)4 Folder (com.nedap.archie.rm.directory.Folder)3 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)3 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)3 I_CompositionAccess (org.ehrbase.dao.access.interfaces.I_CompositionAccess)3 I_EntryAccess (org.ehrbase.dao.access.interfaces.I_EntryAccess)3 CompositionFormat (org.ehrbase.response.ehrscape.CompositionFormat)3 StructuredString (org.ehrbase.response.ehrscape.StructuredString)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3