Mejoras en la gestión de pruebas médicas (filtros de búsqueda)

This commit is contained in:
Marcos Garcia Nuñez
2019-12-29 21:33:57 +01:00
parent ea5f0a4352
commit b6e4116d0f
5 changed files with 341 additions and 258 deletions

View File

@@ -17,6 +17,7 @@ import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import common.MedicalTestType;
import common.QuestionStatus;
import common.Utils;
import ejb.common.CommonFacadeLocal;
import jpa.MedicalTestJPA;
import jpa.PatientJPA;
@@ -24,12 +25,10 @@ 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
*
@@ -96,9 +95,7 @@ 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);
@@ -117,9 +114,7 @@ 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);
@@ -140,8 +135,7 @@ 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);
@@ -156,29 +150,23 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
/**
* Añadir pruebas médicas a una cita
*
* Dado que será añadida por el médico especialista en sesión no hace falta más
* información.
* Dado que será añadida por el médico especialista en sesión no hace falta más información.
*
* @param patientiID
* @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 String addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time,
MedicalTestType testType, String observations) {
try {
SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID);
PatientJPA pat = entman.find(PatientJPA.class, patientID);
public MedicalTestTO addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations) throws Exception {
SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID);
PatientJPA pat = entman.find(PatientJPA.class, patientID);
MedicalTestJPA mt = new MedicalTestJPA(0, date, time, observations, null, testType, pat, specDoctor);
MedicalTestJPA mt = new MedicalTestJPA(date, time, observations, null, testType, pat, specDoctor);
entman.persist(mt);
return "ok";
} catch (Exception ex) {
return ex.getMessage();
}
entman.persist(mt);
return this.commonServices.getPOJOforMedicalTestJPA(mt, 1);
}
/**
@@ -197,8 +185,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
}
private MedicalTestJPA getMedicalTestJPA(int idMedicalTest) {
TypedQuery<MedicalTestJPA> query = entman
.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class);
TypedQuery<MedicalTestJPA> query = entman.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class);
query.setParameter("idMedicalTest", idMedicalTest);
return query.getSingleResult();
}
@@ -239,8 +226,7 @@ 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();
@@ -251,13 +237,11 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
*
* @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) {
@@ -278,9 +262,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
public List<MedicalTestTO> loadMedicalTestForPatient(int patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
TypedQuery<MedicalTestJPA> query = entman.createQuery(
"SELECT q from MedicalTestJPA q where q.patient.id=:patientId order by q.id desc",
MedicalTestJPA.class);
TypedQuery<MedicalTestJPA> query = entman.createQuery("SELECT q from MedicalTestJPA q where q.patient.id=:patientId order by q.id desc", MedicalTestJPA.class);
query.setParameter("patientId", patientID);
@@ -304,18 +286,17 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
}
@Override
public List<MedicalTestTO> loadMedicalTestForFamilyDoctor(int familyDoctorID, int patientID) {
public List<MedicalTestTO> loadMedicalTestForFamilyDoctor(int familyDoctorID, Integer patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if (patientID > 0) {
if (patientID != null) {
extraQuery = " and q.patient.id=:patientID";
}
TypedQuery<MedicalTestJPA> query = entman
.createQuery("SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID "
+ extraQuery + " order by q.id desc", MedicalTestJPA.class);
if (patientID > 0) {
.createQuery("SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID " + extraQuery + " order by q.id desc", MedicalTestJPA.class);
if (patientID != null) {
query.setParameter("patientID", patientID);
}
query.setParameter("familyDoctorID", familyDoctorID);
@@ -330,19 +311,18 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
}
@Override
public List<MedicalTestTO> loadMedicalTestForSpecialistDoctor(int specialistDoctorID, int patientID) {
public List<MedicalTestTO> loadMedicalTestForSpecialistDoctor(int specialistDoctorID, Integer patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if (patientID > 0) {
if (patientID != null) {
extraQuery = " and q.patient.id=:patientID";
}
TypedQuery<MedicalTestJPA> query = entman
.createQuery("SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID "
+ extraQuery + " order by q.id desc", MedicalTestJPA.class);
.createQuery("SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID " + extraQuery + " order by q.id desc", MedicalTestJPA.class);
if (patientID > 0) {
if (patientID != null) {
query.setParameter("patientID", patientID);
}
query.setParameter("specialistDoctorID", specialistDoctorID);
@@ -356,42 +336,73 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
return medicalTests;
}
@Override
public List<PatientTO> loadPatientsForSpecialistDoctor(int specialistDoctorID) {
List<PatientTO> medicalTests = new ArrayList<PatientTO>();
public List<PatientTO> loadPatientsForSpecialistDoctor(int specialistDoctorID, String searchTerm, int pageNumber, int pageSize) {
String strQuery = "SELECT distinct q.patient from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID %s order by q.patient.name, q.patient.surname";
String strFilter = "";
if (searchTerm == null)
searchTerm = "";
else
searchTerm = Utils.normalizeTerm(searchTerm);
TypedQuery<PatientJPA> query = entman.createQuery(
"SELECT distinct q.patient from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID",
PatientJPA.class);
if (searchTerm.length() > 0) {
strFilter = "and lower(q.patient.name) LIKE :searchTerm OR lower(q.patient.surname) LIKE :searchTerm";
}
TypedQuery<PatientJPA> query = entman.createQuery(String.format(strQuery, strFilter), PatientJPA.class);
if (searchTerm.length() > 0)
query.setParameter("searchTerm", "%" + searchTerm + "%");
query.setParameter("specialistDoctorID", specialistDoctorID);
List<PatientJPA> allJPA = query.getResultList();
for (PatientJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1));
if (pageSize > 0) {
query.setFirstResult(pageNumber * pageSize);
query.setMaxResults(pageSize);
}
return medicalTests;
List<PatientJPA> allJPA = query.getResultList();
List<PatientTO> patsTO = new ArrayList<PatientTO>();
for (PatientJPA item : allJPA) {
patsTO.add(commonServices.getPOJOforPatientJPA(item, 1));
}
return patsTO;
}
@Override
public List<PatientTO> loadPatientsForFamilyDoctor(int familyDoctorID) {
List<PatientTO> medicalTests = new ArrayList<PatientTO>();
public List<PatientTO> loadPatientsForFamilyDoctor(int familyDoctorID, String searchTerm, int pageNumber, int pageSize) {
String strQuery = "SELECT distinct q.patient from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID %s order by q.patient.name, q.patient.surname";
TypedQuery<PatientJPA> query = entman.createQuery(
"SELECT distinct q.patient from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID",
PatientJPA.class);
String strFilter = "";
if (searchTerm == null)
searchTerm = "";
else
searchTerm = Utils.normalizeTerm(searchTerm);
if (searchTerm.length() > 0) {
strFilter = "and lower(q.patient.name) LIKE :searchTerm OR lower(q.patient.surname) LIKE :searchTerm";
}
TypedQuery<PatientJPA> query = entman.createQuery(String.format(strQuery, strFilter), PatientJPA.class);
if (searchTerm.length() > 0)
query.setParameter("searchTerm", "%" + searchTerm + "%");
query.setParameter("familyDoctorID", familyDoctorID);
List<PatientJPA> allJPA = query.getResultList();
for (PatientJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1));
if (pageSize > 0) {
query.setFirstResult(pageNumber * pageSize);
query.setMaxResults(pageSize);
}
return medicalTests;
List<PatientJPA> allJPA = query.getResultList();
List<PatientTO> patsTO = new ArrayList<PatientTO>();
for (PatientJPA item : allJPA) {
patsTO.add(commonServices.getPOJOforPatientJPA(item, 1));
}
return patsTO;
}
}