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:
@@ -41,4 +41,10 @@ public class MedicalSpecialtyTO implements Serializable {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s[name=%s]", getClass().getSimpleName(), getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ public class PrimaryHealthCareCenterTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String location;
|
||||
|
||||
|
||||
public PrimaryHealthCareCenterTO() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PrimaryHealthCareCenterTO(String name, String description) {
|
||||
public PrimaryHealthCareCenterTO(String name, String location) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -35,12 +35,30 @@ public class PrimaryHealthCareCenterTO implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
public void setLocation(String description) {
|
||||
this.location = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof PrimaryHealthCareCenterTO) && (name != null)
|
||||
? name.equals(((PrimaryHealthCareCenterTO) other).getName())
|
||||
: (other == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (name != null)
|
||||
? (this.getClass().hashCode() + name.hashCode())
|
||||
: super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s[name=%s]", getClass().getSimpleName(), getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,10 +67,10 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return sdTO;
|
||||
}
|
||||
|
||||
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, String cap) {
|
||||
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) {
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap);
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap.getName());
|
||||
|
||||
// TODO: Lanzar error si no encontramos el cap!!!!!
|
||||
if (phcC != null) {
|
||||
|
||||
@@ -20,15 +20,13 @@ public interface ProfileFacadeRemote {
|
||||
|
||||
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email);
|
||||
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(Integer id, String nif, String name, String surname, String password, String email,
|
||||
MedicalSpecialtyTO specialty);
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty);
|
||||
|
||||
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, String cap);
|
||||
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap);
|
||||
|
||||
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email);
|
||||
|
||||
public SpecialistDoctorTO updateSpecialistDoctorData(Integer id, String nif, String name, String surname, String password, String email,
|
||||
MedicalSpecialtyTO specialty);
|
||||
public SpecialistDoctorTO updateSpecialistDoctorData(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty);
|
||||
|
||||
public FamilyDoctorTO updateFamilyDoctorData(Integer id, String nif, String name, String surname, String password, String email, String cap);
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.PrimaryHealthCareCenterJPA;
|
||||
|
||||
/**
|
||||
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
|
||||
@@ -59,4 +61,26 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
return allSpecialities;
|
||||
}
|
||||
|
||||
public Collection<PrimaryHealthCareCenterTO> listAllCAPs() {
|
||||
return this.listPagedAllCAPs(0, 0);
|
||||
}
|
||||
|
||||
public Collection<PrimaryHealthCareCenterTO> listPagedAllCAPs(int pageNumber, int pageSize) {
|
||||
Query query = entman.createQuery("from PrimaryHealthCareCenterJPA order by name");
|
||||
|
||||
if (pageSize > 0) {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<PrimaryHealthCareCenterJPA> allJPA = query.getResultList();
|
||||
Collection<PrimaryHealthCareCenterTO> allCAPs = new ArrayList<PrimaryHealthCareCenterTO>();
|
||||
|
||||
for (PrimaryHealthCareCenterJPA cap : allJPA) {
|
||||
allCAPs.add(new PrimaryHealthCareCenterTO(cap.getName(), cap.getLocation()));
|
||||
}
|
||||
|
||||
return allCAPs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
|
||||
/**
|
||||
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
|
||||
@@ -19,4 +20,5 @@ public interface SystemAdminFacadeRemote {
|
||||
* Definimos la interfaz remota
|
||||
*/
|
||||
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
|
||||
public Collection<PrimaryHealthCareCenterTO> listAllCAPs();
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class PrimaryHealthCareCenterJPA implements Serializable {
|
||||
|
||||
@Id
|
||||
private String name;
|
||||
private String description;
|
||||
private String location;
|
||||
|
||||
/**
|
||||
* Class constructor methods
|
||||
@@ -28,9 +28,9 @@ public class PrimaryHealthCareCenterJPA implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public PrimaryHealthCareCenterJPA(String name, String description) {
|
||||
public PrimaryHealthCareCenterJPA(String name, String location) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -41,11 +41,11 @@ public class PrimaryHealthCareCenterJPA implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
public void setLocation(String description) {
|
||||
this.location = description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SpecialistDoctorJPA implements Serializable {
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "MedicalSpecialtyName")
|
||||
@JoinColumn(name = "MedicalSpecialtyId")
|
||||
public MedicalSpecialtyJPA getMedicalSpecialty() {
|
||||
return medicalSpecialty;
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ public enum UserType {
|
||||
public String getUserTypename() {
|
||||
return userTypename;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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