Issue #40 corregida.

This commit is contained in:
Roberto Orden Erena
2019-12-28 13:23:00 +01:00
parent 308fa17eba
commit af0a2cf98c
3 changed files with 52 additions and 26 deletions

View File

@@ -20,10 +20,12 @@ import jpa.QuestionJPA;
import jpa.SpecialistDoctorJPA;
/**
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los métodos de la capa de negocio que implementan la logica de negocio y la interacción con la capa de
* persistencia.
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
* métodos de la capa de negocio que implementan la logica de negocio y la
* interacción con la capa de persistencia.
*
* Tanto los pacientes como los médicos deben acceder a la vista de pruebas médicas.
* Tanto los pacientes como los médicos deben acceder a la vista de pruebas
* médicas.
*
* @author rorden
*
@@ -47,18 +49,28 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param title
* @param message
*/
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);
public String askQuestion(int userId, String title, String message) {
PatientJPA pat = entman.find(PatientJPA.class, userId);
qjpa.setPatient(pat);
qjpa.setFamilyDoctor(pat.getFamilyDoctor());
entman.persist(qjpa);
if (pat.getFamilyDoctor() != null) {
QuestionJPA qjpa = new QuestionJPA();
qjpa.setId(0);
qjpa.setTitle(title);
qjpa.setMessage(message);
qjpa.setStatus(QuestionStatus.PENDING);
qjpa.setPatient(pat);
qjpa.setFamilyDoctor(pat.getFamilyDoctor());
entman.persist(qjpa);
return "ok";
} else {
return "No tienes médico de familia elegido, por favor acude a la sección 'Gestionar Perfil' -> 'Cambiar médico de familia'";
}
}
/**
@@ -80,7 +92,9 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
// 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.familyDoctor.id=:docId order by q.status desc, q.title asc",
QuestionJPA.class);
// query.setParameter("status", QuestionStatus.PENDING);
query.setParameter("docId", familyDoctorId);
@@ -99,7 +113,9 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
// 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);
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);
@@ -120,7 +136,8 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
public QuestionTO getQuestion(int idQuestion) {
QuestionTO resp = new QuestionTO();
TypedQuery<QuestionJPA> query = entman.createQuery("SELECT q from QuestionJPA q where q.id=:idquestion", QuestionJPA.class);
TypedQuery<QuestionJPA> query = entman.createQuery("SELECT q from QuestionJPA q where q.id=:idquestion",
QuestionJPA.class);
query.setParameter("idquestion", idQuestion);
@@ -140,7 +157,8 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param idMedicalTest
* @param date
* @param time
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias magnéticas y TAC
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias
* magnéticas y TAC
* @param observations
*/
public void addMedicalTest(int idMedicalTest, Date date, long time, MedicalTestType testType, String observations) {
@@ -183,29 +201,32 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
}
public Long getSpecialistDoctorByMedicalSpecialityCount(int specialityId) {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId", Long.class);
TypedQuery<Long> query = entman.createQuery(
"SELECT count(1) from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId", Long.class);
query.setParameter("specId", specialityId);
return query.getSingleResult();
}
/**
* Listar médicos con una especialidad concreta
*
* @param speciality
*/
public List<SpecialistDoctorTO> findSpecialistDoctorByMedicalSpeciality(int specialityId, int pageNumber, int pageSize) {
public List<SpecialistDoctorTO> findSpecialistDoctorByMedicalSpeciality(int specialityId, int pageNumber,
int pageSize) {
List<SpecialistDoctorTO> pendingQuestions = new ArrayList<SpecialistDoctorTO>();
TypedQuery<SpecialistDoctorJPA> query = entman.createQuery(
"SELECT q from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId order by q.medicalSpecialty.name asc, q.surname asc", SpecialistDoctorJPA.class);
"SELECT q from SpecialistDoctorJPA q where q.medicalSpecialty.id=:specId order by q.medicalSpecialty.name asc, q.surname asc",
SpecialistDoctorJPA.class);
query.setParameter("specId", specialityId);
if (pageSize > 0) {
query.setFirstResult(pageNumber * pageSize);
query.setMaxResults(pageSize);
}
List<SpecialistDoctorJPA> allJPA = query.getResultList();
for (SpecialistDoctorJPA item : allJPA) {

View File

@@ -28,7 +28,7 @@ public interface MedicalTestFacadeRemote {
* @param title
* @param message
*/
public void askQuestion(int userID, String title, String message);
public String askQuestion(int userID, String title, String message);
/**
* El médico responde a una pregunta

View File

@@ -100,10 +100,15 @@ public class QuestionsMBean extends ManagedBeanBase implements Serializable {
}
public void addNewQuestion() {
getRemoteManagerMedicalTest().askQuestion(userID, this.selected.getTitle(), this.selected.getMessage());
this.create();
this.loadQuestions();
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Datos guardados", "La pregunta se registrado correctamente en el sistema.");
String result = getRemoteManagerMedicalTest().askQuestion(userID, this.selected.getTitle(), this.selected.getMessage());
if(result == "ok") {
this.create();
this.loadQuestions();
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Datos guardados", "La pregunta se registrado correctamente en el sistema.");
} else {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", result);
}
}
public boolean isShowPanelDetail() {