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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations