From b6e4116d0fc5f45e2e0817fc8cd7e41b279b3e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garcia=20Nu=C3=B1ez?= Date: Sun, 29 Dec 2019 21:33:57 +0100 Subject: [PATCH] =?UTF-8?q?Mejoras=20en=20la=20gesti=C3=B3n=20de=20pruebas?= =?UTF-8?q?=20m=C3=A9dicas=20(filtros=20de=20b=C3=BAsqueda)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docroot/medicaltest/MedicalTests.xhtml | 188 +++++++++------ .../medicalTest/MedicalTestFacadeBean.java | 153 ++++++------ .../medicalTest/MedicalTestFacadeRemote.java | 27 +-- .../MyHealth/src/jpa/MedicalTestJPA.java | 3 +- .../medicalTest/MedicalTestMBean.java | 228 ++++++++++-------- 5 files changed, 341 insertions(+), 258 deletions(-) diff --git a/1.sources/MyHealth/docroot/medicaltest/MedicalTests.xhtml b/1.sources/MyHealth/docroot/medicaltest/MedicalTests.xhtml index 7218dc2..7c8c48e 100644 --- a/1.sources/MyHealth/docroot/medicaltest/MedicalTests.xhtml +++ b/1.sources/MyHealth/docroot/medicaltest/MedicalTests.xhtml @@ -1,10 +1,7 @@ - @@ -15,33 +12,41 @@ - + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + +
- +
@@ -49,76 +54,109 @@
- + + + + + +
-
Fecha:
-
- +
Fecha:
+
+
-
Hora:
-
- +
Hora:
+
+
-
Observaciones:
-
- +
Observaciones:
+
+
-
Tipo de prueba:
-
- +
Tipo de prueba:
+
+
-
Imagen de alta resolución:
-
-
- - -
-
- -
-
- -
+
+ +
+
Imagen de alta resolución:
+
+ +
+
+ +
+
+ + + +
+
+ +
+
+
- + +
-
Fecha:
-
- +
Paciente:
+
+ + + + + + + + + + + +
-
Hora:
-
- + +
Fecha:
+
+
-
Observaciones:
-
- + +
Hora:
+
+ + +
-
Tipo de prueba:
-
- - + +
Observaciones:
+
+ +
+ +
Tipo de prueba:
+
+ +
-
-
- +
+
+
-
- +
diff --git a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java index c3981df..d4664fe 100644 --- a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java +++ b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java @@ -17,6 +17,7 @@ import TO.QuestionTO; import TO.SpecialistDoctorTO; import common.MedicalTestType; import common.QuestionStatus; +import common.Utils; import ejb.common.CommonFacadeLocal; import jpa.MedicalTestJPA; import jpa.PatientJPA; @@ -24,12 +25,10 @@ import jpa.QuestionJPA; import jpa.SpecialistDoctorJPA; /** - * EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los - * métodos de la capa de negocio que implementan la logica de negocio y la - * interacción con la capa de persistencia. + * EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los métodos de la capa de negocio que implementan la logica de negocio y la interacción con la capa de + * persistencia. * - * Tanto los pacientes como los médicos deben acceder a la vista de pruebas - * médicas. + * Tanto los pacientes como los médicos deben acceder a la vista de pruebas médicas. * * @author rorden * @@ -96,9 +95,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { // TypedQuery query = entman.createQuery("SELECT q from QuestionJPA // q where q.status=:status and q.familyDoctor.id=:docId order by q.title", // QuestionJPA.class); - TypedQuery query = entman.createQuery( - "SELECT q from QuestionJPA q where q.familyDoctor.id=:docId order by q.status desc, q.title asc", - QuestionJPA.class); + TypedQuery query = entman.createQuery("SELECT q from QuestionJPA q where q.familyDoctor.id=:docId order by q.status desc, q.title asc", QuestionJPA.class); // query.setParameter("status", QuestionStatus.PENDING); query.setParameter("docId", familyDoctorId); @@ -117,9 +114,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { // TypedQuery query = entman.createQuery("SELECT q from QuestionJPA // q where q.status=:status and q.familyDoctor.id=:docId order by q.title", // QuestionJPA.class); - TypedQuery query = entman.createQuery( - "SELECT q from QuestionJPA q where q.patient.id=:patientId order by q.status desc, q.title asc", - QuestionJPA.class); + TypedQuery query = entman.createQuery("SELECT q from QuestionJPA q where q.patient.id=:patientId order by q.status desc, q.title asc", QuestionJPA.class); // query.setParameter("status", QuestionStatus.PENDING); query.setParameter("patientId", userId); @@ -140,8 +135,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { public QuestionTO getQuestion(int idQuestion) { QuestionTO resp = new QuestionTO(); - TypedQuery query = entman.createQuery("SELECT q from QuestionJPA q where q.id=:idquestion", - QuestionJPA.class); + TypedQuery query = entman.createQuery("SELECT q from QuestionJPA q where q.id=:idquestion", QuestionJPA.class); query.setParameter("idquestion", idQuestion); @@ -156,29 +150,23 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { /** * Añadir pruebas médicas a una cita * - * Dado que será añadida por el médico especialista en sesión no hace falta más - * información. + * Dado que será añadida por el médico especialista en sesión no hace falta más información. * * @param patientiID * @param date * @param time - * @param testType Pudiera llegar a ser: Análisis de sangre, resonancias - * magnéticas y TAC + * @param testType Pudiera llegar a ser: Análisis de sangre, resonancias magnéticas y TAC * @param observations */ - public String addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, - MedicalTestType testType, String observations) { - try { - SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID); - PatientJPA pat = entman.find(PatientJPA.class, patientID); + public MedicalTestTO addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations) throws Exception { + SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID); + PatientJPA pat = entman.find(PatientJPA.class, patientID); - MedicalTestJPA mt = new MedicalTestJPA(0, date, time, observations, null, testType, pat, specDoctor); + MedicalTestJPA mt = new MedicalTestJPA(date, time, observations, null, testType, pat, specDoctor); - entman.persist(mt); - return "ok"; - } catch (Exception ex) { - return ex.getMessage(); - } + entman.persist(mt); + + return this.commonServices.getPOJOforMedicalTestJPA(mt, 1); } /** @@ -197,8 +185,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { } private MedicalTestJPA getMedicalTestJPA(int idMedicalTest) { - TypedQuery query = entman - .createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class); + TypedQuery query = entman.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class); query.setParameter("idMedicalTest", idMedicalTest); return query.getSingleResult(); } @@ -239,8 +226,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { } public Long getSpecialistDoctorByMedicalSpecialityCount(int specialityId) { - TypedQuery query = entman.createQuery( - "SELECT count(1) from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId", Long.class); + TypedQuery query = entman.createQuery("SELECT count(1) from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId", Long.class); query.setParameter("specId", specialityId); return query.getSingleResult(); @@ -251,13 +237,11 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { * * @param speciality */ - public List findSpecialistDoctorByMedicalSpeciality(int specialityId, int pageNumber, - int pageSize) { + public List findSpecialistDoctorByMedicalSpeciality(int specialityId, int pageNumber, int pageSize) { List pendingQuestions = new ArrayList(); TypedQuery query = entman.createQuery( - "SELECT q from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId order by q.medicalSpecialty.name asc, q.surname asc", - SpecialistDoctorJPA.class); + "SELECT q from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId order by q.medicalSpecialty.name asc, q.surname asc", SpecialistDoctorJPA.class); query.setParameter("specId", specialityId); if (pageSize > 0) { @@ -278,9 +262,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { public List loadMedicalTestForPatient(int patientID) { List medicalTests = new ArrayList(); - TypedQuery query = entman.createQuery( - "SELECT q from MedicalTestJPA q where q.patient.id=:patientId order by q.id desc", - MedicalTestJPA.class); + TypedQuery query = entman.createQuery("SELECT q from MedicalTestJPA q where q.patient.id=:patientId order by q.id desc", MedicalTestJPA.class); query.setParameter("patientId", patientID); @@ -304,18 +286,17 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { } @Override - public List loadMedicalTestForFamilyDoctor(int familyDoctorID, int patientID) { + public List loadMedicalTestForFamilyDoctor(int familyDoctorID, Integer patientID) { List medicalTests = new ArrayList(); String extraQuery = ""; - if (patientID > 0) { + if (patientID != null) { extraQuery = " and q.patient.id=:patientID"; } TypedQuery query = entman - .createQuery("SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID " - + extraQuery + " order by q.id desc", MedicalTestJPA.class); - if (patientID > 0) { + .createQuery("SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID " + extraQuery + " order by q.id desc", MedicalTestJPA.class); + if (patientID != null) { query.setParameter("patientID", patientID); } query.setParameter("familyDoctorID", familyDoctorID); @@ -330,19 +311,18 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { } @Override - public List loadMedicalTestForSpecialistDoctor(int specialistDoctorID, int patientID) { + public List loadMedicalTestForSpecialistDoctor(int specialistDoctorID, Integer patientID) { List medicalTests = new ArrayList(); String extraQuery = ""; - if (patientID > 0) { + if (patientID != null) { extraQuery = " and q.patient.id=:patientID"; } TypedQuery query = entman - .createQuery("SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID " - + extraQuery + " order by q.id desc", MedicalTestJPA.class); + .createQuery("SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID " + extraQuery + " order by q.id desc", MedicalTestJPA.class); - if (patientID > 0) { + if (patientID != null) { query.setParameter("patientID", patientID); } query.setParameter("specialistDoctorID", specialistDoctorID); @@ -356,42 +336,73 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { return medicalTests; } - @Override - public List loadPatientsForSpecialistDoctor(int specialistDoctorID) { - List medicalTests = new ArrayList(); + public List loadPatientsForSpecialistDoctor(int specialistDoctorID, String searchTerm, int pageNumber, int pageSize) { + String strQuery = "SELECT distinct q.patient from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID %s order by q.patient.name, q.patient.surname"; + String strFilter = ""; + if (searchTerm == null) + searchTerm = ""; + else + searchTerm = Utils.normalizeTerm(searchTerm); - TypedQuery query = entman.createQuery( - "SELECT distinct q.patient from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID", - PatientJPA.class); + if (searchTerm.length() > 0) { + strFilter = "and lower(q.patient.name) LIKE :searchTerm OR lower(q.patient.surname) LIKE :searchTerm"; + } + + TypedQuery query = entman.createQuery(String.format(strQuery, strFilter), PatientJPA.class); + + if (searchTerm.length() > 0) + query.setParameter("searchTerm", "%" + searchTerm + "%"); query.setParameter("specialistDoctorID", specialistDoctorID); - List allJPA = query.getResultList(); - - for (PatientJPA item : allJPA) { - medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1)); + if (pageSize > 0) { + query.setFirstResult(pageNumber * pageSize); + query.setMaxResults(pageSize); } - return medicalTests; + List allJPA = query.getResultList(); + List patsTO = new ArrayList(); + + for (PatientJPA item : allJPA) { + patsTO.add(commonServices.getPOJOforPatientJPA(item, 1)); + } + + return patsTO; } - @Override - public List loadPatientsForFamilyDoctor(int familyDoctorID) { - List medicalTests = new ArrayList(); + public List loadPatientsForFamilyDoctor(int familyDoctorID, String searchTerm, int pageNumber, int pageSize) { + String strQuery = "SELECT distinct q.patient from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID %s order by q.patient.name, q.patient.surname"; - TypedQuery query = entman.createQuery( - "SELECT distinct q.patient from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID", - PatientJPA.class); + String strFilter = ""; + if (searchTerm == null) + searchTerm = ""; + else + searchTerm = Utils.normalizeTerm(searchTerm); + + if (searchTerm.length() > 0) { + strFilter = "and lower(q.patient.name) LIKE :searchTerm OR lower(q.patient.surname) LIKE :searchTerm"; + } + + TypedQuery query = entman.createQuery(String.format(strQuery, strFilter), PatientJPA.class); + + if (searchTerm.length() > 0) + query.setParameter("searchTerm", "%" + searchTerm + "%"); query.setParameter("familyDoctorID", familyDoctorID); - List allJPA = query.getResultList(); - - for (PatientJPA item : allJPA) { - medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1)); + if (pageSize > 0) { + query.setFirstResult(pageNumber * pageSize); + query.setMaxResults(pageSize); } - return medicalTests; + List allJPA = query.getResultList(); + List patsTO = new ArrayList(); + + for (PatientJPA item : allJPA) { + patsTO.add(commonServices.getPOJOforPatientJPA(item, 1)); + } + + return patsTO; } } \ No newline at end of file diff --git a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java index 60b3063..a8b3202 100644 --- a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java +++ b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java @@ -66,22 +66,21 @@ public interface MedicalTestFacadeRemote { // TEST public List loadMedicalTestForPatient(int patientID); - + public List loadMedicalTestForFamilyDoctor(int familyDoctorID); - + public List loadMedicalTestForSpecialistDoctor(int specialistDoctorID); - - public List loadMedicalTestForFamilyDoctor(int familyDoctorID, int patientID); - - public List loadMedicalTestForSpecialistDoctor(int specialistDoctorID, int patientID); - - public List loadPatientsForSpecialistDoctor(int specialistDoctorID); - - public List loadPatientsForFamilyDoctor(int familyDoctorID); - + + public List loadMedicalTestForFamilyDoctor(int familyDoctorID, Integer patientID); + + public List loadMedicalTestForSpecialistDoctor(int specialistDoctorID, Integer patientID); + + public List loadPatientsForSpecialistDoctor(int specialistDoctorID, String searchTerm, int pageNumber, int pageSize); + + public List loadPatientsForFamilyDoctor(int familyDoctorID, String searchTerm, int pageNumber, int pageSize); + /** - * Añadir una prueba médica a un paciente - * Dado que será añadida por el médico especialista en sesión no hace falta más información. + * Añadir una prueba médica a un paciente Dado que será añadida por el médico especialista en sesión no hace falta más información. * * @param idMedicalTest * @param date @@ -89,7 +88,7 @@ public interface MedicalTestFacadeRemote { * @param testType Pudiera llegar a ser: Análisis de sangre, resonancias magnéticas y TAC * @param observations */ - public String addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations); + public MedicalTestTO addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations) throws Exception; /** * Recuperar una prueba médica por ID diff --git a/1.sources/MyHealth/src/jpa/MedicalTestJPA.java b/1.sources/MyHealth/src/jpa/MedicalTestJPA.java index 616205b..fa06fa0 100644 --- a/1.sources/MyHealth/src/jpa/MedicalTestJPA.java +++ b/1.sources/MyHealth/src/jpa/MedicalTestJPA.java @@ -57,8 +57,7 @@ public class MedicalTestJPA implements Serializable { super(); } - public MedicalTestJPA(int id, Date date, LocalTime time, String observations, String highresimage, MedicalTestType type, PatientJPA patient, SpecialistDoctorJPA specialistDoctor) { - this.id = id; + public MedicalTestJPA(Date date, LocalTime time, String observations, String highresimage, MedicalTestType type, PatientJPA patient, SpecialistDoctorJPA specialistDoctor) { this.date = date; this.time = time; this.observations = observations; diff --git a/1.sources/MyHealth/src/managedbean/medicalTest/MedicalTestMBean.java b/1.sources/MyHealth/src/managedbean/medicalTest/MedicalTestMBean.java index 1ed7e98..71e7503 100644 --- a/1.sources/MyHealth/src/managedbean/medicalTest/MedicalTestMBean.java +++ b/1.sources/MyHealth/src/managedbean/medicalTest/MedicalTestMBean.java @@ -11,12 +11,12 @@ import javax.faces.event.AjaxBehaviorEvent; import javax.faces.view.ViewScoped; import javax.inject.Named; -import org.primefaces.event.FileUploadEvent; import org.primefaces.event.SelectEvent; import org.primefaces.model.UploadedFile; import TO.MedicalTestTO; import TO.PatientTO; +import common.Constants; import common.MedicalTestType; import common.UserType; import managedbean.common.ManagedBeanBase; @@ -33,8 +33,14 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { private List medicalTests; private MedicalTestTO selected; private PatientTO patSelected; + private PatientTO patientFilterSelected; private boolean addNewMode = false; private UploadedFile imageUpload; + private List patientList; + private List patientWithTestList; + private String lastUIQuery; + private String lastUIQueryPatFilter; + private List medicalTestTypes; public MedicalTestMBean() { } @@ -43,34 +49,48 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { public void init() { this.userType = SessionUtils.getUserType(); this.userID = Integer.valueOf(SessionUtils.getUserId()); + this.medicalTestTypes = new ArrayList(); + this.medicalTestTypes.add(MedicalTestType.BLOOD_TEST); + this.medicalTestTypes.add(MedicalTestType.CT_SCAN); + this.medicalTestTypes.add(MedicalTestType.MAGNETIC_RESONANCE_IMAGING); this.selected = null; this.patSelected = null; + this.lastUIQuery = ""; + this.lastUIQueryPatFilter = ""; + switch (userType) { + case ADMINISTRATOR: + case PATIENT: + this.patientList = null; + this.patientWithTestList = null; + break; + case SPECIALIST_DOCTOR: + this.patientList = this.getRemoteManagerCommon().listPatientsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID, null, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + break; + case FAMILY_DOCTOR: + this.patientList = null; + this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID, null, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + } + this.loadMedicalTests(); - this.getPatients(); - } - - public void addMedicalTest() { - getRemoteManagerMedicalTest().addMedicalTest(this.selected.getPatient().getId(), userID, - this.selected.getDate(), this.selected.getTime(), this.selected.getType(), - this.selected.getObservations()); } public void addImage() { - if(this.imageUpload != null ) { - String content = "data:"+imageUpload.getContentType()+";base64," + Base64.getEncoder().encodeToString(imageUpload.getContents()); - System.out.println("FILE Content base64: "); - System.out.println(content); - this.selected.setHighresimage(content); + if (this.imageUpload != null) { + String content = "data:" + imageUpload.getContentType() + ";base64," + Base64.getEncoder().encodeToString(imageUpload.getContents()); + System.out.println("FILE Content base64: "); + System.out.println(content); + this.selected.setHighresimage(content); getRemoteManagerMedicalTest().addImage(this.selected.getId(), content); this.loadMedicalTests(); this.imageUpload = null; - }else { - System.out.println("IMAGEN SUBIDA ES NULA"); + } else { + System.out.println("IMAGEN SUBIDA ES NULA"); } } - + public UploadedFile getImageUpload() { return imageUpload; } @@ -102,35 +122,68 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { } public void loadMedicalTests() { - if (userType == UserType.PATIENT) { + Integer patId = null; + if (this.patientFilterSelected != null) + patId = this.patientFilterSelected.getId(); + + switch (userType) { + case PATIENT: // Cargar las pruebas para el paciente en sesión this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForPatient(userID); - } else if (userType == UserType.SPECIALIST_DOCTOR) { + break; + case SPECIALIST_DOCTOR: // Cargar las pruebas que el doctor especialista ha creado - this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID, - this.patIdSelected); - } else if (userType == UserType.FAMILY_DOCTOR) { + this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID, patId); + break; + case FAMILY_DOCTOR: // Cargar las pruebas para los pacientes del doctor de familia en sesión - this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID, - this.patIdSelected); - } else { - // Nothing todo - this.medicalTests = new ArrayList(); - } + this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID, patId); + break; + case ADMINISTRATOR: + this.medicalTests = null; + this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Operación no válida para el tipo de usuario actual."); + break; + } } - public List getPatients() { - if (userType == UserType.SPECIALIST_DOCTOR) { - // Cargar los pacientes a los que ha añadido pruebas médicas el médico - // especialista - return getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID); - } else if (userType == UserType.FAMILY_DOCTOR) { - // Cargar los pacientes del médico de familia que tiene pruebas médicas hechas - return getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID); - } else { - // Nothing todo - return new ArrayList(); + public List completePatient(String query) { + if (query != null && query.equals(this.lastUIQuery) == false) { + this.lastUIQuery = query; + // Recuperamos las xxx primeras coincidencias + this.patientList = this.getRemoteManagerCommon().listPatientsFiltered(query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); } + return this.patientList; + } + + public List completePatientFilter(String query) { + if (query != null && query.equals(this.lastUIQueryPatFilter) == false) { + this.lastUIQueryPatFilter = query; + + switch (userType) { + case SPECIALIST_DOCTOR: + // Cargar los pacientes a los que ha añadido pruebas médicas el médico especialista + this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID, query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + break; + case FAMILY_DOCTOR: + // Cargar los pacientes del médico de familia que tiene pruebas médicas hechas + this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID, query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + break; + case ADMINISTRATOR: + case PATIENT: + this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Operación no válida para el tipo de usuario actual."); + this.patientWithTestList = null; + break; + } + } + return this.patientWithTestList; + } + + public List getPatientList() { + return patientList; + } + + public List getPatientWithTestList() { + return patientWithTestList; } public List getMedicalTests() { @@ -141,18 +194,6 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { // Nothing to do } - /*************************************************** METODOS PARA LA VISTA */ - private int patIdSelected = -1; - - public void setPatIdSelected(Integer value) { - this.patIdSelected = value; - this.addNewMode = false; - } - - public Integer getPatIdSelected() { - return this.patIdSelected; - } - public boolean isSpecialistDoctor() { return this.userType == UserType.SPECIALIST_DOCTOR; } @@ -161,10 +202,20 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { return !(userType == UserType.PATIENT); } - public void onSelectPatient(AjaxBehaviorEvent event) { + public void clearFilteredPatient() { + this.selected = null; + this.patientFilterSelected = null; + this.loadMedicalTests(); + } + + public void onChangePatient(AjaxBehaviorEvent event) { + this.selected = null; + this.loadMedicalTests(); + } + + public void onSelectPatient(SelectEvent event) { this.selected = null; this.loadMedicalTests(); - } public void onSelectMT(SelectEvent event) { @@ -173,16 +224,13 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { } public void addMT() { - if (this.patIdSelected != -1) { - this.selected = new MedicalTestTO(); - this.selected.setId(-1); - this.selected.setObservations(""); - this.selected.setType(MedicalTestType.BLOOD_TEST); - this.addNewMode = true; - } else { - this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Atención!", - "Debe elegir un paciente al que añadir la prueba médica."); - } + // Si hay un paciente filtrado en la busqueda de pruebas, lo seleccionamos para la prueba a añadir. + this.patSelected = this.patientFilterSelected; + this.selected = new MedicalTestTO(); + this.selected.setId(-1); + this.selected.setObservations(""); + this.selected.setType(MedicalTestType.BLOOD_TEST); + this.addNewMode = true; } public boolean isAddNewMode() { @@ -202,44 +250,32 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable { } public List getMedicalTestTypes() { - ArrayList list = new ArrayList(); - list.add(MedicalTestType.BLOOD_TEST); - list.add(MedicalTestType.CT_SCAN); - list.add(MedicalTestType.MAGNETIC_RESONANCE_IMAGING); - return list; - } - - public String getMedicalTestTypeSelected() { - return this.selected.getType().getName(); - } - - public void setMedicalTestTypeSelected(String val) { - System.out.println("********************************"); - System.out.println(val); - System.out.println("********************************"); - MedicalTestType mt; - if (val.equals("BLOOD_TEST")) { - mt = MedicalTestType.BLOOD_TEST; - } else if (val.equals("CT_SCAN")) { - mt = MedicalTestType.CT_SCAN; - } else { - mt = MedicalTestType.MAGNETIC_RESONANCE_IMAGING; - } - this.selected.setType(mt); - System.out.println("********************************"); - System.out.println(this.selected.getType()); - System.out.println("********************************"); + return this.medicalTestTypes; } public void save() { - String res = getRemoteManagerMedicalTest().addMedicalTest(this.patIdSelected, userID, this.selected.getDate(), - this.selected.getTime(), this.selected.getType(), this.selected.getObservations()); - if (res.equals("ok")) { - this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Éxito", "Guardado correctamente"); - } else { - this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", res); + try { + + MedicalTestTO mt = this.getRemoteManagerMedicalTest().addMedicalTest(this.patSelected.getId(), this.userID, this.selected.getDate(), this.selected.getTime(), + this.selected.getType(), this.selected.getObservations()); + + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Éxito", String.format("La prueba médica se ha guardado correctamente, el identificador asignado es: %d", mt.getId())); + + // Volvemos al modo añadir (limpiamos el formulario). + this.addMT(); + + this.loadMedicalTests(); + } catch (Exception ex) { + this.manageException(ex); } - this.loadMedicalTests(); + } + + public PatientTO getPatientFilterSelected() { + return patientFilterSelected; + } + + public void setPatientFilterSelected(PatientTO patientFilterSelected) { + this.patientFilterSelected = patientFilterSelected; } }