Search in sources :

Example 6 with EhrStatus

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());
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) EhrService(org.ehrbase.api.service.EhrService) Supplier(java.util.function.Supplier) RequestBody(org.springframework.web.bind.annotation.RequestBody) PutMapping(org.springframework.web.bind.annotation.PutMapping) GetMapping(org.springframework.web.bind.annotation.GetMapping) URI(java.net.URI) PreconditionFailedException(org.ehrbase.api.exception.PreconditionFailedException) HttpHeaders(org.springframework.http.HttpHeaders) Timestamp(java.sql.Timestamp) MediaType(org.springframework.http.MediaType) UUID(java.util.UUID) RestController(org.springframework.web.bind.annotation.RestController) BaseController(org.ehrbase.rest.BaseController) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) InternalServerException(org.ehrbase.api.exception.InternalServerException) EhrStatusResponseData(org.ehrbase.response.openehr.EhrStatusResponseData) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) InternalResponse(org.ehrbase.rest.util.InternalResponse) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) EhrStatusApiSpecification(org.ehrbase.rest.openehr.specification.EhrStatusApiSpecification) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) PreconditionFailedException(org.ehrbase.api.exception.PreconditionFailedException) InternalResponse(org.ehrbase.rest.util.InternalResponse) UUID(java.util.UUID) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with EhrStatus

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) VersionedObjectResponseData(org.ehrbase.response.openehr.VersionedObjectResponseData) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) UUID(java.util.UUID) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with EhrStatus

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);
}
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 9 with EhrStatus

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

Example 10 with EhrStatus

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;
}
Also used : EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Aggregations

EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)23 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)12 UUID (java.util.UUID)11 PartySelf (com.nedap.archie.rm.generic.PartySelf)9 DvText (com.nedap.archie.rm.datavalues.DvText)8 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)7 VersionedEhrStatus (com.nedap.archie.rm.ehr.VersionedEhrStatus)6 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)5 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)5 HttpHeaders (org.springframework.http.HttpHeaders)5 OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)4 URI (java.net.URI)4 InternalServerException (org.ehrbase.api.exception.InternalServerException)4 Test (org.junit.Test)4 MediaType (org.springframework.http.MediaType)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Timestamp (java.sql.Timestamp)3 Optional (java.util.Optional)3 EhrService (org.ehrbase.api.service.EhrService)3 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)3