Merge branch 'master' into rorden

# Conflicts:
#	2.database/01.CreateTables.sql
#	2.database/02.Datos_prueba.sql
This commit is contained in:
Roberto Orden Erena
2019-12-26 12:25:32 +01:00
32 changed files with 946 additions and 201 deletions

View File

@@ -18,20 +18,21 @@ public class LoggedUserTO implements Serializable {
private String id;
private String password;
private String name;
private String displayName;
private UserType userType;
public LoggedUserTO() {
super();
}
public LoggedUserTO(String usrId, String usrName, String usrPwd, UserType usrType) {
public LoggedUserTO(String usrId, String usrName, String usrPwd, UserType usrType, String dispName) {
id = usrId;
name = usrName;
password = usrPwd;
userType = usrType;
displayName = dispName;
}
public String getId() {
return id;
}
@@ -64,4 +65,12 @@ public class LoggedUserTO implements Serializable {
this.userType = value;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
}

View File

@@ -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));
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -20,6 +20,7 @@ import org.omnifaces.util.Exceptions;
import common.UserType;
import common.Utils;
import managedbean.systemAdmin.LoginMBean;
@WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
public class AuthorizationFilter implements Filter {
@@ -46,12 +47,31 @@ public class AuthorizationFilter implements Filter {
HttpServletRequest req = null;
HttpServletResponse resp = null;
HttpSession ses = null;
// Si establecemos esta variable a true se realiza el autologin
// TODO: Eliminar esta variable al terminar el desarrollo
boolean Debug = false;
try {
req = (HttpServletRequest) request;
String reqURI = req.getRequestURI();
resp = (HttpServletResponse) response;
//TODO: Eliminar este código al terminar el desarrollo.
//Realizamos un login automatico (para agilizar el desarrollo.
if (Debug == true) {
ses = req.getSession(true);
if (SessionUtils.isLogedIn(ses) == false) {
LoginMBean login = new LoginMBean();
login.setUsername("PRO#100");
login.setPassword("asdf");
boolean result = login.autoLogin(ses);
}
}
ses = req.getSession(false);
// Para recursos publicos permitimos el acceso exista sesión o no.
@@ -85,7 +105,7 @@ public class AuthorizationFilter implements Filter {
authorized = true;
if (reqURI.indexOf("/systemAdmin/ListDoctorsByCenter") > 0)
authorized = true;
if (reqURI.indexOf("/visit/VisitView") > 0)
if (reqURI.indexOf("/visit/PatientVisitList") > 0)
authorized = true;
if (reqURI.indexOf("/visit/UpdateVisit") > 0)
authorized = true;
@@ -97,7 +117,7 @@ public class AuthorizationFilter implements Filter {
authorized = true;
if (reqURI.indexOf("/visit/UpdateVisit") > 0)
authorized = true;
if (reqURI.indexOf("/visit/CancelVisit") > 0)
if (reqURI.indexOf("/visit/PatientVisitList") > 0)
authorized = true;
if (reqURI.indexOf("/medicaltest/Questions") > 0)
authorized = true;

View File

@@ -127,17 +127,16 @@ public class ManagedBeanBase {
String strType = "";
if (ex.getClass().equals(ViewExpiredException.class)) {
// Sessión expired
// Sessión expirada
strType = "expired";
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Su sesión ha caducado", "Su sesión ha caducado, vuelva a logarse en el sistema.");
} else {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Se ha producido un error inesperado", "Descripción del error: " + ex.getLocalizedMessage());
this.addFacesMessageKeep(FacesMessage.SEVERITY_ERROR, "Se ha producido un error inesperado", "Descripción del error: " + ex.getLocalizedMessage());
}
try {
ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
ctx.redirect(ctx.getApplicationContextPath() + "/error.xhtml?type=" + strType);
} catch (IOException e) {
// TODO Auto-generated catch block

View File

@@ -56,13 +56,13 @@ public class MenuMBean implements Serializable {
subMenu = new DefaultSubMenu("Visitas", "fa fa-calendar");
if (tipoUsuario == UserType.PATIENT)
subMenu.addElement(createMenuItem("Solicitar nueva", "fa fa-calendar-o", "/visit/VisitView", null));
subMenu.addElement(createMenuItem("Solicitar nueva", "fa fa-calendar-o", "/visit/AddVisit", null));
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.ADMINISTRATOR)
subMenu.addElement(createMenuItem("Modificar fecha/hora", "fa fa-briefcase", "/visit/VisitView", null));
subMenu.addElement(createMenuItem("Modificar fecha/hora", "fa fa-briefcase", "/visit/PatientVisitList", null));
if (tipoUsuario == UserType.PATIENT)
subMenu.addElement(createMenuItem("Anular visita", "fa fa-remove", "/visit/VisitView", null));
subMenu.addElement(createMenuItem("Anular visita", "fa fa-remove", "/visit/PatientVisitList", null));
if (tipoUsuario == UserType.FAMILY_DOCTOR)
subMenu.addElement(createMenuItem("Añadir resultado", "fa fa-align-left", "/visit/VisitView", null));
subMenu.addElement(createMenuItem("Añadir resultado", "fa fa-align-left", "/visit/VisitList", null));
if (tipoUsuario == UserType.FAMILY_DOCTOR)
subMenu.addElement(createMenuItem("Ver agenda del día", "fa fa-repeat", "/visit/VisitList", null));

View File

@@ -24,7 +24,7 @@ public class SessionUtils {
else
return null;
}
public static HttpSession getSession() {
return getSession(false);
}
@@ -38,12 +38,18 @@ public class SessionUtils {
}
public static void createOrUpdateSession(LoggedUserTO usr) {
HttpSession ses = getSession(true);
createOrUpdateSession(getSession(true), usr);
}
public static void createOrUpdateSession(HttpSession ses, LoggedUserTO usr) {
if (ses == null)
return;
ses.setAttribute(SessionUtils.SESSION_VAR_USERNAME, usr.getName());
ses.setAttribute(SessionUtils.SESSION_VAR_USERID, usr.getId());
ses.setAttribute(SessionUtils.SESSION_VAR_USERTYPE, usr.getUserType());
ses.setAttribute(SessionUtils.SESSION_VAR_USER, usr);
}
}
public static void DestroySession() {
HttpSession ses = getSession();
@@ -77,6 +83,16 @@ public class SessionUtils {
return "";
}
public static String getUserDisplayName() {
HttpSession session = getSession();
if (session != null && session.getAttribute(SessionUtils.SESSION_VAR_USER) != null) {
LoggedUserTO usr = LoggedUserTO.class.cast(session.getAttribute(SessionUtils.SESSION_VAR_USER));
return usr.getDisplayName();
} else
return "";
}
public static UserType getUserType() {
return getUserType(getSession());
}

View File

@@ -100,6 +100,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
case ADMINISTRATOR:
// TODO: Recuperar usuario administrador para editar su perfil ¿?
// this.getRemoteManagerProfile().retrievePatient(usr.getId());
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Usuario sin perfil", "Usted es un usuario de tipo administrador y no puede editar su perfil de usuario.");
break;
}
}
@@ -300,19 +301,19 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
case PATIENT:
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
this.setPatientData(pat);
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType);
usr = new LoggedUserTO(pat.getId().toString(), pat.getName(), pat.getPassword(), this.userType, pat.getDisplayName());
break;
case FAMILY_DOCTOR:
FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
this.setFamilyDoctorData(fd);
usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType);
usr = new LoggedUserTO(fd.getId().toString(), fd.getName(), fd.getPassword(), this.userType, fd.getDisplayName());
break;
case SPECIALIST_DOCTOR:
SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty);
this.setSpecialistDoctorData(sd);
usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType);
usr = new LoggedUserTO(sd.getId().toString(), sd.getName(), sd.getPassword(), this.userType, sd.getDisplayName());
break;
case ADMINISTRATOR:

View File

@@ -3,6 +3,7 @@ package managedbean.systemAdmin;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Named;
import javax.servlet.http.HttpSession;
import org.primefaces.PrimeFaces;
@@ -50,17 +51,35 @@ public class LoginMBean extends ManagedBeanBase {
this.addFacesMessageKeep(FacesMessage.SEVERITY_INFO, "Login correcto", "Bienvenido " + usr.getName());
viewRedirect = "/home?faces-redirect=true";
} else
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "El usuario o la contraseña son incorrectos");
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "El usuario o la contraseña son incorrectos");
} catch (Exception ex) {
this.addFacesMessage(FacesMessage.SEVERITY_FATAL, "Error fatal", ex.getMessage());
}
} else
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "El usuario o la contraseña son incorrectos");
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "El usuario o la contraseña son incorrectos");
PrimeFaces.current().ajax().addCallbackParam("loggedIn", loggedIn);
return viewRedirect;
}
/**
* Realiza un login semi-automatico. Por ejemplo desde el filtro de autorización.
* Se debe utilizar con propositos de depuración, para evitar realizar el login manual.
*
* @param ses
*/
public boolean autoLogin(HttpSession ses) {
//TODO: Eliminar este metodo al terminar el desarrollo.
boolean bResult = false;
LoggedUserTO usr = this.getRemoteManagerSystemAdmin().login(username, password);
if (usr != null) {
SessionUtils.createOrUpdateSession(ses, usr);
bResult = true;
}
return bResult;
}
// logout event, invalidate session
public String logout() {

View File

@@ -7,12 +7,14 @@ import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.inject.Named;
import javax.persistence.PersistenceException;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import common.Constants;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
import managedbean.common.ValidationUtils;
@Named("ManageSpecialities")
@RequestScoped
@@ -95,20 +97,21 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
public void saveData() {
int error = 0;
if (this.medicalSpecialty.getName() == null) {
if (this.medicalSpecialty.getName() == null || this.medicalSpecialty.getName().trim().length() == 0) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre de especialidad.");
error++;
}
if (this.medicalSpecialty.getDescription() == null) {
if (this.medicalSpecialty.getDescription() == null || this.medicalSpecialty.getDescription().trim().length() == 0) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción.");
error++;
}
if (error == 0) {
try {
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().updateSpecialtyData(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().getSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
this.setSpecialtyData(ms);
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
} catch (Exception e) {
this.manageException(e);
}
@@ -129,8 +132,9 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
if (error == 0) {
try {
this.getRemoteManagerSystemAdmin().deleteSpecialtyData(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
this.getRemoteManagerSystemAdmin().deleteSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los especialidad se ha borrado", "Los datos de la especialidad se han borrado correctamente.");
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
} catch (Exception e) {
this.manageException(e);
}
@@ -148,12 +152,18 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción.");
error++;
}
if (this.getRemoteManagerSystemAdmin().findSpecialtyByName(name) != null) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad ya existente", "La especialidad ya se encuentra en la base de datos");
error++;
}
if (error == 0) {
try {
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().insertSpecialtyData(name, description);
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().insertSpecialty(name, description);
this.setSpecialtyData(ms);
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
} catch (Exception e) {
this.manageException(e);
}

View File

@@ -0,0 +1,122 @@
package managedbean.visit;
import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import TO.FamilyDoctorTO;
import TO.PatientTO;
import TO.VisitTO;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("AddVisit")
@RequestScoped
public class AddVisitMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Date date;
private Time time;
private String observations;
private String result;
private String patientDisplayName;
private String familyDoctorDisplayName;
private PatientTO patient;
private FamilyDoctorTO familyDoctor;
public AddVisitMBean() {
}
@PostConstruct
public void init() {
// El usuario actual es un medico de familia, recuperamos su Id de la sessión actual
Integer patientId = Integer.valueOf(SessionUtils.getUserId());
this.patient = this.getRemoteManagerCommon().findPatientById(patientId);
this.familyDoctor = this.patient.getFamilyDoctor();
this.date = new Date();
}
public void saveData() {
// TODO: Añadir la nueva visita a la BBDD
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Time getTime() {
return time;
}
public void setTime(Time time) {
this.time = time;
}
public String getObservations() {
return observations;
}
public void setObservations(String observations) {
this.observations = observations;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getPatientDisplayName() {
return patientDisplayName;
}
public String getFamilyDoctorDisplayName() {
return familyDoctorDisplayName;
}
public PatientTO getPatient() {
return patient;
}
public void setPatient(PatientTO patient) {
this.patient = patient;
}
public FamilyDoctorTO getFamilyDoctor() {
return familyDoctor;
}
public void setFamilyDoctor(FamilyDoctorTO familyDoctor) {
this.familyDoctor = familyDoctor;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}

View File

@@ -0,0 +1,106 @@
package managedbean.visit;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import TO.FamilyDoctorTO;
import TO.PatientTO;
import TO.VisitTO;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("PatientVisitList")
@ViewScoped
public class PatientVisitListMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private PatientTO patient;
private Integer patientId;
private LazyDataModel<VisitTO> lazyDataModelVisitList;
private Date selectedDate;
public PatientVisitListMBean() {
}
@PostConstruct
public void init() {
// Si el usuario es un paciente listamos las visitas de ese paciente, si es admnistrador listamos todas.
switch (SessionUtils.getUserType())
{
case ADMINISTRATOR:
this.patientId = null;
this.setPatient(null);
this.selectedDate = new Date();
break;
case PATIENT:
this.patientId = Integer.valueOf(SessionUtils.getUserId());
this.setPatient(this.getRemoteManagerCommon().findPatientById(patientId));
this.selectedDate = null;
break;
case FAMILY_DOCTOR:
case SPECIALIST_DOCTOR:
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Acesso denegado", "Su perfil de usuario no está autorizado acceder a esta página.");
return;
}
this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() {
private static final long serialVersionUID = 1L;
@Override
public List<VisitTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
Long totalRowCount = getRemoteManagerVisit().getVisitsCount(patientId, selectedDate);
this.setRowCount(totalRowCount.intValue());
return getRemoteManagerVisit().listVisitsPaged(patientId, selectedDate, (first / pageSize), pageSize);
}
};
}
public void removeVisit(Integer visitId) throws IOException {
// TODO: Eliminar visita de la BBDD
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Visita eliminada", String.format("La visita con Id: %d se ha eliminado correctamente", visitId));
}
public void editVisit(Integer visitId) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect("VisitView.xhtml?id=" + visitId.toString());
}
public LazyDataModel<VisitTO> getLazyDataModelVisitList() {
return lazyDataModelVisitList;
}
public void showData() {
}
public Date getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;
}
public PatientTO getPatient() {
return patient;
}
public void setPatient(PatientTO patient) {
this.patient = patient;
}
}

View File

@@ -1,12 +1,14 @@
package managedbean.visit;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
@@ -17,12 +19,13 @@ import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@Named("VisitList")
@RequestScoped
@ViewScoped
public class VisitListMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private int familyDoctorId;
private String familyDoctorDisplayName;
private LazyDataModel<VisitTO> lazyDataModelVisitList;
private Date selectedDate;
@@ -33,6 +36,8 @@ public class VisitListMBean extends ManagedBeanBase implements Serializable {
public void init() {
// El usuario actual es un medico de familia, recuperamos su Id de la sessión actual
this.familyDoctorId = Integer.valueOf(SessionUtils.getUserId());
this.familyDoctorDisplayName = SessionUtils.getUserDisplayName();
this.selectedDate = new Date();
this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() {
@@ -40,7 +45,7 @@ public class VisitListMBean extends ManagedBeanBase implements Serializable {
@Override
public List<VisitTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
Long totalRowCount = getRemoteManagerMedicalTest().getPendingQuestionsCount(familyDoctorId);
Long totalRowCount = getRemoteManagerVisit().getScheduledVisitsCount(familyDoctorId, selectedDate);
this.setRowCount(totalRowCount.intValue());
return getRemoteManagerVisit().listAllScheduledVisitsPaged(familyDoctorId, selectedDate, (first / pageSize), pageSize);
@@ -51,13 +56,12 @@ public class VisitListMBean extends ManagedBeanBase implements Serializable {
public LazyDataModel<VisitTO> getLazyDataModelVisitList() {
return lazyDataModelVisitList;
}
public void saveData() {
}
public void showData() {
}
public void showVisit(Integer visitId) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect("VisitView.xhtml?id=" + visitId.toString());
}
public Date getSelectedDate() {
@@ -67,4 +71,8 @@ public class VisitListMBean extends ManagedBeanBase implements Serializable {
public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;
}
public String getFamilyDoctorDisplayName() {
return familyDoctorDisplayName;
}
}

View File

@@ -1,28 +1,126 @@
package managedbean.visit;
import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import TO.FamilyDoctorTO;
import TO.PatientTO;
import TO.VisitTO;
import managedbean.common.ManagedBeanBase;
@Named("VisitMBean")
@Named("VisitView")
@RequestScoped
public class VisitMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Date date;
private Time time;
private String observations;
private String result;
private PatientTO patient;
private FamilyDoctorTO familyDoctor;
public VisitMBean() {
}
@PostConstruct
public void init() {
// Inicialización de variables y propiedades van aquí.
FacesContext context = FacesContext.getCurrentInstance();
// Como realizar llamadas al EJB Remoto
// this.getRemoteManagerSystemAdmin().MetodoEJB
Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();
VisitTO vi = null;
try {
// Parámetro con el "name" de la especialidad a editar.
int id = Integer.valueOf(requestParams.get("id").toString());
vi = this.getRemoteManagerVisit().getVisit(id);
} catch (Exception e) {
this.manageException(e);
}
if (vi != null) {
this.date = vi.getDate();
this.time = vi.getTime();
this.observations = vi.getObservations();
this.result = vi.getResult();
this.patient = vi.getPatient();
this.familyDoctor = vi.getFamilyDoctor();
} else {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Identificador de visita no válido", "No se ha podido recuperar el identificador de visita especificado. Por favor, vuelva a intentarlo seleccionando de nuevo la visita.");
}
}
public void saveData() {
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Time getTime() {
return time;
}
public void setTime(Time time) {
this.time = time;
}
public String getObservations() {
return observations;
}
public void setObservations(String observations) {
this.observations = observations;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public PatientTO getPatient() {
return patient;
}
public void setPatient(PatientTO patient) {
this.patient = patient;
}
public FamilyDoctorTO getFamilyDoctor() {
return familyDoctor;
}
public void setFamilyDoctor(FamilyDoctorTO familyDoctor) {
this.familyDoctor = familyDoctor;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}