Preguntas y respuestas funcionando al 100%
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user