únicos para (Pacientes, medicos de familia, medicos especialista y administradores). Nuevos métodos en EJB común para consultar Entidades por Id y por código (Para el login).
128 lines
3.8 KiB
Java
128 lines
3.8 KiB
Java
package managedbean.profile;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.application.FacesMessage;
|
|
import javax.faces.view.ViewScoped;
|
|
import javax.inject.Named;
|
|
|
|
import TO.FamilyDoctorTO;
|
|
import TO.LoggedUserTO;
|
|
import TO.PrimaryHealthCareCenterTO;
|
|
import common.Constants;
|
|
import common.UserType;
|
|
import managedbean.common.ManagedBeanBase;
|
|
import managedbean.common.SessionUtils;
|
|
|
|
/***
|
|
*
|
|
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
|
*
|
|
*/
|
|
@Named("ChangeCAP")
|
|
@ViewScoped
|
|
public class ChangePrimaryHealthCareCenterMBean extends ManagedBeanBase implements Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private int id;
|
|
private PrimaryHealthCareCenterTO currentCenter;
|
|
private PrimaryHealthCareCenterTO newCenter;
|
|
private List<PrimaryHealthCareCenterTO> primaryHealthCareCentersList;
|
|
private String lastUIQuery;
|
|
|
|
public ChangePrimaryHealthCareCenterMBean() {
|
|
|
|
}
|
|
|
|
@PostConstruct
|
|
public void init() {
|
|
// Recuperamos el usuario logeado actual
|
|
LoggedUserTO usr = null;
|
|
this.lastUIQuery = "";
|
|
|
|
try {
|
|
usr = SessionUtils.getloggedOnUser();
|
|
|
|
if (usr == null)
|
|
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
|
|
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
|
|
else {
|
|
this.id = Integer.valueOf(usr.getId());
|
|
|
|
if (usr.getUserType() == UserType.FAMILY_DOCTOR) {
|
|
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
|
|
|
FamilyDoctorTO fd = this.getRemoteManagerCommon().findFamilyDoctorById(this.id);
|
|
this.setCurrentCenter(fd.getPrimaryHealthCareCenter());
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
this.manageException(e);
|
|
}
|
|
|
|
}
|
|
|
|
public List<PrimaryHealthCareCenterTO> getPhcList() {
|
|
return primaryHealthCareCentersList;
|
|
}
|
|
|
|
public List<PrimaryHealthCareCenterTO> completePrimaryHealCareCenter(String query) {
|
|
if (query != null && query.equals(this.lastUIQuery) == false) {
|
|
this.lastUIQuery = query;
|
|
// Recuperamos las 200 primeras coincidencias
|
|
this.primaryHealthCareCentersList = this.getRemoteManagerCommon().listCAPsFiltered(query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
|
}
|
|
return this.primaryHealthCareCentersList;
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public void saveData() {
|
|
int error = 0;
|
|
|
|
if (this.getNewCenter() == null) {
|
|
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Centro de atención primaria no seleccionado", "Por favor, especifique un nuevvo centro de atención primaria.");
|
|
error++;
|
|
}
|
|
|
|
if (this.getNewCenter().getName().equals(this.getCurrentCenter().getName())) {
|
|
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "El centro de atención primeria debe ser diferente", "Por favor, seleccione un centro de atención primaria diferente al cual está actualmente asignado.");
|
|
error++;
|
|
}
|
|
|
|
if (error == 0) {
|
|
try {
|
|
FamilyDoctorTO fd = this.getRemoteManagerProfile().changePrimaryHealthCareCenter(this.id, this.getNewCenter());
|
|
this.currentCenter = fd.getPrimaryHealthCareCenter();
|
|
this.newCenter = null;
|
|
|
|
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Su centro de atención primaria asignado se ha cambiado correctamente.");
|
|
} catch (Exception e) {
|
|
this.manageException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public PrimaryHealthCareCenterTO getCurrentCenter() {
|
|
return currentCenter;
|
|
}
|
|
|
|
public void setCurrentCenter(PrimaryHealthCareCenterTO currentCenter) {
|
|
this.currentCenter = currentCenter;
|
|
}
|
|
|
|
public PrimaryHealthCareCenterTO getNewCenter() {
|
|
return newCenter;
|
|
}
|
|
|
|
public void setNewCenter(PrimaryHealthCareCenterTO newCenter) {
|
|
this.newCenter = newCenter;
|
|
}
|
|
|
|
}
|