249 lines
6.6 KiB
Java
249 lines
6.6 KiB
Java
package managedbean.profile;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.application.FacesMessage;
|
|
import javax.faces.view.ViewScoped;
|
|
import javax.inject.Named;
|
|
import javax.resource.NotSupportedException;
|
|
import javax.validation.constraints.Size;
|
|
|
|
import org.primefaces.PrimeFaces;
|
|
|
|
import TO.FamilyDoctorTO;
|
|
import TO.MedicalSpecialtyTO;
|
|
import TO.PatientTO;
|
|
import TO.PrimaryHealthCareCenterTO;
|
|
import TO.SpecialistDoctorTO;
|
|
import common.UserType;
|
|
import managedbean.common.ManagedBeanBase;
|
|
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("RegisterUser")
|
|
@ViewScoped
|
|
public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private int id;
|
|
private String nif;
|
|
private String name;
|
|
private String surname;
|
|
@Size(min = 4, message = "La contraseña debe tener al menos 4 carácteres.")
|
|
private String password;
|
|
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;
|
|
|
|
public RegisterUserMBean() {
|
|
|
|
}
|
|
|
|
@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);
|
|
this.registered = false;
|
|
|
|
this.userType = UserType.PATIENT.name();
|
|
|
|
this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities();
|
|
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
|
|
}
|
|
|
|
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 ADMINISTRATOR:
|
|
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 setId(int id) {
|
|
this.id = id;
|
|
}
|
|
|
|
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.");
|
|
error++;
|
|
}
|
|
|
|
if (error == 0) {
|
|
try {
|
|
switch (UserType.valueOf(this.userType)) {
|
|
case PATIENT:
|
|
PatientTO pat = this.getRemoteManagerProfile().registerPatient(id, nif, name, surname, password, email);
|
|
this.id = pat.getId();
|
|
|
|
break;
|
|
case FAMILY_DOCTOR:
|
|
FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
|
|
this.id = fd.getId();
|
|
|
|
break;
|
|
case SPECIALIST_DOCTOR:
|
|
SpecialistDoctorTO sd = this.getRemoteManagerProfile().registerSpecialistDoctor(id, nif, name, surname, password, email, this.medicalSpecialty);
|
|
this.id = sd.getId();
|
|
|
|
break;
|
|
case ADMINISTRATOR:
|
|
throw new NotSupportedException("No se soporta el registro directo de administradores.");
|
|
}
|
|
|
|
this.registered = true;
|
|
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Registro realizado", "El usuario " + name + " " + surname + " se ha registrado correctamente.");
|
|
|
|
} catch (Exception e) {
|
|
this.manageException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|