Search in sources :

Example 1 with ActionRestResponseData

use of org.ehrbase.rest.ehrscape.responsedata.ActionRestResponseData in project ehrbase by ehrbase.

the class CompositionController method update.

@PutMapping(path = "/{uid}")
public ResponseEntity<ActionRestResponseData> update(@PathVariable("uid") String compositionUid, @RequestParam(value = "format", defaultValue = "XML") CompositionFormat format, @RequestParam(value = "templateId", required = false) String templateId, @RequestBody String content) {
    if ((format == CompositionFormat.FLAT || format == CompositionFormat.STRUCTURED || format == CompositionFormat.ECISFLAT) && StringUtils.isEmpty(templateId)) {
        throw new InvalidApiParameterException(String.format("Template Id needs to specified for format %s", format));
    }
    ObjectVersionId objectVersionId = getObjectVersionId(compositionUid);
    UUID compositionIdentifier = getCompositionIdentifier(compositionUid);
    UUID ehrId = getEhrId(compositionIdentifier);
    var compoObj = compositionService.buildComposition(content, format, templateId);
    // Actual update
    Optional<CompositionDto> dtoOptional = compositionService.update(ehrId, objectVersionId, compoObj);
    var compositionVersionUid = dtoOptional.orElseThrow(() -> new InternalServerException("Failed to create composition")).getComposition().getUid().toString();
    ActionRestResponseData responseData = new ActionRestResponseData();
    responseData.setAction(Action.UPDATE);
    responseData.setMeta(buildMeta(compositionVersionUid));
    return ResponseEntity.ok(responseData);
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) InternalServerException(org.ehrbase.api.exception.InternalServerException) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) ActionRestResponseData(org.ehrbase.rest.ehrscape.responsedata.ActionRestResponseData) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with ActionRestResponseData

use of org.ehrbase.rest.ehrscape.responsedata.ActionRestResponseData in project ehrbase by ehrbase.

the class CompositionController method delete.

@DeleteMapping(path = "/{uid}")
public ResponseEntity<ActionRestResponseData> delete(@PathVariable("uid") String compositionUid) {
    ObjectVersionId objectVersionId = getObjectVersionId(compositionUid);
    UUID compositionIdentifier = getCompositionIdentifier(compositionUid);
    UUID ehrId = getEhrId(compositionIdentifier);
    compositionService.delete(ehrId, objectVersionId);
    ActionRestResponseData responseData = new ActionRestResponseData();
    responseData.setAction(Action.DELETE);
    responseData.setMeta(buildMeta(""));
    return ResponseEntity.ok(responseData);
}
Also used : ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) ActionRestResponseData(org.ehrbase.rest.ehrscape.responsedata.ActionRestResponseData) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Aggregations

ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)2 UUID (java.util.UUID)2 ActionRestResponseData (org.ehrbase.rest.ehrscape.responsedata.ActionRestResponseData)2 InternalServerException (org.ehrbase.api.exception.InternalServerException)1 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)1 CompositionDto (org.ehrbase.response.ehrscape.CompositionDto)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1