Gestión Centros de Atención Primaria

This commit is contained in:
dalvarezgon
2019-12-29 00:48:29 +01:00
parent d889bdbd6c
commit 8dc561f876
8 changed files with 347 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
package ejb.systemAdmin;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
@@ -12,6 +13,7 @@ import TO.FamilyDoctorTO;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PatientTO;
import TO.PrimaryHealthCareCenterTO;
import TO.SpecialistDoctorTO;
import common.Constants;
import common.HashUtils;
@@ -19,6 +21,7 @@ import common.UserType;
import ejb.common.CommonFacadeLocal;
import jpa.AdministratorJPA;
import jpa.MedicalSpecialtyJPA;
import jpa.PrimaryHealthCareCenterJPA;
/**
*
@@ -148,10 +151,81 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
@Override
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception {
MedicalSpecialtyJPA ms = new MedicalSpecialtyJPA(name, description);
entman.persist(ms);
return this.commonServices.getPOJOforMedicalSpecialtyJPA(ms);
}
@Override
public PrimaryHealthCareCenterTO updateHealthCareCenter(int id, String name, String location) throws Exception {
PrimaryHealthCareCenterJPA ms = entman.find(PrimaryHealthCareCenterJPA.class, id);
if (ms == null) {
throw new Exception("No se pueden actualizar los datos del CAP porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
}
ms.setName(name);
ms.setLocation(location);
entman.persist(ms);
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(ms);
}
public PrimaryHealthCareCenterTO findHealthCareCenterByName(String searchedName) {
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("from PrimaryHealthCareCenterJPA cap where cap.name=:name", PrimaryHealthCareCenterJPA.class);
query.setMaxResults(1);
query.setParameter("name", searchedName);
List<PrimaryHealthCareCenterJPA> results = query.getResultList();
if (results.size() > 0)
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(results.get(0));
else
return null;
}
@Override
public void deleteHealthCareCenter(int id) throws Exception {
PrimaryHealthCareCenterJPA cap = entman.find(PrimaryHealthCareCenterJPA.class, id);
if (cap == null) {
throw new Exception("No se puede borrar el CAP porque no se encuentra en la base de datos ningún registro con id: " + String.valueOf(id));
}
entman.remove(cap);
}
@Override
public PrimaryHealthCareCenterTO insertHealthCareCenter(String name, String location) throws Exception {
PrimaryHealthCareCenterJPA cap = new PrimaryHealthCareCenterJPA(name, location);
entman.persist(cap);
return this.commonServices.getPOJOforPrimaryHealthCareCenterJPA(cap);
}
public Long getCAPCount() {
TypedQuery<Long> query = entman.createQuery("SELECT count(1) from PrimaryHealthCareCenterJPA", Long.class);
return query.getSingleResult();
}
public List<PrimaryHealthCareCenterTO> listCAPsPaged(int pageNumber, int pageSize) {
TypedQuery<PrimaryHealthCareCenterJPA> query = entman.createQuery("SELECT c from PrimaryHealthCareCenterJPA c order by c.name", PrimaryHealthCareCenterJPA.class);
if (pageSize > 0) {
query.setFirstResult(pageNumber * pageSize);
query.setMaxResults(pageSize);
}
List<PrimaryHealthCareCenterJPA> allJPA = query.getResultList();
List<PrimaryHealthCareCenterTO> caps = new ArrayList<PrimaryHealthCareCenterTO>();
for (PrimaryHealthCareCenterJPA item : allJPA) {
caps.add(commonServices.getPOJOforPrimaryHealthCareCenterJPA(item));
}
return caps;
}
}

View File

@@ -1,9 +1,12 @@
package ejb.systemAdmin;
import java.util.List;
import javax.ejb.Remote;
import TO.LoggedUserTO;
import TO.MedicalSpecialtyTO;
import TO.PrimaryHealthCareCenterTO;
/**
*
@@ -25,4 +28,16 @@ public interface SystemAdminFacadeRemote {
public void deleteSpecialty(int id) throws Exception;
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception;
public PrimaryHealthCareCenterTO updateHealthCareCenter(int id, String name, String location) throws Exception;
public PrimaryHealthCareCenterTO findHealthCareCenterByName(String name);
public void deleteHealthCareCenter(int id) throws Exception;
public PrimaryHealthCareCenterTO insertHealthCareCenter(String name, String location) throws Exception;
public Long getCAPCount();
public List<PrimaryHealthCareCenterTO> listCAPsPaged(int pageNumber, int pageSize);
}