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

View File

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