Search in sources :

Example 1 with AuditDetails

use of com.nedap.archie.rm.generic.AuditDetails in project ehrbase by ehrbase.

the class CompositionServiceImp method getOriginalVersionComposition.

@Override
public Optional<OriginalVersion<Composition>> getOriginalVersionComposition(UUID versionedObjectUid, int version) {
    // check for valid version parameter
    if ((version == 0) || I_CompositionAccess.getLastVersionNumber(getDataAccess(), versionedObjectUid) < version) {
        throw new ObjectNotFoundException("versioned_composition", "No VERSIONED_COMPOSITION with given version: " + version);
    }
    // retrieve requested object
    I_CompositionAccess compositionAccess = I_CompositionAccess.retrieveCompositionVersion(getDataAccess(), versionedObjectUid, version);
    if (compositionAccess == null) {
        return Optional.empty();
    }
    // create data for output, i.e. fields of the OriginalVersion<Composition>
    ObjectVersionId versionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + version);
    DvCodedText lifecycleState = new DvCodedText("complete", new CodePhrase(// TODO: once lifecycle state is supported, get it here dynamically
    "532"));
    AuditDetails commitAudit = compositionAccess.getAuditDetailsAccess().getAsAuditDetails();
    ObjectRef<HierObjectId> contribution = new ObjectRef<>(new HierObjectId(compositionAccess.getContributionId().toString()), "openehr", "contribution");
    List<UUID> attestationIdList = I_AttestationAccess.retrieveListOfAttestationsByRef(getDataAccess(), compositionAccess.getAttestationRef());
    List<Attestation> attestations = // as default, gets content if available in the following lines
    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));
    }
    Optional<CompositionDto> compositionDto = retrieve(versionedObjectUid, version);
    Composition composition = null;
    if (compositionDto.isPresent()) {
        composition = compositionDto.get().getComposition();
    }
    OriginalVersion<Composition> versionComposition = new OriginalVersion<>(versionId, precedingVersionId, composition, lifecycleState, commitAudit, contribution, null, null, attestations);
    return Optional.of(versionComposition);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) Composition(com.nedap.archie.rm.composition.Composition) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) AttestationAccess(org.ehrbase.dao.access.jooq.AttestationAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Attestation(com.nedap.archie.rm.generic.Attestation) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) I_CompositionAccess(org.ehrbase.dao.access.interfaces.I_CompositionAccess) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 2 with AuditDetails

use of com.nedap.archie.rm.generic.AuditDetails in project ehrbase by ehrbase.

the class CompositionServiceImp method revisionHistoryItemFromComposition.

private RevisionHistoryItem revisionHistoryItemFromComposition(OriginalVersion<Composition> composition) {
    ObjectVersionId objectVersionId = composition.getUid();
    // 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(composition.getCommitAudit());
    // add retrieval of attestations, if there are any
    if (composition.getAttestations() != null) {
        for (Attestation a : composition.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 : RevisionHistoryItem(com.nedap.archie.rm.generic.RevisionHistoryItem) ArrayList(java.util.ArrayList) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) Attestation(com.nedap.archie.rm.generic.Attestation)

Example 3 with AuditDetails

use of com.nedap.archie.rm.generic.AuditDetails in project ehrbase by ehrbase.

the class ContributionServiceImp method commitContribution.

@Override
public UUID commitContribution(UUID ehrId, String content, CompositionFormat format) {
    // pre-step: check for valid ehrId
    if (!ehrService.hasEhr(ehrId)) {
        throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrId.toString());
    }
    // create new empty/standard-value contribution - will be updated later with full details
    I_ContributionAccess contributionAccess = I_ContributionAccess.getInstance(this.getDataAccess(), ehrId);
    // parse and set audit information from input
    AuditDetails audit = ContributionServiceHelper.parseAuditDetails(content, format);
    contributionAccess.setAuditDetailsValues(audit);
    // commits with all default values (but without audit handling as it is done above)
    UUID contributionId = contributionAccess.commit(null, null, null);
    List<Version> versions = ContributionServiceHelper.parseVersions(content, format);
    if (versions.isEmpty())
        throw new InvalidApiParameterException("Invalid Contribution, must have at least one Version object.");
    // go through those RM objects and execute the action of it (as listed in its audit) and connect it to new contribution
    for (Version version : versions) {
        Object versionData = version.getData();
        if (versionData != null) {
            // the version contains the optional "data" attribute (i.e. payload), therefore has specific object type (composition, folder,...)
            RMObject versionRmObject;
            if (versionData instanceof LinkedHashMap) {
                versionRmObject = ContributionServiceHelper.unmarshalMapContentToRmObject((LinkedHashMap) versionData, format);
            } else {
                throw new IllegalArgumentException("Contribution input can't be processed");
            }
            // switch to allow acting depending on exact type
            SupportedClasses versionClass;
            try {
                versionClass = SupportedClasses.valueOf(versionRmObject.getClass().getSimpleName().toUpperCase());
            } catch (Exception e) {
                throw new InvalidApiParameterException("Invalid version object in contribution. " + versionRmObject.getClass().getSimpleName().toUpperCase() + " not supported.");
            }
            switch(versionClass) {
                case COMPOSITION:
                    try {
                        processCompositionVersion(ehrId, contributionId, version, (Composition) versionRmObject);
                    } catch (UnprocessableEntityException e) {
                        throw new ValidationException(e.getMessage());
                    }
                    break;
                case EHRSTATUS:
                    processEhrStatusVersion(ehrId, contributionId, version, (EhrStatus) versionRmObject);
                    break;
                case FOLDER:
                    processFolderVersion(ehrId, contributionId, version, (Folder) versionRmObject);
                    break;
                default:
                    throw new UnexpectedSwitchCaseException(versionClass);
            }
        } else {
            // version doesn't contain "data", so it is only a metadata one to, for instance, delete a specific object via ID regardless of type
            processMetadataVersion(ehrId, contributionId, version);
        }
    }
    return contributionId;
}
Also used : Version(com.nedap.archie.rm.changecontrol.Version) RMObject(com.nedap.archie.rm.RMObject) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) RMObject(com.nedap.archie.rm.RMObject)

Example 4 with AuditDetails

use of com.nedap.archie.rm.generic.AuditDetails in project ehrbase by ehrbase.

the class AttestationAccess method getAsAttestation.

@Override
public Attestation getAsAttestation() {
    // take most values from super class entry
    AuditDetails audit = auditDetailsAccess.getAsAuditDetails();
    String systemId = audit.getSystemId();
    PartyProxy committer = audit.getCommitter();
    DvDateTime time = audit.getTimeCommitted();
    DvCodedText changeType = audit.getChangeType();
    DvText description = audit.getDescription();
    // FIXME VERSIONED_OBJECT_POC: implement retrieval from "attested_view" table
    DvMultimedia attestedView = null;
    String proof = attestationRecord.getProof();
    // FIXME VERSIONED_OBJECT_POC: implement?! seems to be completely unsupported right now
    List<DvEHRURI> items = null;
    DvText reason = new DvText(attestationRecord.getReason());
    boolean isPending = attestationRecord.getIsPending();
    return new Attestation(systemId, committer, time, changeType, description, attestedView, proof, items, reason, isPending);
}
Also used : DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) DvEHRURI(com.nedap.archie.rm.datavalues.DvEHRURI) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) DvMultimedia(com.nedap.archie.rm.datavalues.encapsulated.DvMultimedia) Attestation(com.nedap.archie.rm.generic.Attestation) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 5 with AuditDetails

use of com.nedap.archie.rm.generic.AuditDetails in project ehrbase by ehrbase.

the class AuditDetailsAccess method getAsAuditDetails.

@Override
public AuditDetails getAsAuditDetails() {
    String systemId = getSystemId().toString();
    PartyProxy party = new PersistedPartyProxy(this).retrieve(getCommitter());
    DvDateTime time = new DvDateTime(getTimeCommitted().toLocalDateTime());
    DvCodedText changeType = new DvCodedText(getChangeType().getLiteral(), new CodePhrase(new TerminologyId("openehr"), Integer.toString(I_ConceptAccess.ContributionChangeType.valueOf(getChangeType().getLiteral().toUpperCase()).getCode())));
    DvText description = new DvText(getDescription());
    return new AuditDetails(systemId, party, time, changeType, description);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText)

Aggregations

AuditDetails (com.nedap.archie.rm.generic.AuditDetails)7 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)4 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)3 DvText (com.nedap.archie.rm.datavalues.DvText)3 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)3 Attestation (com.nedap.archie.rm.generic.Attestation)3 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)3 RMObject (com.nedap.archie.rm.RMObject)2 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)2 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)2 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)1 Version (com.nedap.archie.rm.changecontrol.Version)1 Composition (com.nedap.archie.rm.composition.Composition)1 DvEHRURI (com.nedap.archie.rm.datavalues.DvEHRURI)1 DvMultimedia (com.nedap.archie.rm.datavalues.encapsulated.DvMultimedia)1 VersionedComposition (com.nedap.archie.rm.ehr.VersionedComposition)1 RevisionHistoryItem (com.nedap.archie.rm.generic.RevisionHistoryItem)1 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)1