Filtro por paciente para la consulta y modificación de visitas por parte
de un administrador.
This commit is contained in:
@@ -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