Ver pruebas médicas casi funcionando al completo: falta cargar imagen real

Crear prueba medica: formulario comenzado.
This commit is contained in:
Roberto Orden Erena
2019-12-28 22:59:55 +01:00
parent be08aaff6e
commit 2e0cc8bf36
8 changed files with 619 additions and 139 deletions

View File

@@ -1,5 +1,6 @@
package ejb.medicalTest;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -10,11 +11,14 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import TO.MedicalTestTO;
import TO.PatientTO;
import TO.QuestionTO;
import TO.SpecialistDoctorTO;
import common.MedicalTestType;
import common.QuestionStatus;
import ejb.common.CommonFacadeLocal;
import jpa.MedicalTestJPA;
import jpa.PatientJPA;
import jpa.QuestionJPA;
import jpa.SpecialistDoctorJPA;
@@ -152,16 +156,22 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
/**
* Añadir pruebas médicas a una cita
*
* Sólo médicos especialistas pueden gestionar pruebas médicas en el sistema.
* Dado que será añadida por el médico especialista en sesión no hace falta más información.
*
* @param idMedicalTest
* @param patientiID
* @param date
* @param time
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias
* magnéticas y TAC
* @param observations
*/
public void addMedicalTest(int idMedicalTest, Date date, long time, MedicalTestType testType, String observations) {
public void addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations) {
SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID);
PatientJPA pat = entman.find(PatientJPA.class, patientID);
MedicalTestJPA mt = new MedicalTestJPA(0, date, time, observations, null, testType, pat, specDoctor);
entman.persist(mt);
}
/**
@@ -171,7 +181,19 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
*
* @param idMedicalTest
*/
public void getMedicalTest(int idMedicalTest) {
public MedicalTestTO getMedicalTest(int idMedicalTest) {
MedicalTestTO resp = new MedicalTestTO();
resp = commonServices.getPOJOforMedicalTestJPA(this.getMedicalTestJPA(idMedicalTest), 1);
return resp;
}
private MedicalTestJPA getMedicalTestJPA(int idMedicalTest) {
TypedQuery<MedicalTestJPA> query = entman.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest",
MedicalTestJPA.class);
query.setParameter("idMedicalTest", idMedicalTest);
return query.getSingleResult();
}
/**
@@ -181,6 +203,10 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param image
*/
public void addImage(int idMedicalTest, String image) {
MedicalTestJPA mt = this.getMedicalTestJPA(idMedicalTest);
mt.setHighresimage(image);
entman.persist(mt);
}
/**
@@ -190,6 +216,7 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param image
*/
public void updateImage(int idMedicalTest, String image) {
this.addImage(idMedicalTest, image);
}
/**
@@ -198,6 +225,10 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
* @param idMedicalTest
*/
public void removeImage(int idMedicalTest) {
MedicalTestJPA mt = this.getMedicalTestJPA(idMedicalTest);
mt.setHighresimage(null);
entman.persist(mt);
}
public Long getSpecialistDoctorByMedicalSpecialityCount(int specialityId) {
@@ -236,4 +267,124 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
return pendingQuestions;
}
@Override
public List<MedicalTestTO> loadMedicalTestForPatient(int patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
TypedQuery<MedicalTestJPA> query = entman.createQuery(
"SELECT q from MedicalTestJPA q where q.patient.id=:patientId order by q.id desc",
MedicalTestJPA.class);
query.setParameter("patientId", patientID);
List<MedicalTestJPA> allJPA = query.getResultList();
for (MedicalTestJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforMedicalTestJPA(item, 1));
}
return medicalTests;
}
@Override
public List<MedicalTestTO> loadMedicalTestForFamilyDoctor(int familyDoctorID) {
return this.loadMedicalTestForFamilyDoctor(familyDoctorID, -1);
}
@Override
public List<MedicalTestTO> loadMedicalTestForSpecialistDoctor(int specialistDoctorID) {
return this.loadMedicalTestForSpecialistDoctor(specialistDoctorID, -1);
}
@Override
public List<MedicalTestTO> loadMedicalTestForFamilyDoctor(int familyDoctorID, int patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if(patientID > 0) {
extraQuery = " and q.patient.id=:patientID";
}
TypedQuery<MedicalTestJPA> query = entman.createQuery(
"SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID " + extraQuery + " order by q.id desc",
MedicalTestJPA.class);
if(patientID > 0) {
query.setParameter("patientID", patientID);
}
query.setParameter("familyDoctorID", familyDoctorID);
List<MedicalTestJPA> allJPA = query.getResultList();
for (MedicalTestJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforMedicalTestJPA(item, 1));
}
return medicalTests;
}
@Override
public List<MedicalTestTO> loadMedicalTestForSpecialistDoctor(int specialistDoctorID, int patientID) {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if(patientID > 0) {
extraQuery = " and q.patient.id=:patientID";
}
TypedQuery<MedicalTestJPA> query = entman.createQuery(
"SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID " + extraQuery + " order by q.id desc",
MedicalTestJPA.class);
if(patientID > 0) {
query.setParameter("patientID", patientID);
}
query.setParameter("specialistDoctorID", specialistDoctorID);
List<MedicalTestJPA> allJPA = query.getResultList();
for (MedicalTestJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforMedicalTestJPA(item, 1));
}
return medicalTests;
}
@Override
public List<PatientTO> loadPatientsForSpecialistDoctor(int specialistDoctorID) {
List<PatientTO> medicalTests = new ArrayList<PatientTO>();
TypedQuery<PatientJPA> query = entman.createQuery(
"SELECT distinct q.patient from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID",
PatientJPA.class);
query.setParameter("specialistDoctorID", specialistDoctorID);
List<PatientJPA> allJPA = query.getResultList();
for (PatientJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1));
}
return medicalTests;
}
@Override
public List<PatientTO> loadPatientsForFamilyDoctor(int familyDoctorID) {
List<PatientTO> medicalTests = new ArrayList<PatientTO>();
TypedQuery<PatientJPA> query = entman.createQuery(
"SELECT distinct q.patient from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID",
PatientJPA.class);
query.setParameter("familyDoctorID", familyDoctorID);
List<PatientJPA> allJPA = query.getResultList();
for (PatientJPA item : allJPA) {
medicalTests.add(commonServices.getPOJOforPatientJPA(item, 1));
}
return medicalTests;
}
}