Merge branch 'master' into rorden
# Conflicts: # 1.sources/MyHealth/src/ejb/common/CommonFacadeBean.java
This commit is contained in:
@@ -244,11 +244,27 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
|
||||
return allFDTOs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Método que devuelve una lista con todos los pacientes registrados en el sistema de forma paginada.
|
||||
*
|
||||
* Si pageSize == 0 no se realiza paginación y se devuelven todos los resultados.
|
||||
*
|
||||
* @return Devuelve una Lista de PatientTO (Transfer Objects).
|
||||
*/
|
||||
public List<PatientTO> listPatientsPaged(int pageNumber, int pageSize) {
|
||||
return this.listPatientsFiltered(null, pageNumber, pageSize);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Método que devuelve una lista de pacientes que tienen una coincidencia parcial en el nombre o en los apellidos con el termino de búsqueda (searchTerm) especificado.
|
||||
*
|
||||
* Además permite la paginacción de datos. Si pageSize == 0 no se realiza paginación y se devuelven todos los resultados.
|
||||
*
|
||||
* Si serachTerm es nulo o cadena vacía entonces no se tiene en cuenta el parámetro y devuelven todos los registros existentes.
|
||||
*
|
||||
* @return Devuelve una Lista de PatientTO (Transfer Objects).
|
||||
*/
|
||||
public List<PatientTO> listPatientsFiltered(String searchTerm, int pageNumber, int pageSize) {
|
||||
String strQuery = "SELECT p FROM PatientJPA p %s order by p.name, p.surname";
|
||||
String strFilter = "";
|
||||
@@ -532,8 +548,7 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
/**
|
||||
* Método que recupera un médico especialista a partir de su NIF
|
||||
*
|
||||
* @return SpecialistDoctorTO (Transfer Object del objeto recuperado) o null si
|
||||
* no se encuentra el objeto buscado
|
||||
* @return SpecialistDoctorTO (Transfer Object del objeto recuperado) o null si el objeto JPA es nulo
|
||||
*/
|
||||
public SpecialistDoctorTO findSpecialistDoctorByNif(String searchedNIF) {
|
||||
TypedQuery<SpecialistDoctorJPA> query = entman.createQuery("from SpecialistDoctorJPA d where d.nif=:nif",
|
||||
@@ -552,14 +567,10 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
* Método que convierte un objecto de tipo QuestionJPA (JPA) a su equivalente
|
||||
* QuestionTO (Tranfer Object)
|
||||
*
|
||||
* El parámetro nestedProps es un valor entero que indica a que nivel de
|
||||
* profundidad se debe navegar a través de las propiedades relacionadas para
|
||||
* convertirlas de JPA a TO. Un valor 0 indica que no se convertirá ninguna
|
||||
* propiedad que tenga un entidad JPA relacionada (tendrá valor null en el
|
||||
* objeto TO).
|
||||
* El parámetro nestedProps es un valor entero que indica a que nivel de profundidad se debe navegar a través de las propiedades relacionadas para convertirlas de JPA a TO. Un
|
||||
* valor 0 indica que no se convertirá ninguna propiedad que tenga un entidad JPA relacionada (tendrá valor null en el objeto TO).
|
||||
*
|
||||
* @return QuestionTO (Transfer Object del objeto recuperado) o null si no se
|
||||
* encuentra el objeto buscado
|
||||
* @return QuestionTO (Transfer Object del objeto recuperado) o null si el objeto JPA es nulo
|
||||
*/
|
||||
public QuestionTO getPOJOforQuestionJPA(QuestionJPA qs, int nestedProps) {
|
||||
QuestionTO qsTO = null;
|
||||
@@ -581,6 +592,14 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
return qsTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Método que converite un objeto de tipo VisitJPA a su equivalente VisitTO (Transfer Object)
|
||||
*
|
||||
* El parámetro nestedProps es un valor entero que indica a que nivel de profundidad se debe navegar a través de las propiedades relacionadas para convertirlas de JPA a TO. Un
|
||||
* valor 0 indica que no se convertirá ninguna propiedad que tenga un entidad JPA relacionada (tendrá valor null en el objeto TO).
|
||||
*
|
||||
* @return VisitTO (Transfer Object del objeto recuperado) o null si el objeto JPA es nulo
|
||||
*/
|
||||
public VisitTO getPOJOforVisitJPA(VisitJPA vi, int nestedProps) {
|
||||
VisitTO qsTO = null;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ejb.systemAdmin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
@@ -12,6 +13,7 @@ import TO.FamilyDoctorTO;
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import common.Constants;
|
||||
import common.HashUtils;
|
||||
@@ -19,6 +21,7 @@ import common.UserType;
|
||||
import ejb.common.CommonFacadeLocal;
|
||||
import jpa.AdministratorJPA;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.PrimaryHealthCareCenterJPA;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -148,10 +151,81 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
|
||||
@Override
|
||||
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception {
|
||||
|
||||
MedicalSpecialtyJPA ms = new MedicalSpecialtyJPA(name, description);
|
||||
entman.persist(ms);
|
||||
|
||||
return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryHealthCareCenterTO updateHealthCareCenter(int id, String name, String location) throws Exception {
|
||||
PrimaryHealthCareCenterJPA ms = entman.find(PrimaryHealthCareCenterJPA.class, id);
|
||||
|
||||
if (ms == null) {
|
||||
throw new Exception("No se pueden actualizar los datos del CAP porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
|
||||
}
|
||||
|
||||
ms.setName(name);
|
||||
ms.setLocation(location);
|
||||
|
||||
entman.persist(ms);
|
||||
|
||||
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(ms);
|
||||
}
|
||||
|
||||
public PrimaryHealthCareCenterTO findHealthCareCenterByName(String searchedName) {
|
||||
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("from PrimaryHealthCareCenterJPA cap where cap.name=:name", PrimaryHealthCareCenterJPA.class);
|
||||
query.setMaxResults(1);
|
||||
query.setParameter("name", searchedName);
|
||||
|
||||
List<PrimaryHealthCareCenterJPA> results = query.getResultList();
|
||||
if (results.size() > 0)
|
||||
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(results.get(0));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteHealthCareCenter(int id) throws Exception {
|
||||
PrimaryHealthCareCenterJPA cap = entman.find(PrimaryHealthCareCenterJPA.class, id);
|
||||
|
||||
if (cap == null) {
|
||||
throw new Exception("No se puede borrar el CAP porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
|
||||
}
|
||||
|
||||
entman.remove(cap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryHealthCareCenterTO insertHealthCareCenter(String name, String location) throws Exception {
|
||||
PrimaryHealthCareCenterJPA cap = new PrimaryHealthCareCenterJPA(name, location);
|
||||
entman.persist(cap);
|
||||
|
||||
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(cap);
|
||||
}
|
||||
|
||||
public Long getCAPCount() {
|
||||
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from PrimaryHealthCareCenterJPA", Long.class);
|
||||
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
public List<PrimaryHealthCareCenterTO> listCAPsPaged(int pageNumber, int pageSize) {
|
||||
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("SELECT c from PrimaryHealthCareCenterJPA c order by c.name", PrimaryHealthCareCenterJPA.class);
|
||||
|
||||
if (pageSize > 0) {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
List<PrimaryHealthCareCenterJPA> allJPA = query.getResultList();
|
||||
List<PrimaryHealthCareCenterTO> caps = new ArrayList<PrimaryHealthCareCenterTO>();
|
||||
|
||||
for (PrimaryHealthCareCenterJPA item : allJPA) {
|
||||
caps.add(commonServices.getPOJOforPrimaryHealthCareCenterJPA(item));
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package ejb.systemAdmin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,4 +28,16 @@ public interface SystemAdminFacadeRemote {
|
||||
public void deleteSpecialty(int id) throws Exception;
|
||||
|
||||
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception;
|
||||
|
||||
public PrimaryHealthCareCenterTO updateHealthCareCenter(int id, String name, String location) throws Exception;
|
||||
|
||||
public PrimaryHealthCareCenterTO findHealthCareCenterByName(String name);
|
||||
|
||||
public void deleteHealthCareCenter(int id) throws Exception;
|
||||
|
||||
public PrimaryHealthCareCenterTO insertHealthCareCenter(String name, String location) throws Exception;
|
||||
|
||||
public Long getCAPCount();
|
||||
|
||||
public List<PrimaryHealthCareCenterTO> listCAPsPaged(int pageNumber, int pageSize);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package ejb.visit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
@@ -12,11 +13,13 @@ import javax.persistence.TypedQuery;
|
||||
|
||||
import TO.VisitTO;
|
||||
import ejb.common.CommonFacadeLocal;
|
||||
import jpa.PatientJPA;
|
||||
import jpa.VisitJPA;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author mark
|
||||
*
|
||||
@@ -31,7 +34,8 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
CommonFacadeLocal commonServices;
|
||||
|
||||
public Long getScheduledVisitsCount(int familyDoctorId, Date date) {
|
||||
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from VisitJPA v where v.date=:date and v.familyDoctor.id=:docId", Long.class);
|
||||
TypedQuery<Long> query = entman.createQuery(
|
||||
"SELECT count(1) from VisitJPA v where v.date=:date and v.familyDoctor.id=:docId", Long.class);
|
||||
query.setParameter("date", date);
|
||||
query.setParameter("docId", familyDoctorId);
|
||||
|
||||
@@ -39,7 +43,9 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
}
|
||||
|
||||
public List<VisitTO> listAllScheduledVisitsPaged(int familyDoctorId, Date date, int pageNumber, int pageSize) {
|
||||
TypedQuery<VisitJPA> query = entman.createQuery("SELECT v from VisitJPA v where v.date=:date and v.familyDoctor.id=:docId order by v.date, v.time", VisitJPA.class);
|
||||
TypedQuery<VisitJPA> query = entman.createQuery(
|
||||
"SELECT v from VisitJPA v where v.date=:date and v.familyDoctor.id=:docId order by v.date, v.time",
|
||||
VisitJPA.class);
|
||||
query.setParameter("date", date);
|
||||
query.setParameter("docId", familyDoctorId);
|
||||
|
||||
@@ -57,7 +63,7 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
|
||||
return listTO;
|
||||
}
|
||||
|
||||
|
||||
public Long getVisitsCount(Integer patientId, Date date) {
|
||||
String strQuery = "SELECT count(1) from VisitJPA v %s";
|
||||
String strFilter = "";
|
||||
@@ -80,7 +86,7 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
|
||||
public List<VisitTO> listVisitsPaged(Integer patientId, Date date, int pageNumber, int pageSize) {
|
||||
String strQuery = "SELECT v from VisitJPA v %s order by v.patient, v.date";
|
||||
String strFilter = "";
|
||||
@@ -93,7 +99,7 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
strFilter = "WHERE 1=1 " + strFilter;
|
||||
}
|
||||
strQuery = String.format(strQuery, strFilter);
|
||||
|
||||
|
||||
TypedQuery<VisitJPA> query = entman.createQuery(strQuery, VisitJPA.class);
|
||||
|
||||
if (patientId != null)
|
||||
@@ -105,7 +111,7 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
|
||||
List<VisitJPA> allJPA = query.getResultList();
|
||||
List<VisitTO> listTO = new ArrayList<VisitTO>();
|
||||
|
||||
@@ -116,7 +122,6 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
return listTO;
|
||||
}
|
||||
|
||||
|
||||
public VisitTO getVisit(int id) throws Exception {
|
||||
VisitJPA vi = entman.find(VisitJPA.class, id);
|
||||
if (vi == null) {
|
||||
@@ -125,4 +130,33 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
|
||||
return this.commonServices.getPOJOforVisitJPA(vi, 1);
|
||||
}
|
||||
|
||||
public void addResultToVisit(int id, String result) {
|
||||
VisitJPA vi = entman.find(VisitJPA.class, id);
|
||||
|
||||
vi.setResult(result);
|
||||
entman.persist(vi);
|
||||
}
|
||||
|
||||
public void removeVisit(int id) {
|
||||
VisitJPA vi = entman.find(VisitJPA.class, id);
|
||||
entman.remove(vi);
|
||||
}
|
||||
|
||||
public void updateVisit(int id, Date date, LocalTime time) {
|
||||
VisitJPA vi = entman.find(VisitJPA.class, id);
|
||||
vi.setDate(date);
|
||||
vi.setTime(time);
|
||||
entman.persist(vi);
|
||||
}
|
||||
|
||||
public VisitTO addVisit(int patientId, Date date, LocalTime time, String observations) {
|
||||
|
||||
PatientJPA pat = entman.find(PatientJPA.class, patientId);
|
||||
|
||||
VisitJPA vi = new VisitJPA(date, time, observations, "", pat, pat.getFamilyDoctor());
|
||||
entman.persist(vi);
|
||||
|
||||
return this.commonServices.getPOJOforVisitJPA(vi, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ejb.visit;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -8,9 +9,10 @@ import javax.ejb.Remote;
|
||||
import TO.VisitTO;
|
||||
|
||||
/**
|
||||
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para los clientes del EJB
|
||||
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
|
||||
* los clientes del EJB
|
||||
*
|
||||
* @author mark
|
||||
* @author alina
|
||||
*
|
||||
*/
|
||||
@Remote
|
||||
@@ -28,4 +30,13 @@ public interface VisitFacadeRemote {
|
||||
public List<VisitTO> listVisitsPaged(Integer patientId, Date date, int pageNumber, int pageSize);
|
||||
|
||||
public VisitTO getVisit(int id) throws Exception;
|
||||
|
||||
public void addResultToVisit(int id, String result);
|
||||
|
||||
public void removeVisit(int id);
|
||||
|
||||
public void updateVisit(int id, Date date, LocalTime time);
|
||||
|
||||
public VisitTO addVisit(int patientId, Date date, LocalTime time, String observations);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user