Nueva funcionalidad (vista, controlador y persistencia) de cambiar

medico de familia asignado.
Incluidos cambios para utilizar nuvo EJB Common con interfaz local y
remota.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-09 23:08:45 +01:00
parent 57855362f6
commit 4c7c978ccd
11 changed files with 165 additions and 162 deletions

View File

@@ -1,50 +1,114 @@
package managedbean.profile;
import java.io.Serializable;
import java.util.Properties;
import java.util.Collection;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import ejb.profile.ProfileFacadeRemote;
import TO.FamilyDoctorTO;
import TO.LoggedUserTO;
import TO.PatientTO;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
/***
*
* @author Marcos García Núñez (mgarcianun@uoc.edu)
*
*/
@Named( "ChangeFamilyDoctorMBean")
@RequestScoped
@Named("ChangeFD")
@ViewScoped
public class ChangeFamilyDoctorMBean extends ManagedBeanBase implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private ProfileFacadeRemote remoteManager;
private int id;
private FamilyDoctorTO currentFamilyDoctor;
private FamilyDoctorTO newFamilyDoctor;
private Collection<FamilyDoctorTO> familyDoctorList;
public ChangeFamilyDoctorMBean() {
/**
* Constructor. Inicializa la conexión con el EJB Remoto
*
* @throws Exception
*/
public ChangeFamilyDoctorMBean() throws Exception {
initializeAdminFacadeRemote();
}
/**
* 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");
@PostConstruct
public void init() {
// 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.id = Integer.valueOf(usr.getId());
if (usr.getUserType() == UserType.PATIENT) {
this.familyDoctorList = this.getRemoteManagerCommon().listAllFamilyDoctors();
PatientTO pat = this.getRemoteManagerCommon().retrievePatient(this.id);
this.setCurrentFamilyDoctor(pat.getFamilyDoctor());
}
}
} catch (Exception e) {
this.manageException(e);
}
}
public Collection<FamilyDoctorTO> getFamilyDoctorList() {
return familyDoctorList;
}
public int getId() {
return id;
}
public void saveData() {
int error = 0;
if (this.getNewFamilyDoctor() == null) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nuevo médico de familia no seleccionado", "Por favor, especifique un nuevvo médico de familia.");
error++;
}
if (this.getCurrentFamilyDoctor() != null && this.getNewFamilyDoctor().getId() == this.getCurrentFamilyDoctor().getId()) {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El médico de familia debe ser diferente",
"Por favor, seleccione un médico de familia diferente al que tiene actualmente asignado.");
error++;
}
if (error == 0) {
try {
PatientTO paTO = this.getRemoteManagerProfile().changeFamilyDoctor(this.getId(), this.newFamilyDoctor.getId());
this.currentFamilyDoctor = paTO.getFamilyDoctor();
this.newFamilyDoctor = null;
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Su médico de familia asignado se ha cambiado correctamente.");
} catch (Exception e) {
this.manageException(e);
}
}
}
public FamilyDoctorTO getCurrentFamilyDoctor() {
return currentFamilyDoctor;
}
public void setCurrentFamilyDoctor(FamilyDoctorTO familyDoctor) {
this.currentFamilyDoctor = familyDoctor;
}
public FamilyDoctorTO getNewFamilyDoctor() {
return newFamilyDoctor;
}
public void setNewFamilyDoctor(FamilyDoctorTO familyDoctor) {
this.newFamilyDoctor = familyDoctor;
}
}

View File

@@ -48,9 +48,9 @@ public class ChangePrimaryHealthCareCenterMBean extends ManagedBeanBase implemen
this.id = Integer.valueOf(usr.getId());
if (usr.getUserType() == UserType.FAMILY_DOCTOR) {
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listAllCAPs();
FamilyDoctorTO fd = this.getRemoteManagerProfile().retrieveFamilyDoctor(this.id);
FamilyDoctorTO fd = this.getRemoteManagerCommon().retrieveFamilyDoctor(this.id);
this.setCurrentCenter(fd.getPrimaryHealthCareCenter());
}
}

View File

@@ -67,8 +67,8 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable {
this.userType = UserType.PATIENT.name();
this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities();
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listAllMedicalSpecialities();
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listAllCAPs();
}
public List<UserType> getUserTypes() {

View File

@@ -87,7 +87,7 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
switch (usr.getUserType()) {
case PATIENT:
PatientTO pat = this.getRemoteManagerProfile().retrievePatient(this.id);
PatientTO pat = this.getRemoteManagerCommon().retrievePatient(this.id);
this.name = pat.getName();
this.surname = pat.getName();
@@ -96,8 +96,8 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.currentPassword = pat.getPassword();
break;
case SPECIALIST_DOCTOR:
this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities();
SpecialistDoctorTO sd = this.getRemoteManagerProfile().retrieveSpecialistDoctor(this.id);
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listAllMedicalSpecialities();
SpecialistDoctorTO sd = this.getRemoteManagerCommon().retrieveSpecialistDoctor(this.id);
this.name = sd.getName();
this.surname = sd.getName();
@@ -107,8 +107,8 @@ public class UpdateProfileMBean extends ManagedBeanBase implements Serializable
this.medicalSpecialty = sd.getMedicalSpecialty();
break;
case FAMILY_DOCTOR:
this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs();
FamilyDoctorTO fd = this.getRemoteManagerProfile().retrieveFamilyDoctor(this.id);
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listAllCAPs();
FamilyDoctorTO fd = this.getRemoteManagerCommon().retrieveFamilyDoctor(this.id);
this.name = fd.getName();
this.surname = fd.getName();