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