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"> <div class="ui-g-5 ui-md-5">
<p:panel id="mainPanel" header="Pruebas médicas"> <p:panel id="mainPanel" header="Pruebas médicas">
<f:facet name="actions"> <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:outputText styleClass="ui-icon pi pi-plus" />
</h:commandLink> </h:commandLink>
</f:facet> </f:facet>
@@ -76,10 +76,16 @@
</div> </div>
<div class="ui-g-4 ui-md-4">Tipo de prueba: </div> <div class="ui-g-4 ui-md-4">Tipo de prueba: </div>
<div class="ui-g-8 ui-md-8"> <div class="ui-g-8 ui-md-8">
<p:selectOneMenu value="#{mt.selected.type}"> <p:selectOneMenu value="#{mt.medicalTestTypeSelected}">
<f:selectItems value="#{mt.selected.type}" /> <f:selectItems value="#{mt.medicalTestTypes}" var="el" itemLabel="#{el.testTypeName}" itemValue="#{el.name}" />
</p:selectOneMenu> </p:selectOneMenu>
</div> </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> </div>
</p:panel> </p:panel>
</div> </div>

View File

@@ -156,22 +156,29 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
/** /**
* Añadir pruebas médicas a una cita * 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 patientiID
* @param date * @param date
* @param time * @param time
* @param testType Pudiera llegar a ser: Análisis de sangre, resonancias * @param testType Pudiera llegar a ser: Análisis de sangre, resonancias
* magnéticas y TAC * magnéticas y TAC
* @param observations * @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,
SpecialistDoctorJPA specDoctor = entman.find(SpecialistDoctorJPA.class, doctorSpecialistID); MedicalTestType testType, String observations) {
PatientJPA pat = entman.find(PatientJPA.class, patientID); 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) { private MedicalTestJPA getMedicalTestJPA(int idMedicalTest) {
TypedQuery<MedicalTestJPA> query = entman.createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", TypedQuery<MedicalTestJPA> query = entman
MedicalTestJPA.class); .createQuery("SELECT q from MedicalTestJPA q where q.id=:idMedicalTest", MedicalTestJPA.class);
query.setParameter("idMedicalTest", idMedicalTest); query.setParameter("idMedicalTest", idMedicalTest);
return query.getSingleResult(); return query.getSingleResult();
} }
@@ -301,14 +308,14 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>(); List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = ""; String extraQuery = "";
if(patientID > 0) { if (patientID > 0) {
extraQuery = " and q.patient.id=:patientID"; extraQuery = " and q.patient.id=:patientID";
} }
TypedQuery<MedicalTestJPA> query = entman.createQuery( TypedQuery<MedicalTestJPA> query = entman
"SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID " + extraQuery + " order by q.id desc", .createQuery("SELECT q from MedicalTestJPA q where q.patient.familyDoctor.id=:familyDoctorID "
MedicalTestJPA.class); + extraQuery + " order by q.id desc", MedicalTestJPA.class);
if(patientID > 0) { if (patientID > 0) {
query.setParameter("patientID", patientID); query.setParameter("patientID", patientID);
} }
query.setParameter("familyDoctorID", familyDoctorID); query.setParameter("familyDoctorID", familyDoctorID);
@@ -327,15 +334,15 @@ public class MedicalTestFacadeBean implements MedicalTestFacadeRemote {
List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>(); List<MedicalTestTO> medicalTests = new ArrayList<MedicalTestTO>();
String extraQuery = ""; String extraQuery = "";
if(patientID > 0) { if (patientID > 0) {
extraQuery = " and q.patient.id=:patientID"; extraQuery = " and q.patient.id=:patientID";
} }
TypedQuery<MedicalTestJPA> query = entman.createQuery( TypedQuery<MedicalTestJPA> query = entman
"SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID " + extraQuery + " order by q.id desc", .createQuery("SELECT q from MedicalTestJPA q where q.specialistDoctor.id=:specialistDoctorID "
MedicalTestJPA.class); + extraQuery + " order by q.id desc", MedicalTestJPA.class);
if(patientID > 0) { if (patientID > 0) {
query.setParameter("patientID", patientID); query.setParameter("patientID", patientID);
} }
query.setParameter("specialistDoctorID", specialistDoctorID); 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 testType Pudiera llegar a ser: Análisis de sangre, resonancias magnéticas y TAC
* @param observations * @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 * Recuperar una prueba médica por ID

View File

@@ -15,6 +15,7 @@ import org.primefaces.event.SelectEvent;
import TO.MedicalTestTO; import TO.MedicalTestTO;
import TO.PatientTO; import TO.PatientTO;
import common.MedicalTestType;
import common.UserType; import common.UserType;
import managedbean.common.ManagedBeanBase; import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils; import managedbean.common.SessionUtils;
@@ -87,10 +88,12 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForPatient(userID); this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForPatient(userID);
} else if (userType == UserType.SPECIALIST_DOCTOR) { } else if (userType == UserType.SPECIALIST_DOCTOR) {
// Cargar las pruebas que el doctor especialista ha creado // 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) { } else if (userType == UserType.FAMILY_DOCTOR) {
// Cargar las pruebas para los pacientes del doctor de familia en sesión // 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 { } else {
// Nothing todo // Nothing todo
this.medicalTests = new ArrayList<MedicalTestTO>(); this.medicalTests = new ArrayList<MedicalTestTO>();
@@ -121,7 +124,7 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
} }
/*************************************************** METODOS PARA LA VISTA */ /*************************************************** METODOS PARA LA VISTA */
private Integer patIdSelected = -1; private int patIdSelected = -1;
public void setPatIdSelected(Integer value) { public void setPatIdSelected(Integer value) {
this.patIdSelected = value; this.patIdSelected = value;
@@ -132,22 +135,8 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
return this.patIdSelected; return this.patIdSelected;
} }
public String getTitlePanel() { public boolean isSpecialistDoctor() {
String res; return this.userType == UserType.SPECIALIST_DOCTOR;
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 isPatSelector() { public boolean isPatSelector() {
@@ -156,13 +145,8 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
public void onSelectPatient(AjaxBehaviorEvent event) { public void onSelectPatient(AjaxBehaviorEvent event) {
this.selected = null; this.selected = null;
if (userType == UserType.SPECIALIST_DOCTOR) { this.loadMedicalTests();
// 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);
}
} }
public void onSelectMT(SelectEvent event) { public void onSelectMT(SelectEvent event) {
@@ -175,9 +159,11 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
this.selected = new MedicalTestTO(); this.selected = new MedicalTestTO();
this.selected.setId(-1); this.selected.setId(-1);
this.selected.setObservations(""); this.selected.setObservations("");
this.selected.setType(MedicalTestType.BLOOD_TEST);
this.addNewMode = true; this.addNewMode = true;
} else { } 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() { public boolean getViewCreate() {
return addNewMode; return addNewMode && userType == UserType.SPECIALIST_DOCTOR;
} }
public boolean getViewEdit() { public boolean getViewEdit() {
return !addNewMode && this.selected != null; 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();
}
} }