From d8704c1fcf7ee87a7617ed20af3242a4d6f529f1 Mon Sep 17 00:00:00 2001 From: Mirna Gama Date: Wed, 10 Jan 2024 16:53:15 -0300 Subject: [PATCH] [R8] Deactivate patient method in service class --- .../services/PatientServiceImpl.java | 22 +++++++++++++++++++ .../domain/services/PatientService.java | 8 +++++++ 2 files changed, 30 insertions(+) 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); }