/** * @(#) PersistenciaTamovext.java */ package com.tarisan.control; import com.tarisan.data.*; import com.tarisan.excepcion.*; import com.tarisan.log.*; import com.tarisan.util.Utilidades; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.sql.Date; import java.util.Calendar; import java.util.Vector; /** * Controla los accesos a la persistencia para la entidad Tamovext. * @author Dpto. Informática. * @version 1.0, 24/09/2003 */ public class PersistenciaTamovext { /** * 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; } /** * Obtiene el último valor del campo NUMSEQ del médico indicado perteneciente a la tabla TAMOVEXT. * @param medico Código del médico conectado. * @return El último valor del campo NUMSEQ del médico en cuestión. * @throws * * OBSOLETO * 25/10/2017 * csm_jjripaper * Cambiamos en oracle el campo numseq al tipo autoincrement de oracle (trigger berfore insert llamando a una secuencia). */ public int obtenerUltimoValorNumSeq2(int medico) throws ExcepcionTarisan { StringBuffer strSql = new StringBuffer(); Object aCondiciones[]=null; int intUltimoValorNumseq = 1; try { /* strSql.append("SELECT MAX(numseq) as max_numseq"); strSql.append(" FROM tamovext"); strSql.append(" WHERE medico=?");*/ /* * Cambiamos a una secuencia por que estamos viendo que hay veces que no incrementa bien el contador * // select NUMSEQ_SEQ.nextval from dual; */ /*strSql.append("select NUMSEQ_SEQ.nextval as MAXNUMSEQ"); strSql.append(" FROM dual");*/ String sql = "select NUMSEQ_SEQ.nextval as MAXNUMSEQ FROM dual"; aCondiciones = new Object[1]; aCondiciones[0]=Integer.valueOf(medico); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sql/*, aCondiciones*/); //nos posicionamos en el registro if (rs.next()) //obtenemos el campo PARAM1 intUltimoValorNumseq = rs.getInt("MAXNUMSEQ"); rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionado el valor " + intUltimoValorNumseq + " del campo NUMSEQ de la tabla TAMOVEXT (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return intUltimoValorNumseq; } /** * Añade a la tabla TAMOVEXT un nuevo registro según la sentencia INSERT indicada. * @param sqlSelect La sentencia INSERT. * @param aValores Array que contiene los valores de los parámetros utilizados en la sentencia. * @throws */ public void insertarMovimiento(String sqlSelect, Object[] aValores) throws ExcepcionTarisan { try { ParametrosConfiguracion.dataStore.insertar(sqlSelect, aValores); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw (ExcepcionTarisan)sqle; } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } } /** * Añade a la tabla TAMOVEXT un nuevo registro según la sentencia INSERT indicada. * @param sqlSelect La sentencia INSERT. * @param aValores Array que contiene los valores de los parámetros utilizados en la sentencia. * @param conexion La conexión por la que se ejecuta la sentencia. Utilizado para el uso transacciones. * @throws */ public void insertarMovimiento(String sqlSelect, Object[] aValores, Connection conexion) throws ExcepcionTarisan { try { ParametrosConfiguracion.dataStore.insertar(sqlSelect, aValores, conexion); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw (ExcepcionTarisan)sqle; } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + sqlSelect + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } } /** * Busca un movimiento en tamovex, devuelve cierto si lo encuentra * @param aCondiciones * @param conexion * @return */ public boolean buscarDuplicadoTamovext(Object[] aCondiciones, Connection conexion) { boolean resultado = false; StringBuffer strSql = new StringBuffer(); strSql.append("Select * from TAMOVEXT"); strSql.append("where MEDICO = ?"); strSql.append("and ESPECIALIDAD = ?"); strSql.append("and ACTO = ?"); strSql.append("and COLECTIVO = ?"); strSql.append("and POLIZA = ?"); strSql.append("and ORDEN = ?"); strSql.append("and FECHA = ?"); try { ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) resultado = true; } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } return resultado; } public boolean insertarTamovext(Object[] aValores, Connection conexion) { boolean resultado = false; StringBuffer strSql = new StringBuffer(); strSql.append("INSERT INTO TAMOVEXT"); strSql.append(" (MEDICO, ESPECIALIDAD, ACTO, COLECTIVO, POLIZA, ORDEN, FECHA, PRECIO, PRESCRIPTOR, ENTIDAD, TARJETA_CHIPCARD, AUTORIZACION, ESPECIALIDAD_CHIPCARD, ACTO_CHIPCARD)"); strSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); try { ParametrosConfiguracion.dataStore.insertar(strSql.toString(), aValores, conexion); resultado = true; } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } return resultado; } public boolean insertarTamovextDesplazado(Object[] aValores, Connection conexion) { boolean resultado = false; StringBuffer strSql = new StringBuffer(); strSql.append("INSERT INTO TAMOVEXT"); strSql.append(" (MEDICO, ESPECIALIDAD, ACTO, COLECTIVO, POLIZA, ORDEN, FECHA, PRECIO, PRESCRIPTOR, TARJETA_CHIPCARD, ESPECIALIDAD_CHIPCARD, ACTO_CHIPCARD, TALON_CHIPCARD, ENTIDAD, AUTORIZACION)"); strSql.append(" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); try { resultado = ParametrosConfiguracion.dataStore.insertar(strSql.toString(), aValores, conexion); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } return resultado; } public boolean tieneRevisionHoy(int medico, String tarjeta, boolean chipcard) { boolean resul = false; StringBuffer strSql = new StringBuffer(); java.sql.Date intUltimoValorNumseq = null; java.sql.Date dtFecha = null; Object[] aCondiciones; try { strSql.append("SELECT fecha"); strSql.append(" FROM tamovext"); strSql.append(" WHERE medico="+medico); strSql.append(" and tarjeta_chipcard='"+tarjeta+"'"); strSql.append(" and acto in (1,2)"); Calendar calFechaActual = Calendar.getInstance(); int mes = calFechaActual.get(Calendar.MONTH)+1; String strhoy = calFechaActual.get(Calendar.DAY_OF_MONTH)+"/"+mes+"/"+calFechaActual.get(Calendar.YEAR); strSql.append(" and fecha = to_date('"+strhoy+"', 'dd/mm/yyyy')"); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); LogTarisan.logger.log(NivelLog.DEBUG, "Consulta: "+strSql.toString()); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString()); //nos posicionamos en el registro if (rs.next()) //obtenemos el campo PARAM1 resul = true; } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT (TIENE REVISION DESPLAZADO): " + sqle + " (" + strSql.toString() + ")"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public boolean tieneRevisionHoyColPolOrd(int medico, long colectivo, double poliza, int beneficiario, boolean chipcard) { boolean resul = false; StringBuffer strSql = new StringBuffer(); java.sql.Date intUltimoValorNumseq = null; java.sql.Date dtFecha = null; Object[] aCondiciones; try { strSql.append("SELECT fecha"); strSql.append(" FROM tamovext"); strSql.append(" WHERE medico="+medico); strSql.append(" and colectivo="+colectivo); strSql.append(" and poliza="+poliza); strSql.append(" and orden="+beneficiario); strSql.append(" and acto in (1,2)"); Calendar calFechaActual = Calendar.getInstance(); int mes = calFechaActual.get(Calendar.MONTH)+1; String strhoy = calFechaActual.get(Calendar.DAY_OF_MONTH)+"/"+mes+"/"+calFechaActual.get(Calendar.YEAR); strSql.append(" and fecha = to_date('"+strhoy+"', 'dd/mm/yyyy')"); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); LogTarisan.logger.log(NivelLog.DEBUG, "Consulta: "+strSql.toString()); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString()); //nos posicionamos en el registro if (rs.next()) //obtenemos el campo PARAM1 resul = true; } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT (TIENE REVISION DESPLAZADO): " + sqle + " (" + strSql.toString() + ")"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } /** * Comprueba si un asegurado determinado ya ha tenido consulta de "chipcard" para un médico determinado. * * @param medico el médico para el que buscamos * @param tarjeta la tarjeta chipcard que buscamos * @return cierto si hay acto "consulta" en tamovext */ public boolean tieneConsultaChipcard(int medico, String tarjeta) { boolean resul = false; StringBuffer strSql = new StringBuffer(); Object[] aCondiciones; try { strSql.append("Select count(*) COUNT from tamovext"); strSql.append(" where medico = ?"); strSql.append(" and tarjeta_chipcard=?"); strSql.append(" and acto_chipcard=1"); aCondiciones = new Object[2]; aCondiciones[0] = Integer.valueOf(medico); aCondiciones[1] = new String(tarjeta); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { if(rs.getInt("COUNT")>0) resul = true; } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "La tarjeta "+tarjeta+" tiene consulta en tamovext para el medico "+medico+": "+resul); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT (PRIMERA VISITA DESPLAZADO): " + sqle + " (" + strSql.toString() + ")"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public boolean esPrimeraVisitaDesplazado(int medico, String tarjeta, boolean chipcard) { boolean resul = false; StringBuffer strSql = new StringBuffer(); java.sql.Date intUltimoValorNumseq = null; java.sql.Date dtFecha = null; Object[] aCondiciones; try { strSql.append("SELECT fecha"); strSql.append(" FROM tamovext"); strSql.append(" WHERE medico=?"); strSql.append(" and tarjeta_chipcard=?"); strSql.append(" and acto in (1)"); aCondiciones = new Object[2]; aCondiciones[0]=Integer.valueOf(medico); aCondiciones[1]=new String(tarjeta); 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 dtFecha = rs.getDate("fecha"); rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); //YA TENEMOS LA FECHA DE LA ÚLTIMA VISITA (O NULL SI NO HA VENIDO NUNCA) if (dtFecha!=null) //existe registro. Se comprueba si es la primera visita { Calendar calFechaPrimeraVisita = Calendar.getInstance(); calFechaPrimeraVisita.setTime(dtFecha); Calendar calFechaActual = Calendar.getInstance(); if (ParametrosConfiguracion.periodoNatural.equalsIgnoreCase("si")) //se trata de un periodo natural { if (calFechaActual.get(Calendar.YEAR)>calFechaPrimeraVisita.get(Calendar.YEAR)) { //años diferentes resul = true; } else { if (calFechaActual.get(Calendar.YEAR)==calFechaPrimeraVisita.get(Calendar.YEAR )) //mismo año { //le sumamos a la fecha obtenida el periodo de meses para conocer si es primera visita if(chipcard) calFechaPrimeraVisita.add(Calendar.MONTH, ParametrosConfiguracion.periodoPrimeraVisitaChipcard); else calFechaPrimeraVisita.add(Calendar.MONTH, ParametrosConfiguracion.periodoPrimeraVisita); if ( calFechaPrimeraVisita.getTime().compareTo( calFechaActual.getTime() ) < 0 ) { //la fecha de la primera visita mas el periodo es inferior a la fecha actual resul = true; } } } } else //se trata de un periodo no natural { //le sumamos a la fecha obtenida el periodo de meses para conocer si es primera visita calFechaPrimeraVisita.add(Calendar.MONTH, ParametrosConfiguracion.periodoPrimeraVisita); if ( calFechaPrimeraVisita.getTime().compareTo( calFechaActual.getTime() ) < 0 ) //la fecha de la primera visita mas el periodo es inferior a la fecha actual resul = true; } } else { //No existe registro. Es primera visita resul = true; } LogTarisan.logger.log(NivelLog.DEBUG, "Es primera visita DESPLAZADO: " + resul +" (" + strSql.toString() + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT (PRIMERA VISITA DESPLAZADO): " + sqle + " (" + strSql.toString() + ")"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector ObtenerMovimientosMismaPolizaYMedico(int medico, int espe, int acto, int entidad, long col, long pol, int ord) { Vector resul = new Vector();; StringBuffer sqlSelect = new StringBuffer(); Object[] aCondiciones = new Object[7]; try { sqlSelect.append("Select * from tamovext_espia "); sqlSelect.append("where medico = ? "); sqlSelect.append("and especialidad = ? "); sqlSelect.append("and acto = ? "); sqlSelect.append("and entidad = ? "); sqlSelect.append("and colectivo = ? "); sqlSelect.append("and poliza = ? "); sqlSelect.append("and orden = ? "); sqlSelect.append("order by fecha desc "); aCondiciones[0] = Integer.valueOf(medico); aCondiciones[1] = Integer.valueOf(espe); aCondiciones[2] = Integer.valueOf(acto); aCondiciones[3] = Integer.valueOf(entidad); aCondiciones[4] = Long.valueOf(col); aCondiciones[5] = Long.valueOf(pol); aCondiciones[6] = Integer.valueOf(ord); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones); while (rs.next()) { Tamovext ta = new Tamovext(); ta.setMedico(rs.getInt("MEDICO")); ta.setEspecialidad(rs.getInt("ESPECIALIDAD")); ta.setActo(rs.getInt("ACTO")); ta.setNumseq(rs.getInt("NUMSEQ")); ta.setEntidad(rs.getInt("ENTIDAD")); ta.setColec(rs.getInt("COLECTIVO")); ta.setPoliza(rs.getDouble("POLIZA")); ta.setOrden(rs.getInt("ORDEN")); ta.setFecha(rs.getDate("FECHA")); ta.setPrecio(rs.getDouble("PRECIO")); ta.setPrescriptor(rs.getInt("PRESCRIPTOR")); ta.setAutorizacion(rs.getLong("AUTORIZACION")); /* * TODO faltan los de chipcard */ resul.add(ta); } } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT obteniendo movimientos previos de la misma poliza y medico"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector ObtenerMovimientosAutorizacion(long autorizacion) { Vector resul = new Vector();; StringBuffer sqlSelect = new StringBuffer(); Object[] aCondiciones = new Object[1]; try { sqlSelect.append("Select * from tamovext_espia "); sqlSelect.append("where autorizacion = ? "); sqlSelect.append("order by fecha desc "); aCondiciones[0] = Long.valueOf(autorizacion); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones); while (rs.next()) { Tamovext ta = new Tamovext(); ta.setMedico(rs.getInt("MEDICO")); ta.setEspecialidad(rs.getInt("ESPECIALIDAD")); ta.setActo(rs.getInt("ACTO")); ta.setNumseq(rs.getInt("NUMSEQ")); ta.setEntidad(rs.getInt("ENTIDAD")); ta.setColec(rs.getInt("COLECTIVO")); ta.setPoliza(rs.getDouble("POLIZA")); ta.setOrden(rs.getInt("ORDEN")); ta.setFecha(rs.getDate("FECHA")); ta.setPrecio(rs.getDouble("PRECIO")); ta.setPrescriptor(rs.getInt("PRESCRIPTOR")); ta.setAutorizacion(rs.getLong("AUTORIZACION")); /* * TODO faltan los de chipcard */ resul.add(ta); } } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT obteniendo movimientos previos de la misma poliza y medico"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector AnaliticasCapturadasTotal(int medico) { return this.AnaliticasCapturadas(medico, null, null); } public Vector AnaliticasCapturadasDesde(int medico, java.sql.Date fecini) { return this.AnaliticasCapturadas(medico, fecini, null); } public Vector AnaliticasCapturadasHasta(int medico, java.sql.Date fecfin) { return this.AnaliticasCapturadas(medico, null, fecfin); } public Vector AnaliticasCapturadas(int medico, java.sql.Date fecini, java.sql.Date fecfin) { Vector resul = new Vector(); StringBuffer sqlSelect = new StringBuffer(); Object[] aCondiciones = null; int i = 1; try { /* * select tamovext_espia.autorizacion , TTCLIENT.APELLIDOS, ttactmed.DESCRIPCION from tamovext_espia, ttactmed, TTBENEFI, TTCLIENT where TAMOVEXT_ESPIA.MEDICO = 363 and TAMOVEXT_ESPIA.ACTO = ttactmed.ACTO and TAMOVEXT_ESPIA.ESPECIALIDAD = ttactmed.ESPECIALIDAD and TAMOVEXT_ESPIA.entidad = TTBENEFI.ENTIDAD and TAMOVEXT_ESPIA.COLECTIVO = TTBENEFI.COLECTIVO and TAMOVEXT_ESPIA.POLIZA = TTBENEFI.POLIZA and TAMOVEXT_ESPIA.ORDEN = TTBENEFI.ORDEN and TTBENEFI.CLIENTE = TTCLIENT.CLIENTE order by TAMOVEXT_ESPIA.FECHA desc */ sqlSelect.append("select distinct(TTCLIENT.APELLIDOS), tamovext_espia.autorizacion, TAMOVEXT_ESPIA.FECHA "); sqlSelect.append("from tamovext_espia, TTBENEFI, TTCLIENT "); sqlSelect.append("where TAMOVEXT_ESPIA.MEDICO = ? "); sqlSelect.append("and TAMOVEXT_ESPIA.entidad = TTBENEFI.ENTIDAD "); sqlSelect.append("and TAMOVEXT_ESPIA.COLECTIVO = TTBENEFI.COLECTIVO "); sqlSelect.append("and TAMOVEXT_ESPIA.POLIZA = TTBENEFI.POLIZA "); sqlSelect.append("and TAMOVEXT_ESPIA.ORDEN = TTBENEFI.ORDEN "); sqlSelect.append("and TTBENEFI.CLIENTE = TTCLIENT.CLIENTE "); //si hay fecha inicio if(fecini != null) { sqlSelect.append("and tamovext_espia.fecha >= ? "); i+=1; } if(fecfin != null) { sqlSelect.append("and tamovext_espia.fecha <= ? "); i+=1; } sqlSelect.append("order by TAMOVEXT_ESPIA.FECHA desc "); aCondiciones = new Object[i]; aCondiciones[0] = Integer.valueOf(medico); if(fecini != null) { aCondiciones[1] = fecini; if(fecfin != null) { aCondiciones[2] = fecfin; } } else if(fecfin != null) aCondiciones[1] = fecfin; Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones); while (rs.next()) { Object[] aResultados = new Object[3]; aResultados[0] = new String(rs.getString(1)); aResultados[1] = Long.valueOf(rs.getLong(2)); aResultados[2] = rs.getDate(3); resul.addElement(aResultados); } } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT obteniendo AnaliticasCapturadas"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector MovimientosCapturadosPorMedico(int pagina, int medico, int especialidad) { Vector resul = new Vector(); StringBuffer sqlSelect = new StringBuffer(); Object[] aCondiciones = null; int elementosPaginacion=1; try { sqlSelect.append("select distinct(TTCLIENT.APELLIDOS), tamovext.autorizacion, TAMOVEXT.FECHA, SUM(TAMOVEXT.PRECIO) "); sqlSelect.append("from tamovext, TTBENEFI, TTCLIENT "); sqlSelect.append("where TAMOVEXT.MEDICO = ? "); sqlSelect.append("and TAMOVEXT.entidad = TTBENEFI.ENTIDAD "); sqlSelect.append("and TAMOVEXT.COLECTIVO = TTBENEFI.COLECTIVO "); sqlSelect.append("and TAMOVEXT.POLIZA = TTBENEFI.POLIZA "); sqlSelect.append("and TAMOVEXT.ORDEN = TTBENEFI.ORDEN "); sqlSelect.append("and TTBENEFI.CLIENTE = TTCLIENT.CLIENTE "); sqlSelect.append("and TAMOVEXT.ESPECIALIDAD = ? "); sqlSelect.append("GROUP BY TTCLIENT.APELLIDOS, tamovext.autorizacion, TAMOVEXT.FECHA"); aCondiciones = new Object[2]; aCondiciones[0] = Integer.valueOf(medico); aCondiciones[1] = Integer.valueOf(especialidad); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones); objPaginacion.inicializarPaginacion(rs); if (objPaginacion.getNumeroRegistrosTotales()!=0) { objPaginacion.realizarPaginacion(rs, pagina); while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina())) { Object[] aResultados = new Object[4]; aResultados[0] = new String(rs.getString(1)); aResultados[1] = Long.valueOf(rs.getLong(2)); aResultados[2] = rs.getDate(3); aResultados[3] = Double.valueOf(rs.getDouble(4)); resul.addElement(aResultados); if (pagina!=0) //Se quiere realizar la paginacion elementosPaginacion++; } } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + resul.size() + " movimientos (análisis o radiodiagnósticos) de la tabla TAMOVEXT (" + sqlSelect + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT obteniendo MovimientosCapturadosPorMedico"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector MovimientosCapturadosDetallePorAutorizacion(int pagina, int medico, long autorizacion, int especialidad) { Vector resul = new Vector(); StringBuffer sqlSelect = new StringBuffer(); Object[] aCondiciones = null; int elementosPaginacion=1; try { sqlSelect.append("select distinct(TTCLIENT.APELLIDOS), tamovext.autorizacion, TAMOVEXT.FECHA, TTACTMED.acto, TTACTMED.DESCRIPCION, TAMOVEXT.PRECIO "); sqlSelect.append("from tamovext, TTACTMED, TTBENEFI, TTCLIENT "); sqlSelect.append("where TAMOVEXT.MEDICO = ? "); sqlSelect.append("AND TTACTMED.acto = TAMOVEXT.acto "); sqlSelect.append("AND TTACTMED.especialidad = ? "); sqlSelect.append("and TAMOVEXT.autorizacion = ? "); sqlSelect.append("and TAMOVEXT.entidad = TTBENEFI.ENTIDAD "); sqlSelect.append("and TAMOVEXT.COLECTIVO = TTBENEFI.COLECTIVO "); sqlSelect.append("and TAMOVEXT.POLIZA = TTBENEFI.POLIZA "); sqlSelect.append("and TAMOVEXT.ORDEN = TTBENEFI.ORDEN "); sqlSelect.append("and TTBENEFI.CLIENTE = TTCLIENT.CLIENTE "); aCondiciones = new Object[3]; aCondiciones[0] = Integer.valueOf(medico); aCondiciones[1] = Integer.valueOf(especialidad); aCondiciones[2] = Long.valueOf(autorizacion); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones); objPaginacion.inicializarPaginacion(rs); if (objPaginacion.getNumeroRegistrosTotales()!=0) { objPaginacion.realizarPaginacion(rs, pagina); while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina())) { Object[] aResultados = new Object[6]; aResultados[0] = new String(rs.getString(1)); aResultados[1] = Long.valueOf(rs.getLong(2)); aResultados[2] = new String(Utilidades.formatear_fecha(rs.getDate(3))); aResultados[3] = Integer.valueOf(rs.getInt(4)); aResultados[4] = new String(rs.getString(5)); aResultados[5] = Double.valueOf(rs.getDouble(6)); resul.addElement(aResultados); if (pagina!=0) //Se quiere realizar la paginacion elementosPaginacion++; } } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + resul.size() + " analisis de la tabla TAMOVEXT (" + sqlSelect + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMOVEXT obteniendo AnaliticasCapturadasPorMedico"); } catch (ExcepcionTarisan e) { // TODO Auto-generated catch block e.printStackTrace(); } return resul; } public Vector MovimientosImputados(int pagina, int medico, String fecha, String apellido1, String apellido2, String nombre) { Vector vResultado = new Vector(); int elementosPaginacion=1; StringBuffer sqlSelect = new StringBuffer(); try { if (fecha=="") fecha="%"; if (apellido1=="") apellido1="%"; if (apellido2=="") apellido2="%"; if (nombre=="") nombre="%"; sqlSelect.append("SELECT TAMOVEXT.MEDICO, TAMOVEXT.FECHA, TAMOVEXT.ACTO, TAMOVEXT.ENTIDAD, TTCLIENT.APELLIDO1, TTCLIENT.APELLIDO2, TTCLIENT.NOMBRE, TAMOVEXT.ESPECIALIDAD, TAMOVEXT.NUMSEQ, TAMOVEXT.COLECTIVO, TAMOVEXT.POLIZA, TAMOVEXT.ORDEN "); sqlSelect.append("FROM tamovext, ttbenefi, ttclient "); sqlSelect.append("WHERE TAMOVEXT.MEDICO = "+ medico + " "); if (fecha=="%") sqlSelect.append("AND tamovext.fecha LIKE '%"+ fecha +"%' "); else sqlSelect.append("AND tamovext.fecha = '"+ fecha +"' "); sqlSelect.append("AND TTCLIENT.APELLIDO1 LIKE '%"+ apellido1 +"%' "); sqlSelect.append("AND TTCLIENT.APELLIDO2 LIKE '%"+ apellido2 +"%' "); sqlSelect.append("AND TTCLIENT.NOMBRE LIKE '%"+ nombre +"%' "); sqlSelect.append("AND TTBENEFI.COLECTIVO = TAMOVEXT.COLECTIVO "); sqlSelect.append("AND TTBENEFI.POLIZA = TAMOVEXT.POLIZA "); sqlSelect.append("AND TTBENEFI.ORDEN = TAMOVEXT.ORDEN "); sqlSelect.append("AND TTCLIENT.CLIENTE = TTBENEFI.CLIENTE "); sqlSelect.append("ORDER BY TAMOVEXT.FECHA DESC"); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString()); objPaginacion.inicializarPaginacion(rs); if (objPaginacion.getNumeroRegistrosTotales()!=0) { objPaginacion.realizarPaginacion(rs, pagina); while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina())) { Object[] aResultados = new Object[12]; aResultados[0] = Integer.valueOf(rs.getInt(1)); aResultados[1] = new String(Utilidades.formatear_fecha(rs.getDate(2))); aResultados[2] = Integer.valueOf(rs.getInt(3)); aResultados[3] = Integer.valueOf(rs.getInt(4)); aResultados[4] = new String(rs.getString(5)); aResultados[5] = new String(rs.getString(6)); aResultados[6] = new String(rs.getString(7)); aResultados[7] = Integer.valueOf(rs.getInt(8)); aResultados[8] = Integer.valueOf(rs.getInt(9)); aResultados[9] = Integer.valueOf(rs.getInt(10)); aResultados[10] = Integer.valueOf(rs.getInt(11)); aResultados[11] = Integer.valueOf(rs.getInt(12)); vResultado.addElement(aResultados); if (pagina!=0) //Se quiere realizar la paginacion elementosPaginacion++; } } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " actos imputados de la tabla TAMOVEXT (" + sqlSelect + ")"); } catch (ExcepcionTarisan et) { et.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } return vResultado; } public boolean EliminarMovimientoImputado(int medico, int especialidad, int acto, int numseeq, int colectivo, int poliza, int orden, String fecha) throws ParseException { boolean resultado = false; StringBuffer strSql = new StringBuffer(); strSql.append("DELETE FROM TAMOVEXT"); strSql.append(" WHERE MEDICO = "+ medico +" AND ESPECIALIDAD = "+ especialidad +" AND ACTO = "+ acto +" AND NUMSEQ = "+ numseeq +" AND COLECTIVO = "+ colectivo +" AND POLIZA = "+ poliza +" AND ORDEN = "+ orden +" AND FECHA = '"+ fecha + "'"); //strSql.append(" WHERE MEDICO = "+ medico +" AND ESPECIALIDAD = "+ especialidad +" AND ACTO = "+ acto +" AND NUMSEQ = "+ numseeq +" AND COLECTIVO = "+ colectivo +" AND POLIZA = "+ poliza +" AND ORDEN = "+ orden); try { resultado = ParametrosConfiguracion.dataStore.borrar(strSql.toString()); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la eliminacion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la eliminacion de TAMOVEXT: " + sqle + " (" + strSql + ")"); } return resultado; } }