Preguntas y respuestas funcionando para médicos

This commit is contained in:
Roberto Orden Erena
2019-12-24 18:36:41 +01:00
parent 000e2a8721
commit a35d7fe7fe
23 changed files with 647 additions and 163 deletions

View File

@@ -27,6 +27,8 @@ public class QuestionTO implements Serializable {
public QuestionTO() {
super();
this.patient = new PatientTO();
this.fdoctor = new FamilyDoctorTO();
}
public QuestionTO(int id, String title, String message, QuestionStatus status, PatientTO patient,
@@ -96,5 +98,21 @@ public class QuestionTO implements Serializable {
public void setResponse(String response) {
this.response = response;
}
public String toString() {
return "{"
+ "ObjectID" + super.toString()
+ ",id" + this.getId()
+ ",title" + this.getTitle()
+ ",message" + this.getMessage()
+ ",response" + this.getResponse()
+ ",status" + this.getStatus()
+ ",patient-id" + this.getPatient().getId()
+ ",patient-name-surname" + this.getPatient().getName() + " " + this.getPatient().getSurname()
+ ",fdoctor-id" + this.getDoctor().getId()
+ ",fdoctor-name-surname" + this.getDoctor().getName() + " " + this.getDoctor().getSurname()
+ "}";
}
}

View File

@@ -6,7 +6,7 @@ package common;
*
*/
public enum QuestionStatus {
ANSWERED("Respondida"), PENDING("Pendiente");
ANSWERED("Respondida"), PENDING("Pendiente"), NEW("New");
private String questionStatusName;

View File

@@ -74,11 +74,35 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param response
*/
@Override
public void answerQuestion(String question, String response) {
public void answerQuestion(QuestionTO q) {
QuestionJPA qjpa = entman.find(QuestionJPA.class, q.getId());
qjpa.setResponse(q.getResponse());
qjpa.setStatus(QuestionStatus.ANSWERED);
PatientJPA patient = entman.find(PatientJPA.class, q.getPatient().getId());
// 1. Buscar el médico de familia con ese professionalNumber
FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, q.getDoctor().getId());
qjpa.setPatient(patient);
qjpa.setFamilyDoctor(fdoctor);
entman.persist(qjpa);
}
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId) {
return null;
// TypedQuery<QuestionJPA> query = entman.createQuery("SELECT q from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId order by q.title", QuestionJPA.class);
TypedQuery<QuestionJPA> 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);
List<QuestionJPA> allJPA = query.getResultList();
List<QuestionTO> pendingQuestions = new ArrayList<QuestionTO>();
for (QuestionJPA item : allJPA) {
pendingQuestions.add(commonServices.getPOJOforQuestionJPA(item, 1));
}
return pendingQuestions;
}
public Long getPendingQuestionsCount(int familyDoctorId) {

View File

@@ -37,7 +37,7 @@ public interface MedicalTestFacadeRemote {
* @param question
* @param response
*/
public void answerQuestion(String question, String response);
public void answerQuestion(QuestionTO question);
/**
* Recuperar las preguntas sin respuesta para un médico

View File

@@ -12,6 +12,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import TO.QuestionTO;
import common.QuestionStatus;
/**

View File

@@ -99,7 +99,7 @@ public class AuthorizationFilter implements Filter {
authorized = true;
if (reqURI.indexOf("/visit/CancelVisit") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/AddQuestion") > 0)
if (reqURI.indexOf("/medicaltest/Questions") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/ViewMedicalTest") > 0)
authorized = true;
@@ -121,9 +121,7 @@ public class AuthorizationFilter implements Filter {
authorized = true;
if (reqURI.indexOf("/medicaltest/MedicalTests") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/AnswerQuestion") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/PendingQuestions") > 0)
if (reqURI.indexOf("/medicaltest/Questions") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/ViewMedicalTest") > 0)
authorized = true;

View File

@@ -78,7 +78,7 @@ public class MenuMBean implements Serializable {
// Todos pueden consultar (P S F)
subMenu.addElement(createMenuItem("Consultar prueba", "fa fa-search", "/medicaltest/MedicalTests", null));
subMenu.addElement(new DefaultSeparator());
subMenu.addElement(new DefaultSeparator());
if (tipoUsuario == UserType.SPECIALIST_DOCTOR) {
subMenu.addElement(new DefaultSeparator());
@@ -93,18 +93,7 @@ public class MenuMBean implements Serializable {
// Preguntas médicas
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.FAMILY_DOCTOR) {
subMenu = new DefaultSubMenu("Preguntas", "fa fa-question-circle");
if (tipoUsuario == UserType.PATIENT)
subMenu.addElement(createMenuItem("Hacer pregunta", "fa fa-comment-o", "/medicaltest/MedicalTests", null));
if (tipoUsuario == UserType.FAMILY_DOCTOR)
subMenu.addElement(createMenuItem("Responder pregunta", "fa fa-comments", "/medicaltest/MedicalTests", null));
if (tipoUsuario == UserType.FAMILY_DOCTOR)
subMenu.addElement(createMenuItem("Ver preguntas pendientes", "fa fa-comments-o", "/medicaltest/PendingQuestions", null));
model.addElement(subMenu);
model.addElement(createMenuItem("Preguntas", "fa fa-comment-o", "/medicaltest/Questions", null));
}
}

View File

@@ -1,55 +0,0 @@
package managedbean.medicalTest;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import TO.QuestionTO;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("PendingQuestions")
@ViewScoped
public class PendingQuestionsMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private int familyDoctorId;
private LazyDataModel<QuestionTO> lazyDataModelQuestionList;
public PendingQuestionsMBean() {
}
@PostConstruct
public void init() {
// Inicialización de variables y propiedades van aquí.
this.familyDoctorId = Integer.valueOf(SessionUtils.getUserId());
this.lazyDataModelQuestionList = new LazyDataModel<QuestionTO>() {
private static final long serialVersionUID = 1L;
@Override
public List<QuestionTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
Long totalRowCount = getRemoteManagerMedicalTest().getPendingQuestionsCount(familyDoctorId);
this.setRowCount(totalRowCount.intValue());
return getRemoteManagerMedicalTest().listPendingQuestionsPaged(familyDoctorId, (first / pageSize), pageSize);
}
};
}
public LazyDataModel<QuestionTO> getLazyDataModelQuestionList() {
return lazyDataModelQuestionList;
}
public void saveData() {
}
}

View File

@@ -0,0 +1,191 @@
package managedbean.medicalTest;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.SelectEvent;
import TO.PatientTO;
import TO.QuestionTO;
import common.QuestionStatus;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("Questions")
@ViewScoped
public class QuestionsMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private int userID;
private UserType userType;
private List<QuestionTO> pendingQuestions;
protected String title;
protected String message;
protected String response;
protected QuestionTO selected;
public QuestionsMBean() {
}
@PostConstruct
public void init() {
// Inicialización de variables y propiedades van aquí.
this.userType = SessionUtils.getUserType();
this.userID = Integer.valueOf(SessionUtils.getUserId());
this.loadQuestions();
this.printSelected();
}
private void printSelected() {
System.out.println("Selected: ");
System.out.println(this.selected);
}
public List<QuestionTO> getPendingQuestions() {
return pendingQuestions;
}
public void setPendingQuestions(List<QuestionTO> value) {
this.pendingQuestions = value;
}
/**
* Cargará las preguntas enviadas al médico o escritas por el paciente, esto irá
* en función del tipo de usuario en sesión
*/
private void loadQuestions() {
this.printSelected();
if (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) {
// 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.
}
}
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 boolean getEnableResponseEditor() {
if(this.selected != null) {
return this.selected.getStatus() == QuestionStatus.PENDING;
}
return false;
}
public boolean isEnableResponseEditor() {
return this.getEnableResponseEditor();
}
public void setEnableResponseEditor(boolean bval) {
// Nothing to do
}
public boolean getEnableResponseOutput() {
if(this.selected != null) {
return this.selected.getStatus() == QuestionStatus.ANSWERED;
}
return false;
}
public boolean isEnableResponseOutput() {
return this.getEnableResponseEditor();
}
public void setEnableResponseOutput(boolean bval) {
// Nothing to do
}
public void onSelect(SelectEvent event) {
this.printSelected();
this.selected = (QuestionTO) event.getObject();
this.printSelected();
}
public void onUnSelect(SelectEvent event) {
this.selected = null;
}
public void setSelected(QuestionTO selected) {
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() {
getRemoteManagerMedicalTest().answerQuestion(this.selected);
}
public void create() {
this.printSelected();
String template = "-";
this.selected = new QuestionTO();
this.selected.setTitle(template);
this.selected.setMessage(template);
this.selected.setResponse(template);
this.selected.setStatus(QuestionStatus.NEW);
this.selected.getPatient().setName(template);
this.selected.getPatient().setSurname(template);
this.printSelected();
}
public boolean getShowPanelDetail() {
return this.selected != null;
}
public boolean isShowPanelDetail() {
return this.getShowPanelDetail();
}
public void setShowPanelDetail() {
//
}
}