Merge branch 'master' into rorden
# Conflicts: # 2.database/01.CreateTables.sql # 2.database/02.Datos_prueba.sql
This commit is contained in:
@@ -481,19 +481,19 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
return qsTO;
|
||||
}
|
||||
|
||||
public VisitTO getPOJOforVisitJPA(VisitJPA qs, int nestedProps) {
|
||||
public VisitTO getPOJOforVisitJPA(VisitJPA vi, int nestedProps) {
|
||||
VisitTO qsTO = null;
|
||||
|
||||
if (qs != null) {
|
||||
if (vi != null) {
|
||||
FamilyDoctorJPA fd = null;
|
||||
PatientJPA pat = null;
|
||||
if (nestedProps > 0) {
|
||||
fd = qs.getFamilyDoctor();
|
||||
pat = qs.getPatient();
|
||||
fd = vi.getFamilyDoctor();
|
||||
pat = vi.getPatient();
|
||||
}
|
||||
|
||||
nestedProps--;
|
||||
qsTO = new VisitTO(qs.getId(), qs.getDate(), qs.getTime(), qs.getObservations(), qs.getResult(), this.getPOJOforFamilyDoctorJPA(fd, nestedProps),
|
||||
qsTO = new VisitTO(vi.getId(), vi.getDate(), vi.getTime(), vi.getObservations(), vi.getResult(), this.getPOJOforFamilyDoctorJPA(fd, nestedProps),
|
||||
this.getPOJOforPatientJPA(pat, nestedProps));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package ejb.systemAdmin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import TO.FamilyDoctorTO;
|
||||
import TO.LoggedUserTO;
|
||||
@@ -33,29 +36,23 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
CommonFacadeLocal commonServices;
|
||||
|
||||
/**
|
||||
* Si la autenticación no es correcgta devuelve null, sino devuelve un POJO con
|
||||
* datos del usuario logeado.
|
||||
* Si la autenticación no es correcgta devuelve null, sino devuelve un POJO con datos del usuario logeado.
|
||||
*
|
||||
* La autenticación se realiza en 2 pasos:
|
||||
*
|
||||
* Paso 1. Se intenta localizar un registro de usuario, por orden:
|
||||
*
|
||||
* a. Primero Paciente, si el identificador comienza por los caracteres
|
||||
* correctos.
|
||||
* a. Primero Paciente, si el identificador comienza por los caracteres correctos.
|
||||
*
|
||||
* b.Después médico de familia, si el identificador es de profesional
|
||||
*
|
||||
* c. Si no lo localizamos buscamos el identificador en la tabla de médicos
|
||||
* especialistas (el identificador es de profesional)
|
||||
* c. Si no lo localizamos buscamos el identificador en la tabla de médicos especialistas (el identificador es de profesional)
|
||||
*
|
||||
* d. Si no hemos localizado aún al usuario, lo buscamos en la tabla de
|
||||
* administradores, aún cuando el identificador comience por cualquier carácter
|
||||
* (podría ser una dirección de email que comienza por caracteres del
|
||||
* identificaodr de paciente o profesional)
|
||||
* d. Si no hemos localizado aún al usuario, lo buscamos en la tabla de administradores, aún cuando el identificador comience por cualquier carácter (podría ser una dirección
|
||||
* de email que comienza por caracteres del identificaodr de paciente o profesional)
|
||||
*
|
||||
* Paso 2. Si hemos localizado un registro de usuario, verificamos si el
|
||||
* password recibido coincide con el de la base de datos, en tal caso la
|
||||
* autenticación se compelta y es correcta.
|
||||
* Paso 2. Si hemos localizado un registro de usuario, verificamos si el password recibido coincide con el de la base de datos, en tal caso la autenticación se compelta y es
|
||||
* correcta.
|
||||
*/
|
||||
public LoggedUserTO login(String userCode, String pwd) {
|
||||
LoggedUserTO usr = null;
|
||||
@@ -65,7 +62,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
// login.
|
||||
PatientTO pat = this.commonServices.findPatientByCode(userCode);
|
||||
if (pat != null) {
|
||||
usr = new LoggedUserTO(String.valueOf(pat.getId()), pat.getName(), pat.getPassword(), UserType.PATIENT);
|
||||
usr = new LoggedUserTO(String.valueOf(pat.getId()), pat.getName(), pat.getPassword(), UserType.PATIENT, pat.getDisplayName());
|
||||
}
|
||||
} else if (userCode.startsWith(Constants.PROFESSIONAL_NUMBER_PREFIX)) {
|
||||
// Si el identificador de usuario es de tipo profesional, intentamos realizar el
|
||||
@@ -73,13 +70,13 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
FamilyDoctorTO fd = this.commonServices.findFamilyDoctorByCode(userCode);
|
||||
|
||||
if (fd != null) {
|
||||
usr = new LoggedUserTO(String.valueOf(fd.getId()), fd.getName(), fd.getPassword(), UserType.FAMILY_DOCTOR);
|
||||
usr = new LoggedUserTO(String.valueOf(fd.getId()), fd.getName(), fd.getPassword(), UserType.FAMILY_DOCTOR, fd.getDisplayName());
|
||||
} else {
|
||||
// No era un código de médico de familia, intenamos logearlo como especialista
|
||||
SpecialistDoctorTO sd = this.commonServices.findSpecialistDoctorByCode(userCode);
|
||||
|
||||
if (sd != null) {
|
||||
usr = new LoggedUserTO(String.valueOf(sd.getId()), sd.getName(), sd.getPassword(), UserType.SPECIALIST_DOCTOR);
|
||||
usr = new LoggedUserTO(String.valueOf(sd.getId()), sd.getName(), sd.getPassword(), UserType.SPECIALIST_DOCTOR, sd.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +90,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
AdministratorJPA adm = entman.find(AdministratorJPA.class, userCode);
|
||||
|
||||
if (adm != null) {
|
||||
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR);
|
||||
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR, adm.getEmail());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +108,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MedicalSpecialtyTO updateSpecialtyData(int id, String name, String description) throws Exception {
|
||||
public MedicalSpecialtyTO getSpecialty(int id, String name, String description) throws Exception {
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id);
|
||||
|
||||
if (ms == null) {
|
||||
@@ -125,9 +122,21 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
|
||||
return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms);
|
||||
}
|
||||
|
||||
|
||||
public MedicalSpecialtyTO findSpecialtyByName(String searchedName) {
|
||||
TypedQuery<MedicalSpecialtyJPA> query = entman.createQuery("from MedicalSpecialtyJPA ms where ms.name=:name", MedicalSpecialtyJPA.class);
|
||||
query.setMaxResults(1);
|
||||
query.setParameter("name", searchedName);
|
||||
|
||||
List<MedicalSpecialtyJPA> results = query.getResultList();
|
||||
if (results.size() > 0)
|
||||
return this.commonServices.getPOJOforMedicalSpecialtyJPA(results.get(0));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSpecialtyData(int id, String name, String description) throws Exception {
|
||||
public void deleteSpecialty(int id, String name, String description) throws Exception {
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id);
|
||||
|
||||
if (ms == null) {
|
||||
@@ -138,7 +147,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MedicalSpecialtyTO insertSpecialtyData(String name, String description) throws Exception {
|
||||
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception {
|
||||
|
||||
MedicalSpecialtyJPA ms = new MedicalSpecialtyJPA(name, description);
|
||||
entman.persist(ms);
|
||||
|
||||
@@ -4,6 +4,7 @@ import javax.ejb.Remote;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -18,9 +19,11 @@ public interface SystemAdminFacadeRemote {
|
||||
|
||||
public LoggedUserTO login(String id, String pwd);
|
||||
|
||||
public MedicalSpecialtyTO updateSpecialtyData(int id, String name, String description) throws Exception;
|
||||
public MedicalSpecialtyTO getSpecialty(int id, String name, String description) throws Exception;
|
||||
|
||||
public void deleteSpecialtyData(int id, String name, String description) throws Exception;
|
||||
public MedicalSpecialtyTO findSpecialtyByName(String name);
|
||||
|
||||
public MedicalSpecialtyTO insertSpecialtyData(String name, String description) throws Exception;
|
||||
public void deleteSpecialty(int id, String name, String description) throws Exception;
|
||||
|
||||
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception;
|
||||
}
|
||||
@@ -11,9 +11,14 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import TO.VisitTO;
|
||||
import common.HashUtils;
|
||||
import common.QuestionStatus;
|
||||
import common.Utils;
|
||||
import ejb.common.CommonFacadeLocal;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.QuestionJPA;
|
||||
import jpa.SpecialistDoctorJPA;
|
||||
import jpa.VisitJPA;
|
||||
|
||||
/**
|
||||
@@ -39,7 +44,7 @@ public class VisitFacadeBean implements VisitFacadeRemote {
|
||||
|
||||
return query.getSingleResult();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
query.setParameter("date", date);
|
||||
@@ -59,5 +64,70 @@ 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 = "";
|
||||
if (patientId != null)
|
||||
strFilter = " and v.patient.id=:patientId ";
|
||||
if (date != null)
|
||||
strFilter += " and v.date=:date ";
|
||||
|
||||
if (strFilter.length() > 0) {
|
||||
strQuery = String.format(strQuery, "WHERE 1=1 " + strFilter);
|
||||
}
|
||||
|
||||
TypedQuery<Long> query = entman.createQuery(strQuery, Long.class);
|
||||
|
||||
if (patientId != null)
|
||||
query.setParameter("patientId", patientId);
|
||||
if (date != null)
|
||||
query.setParameter("date", date);
|
||||
|
||||
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 = "";
|
||||
if (patientId != null)
|
||||
strFilter = " and v.patient.id=:patientId ";
|
||||
if (date != null)
|
||||
strFilter += " and v.date=:date ";
|
||||
|
||||
if (strFilter.length() > 0) {
|
||||
strQuery = String.format(strQuery, "WHERE 1=1 " + strFilter);
|
||||
}
|
||||
|
||||
TypedQuery<VisitJPA> query = entman.createQuery(strQuery, VisitJPA.class);
|
||||
|
||||
if (patientId != null)
|
||||
query.setParameter("patientId", patientId);
|
||||
if (date != null)
|
||||
query.setParameter("date", date);
|
||||
|
||||
if (pageSize > 0) {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
List<VisitJPA> allJPA = query.getResultList();
|
||||
List<VisitTO> listTO = new ArrayList<VisitTO>();
|
||||
|
||||
for (VisitJPA item : allJPA) {
|
||||
listTO.add(commonServices.getPOJOforVisitJPA(item, 1));
|
||||
}
|
||||
|
||||
return listTO;
|
||||
}
|
||||
|
||||
|
||||
public VisitTO getVisit(int id) throws Exception {
|
||||
VisitJPA vi = entman.find(VisitJPA.class, id);
|
||||
if (vi == null) {
|
||||
throw new Exception("No se encuentra la visita con identificador: " + String.valueOf(id));
|
||||
}
|
||||
|
||||
return this.commonServices.getPOJOforVisitJPA(vi, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,10 @@ public interface VisitFacadeRemote {
|
||||
public Long getScheduledVisitsCount(int familyDoctorId, Date date);
|
||||
|
||||
public List<VisitTO> listAllScheduledVisitsPaged(int familyDoctorId, Date date, int pageNumber, int pageSize);
|
||||
|
||||
public Long getVisitsCount(Integer patientId, Date date);
|
||||
|
||||
public List<VisitTO> listVisitsPaged(Integer patientId, Date date, int pageNumber, int pageSize);
|
||||
|
||||
public VisitTO getVisit(int id) throws Exception;
|
||||
}
|
||||
Reference in New Issue
Block a user