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:
Marcos Garcia Nuñez
2019-12-08 22:26:15 +01:00
parent f8d69e9e12
commit e718afeb3a
12 changed files with 560 additions and 153 deletions

View File

@@ -21,7 +21,7 @@
} }
} }
</h:outputScript> </h:outputScript>
<h:form id="frmRegisterUser"> <h:form id="frmUpdateProfile">
<p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" /> <p:messages id="mesgs" showDetail="true" closable="true" autoupdate="true" />
<p:panel id="tipoUsuario" header="Tipo de usuario registrado"> <p:panel id="tipoUsuario" header="Tipo de usuario registrado">
@@ -30,9 +30,9 @@
<p:outputLabel value="Tipo de usuario:" for="selUsertype" /> <p:outputLabel value="Tipo de usuario:" for="selUsertype" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:selectOneButton id="selUsertype" value="#{RegisterUser.userType}" disabled="true" required="true" unselectable="false" <p:selectOneButton id="selUsertype" value="#{UpdateProfile.userType}" disabled="true" required="true" unselectable="false"
requiredMessage="Debe especificar un tipo de usuario"> requiredMessage="Debe especificar un tipo de usuario">
<f:selectItems value="#{RegisterUser.userTypes}" var="item" itemLabel="#{item.userTypename}" itemValue="#{item.name}" /> <f:selectItems value="#{UpdateProfile.userTypes}" var="item" itemLabel="#{item.userTypename}" itemValue="#{item.name}" />
</p:selectOneButton> </p:selectOneButton>
</div> </div>
<div class="ui-g-4 ui-md-4"></div> <div class="ui-g-4 ui-md-4"></div>
@@ -43,11 +43,11 @@
<div class="ui-g ui-fluid"> <div class="ui-g ui-fluid">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<h:outputLabel value="value = 10" rendered="#{row == 10}" /> <h:outputLabel value="value = 10" rendered="#{row == 10}" />
<p:outputLabel value="Código de Identificación Personal (CIP):" rendered="#{RegisterUser.patient}" for="id" /> <p:outputLabel value="Código de Identificación Personal (CIP):" rendered="#{UpdateProfile.patient}" for="id" />
<p:outputLabel value="Número de Profesional:" rendered="#{RegisterUser.familyDoctor or RegisterUser.specialistDoctor}" for="id" /> <p:outputLabel value="Número de Profesional:" rendered="#{UpdateProfile.familyDoctor or UpdateProfile.specialistDoctor}" for="id" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="id" value="#{RegisterUser.id}" disabled="true" required="true" requiredMessage="Por favor, indque su identificador" /> <p:inputText id="id" value="#{UpdateProfile.id}" disabled="true" required="true" requiredMessage="Por favor, indque su identificador" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="id" display="text" /> <p:message for="id" display="text" />
@@ -57,7 +57,7 @@
<p:outputLabel value="NIF:" for="nif" /> <p:outputLabel value="NIF:" for="nif" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="nif" value="#{RegisterUser.nif}" required="true" requiredMessage="Por favor, indque su NIF" /> <p:inputText id="nif" value="#{UpdateProfile.nif}" required="true" requiredMessage="Por favor, indque su NIF" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="nif" display="text" /> <p:message for="nif" display="text" />
@@ -67,7 +67,7 @@
<p:outputLabel value="Nombre:" for="name" /> <p:outputLabel value="Nombre:" for="name" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="name" value="#{RegisterUser.name}" required="true" requiredMessage="Por favor, indique su nombre" /> <p:inputText id="name" value="#{UpdateProfile.name}" required="true" requiredMessage="Por favor, indique su nombre" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="name" /> <p:message for="name" />
@@ -77,7 +77,7 @@
<p:outputLabel value="Apellidos:" for="surname" /> <p:outputLabel value="Apellidos:" for="surname" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="surname" value="#{RegisterUser.surname}" required="true" requiredMessage="Por favor, indique sus apellidos" /> <p:inputText id="surname" value="#{UpdateProfile.surname}" required="true" requiredMessage="Por favor, indique sus apellidos" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="surname" /> <p:message for="surname" />
@@ -87,7 +87,7 @@
<p:outputLabel value="Correo electrónico:" for="email" /> <p:outputLabel value="Correo electrónico:" for="email" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:inputText id="email" value="#{RegisterUser.email}" required="true" requiredMessage="Por favor, especifique su correo electrónico" /> <p:inputText id="email" value="#{UpdateProfile.email}" required="true" requiredMessage="Por favor, especifique su correo electrónico" />
</div> </div>
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="email" /> <p:message for="email" />
@@ -96,7 +96,7 @@
<p:outputLabel value="Contraseña" for="password" /> <p:outputLabel value="Contraseña" for="password" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:password id="password" value="#{RegisterUser.password}" match="passwordRepeat" required="true" requiredMessage="Por favor, especifique una contraseña" maxlength="50" <p:password id="password" value="#{UpdateProfile.password}" match="passwordRepeat" required="false" requiredMessage="Por favor, especifique una contraseña" maxlength="50"
feedback="true" promptLabel="Especifique una contraseña segura" weakLabel="La contraseña es débil" goodLabel="La contraseña es buena" strongLabel="La contraseña es segura" feedback="true" promptLabel="Especifique una contraseña segura" weakLabel="La contraseña es débil" goodLabel="La contraseña es buena" strongLabel="La contraseña es segura"
validatorMessage="La contraseña y su verificación deben ser iguales" /> validatorMessage="La contraseña y su verificación deben ser iguales" />
</div> </div>
@@ -107,21 +107,21 @@
<p:outputLabel value="Verificación de contraseña:" for="passwordRepeat" /> <p:outputLabel value="Verificación de contraseña:" for="passwordRepeat" />
</div> </div>
<div class="ui-g-4"> <div class="ui-g-4">
<p:password id="passwordRepeat" value="#{RegisterUser.password}" required="true" requiredMessage="Por favor, escriba la verificación de su contraseña" maxlength="50" /> <p:password id="passwordRepeat" value="#{UpdateProfile.password}" required="false" requiredMessage="Por favor, escriba la verificación de su contraseña" maxlength="50" />
</div> </div>
<div class="ui-g-6"> <div class="ui-g-6">
<p:message for="passwordRepeat" /> <p:message for="passwordRepeat" />
</div> </div>
<div id="panCentros" class="ui-g-12 ui-g-nopad hide"> <h:panelGroup id="panCentros" layout="block" class="ui-g-12 ui-g-nopad" rendered="#{UpdateProfile.familyDoctor}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Centro:" for="selPHC" /> <p:outputLabel value="Centro:" for="selPHC" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:selectOneMenu id="selPHC" value="#{RegisterUser.primaryHealthCareCenter}" converter="omnifaces.SelectItemsConverter" required="#{RegisterUser.familyDoctor}" <p:selectOneMenu id="selPHC" value="#{UpdateProfile.primaryHealthCareCenter}" converter="omnifaces.SelectItemsConverter" required="#{UpdateProfile.familyDoctor}"
requiredMessage="Por favor, selecciona un centro de antención primaria"> requiredMessage="Por favor, selecciona un centro de antención primaria">
<f:selectItem itemLabel="Seleccione un centro de antención primario..." itemValue="" noSelectionOption="true" /> <f:selectItem itemLabel="Seleccione un centro de antención primario..." itemValue="" noSelectionOption="true" />
<f:selectItems value="#{RegisterUser.phcList}" var="phc" itemLabel="#{phc.location}" itemValue="#{phc}" /> <f:selectItems value="#{UpdateProfile.phcList}" var="phc" itemLabel="#{phc.location}" itemValue="#{phc}" />
<p:column>#{phc.name}</p:column> <p:column>#{phc.name}</p:column>
<p:column>#{phc.location}</p:column> <p:column>#{phc.location}</p:column>
</p:selectOneMenu> </p:selectOneMenu>
@@ -129,17 +129,17 @@
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="selPHC" /> <p:message for="selPHC" />
</div> </div>
</div> </h:panelGroup>
<div id="panEspecialidades" class="ui-g-12 ui-g-nopad hide"> <h:panelGroup id="panEspecialidades" layout="block" class="ui-g-12 ui-g-nopad" rendered="#{UpdateProfile.specialistDoctor}">
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:outputLabel value="Especialidad médica:" for="selMS" /> <p:outputLabel value="Especialidad médica:" for="selMS" />
</div> </div>
<div class="ui-g-4 ui-md-4"> <div class="ui-g-4 ui-md-4">
<p:selectOneMenu id="selMS" value="#{RegisterUser.medicalSpecialty}" converter="omnifaces.SelectItemsConverter" required="#{RegisterUser.specialistDoctor}" <p:selectOneMenu id="selMS" value="#{UpdateProfile.medicalSpecialty}" converter="omnifaces.SelectItemsConverter" required="#{UpdateProfile.specialistDoctor}"
requiredMessage="Por favor, seleccione una especialidad médica"> requiredMessage="Por favor, seleccione una especialidad médica">
<f:selectItem itemLabel="Seleccione una especialidad médica..." itemValue="" noSelectionOption="true" /> <f:selectItem itemLabel="Seleccione una especialidad médica..." itemValue="" noSelectionOption="true" />
<f:selectItems value="#{RegisterUser.medicalSpecialtiesList}" var="ms" itemLabel="#{ms.description}" itemValue="#{ms}" /> <f:selectItems value="#{UpdateProfile.medicalSpecialtiesList}" var="ms" itemLabel="#{ms.description}" itemValue="#{ms}" />
<p:column>#{ms.name}</p:column> <p:column>#{ms.name}</p:column>
<p:column>#{ms.description}</p:column> <p:column>#{ms.description}</p:column>
</p:selectOneMenu> </p:selectOneMenu>
@@ -147,12 +147,12 @@
<div class="ui-g-6 ui-md-6"> <div class="ui-g-6 ui-md-6">
<p:message for="selMS" /> <p:message for="selMS" />
</div> </div>
</div> </h:panelGroup>
<div class="ui-g-12 ui-g-nopad"> <div class="ui-g-12 ui-g-nopad">
<div class="ui-g-4 ui-md-4"></div> <div class="ui-g-4 ui-md-4"></div>
<div class="ui-g-2 ui-md-2 "> <div class="ui-g-2 ui-md-2 ">
<p:commandButton validateClient="true" value="Registrarse" update="mesgs" action="#{RegisterUser.addNewUser}" icon="pi pi-check" /> <p:commandButton validateClient="true" value="Guardar" update="mesgs" action="#{UpdateProfile.saveData}" icon="pi pi-check" />
</div> </div>
<div class="ui-g-2 ui-md-2"> <div class="ui-g-2 ui-md-2">
<p:button value="Volver" outcome="/home" icon="pi pi-home" /> <p:button value="Volver" outcome="/home" icon="pi pi-home" />

View File

@@ -19,18 +19,20 @@ public class FamilyDoctorTO implements Serializable {
private String surname; private String surname;
private String password; private String password;
private String email; private String email;
private PrimaryHealthCareCenterTO primaryHealthCareCenter;
public FamilyDoctorTO() { public FamilyDoctorTO() {
super(); super();
} }
public FamilyDoctorTO(Integer 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, PrimaryHealthCareCenterTO phc) {
this.setId(id); this.setId(id);
this.setNif(nif); this.setNif(nif);
this.setName(name); this.setName(name);
this.setSurname(surname); this.setSurname(surname);
this.setPassword(password); this.setPassword(password);
this.setEmail(email); this.setEmail(email);
this.setPrimaryHealthCareCenter(phc);
} }
public String getEmail() { public String getEmail() {
@@ -81,4 +83,12 @@ public class FamilyDoctorTO implements Serializable {
this.id = id; this.id = id;
} }
public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() {
return primaryHealthCareCenter;
}
public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) {
this.primaryHealthCareCenter = primaryHealthCareCenter;
}
} }

View File

@@ -30,13 +30,14 @@ public class PatientTO implements Serializable {
super(); super();
} }
public PatientTO(Integer 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, FamilyDoctorTO familyDoc) {
this.setId(id); this.setId(id);
this.setNif(nif); this.setNif(nif);
this.setName(name); this.setName(name);
this.setSurname(surname); this.setSurname(surname);
this.setPassword(password); this.setPassword(password);
this.setEmail(email); this.setEmail(email);
this.setFamilyDoctor(familyDoc);
} }
public String getEmail() { public String getEmail() {
@@ -87,5 +88,13 @@ public class PatientTO implements Serializable {
this.id = id; this.id = id;
} }
public FamilyDoctorTO getFamilyDoctor() {
return familyDoctor;
}
public void setFamilyDoctor(FamilyDoctorTO familyDoctor) {
this.familyDoctor = familyDoctor;
}
} }

View File

@@ -19,18 +19,20 @@ public class SpecialistDoctorTO implements Serializable {
private String surname; private String surname;
private String password; private String password;
private String email; private String email;
private MedicalSpecialtyTO medicalSpecialty;
public SpecialistDoctorTO() { public SpecialistDoctorTO() {
super(); super();
} }
public SpecialistDoctorTO(Integer 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, MedicalSpecialtyTO medicalSpec) {
this.setId(id); this.setId(id);
this.setNif(nif); this.setNif(nif);
this.setName(name); this.setName(name);
this.setSurname(surname); this.setSurname(surname);
this.setPassword(password); this.setPassword(password);
this.setEmail(email); this.setEmail(email);
this.setMedicalSpecialty(medicalSpec);
} }
public String getEmail() { public String getEmail() {
@@ -81,4 +83,12 @@ public class SpecialistDoctorTO implements Serializable {
this.id = id; this.id = id;
} }
public MedicalSpecialtyTO getMedicalSpecialty() {
return medicalSpecialty;
}
public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) {
this.medicalSpecialty = medicalSpecialty;
}
} }

View File

@@ -28,95 +28,100 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
@PersistenceContext(unitName = "MyHealth") @PersistenceContext(unitName = "MyHealth")
private EntityManager entman; private EntityManager entman;
public PatientTO changeFamilyDoctor(Integer id, Integer ProfessionalNumberId) { public PatientTO changeFamilyDoctor(int patientId, int ProfessionalNumberId) throws Exception {
PatientTO paTO = null; PatientJPA pat = entman.find(PatientJPA.class, patientId);
if (pat == null) {
throw new Exception("No se pueden actualizar los datos del paciente porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(patientId));
}
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, ProfessionalNumberId); FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, ProfessionalNumberId);
PatientJPA pa = entman.find(PatientJPA.class, id); if (fd == null) {
throw new Exception("No se pueden actualizar los datos del médico de familia porque no se encuentra en la base de datos ningún registro con id: "
if (fd != null && pa != null) { + String.valueOf(ProfessionalNumberId));
pa.setFamilyDoctor(fd);
paTO = new PatientTO();
} }
return paTO; PatientTO paTO = null;
pat.setFamilyDoctor(fd);
entman.persist(pat);
return this.retrievePatient(pat.getId());
} }
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email) { public PatientTO registerPatient(int id, String nif, String name, String surname, String password, String email) {
PatientTO paTO = null; PatientTO paTO = null;
if (id == null) PatientJPA pat = new PatientJPA(nif, name, surname, HashUtils.hashMD5(password), email, null);
id = 1; entman.persist(pat);
paTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
PatientJPA ms = new PatientJPA(nif, name, surname, HashUtils.hashMD5(password), email);
entman.persist(ms);
paTO = new PatientTO(ms.getId(), ms.getNif(), ms.getName(), ms.getSurname(), ms.getPassword(), ms.getEmail());
return paTO; return paTO;
} }
public SpecialistDoctorTO registerSpecialistDoctor(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty) { public SpecialistDoctorTO registerSpecialistDoctor(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty)
SpecialistDoctorTO sdTO = null; throws Exception {
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName()); MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName());
if (ms == null) {
throw new Exception("No se encuentra la especialidad médica con identificador: " + specialty.getName());
}
// TODO: Lanzar error si no se encuentra la especialidad.
if (ms != null) {
SpecialistDoctorJPA sd = new SpecialistDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, ms); SpecialistDoctorJPA sd = new SpecialistDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, ms);
entman.persist(sd); entman.persist(sd);
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail()); SpecialistDoctorTO sdTO = null;
} sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
return sdTO; return sdTO;
} }
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) { public FamilyDoctorTO registerFamilyDoctor(int id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) throws Exception {
FamilyDoctorTO fdTO = null; FamilyDoctorTO fdTO = null;
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap.getName()); PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap.getName());
if (phcC == null) {
// TODO: Lanzar error si no encontramos el cap!!!!! throw new Exception("No se encuentra el centro de atención primaria con identificador: " + cap.getName());
if (phcC != null) { }
FamilyDoctorJPA fd = new FamilyDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, phcC); FamilyDoctorJPA fd = new FamilyDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, phcC);
entman.persist(fd); entman.persist(fd);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail()); fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), cap);
}
return fdTO; return fdTO;
} }
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email) { public PatientTO updatePatientData(int id, String nif, String name, String surname, String password, String email) throws Exception {
PatientJPA fd = entman.find(PatientJPA.class, id); PatientJPA pat = entman.find(PatientJPA.class, id);
PatientTO ptTO = null;
if (fd != null) { if (pat == null) {
fd.setNif(nif); throw new Exception("No se pueden actualizar los datos del paciente porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
fd.setName(name);
fd.setSurname(surname);
fd.setPassword(HashUtils.hashMD5(password));
fd.setEmail(email);
entman.persist(fd);
ptTO = new PatientTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail());
} }
return ptTO; pat.setNif(nif);
pat.setName(name);
pat.setSurname(surname);
pat.setPassword(HashUtils.hashMD5(password));
pat.setEmail(email);
entman.persist(pat);
PatientTO patTO = null;
patTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
return patTO;
} }
public SpecialistDoctorTO updateSpecialistDoctorData(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty) { public SpecialistDoctorTO updateSpecialistDoctorData(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty)
SpecialistDoctorTO sdTO = null; throws Exception {
SpecialistDoctorJPA sd = entman.find(SpecialistDoctorJPA.class, id); SpecialistDoctorJPA sd = entman.find(SpecialistDoctorJPA.class, id);
if (sd == null) {
throw new Exception("No se pueden actualizar los datos del médico de familia porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
}
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName()); MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName());
if (ms == null) {
throw new Exception("No se encuentra la especialidad médica con identificador: " + specialty.getName());
}
// TODO: Lanzar error al no encontrar la especialidad indicada ?????
if (sd != null && ms != null) {
sd.setNif(nif); sd.setNif(nif);
sd.setName(name); sd.setName(name);
sd.setSurname(surname); sd.setSurname(surname);
@@ -126,49 +131,101 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
entman.persist(sd); entman.persist(sd);
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail()); SpecialistDoctorTO sdTO = null;
} sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
return sdTO; return sdTO;
} }
public FamilyDoctorTO updateFamilyDoctorData(Integer id, String nif, String name, String surname, String password, String email, String cap) { public FamilyDoctorTO updateFamilyDoctorData(int id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO phcTO) throws Exception {
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, id); FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, id);
FamilyDoctorTO fdTO = null; if (fd == null) {
throw new Exception("No se pueden actualizar los datos del médico de familia porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
}
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, phcTO.getName());
if (phcC == null) {
throw new Exception("No se encuentra el centro de atención primaria con identificador: " + phcTO.getName());
}
if (fd != null) {
fd.setNif(nif); fd.setNif(nif);
fd.setName(name); fd.setName(name);
fd.setSurname(surname); fd.setSurname(surname);
fd.setPassword(HashUtils.hashMD5(password)); fd.setPassword(HashUtils.hashMD5(password));
fd.setEmail(email); fd.setEmail(email);
fd.setPrimaryHealthCareCenter(phcC);
// TODO: Es posible actualizar el cap? ¿No debería utilizar el método
// changePrimaryHealthCareCenter?
// cap debería ser PrimaryHealthCareCenterTO newCenter
// fd.setPrimaryHealthCareCenter(cap);
entman.persist(fd); entman.persist(fd);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail()); FamilyDoctorTO fdTO = null;
} fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), phcTO);
return fdTO; return fdTO;
} }
public FamilyDoctorTO changePrimaryHealthCareCenter(Integer FamilyDoctorId, PrimaryHealthCareCenterTO newCenter) { public FamilyDoctorTO changePrimaryHealthCareCenter(int professionalId, PrimaryHealthCareCenterTO newCenter) throws Exception {
FamilyDoctorTO fdTO = null; FamilyDoctorTO fdTO = null;
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, newCenter); FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, professionalId);
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, FamilyDoctorId); if (fd == null) {
throw new Exception("No se encuentra en la base de datos ningún médico de familia con id: " + String.valueOf(professionalId));
if (phcC != null && fd != null) {
fd.setPrimaryHealthCareCenter(phcC);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail());
} }
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, newCenter.getName());
if (phcC == null) {
throw new Exception("No se encuentra el centro de atención primaria con identificador: " + newCenter.getName());
}
fd.setPrimaryHealthCareCenter(phcC);
entman.persist(fd);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), newCenter);
return fdTO; return fdTO;
} }
public PatientTO retrievePatient(int patientId) throws Exception {
PatientJPA pat = entman.find(PatientJPA.class, patientId);
if (pat == null) {
throw new Exception("No se pueden actualizar los datos del paciente porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(patientId));
}
FamilyDoctorTO fdTO = null;
if (pat.getFamilyDoctor() != null) {
FamilyDoctorJPA fd = pat.getFamilyDoctor();
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), null);
}
PatientTO paTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), fdTO);
return paTO;
}
public FamilyDoctorTO retrieveFamilyDoctor(int ProfessionalNumberId) throws Exception {
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, ProfessionalNumberId);
if (fd == null) {
throw new Exception("No se encuentra en la base de datos ningún médico de familia con id: " + String.valueOf(ProfessionalNumberId));
}
PrimaryHealthCareCenterTO phc = null;
if (fd.getPrimaryHealthCareCenter() != null)
phc = new PrimaryHealthCareCenterTO(fd.getPrimaryHealthCareCenter().getName(), fd.getPrimaryHealthCareCenter().getLocation());
FamilyDoctorTO fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), phc);
return fdTO;
}
public SpecialistDoctorTO retrieveSpecialistDoctor(int professionalId) throws Exception {
SpecialistDoctorJPA sd = entman.find(SpecialistDoctorJPA.class, professionalId);
if (sd == null) {
throw new Exception(
"No se pueden actualizar los datos del médico de familia porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(professionalId));
}
MedicalSpecialtyTO ms = null;
if (sd.getMedicalSpecialty() != null)
ms = new MedicalSpecialtyTO(sd.getMedicalSpecialty().getName(), sd.getMedicalSpecialty().getDescription());
SpecialistDoctorTO sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), ms);
return sdTO;
}
} }

View File

@@ -16,19 +16,25 @@ import TO.SpecialistDoctorTO;
@Remote @Remote
public interface ProfileFacadeRemote { public interface ProfileFacadeRemote {
public PatientTO changeFamilyDoctor(Integer id, Integer ProfessionalNumberId); public PatientTO changeFamilyDoctor(int id, int ProfessionalNumberId) throws Exception;
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email); public PatientTO registerPatient(int 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(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty) throws Exception;
public FamilyDoctorTO registerFamilyDoctor1(Integer id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap); public FamilyDoctorTO registerFamilyDoctor(int id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) throws Exception;
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email); public PatientTO updatePatientData(int id, String nif, String name, String surname, String password, String email) throws Exception;
public SpecialistDoctorTO updateSpecialistDoctorData(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty); public SpecialistDoctorTO updateSpecialistDoctorData(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty) throws Exception;
public FamilyDoctorTO updateFamilyDoctorData(Integer id, String nif, String name, String surname, String password, String email, String cap); public FamilyDoctorTO updateFamilyDoctorData(int id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) throws Exception;
public FamilyDoctorTO changePrimaryHealthCareCenter(Integer id, PrimaryHealthCareCenterTO newCenter); public FamilyDoctorTO changePrimaryHealthCareCenter(int ProfessionalNumberId, PrimaryHealthCareCenterTO newCenter) throws Exception;
public PatientTO retrievePatient(int patientId) throws Exception;
public FamilyDoctorTO retrieveFamilyDoctor(int ProfessionalNumberId) throws Exception;
public SpecialistDoctorTO retrieveSpecialistDoctor(int ProfessionalNumberId) throws Exception;
} }

View File

@@ -26,13 +26,18 @@ public class FamilyDoctorJPA implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id @Id
private int id; @GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String nif; private String nif;
private String name; private String name;
private String surname; private String surname;
private String password; private String password;
private String email; private String email;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FamilyDoctorId")
private Collection<PatientJPA> patients; private Collection<PatientJPA> patients;
@ManyToOne
@JoinColumn (name="PrimaryHealthCareCenterId")
private PrimaryHealthCareCenterJPA primaryHealthCareCenter; private PrimaryHealthCareCenterJPA primaryHealthCareCenter;
/** /**
@@ -51,13 +56,11 @@ public class FamilyDoctorJPA implements Serializable {
this.primaryHealthCareCenter = phc; this.primaryHealthCareCenter = phc;
} }
@Id public Integer getId() {
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id; return id;
} }
public void setId(int value) { public void setId(Integer value) {
this.id = value; this.id = value;
} }
@@ -105,8 +108,6 @@ public class FamilyDoctorJPA implements Serializable {
* Metodos para get/set de relaciones (pacientes) * Metodos para get/set de relaciones (pacientes)
* @return * @return
*/ */
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FamilyDoctorId")
public Collection<PatientJPA> getPatients() { public Collection<PatientJPA> getPatients() {
return patients; return patients;
} }
@@ -115,8 +116,6 @@ public class FamilyDoctorJPA implements Serializable {
this.patients = patients; this.patients = patients;
} }
@ManyToOne
@JoinColumn (name="PrimaryHealthCareCenterId")
public PrimaryHealthCareCenterJPA getPrimaryHealthCareCenter() { public PrimaryHealthCareCenterJPA getPrimaryHealthCareCenter() {
return primaryHealthCareCenter; return primaryHealthCareCenter;
} }

View File

@@ -23,7 +23,7 @@ public class PatientJPA implements Serializable {
@Id @Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id; private Integer id;
private String nif; private String nif;
private String name; private String name;
private String surname; private String surname;
@@ -40,19 +40,20 @@ public class PatientJPA implements Serializable {
super(); super();
} }
public PatientJPA(String nif, String name, String surname, String password, String email) { public PatientJPA(String nif, String name, String surname, String password, String email, FamilyDoctorJPA familyDoc) {
this.nif = nif; this.nif = nif;
this.name = name; this.name = name;
this.surname = surname; this.surname = surname;
this.password = password; this.password = password;
this.email = email; this.email = email;
this.familyDoctor = familyDoc;
} }
public int getId() { public Integer getId() {
return id; return id;
} }
public void setId(int value) { public void setId(Integer value) {
this.id = value; this.id = value;
} }
@@ -96,9 +97,6 @@ public class PatientJPA implements Serializable {
this.email = email; this.email = email;
} }
/**
* Methods get/set persistent relationships
*/
public FamilyDoctorJPA getFamilyDoctor() { public FamilyDoctorJPA getFamilyDoctor() {
return familyDoctor; return familyDoctor;
} }

View File

@@ -22,12 +22,15 @@ public class SpecialistDoctorJPA implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id @Id
private int id; @GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String nif; private String nif;
private String name; private String name;
private String surname; private String surname;
private String password; private String password;
private String email; private String email;
@ManyToOne
@JoinColumn(name = "MedicalSpecialtyId")
private MedicalSpecialtyJPA medicalSpecialty; private MedicalSpecialtyJPA medicalSpecialty;
/** /**
@@ -46,13 +49,11 @@ public class SpecialistDoctorJPA implements Serializable {
this.medicalSpecialty = ms; this.medicalSpecialty = ms;
} }
@Id public Integer getId() {
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id; return id;
} }
public void setId(int value) { public void setId(Integer value) {
this.id = value; this.id = value;
} }
@@ -96,8 +97,6 @@ public class SpecialistDoctorJPA implements Serializable {
this.email = email; this.email = email;
} }
@ManyToOne
@JoinColumn(name = "MedicalSpecialtyId")
public MedicalSpecialtyJPA getMedicalSpecialty() { public MedicalSpecialtyJPA getMedicalSpecialty() {
return medicalSpecialty; return medicalSpecialty;
} }

View File

@@ -12,7 +12,7 @@ public class SessionUtils {
public static final String SESSION_VAR_USERNAME = "userName"; public static final String SESSION_VAR_USERNAME = "userName";
public static final String SESSION_VAR_USERID = "userId"; public static final String SESSION_VAR_USERID = "userId";
public static final String SESSION_VAR_USERTYPE = "userType"; public static final String SESSION_VAR_USERTYPE = "userType";
public static final String SESSION_VAR_USER = "loggedInUser"; public static final String SESSION_VAR_USER = "loggedOnUser";
public static HttpSession getSession() { public static HttpSession getSession() {
FacesContext ctx = FacesContext.getCurrentInstance(); FacesContext ctx = FacesContext.getCurrentInstance();
@@ -69,4 +69,12 @@ public class SessionUtils {
else else
return ""; return "";
} }
public static LoggedUserTO getloggedOnUser() {
HttpSession session = getSession();
if (session != null && session.getAttribute(SessionUtils.SESSION_VAR_USER) != null)
return LoggedUserTO.class.cast(session.getAttribute(SessionUtils.SESSION_VAR_USER));
else
return null;
}
} }

View File

@@ -205,7 +205,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
break; break;
case FAMILY_DOCTOR: case FAMILY_DOCTOR:
FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor1(id, nif, name, surname, password, email, this.primaryHealthCareCenter); FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor(id, nif, name, surname, password, email, this.primaryHealthCareCenter);
this.id = fd.getId(); this.id = fd.getId();
break; break;

View File

@@ -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;
}
}