diff --git a/1.sources/MyHealth/docroot/systemAdmin/ManageSpecialties.xhtml b/1.sources/MyHealth/docroot/systemAdmin/ManageSpecialties.xhtml index 37061e9..04ba735 100644 --- a/1.sources/MyHealth/docroot/systemAdmin/ManageSpecialties.xhtml +++ b/1.sources/MyHealth/docroot/systemAdmin/ManageSpecialties.xhtml @@ -8,7 +8,7 @@ - +
@@ -20,19 +20,42 @@
- +
- +
+
+ +
+
+ +
+
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
- +
diff --git a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java index f0b239f..787169a 100644 --- a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java +++ b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeBean.java @@ -16,7 +16,6 @@ import common.UserType; import ejb.common.CommonFacadeLocal; import jpa.AdministratorJPA; import jpa.MedicalSpecialtyJPA; -import jpa.PatientJPA; /** * @@ -126,4 +125,24 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote { return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms); } + + @Override + public void deleteSpecialtyData(int id, String name, String description) throws Exception { + MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id); + + if (ms == null) { + throw new Exception("No se puede borrar la especialidad porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id)); + } + + entman.remove(ms); + } + + @Override + public MedicalSpecialtyTO insertSpecialtyData(String name, String description) throws Exception { + + MedicalSpecialtyJPA ms = new MedicalSpecialtyJPA(name, description); + entman.persist(ms); + + return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms); + } } diff --git a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeRemote.java b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeRemote.java index 7c8cfe9..f4ab02d 100644 --- a/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeRemote.java +++ b/1.sources/MyHealth/src/ejb/systemAdmin/SystemAdminFacadeRemote.java @@ -1,13 +1,9 @@ package ejb.systemAdmin; -import java.util.Collection; - import javax.ejb.Remote; import TO.LoggedUserTO; import TO.MedicalSpecialtyTO; -import TO.PatientTO; -import TO.PrimaryHealthCareCenterTO; /** * @@ -23,4 +19,8 @@ public interface SystemAdminFacadeRemote { public LoggedUserTO login(String id, String pwd); public MedicalSpecialtyTO updateSpecialtyData(int id, String name, String description) throws Exception; + + public void deleteSpecialtyData(int id, String name, String description) throws Exception; + + public MedicalSpecialtyTO insertSpecialtyData(String name, String description) throws Exception; } \ No newline at end of file diff --git a/1.sources/MyHealth/src/managedbean/systemAdmin/ManageSpecialitiesMBean.java b/1.sources/MyHealth/src/managedbean/systemAdmin/ManageSpecialitiesMBean.java index 8a12fc3..c225f76 100644 --- a/1.sources/MyHealth/src/managedbean/systemAdmin/ManageSpecialitiesMBean.java +++ b/1.sources/MyHealth/src/managedbean/systemAdmin/ManageSpecialitiesMBean.java @@ -6,7 +6,6 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; import javax.inject.Named; import TO.LoggedUserTO; @@ -115,4 +114,49 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ } } } + + public void deleteData() { + int error = 0; + + if (this.medicalSpecialty.getName() == null) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre de especialidad."); + error++; + } + if (this.medicalSpecialty.getDescription() == null) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción."); + error++; + } + + if (error == 0) { + try { + this.getRemoteManagerSystemAdmin().deleteSpecialtyData(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription()); + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los especialidad se ha borrado", "Los datos de la especialidad se han borrado correctamente."); + } catch (Exception e) { + this.manageException(e); + } + } + } + + public void insertData() { + int error = 0; + + if (name == null || name.trim().length() == 0) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre de especialidad."); + error++; + } + if (description == null || description.trim().length() == 0) { + this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción."); + error++; + } + + if (error == 0) { + try { + MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().insertSpecialtyData(name, description); + this.setSpecialtyData(ms); + this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente."); + } catch (Exception e) { + this.manageException(e); + } + } + } }