Preguntas y respuestas funcionando al 100%
This commit is contained in:
@@ -36,9 +36,12 @@
|
||||
<div class="ui-g-1 ui-md-1"></div>
|
||||
<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} ">
|
||||
<h:outputText rendered="#{Questions.selected.status != 'NEW'}">#{Questions.selected.title}</h:outputText>
|
||||
<p:inputText rendered="#{Questions.selected.status == 'NEW'}"></p:inputText>
|
||||
<!-- Creación de pregunta -->
|
||||
<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>
|
||||
|
||||
<!-- 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>
|
||||
<p:panel rendered="#{Questions.selected.status != 'NEW'}" style="border: 0px !important;">
|
||||
<h3>Respuesta:</h3>
|
||||
@@ -47,30 +50,7 @@
|
||||
</p:panel>
|
||||
<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: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>
|
||||
-->
|
||||
|
||||
</p:panel>
|
||||
</div>
|
||||
</div>
|
||||
</p:panel>
|
||||
|
||||
@@ -54,17 +54,15 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
|
||||
*/
|
||||
@Override
|
||||
public void askQuestion(int professionalNumber, String title, String message) {
|
||||
if (SessionUtils.getUserType() == UserType.PATIENT) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,23 +73,34 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
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());
|
||||
|
||||
entman.persist(qjpa);
|
||||
}
|
||||
|
||||
@Override
|
||||
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 q where q.familyDoctor.id=:docId order by q.status desc, q.title asc", 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);
|
||||
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);
|
||||
|
||||
@@ -105,16 +114,39 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
|
||||
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) {
|
||||
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("docId", familyDoctorId);
|
||||
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
|
||||
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("docId", familyDoctorId);
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ public interface MedicalTestFacadeRemote {
|
||||
*/
|
||||
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 List<QuestionTO> listPendingQuestionsPaged(int familyDoctorId, int pageNumber, int pageSize);
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ManagedBeanBase {
|
||||
remoteManagerMedicalTest = this.getContext("java:app/MyHealth.jar/MedicalTestFacadeBean!ejb.medicalTest.MedicalTestFacadeRemote", MedicalTestFacadeRemote.class);
|
||||
}
|
||||
|
||||
return remoteManagerMedicalTest;
|
||||
return remoteManagerMedicalTest;
|
||||
}
|
||||
|
||||
protected void addFacesMessageKeep(FacesMessage.Severity severity, String summary, String detail) {
|
||||
|
||||
@@ -38,6 +38,7 @@ 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.selected = null;
|
||||
|
||||
this.loadQuestions();
|
||||
this.printSelected();
|
||||
@@ -69,6 +70,7 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
|
||||
// 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.
|
||||
this.pendingQuestions = getRemoteManagerMedicalTest().listAllMyQuestions(userID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,36 +100,6 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
|
||||
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();
|
||||
@@ -140,6 +112,7 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
|
||||
}
|
||||
|
||||
public void setSelected(QuestionTO selected) {
|
||||
this.printSelected();
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@@ -160,19 +133,22 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.printSelected();
|
||||
getRemoteManagerMedicalTest().answerQuestion(this.selected);
|
||||
this.init();
|
||||
}
|
||||
|
||||
public void create() {
|
||||
this.printSelected();
|
||||
String template = "-";
|
||||
String template = "";
|
||||
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().setName(template);
|
||||
this.selected.getPatient().setSurname(template);
|
||||
this.selected.getPatient().setId(Integer.parseInt(SessionUtils.getloggedOnUser().getId()));
|
||||
this.selected.getPatient().setName(SessionUtils.getloggedOnUser().getName());
|
||||
this.printSelected();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user