diff --git a/src/main/java/com/mirna/hospitalmanagementapi/application/services/PatientServiceImpl.java b/src/main/java/com/mirna/hospitalmanagementapi/application/services/PatientServiceImpl.java index 4e773e3..2e2ec4a 100644 --- a/src/main/java/com/mirna/hospitalmanagementapi/application/services/PatientServiceImpl.java +++ b/src/main/java/com/mirna/hospitalmanagementapi/application/services/PatientServiceImpl.java @@ -140,4 +140,26 @@ public class PatientServiceImpl implements PatientService { return patient; } + /** + * Deactivates an existing patient record by provided id + * + * @param id Long that represents the patient's unique identifier + * + * @return The deactivated patient if successful, or throws an + * EntityNotFoundException if it is non-existent. + * @throws EntityNotFoundException When patient with id provided is non-existent + */ + @Override + public Patient deactivatePatient(Long id) throws EntityNotFoundException { + Patient patient = findPatientById.execute(id); + + if (patient == null) { + throw new EntityNotFoundException(); + } + + patient.setActive(false); + + return savePatient.execute(patient); + } + } diff --git a/src/main/java/com/mirna/hospitalmanagementapi/domain/services/PatientService.java b/src/main/java/com/mirna/hospitalmanagementapi/domain/services/PatientService.java index 13ffa5d..a3eed40 100644 --- a/src/main/java/com/mirna/hospitalmanagementapi/domain/services/PatientService.java +++ b/src/main/java/com/mirna/hospitalmanagementapi/domain/services/PatientService.java @@ -49,4 +49,12 @@ public interface PatientService { * @return The updated patient if successful, or null if there is an error. */ public Patient updatePatient(PatientUpdatedDataDTO patientUpdatedDataDTO); + + /** + * Deactivates an existing patient record by provided id + * @param id Long that represents the patient's unique identifier + * + * @return The deactivated patient if successful, or null if there is an error. + */ + public Patient deactivatePatient(Long id); }