Preguntas y respuestas funcionando al 100%

This commit is contained in:
Roberto Orden Erena
2019-12-26 12:14:12 +01:00
parent a35d7fe7fe
commit b2f5cf88e4
5 changed files with 79 additions and 86 deletions

View File

@@ -36,9 +36,12 @@
<div class="ui-g-1 ui-md-1"></div> <div class="ui-g-1 ui-md-1"></div>
<div class="ui-g-8 ui-md-8"> <div class="ui-g-8 ui-md-8">
<p:panel id="panelDetail" visible="#{Questions.showPanelDetail}" header="Pregunta de #{Questions.selected.patient.name} #{Questions.selected.patient.surname} "> <p:panel id="panelDetail" visible="#{Questions.showPanelDetail}" header="Pregunta de #{Questions.selected.patient.name} #{Questions.selected.patient.surname} ">
<h:outputText rendered="#{Questions.selected.status != 'NEW'}">#{Questions.selected.title}</h:outputText> <!-- Creación de pregunta -->
<p:inputText rendered="#{Questions.selected.status == 'NEW'}"></p:inputText> <p:inputText rendered="#{Questions.selected.status == 'NEW'}" value="#{Questions.selected.title}"></p:inputText>
<p:textEditor rendered="#{Questions.selected.status == 'NEW'}" value="#{Questions.selected.message}" ></p:textEditor> <p:textEditor rendered="#{Questions.selected.status == 'NEW'}" value="#{Questions.selected.message}" ></p:textEditor>
<!-- Respuesta a una pregunta -->
<h:outputText rendered="#{Questions.selected.status != 'NEW'}">#{Questions.selected.title}</h:outputText>
<h:outputText rendered="#{Questions.selected.status != 'NEW'}" value="#{Questions.selected.message}" escape="false"></h:outputText> <h:outputText rendered="#{Questions.selected.status != 'NEW'}" value="#{Questions.selected.message}" escape="false"></h:outputText>
<p:panel rendered="#{Questions.selected.status != 'NEW'}" style="border: 0px !important;"> <p:panel rendered="#{Questions.selected.status != 'NEW'}" style="border: 0px !important;">
<h3>Respuesta:</h3> <h3>Respuesta:</h3>
@@ -48,29 +51,6 @@
<br/> <br/>
<p:commandButton rendered="#{Questions.selected.status != 'ANSWERED'}" value="#{Questions.selected.status == 'NEW' ? 'Preguntar' : 'Responder'}" action="#{Questions.save}" update="frmQuestions" icon="pi pi-save" ></p:commandButton> <p:commandButton rendered="#{Questions.selected.status != 'ANSWERED'}" value="#{Questions.selected.status == 'NEW' ? 'Preguntar' : 'Responder'}" action="#{Questions.save}" update="frmQuestions" icon="pi pi-save" ></p:commandButton>
</p:panel> </p:panel>
<!--
<p:panel id="panelDetail" visible="#{Questions.showPanelDetail}" header="Pregunta de #{Questions.selected.patient.name} #{Questions.selected.patient.surname} ">
<h:div rendered="#{Questions.selected.status == 'NEW'}">
<p:inputText rendered="#{Questions.selected.status == 'NEW'}" aria-placeholder="Título de la pregunta"></p:inputText>
<p:textEditor rendered="#{Questions.selected.status == 'NEW'}" value="#{Questions.selected.message}" ></p:textEditor>
<br/>
<p:commandButton rendered="#{Questions.selected.status == 'NEW'}" value="Preguntar" action="#{Questions.save}" update="frmQuestions" icon="pi pi-save" ></p:commandButton>
</h:div>
<h:div rendered="#{Questions.selected.status != 'NEW'}">
<h:h3 rendered="#{Questions.selected.status != 'NEW'}">#{Questions.selected.title}</h:h3>
<h:outputText rendered="#{Questions.selected.status != 'NEW'}" value="#{Questions.selected.message}" escape="false"></h:outputText>
<p:panel visible="#{Questions.selected.status != 'NEW'}" style="border: 0px !important;">
<h3>Respuesta:</h3>
<p:textEditor rendered="#{Questions.enableResponseEditor}" value="#{Questions.selected.response}"></p:textEditor>
<h:outputText visible="#{Questions.enableResponseOutput}" value="#{Questions.selected.response}" escape="false"></h:outputText>
</p:panel>
<br/>
<p:commandButton rendered="#{Questions.selected.status != 'NEW'}" value="Responder" action="#{Questions.save}" update="frmQuestions,listQuestions" icon="pi pi-save" ></p:commandButton>
</h:div>
</p:panel>
-->
</div> </div>
</div> </div>
</p:panel> </p:panel>

View File

@@ -54,17 +54,15 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
*/ */
@Override @Override
public void askQuestion(int professionalNumber, String title, String message) { public void askQuestion(int professionalNumber, String title, String message) {
if (SessionUtils.getUserType() == UserType.PATIENT) { LoggedUserTO user = SessionUtils.getloggedOnUser();
LoggedUserTO user = SessionUtils.getloggedOnUser(); // 0. Conseguir el paciente en sesión
// 0. Conseguir el paciente en sesión PatientJPA patient = entman.find(PatientJPA.class, user.getId());
PatientJPA patient = entman.find(PatientJPA.class, user.getId()); // 1. Buscar el médico de familia con ese professionalNumber
// 1. Buscar el médico de familia con ese professionalNumber FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, professionalNumber);
FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, professionalNumber); // 2. Crear un objeto de Question para ese médico desde el paciente en sesión
// 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);
QuestionJPA question = new QuestionJPA(0, title, message, QuestionStatus.PENDING, patient, fdoctor, null); // 3. Guardar
// 3. Guardar entman.persist(question);
entman.persist(question);
}
} }
/** /**
@@ -75,23 +73,34 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
*/ */
@Override @Override
public void answerQuestion(QuestionTO q) { public void answerQuestion(QuestionTO q) {
QuestionJPA qjpa = entman.find(QuestionJPA.class, q.getId()); QuestionJPA qjpa;
qjpa.setResponse(q.getResponse()); if(q.getId() >= 0) {
qjpa.setStatus(QuestionStatus.ANSWERED); 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 patient = entman.find(PatientJPA.class, q.getPatient().getId()); PatientJPA pat = entman.find(PatientJPA.class, q.getPatient().getId());
// 1. Buscar el médico de familia con ese professionalNumber qjpa.setPatient(pat);
FamilyDoctorJPA fdoctor = entman.find(FamilyDoctorJPA.class, q.getDoctor().getId()); qjpa.setFamilyDoctor(pat.getFamilyDoctor());
qjpa.setPatient(patient);
qjpa.setFamilyDoctor(fdoctor);
entman.persist(qjpa); entman.persist(qjpa);
} }
@Override
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId) { public List<QuestionTO> listAllPendingQuestions(int familyDoctorId) {
// 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
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); // 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("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId); query.setParameter("docId", familyDoctorId);
@@ -105,8 +114,29 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
return pendingQuestions; return pendingQuestions;
} }
public List<QuestionTO> listAllMyQuestions(int userId) {
List<QuestionTO> pendingQuestions = new ArrayList<QuestionTO>();
// 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.patient.id=:patientId order by q.status desc, q.title asc",
QuestionJPA.class);
// query.setParameter("status", QuestionStatus.PENDING);
query.setParameter("patientId", userId);
List<QuestionJPA> allJPA = query.getResultList();
for (QuestionJPA item : allJPA) {
pendingQuestions.add(commonServices.getPOJOforQuestionJPA(item, 1));
}
return pendingQuestions;
}
public Long getPendingQuestionsCount(int familyDoctorId) { public Long getPendingQuestionsCount(int familyDoctorId) {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from QuestionJPA q where q.status=:status and q.familyDoctor.id=:docId", Long.class); TypedQuery<Long> 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("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId); query.setParameter("docId", familyDoctorId);
@@ -114,7 +144,9 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
} }
public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize) { public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize) {
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.status=:status and q.familyDoctor.id=:docId order by q.title",
QuestionJPA.class);
query.setParameter("status", QuestionStatus.PENDING); query.setParameter("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId); query.setParameter("docId", familyDoctorId);

View File

@@ -48,6 +48,11 @@ public interface MedicalTestFacadeRemote {
*/ */
public List<QuestionTO> listAllPendingQuestions(int familyDoctorId); public List<QuestionTO> listAllPendingQuestions(int familyDoctorId);
/**
* Recuperar las preguntas hechas por un paciente
*/
public List<QuestionTO> listAllMyQuestions(int userId);
public Long getPendingQuestionsCount(int familyDoctorId); public Long getPendingQuestionsCount(int familyDoctorId);
public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize); public List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize);

View File

@@ -38,6 +38,7 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
// Inicialización de variables y propiedades van aquí. // Inicialización de variables y propiedades van aquí.
this.userType = SessionUtils.getUserType(); this.userType = SessionUtils.getUserType();
this.userID = Integer.valueOf(SessionUtils.getUserId()); this.userID = Integer.valueOf(SessionUtils.getUserId());
this.selected = null;
this.loadQuestions(); this.loadQuestions();
this.printSelected(); this.printSelected();
@@ -69,6 +70,7 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
// Listar las preguntas realiadas por él // Listar las preguntas realiadas por él
// Para reutilizar la misma view, necesitaremos nuevos métodos para el API de // Para reutilizar la misma view, necesitaremos nuevos métodos para el API de
// cara a recoger sus preguntas realizadas. // cara a recoger sus preguntas realizadas.
this.pendingQuestions = getRemoteManagerMedicalTest().listAllMyQuestions(userID);
} }
} }
@@ -99,36 +101,6 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
// Nothing to do // 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) { public void onSelect(SelectEvent event) {
this.printSelected(); this.printSelected();
this.selected = (QuestionTO) event.getObject(); this.selected = (QuestionTO) event.getObject();
@@ -140,6 +112,7 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
} }
public void setSelected(QuestionTO selected) { public void setSelected(QuestionTO selected) {
this.printSelected();
this.selected = selected; this.selected = selected;
} }
@@ -160,19 +133,22 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
} }
public void save() { public void save() {
this.printSelected();
getRemoteManagerMedicalTest().answerQuestion(this.selected); getRemoteManagerMedicalTest().answerQuestion(this.selected);
this.init();
} }
public void create() { public void create() {
this.printSelected(); this.printSelected();
String template = "-"; String template = "";
this.selected = new QuestionTO(); this.selected = new QuestionTO();
this.selected.setId(-1);
this.selected.setTitle(template); this.selected.setTitle(template);
this.selected.setMessage(template); this.selected.setMessage(template);
this.selected.setResponse(template); this.selected.setResponse(template);
this.selected.setStatus(QuestionStatus.NEW); this.selected.setStatus(QuestionStatus.NEW);
this.selected.getPatient().setName(template); this.selected.getPatient().setId(Integer.parseInt(SessionUtils.getloggedOnUser().getId()));
this.selected.getPatient().setSurname(template); this.selected.getPatient().setName(SessionUtils.getloggedOnUser().getName());
this.printSelected(); this.printSelected();
} }