diff --git a/1.sources/MyHealth/docroot/medicaltest/Questions.xhtml b/1.sources/MyHealth/docroot/medicaltest/Questions.xhtml index f5bbd65..8e709c6 100644 --- a/1.sources/MyHealth/docroot/medicaltest/Questions.xhtml +++ b/1.sources/MyHealth/docroot/medicaltest/Questions.xhtml @@ -1,56 +1,85 @@ - - + +
-
- - - - - - - - - - - - +
+ + + + + + + + + + + + + + + + +
-
-
- - - - - - - #{Questions.selected.title} - - -

Respuesta:

- - -
-
- -
+
+ +
+
+

Título:

+
+
+ +
+
+

Pregunta:

+
+
+ +
+
+
+ +
+
+
+ + + +
+
+

Título:

+
+
+ +
+
+

Pregunta:

+
+
+ +
+
+

Respuesta:

+
+
+ +
+
+
+ +
+
+
+
diff --git a/1.sources/MyHealth/docroot/medicaltest/SearchSpecialist.xhtml b/1.sources/MyHealth/docroot/medicaltest/SearchSpecialist.xhtml new file mode 100644 index 0000000..1ab2a88 --- /dev/null +++ b/1.sources/MyHealth/docroot/medicaltest/SearchSpecialist.xhtml @@ -0,0 +1,55 @@ + + + + + + + + + + +
+ +
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ + #{dd.name} #{dd.surname} <#{dd.email}> + +
+
+
+
+
+
+ diff --git a/1.sources/MyHealth/ecosystem.json b/1.sources/MyHealth/ecosystem.json index e590ff6..ccb1896 100644 --- a/1.sources/MyHealth/ecosystem.json +++ b/1.sources/MyHealth/ecosystem.json @@ -3,7 +3,11 @@ "name": "ANT", "script": "start.sh", "cwd": "./", - "ignore_watch": ["*.ear", "*.jar", "*.war", "./build/*", "./dist/*"], + "ignore_watch": ["*.ear", "*.jar", "*.war", "./build/*", "./dist/*", "ecosystem.json"], "watch": true + },{ + "name": "Widlfly", + "script": "standalone.sh", + "cwd": "/opt/wildfly/bin/" }] } diff --git a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java index 18a9f76..b88abf7 100644 --- a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java +++ b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeBean.java @@ -13,6 +13,7 @@ import javax.persistence.TypedQuery; import TO.LoggedUserTO; import TO.MedicalSpecialtyTO; import TO.QuestionTO; +import TO.SpecialistDoctorTO; import common.MedicalTestType; import common.QuestionStatus; import common.UserType; @@ -20,6 +21,7 @@ import ejb.common.CommonFacadeLocal; import jpa.FamilyDoctorJPA; import jpa.PatientJPA; import jpa.QuestionJPA; +import jpa.SpecialistDoctorJPA; import managedbean.common.SessionUtils; /** @@ -53,16 +55,18 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { * @param message */ @Override - public void askQuestion(int professionalNumber, String title, String message) { - LoggedUserTO user = SessionUtils.getloggedOnUser(); - // 0. Conseguir el paciente en sesión - PatientJPA patient = entman.find(PatientJPA.class, user.getId()); - // 1. Buscar el médico de familia con ese professionalNumber - FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, professionalNumber); - // 2. Crear un objeto de Question para ese médico desde el paciente en sesión - QuestionJPA question = new QuestionJPA(0, title, message, QuestionStatus.PENDING, patient, fdoctor, null); - // 3. Guardar - entman.persist(question); + public void askQuestion(int userId, String title, String message) { + QuestionJPA qjpa = new QuestionJPA(); + qjpa.setId(0); + qjpa.setTitle(title); + qjpa.setMessage(message); + qjpa.setStatus(QuestionStatus.PENDING); + + PatientJPA pat = entman.find(PatientJPA.class, userId); + qjpa.setPatient(pat); + qjpa.setFamilyDoctor(pat.getFamilyDoctor()); + + entman.persist(qjpa); } /** @@ -72,23 +76,11 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { * @param response */ @Override - public void answerQuestion(QuestionTO q) { + public void answerQuestion(int questionId, String response) { QuestionJPA qjpa; - if(q.getId() >= 0) { - qjpa = entman.find(QuestionJPA.class, q.getId()); - qjpa.setResponse(q.getResponse()); - qjpa.setStatus(QuestionStatus.ANSWERED); - } else { - qjpa = new QuestionJPA(); - qjpa.setId(0); - qjpa.setTitle(q.getTitle()); - qjpa.setMessage(q.getMessage()); - qjpa.setStatus(QuestionStatus.PENDING); - } - - PatientJPA pat = entman.find(PatientJPA.class, q.getPatient().getId()); - qjpa.setPatient(pat); - qjpa.setFamilyDoctor(pat.getFamilyDoctor()); + qjpa = entman.find(QuestionJPA.class, questionId); + qjpa.setResponse(response); + qjpa.setStatus(QuestionStatus.ANSWERED); entman.persist(qjpa); } @@ -134,44 +126,24 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { return pendingQuestions; } - public Long getPendingQuestionsCount(int familyDoctorId) { - TypedQuery query = entman.createQuery( - "SELECT count(1) from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId", Long.class); - query.setParameter("status", QuestionStatus.PENDING); - query.setParameter("docId", familyDoctorId); - - return query.getSingleResult(); - } - - public List listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize) { - TypedQuery query = entman.createQuery( - "SELECT q from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId order by q.title", - QuestionJPA.class); - query.setParameter("status", QuestionStatus.PENDING); - query.setParameter("docId", familyDoctorId); - - if (pageSize > 0) { - query.setFirstResult(pageNumber * pageSize); - query.setMaxResults(pageSize); - } - - List allJPA = query.getResultList(); - List pendingQuestions = new ArrayList(); - - for (QuestionJPA item : allJPA) { - pendingQuestions.add(commonServices.getPOJOforQuestionJPA(item, 1)); - } - - return pendingQuestions; - } - /** - * Recuperar una pregunta por su String + * Recuperar una pregunta por su identificador * * @param question */ @Override - public void getQuestion(String question) { + public QuestionTO getQuestion(int idQuestion) { + QuestionTO resp = new QuestionTO(); + + TypedQuery query = entman.createQuery( + "SELECT q from QuestionJPA q where q.id=:idquestion", + QuestionJPA.class); + + query.setParameter("idquestion", idQuestion); + + resp = commonServices.getPOJOforQuestionJPA(query.getSingleResult(),1); + + return resp; } // ********************************************************************* @@ -239,7 +211,21 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote { * @param speciality */ @Override - public void findSpecialistDoctorByMedicalSpeciality(MedicalSpecialtyTO speciality) { + public List findSpecialistDoctorByMedicalSpeciality(MedicalSpecialtyTO speciality) { + List pendingQuestions = new ArrayList(); + + TypedQuery query = entman.createQuery( + "SELECT q from SpecialistDoctorJPA q where q.medicalSpecialty.name=:spec order by q.medicalSpecialty.name asc, q.surname asc", + SpecialistDoctorJPA.class); + query.setParameter("spec", speciality.getName()); + + List allJPA = query.getResultList(); + + for (SpecialistDoctorJPA item : allJPA) { + pendingQuestions.add(commonServices.getPOJOforSpecialistDoctorJPA(item, 1)); + } + + return pendingQuestions; } } \ 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 199aadb..e1c67de 100644 --- a/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java +++ b/1.sources/MyHealth/src/ejb/medicalTest/MedicalTestFacadeRemote.java @@ -7,6 +7,7 @@ import javax.ejb.Remote; import TO.MedicalSpecialtyTO; import TO.QuestionTO; +import TO.SpecialistDoctorTO; import common.MedicalTestType; /** @@ -29,7 +30,7 @@ public interface MedicalTestFacadeRemote { * @param title * @param message */ - public void askQuestion(int professionalNumber, String title, String message); + public void askQuestion(int userID, String title, String message); /** * El médico responde a una pregunta @@ -37,7 +38,7 @@ public interface MedicalTestFacadeRemote { * @param question * @param response */ - public void answerQuestion(QuestionTO question); + public void answerQuestion(int questionId, String response); /** * Recuperar las preguntas sin respuesta para un médico @@ -52,17 +53,13 @@ public interface MedicalTestFacadeRemote { * Recuperar las preguntas hechas por un paciente */ public List listAllMyQuestions(int userId); - - public Long getPendingQuestionsCount(int familyDoctorId); - - public List listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize); /** * Recuperar una pregunta por su String * * @param question */ - public void getQuestion(String question); + public QuestionTO getQuestion(int idQuestion); // ********************************************************************* MEDICAL // TEST @@ -114,5 +111,5 @@ public interface MedicalTestFacadeRemote { * * @param speciality */ - public void findSpecialistDoctorByMedicalSpeciality(MedicalSpecialtyTO speciality); + public List findSpecialistDoctorByMedicalSpeciality(MedicalSpecialtyTO speciality); } \ No newline at end of file diff --git a/1.sources/MyHealth/src/managedbean/common/AuthorizationFilter.java b/1.sources/MyHealth/src/managedbean/common/AuthorizationFilter.java index 54fe9d5..b9b0648 100644 --- a/1.sources/MyHealth/src/managedbean/common/AuthorizationFilter.java +++ b/1.sources/MyHealth/src/managedbean/common/AuthorizationFilter.java @@ -125,7 +125,7 @@ public class AuthorizationFilter implements Filter { authorized = true; if (reqURI.indexOf("/medicaltest/MedicalTests") > 0) authorized = true; - if (reqURI.indexOf("/medicaltest/SearchSpecialistBySpecialty") > 0) + if (reqURI.indexOf("/medicaltest/SearchSpecialist") > 0) authorized = true; if (reqURI.indexOf("/profile/UpdateProfile") > 0) authorized = true; diff --git a/1.sources/MyHealth/src/managedbean/common/MenuMBean.java b/1.sources/MyHealth/src/managedbean/common/MenuMBean.java index f19e437..675ed59 100644 --- a/1.sources/MyHealth/src/managedbean/common/MenuMBean.java +++ b/1.sources/MyHealth/src/managedbean/common/MenuMBean.java @@ -86,7 +86,7 @@ public class MenuMBean implements Serializable { } if (tipoUsuario == UserType.PATIENT) - subMenu.addElement(createMenuItem("Buscar especialista...", "fa fa-heartbeat", "/medicaltest/MedicalTests", null)); + subMenu.addElement(createMenuItem("Buscar especialista...", "fa fa-heartbeat", "/medicaltest/SearchSpecialist", null)); model.addElement(subMenu); } diff --git a/1.sources/MyHealth/src/managedbean/medicalTest/QuestionsMBean.java b/1.sources/MyHealth/src/managedbean/medicalTest/QuestionsMBean.java index 84d64e0..dc36577 100644 --- a/1.sources/MyHealth/src/managedbean/medicalTest/QuestionsMBean.java +++ b/1.sources/MyHealth/src/managedbean/medicalTest/QuestionsMBean.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; +import javax.faces.application.FacesMessage; import javax.faces.view.ViewScoped; import javax.inject.Named; @@ -24,10 +25,9 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable { private int userID; private UserType userType; private List pendingQuestions; - protected String title; - protected String message; - protected String response; - protected QuestionTO selected; + private Integer id; + private QuestionTO selected; + private boolean addNewMode; public QuestionsMBean() { } @@ -37,15 +37,11 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable { // Inicialización de variables y propiedades van aquí. this.userType = SessionUtils.getUserType(); this.userID = Integer.valueOf(SessionUtils.getUserId()); + + this.addNewMode = false; this.selected = null; this.loadQuestions(); - this.printSelected(); - } - - private void printSelected() { - System.out.println("Selected: "); - System.out.println(this.selected); } public List getPendingQuestions() { @@ -60,12 +56,11 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable { * en función del tipo de usuario en sesión */ private void loadQuestions() { - this.printSelected(); - if (userType == UserType.FAMILY_DOCTOR) { + if (this.userType == UserType.FAMILY_DOCTOR) { // Listar las preguntas destinadas a él // El método disponible del API básico es referente al doctor this.pendingQuestions = getRemoteManagerMedicalTest().listAllPendingQuestions(userID); - } else if (userType == UserType.PATIENT) { + } else if (this.userType == UserType.PATIENT) { // Listar las preguntas realiadas por él // Para reutilizar la misma view, necesitaremos nuevos métodos para el API de // cara a recoger sus preguntas realizadas. @@ -73,37 +68,9 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable { } } - public boolean getShowCreate() { - return userType == UserType.PATIENT; - } - - public boolean isShowCreate() { - return this.getShowCreate(); - } - - public void setShowCreate() { - // - } - - public boolean getDisabledMessage() { - if(this.selected != null) { - return this.selected.getStatus() != QuestionStatus.NEW; - } - return false; - } - - public boolean isDisabledMessage() { - return this.getDisabledMessage(); - } - - public void setDisabledMessage(boolean bval) { - // Nothing to do - } - public void onSelect(SelectEvent event) { - this.printSelected(); + this.addNewMode = false; this.selected = (QuestionTO) event.getObject(); - this.printSelected(); } public void onUnSelect(SelectEvent event) { @@ -111,56 +78,55 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable { } public void setSelected(QuestionTO selected) { - this.printSelected(); this.selected = selected; } public QuestionTO getSelected() { return this.selected; } - - public void setTitle(String title) { - this.title = title; - } - - public void setMessage(String message) { - this.message = message; - } - - public void setResponse(String response) { - this.response = response; - } public void save() { - this.printSelected(); - getRemoteManagerMedicalTest().answerQuestion(this.selected); - this.init(); + getRemoteManagerMedicalTest().answerQuestion(this.selected.getId(), this.selected.getResponse()); + this.loadQuestions(); + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Datos guardados", "La respuesta se registrado correctamente en el sistema."); + this.selected = null; } public void create() { - this.printSelected(); - String template = ""; + this.addNewMode = true; this.selected = new QuestionTO(); this.selected.setId(-1); - this.selected.setTitle(template); - this.selected.setMessage(template); - this.selected.setResponse(template); - this.selected.setStatus(QuestionStatus.NEW); - this.selected.getPatient().setId(Integer.parseInt(SessionUtils.getloggedOnUser().getId())); - this.selected.getPatient().setName(SessionUtils.getloggedOnUser().getName()); - this.printSelected(); + this.selected.setTitle(""); + this.selected.setMessage(""); } - - public boolean getShowPanelDetail() { - return this.selected != null; + + public void addNewQuestion() { + getRemoteManagerMedicalTest().askQuestion(userID, this.selected.getTitle(), this.selected.getMessage()); + this.loadQuestions(); + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Datos guardados", "La pregunta se registrado correctamente en el sistema."); } public boolean isShowPanelDetail() { - return this.getShowPanelDetail(); + return this.selected != null && this.addNewMode == false; } - public void setShowPanelDetail() { - // + public boolean isPatient() { + return (this.userType == UserType.PATIENT); } + public boolean isFamilyDoctor() { + return (this.userType == UserType.FAMILY_DOCTOR); + } + + public boolean isAddNewMode() { + return addNewMode; + } + + public boolean isRespuestaEditable() { + return (this.userType == UserType.FAMILY_DOCTOR && this.selected != null && this.selected.getStatus() == QuestionStatus.PENDING); + } + + public void setAddNewMode(boolean addNewMode) { + this.addNewMode = addNewMode; + } } diff --git a/1.sources/MyHealth/src/managedbean/medicalTest/SearchSpecialistMBean.java b/1.sources/MyHealth/src/managedbean/medicalTest/SearchSpecialistMBean.java new file mode 100644 index 0000000..94f34a1 --- /dev/null +++ b/1.sources/MyHealth/src/managedbean/medicalTest/SearchSpecialistMBean.java @@ -0,0 +1,90 @@ +package managedbean.medicalTest; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.faces.view.ViewScoped; +import javax.inject.Named; + +import org.primefaces.event.SelectEvent; + +import TO.MedicalSpecialtyTO; +import TO.SpecialistDoctorTO; +import common.Constants; +import common.UserType; +import managedbean.common.ManagedBeanBase; +import managedbean.common.SessionUtils; + +@Named("sspec") +@ViewScoped +public class SearchSpecialistMBean extends ManagedBeanBase implements Serializable { + + private static final long serialVersionUID = 1L; + + private int userID; + private UserType userType; + private List listDoctors; + private List medicalSpecialitiesList; + private MedicalSpecialtyTO medicalSpeciality; + private String lastUIQueryMS; + + public SearchSpecialistMBean() { + } + + @PostConstruct + public void init() { + // Inicialización de variables y propiedades van aquí. + this.userType = SessionUtils.getUserType(); + this.userID = Integer.valueOf(SessionUtils.getUserId()); + this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, + Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + this.medicalSpeciality = null; + this.lastUIQueryMS = ""; + this.listDoctors = new ArrayList(); + } + + public void onSelect(SelectEvent event) { + System.out.println("onSelect"); + this.medicalSpeciality = (MedicalSpecialtyTO) event.getObject(); + System.out.println(this.medicalSpeciality); + this.listDoctors = getRemoteManagerMedicalTest() + .findSpecialistDoctorByMedicalSpeciality(this.medicalSpeciality); + } + + public List completeMedicalSpeciality(String query) { + if (query != null && query.equals(this.lastUIQueryMS) == false) { + this.lastUIQueryMS = query; + // Recuperamos las 200 primeras coincidencias + this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesFiltered(query, 0, + Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH); + } + return this.medicalSpecialitiesList; + } + + public List getListDoctors() { + return listDoctors; + } + + public void setListDoctors(List listDoctors) { + this.listDoctors = listDoctors; + } + + public List getMedicalSpecialitiesList() { + return medicalSpecialitiesList; + } + + public void setMedicalSpecialitiesList(List medicalSpecialitiesList) { + this.medicalSpecialitiesList = medicalSpecialitiesList; + } + + public MedicalSpecialtyTO getMedicalSpeciality() { + return medicalSpeciality; + } + + public void setMedicalSpeciality(MedicalSpecialtyTO medicalSpecialty) { + this.medicalSpeciality = medicalSpecialty; + } + +}