Search in sources :

Example 11 with OriginalVersion

use of com.nedap.archie.rm.changecontrol.OriginalVersion in project openEHR_SDK by ehrbase.

the class DefaultRestVersionedCompositionEndpointIT method testFindVersionByIdWrongVersionId.

@Test
public void testFindVersionByIdWrongVersionId() {
    ehrId = openEhrClient.ehrEndpoint().createEhr();
    EpisodeOfCareComposition composition = TestData.buildEpisodeOfCareComposition();
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition);
    VersionUid dummyVersionId = new VersionUid(composition.getVersionUid().getUuid(), composition.getVersionUid().getSystem(), 5);
    Optional<OriginalVersion<EpisodeOfCareComposition>> originalVersion = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionById(composition.getVersionUid().getUuid(), dummyVersionId, EpisodeOfCareComposition.class);
    Assert.assertTrue(originalVersion.isEmpty());
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) VersionUid(org.ehrbase.client.openehrclient.VersionUid) EpisodeOfCareComposition(org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition) Test(org.junit.Test)

Example 12 with OriginalVersion

use of com.nedap.archie.rm.changecontrol.OriginalVersion in project openEHR_SDK by ehrbase.

the class DefaultRestVersionedCompositionEndpointIT method testFindVersionAtTime.

@Test
public void testFindVersionAtTime() {
    ehrId = openEhrClient.ehrEndpoint().createEhr();
    LocalDateTime versionAtTime;
    Optional<OriginalVersion<AlternativeEventsComposition>> result;
    // Before
    versionAtTime = LocalDateTime.now();
    AlternativeEventsComposition composition1 = TestData.buildAlternativeEventsComposition();
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition1);
    result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition1.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
    Assert.assertTrue(result.isEmpty());
    // Between
    AlternativeEventsComposition composition2 = TestData.buildAlternativeEventsComposition();
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
    VersionUid v2 = openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2).getVersionUid();
    versionAtTime = LocalDateTime.now();
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition2);
    result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition2.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
    Assert.assertTrue(result.isPresent());
    Assert.assertEquals(v2.toString(), result.get().getUid().getValue());
    // Last
    AlternativeEventsComposition composition3 = TestData.buildAlternativeEventsComposition();
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
    openEhrClient.compositionEndpoint(ehrId).mergeCompositionEntity(composition3);
    versionAtTime = LocalDateTime.now();
    result = openEhrClient.versionedCompositionEndpoint(ehrId).findVersionAtTime(composition3.getVersionUid().getUuid(), versionAtTime, AlternativeEventsComposition.class);
    Assert.assertTrue(result.isPresent());
    Assert.assertEquals(composition3.getVersionUid().toString(), result.get().getUid().getValue());
}
Also used : LocalDateTime(java.time.LocalDateTime) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) VersionUid(org.ehrbase.client.openehrclient.VersionUid) AlternativeEventsComposition(org.ehrbase.client.classgenerator.examples.alternativeeventscomposition.AlternativeEventsComposition) Test(org.junit.Test)

Example 13 with OriginalVersion

use of com.nedap.archie.rm.changecontrol.OriginalVersion in project ehrbase by ehrbase.

the class OpenehrEhrStatusController method buildEhrStatusResponseData.

/**
 * 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       Ehr reference
 * @param ehrStatusId EhrStatus versioned object ID
 * @param version     EhrStatus version number
 * @param accept      Requested content format
 * @param headerList  Requested headers that need to be set
 * @param <T>         Either only header response or specific class EhrStatusResponseData
 * @return
 */
private <T extends EhrStatusResponseData> Optional<InternalResponse<T>> buildEhrStatusResponseData(Supplier<T> factory, UUID ehrId, UUID ehrStatusId, int version, String accept, List<String> headerList) {
    // create either EhrStatusResponseData or null (means no body, only headers incl. link to resource), via lambda request
    T minimalOrRepresentation = factory.get();
    // check for valid format header to produce content accordingly
    MediaType contentType = resolveContentType(// to prepare header input if this header is needed later
    accept);
    Optional<OriginalVersion<EhrStatus>> ehrStatus = ehrService.getEhrStatusAtVersion(ehrId, ehrStatusId, version);
    if (minimalOrRepresentation != null) {
        // when this "if" is true the following casting can be executed and data manipulated by reference (handled by temporary variable)
        EhrStatusResponseData objByReference = minimalOrRepresentation;
        if (ehrStatus.isPresent()) {
            objByReference.setArchetypeNodeId(ehrStatus.get().getData().getArchetypeNodeId());
            objByReference.setName(ehrStatus.get().getData().getName());
            objByReference.setUid(ehrStatus.get().getUid());
            objByReference.setSubject(ehrStatus.get().getData().getSubject());
            objByReference.setOtherDetails(ehrStatus.get().getData().getOtherDetails());
            objByReference.setModifiable(ehrStatus.get().getData().isModifiable());
            objByReference.setQueryable(ehrStatus.get().getData().isQueryable());
        } else {
            return Optional.empty();
        }
    }
    // 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:
                respHeaders.setContentType(contentType);
                break;
            case LOCATION:
                try {
                    URI url = new URI(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId + "/ehr_status/" + ehrStatusId + "::" + ehrService.getServerConfig().getNodename() + "::" + version);
                    respHeaders.setLocation(url);
                } catch (Exception e) {
                    throw new InternalServerException(e.getMessage());
                }
                break;
            case ETAG:
                respHeaders.setETag("\"" + ehrStatusId + "::" + ehrService.getServerConfig().getNodename() + "::" + version + "\"");
                break;
            case LAST_MODIFIED:
                ehrStatus.ifPresent(ehrStatusOriginalVersion -> respHeaders.setLastModified(ehrStatusOriginalVersion.getCommitAudit().getTimeCommitted().getMagnitude()));
                break;
            default:
        }
    }
    return Optional.of(new InternalResponse<>(minimalOrRepresentation, respHeaders));
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) HttpHeaders(org.springframework.http.HttpHeaders) InternalServerException(org.ehrbase.api.exception.InternalServerException) EhrStatusResponseData(org.ehrbase.response.openehr.EhrStatusResponseData) MediaType(org.springframework.http.MediaType) URI(java.net.URI) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) PreconditionFailedException(org.ehrbase.api.exception.PreconditionFailedException) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException)

Example 14 with OriginalVersion

use of com.nedap.archie.rm.changecontrol.OriginalVersion in project ehrbase by ehrbase.

the class OpenehrEhrStatusController method getEhrStatusByVersionId.

/**
 * {@inheritDoc}
 */
@Override
@GetMapping(path = "/{version_uid}")
@PreAuthorize("checkAbacPre(@openehrEhrStatusController.EHR_STATUS, @ehrService.getSubjectExtRef(#ehrIdString))")
public ResponseEntity<EhrStatusResponseData> getEhrStatusByVersionId(@PathVariable(name = "ehr_id") UUID ehrId, @PathVariable(name = "version_uid") String versionUid, @RequestHeader(name = HttpHeaders.ACCEPT, required = false) String accept) {
    assertEhrExists(ehrId);
    UUID versionedObjectUid = extractVersionedObjectUidFromVersionUid(versionUid);
    int version = extractVersionFromVersionUid(versionUid);
    Optional<OriginalVersion<EhrStatus>> ehrStatus = ehrService.getEhrStatusAtVersion(ehrId, versionedObjectUid, version);
    UUID ehrStatusId = extractVersionedObjectUidFromVersionUid(ehrStatus.orElseThrow(() -> new ObjectNotFoundException("ehr_status", "EHR_STATUS not found")).getUid().toString());
    return internalGetEhrStatusProcessing(accept, ehrId, ehrStatusId, version);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) UUID(java.util.UUID) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with OriginalVersion

use of com.nedap.archie.rm.changecontrol.OriginalVersion 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

OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)16 UUID (java.util.UUID)8 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)6 Test (org.junit.Test)6 LocalDateTime (java.time.LocalDateTime)5 InternalServerException (org.ehrbase.api.exception.InternalServerException)5 EpisodeOfCareComposition (org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition)5 RevisionHistory (com.nedap.archie.rm.generic.RevisionHistory)4 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)4 HttpHeaders (org.springframework.http.HttpHeaders)4 MediaType (org.springframework.http.MediaType)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)3 VersionedEhrStatus (com.nedap.archie.rm.ehr.VersionedEhrStatus)3 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 ContributionService (org.ehrbase.api.service.ContributionService)3 EhrService (org.ehrbase.api.service.EhrService)3 ContributionDto (org.ehrbase.response.ehrscape.ContributionDto)3