/**
* @(#) PersistenciaVTaprescrTamedico.java
*/
package com.tarisan.control;
import com.tarisan.data.VTaprescrTamedico;
import com.tarisan.log.*;
import com.tarisan.util.Utilidades;
import com.tarisan.excepcion.ExcepcionTarisan;
import java.sql.*;
import java.util.Vector;
/**
* Controla los accesos a la persistencia para la entidad VTaprescrTamedico.
* @author Dpto. Informática.
* @version 1.0, 24/09/2003
*/
public class PersistenciaVTaprescrTamedico
{
/**
* El objeto Paginacion que controla el número de filas a mostrar por cada página.
*/
private Paginacion objPaginacion = new Paginacion();
/**
* Obtiene el valor del objeto Paginacion para saber que página se está visualizando.
* @return El objeto Paginacion.
*/
public Paginacion getPaginacion()
{
return objPaginacion;
}
/**
* Selecciona los registros de las tablas TAMEDICO y TAPRESCR en función de la sentencia SELECT indicada.
* @param sqlSelect La sentencia SELECT de selección.
* @param pagina Número de página a mostrar.
* @param aCondiciones Array que contiene los parámetros utilizados en la sentencia SELECT.
* @return El Vector con los registros seleccionados (todos pertenencientes a la clase VTaprescrTamedico).
* @throws
*/
public Vector seleccionar(String sqlSelect, int pagina, Object[] aCondiciones) throws ExcepcionTarisan
{
int elementosPaginacion=1;
Vector vResultado = new Vector();
VTaprescrTamedico vTaprescrTamedico = null;
try
{
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect, aCondiciones);
objPaginacion.inicializarPaginacion(rs);
if (objPaginacion.getNumeroRegistrosTotales()!=0)
{
objPaginacion.realizarPaginacion(rs, pagina);
while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina()))
{
vTaprescrTamedico = new VTaprescrTamedico();
vTaprescrTamedico.setNombre(rs.getString("NOMBRE"));
vTaprescrTamedico.setApellidos(rs.getString("APELLIDOS"));
vTaprescrTamedico.setImporte(rs.getDouble("IMPORTE"));
vResultado.addElement(vTaprescrTamedico);
if (pagina!=0) //Se quiere realizar la paginacion
elementosPaginacion++;
}
}
rs.close();
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TAPRESCR (" + sqlSelect + ")");
}
catch (ExcepcionTarisan sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAPRESCR: " + sqle + " (" + sqlSelect + ")");
throw (ExcepcionTarisan)sqle;
}
catch(SQLException sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAPRESCR: " + sqle + " (" + sqlSelect + ")");
throw new ExcepcionTarisan(sqle.getMessage());
}
catch(Exception sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAPRESCR: " + sqle + " (" + sqlSelect + ")");
throw new ExcepcionTarisan(sqle.getMessage());
}
catch(Throwable sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAPRESCR: " + sqle + " (" + sqlSelect + ")");
throw new ExcepcionTarisan(sqle.getMessage());
}
return vResultado;
}
/**
* Obtiene el importe total de las prescripciones de un determinado médico.
* @param medico Código del médico prescriptor.
* @param anio año que sirve de filtro para obtener las prescripciones para un determinado año. En caso de que no se quiera realizar ningún filtro, el valor de este campo será 0.
* @return El importe total asociado a las prescripciones del médico indicado.
* @throws
*/
public double obtenerImporteTotal(int medico, int anio) throws ExcepcionTarisan
{
StringBuffer strSql = new StringBuffer();
Object aCondiciones[]=null;
double dblImporteTotal = 0;
try
{
strSql.append("SELECT SUM(IMPORTE) AS IMPORTE_TOTAL");
strSql.append(" FROM TAPRESCR");
strSql.append(" WHERE PRESCRIPTOR=?");
if (anio!=0) //se hace el filtro de las prescripciones por un determinado año.
{
strSql.append(" AND ANO=?");
aCondiciones = new Object[2];
aCondiciones[1] = Integer.valueOf(anio);
}
else //se sacan todas las prescripciones. No se tiene en cuenta el año.
aCondiciones = new Object[1];
aCondiciones[0]=Integer.valueOf(medico);
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones);
//nos posicionamos en el registro
if (rs.next())
//obtenemos el campo PARAM1
dblImporteTotal = rs.getDouble("IMPORTE_TOTAL");
rs.close();
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
LogTarisan.logger.log(NivelLog.DEBUG, "El importe total de las prescripciones de la tabla TAPRESCR es: " + dblImporteTotal + " (" + strSql.toString() + ")");
}
catch (ExcepcionTarisan sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la obtención del importe total de las prescripciones de la tabla TAPRESCR: " + sqle + " (" + strSql.toString() + ")");
throw (ExcepcionTarisan)sqle;
}
catch(SQLException sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la obtención del importe total de las prescripciones de la tabla TAPRESCR: " + sqle + " (" + strSql.toString() + ")");
throw new ExcepcionTarisan(sqle.getMessage());
}
catch(Exception sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la obtención del importe total de las prescripciones de la tabla TAPRESCR: " + sqle + " (" + strSql.toString() + ")");
throw new ExcepcionTarisan(sqle.getMessage());
}
catch(Throwable sqle)
{
LogTarisan.logger.log(NivelLog.ERROR, "Error en la obtención del importe total de las prescripciones de la tabla TAPRESCR: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage());
}
return dblImporteTotal;
}
public Vector listado_prescripciones(String anio, int medico, int intPagina)
{
Vector resul = new Vector();
StringBuffer strSql = new StringBuffer();
Object [] aCondiciones = new Object[1];
String consulta = "";
strSql.append("SELECT TAMEDICO.NOMBRE, TAMEDICO.APELLIDOS, TAPRESCR.IMPORTE");
strSql.append(" FROM TAMEDICO, TAPRESCR");
strSql.append(" WHERE TAMEDICO.MEDICO=TAPRESCR.MEDICO");
strSql.append(" AND TAPRESCR.PRESCRIPTOR=?");
if (!anio.equalsIgnoreCase("")) //se realiza una busqueda por año
{
strSql.append(" AND TAPRESCR.ANO=?");
//la consulta sql tendra dos parametros
aCondiciones = new Object[2];
aCondiciones[1] = Integer.valueOf(anio);
}
else //no se realiza busqueda por año
//la consulta sql tendra un solo parametro
aCondiciones = new Object[1];
strSql.append(" ORDER BY TAMEDICO.NOMBRE, TAMEDICO.APELLIDOS");
aCondiciones[0] = Integer.valueOf(medico);
try {
resul = this.seleccionar(strSql.toString(), intPagina, aCondiciones);
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
} catch (ExcepcionTarisan e) {
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tamedico_Taprescr (listado_prescripciones): " + e + " (" + consulta + ")");
}
return resul;
}
}