diff --git a/1.sources/MyHealth/docroot/profile/UpdateProfile.xhtml b/1.sources/MyHealth/docroot/profile/UpdateProfile.xhtml index 974ecea..37a7300 100644 --- a/1.sources/MyHealth/docroot/profile/UpdateProfile.xhtml +++ b/1.sources/MyHealth/docroot/profile/UpdateProfile.xhtml @@ -21,7 +21,7 @@ } } - + @@ -30,24 +30,24 @@
- - +
-
+
- - + +
- +
@@ -57,7 +57,7 @@
- +
@@ -67,7 +67,7 @@
- +
@@ -77,7 +77,7 @@
- +
@@ -87,7 +87,7 @@
- +
@@ -96,7 +96,7 @@
-
@@ -107,21 +107,21 @@
- +
-
+
- - + #{phc.name} #{phc.location} @@ -129,17 +129,17 @@
-
+
-
+
- - + #{ms.name} #{ms.description} @@ -147,12 +147,12 @@
-
+
- +
diff --git a/1.sources/MyHealth/src/TO/FamilyDoctorTO.java b/1.sources/MyHealth/src/TO/FamilyDoctorTO.java index 6d50357..c37fef8 100644 --- a/1.sources/MyHealth/src/TO/FamilyDoctorTO.java +++ b/1.sources/MyHealth/src/TO/FamilyDoctorTO.java @@ -19,18 +19,20 @@ public class FamilyDoctorTO implements Serializable { private String surname; private String password; private String email; + private PrimaryHealthCareCenterTO primaryHealthCareCenter; public FamilyDoctorTO() { super(); } - public FamilyDoctorTO(Integer id, String nif, String name, String surname, String password, String email) { + public FamilyDoctorTO(Integer id, String nif, String name, String surname, String password, String email, PrimaryHealthCareCenterTO phc) { this.setId(id); this.setNif(nif); this.setName(name); this.setSurname(surname); this.setPassword(password); this.setEmail(email); + this.setPrimaryHealthCareCenter(phc); } public String getEmail() { @@ -81,4 +83,12 @@ public class FamilyDoctorTO implements Serializable { this.id = id; } + public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() { + return primaryHealthCareCenter; + } + + public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) { + this.primaryHealthCareCenter = primaryHealthCareCenter; + } + } diff --git a/1.sources/MyHealth/src/TO/PatientTO.java b/1.sources/MyHealth/src/TO/PatientTO.java index 144e532..69c555b 100644 --- a/1.sources/MyHealth/src/TO/PatientTO.java +++ b/1.sources/MyHealth/src/TO/PatientTO.java @@ -30,13 +30,14 @@ public class PatientTO implements Serializable { super(); } - public PatientTO(Integer id, String nif, String name, String surname, String password, String email) { + public PatientTO(Integer id, String nif, String name, String surname, String password, String email, FamilyDoctorTO familyDoc) { this.setId(id); this.setNif(nif); this.setName(name); this.setSurname(surname); this.setPassword(password); this.setEmail(email); + this.setFamilyDoctor(familyDoc); } public String getEmail() { @@ -85,6 +86,14 @@ public class PatientTO implements Serializable { public void setId(Integer id) { this.id = id; + } + + public FamilyDoctorTO getFamilyDoctor() { + return familyDoctor; + } + + public void setFamilyDoctor(FamilyDoctorTO familyDoctor) { + this.familyDoctor = familyDoctor; } diff --git a/1.sources/MyHealth/src/TO/SpecialistDoctorTO.java b/1.sources/MyHealth/src/TO/SpecialistDoctorTO.java index 944eec1..5397814 100644 --- a/1.sources/MyHealth/src/TO/SpecialistDoctorTO.java +++ b/1.sources/MyHealth/src/TO/SpecialistDoctorTO.java @@ -19,18 +19,20 @@ public class SpecialistDoctorTO implements Serializable { private String surname; private String password; private String email; + private MedicalSpecialtyTO medicalSpecialty; public SpecialistDoctorTO() { super(); } - public SpecialistDoctorTO(Integer id, String nif, String name, String surname, String password, String email) { + public SpecialistDoctorTO(Integer id, String nif, String name, String surname, String password, String email, MedicalSpecialtyTO medicalSpec) { this.setId(id); this.setNif(nif); this.setName(name); this.setSurname(surname); this.setPassword(password); this.setEmail(email); + this.setMedicalSpecialty(medicalSpec); } public String getEmail() { @@ -81,4 +83,12 @@ public class SpecialistDoctorTO implements Serializable { this.id = id; } + public MedicalSpecialtyTO getMedicalSpecialty() { + return medicalSpecialty; + } + + public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) { + this.medicalSpecialty = medicalSpecialty; + } + } diff --git a/1.sources/MyHealth/src/ejb/profile/ProfileFacadeBean.java b/1.sources/MyHealth/src/ejb/profile/ProfileFacadeBean.java index efd2d82..dd45a54 100644 --- a/1.sources/MyHealth/src/ejb/profile/ProfileFacadeBean.java +++ b/1.sources/MyHealth/src/ejb/profile/ProfileFacadeBean.java @@ -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; + } } diff --git a/1.sources/MyHealth/src/ejb/profile/ProfileFacadeRemote.java b/1.sources/MyHealth/src/ejb/profile/ProfileFacadeRemote.java index 8038dd7..21919b0 100644 --- a/1.sources/MyHealth/src/ejb/profile/ProfileFacadeRemote.java +++ b/1.sources/MyHealth/src/ejb/profile/ProfileFacadeRemote.java @@ -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; } \ No newline at end of file diff --git a/1.sources/MyHealth/src/jpa/FamilyDoctorJPA.java b/1.sources/MyHealth/src/jpa/FamilyDoctorJPA.java index 0961147..dd02336 100644 --- a/1.sources/MyHealth/src/jpa/FamilyDoctorJPA.java +++ b/1.sources/MyHealth/src/jpa/FamilyDoctorJPA.java @@ -26,13 +26,18 @@ public class FamilyDoctorJPA implements Serializable { private static final long serialVersionUID = 1L; @Id - private int id; + @GeneratedValue(strategy=GenerationType.IDENTITY) + private Integer id; private String nif; private String name; private String surname; private String password; private String email; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "FamilyDoctorId") private Collection patients; + @ManyToOne + @JoinColumn (name="PrimaryHealthCareCenterId") private PrimaryHealthCareCenterJPA primaryHealthCareCenter; /** @@ -51,13 +56,11 @@ public class FamilyDoctorJPA implements Serializable { this.primaryHealthCareCenter = phc; } - @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) - public int getId() { + public Integer getId() { return id; } - public void setId(int value) { + public void setId(Integer value) { this.id = value; } @@ -105,8 +108,6 @@ public class FamilyDoctorJPA implements Serializable { * Metodos para get/set de relaciones (pacientes) * @return */ - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "FamilyDoctorId") public Collection getPatients() { return patients; } @@ -115,8 +116,6 @@ public class FamilyDoctorJPA implements Serializable { this.patients = patients; } - @ManyToOne - @JoinColumn (name="PrimaryHealthCareCenterId") public PrimaryHealthCareCenterJPA getPrimaryHealthCareCenter() { return primaryHealthCareCenter; } diff --git a/1.sources/MyHealth/src/jpa/PatientJPA.java b/1.sources/MyHealth/src/jpa/PatientJPA.java index c239379..be58fef 100644 --- a/1.sources/MyHealth/src/jpa/PatientJPA.java +++ b/1.sources/MyHealth/src/jpa/PatientJPA.java @@ -23,7 +23,7 @@ public class PatientJPA implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) - private int id; + private Integer id; private String nif; private String name; private String surname; @@ -40,19 +40,20 @@ public class PatientJPA implements Serializable { super(); } - public PatientJPA(String nif, String name, String surname, String password, String email) { + public PatientJPA(String nif, String name, String surname, String password, String email, FamilyDoctorJPA familyDoc) { this.nif = nif; this.name = name; this.surname = surname; this.password = password; this.email = email; + this.familyDoctor = familyDoc; } - public int getId() { + public Integer getId() { return id; } - public void setId(int value) { + public void setId(Integer value) { this.id = value; } @@ -96,9 +97,6 @@ public class PatientJPA implements Serializable { this.email = email; } - /** - * Methods get/set persistent relationships - */ public FamilyDoctorJPA getFamilyDoctor() { return familyDoctor; } diff --git a/1.sources/MyHealth/src/jpa/SpecialistDoctorJPA.java b/1.sources/MyHealth/src/jpa/SpecialistDoctorJPA.java index 065d40e..7c7e1b5 100644 --- a/1.sources/MyHealth/src/jpa/SpecialistDoctorJPA.java +++ b/1.sources/MyHealth/src/jpa/SpecialistDoctorJPA.java @@ -22,12 +22,15 @@ public class SpecialistDoctorJPA implements Serializable { private static final long serialVersionUID = 1L; @Id - private int id; + @GeneratedValue(strategy=GenerationType.IDENTITY) + private Integer id; private String nif; private String name; private String surname; private String password; private String email; + @ManyToOne + @JoinColumn(name = "MedicalSpecialtyId") private MedicalSpecialtyJPA medicalSpecialty; /** @@ -46,13 +49,11 @@ public class SpecialistDoctorJPA implements Serializable { this.medicalSpecialty = ms; } - @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) - public int getId() { + public Integer getId() { return id; } - public void setId(int value) { + public void setId(Integer value) { this.id = value; } @@ -96,8 +97,6 @@ public class SpecialistDoctorJPA implements Serializable { this.email = email; } - @ManyToOne - @JoinColumn(name = "MedicalSpecialtyId") public MedicalSpecialtyJPA getMedicalSpecialty() { return medicalSpecialty; } diff --git a/1.sources/MyHealth/src/managedbean/common/SessionUtils.java b/1.sources/MyHealth/src/managedbean/common/SessionUtils.java index 251aca7..5e5eb6c 100644 --- a/1.sources/MyHealth/src/managedbean/common/SessionUtils.java +++ b/1.sources/MyHealth/src/managedbean/common/SessionUtils.java @@ -12,7 +12,7 @@ public class SessionUtils { public static final String SESSION_VAR_USERNAME = "userName"; public static final String SESSION_VAR_USERID = "userId"; public static final String SESSION_VAR_USERTYPE = "userType"; - public static final String SESSION_VAR_USER = "loggedInUser"; + public static final String SESSION_VAR_USER = "loggedOnUser"; public static HttpSession getSession() { FacesContext ctx = FacesContext.getCurrentInstance(); @@ -69,4 +69,12 @@ public class SessionUtils { else return ""; } + + public static LoggedUserTO getloggedOnUser() { + HttpSession session = getSession(); + if (session != null && session.getAttribute(SessionUtils.SESSION_VAR_USER) != null) + return LoggedUserTO.class.cast(session.getAttribute(SessionUtils.SESSION_VAR_USER)); + else + return null; + } } diff --git a/1.sources/MyHealth/src/managedbean/profile/RegisterUserMBean.java b/1.sources/MyHealth/src/managedbean/profile/RegisterUserMBean.java index 60f10d7..dca9733 100644 --- a/1.sources/MyHealth/src/managedbean/profile/RegisterUserMBean.java +++ b/1.sources/MyHealth/src/managedbean/profile/RegisterUserMBean.java @@ -205,7 +205,7 @@ public class RegisterUserMBean extends ManagedBeanBase implements Serializable { break; case FAMILY_DOCTOR: - FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor1(id, nif, name, surname, password, email, this.primaryHealthCareCenter); + FamilyDoctorTO fd = this.getRemoteManagerProfile().registerFamilyDoctor(id, nif, name, surname, password, email, this.primaryHealthCareCenter); this.id = fd.getId(); break; diff --git a/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java b/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java new file mode 100644 index 0000000..b9de3af --- /dev/null +++ b/1.sources/MyHealth/src/managedbean/profile/UpdateProfileMBean.java @@ -0,0 +1,311 @@ +package managedbean.profile; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Properties; + +import javax.annotation.PostConstruct; +import javax.faces.application.FacesMessage; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.faces.view.ViewScoped; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.print.attribute.standard.Severity; +import javax.resource.NotSupportedException; + +import org.primefaces.PrimeFaces; + +import TO.FamilyDoctorTO; +import TO.LoggedUserTO; +import TO.MedicalSpecialtyTO; +import TO.PatientTO; +import TO.PrimaryHealthCareCenterTO; +import TO.SpecialistDoctorTO; +import common.UserType; +import ejb.systemAdmin.SystemAdminFacadeRemote; +import managedbean.common.ManagedBeanBase; +import managedbean.common.SessionUtils; +import managedbean.common.ValidationUtils; + +/** + * ManagedBEan que gestiona el registro de usuarios: Usuarios de tipo "Paciente" + * Usuarios de tipo "Médico de Familia" usuarios de tipo "Médico especialista" + * + * @author Marcos García Núñez (mgarcianun@uoc.edu) + * + */ +@Named("UpdateProfile") +@ViewScoped +public class UpdateProfileMBean extends ManagedBeanBase implements Serializable { + + private static final long serialVersionUID = 1L; + + private int id; + private String nif; + private String name; + private String surname; + private String password; + private String passwordRepeat; + private String email; + private boolean registered; + + // private HashMap userTypes; + private List userTypes; + private String userType; + private PrimaryHealthCareCenterTO primaryHealthCareCenter; + private MedicalSpecialtyTO medicalSpecialty; + private Collection medicalSpecialitiesList; + private Collection primaryHealthCareCentersList; + + /** + * Constructor. Inicializa la conexión con el EJB Remoto + * + * @throws Exception + */ + public UpdateProfileMBean() { + + } + + @PostConstruct + public void init() { + this.userTypes = new ArrayList(); + this.userTypes.add(UserType.PATIENT); + this.userTypes.add(UserType.FAMILY_DOCTOR); + this.userTypes.add(UserType.SPECIALIST_DOCTOR); + + // 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.userType = usr.getUserType().getName(); + this.id = Integer.valueOf(usr.getId()); + + switch (usr.getUserType()) { + case PATIENT: + PatientTO pat = this.getRemoteManagerProfile().retrievePatient(this.id); + + this.name = pat.getName(); + this.surname = pat.getName(); + this.nif = pat.getNif(); + this.email = pat.getEmail(); + break; + case SPECIALIST_DOCTOR: + this.medicalSpecialitiesList = this.getRemoteManagerSystemAdmin().listAllMedicalSpecialities(); + SpecialistDoctorTO sd = this.getRemoteManagerProfile().retrieveSpecialistDoctor(this.id); + + this.name = sd.getName(); + this.surname = sd.getName(); + this.nif = sd.getNif(); + this.email = sd.getEmail(); + this.medicalSpecialty = sd.getMedicalSpecialty(); + break; + case FAMILY_DOCTOR: + this.primaryHealthCareCentersList = this.getRemoteManagerSystemAdmin().listAllCAPs(); + FamilyDoctorTO fd = this.getRemoteManagerProfile().retrieveFamilyDoctor(this.id); + + this.name = fd.getName(); + this.surname = fd.getName(); + this.nif = fd.getNif(); + this.email = fd.getEmail(); + this.primaryHealthCareCenter = fd.getPrimaryHealthCareCenter(); + break; + case ADMINISTRADOR: + // TODO: Recuperar usuario administrador para editar su perfil ¿? + // this.getRemoteManagerProfile().retrievePatient(usr.getId()); + break; + } + } + } catch (Exception e) { + this.manageException(e); + } + + } + + public List getUserTypes() { + return userTypes; + } + + public void onUserTypeChange() { + switch (UserType.valueOf(this.userType)) { + case SPECIALIST_DOCTOR: + try { + PrimeFaces.current().ajax().addCallbackParam("specs", true); + } catch (Exception e) { + this.manageException(e); + } + break; + case FAMILY_DOCTOR: + try { + PrimeFaces.current().ajax().addCallbackParam("caps", true); + } catch (Exception e) { + this.manageException(e); + } + break; + case ADMINISTRADOR: + case PATIENT: + PrimeFaces.current().ajax().addCallbackParam("pats", true); + break; + } + } + + public Collection getMedicalSpecialtiesList() { + return medicalSpecialitiesList; + } + + public Collection getPhcList() { + return primaryHealthCareCentersList; + } + + public boolean isPatient() { + return (UserType.valueOf(this.userType) == UserType.PATIENT); + } + + public boolean isFamilyDoctor() { + return (UserType.valueOf(this.userType) == UserType.FAMILY_DOCTOR); + } + + public boolean isSpecialistDoctor() { + return (UserType.valueOf(this.userType) == UserType.SPECIALIST_DOCTOR); + } + + public boolean isDoctor() { + return (isFamilyDoctor() || isSpecialistDoctor()); + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getNif() { + return nif; + } + + public void setNif(String nif) { + this.nif = nif; + } + + public int getId() { + return id; + } + + public void saveData() { + int error = 0; + + if (this.isFamilyDoctor() && this.primaryHealthCareCenter == null) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un centro de atención primaria."); + error++; + } + if (this.isSpecialistDoctor() && this.medicalSpecialty == null) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad médica no seleccionada", "Por favor, especifique una especialidad médica."); + error++; + } + if (ValidationUtils.isValid(nif) == false) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El NIF indicado no es válido", "Por favor, especifique un NIF válido."); + error++; + } + + if (error == 0) { + try { + switch (UserType.valueOf(this.userType)) { + case PATIENT: + PatientTO pat = this.getRemoteManagerProfile().updatePatientData(id, nif, name, surname, password, email); + this.id = pat.getId(); + + break; + case FAMILY_DOCTOR: + FamilyDoctorTO fd = this.getRemoteManagerProfile().updateFamilyDoctorData(id, nif, name, surname, password, email, this.primaryHealthCareCenter); + this.id = fd.getId(); + + break; + case SPECIALIST_DOCTOR: + SpecialistDoctorTO sd = this.getRemoteManagerProfile().updateSpecialistDoctorData(id, nif, name, surname, password, email, this.medicalSpecialty); + this.id = sd.getId(); + + break; + case ADMINISTRADOR: + throw new NotSupportedException("No se soporta la edición de perfiles de administrador."); + } + + this.registered = true; + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos guardados", "Los datos de su perfil se han guardado correctamente en la base de datos."); + + } catch (Exception e) { + this.manageException(e); + } + } + } + + public String getPasswordRepeat() { + return passwordRepeat; + } + + public void setPasswordRepeat(String passwordRepeat) { + this.passwordRepeat = passwordRepeat; + } + + public String getUserType() { + return userType; + } + + public void setUserType(String userType) { + this.userType = userType; + } + + public MedicalSpecialtyTO getMedicalSpecialty() { + return medicalSpecialty; + } + + public void setMedicalSpecialty(MedicalSpecialtyTO medicalSpecialty) { + this.medicalSpecialty = medicalSpecialty; + } + + public PrimaryHealthCareCenterTO getPrimaryHealthCareCenter() { + return primaryHealthCareCenter; + } + + public void setPrimaryHealthCareCenter(PrimaryHealthCareCenterTO primaryHealthCareCenter) { + this.primaryHealthCareCenter = primaryHealthCareCenter; + } + + public boolean isRegistered() { + return registered; + } + +}