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:
@@ -28,147 +28,204 @@ public class ProfileFacadeBean implements ProfileFacadeRemote {
|
||||
@PersistenceContext(unitName = "MyHealth")
|
||||
private EntityManager entman;
|
||||
|
||||
public PatientTO changeFamilyDoctor(Integer id, Integer ProfessionalNumberId) {
|
||||
PatientTO paTO = null;
|
||||
public PatientTO changeFamilyDoctor(int patientId, int ProfessionalNumberId) 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);
|
||||
PatientJPA pa = entman.find(PatientJPA.class, id);
|
||||
|
||||
if (fd != null && pa != null) {
|
||||
pa.setFamilyDoctor(fd);
|
||||
paTO = new PatientTO();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return paTO;
|
||||
}
|
||||
|
||||
public PatientTO registerPatient(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
PatientTO paTO = null;
|
||||
pat.setFamilyDoctor(fd);
|
||||
entman.persist(pat);
|
||||
|
||||
if (id == null)
|
||||
id = 1;
|
||||
return this.retrievePatient(pat.getId());
|
||||
}
|
||||
|
||||
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());
|
||||
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);
|
||||
entman.persist(pat);
|
||||
paTO = new PatientTO(pat.getId(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), null);
|
||||
|
||||
return paTO;
|
||||
}
|
||||
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty) {
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
|
||||
public SpecialistDoctorTO registerSpecialistDoctor(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty)
|
||||
throws Exception {
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, 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);
|
||||
entman.persist(sd);
|
||||
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail());
|
||||
if (ms == null) {
|
||||
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);
|
||||
entman.persist(sd);
|
||||
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
|
||||
|
||||
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;
|
||||
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, cap.getName());
|
||||
|
||||
// TODO: Lanzar error si no encontramos el cap!!!!!
|
||||
if (phcC != null) {
|
||||
|
||||
FamilyDoctorJPA fd = new FamilyDoctorJPA(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());
|
||||
if (phcC == null) {
|
||||
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);
|
||||
entman.persist(fd);
|
||||
|
||||
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), cap);
|
||||
|
||||
return fdTO;
|
||||
}
|
||||
|
||||
public PatientTO updatePacientData(Integer id, String nif, String name, String surname, String password, String email) {
|
||||
PatientJPA fd = entman.find(PatientJPA.class, id);
|
||||
PatientTO ptTO = null;
|
||||
public PatientTO updatePatientData(int id, String nif, String name, String surname, String password, String email) throws Exception {
|
||||
PatientJPA pat = entman.find(PatientJPA.class, id);
|
||||
|
||||
if (fd != null) {
|
||||
fd.setNif(nif);
|
||||
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());
|
||||
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(id));
|
||||
}
|
||||
|
||||
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) {
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
|
||||
public SpecialistDoctorTO updateSpecialistDoctorData(int id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO specialty)
|
||||
throws Exception {
|
||||
SpecialistDoctorJPA sd = entman.find(SpecialistDoctorJPA.class, id);
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, specialty.getName());
|
||||
|
||||
// TODO: Lanzar error al no encontrar la especialidad indicada ?????
|
||||
|
||||
if (sd != null && ms != null) {
|
||||
sd.setNif(nif);
|
||||
sd.setName(name);
|
||||
sd.setSurname(surname);
|
||||
sd.setPassword(HashUtils.hashMD5(password));
|
||||
sd.setEmail(email);
|
||||
sd.setMedicalSpecialty(ms);
|
||||
|
||||
entman.persist(sd);
|
||||
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail());
|
||||
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());
|
||||
if (ms == null) {
|
||||
throw new Exception("No se encuentra la especialidad médica con identificador: " + specialty.getName());
|
||||
}
|
||||
|
||||
sd.setNif(nif);
|
||||
sd.setName(name);
|
||||
sd.setSurname(surname);
|
||||
sd.setPassword(HashUtils.hashMD5(password));
|
||||
sd.setEmail(email);
|
||||
sd.setMedicalSpecialty(ms);
|
||||
|
||||
entman.persist(sd);
|
||||
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), specialty);
|
||||
|
||||
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);
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
if (fd != null) {
|
||||
fd.setNif(nif);
|
||||
fd.setName(name);
|
||||
fd.setSurname(surname);
|
||||
fd.setPassword(HashUtils.hashMD5(password));
|
||||
fd.setEmail(email);
|
||||
|
||||
// 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);
|
||||
|
||||
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail());
|
||||
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());
|
||||
}
|
||||
|
||||
fd.setNif(nif);
|
||||
fd.setName(name);
|
||||
fd.setSurname(surname);
|
||||
fd.setPassword(HashUtils.hashMD5(password));
|
||||
fd.setEmail(email);
|
||||
fd.setPrimaryHealthCareCenter(phcC);
|
||||
|
||||
entman.persist(fd);
|
||||
|
||||
FamilyDoctorTO fdTO = null;
|
||||
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), phcTO);
|
||||
|
||||
return fdTO;
|
||||
}
|
||||
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(Integer FamilyDoctorId, PrimaryHealthCareCenterTO newCenter) {
|
||||
public FamilyDoctorTO changePrimaryHealthCareCenter(int professionalId, PrimaryHealthCareCenterTO newCenter) throws Exception {
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
PrimaryHealthCareCenterJPA phcC = entman.find(PrimaryHealthCareCenterJPA.class, newCenter);
|
||||
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, FamilyDoctorId);
|
||||
|
||||
if (phcC != null && fd != null) {
|
||||
fd.setPrimaryHealthCareCenter(phcC);
|
||||
fdTO = new FamilyDoctorTO(fd.getId(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail());
|
||||
|
||||
FamilyDoctorJPA fd = entman.find(FamilyDoctorJPA.class, professionalId);
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,25 @@ import TO.SpecialistDoctorTO;
|
||||
@Remote
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user