Search in sources :

Example 6 with ObjectVersionId

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);
    }
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId)

Example 7 with ObjectVersionId

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);
    }
}
Also used : ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId)

Example 8 with ObjectVersionId

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);
}
Also used : ArrayList(java.util.ArrayList) StructuredString(org.ehrbase.response.ehrscape.StructuredString) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId)

Example 9 with ObjectVersionId

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);
}
Also used : I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) InternalServerException(org.ehrbase.api.exception.InternalServerException) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) I_ContributionAccess(org.ehrbase.dao.access.interfaces.I_ContributionAccess) I_EhrAccess(org.ehrbase.dao.access.interfaces.I_EhrAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Timestamp(java.sql.Timestamp)

Example 10 with ObjectVersionId

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

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