Implementación de registro de usuarios para pacientes, medicos de
familia y medicos especialistas. * Correcciones varias a clases JPA. * Correcciones en clases POJO. * Listas desplegables para selección de especialidaes y CAPs. * Validaciones varias. * Estilo de interfaz con flexUI de PrimeFaces.
This commit is contained in:
@@ -3,15 +3,16 @@ package managedbean.profile;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.resource.NotSupportedException;
|
||||
|
||||
import org.primefaces.PrimeFaces;
|
||||
@@ -26,14 +27,14 @@ import managedbean.common.UserType;
|
||||
import managedbean.common.ValidationUtils;
|
||||
|
||||
/**
|
||||
* ManagedBEan que gestiona la edición y actualización de una especialidad
|
||||
* médica.
|
||||
* 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 mark
|
||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||
*
|
||||
*/
|
||||
@Named("registerUser")
|
||||
@RequestScoped
|
||||
@ViewScoped
|
||||
public class RegisterUserMBean extends ProfileMBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -45,12 +46,13 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
private String password;
|
||||
private String passwordRepeat;
|
||||
private String email;
|
||||
private HashMap<String, String> userTypes;
|
||||
// private HashMap<String, String> userTypes;
|
||||
private List<UserType> userTypes;
|
||||
private String userType;
|
||||
private String primaryHealthCareCenter;
|
||||
private String medicalSpecialty;
|
||||
private Collection<MedicalSpecialtyTO> medicalSpecialities;
|
||||
private Collection<PrimaryHealthCareCenterTO> healthcareCenters;
|
||||
private PrimaryHealthCareCenterTO primaryHealthCareCenter;
|
||||
private MedicalSpecialtyTO medicalSpecialty;
|
||||
private Collection<MedicalSpecialtyTO> medicalSpecialitiesList;
|
||||
private Collection<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
|
||||
|
||||
/**
|
||||
* Constructor. Inicializa la conexión con el EJB Remoto
|
||||
@@ -63,15 +65,27 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.userTypes = new HashMap<String, String>();
|
||||
this.userTypes.put(UserType.PATIENT.getUserTypename(), UserType.PATIENT.name());
|
||||
this.userTypes.put(UserType.FAMILY_DOCTOR.getUserTypename(), UserType.FAMILY_DOCTOR.name());
|
||||
this.userTypes.put(UserType.SPECIALIST_DOCTOR.getUserTypename(), UserType.SPECIALIST_DOCTOR.name());
|
||||
this.userType = UserType.PATIENT.getUserTypename();
|
||||
this.userTypes = new ArrayList<UserType>();
|
||||
this.userTypes.add(UserType.PATIENT);
|
||||
this.userTypes.add(UserType.FAMILY_DOCTOR);
|
||||
this.userTypes.add(UserType.SPECIALIST_DOCTOR);
|
||||
|
||||
this.userType = UserType.PATIENT.name();
|
||||
|
||||
Properties props = System.getProperties();
|
||||
Context ctx;
|
||||
try {
|
||||
ctx = new InitialContext(props);
|
||||
SystemAdminFacadeRemote rman = (SystemAdminFacadeRemote) ctx.lookup("java:app/MyHealth.jar/SystemAdminFacadeBean!ejb.systemAdmin.SystemAdminFacadeRemote");
|
||||
|
||||
this.medicalSpecialitiesList = rman.listAllMedicalSpecialities();
|
||||
this.primaryHealthCareCentersList = rman.listAllCAPs();
|
||||
} catch (NamingException e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> getUserTypes() {
|
||||
public List<UserType> getUserTypes() {
|
||||
return userTypes;
|
||||
}
|
||||
|
||||
@@ -79,12 +93,6 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
switch (UserType.valueOf(this.userType)) {
|
||||
case SPECIALIST_DOCTOR:
|
||||
try {
|
||||
Properties props = System.getProperties();
|
||||
Context ctx = new InitialContext(props);
|
||||
SystemAdminFacadeRemote rman = (SystemAdminFacadeRemote) ctx.lookup("java:app/MyHealth.jar/SystemAdminFacadeBean!ejb.systemAdmin.SystemAdminFacadeRemote");
|
||||
|
||||
this.medicalSpecialities = rman.listAllMedicalSpecialities();
|
||||
|
||||
PrimeFaces.current().ajax().addCallbackParam("specs", true);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
@@ -92,11 +100,6 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
try {
|
||||
// TODO: Load Primary Healthcare Centers from remote EJB
|
||||
this.healthcareCenters = new ArrayList<PrimaryHealthCareCenterTO>();
|
||||
this.healthcareCenters.add(new PrimaryHealthCareCenterTO("Prueba", "Descripción prueba"));
|
||||
this.healthcareCenters.add(new PrimaryHealthCareCenterTO("Centro 2", "Centro 2"));
|
||||
|
||||
PrimeFaces.current().ajax().addCallbackParam("caps", true);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
@@ -104,12 +107,37 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
case PATIENT:
|
||||
PrimeFaces.current().ajax().addCallbackParam("pats", true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<MedicalSpecialtyTO> getMedicalSpecialties() {
|
||||
return medicalSpecialities;
|
||||
public Collection<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
|
||||
return medicalSpecialitiesList;
|
||||
}
|
||||
|
||||
// public void setMedicalSpecialtiesList(Collection<MedicalSpecialtyTO> list) {
|
||||
// medicalSpecialitiesList = list;
|
||||
// }
|
||||
|
||||
public Collection<PrimaryHealthCareCenterTO> getPhcList() {
|
||||
return primaryHealthCareCentersList;
|
||||
}
|
||||
|
||||
// public void setPhcList(Collection<PrimaryHealthCareCenterTO> list) {
|
||||
// primaryHealthCareCentersList = list;
|
||||
// }
|
||||
|
||||
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 String getEmail() {
|
||||
@@ -161,9 +189,22 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
}
|
||||
|
||||
public void addNewUser() {
|
||||
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.");
|
||||
} else {
|
||||
error++;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
switch (UserType.valueOf(this.userType)) {
|
||||
case PATIENT:
|
||||
@@ -171,11 +212,11 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
FamilyDoctorTO fd = this.remoteManager.registerFamilyDoctor1(id, nif, name, surname, password, email, null);
|
||||
FamilyDoctorTO fd = this.remoteManager.registerFamilyDoctor1(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
|
||||
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
SpecialistDoctorTO sd = this.remoteManager.registerSpecialistDoctor(id, nif, name, surname, password, email, null);
|
||||
SpecialistDoctorTO sd = this.remoteManager.registerSpecialistDoctor(id, nif, name, surname, password, email, this.medicalSpecialty);
|
||||
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
@@ -207,21 +248,21 @@ public class RegisterUserMBean extends ProfileMBeanBase implements Serializable
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getMedicalSpecialty() {
|
||||
|
||||
public MedicalSpecialtyTO getMedicalSpecialty() {
|
||||
return medicalSpecialty;
|
||||
}
|
||||
|
||||
public void setMedicalSpecialty(String medicalSpecialty) {
|
||||
public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) {
|
||||
this.medicalSpecialty = medicalSpecialty;
|
||||
}
|
||||
|
||||
public String getPrimaryHealthCareCenter() {
|
||||
public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() {
|
||||
return primaryHealthCareCenter;
|
||||
}
|
||||
|
||||
public void setPrimaryHealthCareCenter(String primaryHealthCareCenter) {
|
||||
public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) {
|
||||
this.primaryHealthCareCenter = primaryHealthCareCenter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user