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:
@@ -1,5 +1,6 @@
|
||||
package ejb.profile;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
@@ -10,6 +11,9 @@ import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import common.HashUtils;
|
||||
import ejb.common.CommonFacadeBean;
|
||||
import ejb.common.CommonFacadeLocal;
|
||||
import ejb.common.CommonFacadeRemote;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.MedicalSpecialtyJPA;
|
||||
import jpa.PatientJPA;
|
||||
@@ -27,6 +31,9 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
// Persistence Unit Context
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
|
||||
@EJB
|
||||
CommonFacadeLocal commonServices;
|
||||
|
||||
public PatientTO changeFamilyDoctor(int patientId, int ProfessionalNumberId) throws Exception {
|
||||
PatientJPA pat = entman.find(PatientJPA.class, patientId);
|
||||
@@ -44,7 +51,8 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
pat.setFamilyDoctor(fd);
|
||||
entman.persist(pat);
|
||||
|
||||
return this.retrievePatient(pat.getId());
|
||||
//CommonFacadeRemote common = new CommonFacadeBean();
|
||||
return commonServices.retrievePatient(pat.getId());
|
||||
}
|
||||
|
||||
public PatientTO registerPatient(int id, String nif, String name, String surname, String password, String email) {
|
||||
@@ -188,50 +196,4 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,5 @@ public interface ProfileFacadeRemote {
|
||||
public FamilyDoctorTO updateFamilyDoctorData(int id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO cap) throws Exception;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -32,62 +32,6 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public LoggedUserTO login(String id, String pwd) {
|
||||
LoggedUserTO usr = null;
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@ public interface SystemAdminFacadeRemote {
|
||||
/**
|
||||
* Definimos la interfaz remota
|
||||
*/
|
||||
public Collection<MedicalSpecialtyTO> listAllMedicalSpecialities();
|
||||
|
||||
public Collection<PrimaryHealthCareCenterTO> listAllCAPs();
|
||||
|
||||
public LoggedUserTO login(String id, String pwd);
|
||||
}
|
||||
Reference in New Issue
Block a user