Multiples cambios para soportar la utilización de códigos de usuario

únicos para (Pacientes, medicos de familia, medicos especialista y
administradores).
Nuevos métodos en EJB común para consultar Entidades por Id y por código
(Para el login).
This commit is contained in:
Marcos Garcia Nuñez
2019-12-11 21:47:44 +01:00
parent acdc195828
commit 28b1192036
19 changed files with 366 additions and 164 deletions

View File

@@ -4,16 +4,16 @@ import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import TO.FamilyDoctorTO;
import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.SpecialistDoctorTO;
import common.Constants;
import common.HashUtils;
import ejb.common.CommonFacadeBean;
import ejb.common.CommonFacadeLocal;
import ejb.common.CommonFacadeRemote;
import jpa.FamilyDoctorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PatientJPA;
@@ -31,36 +31,46 @@ 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 {
@EJB
CommonFacadeLocal commonServices;
private String getNextProfessionalNumber() {
Query q = entman.createNativeQuery("select nextval('myhealth.profesionalnumber')");
return Constants.PROFESSIONAL_NUMBER_PREFIX.concat(String.valueOf(q.getSingleResult()));
}
private String getNextPersonalIdentificationCode() {
Query q = entman.createNativeQuery("select nextval('myhealth.profesionalnumber')");
return Constants.PERSONAL_IDENTIFICATION_CODE_PREFIX.concat(String.valueOf(q.getSingleResult()));
}
public PatientTO changeFamilyDoctor(int patientId, int newDoctor) 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));
}
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, ProfessionalNumberId);
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, newDoctor);
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(ProfessionalNumberId));
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(newDoctor));
}
PatientTO paTO = null;
pat.setFamilyDoctor(fd);
entman.persist(pat);
//CommonFacadeRemote common = new CommonFacadeBean();
return commonServices.retrievePatient(pat.getId());
// CommonFacadeRemote common = new CommonFacadeBean();
return commonServices.findPatientById(pat.getId());
}
public PatientTO registerPatient(int id, String nif, String name, String surname, String password, String email) {
PatientTO paTO = null;
PatientJPA pat = new PatientJPA(nif, name, surname, HashUtils.hashMD5(password), email, null);
PatientJPA pat = new PatientJPA(this.getNextPersonalIdentificationCode(), nif, name, surname, HashUtils.hashMD5(password), email, null);
entman.persist(pat);
paTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
paTO = new PatientTO(pat.getId(), this.getNextPersonalIdentificationCode(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
return paTO;
}
@@ -72,11 +82,11 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
throw new Exception("No se encuentra la especialidad médica con identificador: " + specialty.getName());
}
SpecialistDoctorJPA sd = new SpecialistDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, ms);
SpecialistDoctorJPA sd = new SpecialistDoctorJPA(this.getNextProfessionalNumber(), nif, name, surname, HashUtils.hashMD5(password), email, ms);
entman.persist(sd);
SpecialistDoctorTO sdTO = null;
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
sdTO = new SpecialistDoctorTO(sd.getId(), this.getNextProfessionalNumber(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
return sdTO;
}
@@ -89,10 +99,10 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
throw new Exception("No se encuentra el centro de atención primaria con identificador: " + cap.getName());
}
FamilyDoctorJPA fd = new FamilyDoctorJPA(nif, name, surname, HashUtils.hashMD5(password), email, phcC);
FamilyDoctorJPA fd = new FamilyDoctorJPA(this.getNextProfessionalNumber(), nif, name, surname, HashUtils.hashMD5(password), email, phcC);
entman.persist(fd);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), cap);
fdTO = new FamilyDoctorTO(fd.getId(), this.getNextProfessionalNumber(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), cap);
return fdTO;
}
@@ -115,7 +125,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
entman.persist(pat);
PatientTO patTO = null;
patTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
patTO = new PatientTO(pat.getId(), pat.getPersonalIdentificationCode(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
return patTO;
}
@@ -144,7 +154,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
entman.persist(sd);
SpecialistDoctorTO sdTO = null;
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getProfessionalNumber(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
return sdTO;
}
@@ -172,7 +182,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
entman.persist(fd);
FamilyDoctorTO fdTO = null;
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), phcTO);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getProfessionalNumber(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), phcTO);
return fdTO;
}
@@ -192,7 +202,7 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
fd.setPrimaryHealthCareCenter(phcC);
entman.persist(fd);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), newCenter);
fdTO = new FamilyDoctorTO(fd.getId(), fd.getProfessionalNumber(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), newCenter);
return fdTO;
}

View File

@@ -16,7 +16,7 @@ import TO.SpecialistDoctorTO;
@Remote
public interface ProfileFacadeRemote {
public PatientTO changeFamilyDoctor(int id, int ProfessionalNumberId) throws Exception;
public PatientTO changeFamilyDoctor(int id, int newDoctor) throws Exception;
public PatientTO registerPatient(int id, String nif, String name, String surname, String password, String email);