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:
@@ -1,7 +1,6 @@
|
||||
package ejb.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
@@ -10,6 +9,8 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.jboss.security.auth.spi.Users.User;
|
||||
|
||||
import TO.FamilyDoctorTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
@@ -71,8 +72,8 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
List<MedicalSpecialtyJPA> allJPA = query.getResultList();
|
||||
List<MedicalSpecialtyTO> allSpecialities = new ArrayList<MedicalSpecialtyTO>();
|
||||
|
||||
for (MedicalSpecialtyJPA cap : allJPA) {
|
||||
allSpecialities.add(new MedicalSpecialtyTO(cap.getId(), cap.getName(), cap.getDescription()));
|
||||
for (MedicalSpecialtyJPA item : allJPA) {
|
||||
allSpecialities.add(this.getPOJOforMedicalSpecialtyJPA(item));
|
||||
}
|
||||
|
||||
return allSpecialities;
|
||||
@@ -111,8 +112,8 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
List<PrimaryHealthCareCenterJPA> allJPA = query.getResultList();
|
||||
List<PrimaryHealthCareCenterTO> allCAPs = new ArrayList<PrimaryHealthCareCenterTO>();
|
||||
|
||||
for (PrimaryHealthCareCenterJPA cap : allJPA) {
|
||||
allCAPs.add(new PrimaryHealthCareCenterTO(cap.getId(), cap.getName(), cap.getLocation()));
|
||||
for (PrimaryHealthCareCenterJPA item : allJPA) {
|
||||
allCAPs.add(this.getPOJOforPrimaryHealthCareCenterJPA(item));
|
||||
}
|
||||
|
||||
return allCAPs;
|
||||
@@ -148,60 +149,127 @@ public class CommonFacadeBean implements CommonFacadeRemote, CommonFacadeLocal {
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FamilyDoctorJPA> allFDsJPA = query.getResultList();
|
||||
List<FamilyDoctorTO> allFDTOs = new ArrayList<FamilyDoctorTO>();
|
||||
|
||||
for (FamilyDoctorJPA item : allFDsJPA) {
|
||||
allFDTOs.add(new FamilyDoctorTO(item.getId(), item.getNif(), item.getName(), item.getSurname(), item.getPassword(), item.getEmail(), null));
|
||||
allFDTOs.add(this.getPOJOforFamilyDoctorJPA(item, 0));
|
||||
}
|
||||
|
||||
return allFDTOs;
|
||||
}
|
||||
|
||||
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));
|
||||
private MedicalSpecialtyTO getPOJOforMedicalSpecialtyJPA(MedicalSpecialtyJPA ms) {
|
||||
MedicalSpecialtyTO msTO = null;
|
||||
|
||||
if (ms != null) {
|
||||
msTO = new MedicalSpecialtyTO(ms.getId(), ms.getName(), ms.getDescription());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return msTO;
|
||||
}
|
||||
|
||||
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));
|
||||
private PrimaryHealthCareCenterTO getPOJOforPrimaryHealthCareCenterJPA(PrimaryHealthCareCenterJPA phc) {
|
||||
PrimaryHealthCareCenterTO phcTO = null;
|
||||
|
||||
if (phc != null) {
|
||||
phcTO = new PrimaryHealthCareCenterTO(phc.getId(), phc.getName(), phc.getLocation());
|
||||
}
|
||||
|
||||
PrimaryHealthCareCenterTO phc = null;
|
||||
if (fd.getPrimaryHealthCareCenter() != null)
|
||||
phc = new PrimaryHealthCareCenterTO(fd.getPrimaryHealthCareCenter().getId(), 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;
|
||||
|
||||
return phcTO;
|
||||
}
|
||||
|
||||
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));
|
||||
private SpecialistDoctorTO getPOJOforSpecialistDoctorJPA(SpecialistDoctorJPA sd, int nestedProps) {
|
||||
SpecialistDoctorTO sdTO = null;
|
||||
|
||||
if (sd != null) {
|
||||
MedicalSpecialtyJPA ms = null;
|
||||
if (nestedProps > 0)
|
||||
ms = sd.getMedicalSpecialty();
|
||||
|
||||
nestedProps--;
|
||||
sdTO = new SpecialistDoctorTO(sd.getId(), sd.getProfessionalNumber(), sd.getNif(), sd.getName(), sd.getSurname(), sd.getPassword(), sd.getEmail(), this.getPOJOforMedicalSpecialtyJPA(ms));
|
||||
}
|
||||
|
||||
MedicalSpecialtyTO ms = null;
|
||||
if (sd.getMedicalSpecialty() != null)
|
||||
ms = new MedicalSpecialtyTO(sd.getMedicalSpecialty().getId(), 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;
|
||||
}
|
||||
|
||||
private FamilyDoctorTO getPOJOforFamilyDoctorJPA(FamilyDoctorJPA fd, int nestedProps) {
|
||||
FamilyDoctorTO fdTO = null;
|
||||
|
||||
if (fd != null) {
|
||||
PrimaryHealthCareCenterJPA phc = null;
|
||||
if (nestedProps > 0)
|
||||
phc = fd.getPrimaryHealthCareCenter();
|
||||
|
||||
nestedProps--;
|
||||
fdTO = new FamilyDoctorTO(fd.getId(), fd.getProfessionalNumber(), fd.getNif(), fd.getName(), fd.getSurname(), fd.getPassword(), fd.getEmail(), this.getPOJOforPrimaryHealthCareCenterJPA(phc));
|
||||
}
|
||||
|
||||
return fdTO;
|
||||
}
|
||||
|
||||
private PatientTO getPOJOforPatientJPA(PatientJPA pat, int nestedProps) {
|
||||
PatientTO paTO = null;
|
||||
|
||||
if (pat != null) {
|
||||
FamilyDoctorJPA fd = null;
|
||||
if (nestedProps > 0)
|
||||
fd = pat.getFamilyDoctor();
|
||||
|
||||
nestedProps--;
|
||||
paTO = new PatientTO(pat.getId(), pat.getPersonalIdentificationCode(), pat.getNif(), pat.getName(), pat.getSurname(), pat.getPassword(), pat.getEmail(), this.getPOJOforFamilyDoctorJPA(fd, nestedProps));
|
||||
}
|
||||
|
||||
return paTO;
|
||||
}
|
||||
|
||||
public PatientTO findPatientById(int patientId) {
|
||||
// Recuperamos propiedades anidadas 1 nivel!
|
||||
return this.getPOJOforPatientJPA(entman.find(PatientJPA.class, patientId), 1);
|
||||
}
|
||||
|
||||
|
||||
public PatientJPA findPatientByCode(String code) {
|
||||
TypedQuery<PatientJPA> query = entman.createQuery("from PatientJPA pat where pat.personalIdentificationCode=:code", PatientJPA.class);
|
||||
|
||||
query.setParameter("code", code);
|
||||
|
||||
List<PatientJPA> results = query.getResultList();
|
||||
if (results.size() > 0)
|
||||
return results.get(0);
|
||||
else
|
||||
return null; }
|
||||
|
||||
public FamilyDoctorTO findFamilyDoctorById(int ProfessionalNumberId) {
|
||||
return this.getPOJOforFamilyDoctorJPA(entman.find(FamilyDoctorJPA.class, ProfessionalNumberId), 1);
|
||||
}
|
||||
|
||||
public FamilyDoctorJPA findFamilyDoctorByCode(String code) {
|
||||
TypedQuery<FamilyDoctorJPA> query = entman.createQuery("from FamilyDoctorJPA d where d.professionalNumber=:code", FamilyDoctorJPA.class);
|
||||
|
||||
query.setParameter("code", code);
|
||||
|
||||
List<FamilyDoctorJPA> results = query.getResultList();
|
||||
if (results.size() > 0)
|
||||
return results.get(0);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public SpecialistDoctorTO findSpecialistDoctorById(int ProfessionalNumberId) {
|
||||
return this.getPOJOforSpecialistDoctorJPA(entman.find(SpecialistDoctorJPA.class, ProfessionalNumberId), 1);
|
||||
}
|
||||
|
||||
public SpecialistDoctorJPA findSpecialistDoctorByCode(String code) {
|
||||
TypedQuery<SpecialistDoctorJPA> query = entman.createQuery("from SpecialistDoctorJPA d where d.professionalNumber=:code", SpecialistDoctorJPA.class);
|
||||
|
||||
query.setParameter("code", code);
|
||||
|
||||
List<SpecialistDoctorJPA> results = query.getResultList();
|
||||
if (results.size() > 0)
|
||||
return results.get(0);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.PatientJPA;
|
||||
import jpa.SpecialistDoctorJPA;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -37,9 +40,16 @@ public interface CommonFacadeLocal {
|
||||
|
||||
public List<FamilyDoctorTO> listFamilyDoctorsFiltered(String searchTerm, int pageNumber, int pageSize);
|
||||
|
||||
public PatientTO retrievePatient(int patientId) throws Exception;
|
||||
public PatientTO findPatientById(int patientId);
|
||||
|
||||
public FamilyDoctorTO retrieveFamilyDoctor(int ProfessionalNumberId) throws Exception;
|
||||
public PatientJPA findPatientByCode(String code);
|
||||
|
||||
public FamilyDoctorTO findFamilyDoctorById(int ProfessionalNumberId);
|
||||
|
||||
public FamilyDoctorJPA findFamilyDoctorByCode(String code);
|
||||
|
||||
public SpecialistDoctorTO findSpecialistDoctorById(int ProfessionalNumberId);
|
||||
|
||||
public SpecialistDoctorJPA findSpecialistDoctorByCode(String code);
|
||||
|
||||
public SpecialistDoctorTO retrieveSpecialistDoctor(int ProfessionalNumberId) throws Exception;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ import TO.MedicalSpecialtyTO;
|
||||
import TO.PatientTO;
|
||||
import TO.PrimaryHealthCareCenterTO;
|
||||
import TO.SpecialistDoctorTO;
|
||||
import jpa.FamilyDoctorJPA;
|
||||
import jpa.PatientJPA;
|
||||
import jpa.SpecialistDoctorJPA;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -37,9 +40,16 @@ public interface CommonFacadeRemote {
|
||||
|
||||
public List<FamilyDoctorTO> listFamilyDoctorsFiltered(String searchTerm, int pageNumber, int pageSize);
|
||||
|
||||
public PatientTO retrievePatient(int patientId) throws Exception;
|
||||
public PatientTO findPatientById(int patientId);
|
||||
|
||||
public FamilyDoctorTO retrieveFamilyDoctor(int ProfessionalNumberId) throws Exception;
|
||||
public PatientJPA findPatientByCode(String code);
|
||||
|
||||
public FamilyDoctorTO findFamilyDoctorById(int ProfessionalNumberId);
|
||||
|
||||
public FamilyDoctorJPA findFamilyDoctorByCode(String code);
|
||||
|
||||
public SpecialistDoctorTO findSpecialistDoctorById(int ProfessionalNumberId);
|
||||
|
||||
public SpecialistDoctorJPA findSpecialistDoctorByCode(String code);
|
||||
|
||||
public SpecialistDoctorTO retrieveSpecialistDoctor(int ProfessionalNumberId) throws Exception;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user