Search in sources :

Example 16 with OriginalVersion

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

the class EhrServiceImp method getRevisionHistoryOfVersionedEhrStatus.

@Override
public RevisionHistory getRevisionHistoryOfVersionedEhrStatus(UUID ehrUid) {
    I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrUid);
    // get number of versions
    int versions = I_StatusAccess.getLatestVersionNumber(getDataAccess(), ehrAccess.getStatusId());
    // fetch each version
    UUID versionedObjectUid = getEhrStatusVersionedObjectUidByEhr(ehrUid);
    RevisionHistory revisionHistory = new RevisionHistory();
    for (int i = 1; i <= versions; i++) {
        Optional<OriginalVersion<EhrStatus>> ehrStatus = getEhrStatusAtVersion(ehrUid, versionedObjectUid, i);
        // create RevisionHistoryItem for each version and append it to RevisionHistory
        if (ehrStatus.isPresent())
            revisionHistory.addItem(revisionHistoryItemFromEhrStatus(ehrStatus.get(), i));
    }
    if (revisionHistory.getItems().isEmpty()) {
        // never should be empty; not valid
        throw new InternalServerException("Problem creating RevisionHistory");
    }
    return revisionHistory;
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) UUID(java.util.UUID)

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