This commit is contained in:
Roberto Orden Erena
2019-12-09 21:53:51 +01:00
11 changed files with 202 additions and 94 deletions

View File

@@ -6,31 +6,67 @@
<ui:composition template="../header.xhtml">
<ui:define name="content">
<h:form id="frmRegisterUser">
<h:form id="frmChangePHCC">
<p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" />
<p:panel id="DatosPersonales" header="Cambiar el Centro de Atención Primaria">
<p:panel id="badProfile" rendered="#{not home.familyDoctor}">
<div class="ui-g-3 ui-md-3" />
<div class="ui-g-6 ui-md-6">
<p:panel id="badProfileInfo" header="Perfil de usuario incorrecto para realizar acción">
<div class="ui-g ui-fluid">
<div class="ui-g-2 ui-md-2">
<p:outputLabel value="Campo1:" for="campo1" />
<div class="ui-g-12">
Su perfil de usuario no permite que pueda cambiar su Centro de Atención Primaria asignado.<br /> Si cree que no debería estar viendo esta página y que se trata de un
error, por favor, contacte con el soporte de la aplicación para obtener asistencia tecnica.
</div>
<div class="ui-g-3"></div>
<div class="ui-g-6">
<p:button value="Ir a la página principal" outcome="/home" icon="pi pi-home" />
</div>
<div class="ui-g-3"></div>
</div>
</p:panel>
</div>
<div class="ui-g-3 ui-md-3" />
</p:panel>
<p:panel id="PanelPHC" header="Cambiar centro de antención primaria asignado" rendered="#{home.familyDoctor}">
<div class="ui-g ui-fluid">
<div class="ui-g-4 ui-md-4">
<p:outputLabel value="Centro de antención primaria actualmente asignado:" />
</div>
<div class="ui-g-4 ui-md-4">
<p:inputText id="campo1" value="123 asdf 123" required="true" requiredMessage="Por favor, indque el campo 1" />
<p:outputLabel id="lblCurrentCenter" value="#{ChangeCAP.currentCenter.displayDescription}" />
</div>
<div class="ui-g-6 ui-md-6">
<p:message for="campo1" display="text" />
<div class="ui-g-4 ui-md-4" />
<div class="ui-g-4 ui-md-4">
<p:outputLabel value="Nuevo centro de atención primaria:" for="newCenter" />
</div>
<div class="ui-g-4 ui-md-4">
<p:selectOneMenu id="newCenter" value="#{ChangeCAP.newCenter}" converter="omnifaces.SelectItemsConverter" required="true"
requiredMessage="Por favor, selecciona un nuevo centro de antención primaria">
<f:selectItem itemLabel="Seleccione un nuevo centro de antención primario..." itemValue="" noSelectionOption="true" />
<f:selectItems value="#{ChangeCAP.phcList}" var="phc" itemLabel="#{phc.displayDescription}" itemValue="#{phc}" />
<p:column headerText="Nombre"><h:outputText value="#{phc.name}" /></p:column>
<p:column headerText="Localización"><h:outputText value="#{phc.location}" /></p:column>
</p:selectOneMenu>
</div>
<div class="ui-g-4 ui-md-4">
<p:message for="newCenter" />
</div>
<div class="ui-g-12 ui-g-nopad">
<div class="ui-g-4 ui-md-4"></div>
<div class="ui-g-4 ui-md-4" />
<div class="ui-g-2 ui-md-2 ">
<p:commandButton validateClient="true" value="Guardar" update="mesgs" icon="pi pi-check" />
<p:commandButton validateClient="true" value="Guardar" update="frmChangePHCC" action="#{ChangeCAP.saveData}" icon="pi pi-check" />
</div>
<div class="ui-g-2 ui-md-2">
<p:button value="Volver" outcome="/home" icon="pi pi-home" />
</div>
<div class="ui-g-4 ui-md-4"></div>
<div class="ui-g-4 ui-md-4" />
</div>
</div>
</p:panel>
</h:form>
</ui:define>

View File

@@ -6,21 +6,6 @@
<ui:composition template="../header.xhtml">
<ui:define name="content">
<h:outputScript>
function handleRequest(xhr, status, args) {
if(args.specs) {
$('#panCentros').slideUp();
$('#panEspecialidades').slideDown();
}
else if (args.caps) {
$('#panEspecialidades').slideUp();
$('#panCentros').slideDown();
} else {
$('#panCentros').slideUp();
$('#panEspecialidades').slideUp();
}
}
</h:outputScript>
<h:form id="frmUpdateProfile">
<p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" />
@@ -42,7 +27,6 @@
<p:panel id="DatosPersonales" header="Actualizar datos personales">
<div class="ui-g ui-fluid">
<div class="ui-g-2 ui-md-2">
<h:outputLabel value="value = 10" rendered="#{row == 10}" />
<p:outputLabel value="Código de Identificación Personal (CIP):" rendered="#{UpdateProfile.patient}" for="id" />
<p:outputLabel value="Número de Profesional:" rendered="#{UpdateProfile.familyDoctor or UpdateProfile.specialistDoctor}" for="id" />
</div>
@@ -161,7 +145,7 @@
<div class="ui-g-12 ui-g-nopad">
<div class="ui-g-4 ui-md-4"></div>
<div class="ui-g-2 ui-md-2 ">
<p:commandButton validateClient="true" value="Guardar" update="mesgs" action="#{UpdateProfile.saveData}" icon="pi pi-check" />
<p:commandButton validateClient="true" value="Guardar" update="frmUpdateProfile" action="#{UpdateProfile.saveData}" icon="pi pi-check" />
</div>
<div class="ui-g-2 ui-md-2">
<p:button value="Volver" outcome="/home" icon="pi pi-home" />

View File

@@ -42,6 +42,10 @@ public class MedicalSpecialtyTO implements Serializable {
this.description = description;
}
public String getDisplayDescription() {
return String.format("[%s] %s", this.name, this.description);
}
@Override
public String toString() {
return String.format("%s[name=%s]", getClass().getSimpleName(), getName());

View File

@@ -43,8 +43,12 @@ public class PrimaryHealthCareCenterTO implements Serializable {
this.location = description;
}
public String getDisplayDescription() {
return String.format("[%s] %s", this.name, this.location);
}
@Override
public String toString() {
return String.format("%s[name=%s]", getClass().getSimpleName(), getName());
return String.format("%s[name=%s]", getClass().getSimpleName(), this.getName());
}
}

View File

@@ -4,7 +4,7 @@ public enum UserType {
PATIENT("Paciente"),
FAMILY_DOCTOR("Médico de familia"),
SPECIALIST_DOCTOR("Médico especialista"),
ADMINISTRADOR("Administrador");
ADMINISTRATOR("Administrador");
private String userTypename;

View File

@@ -94,7 +94,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
// First try to login as Admin
AdministratorJPA adm = entman.find(AdministratorJPA.class, id);
if (adm != null) {
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRADOR);
usr = new LoggedUserTO(adm.getEmail(), adm.getEmail(), adm.getPassword(), UserType.ADMINISTRATOR);
} else {
try {
int iId = Integer.parseInt(id);

View File

@@ -41,7 +41,7 @@ public class MenuMBean implements Serializable {
tipoUsuario = SessionUtils.getUserType();
// Administracion Sistema
if (tipoUsuario == UserType.ADMINISTRADOR) {
if (tipoUsuario == UserType.ADMINISTRATOR) {
subMenu = new DefaultSubMenu("Administración del sistema", "pi pi-cog");
subMenu.addElement(createMenuItem("Gestionar especialidades", "pi pi-calendar", "/systemAdmin/ManageSpecialties", null));
@@ -55,12 +55,12 @@ public class MenuMBean implements Serializable {
}
// Visitas
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.ADMINISTRADOR || tipoUsuario == UserType.FAMILY_DOCTOR) {
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.ADMINISTRATOR || tipoUsuario == UserType.FAMILY_DOCTOR) {
subMenu = new DefaultSubMenu("Visitas", "pi pi-calendar");
if (tipoUsuario == UserType.PATIENT)
subMenu.addElement(createMenuItem("Solicitar nueva", "pi pi-calendar", "/visit/VisitView", null));
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.ADMINISTRADOR)
if (tipoUsuario == UserType.PATIENT || tipoUsuario == UserType.ADMINISTRATOR)
subMenu.addElement(createMenuItem("Modificar fecha/hora", "pi pi-calendar", "/visit/VisitView", null));
if (tipoUsuario == UserType.PATIENT)
subMenu.addElement(createMenuItem("Anular visita", "pi pi-calendar", "/visit/VisitView", null));
@@ -121,7 +121,7 @@ public class MenuMBean implements Serializable {
model.addElement(subMenu);
} else {
if (tipoUsuario != UserType.ADMINISTRADOR) {
if (tipoUsuario != UserType.ADMINISTRATOR) {
subMenu.addElement(createMenuItem("Modificar datos personales", "pi pi-user-edit", "/profile/UpdateProfile", null));
subMenu.addElement(new DefaultSeparator());

View File

@@ -5,11 +5,10 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import common.UserType;
/***
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
@@ -21,11 +20,17 @@ public class homeMBean implements Serializable {
private static final long serialVersionUID = 1L;
private boolean isLogedIn;
private String userId;
private String userName;
private UserType userType;
private int refresh;
@PostConstruct
public void init() {
isLogedIn = SessionUtils.isLogedIn();
userName = SessionUtils.getUserName();
userId = SessionUtils.getUserId();
userType = SessionUtils.getUserType();
}
public List<Theme> getThemes() {
@@ -40,15 +45,15 @@ public class homeMBean implements Serializable {
if (this.isLogedIn == false)
return "Invitado";
else
return SessionUtils.getUserName();
return this.userName;
}
public String getUserId() {
return SessionUtils.getUserId();
return this.userId;
}
public String getUserType() {
return SessionUtils.getUserType().getUserTypename();
return this.userType.getUserTypename();
}
public int getRefresh() {
@@ -59,4 +64,23 @@ public class homeMBean implements Serializable {
this.refresh = refresh;
}
public boolean isPatient() {
return (this.userType == UserType.PATIENT);
}
public boolean isFamilyDoctor() {
return (this.userType == UserType.FAMILY_DOCTOR);
}
public boolean isSpecialistDoctor() {
return (this.userType == UserType.SPECIALIST_DOCTOR);
}
public boolean isAdministrator() {
return (this.userType == UserType.ADMINISTRATOR);
}
public boolean isDoctor() {
return (isFamilyDoctor() || isSpecialistDoctor());
}
}

View File

@@ -1,50 +1,113 @@
package managedbean.profile;
import java.io.Serializable;
import java.util.Properties;
import java.util.Collection;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import ejb.profile.ProfileFacadeRemote;
import TO.FamilyDoctorTO;
import TO.LoggedUserTO;
import TO.PrimaryHealthCareCenterTO;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
/***
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Named( "ChangePrimaryHealthCareCenterMBean")
@RequestScoped
@Named("ChangeCAP")
@ViewScoped
public class ChangePrimaryHealthCareCenterMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private ProfileFacadeRemote remoteManager;
private int id;
private PrimaryHealthCareCenterTO currentCenter;
private PrimaryHealthCareCenterTO newCenter;
private Collection<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
public ChangePrimaryHealthCareCenterMBean() {
/**
* Constructor. Inicializa la conexión con el EJB Remoto
*
* @throws Exception
*/
public ChangePrimaryHealthCareCenterMBean() throws Exception {
initializeAdminFacadeRemote();
}
/**
* Inicializa la conexión con el EJB Remoto
*
* @throws Exception
*/
private void initializeAdminFacadeRemote() throws Exception {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
remoteManager = (ProfileFacadeRemote) ctx
.lookup("java:app/myHealth.jar/ProfileFacadeBean!ejb.component.ProfileFacadeRemote");
@PostConstruct
public void init() {
// Recuperamos el usuario logeado actual
LoggedUserTO usr = null;
try {
usr = SessionUtils.getloggedOnUser();
if (usr == null)
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
else {
this.id = Integer.valueOf(usr.getId());
if (usr.getUserType() == UserType.FAMILY_DOCTOR) {
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
FamilyDoctorTO fd = this.getRemoteManagerProfile().retrieveFamilyDoctor(this.id);
this.setCurrentCenter(fd.getPrimaryHealthCareCenter());
}
}
} catch (Exception e) {
this.manageException(e);
}
}
public Collection<PrimaryHealthCareCenterTO> getPhcList() {
return primaryHealthCareCentersList;
}
public int getId() {
return id;
}
public void saveData() {
int error = 0;
if (this.getNewCenter() == null) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un nuevvo centro de atención primaria.");
error++;
}
if (this.getNewCenter().getName().equals(this.getCurrentCenter().getName())) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El centro de atención primeria debe ser diferente", "Por favor, seleccione un centro de atención primaria diferente al cual está actualmente asignado.");
error++;
}
if (error == 0) {
try {
FamilyDoctorTO fd = this.getRemoteManagerProfile().changePrimaryHealthCareCenter(this.id, this.getNewCenter());
this.currentCenter = fd.getPrimaryHealthCareCenter();
this.newCenter = null;
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Su centro de atención primaria asignado se ha cambiado correctamente.");
} catch (Exception e) {
this.manageException(e);
}
}
}
public PrimaryHealthCareCenterTO getCurrentCenter() {
return currentCenter;
}
public void setCurrentCenter(PrimaryHealthCareCenterTO currentCenter) {
this.currentCenter = currentCenter;
}
public PrimaryHealthCareCenterTO getNewCenter() {
return newCenter;
}
public void setNewCenter(PrimaryHealthCareCenterTO newCenter) {
this.newCenter = newCenter;
}
}

View File

@@ -53,11 +53,6 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
private Collection<MedicalSpecialtyTO> medicalSpecialitiesList;
private Collection<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
/**
* Constructor. Inicializa la conexión con el EJB Remoto
*
* @throws Exception
*/
public RegisterUserMBean() {
}
@@ -96,7 +91,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
this.manageException(e);
}
break;
case ADMINISTRADOR:
case ADMINISTRATOR:
case PATIENT:
PrimeFaces.current().ajax().addCallbackParam("pats", true);
break;
@@ -106,6 +101,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
public Collection<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
return medicalSpecialitiesList;
}
public Collection<PrimaryHealthCareCenterTO> getPhcList() {
return primaryHealthCareCentersList;
}
@@ -208,7 +204,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
this.id = sd.getId();
break;
case ADMINISTRADOR:
case ADMINISTRATOR:
throw new NotSupportedException("No se soporta el registro directo de administradores.");
}

View File

@@ -55,7 +55,6 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
private String password;
private String email;
// private HashMap<String, String> userTypes;
private List<UserType> userTypes;
private String userType;
private PrimaryHealthCareCenterTO primaryHealthCareCenter;
@@ -63,11 +62,6 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
private Collection<MedicalSpecialtyTO> medicalSpecialitiesList;
private Collection<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
/**
* Constructor. Inicializa la conexión con el EJB Remoto
*
* @throws Exception
*/
public UpdateProfileMBean() {
}
@@ -85,7 +79,8 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
usr = SessionUtils.getloggedOnUser();
if (usr == null)
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida", "Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
else {
this.userType = usr.getUserType().getName();
this.id = Integer.valueOf(usr.getId());
@@ -122,7 +117,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.currentPassword = fd.getPassword();
this.primaryHealthCareCenter = fd.getPrimaryHealthCareCenter();
break;
case ADMINISTRADOR:
case ADMINISTRATOR:
// TODO: Recuperar usuario administrador para editar su perfil ¿?
// this.getRemoteManagerProfile().retrievePatient(usr.getId());
break;
@@ -154,7 +149,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.manageException(e);
}
break;
case ADMINISTRADOR:
case ADMINISTRATOR:
case PATIENT:
PrimeFaces.current().ajax().addCallbackParam("pats", true);
break;
@@ -246,12 +241,14 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
error++;
}
if (changePassword == true) {
// el usuario queire cambiar el password Comprobamos que el password especificado coincide con el guardado
// el usuario queire cambiar el password Comprobamos que el password
// especificado coincide con el guardado
if (this.password == null || this.password.length() < 4) {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Nueva contraseña incorrectra", "Su nueva contraseña debe tener al menos 4 caracteres.");
error++;
} else if (HashUtils.hashMD5(this.oldPassword).equals(this.currentPassword) == false) {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Contraseña actual incorrecta", "Su actual contraseña es incorrecta. Por favor, especifique su contraseña actual.");
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Contraseña actual incorrecta",
"Su actual contraseña es incorrecta. Por favor, especifique su contraseña actual.");
error++;
}
}
@@ -274,7 +271,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.id = sd.getId();
break;
case ADMINISTRADOR:
case ADMINISTRATOR:
throw new NotSupportedException("No se soporta la edición de perfiles de tipo administrador.");
}