use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class OpenehrEhrController method buildEhrResponseData.
/**
* 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 Current object's reference
* @param accept Requested content format
* @param headerList Requested headers that need to be set
* @param <T> Either EhrResponseData itself or more specific sub-class EhrResponseDataRepresentation
* @return
*/
private <T extends EhrResponseData> Optional<InternalResponse<T>> buildEhrResponseData(Supplier<T> factory, UUID ehrId, /*Action create,*/
String accept, List<String> headerList) {
// check for valid format header to produce content accordingly
MediaType contentType = resolveContentType(accept);
// Optional<EhrStatusDto> ehrStatus = ehrService.getEhrStatusEhrScape(ehrId, CompositionFormat.FLAT); // older, keep until rework of formatting
Optional<EhrStatus> ehrStatus = ehrService.getEhrStatus(ehrId);
if (ehrStatus.isEmpty()) {
return Optional.empty();
}
// create either null or maximum response data class
T minimalOrRepresentation = factory.get();
if (minimalOrRepresentation != null) {
// populate maximum response data
EhrResponseData objByReference = minimalOrRepresentation;
objByReference.setEhrId(new HierObjectId(ehrId.toString()));
objByReference.setEhrStatus(ehrStatus.get());
objByReference.setSystemId(new HierObjectId(ehrService.getSystemUuid().toString()));
DvDateTime timeCreated = ehrService.getCreationTime(ehrId);
objByReference.setTimeCreated(timeCreated.getValue().toString());
// objByReference.setCompositions(null); // TODO get actual data from service layer
// objByReference.setContributions(null); // TODO get actual data from service layer
}
// 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:
if (// if response is going to have a body
minimalOrRepresentation != null)
respHeaders.setContentType(contentType);
break;
case LOCATION:
try {
URI url = new URI(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId);
respHeaders.setLocation(url);
} catch (Exception e) {
throw new InternalServerException(e.getMessage());
}
break;
case ETAG:
respHeaders.setETag("\"" + ehrId + "\"");
break;
case LAST_MODIFIED:
// TODO should be VERSION.commit_audit.time_committed.value which is not implemented yet - mock for now
respHeaders.setLastModified(123124442);
break;
default:
}
}
return Optional.of(new InternalResponse<>(minimalOrRepresentation, respHeaders));
}
use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class EhrServiceImp method getVersionedEhrStatus.
@Override
public VersionedEhrStatus getVersionedEhrStatus(UUID ehrUid) {
// FIXME VERSIONED_OBJECT_POC: Pre_has_ehr: has_ehr (an_ehr_id)
// FIXME VERSIONED_OBJECT_POC: Pre_has_ehr_status_version: has_ehr_status_version (an_ehr_id, a_version_uid)
Optional<EhrStatus> ehrStatus = getEhrStatus(ehrUid);
VersionedEhrStatus versionedEhrStatus = new VersionedEhrStatus();
if (ehrStatus.isPresent()) {
versionedEhrStatus.setUid(new HierObjectId(ehrStatus.get().getUid().getRoot().getValue()));
versionedEhrStatus.setOwnerId(new ObjectRef<>(new HierObjectId(ehrUid.toString()), "local", "EHR"));
I_EhrAccess ehrAccess = I_EhrAccess.retrieveInstance(getDataAccess(), ehrUid);
versionedEhrStatus.setTimeCreated(new DvDateTime(OffsetDateTime.of(ehrAccess.getStatusAccess().getInitialTimeOfVersionedEhrStatus().toLocalDateTime(), OffsetDateTime.now().getOffset())));
}
return versionedEhrStatus;
}
use of com.nedap.archie.rm.ehr.EhrStatus 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