Search in sources :

Example 21 with EhrStatus

use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.

the class OpenehrEhrController method buildEhrResponseData.

/**
 * Builder method to prepare appropriate HTTP response. Flexible to either allow minimal or full representation of resource.
 *
 * @param factory    Lambda function to constructor of desired object
 * @param ehrId      Current object's reference
 * @param accept     Requested content format
 * @param headerList Requested headers that need to be set
 * @param <T>        Either EhrResponseData itself or more specific sub-class EhrResponseDataRepresentation
 * @return
 */
private <T extends EhrResponseData> Optional<InternalResponse<T>> buildEhrResponseData(Supplier<T> factory, UUID ehrId, /*Action create,*/
String accept, List<String> headerList) {
    // check for valid format header to produce content accordingly
    MediaType contentType = resolveContentType(accept);
    // Optional<EhrStatusDto> ehrStatus = ehrService.getEhrStatusEhrScape(ehrId, CompositionFormat.FLAT);    // older, keep until rework of formatting
    Optional<EhrStatus> ehrStatus = ehrService.getEhrStatus(ehrId);
    if (ehrStatus.isEmpty()) {
        return Optional.empty();
    }
    // create either null or maximum response data class
    T minimalOrRepresentation = factory.get();
    if (minimalOrRepresentation != null) {
        // populate maximum response data
        EhrResponseData objByReference = minimalOrRepresentation;
        objByReference.setEhrId(new HierObjectId(ehrId.toString()));
        objByReference.setEhrStatus(ehrStatus.get());
        objByReference.setSystemId(new HierObjectId(ehrService.getSystemUuid().toString()));
        DvDateTime timeCreated = ehrService.getCreationTime(ehrId);
        objByReference.setTimeCreated(timeCreated.getValue().toString());
    // objByReference.setCompositions(null);    // TODO get actual data from service layer
    // objByReference.setContributions(null);   // TODO get actual data from service layer
    }
    // create and supplement headers with data depending on which headers are requested
    HttpHeaders respHeaders = new HttpHeaders();
    for (String header : headerList) {
        switch(header) {
            case CONTENT_TYPE:
                if (// if response is going to have a body
                minimalOrRepresentation != null)
                    respHeaders.setContentType(contentType);
                break;
            case LOCATION:
                try {
                    URI url = new URI(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId);
                    respHeaders.setLocation(url);
                } catch (Exception e) {
                    throw new InternalServerException(e.getMessage());
                }
                break;
            case ETAG:
                respHeaders.setETag("\"" + ehrId + "\"");
                break;
            case LAST_MODIFIED:
                // TODO should be VERSION.commit_audit.time_committed.value which is not implemented yet - mock for now
                respHeaders.setLastModified(123124442);
                break;
            default:
        }
    }
    return Optional.of(new InternalResponse<>(minimalOrRepresentation, respHeaders));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) InternalServerException(org.ehrbase.api.exception.InternalServerException) URI(java.net.URI) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) StateConflictException(org.ehrbase.api.exception.StateConflictException) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) MediaType(org.springframework.http.MediaType) EhrResponseData(org.ehrbase.response.openehr.EhrResponseData) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 22 with EhrStatus

use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.

the class EhrServiceImp method getVersionedEhrStatus.

@Override
public VersionedEhrStatus getVersionedEhrStatus(UUID ehrUid) {
    // FIXME VERSIONED_OBJECT_POC: Pre_has_ehr: has_ehr (an_ehr_id)
    // FIXME VERSIONED_OBJECT_POC: Pre_has_ehr_status_version: has_ehr_status_version (an_ehr_id, a_version_uid)
    Optional<EhrStatus> ehrStatus = getEhrStatus(ehrUid);
    VersionedEhrStatus versionedEhrStatus = new VersionedEhrStatus();
    if (ehrStatus.isPresent()) {
        versionedEhrStatus.setUid(new HierObjectId(ehrStatus.get().getUid().getRoot().getValue()));
        versionedEhrStatus.setOwnerId(new ObjectRef<>(new HierObjectId(ehrUid.toString()), "local", "EHR"));
        I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrUid);
        versionedEhrStatus.setTimeCreated(new DvDateTime(OffsetDateTime.of(ehrAccess.getStatusAccess().getInitialTimeOfVersionedEhrStatus().toLocalDateTime(), OffsetDateTime.now().getOffset())));
    }
    return versionedEhrStatus;
}
Also used : VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 23 with EhrStatus

use of com.nedap.archie.rm.ehr.EhrStatus 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)

Aggregations

EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)23 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)12 UUID (java.util.UUID)11 PartySelf (com.nedap.archie.rm.generic.PartySelf)9 DvText (com.nedap.archie.rm.datavalues.DvText)8 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)7 VersionedEhrStatus (com.nedap.archie.rm.ehr.VersionedEhrStatus)6 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)5 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)5 HttpHeaders (org.springframework.http.HttpHeaders)5 OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)4 URI (java.net.URI)4 InternalServerException (org.ehrbase.api.exception.InternalServerException)4 Test (org.junit.Test)4 MediaType (org.springframework.http.MediaType)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Timestamp (java.sql.Timestamp)3 Optional (java.util.Optional)3 EhrService (org.ehrbase.api.service.EhrService)3 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)3