Avances en la pantalla de registro de usuarios nuevos (pacientes).
* Actualización de script para crear tablas (Todo a minusculas, no case sensitive) * Script de datos de pruebas de especialides médicas. * Nuevo bean para registro de usuarios (Quidato de filtro de seguridad de login, acceso sin login). * Actualización de entidades JPA con campos Identity. * Enumerado para gestionar tipos de usuarios (Paciente, Medico Familia, Especialista y Administrador) * Clase común para realizar validaciones (función para validar nif).
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0">
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
|
||||
<persistence-unit name="MyHealth">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:jboss/postgresDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.PostgreSQL94Dialect" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
|
||||
<!-- <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> -->
|
||||
<!-- <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.EJB3NamingStrategy" /> -->
|
||||
<property name="hibernate.show_sql" value="true"></property>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
@@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
public class FamilyDoctorTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
@@ -24,7 +24,7 @@ public class FamilyDoctorTO implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public FamilyDoctorTO(String id, String nif, String name, String surname, String password, String email) {
|
||||
public FamilyDoctorTO(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.setId(id);
|
||||
this.setNif(nif);
|
||||
this.setName(name);
|
||||
@@ -73,11 +73,11 @@ public class FamilyDoctorTO implements Serializable {
|
||||
this.nif = nif;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import jpa.FamilyDoctorJPA;
|
||||
public class PatientTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
@@ -30,7 +30,7 @@ public class PatientTO implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public PatientTO(String id, String nif, String name, String surname, String password, String email) {
|
||||
public PatientTO(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.setId(id);
|
||||
this.setNif(nif);
|
||||
this.setName(name);
|
||||
@@ -79,11 +79,11 @@ public class PatientTO implements Serializable {
|
||||
this.nif = nif;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,33 @@ public class PrimaryHealthCareCenterTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
|
||||
public PrimaryHealthCareCenterTO() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PrimaryHealthCareCenterTO(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
public class SpecialistDoctorTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
@@ -24,7 +24,7 @@ public class SpecialistDoctorTO implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpecialistDoctorTO(String id, String nif, String name, String surname, String password, String email) {
|
||||
public SpecialistDoctorTO(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.setId(id);
|
||||
this.setNif(nif);
|
||||
this.setName(name);
|
||||
@@ -73,11 +73,11 @@ public class SpecialistDoctorTO implements Serializable {
|
||||
this.nif = nif;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
|
||||
public PatientTO changeFamilyDoctor(String id, String ProfessionalNumberId) {
|
||||
public PatientTO changeFamilyDoctor(Integer id, Integer ProfessionalNumberId) {
|
||||
PatientTO paTO = null;
|
||||
|
||||
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, ProfessionalNumberId);
|
||||
@@ -42,7 +42,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return paTO;
|
||||
}
|
||||
|
||||
public PatientTO registerPacient(String id, String nif, String name, String surname, String password, String email) {
|
||||
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
PatientTO paTO = null;
|
||||
|
||||
PatientJPA ms = new PatientJPA(id, nif, name, surname, password, email);
|
||||
@@ -52,7 +52,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return paTO;
|
||||
}
|
||||
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(String 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) {
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName());
|
||||
@@ -67,7 +67,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return sdTO;
|
||||
}
|
||||
|
||||
public FamilyDoctorTO registerFamilyDoctor1(String 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, String cap) {
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap);
|
||||
@@ -86,7 +86,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return fdTO;
|
||||
}
|
||||
|
||||
public PatientTO updatePacientData(String id, String nif, String name, String surname, String password, String email) {
|
||||
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
PatientJPA fd = entman.find(PatientJPA.class, id);
|
||||
PatientTO ptTO = null;
|
||||
|
||||
@@ -105,7 +105,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return ptTO;
|
||||
}
|
||||
|
||||
public SpecialistDoctorTO updateSpecialistDoctorData(String 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) {
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
|
||||
SpecialistDoctorJPA sd = entman.find(SpecialistDoctorJPA.class, id);
|
||||
@@ -129,7 +129,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return sdTO;
|
||||
}
|
||||
|
||||
public FamilyDoctorTO updateFamilyDoctorData(String id, String nif, String name, String surname, String password, String email, String cap) {
|
||||
public FamilyDoctorTO updateFamilyDoctorData(Integer id, String nif, String name, String surname, String password, String email, String cap) {
|
||||
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, id);
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
return fdTO;
|
||||
}
|
||||
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(String FamilyDoctorId, PrimaryHealthCareCenterTO newCenter) {
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(Integer FamilyDoctorId, PrimaryHealthCareCenterTO newCenter) {
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, newCenter);
|
||||
|
||||
@@ -16,21 +16,21 @@ import TO.SpecialistDoctorTO;
|
||||
@Remote
|
||||
public interface ProfileFacadeRemote {
|
||||
|
||||
public PatientTO changeFamilyDoctor(String id, String ProfessionalNumberId);
|
||||
public PatientTO changeFamilyDoctor(Integer id, Integer ProfessionalNumberId);
|
||||
|
||||
public PatientTO registerPacient(String id, String nif, String name, String surname, String password, String email);
|
||||
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email);
|
||||
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(String 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 FamilyDoctorTO registerFamilyDoctor1(String 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, String cap);
|
||||
|
||||
public PatientTO updatePacientData(String id, String nif, String name, String surname, String password, String email);
|
||||
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email);
|
||||
|
||||
public SpecialistDoctorTO updateSpecialistDoctorData(String 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 FamilyDoctorTO updateFamilyDoctorData(String id, String nif, String name, String surname, String password, String email, String cap);
|
||||
public FamilyDoctorTO updateFamilyDoctorData(Integer id, String nif, String name, String surname, String password, String email, String cap);
|
||||
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(String id, PrimaryHealthCareCenterTO newCenter);
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(Integer id, PrimaryHealthCareCenterTO newCenter);
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
package ejb.systemAdmin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
|
||||
/**
|
||||
* EJB Session Bean Class para la Practica 2, Ejercicio 1 (ISCSD) Implementa los
|
||||
@@ -20,9 +26,37 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
|
||||
public void ejbMethod(String parameter)
|
||||
{
|
||||
|
||||
/**
|
||||
* Metodo que devuelve todas las especialidades medicas
|
||||
*/
|
||||
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities() {
|
||||
return this.listPagedMedicalSpecialities(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Metodo que devuelve las especialidades médicas de forma paginada
|
||||
*
|
||||
* Acepta como parametro la página (comenzando en 0) y el número de elementos de
|
||||
* cada página
|
||||
*
|
||||
*/
|
||||
public Collection<MedicalSpecialtyTO> listPagedMedicalSpecialities(int pageNumber, int pageSize) {
|
||||
Query query = entman.createQuery("from MedicalSpecialtyJPA order by name");
|
||||
|
||||
if (pageSize > 0) {
|
||||
query.setFirstResult(pageNumber * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<MedicalSpecialtyJPA> allJPA = query.getResultList();
|
||||
Collection<MedicalSpecialtyTO> allSpecialities = new ArrayList<MedicalSpecialtyTO>();
|
||||
|
||||
for (MedicalSpecialtyJPA ms : allJPA) {
|
||||
allSpecialities.add(new MedicalSpecialtyTO(ms.getName(), ms.getDescription()));
|
||||
}
|
||||
|
||||
return allSpecialities;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package ejb.systemAdmin;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ejb.Remote;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
|
||||
/**
|
||||
* Interfaz remota del EJB Definimos los métodos que estarán disponibles para
|
||||
* los clientes del EJB
|
||||
@@ -14,5 +18,5 @@ public interface SystemAdminFacadeRemote {
|
||||
/**
|
||||
* Definimos la interfaz remota
|
||||
*/
|
||||
public void ejbMethod(String parameter);
|
||||
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import java.util.Collection;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
@@ -24,7 +26,7 @@ public class FamilyDoctorJPA implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
@@ -40,7 +42,7 @@ public class FamilyDoctorJPA implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public FamilyDoctorJPA(String id, String nif, String name, String surname, String password, String email) {
|
||||
public FamilyDoctorJPA(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.id = id;
|
||||
this.nif = nif;
|
||||
this.name = name;
|
||||
@@ -50,11 +52,12 @@ public class FamilyDoctorJPA implements Serializable {
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getId() {
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String value) {
|
||||
public void setId(Integer value) {
|
||||
this.id = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package jpa;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
@@ -20,12 +22,15 @@ public class PatientJPA implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String password;
|
||||
private String email;
|
||||
@ManyToOne
|
||||
@JoinColumn (name="FamilyDoctorId")
|
||||
private FamilyDoctorJPA familyDoctor;
|
||||
|
||||
/**
|
||||
@@ -35,7 +40,7 @@ public class PatientJPA implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public PatientJPA(String id, String nif, String name, String surname, String password, String email) {
|
||||
public PatientJPA(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.id = id;
|
||||
this.nif = nif;
|
||||
this.name = name;
|
||||
@@ -44,12 +49,11 @@ public class PatientJPA implements Serializable {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getId() {
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String value) {
|
||||
public void setId(Integer value) {
|
||||
this.id = value;
|
||||
}
|
||||
|
||||
@@ -96,8 +100,6 @@ public class PatientJPA implements Serializable {
|
||||
/**
|
||||
* Methods get/set persistent relationships
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn (name="FamilyDoctorId")
|
||||
public FamilyDoctorJPA getFamilyDoctor() {
|
||||
return familyDoctor;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public class PrimaryHealthCareCenterJPA implements Serializable {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package jpa;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
@@ -20,7 +22,7 @@ public class SpecialistDoctorJPA implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
@@ -35,7 +37,7 @@ public class SpecialistDoctorJPA implements Serializable {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpecialistDoctorJPA(String id, String nif, String name, String surname, String password, String email) {
|
||||
public SpecialistDoctorJPA(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
this.id = id;
|
||||
this.nif = nif;
|
||||
this.name = name;
|
||||
@@ -45,11 +47,12 @@ public class SpecialistDoctorJPA implements Serializable {
|
||||
}
|
||||
|
||||
@Id
|
||||
public String getId() {
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String value) {
|
||||
public void setId(Integer value) {
|
||||
this.id = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class AuthorizationFilter implements Filter {
|
||||
HttpSession ses = reqt.getSession(false);
|
||||
|
||||
String reqURI = reqt.getRequestURI();
|
||||
if (reqURI.indexOf("/login.xhtml") >= 0 || (ses != null && ses.getAttribute("username") != null)
|
||||
if (reqURI.indexOf("/login.xhtml") >= 0 || reqURI.indexOf("/RegisterUser.xhtml") >= 0 || (ses != null && ses.getAttribute("username") != null)
|
||||
|| reqURI.indexOf("/public/") >= 0 || reqURI.indexOf("/home.xhtml") >= 0 || reqURI.contains("javax.faces.resource"))
|
||||
chain.doFilter(request, response);
|
||||
else
|
||||
|
||||
18
1.sources/MyHealth/src/managedbean/common/UserType.java
Normal file
18
1.sources/MyHealth/src/managedbean/common/UserType.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package managedbean.common;
|
||||
|
||||
public enum UserType {
|
||||
PATIENT("Paciente"),
|
||||
FAMILY_DOCTOR("Médico de familia"),
|
||||
SPECIALIST_DOCTOR("Médico especialista"),
|
||||
ADMINISTRADOR("Administrador");
|
||||
|
||||
private String userTypename;
|
||||
|
||||
private UserType (String userTypename){
|
||||
this.userTypename = userTypename;
|
||||
}
|
||||
|
||||
public String getUserTypename() {
|
||||
return userTypename;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package managedbean.common;
|
||||
|
||||
/***
|
||||
*
|
||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||
*
|
||||
*/
|
||||
public class ValidationUtils {
|
||||
static final String NIF_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE";
|
||||
static final String NIE_LETTERS = "XYZ";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nif NIF a validar
|
||||
* @return true si es válido, false en otro caso
|
||||
*/
|
||||
public static boolean isValid(String nif) {
|
||||
if (nif == null)
|
||||
return false;
|
||||
|
||||
nif = nif.toUpperCase().replace("-", "").replace(".", "");
|
||||
|
||||
if (nif.length() < 2 || nif.length() > 9)
|
||||
return false;
|
||||
|
||||
if (nif.startsWith("X")) {
|
||||
nif = nif.replace('X', '0');
|
||||
} else if (nif.startsWith("Y")) {
|
||||
nif = nif.replace('Y', '1');
|
||||
} else if (nif.startsWith("Z")) {
|
||||
nif = nif.replace('Z', '2');
|
||||
}
|
||||
|
||||
char letra = nif.charAt(nif.length() - 1);
|
||||
if (NIF_LETTERS.indexOf(letra) < 0)
|
||||
return false;
|
||||
|
||||
String numbers = nif.substring(0, nif.length() - 1);
|
||||
|
||||
try {
|
||||
if (NIF_LETTERS.charAt(Integer.parseInt(numbers) % 23) == letra)
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
package managedbean.profile;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
import ejb.profile.ProfileFacadeRemote;
|
||||
|
||||
/**
|
||||
* ManagedBEan que gestiona la edición y actualización de una especialidad
|
||||
@@ -17,31 +14,98 @@ import ejb.profile.ProfileFacadeRemote;
|
||||
* @author mark
|
||||
*
|
||||
*/
|
||||
@Named( "AddPatientMBean")
|
||||
@Named("addPatientMBean")
|
||||
@RequestScoped
|
||||
public class AddPatientMBean extends ProfileMBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String password;
|
||||
private String passwordRepeat;
|
||||
private String email;
|
||||
private String primaryHealthCareCenter;
|
||||
private String medicalSpecialty;
|
||||
|
||||
/**
|
||||
* Constructor. Inicializa la conexión con el EJB Remoto
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public AddPatientMBean() throws Exception {
|
||||
initializeAdminFacadeRemote();
|
||||
super.initializeProfileFacadeRemote();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
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 String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
FacesMessage msg;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Alta realizada", "El usuario " + name + " " + surname + " se ha registrado correctamente.");
|
||||
} catch (Exception e) {
|
||||
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Se ha producido un error inesperado: " + e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
FacesContext.getCurrentInstance().addMessage(null, msg);
|
||||
}
|
||||
|
||||
public String getPasswordRepeat() {
|
||||
return passwordRepeat;
|
||||
}
|
||||
|
||||
public void setPasswordRepeat(String passwordRepeat) {
|
||||
this.passwordRepeat = passwordRepeat;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,21 @@ import javax.naming.InitialContext;
|
||||
|
||||
import ejb.profile.ProfileFacadeRemote;
|
||||
|
||||
/***
|
||||
*
|
||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||
*
|
||||
*/
|
||||
@Named("profileMBean")
|
||||
public class ProfileMBeanBase {
|
||||
@EJB
|
||||
protected ProfileFacadeRemote remoteManager;
|
||||
|
||||
/**
|
||||
* Inicializa la conexión con el EJB Remoto
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected void initializeProfileFacadeRemote() throws Exception {
|
||||
Properties props = System.getProperties();
|
||||
Context ctx = new InitialContext(props);
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package managedbean.profile;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.resource.NotSupportedException;
|
||||
|
||||
import org.primefaces.PrimeFaces;
|
||||
|
||||
import TO.FamilyDoctorTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import ejb.systemAdmin.SystemAdminFacadeRemote;
|
||||
import managedbean.common.UserType;
|
||||
import managedbean.common.ValidationUtils;
|
||||
|
||||
/**
|
||||
* ManagedBEan que gestiona la edición y actualización de una especialidad
|
||||
* médica.
|
||||
*
|
||||
* @author mark
|
||||
*
|
||||
*/
|
||||
@Named("registerUser")
|
||||
@RequestScoped
|
||||
public class RegisterUserMBean extends ProfileMBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private String nif;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String password;
|
||||
private String passwordRepeat;
|
||||
private String email;
|
||||
private HashMap<String, String> userTypes;
|
||||
private String userType;
|
||||
private String primaryHealthCareCenter;
|
||||
private String medicalSpecialty;
|
||||
private Collection<MedicalSpecialtyTO> medicalSpecialities;
|
||||
private Collection<PrimaryHealthCareCenterTO> healthcareCenters;
|
||||
|
||||
/**
|
||||
* Constructor. Inicializa la conexión con el EJB Remoto
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public RegisterUserMBean() throws Exception {
|
||||
super.initializeProfileFacadeRemote();
|
||||
}
|
||||
|
||||
@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 = "patient";
|
||||
|
||||
}
|
||||
|
||||
public HashMap<String, String> getUserTypes() {
|
||||
return userTypes;
|
||||
}
|
||||
|
||||
public void onUserTypeChange() {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
case PATIENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<MedicalSpecialtyTO> getMedicalSpecialties() {
|
||||
return medicalSpecialities;
|
||||
}
|
||||
|
||||
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 Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void addNewUser() {
|
||||
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 {
|
||||
try {
|
||||
switch (UserType.valueOf(this.userType)) {
|
||||
case PATIENT:
|
||||
PatientTO pat = this.remoteManager.registerPatient(id, nif, name, surname, password, email);
|
||||
|
||||
break;
|
||||
case FAMILY_DOCTOR:
|
||||
FamilyDoctorTO fd = this.remoteManager.registerFamilyDoctor1(id, nif, name, surname, password, email, null);
|
||||
|
||||
break;
|
||||
case SPECIALIST_DOCTOR:
|
||||
SpecialistDoctorTO sd = this.remoteManager.registerSpecialistDoctor(id, nif, name, surname, password, email, null);
|
||||
|
||||
break;
|
||||
case ADMINISTRADOR:
|
||||
throw new NotSupportedException("No se soporta el registro directo de administradores.");
|
||||
}
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Alta realizada",
|
||||
"El usuario " + name + " " + surname + " se ha registrado correctamente. Por favor, comprueba su correo electrónico para verificar su cuenta.");
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// FacesContext.getCurrentInstance().addMessage(null, msg);
|
||||
}
|
||||
|
||||
private void addFacesMessage(FacesMessage.Severity severity, String summary, String detail) {
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, summary, detail));
|
||||
}
|
||||
|
||||
private void manageException(Exception ex) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Se ha producido un error inesperado", "Descripción del error: " + ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
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 String getmedicalSpecialty() {
|
||||
return medicalSpecialty;
|
||||
}
|
||||
|
||||
public void setmedicalSpecialty(String medicalSpecialty) {
|
||||
this.medicalSpecialty = medicalSpecialty;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package managedbean.systemAdmin;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user