Search in sources :

Example 1 with OriginalVersion

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

the class CompositionServiceImp method getRevisionHistoryOfVersionedComposition.

@Override
public RevisionHistory getRevisionHistoryOfVersionedComposition(UUID composition) {
    // get number of versions
    int versions = getLastVersionNumber(composition);
    // fetch each version and add to revision history
    RevisionHistory revisionHistory = new RevisionHistory();
    for (int i = 1; i <= versions; i++) {
        Optional<OriginalVersion<Composition>> compoVersion = getOriginalVersionComposition(composition, i);
        compoVersion.ifPresent(compositionOriginalVersion -> revisionHistory.addItem(revisionHistoryItemFromComposition(compositionOriginalVersion)));
    }
    if (revisionHistory.getItems().isEmpty()) {
        throw new InternalServerException(// never should be empty; not valid
        "Problem creating RevisionHistory");
    }
    return revisionHistory;
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) RevisionHistory(com.nedap.archie.rm.generic.RevisionHistory) InternalServerException(org.ehrbase.api.exception.InternalServerException)

Example 2 with OriginalVersion

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

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

the class OpenehrVersionedCompositionController method getOriginalVersionResponseDataResponseEntity.

private ResponseEntity<OriginalVersionResponseData<Composition>> getOriginalVersionResponseDataResponseEntity(String accept, UUID ehrId, UUID versionedObjectId, int version) {
    Optional<OriginalVersion<Composition>> compositionOriginalVersion = compositionService.getOriginalVersionComposition(versionedObjectId, version);
    UUID contributionId = compositionOriginalVersion.map(i -> UUID.fromString(i.getContribution().getId().getValue())).orElseThrow(() -> new InvalidApiParameterException("Couldn't retrieve Composition with given parameters"));
    Optional<ContributionDto> optionalContributionDto = contributionService.getContribution(ehrId, contributionId);
    // shouldn't happen
    ContributionDto contributionDto = optionalContributionDto.orElseThrow(() -> new InternalServerException("Couldn't fetch contribution for existing Composition"));
    OriginalVersionResponseData<Composition> originalVersionResponseData = new OriginalVersionResponseData<>(compositionOriginalVersion.orElseThrow(() -> new InternalServerException("Composition exists but can't be retrieved as Original Version.")), contributionDto);
    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.setContentType(resolveContentType(accept));
    return ResponseEntity.ok().headers(respHeaders).body(originalVersionResponseData);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ContributionService(org.ehrbase.api.service.ContributionService) Composition(com.nedap.archie.rm.composition.Composition) LocalDateTime(java.time.LocalDateTime) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EhrService(org.ehrbase.api.service.EhrService) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) VersionedCompositionApiSpecification(org.ehrbase.rest.openehr.specification.VersionedCompositionApiSpecification) RevisionHistoryResponseData(org.ehrbase.response.openehr.RevisionHistoryResponseData) GetMapping(org.springframework.web.bind.annotation.GetMapping) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) HttpHeaders(org.springframework.http.HttpHeaders) VersionedObjectResponseData(org.ehrbase.response.openehr.VersionedObjectResponseData) MediaType(org.springframework.http.MediaType) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) UUID(java.util.UUID) RestController(org.springframework.web.bind.annotation.RestController) BaseController(org.ehrbase.rest.BaseController) Objects(java.util.Objects) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) CompositionService(org.ehrbase.api.service.CompositionService) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) Optional(java.util.Optional) RevisionHistory(com.nedap.archie.rm.generic.RevisionHistory) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) HttpHeaders(org.springframework.http.HttpHeaders) Composition(com.nedap.archie.rm.composition.Composition) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) InternalServerException(org.ehrbase.api.exception.InternalServerException) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) UUID(java.util.UUID) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData)

Example 4 with OriginalVersion

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

the class OpenehrVersionedEhrStatusController method retrieveVersionOfEhrStatusByVersionUid.

@GetMapping(path = "/version/{version_uid}")
// checkAbacPre /-Post attributes (type, subject, payload, content type)
@PreAuthorize("checkAbacPre(@openehrVersionedEhrStatusController.EHR_STATUS, " + "@ehrService.getSubjectExtRef(#ehrIdString), null, null)")
@Override
public ResponseEntity<OriginalVersionResponseData<EhrStatus>> retrieveVersionOfEhrStatusByVersionUid(@RequestHeader(value = HttpHeaders.ACCEPT, required = false) String accept, @PathVariable(value = "ehr_id") String ehrIdString, @PathVariable(value = "version_uid") String versionUid) {
    UUID ehrId = getEhrUuid(ehrIdString);
    // check if EHR is valid
    if (!ehrService.hasEhr(ehrId)) {
        throw new ObjectNotFoundException("ehr", "No EHR with this ID can be found.");
    }
    // parse given version uid
    UUID versionedObjectId;
    int version;
    try {
        versionedObjectId = UUID.fromString(versionUid.split("::")[0]);
        version = Integer.parseInt(versionUid.split("::")[2]);
    } catch (Exception e) {
        throw new InvalidApiParameterException("VERSION UID parameter has wrong format: " + e.getMessage());
    }
    if (version < 1)
        throw new InvalidApiParameterException("Version can't be negative.");
    if (!ehrService.hasStatus(versionedObjectId)) {
        throw new ObjectNotFoundException("ehr_status", "No EHR_STATUS with given ID can be found.");
    }
    Optional<OriginalVersion<EhrStatus>> ehrStatusOriginalVersion = ehrService.getEhrStatusAtVersion(ehrId, versionedObjectId, version);
    UUID contributionId = ehrStatusOriginalVersion.map(i -> UUID.fromString(i.getContribution().getId().getValue())).orElseThrow(() -> new InvalidApiParameterException("Couldn't retrieve EhrStatus with given parameters"));
    Optional<ContributionDto> optionalContributionDto = contributionService.getContribution(ehrId, contributionId);
    // shouldn't happen
    ContributionDto contributionDto = optionalContributionDto.orElseThrow(() -> new InternalServerException("Couldn't fetch contribution for existing EhrStatus"));
    OriginalVersionResponseData<EhrStatus> originalVersionResponseData = new OriginalVersionResponseData<>(ehrStatusOriginalVersion.get(), contributionDto);
    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.setContentType(resolveContentType(accept));
    return ResponseEntity.ok().headers(respHeaders).body(originalVersionResponseData);
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ContributionService(org.ehrbase.api.service.ContributionService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LocalDateTime(java.time.LocalDateTime) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EhrService(org.ehrbase.api.service.EhrService) VersionedEhrStatusApiSpecification(org.ehrbase.rest.openehr.specification.VersionedEhrStatusApiSpecification) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) RevisionHistoryResponseData(org.ehrbase.response.openehr.RevisionHistoryResponseData) GetMapping(org.springframework.web.bind.annotation.GetMapping) HttpHeaders(org.springframework.http.HttpHeaders) Timestamp(java.sql.Timestamp) VersionedObjectResponseData(org.ehrbase.response.openehr.VersionedObjectResponseData) MediaType(org.springframework.http.MediaType) UUID(java.util.UUID) RestController(org.springframework.web.bind.annotation.RestController) BaseController(org.ehrbase.rest.BaseController) Objects(java.util.Objects) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) Optional(java.util.Optional) RevisionHistory(com.nedap.archie.rm.generic.RevisionHistory) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData) HttpHeaders(org.springframework.http.HttpHeaders) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) InternalServerException(org.ehrbase.api.exception.InternalServerException) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData) 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 5 with OriginalVersion

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

the class OpenehrVersionedEhrStatusController method retrieveVersionOfEhrStatusByTime.

@GetMapping(path = "/version")
// checkAbacPre /-Post attributes (type, subject, payload, content type)
@PreAuthorize("checkAbacPre(@openehrVersionedEhrStatusController.EHR_STATUS, " + "@ehrService.getSubjectExtRef(#ehrIdString), null, null)")
@Override
public ResponseEntity<OriginalVersionResponseData<EhrStatus>> retrieveVersionOfEhrStatusByTime(@RequestHeader(value = HttpHeaders.ACCEPT, required = false) String accept, @PathVariable(value = "ehr_id") String ehrIdString, @RequestParam(value = "version_at_time", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime versionAtTime) {
    UUID ehrId = getEhrUuid(ehrIdString);
    // check if EHR is valid
    if (!ehrService.hasEhr(ehrId)) {
        throw new ObjectNotFoundException("ehr", "No EHR with this ID can be found");
    }
    UUID versionedObjectId = ehrService.getEhrStatusVersionedObjectUidByEhr(ehrId);
    int version;
    if (versionAtTime != null) {
        version = ehrService.getEhrStatusVersionByTimestamp(ehrId, Timestamp.valueOf(versionAtTime));
    } else {
        version = Integer.parseInt(ehrService.getLatestVersionUidOfStatus(ehrId).split("::")[2]);
    }
    Optional<OriginalVersion<EhrStatus>> ehrStatusOriginalVersion = ehrService.getEhrStatusAtVersion(ehrId, versionedObjectId, version);
    UUID contributionId = ehrStatusOriginalVersion.map(i -> UUID.fromString(i.getContribution().getId().getValue())).orElseThrow(() -> new InvalidApiParameterException("Couldn't retrieve EhrStatus with given parameters"));
    Optional<ContributionDto> optionalContributionDto = contributionService.getContribution(ehrId, contributionId);
    // shouldn't happen
    ContributionDto contributionDto = optionalContributionDto.orElseThrow(() -> new InternalServerException("Couldn't fetch contribution for existing EhrStatus"));
    OriginalVersionResponseData<EhrStatus> originalVersionResponseData = new OriginalVersionResponseData<>(ehrStatusOriginalVersion.get(), contributionDto);
    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.setContentType(resolveContentType(accept));
    return ResponseEntity.ok().headers(respHeaders).body(originalVersionResponseData);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) ContributionService(org.ehrbase.api.service.ContributionService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LocalDateTime(java.time.LocalDateTime) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EhrService(org.ehrbase.api.service.EhrService) VersionedEhrStatusApiSpecification(org.ehrbase.rest.openehr.specification.VersionedEhrStatusApiSpecification) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) RevisionHistoryResponseData(org.ehrbase.response.openehr.RevisionHistoryResponseData) GetMapping(org.springframework.web.bind.annotation.GetMapping) HttpHeaders(org.springframework.http.HttpHeaders) Timestamp(java.sql.Timestamp) VersionedObjectResponseData(org.ehrbase.response.openehr.VersionedObjectResponseData) MediaType(org.springframework.http.MediaType) UUID(java.util.UUID) RestController(org.springframework.web.bind.annotation.RestController) BaseController(org.ehrbase.rest.BaseController) Objects(java.util.Objects) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) Optional(java.util.Optional) RevisionHistory(com.nedap.archie.rm.generic.RevisionHistory) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) HttpHeaders(org.springframework.http.HttpHeaders) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) InternalServerException(org.ehrbase.api.exception.InternalServerException) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) OriginalVersionResponseData(org.ehrbase.response.openehr.OriginalVersionResponseData) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) UUID(java.util.UUID) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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