use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class OpenehrEhrStatusController method updateEhrStatus.
/**
* {@inheritDoc}
*/
@Override
@PutMapping
@PreAuthorize("checkAbacPre(@openehrEhrStatusController.EHR_STATUS, @ehrService.getSubjectExtRef(#ehrIdString))")
public ResponseEntity<EhrStatusResponseData> updateEhrStatus(@PathVariable("ehr_id") UUID ehrId, @RequestHeader(name = IF_MATCH) String versionUid, @RequestHeader(name = PREFER, required = false) String prefer, @RequestHeader(name = HttpHeaders.ACCEPT, required = false) String accept, @RequestHeader(name = HttpHeaders.CONTENT_TYPE, required = false) String contentType, @RequestBody EhrStatus ehrStatus) {
assertEhrExists(ehrId);
// If-Match header check
String latestVersionUid = ehrService.getLatestVersionUidOfStatus(ehrId);
if (!latestVersionUid.equals(versionUid)) {
throw new PreconditionFailedException("Given If-Match header does not match latest existing version");
}
// update EHR_STATUS and check for success
Optional<EhrStatus> updateStatus = ehrService.updateStatus(ehrId, ehrStatus, null);
EhrStatus status = updateStatus.orElseThrow(() -> new InvalidApiParameterException("Could not update EHR_STATUS"));
// update and prepare current version number
String newLatestVersionUid = ehrService.getLatestVersionUidOfStatus(ehrId);
String[] split = latestVersionUid.split("::");
if (latestVersionUid.equals(newLatestVersionUid) || split.length != 3) {
throw new InvalidApiParameterException("Update of EHR_STATUS failed");
}
int version = Integer.parseInt(split[split.length - 1]) + 1;
List<String> headerList = Arrays.asList(CONTENT_TYPE, LOCATION, ETAG, // whatever is required by REST spec
LAST_MODIFIED);
// variable to overload with more specific object if requested
Optional<InternalResponse<EhrStatusResponseData>> respData;
UUID statusUid = UUID.fromString(status.getUid().getValue().split("::")[0]);
respData = buildEhrStatusResponseData(EhrStatusResponseData::new, ehrId, statusUid, version, accept, headerList);
return respData.map(i -> ResponseEntity.ok().headers(i.getHeaders()).body(i.getResponseData())).orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build());
}
use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class OpenehrVersionedEhrStatusController method retrieveVersionedEhrStatusByEhr.
@GetMapping
@Override
public ResponseEntity<VersionedObjectResponseData<EhrStatus>> retrieveVersionedEhrStatusByEhr(@PathVariable(value = "ehr_id") String ehrIdString, @RequestHeader(value = HttpHeaders.ACCEPT, required = false) String accept) {
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");
}
VersionedEhrStatus versionedEhrStatus = ehrService.getVersionedEhrStatus(ehrId);
VersionedObjectResponseData<EhrStatus> response = new VersionedObjectResponseData<>(versionedEhrStatus);
HttpHeaders respHeaders = new HttpHeaders();
respHeaders.setContentType(resolveContentType(accept));
return ResponseEntity.ok().headers(respHeaders).body(response);
}
use of com.nedap.archie.rm.ehr.EhrStatus 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.ehr.EhrStatus 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);
}
use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class EhrController method extractEhrStatus.
private EhrStatus extractEhrStatus(@RequestBody String content) {
EhrStatus ehrStatus = new EhrStatus();
if (StringUtils.isNotBlank(content)) {
Gson json = new GsonBuilder().create();
Map<String, Object> atributes = json.fromJson(content, Map.class);
if (atributes.containsKey(MODIFIABLE)) {
ehrStatus.setModifiable((Boolean) atributes.get(MODIFIABLE));
}
if (atributes.containsKey(QUERYABLE)) {
ehrStatus.setQueryable((Boolean) atributes.get(QUERYABLE));
}
}
return ehrStatus;
}
Aggregations