Cambios para la edición del perfil de usuario y su actualización (Vista,
managed bean, metodos en EJB para recuperar datos de Paciente, Medico de familia y medico especialista).
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
package managedbean.profile;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.ExternalContext;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.print.attribute.standard.Severity;
|
||||
import javax.resource.NotSupportedException;
|
||||
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
import TO.FamilyDoctorTO;
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import common.UserType;
|
||||
import ejb.systemAdmin.SystemAdminFacadeRemote;
|
||||
import managedbean.common.ManagedBeanBase;
|
||||
import managedbean.common.SessionUtils;
|
||||
import managedbean.common.ValidationUtils;
|
||||
|
||||
/**
|
||||
* ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente"
|
||||
* Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista"
|
||||
*
|
||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||
*
|
||||
*/
|
||||
@Named("UpdateProfile")
|
||||
@ViewScoped
|
||||
public class UpdateProfileMBean extends ManagedBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String password;
|
||||
private String passwordRepeat;
|
||||
private String email;
|
||||
private boolean registered;
|
||||
|
||||
// private HashMap<String, String> userTypes;
|
||||
private List<UserType> userTypes;
|
||||
private String userType;
|
||||
private PrimaryHealthCareCenterTO primaryHealthCareCenter;
|
||||
private MedicalSpecialtyTO medicalSpecialty;
|
||||
private Collection<MedicalSpecialtyTO> medicalSpecialitiesList;
|
||||
private Collection<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
|
||||
|
||||
/**
|
||||
* Constructor. Inicializa la conexión con el EJB Remoto
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public UpdateProfileMBean() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.userTypes = new ArrayList<UserType>();
|
||||
this.userTypes.add(UserType.PATIENT);
|
||||
this.userTypes.add(UserType.FAMILY_DOCTOR);
|
||||
this.userTypes.add(UserType.SPECIALIST_DOCTOR);
|
||||
|
||||
// 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.userType = usr.getUserType().getName();
|
||||
this.id = Integer.valueOf(usr.getId());
|
||||
|
||||
switch (usr.getUserType()) {
|
||||
case PATIENT:
|
||||
PatientTO pat = this.getRemoteManagerProfile().retrievePatient(this.id);
|
||||
|
||||
this.name = pat.getName();
|
||||
this.surname = pat.getName();
|
||||
this.nif = pat.getNif();
|
||||
this.email = pat.getEmail();
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities();
|
||||
SpecialistDoctorTO sd = this.getRemoteManagerProfile().retrieveSpecialistDoctor(this.id);
|
||||
|
||||
this.name = sd.getName();
|
||||
this.surname = sd.getName();
|
||||
this.nif = sd.getNif();
|
||||
this.email = sd.getEmail();
|
||||
this.medicalSpecialty = sd.getMedicalSpecialty();
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
|
||||
FamilyDoctorTO fd = this.getRemoteManagerProfile().retrieveFamilyDoctor(this.id);
|
||||
|
||||
this.name = fd.getName();
|
||||
this.surname = fd.getName();
|
||||
this.nif = fd.getNif();
|
||||
this.email = fd.getEmail();
|
||||
this.primaryHealthCareCenter = fd.getPrimaryHealthCareCenter();
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
// TODO: Recuperar usuario administrador para editar su perfil ¿?
|
||||
// this.getRemoteManagerProfile().retrievePatient(usr.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<UserType> getUserTypes() {
|
||||
return userTypes;
|
||||
}
|
||||
|
||||
public void onUserTypeChange() {
|
||||
switch (UserType.valueOf(this.userType)) {
|
||||
case SPECIALIST_DOCTOR:
|
||||
try {
|
||||
PrimeFaces.current().ajax().addCallbackParam("specs", true);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
try {
|
||||
PrimeFaces.current().ajax().addCallbackParam("caps", true);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
case PATIENT:
|
||||
PrimeFaces.current().ajax().addCallbackParam("pats", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
|
||||
return medicalSpecialitiesList;
|
||||
}
|
||||
|
||||
public Collection<PrimaryHealthCareCenterTO> getPhcList() {
|
||||
return primaryHealthCareCentersList;
|
||||
}
|
||||
|
||||
public boolean isPatient() {
|
||||
return (UserType.valueOf(this.userType) == UserType.PATIENT);
|
||||
}
|
||||
|
||||
public boolean isFamilyDoctor() {
|
||||
return (UserType.valueOf(this.userType) == UserType.FAMILY_DOCTOR);
|
||||
}
|
||||
|
||||
public boolean isSpecialistDoctor() {
|
||||
return (UserType.valueOf(this.userType) == UserType.SPECIALIST_DOCTOR);
|
||||
}
|
||||
|
||||
public boolean isDoctor() {
|
||||
return (isFamilyDoctor() || isSpecialistDoctor());
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNif() {
|
||||
return nif;
|
||||
}
|
||||
|
||||
public void setNif(String nif) {
|
||||
this.nif = nif;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
int error = 0;
|
||||
|
||||
if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un centro de atención primaria.");
|
||||
error++;
|
||||
}
|
||||
if (this.isSpecialistDoctor() && this.medicalSpecialty == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad médica no seleccionada", "Por favor, especifique una especialidad médica.");
|
||||
error++;
|
||||
}
|
||||
if (ValidationUtils.isValid(nif) == false) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El NIF indicado no es válido", "Por favor, especifique un NIF válido.");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
switch (UserType.valueOf(this.userType)) {
|
||||
case PATIENT:
|
||||
PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email);
|
||||
this.id = pat.getId();
|
||||
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
|
||||
this.id = fd.getId();
|
||||
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty);
|
||||
this.id = sd.getId();
|
||||
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
throw new NotSupportedException("No se soporta la edición de perfiles de administrador.");
|
||||
}
|
||||
|
||||
this.registered = true;
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos guardados", "Los datos de su perfil se han guardado correctamente en la base de datos.");
|
||||
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPasswordRepeat() {
|
||||
return passwordRepeat;
|
||||
}
|
||||
|
||||
public void setPasswordRepeat(String passwordRepeat) {
|
||||
this.passwordRepeat = passwordRepeat;
|
||||
}
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public MedicalSpecialtyTO getMedicalSpecialty() {
|
||||
return medicalSpecialty;
|
||||
}
|
||||
|
||||
public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) {
|
||||
this.medicalSpecialty = medicalSpecialty;
|
||||
}
|
||||
|
||||
public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() {
|
||||
return primaryHealthCareCenter;
|
||||
}
|
||||
|
||||
public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) {
|
||||
this.primaryHealthCareCenter = primaryHealthCareCenter;
|
||||
}
|
||||
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user