Creando un MT

This commit is contained in:
Roberto Orden Erena
2019-12-29 10:20:16 +01:00
parent 47caa1fc54
commit 9cd602f8cf
4 changed files with 98 additions and 64 deletions

View File

@@ -15,7 +15,7 @@
<div class="ui-g-5 ui-md-5">
<p:panel id="mainPanel" header="Pruebas médicas">
<f:facet name="actions">
<h:commandLink action="#{mt.addMT}" immediate="true" update="frmMT" styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default">
<h:commandLink rendered="#{mt.specialistDoctor}" action="#{mt.addMT}" immediate="true" update="frmMT" styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default">
<h:outputText styleClass="ui-icon pi pi-plus" />
</h:commandLink>
</f:facet>
@@ -76,10 +76,16 @@
</div>
<div class="ui-g-4 ui-md-4">Tipo de prueba: </div>
<div class="ui-g-8 ui-md-8">
<p:selectOneMenu value="#{mt.selected.type}">
<f:selectItems value="#{mt.selected.type}" />
<p:selectOneMenu value="#{mt.medicalTestTypeSelected}">
<f:selectItems value="#{mt.medicalTestTypes}" var="el" itemLabel="#{el.testTypeName}" itemValue="#{el.name}" />
</p:selectOneMenu>
</div>
<div class="ui-g-4 ui-md-4"></div>
<div class="ui-g-4 ui-md-4">
<p:commandButton value="Guardar" action="#{mt.save}" icon="pi pi-save" update="frmMT" />
</div>
<div class="ui-g-4 ui-md-4"></div>
</div>
</p:panel>
</div>

View File

@@ -156,22 +156,29 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
/**
* Añadir pruebas médicas a una cita
*
* Dado que será añadida por el médico especialista en sesión no hace falta más información.
* Dado que será añadida por el médico especialista en sesión no hace falta más
* información.
*
* @param patientiID
* @param date
* @param time
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias
* magnéticas y TAC
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias
* magnéticas y TAC
* @param 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);
public String addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time,
MedicalTestType testType, String observations) {
try {
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);
MedicalTestJPA mt = new MedicalTestJPA(0, date, time, observations, null, testType, pat, specDoctor);
entman.persist(mt);
entman.persist(mt);
return "ok";
} catch (Exception ex) {
return ex.getMessage();
}
}
/**
@@ -190,8 +197,8 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
}
private MedicalTestJPA getMedicalTestJPA(int idMedicalTest) {
TypedQuery<MedicalTestJPA> query = entman.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest",
MedicalTestJPA.class);
TypedQuery<MedicalTestJPA> query = entman
.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class);
query.setParameter("idMedicalTest", idMedicalTest);
return query.getSingleResult();
}
@@ -301,14 +308,14 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if(patientID > 0) {
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) {
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);
@@ -327,15 +334,15 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = "";
if(patientID > 0) {
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);
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) {
if (patientID > 0) {
query.setParameter("patientID", patientID);
}
query.setParameter("specialistDoctorID", specialistDoctorID);

View File

@@ -89,7 +89,7 @@ public interface MedicalTestFacadeRemote {
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias magnéticas y TAC
* @param observations
*/
public void addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations);
public String addMedicalTest(int patientID, int doctorSpecialistID, Date date, LocalTime time, MedicalTestType testType, String observations);
/**
* Recuperar una prueba médica por ID

View File

@@ -15,6 +15,7 @@ import org.primefaces.event.SelectEvent;
import TO.MedicalTestTO;
import TO.PatientTO;
import common.MedicalTestType;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@@ -87,10 +88,12 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForPatient(userID);
} else if (userType == UserType.SPECIALIST_DOCTOR) {
// Cargar las pruebas que el doctor especialista ha creado
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID);
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID,
this.patIdSelected);
} else if (userType == UserType.FAMILY_DOCTOR) {
// Cargar las pruebas para los pacientes del doctor de familia en sesión
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID);
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID,
this.patIdSelected);
} else {
// Nothing todo
this.medicalTests = new ArrayList<MedicalTestTO>();
@@ -121,7 +124,7 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
}
/*************************************************** METODOS PARA LA VISTA */
private Integer patIdSelected = -1;
private int patIdSelected = -1;
public void setPatIdSelected(Integer value) {
this.patIdSelected = value;
@@ -132,22 +135,8 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
return this.patIdSelected;
}
public String getTitlePanel() {
String res;
if (userType == UserType.PATIENT) {
// Cargar las pruebas para el paciente en sesión
res = "Realizadas al paciente: " + SessionUtils.getloggedOnUser().getName();
} else if (userType == UserType.SPECIALIST_DOCTOR) {
// Cargar las pruebas que el doctor especialista ha creado
res = "Solicitadas por el médico especialista: " + SessionUtils.getloggedOnUser().getName();
} else if (userType == UserType.FAMILY_DOCTOR) {
// Cargar las pruebas para los pacientes del doctor de familia en sesión
res = "Pacientes del médico de familia: " + SessionUtils.getloggedOnUser().getName();
} else {
// Nothing todo
res = "Error";
}
return res;
public boolean isSpecialistDoctor() {
return this.userType == UserType.SPECIALIST_DOCTOR;
}
public boolean isPatSelector() {
@@ -156,13 +145,8 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
public void onSelectPatient(AjaxBehaviorEvent event) {
this.selected = null;
if (userType == UserType.SPECIALIST_DOCTOR) {
// Cargar las pruebas que el doctor especialista ha creado
medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID, this.patIdSelected);
} else if (userType == UserType.FAMILY_DOCTOR) {
// Cargar las pruebas para los pacientes del doctor de familia en sesión
medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID, this.patIdSelected);
}
this.loadMedicalTests();
}
public void onSelectMT(SelectEvent event) {
@@ -175,9 +159,11 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
this.selected = new MedicalTestTO();
this.selected.setId(-1);
this.selected.setObservations("");
this.selected.setType(MedicalTestType.BLOOD_TEST);
this.addNewMode = true;
} else {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Atención!", "Debe elegir un paciente al que añadir la prueba médica.");
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Atención!",
"Debe elegir un paciente al que añadir la prueba médica.");
}
}
@@ -190,11 +176,46 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
}
public boolean getViewCreate() {
return addNewMode;
return addNewMode && userType == UserType.SPECIALIST_DOCTOR;
}
public boolean getViewEdit() {
return !addNewMode && this.selected != null;
}
public List<MedicalTestType> getMedicalTestTypes() {
ArrayList<MedicalTestType> list = new ArrayList<MedicalTestType>();
list.add(MedicalTestType.BLOOD_TEST);
list.add(MedicalTestType.CT_SCAN);
list.add(MedicalTestType.MAGNETIC_RESONANCE_IMAGING);
return list;
}
public String getMedicalTestTypeSelected() {
return this.selected.getType().getName();
}
public void setMedicalTestTypeSelected(String val) {
MedicalTestType mt;
if (val.equals(MedicalTestType.BLOOD_TEST)) {
mt = MedicalTestType.BLOOD_TEST;
} else if (val.equals(MedicalTestType.CT_SCAN)) {
mt = MedicalTestType.CT_SCAN;
} else {
mt = MedicalTestType.MAGNETIC_RESONANCE_IMAGING;
}
this.selected.setType(mt);
}
public void save() {
String res = getRemoteManagerMedicalTest().addMedicalTest(this.patIdSelected, userID, this.selected.getDate(),
this.selected.getTime(), this.selected.getType(), this.selected.getObservations());
if (res.equals("ok")) {
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Éxito", "Guardado correctamente");
} else {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", res);
}
this.loadMedicalTests();
}
}