Filtro por paciente para la consulta y modificación de visitas por parte
de un administrador.
This commit is contained in:
@@ -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:commandButton value="Mostrar" update="frmPatientVisitList" action="#{PatientVisitList.showData}" icon="fa calendar-alt" />
|
||||
<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"
|
||||
|
||||
@@ -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>
|
||||
@@ -62,7 +64,7 @@
|
||||
<p:column headerText="Editar" width="80px;">
|
||||
<p:commandButton value="Editar" action="#{VisitList.editVisit(v.id)}" icon="pi pi-check" />
|
||||
</p:column>
|
||||
|
||||
|
||||
<f:facet name="paginatorBottomLeft">
|
||||
<p:commandButton update="dtVisitList" action="#{VisitList.showData}" icon="pi pi-refresh" />
|
||||
</f:facet>
|
||||
|
||||
@@ -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,9 +97,10 @@ 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);
|
||||
|
||||
if (patientId != null)
|
||||
|
||||
@@ -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:
|
||||
@@ -57,12 +62,17 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Acesso denegado", "Su perfil de usuario no está autorizado acceder a esta página.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@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,16 +81,29 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
public void editVisit(Integer visitId) throws IOException {
|
||||
FacesContext ctx = FacesContext.getCurrentInstance();
|
||||
ctx.getExternalContext().redirect(String.format("UpdateVisit.xhtml?id=%d&fromPage=%s", visitId, ctx.getViewRoot().getViewId()));
|
||||
ctx.getExternalContext().redirect(String.format("UpdateVisit.xhtml?id=%d&fromPage=%s", visitId, ctx.getViewRoot().getViewId()));
|
||||
}
|
||||
|
||||
|
||||
public LazyDataModel<VisitTO> getLazyDataModelVisitList() {
|
||||
return lazyDataModelVisitList;
|
||||
}
|
||||
@@ -104,4 +127,7 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
|
||||
this.patient = patient;
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return SessionUtils.getUserType() == UserType.ADMINISTRATOR;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user