Filtro por paciente para la consulta y modificación de visitas por parte

de un administrador.
This commit is contained in:
Marcos Garcia Nuñez
2019-12-27 01:41:17 +01:00
parent 1d0118bcc8
commit ec3b1dc1cd
4 changed files with 68 additions and 22 deletions

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui">
<ui:composition template="../header.xhtml">
<ui:define name="content">
@@ -16,15 +16,31 @@
</div>
<div class="ui-g-3">
<div class="ui-inputgroup">
<p:datePicker id="fecha" value="#{PatientVisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true" required="true"
requiredMessage="Especifique una fecha para realizar la consulta." />
<p:datePicker id="fecha" value="#{PatientVisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true">
<p:ajax event="dateSelect" listener="#{PatientVisitList.showData}" update="frmPatientVisitList" />
</p:datePicker>
<p:commandButton value="Mostrar" update="frmPatientVisitList" action="#{PatientVisitList.showData}" icon="fa calendar-alt" />
</div>
</div>
<div class="ui-g-2" />
<div class="ui-g-5">
Paciente:
<h:outputText value="#{PatientVisitList.patient.displayName}" style="font-weight: bold;" />
<div class="ui-g-1" />
<div class="ui-g-2">Paciente:</div>
<div class="ui-g-4">
<h:outputText rendered="#{not PatientVisitList.admin}" value="#{PatientVisitList.patient.displayName}" style="font-weight: bold;" />
<p:autoComplete rendered="#{PatientVisitList.admin}" id="filterPatient" dropdown="true" value="#{PatientVisitList.patient}"
completeMethod="#{PatientVisitList.completePatient}" var="p" itemLabel="#{p.displayName}" itemValue="#{p}" forceSelection="true"
placeholder="Seleccione un paciente o teclee para buscar...">
<o:converter converterId="omnifaces.ListConverter" list="#{PatientVisitList.patientList}" />
<p:column headerText="Num. Prof.">
<h:outputText value="#{p.personalIdentificationCode}" />
</p:column>
<p:column headerText="Nombre">
<h:outputText value="#{p.name}" />
</p:column>
<p:column headerText="Apellidos">
<h:outputText value="#{p.surname}" />
</p:column>
<p:ajax event="itemSelect" listener="#{PatientVisitList.showData}" update="frmPatientVisitList" />
</p:autoComplete>
</div>
<p:dataTable id="dtPatientVisitList" widgetVar="dtPatientVisitList" var="v" value="#{PatientVisitList.lazyDataModelVisitList}" lazy="true" paginator="true" rows="10"

View File

@@ -17,7 +17,9 @@
<div class="ui-g-3">
<div class="ui-inputgroup">
<p:datePicker id="fecha" value="#{VisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true" required="true"
requiredMessage="Especifique una fecha para realizar la consulta." />
requiredMessage="Especifique una fecha para realizar la consulta.">
<p:ajax event="dateSelect" listener="#{VisitList.showData}" update="frmVisitList" />
</p:datePicker>
<p:commandButton value="Mostrar" update="frmVisitList" action="#{VisitList.showData}" icon="fa calendar-alt" />
</div>
</div>

View File

@@ -74,8 +74,9 @@ public class VisitFacadeBean implements VisitFacadeRemote {
strFilter += " and v.date=:date ";
if (strFilter.length() > 0) {
strQuery = String.format(strQuery, "WHERE 1=1 " + strFilter);
strFilter = "WHERE 1=1 " + strFilter;
}
strQuery = String.format(strQuery, strFilter);
TypedQuery<Long> query = entman.createQuery(strQuery, Long.class);
@@ -96,8 +97,9 @@ public class VisitFacadeBean implements VisitFacadeRemote {
strFilter += " and v.date=:date ";
if (strFilter.length() > 0) {
strQuery = String.format(strQuery, "WHERE 1=1 " + strFilter);
strFilter = "WHERE 1=1 " + strFilter;
}
strQuery = String.format(strQuery, strFilter);
TypedQuery<VisitJPA> query = entman.createQuery(strQuery, VisitJPA.class);

View File

@@ -15,9 +15,9 @@ import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import TO.FamilyDoctorTO;
import TO.PatientTO;
import TO.VisitTO;
import common.Constants;
import common.UserType;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;
@@ -33,23 +33,28 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
private Integer patientId;
private LazyDataModel<VisitTO> lazyDataModelVisitList;
private Date selectedDate;
private String lastUIQuery;
private List<PatientTO> patientList;
public PatientVisitListMBean() {
}
@PostConstruct
public void init() {
this.lastUIQuery = "";
// Si el usuario es un paciente listamos las visitas de ese paciente, si es admnistrador listamos todas.
switch (SessionUtils.getUserType())
{
switch (SessionUtils.getUserType()) {
case ADMINISTRATOR:
this.patientId = null;
this.setPatient(null);
this.patient = null;
this.selectedDate = new Date();
this.patientList = this.getRemoteManagerCommon().listPatientsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
break;
case PATIENT:
this.patientId = Integer.valueOf(SessionUtils.getUserId());
this.setPatient(this.getRemoteManagerCommon().findPatientById(patientId));
this.patient = this.getRemoteManagerCommon().findPatientById(patientId);
this.selectedDate = null;
break;
case FAMILY_DOCTOR:
@@ -63,6 +68,11 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
@Override
public List<VisitTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
if (patient != null)
patientId = patient.getId();
else
patientId = null;
Long totalRowCount = getRemoteManagerVisit().getVisitsCount(patientId, selectedDate);
this.setRowCount(totalRowCount.intValue());
@@ -71,6 +81,19 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
};
}
public List<PatientTO> completePatient(String query) {
if (query != null && query.equals(this.lastUIQuery) == false) {
this.lastUIQuery = query;
// Recuperamos las 200 primeras coincidencias
this.patientList = this.getRemoteManagerCommon().listPatientsFiltered(query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
}
return this.patientList;
}
public List<PatientTO> getPatientList() {
return patientList;
}
public void removeVisit(Integer visitId) throws IOException {
// TODO: Eliminar visita de la BBDD
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Visita eliminada", String.format("La visita con Id: %d se ha eliminado correctamente", visitId));
@@ -104,4 +127,7 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
this.patient = patient;
}
public boolean isAdmin() {
return SessionUtils.getUserType() == UserType.ADMINISTRATOR;
}
}