This commit is contained in:
Alejandro Linares Amado
2019-12-29 22:10:38 +01:00
9 changed files with 353 additions and 272 deletions

View File

@@ -11,12 +11,12 @@ import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.UploadedFile;
import TO.MedicalTestTO;
import TO.PatientTO;
import common.Constants;
import common.MedicalTestType;
import common.UserType;
import managedbean.common.ManagedBeanBase;
@@ -33,8 +33,14 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
private List<MedicalTestTO> medicalTests;
private MedicalTestTO selected;
private PatientTO patSelected;
private PatientTO patientFilterSelected;
private boolean addNewMode = false;
private UploadedFile imageUpload;
private List<PatientTO> patientList;
private List<PatientTO> patientWithTestList;
private String lastUIQuery;
private String lastUIQueryPatFilter;
private List<MedicalTestType> medicalTestTypes;
public MedicalTestMBean() {
}
@@ -43,34 +49,48 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
public void init() {
this.userType = SessionUtils.getUserType();
this.userID = Integer.valueOf(SessionUtils.getUserId());
this.medicalTestTypes = new ArrayList<MedicalTestType>();
this.medicalTestTypes.add(MedicalTestType.BLOOD_TEST);
this.medicalTestTypes.add(MedicalTestType.CT_SCAN);
this.medicalTestTypes.add(MedicalTestType.MAGNETIC_RESONANCE_IMAGING);
this.selected = null;
this.patSelected = null;
this.lastUIQuery = "";
this.lastUIQueryPatFilter = "";
switch (userType) {
case ADMINISTRATOR:
case PATIENT:
this.patientList = null;
this.patientWithTestList = null;
break;
case SPECIALIST_DOCTOR:
this.patientList = this.getRemoteManagerCommon().listPatientsPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID, null, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
break;
case FAMILY_DOCTOR:
this.patientList = null;
this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID, null, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
}
this.loadMedicalTests();
this.getPatients();
}
public void addMedicalTest() {
getRemoteManagerMedicalTest().addMedicalTest(this.selected.getPatient().getId(), userID,
this.selected.getDate(), this.selected.getTime(), this.selected.getType(),
this.selected.getObservations());
}
public void addImage() {
if(this.imageUpload != null ) {
String content = "data:"+imageUpload.getContentType()+";base64," + Base64.getEncoder().encodeToString(imageUpload.getContents());
System.out.println("FILE Content base64: ");
System.out.println(content);
this.selected.setHighresimage(content);
if (this.imageUpload != null) {
String content = "data:" + imageUpload.getContentType() + ";base64," + Base64.getEncoder().encodeToString(imageUpload.getContents());
System.out.println("FILE Content base64: ");
System.out.println(content);
this.selected.setHighresimage(content);
getRemoteManagerMedicalTest().addImage(this.selected.getId(), content);
this.loadMedicalTests();
this.imageUpload = null;
}else {
System.out.println("IMAGEN SUBIDA ES NULA");
} else {
System.out.println("IMAGEN SUBIDA ES NULA");
}
}
public UploadedFile getImageUpload() {
return imageUpload;
}
@@ -102,35 +122,68 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
}
public void loadMedicalTests() {
if (userType == UserType.PATIENT) {
Integer patId = null;
if (this.patientFilterSelected != null)
patId = this.patientFilterSelected.getId();
switch (userType) {
case PATIENT:
// Cargar las pruebas para el paciente en sesión
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForPatient(userID);
} else if (userType == UserType.SPECIALIST_DOCTOR) {
break;
case SPECIALIST_DOCTOR:
// Cargar las pruebas que el doctor especialista ha creado
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID,
this.patIdSelected);
} else if (userType == UserType.FAMILY_DOCTOR) {
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForSpecialistDoctor(userID, patId);
break;
case FAMILY_DOCTOR:
// Cargar las pruebas para los pacientes del doctor de familia en sesión
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID,
this.patIdSelected);
} else {
// Nothing todo
this.medicalTests = new ArrayList<MedicalTestTO>();
}
this.medicalTests = getRemoteManagerMedicalTest().loadMedicalTestForFamilyDoctor(userID, patId);
break;
case ADMINISTRATOR:
this.medicalTests = null;
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Operación no válida para el tipo de usuario actual.");
break;
}
}
public List<PatientTO> getPatients() {
if (userType == UserType.SPECIALIST_DOCTOR) {
// Cargar los pacientes a los que ha añadido pruebas médicas el médico
// especialista
return getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID);
} else if (userType == UserType.FAMILY_DOCTOR) {
// Cargar los pacientes del médico de familia que tiene pruebas médicas hechas
return getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID);
} else {
// Nothing todo
return new ArrayList<PatientTO>();
public List<PatientTO> completePatient(String query) {
if (query != null && query.equals(this.lastUIQuery) == false) {
this.lastUIQuery = query;
// Recuperamos las xxx primeras coincidencias
this.patientList = this.getRemoteManagerCommon().listPatientsFiltered(query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
}
return this.patientList;
}
public List<PatientTO> completePatientFilter(String query) {
if (query != null && query.equals(this.lastUIQueryPatFilter) == false) {
this.lastUIQueryPatFilter = query;
switch (userType) {
case SPECIALIST_DOCTOR:
// Cargar los pacientes a los que ha añadido pruebas médicas el médico especialista
this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForSpecialistDoctor(userID, query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
break;
case FAMILY_DOCTOR:
// Cargar los pacientes del médico de familia que tiene pruebas médicas hechas
this.patientWithTestList = this.getRemoteManagerMedicalTest().loadPatientsForFamilyDoctor(userID, query, 0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
break;
case ADMINISTRATOR:
case PATIENT:
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Operación no válida para el tipo de usuario actual.");
this.patientWithTestList = null;
break;
}
}
return this.patientWithTestList;
}
public List<PatientTO> getPatientList() {
return patientList;
}
public List<PatientTO> getPatientWithTestList() {
return patientWithTestList;
}
public List<MedicalTestTO> getMedicalTests() {
@@ -141,18 +194,6 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
// Nothing to do
}
/*************************************************** METODOS PARA LA VISTA */
private int patIdSelected = -1;
public void setPatIdSelected(Integer value) {
this.patIdSelected = value;
this.addNewMode = false;
}
public Integer getPatIdSelected() {
return this.patIdSelected;
}
public boolean isSpecialistDoctor() {
return this.userType == UserType.SPECIALIST_DOCTOR;
}
@@ -161,10 +202,20 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
return !(userType == UserType.PATIENT);
}
public void onSelectPatient(AjaxBehaviorEvent event) {
public void clearFilteredPatient() {
this.selected = null;
this.patientFilterSelected = null;
this.loadMedicalTests();
}
public void onChangePatient(AjaxBehaviorEvent event) {
this.selected = null;
this.loadMedicalTests();
}
public void onSelectPatient(SelectEvent event) {
this.selected = null;
this.loadMedicalTests();
}
public void onSelectMT(SelectEvent event) {
@@ -173,16 +224,13 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
}
public void addMT() {
if (this.patIdSelected != -1) {
this.selected = new MedicalTestTO();
this.selected.setId(-1);
this.selected.setObservations("");
this.selected.setType(MedicalTestType.BLOOD_TEST);
this.addNewMode = true;
} else {
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Atención!",
"Debe elegir un paciente al que añadir la prueba médica.");
}
// Si hay un paciente filtrado en la busqueda de pruebas, lo seleccionamos para la prueba a añadir.
this.patSelected = this.patientFilterSelected;
this.selected = new MedicalTestTO();
this.selected.setId(-1);
this.selected.setObservations("");
this.selected.setType(MedicalTestType.BLOOD_TEST);
this.addNewMode = true;
}
public boolean isAddNewMode() {
@@ -202,44 +250,32 @@ public class MedicalTestMBean extends ManagedBeanBase implements Serializable {
}
public List<MedicalTestType> getMedicalTestTypes() {
ArrayList<MedicalTestType> list = new ArrayList<MedicalTestType>();
list.add(MedicalTestType.BLOOD_TEST);
list.add(MedicalTestType.CT_SCAN);
list.add(MedicalTestType.MAGNETIC_RESONANCE_IMAGING);
return list;
}
public String getMedicalTestTypeSelected() {
return this.selected.getType().getName();
}
public void setMedicalTestTypeSelected(String val) {
System.out.println("********************************");
System.out.println(val);
System.out.println("********************************");
MedicalTestType mt;
if (val.equals("BLOOD_TEST")) {
mt = MedicalTestType.BLOOD_TEST;
} else if (val.equals("CT_SCAN")) {
mt = MedicalTestType.CT_SCAN;
} else {
mt = MedicalTestType.MAGNETIC_RESONANCE_IMAGING;
}
this.selected.setType(mt);
System.out.println("********************************");
System.out.println(this.selected.getType());
System.out.println("********************************");
return this.medicalTestTypes;
}
public void save() {
String res = getRemoteManagerMedicalTest().addMedicalTest(this.patIdSelected, userID, this.selected.getDate(),
this.selected.getTime(), this.selected.getType(), this.selected.getObservations());
if (res.equals("ok")) {
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Éxito", "Guardado correctamente");
} else {
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Error", res);
try {
MedicalTestTO mt = this.getRemoteManagerMedicalTest().addMedicalTest(this.patSelected.getId(), this.userID, this.selected.getDate(), this.selected.getTime(),
this.selected.getType(), this.selected.getObservations());
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Éxito", String.format("La prueba médica se ha guardado correctamente, el identificador asignado es: %d", mt.getId()));
// Volvemos al modo añadir (limpiamos el formulario).
this.addMT();
this.loadMedicalTests();
} catch (Exception ex) {
this.manageException(ex);
}
this.loadMedicalTests();
}
public PatientTO getPatientFilterSelected() {
return patientFilterSelected;
}
public void setPatientFilterSelected(PatientTO patientFilterSelected) {
this.patientFilterSelected = patientFilterSelected;
}
}