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"> <!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" <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:composition template="../header.xhtml">
<ui:define name="content"> <ui:define name="content">
@@ -16,15 +16,31 @@
</div> </div>
<div class="ui-g-3"> <div class="ui-g-3">
<div class="ui-inputgroup"> <div class="ui-inputgroup">
<p:datePicker id="fecha" value="#{PatientVisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true" required="true" <p:datePicker id="fecha" value="#{PatientVisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true">
requiredMessage="Especifique una fecha para realizar la consulta." /> <p:ajax event="dateSelect" listener="#{PatientVisitList.showData}" update="frmPatientVisitList" />
<p:commandButton value="Mostrar" update="frmPatientVisitList" action="#{PatientVisitList.showData}" icon="fa calendar-alt" /> </p:datePicker>
<p:commandButton value="Mostrar" update="frmPatientVisitList" action="#{PatientVisitList.showData}" icon="fa calendar-alt" />
</div> </div>
</div> </div>
<div class="ui-g-2" /> <div class="ui-g-1" />
<div class="ui-g-5"> <div class="ui-g-2">Paciente:</div>
Paciente: <div class="ui-g-4">
<h:outputText value="#{PatientVisitList.patient.displayName}" style="font-weight: bold;" /> <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> </div>
<p:dataTable id="dtPatientVisitList" widgetVar="dtPatientVisitList" var="v" value="#{PatientVisitList.lazyDataModelVisitList}" lazy="true" paginator="true" rows="10" <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-g-3">
<div class="ui-inputgroup"> <div class="ui-inputgroup">
<p:datePicker id="fecha" value="#{VisitList.selectedDate}" pattern="dd/MM/yyyy" showIcon="true" showButtonBar="true" autocomplete="true" required="true" <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" /> <p:commandButton value="Mostrar" update="frmVisitList" action="#{VisitList.showData}" icon="fa calendar-alt" />
</div> </div>
</div> </div>
@@ -62,7 +64,7 @@
<p:column headerText="Editar" width="80px;"> <p:column headerText="Editar" width="80px;">
<p:commandButton value="Editar" action="#{VisitList.editVisit(v.id)}" icon="pi pi-check" /> <p:commandButton value="Editar" action="#{VisitList.editVisit(v.id)}" icon="pi pi-check" />
</p:column> </p:column>
<f:facet name="paginatorBottomLeft"> <f:facet name="paginatorBottomLeft">
<p:commandButton update="dtVisitList" action="#{VisitList.showData}" icon="pi pi-refresh" /> <p:commandButton update="dtVisitList" action="#{VisitList.showData}" icon="pi pi-refresh" />
</f:facet> </f:facet>

View File

@@ -74,8 +74,9 @@ public class VisitFacadeBean implements VisitFacadeRemote {
strFilter += " and v.date=:date "; strFilter += " and v.date=:date ";
if (strFilter.length() > 0) { 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); TypedQuery<Long> query = entman.createQuery(strQuery, Long.class);
@@ -96,9 +97,10 @@ public class VisitFacadeBean implements VisitFacadeRemote {
strFilter += " and v.date=:date "; strFilter += " and v.date=:date ";
if (strFilter.length() > 0) { 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); TypedQuery<VisitJPA> query = entman.createQuery(strQuery, VisitJPA.class);
if (patientId != null) if (patientId != null)

View File

@@ -15,9 +15,9 @@ import javax.inject.Named;
import org.primefaces.model.LazyDataModel; import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder; import org.primefaces.model.SortOrder;
import TO.FamilyDoctorTO;
import TO.PatientTO; import TO.PatientTO;
import TO.VisitTO; import TO.VisitTO;
import common.Constants;
import common.UserType; import common.UserType;
import managedbean.common.ManagedBeanBase; import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils; import managedbean.common.SessionUtils;
@@ -33,23 +33,28 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
private Integer patientId; private Integer patientId;
private LazyDataModel<VisitTO> lazyDataModelVisitList; private LazyDataModel<VisitTO> lazyDataModelVisitList;
private Date selectedDate; private Date selectedDate;
private String lastUIQuery;
private List<PatientTO> patientList;
public PatientVisitListMBean() { public PatientVisitListMBean() {
} }
@PostConstruct @PostConstruct
public void init() { public void init() {
this.lastUIQuery = "";
// Si el usuario es un paciente listamos las visitas de ese paciente, si es admnistrador listamos todas. // 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: case ADMINISTRATOR:
this.patientId = null; this.patientId = null;
this.setPatient(null); this.patient = null;
this.selectedDate = new Date(); this.selectedDate = new Date();
this.patientList = this.getRemoteManagerCommon().listPatientsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
break; break;
case PATIENT: case PATIENT:
this.patientId = Integer.valueOf(SessionUtils.getUserId()); this.patientId = Integer.valueOf(SessionUtils.getUserId());
this.setPatient(this.getRemoteManagerCommon().findPatientById(patientId)); this.patient = this.getRemoteManagerCommon().findPatientById(patientId);
this.selectedDate = null; this.selectedDate = null;
break; break;
case FAMILY_DOCTOR: 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."); this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Acesso denegado", "Su perfil de usuario no está autorizado acceder a esta página.");
return; return;
} }
this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() { this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public List<VisitTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) { 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); Long totalRowCount = getRemoteManagerVisit().getVisitsCount(patientId, selectedDate);
this.setRowCount(totalRowCount.intValue()); 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 { public void removeVisit(Integer visitId) throws IOException {
// TODO: Eliminar visita de la BBDD // 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)); 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 { public void editVisit(Integer visitId) throws IOException {
FacesContext ctx = FacesContext.getCurrentInstance(); 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() { public LazyDataModel<VisitTO> getLazyDataModelVisitList() {
return lazyDataModelVisitList; return lazyDataModelVisitList;
} }
@@ -104,4 +127,7 @@ public class PatientVisitListMBean extends ManagedBeanBase implements Serializab
this.patient = patient; this.patient = patient;
} }
public boolean isAdmin() {
return SessionUtils.getUserType() == UserType.ADMINISTRATOR;
}
} }