@Test public void deleteInvalidPatientReturns404() throws QueryException { this.exception.expect(HttpStatus.of(Response.Status.NOT_FOUND)); this.component.deletePatient(ID_LABEL, ID_VALUE); }
@Override public Response deletePatient(String label, String id) { this.logger.debug("Deleting patient record with label [{}] and corresponding external ID [{}] via REST", label, id); Patient patient; List<String> patients = getPatientInternalIdentifiersByLabelAndEid(label, id); if (patients.size() == 1) { patient = this.repository.get(patients.get(0)); } else { return returnIfEmptyOrMultipleExistResponse(patients, label, id); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.logger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); throw new WebApplicationException(Response.Status.FORBIDDEN); } try { this.repository.delete(patient); } catch (Exception ex) { this.logger.warn("Failed to delete patient record with label [{}] and corresponding external id [{}]: {}", label, id, ex.getMessage(), ex); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } this.logger.debug("Deleted patient record with label [{}] corresponding external id [{}]", label, id); return Response.noContent().build(); }
DefaultPatientByLabeledExternalIdentifierResourceImpl extends XWikiResource implements
    PatientByLabeledExternalIdentifierResource { @Override public Response deletePatient(String label, String id) { this.logger.debug("Deleting patient record with label [{}] and corresponding external ID [{}] via REST", label, id); Patient patient; List<String> patients = getPatientInternalIdentifiersByLabelAndEid(label, id); if (patients.size() == 1) { patient = this.repository.get(patients.get(0)); } else { return returnIfEmptyOrMultipleExistResponse(patients, label, id); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.logger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); throw new WebApplicationException(Response.Status.FORBIDDEN); } try { this.repository.delete(patient); } catch (Exception ex) { this.logger.warn("Failed to delete patient record with label [{}] and corresponding external id [{}]: {}", label, id, ex.getMessage(), ex); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } this.logger.debug("Deleted patient record with label [{}] corresponding external id [{}]", label, id); return Response.noContent().build(); } }
DefaultPatientByLabeledExternalIdentifierResourceImpl extends XWikiResource implements
    PatientByLabeledExternalIdentifierResource { @Override public Response deletePatient(String label, String id) { this.logger.debug("Deleting patient record with label [{}] and corresponding external ID [{}] via REST", label, id); Patient patient; List<String> patients = getPatientInternalIdentifiersByLabelAndEid(label, id); if (patients.size() == 1) { patient = this.repository.get(patients.get(0)); } else { return returnIfEmptyOrMultipleExistResponse(patients, label, id); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.logger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); throw new WebApplicationException(Response.Status.FORBIDDEN); } try { this.repository.delete(patient); } catch (Exception ex) { this.logger.warn("Failed to delete patient record with label [{}] and corresponding external id [{}]: {}", label, id, ex.getMessage(), ex); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } this.logger.debug("Deleted patient record with label [{}] corresponding external id [{}]", label, id); return Response.noContent().build(); }  }
DefaultPatientByLabeledExternalIdentifierResourceImpl extends XWikiResource implements
    PatientByLabeledExternalIdentifierResource { @Override public Response deletePatient(String label, String id) { this.logger.debug("Deleting patient record with label [{}] and corresponding external ID [{}] via REST", label, id); Patient patient; List<String> patients = getPatientInternalIdentifiersByLabelAndEid(label, id); if (patients.size() == 1) { patient = this.repository.get(patients.get(0)); } else { return returnIfEmptyOrMultipleExistResponse(patients, label, id); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.logger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); throw new WebApplicationException(Response.Status.FORBIDDEN); } try { this.repository.delete(patient); } catch (Exception ex) { this.logger.warn("Failed to delete patient record with label [{}] and corresponding external id [{}]: {}", label, id, ex.getMessage(), ex); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } this.logger.debug("Deleted patient record with label [{}] corresponding external id [{}]", label, id); return Response.noContent().build(); }  @Override Response getPatient(String label, String id); @Override Response updatePatient(final String json, final String label, final String id,
        final String policy, final boolean create); @Override Response patchPatient(String json, String label, String id, boolean create); @Override Response deletePatient(String label, String id); }
DefaultPatientByLabeledExternalIdentifierResourceImpl extends XWikiResource implements
    PatientByLabeledExternalIdentifierResource { @Override public Response deletePatient(String label, String id) { this.logger.debug("Deleting patient record with label [{}] and corresponding external ID [{}] via REST", label, id); Patient patient; List<String> patients = getPatientInternalIdentifiersByLabelAndEid(label, id); if (patients.size() == 1) { patient = this.repository.get(patients.get(0)); } else { return returnIfEmptyOrMultipleExistResponse(patients, label, id); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.DELETE, patient.getDocumentReference())) { this.logger.debug("Delete access denied to user [{}] on patient record [{}]", currentUser, patient.getId()); throw new WebApplicationException(Response.Status.FORBIDDEN); } try { this.repository.delete(patient); } catch (Exception ex) { this.logger.warn("Failed to delete patient record with label [{}] and corresponding external id [{}]: {}", label, id, ex.getMessage(), ex); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } this.logger.debug("Deleted patient record with label [{}] corresponding external id [{}]", label, id); return Response.noContent().build(); }  @Override Response getPatient(String label, String id); @Override Response updatePatient(final String json, final String label, final String id,
        final String policy, final boolean create); @Override Response patchPatient(String json, String label, String id, boolean create); @Override Response deletePatient(String label, String id);  }