263 lines
11 KiB
Java
263 lines
11 KiB
Java
package com.tarisan.control;
|
|
|
|
import java.sql.*;
|
|
import java.util.Calendar;
|
|
|
|
import com.tarisan.excepcion.ExcepcionTarisan;
|
|
import com.tarisan.log.LogTarisan;
|
|
import com.tarisan.log.NivelLog;
|
|
import com.tarisan.util.Utilidades;
|
|
import com.tarisan.data.*;
|
|
|
|
public class PersistenciaTaDespla implements Constantes
|
|
{
|
|
public Tadespla Seleccionar_Tadespla(String tarjeta)
|
|
{
|
|
Tadespla tades = new Tadespla ();
|
|
StringBuffer sqlSelect = new StringBuffer();
|
|
tades.set_tarjeta("");
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "PersistenciaTaDespla - Seleccionar_Tadespla - Inicio");
|
|
try {
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
sqlSelect.append("Select * from tadesplaz ");
|
|
sqlSelect.append("where TARJETA_CHIPCARD = ?");
|
|
|
|
Object aCondiciones[] = new Object[1];
|
|
aCondiciones[0] = new String(tarjeta);
|
|
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones);
|
|
while(rs.next())
|
|
{
|
|
tades.set_tarjeta((tarjeta == null)?"":tarjeta);
|
|
tades.setContrato(rs.getInt("CONTRATO_CHIPCARD"));
|
|
tades.setEntidad_chipcard(rs.getInt("ENTIDAD_CHIPCARD"));
|
|
tades.setFecha_Alta(rs.getDate("FECHA_ALTA"));
|
|
tades.setFecha_Registro(rs.getDate("FECHA_REGISTRO"));
|
|
tades.setNombre(rs.getString("NOMBRE_COMPLETO"));
|
|
tades.setResultado(rs.getInt("TRATADO"));
|
|
}
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "PersistenciaTaDespla - Seleccionar_Tadespla - Error: " + e.toString() + " (" + sqlSelect.toString() + ")");
|
|
} catch (SQLException e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "PersistenciaTaDespla - Seleccionar_Tadespla - Error: " + e.toString() + " (" + sqlSelect.toString() + ")");
|
|
}
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "PersistenciaTaDespla - Seleccionar_Tadespla - Fin");
|
|
return tades;
|
|
}
|
|
|
|
public Date UltimaVisita_Tadespla(int tarjeta, int medico, int espe) throws ExcepcionTarisan
|
|
{
|
|
Date resultado = new Date(Calendar.getInstance().getTimeInMillis());
|
|
StringBuffer sqlSelect = new StringBuffer();
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "\nPersistenciaTaDespla - UltimaVisita_Tadespla - Inicio");
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
|
|
sqlSelect.append("Select max(fecha_imp) as fecha_imp from tadespla ");
|
|
sqlSelect.append("where tarjeta = ? ");
|
|
sqlSelect.append("and medico = ? ");
|
|
sqlSelect.append("and especialidad = ? ");
|
|
|
|
Object aCondiciones[] = new Object[3];
|
|
aCondiciones[0] = Integer.valueOf(tarjeta);
|
|
aCondiciones[1] = Integer.valueOf(medico);
|
|
aCondiciones[2] = Integer.valueOf(espe);
|
|
|
|
try
|
|
{
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones);
|
|
while(rs.next())
|
|
{
|
|
resultado = rs.getDate("fecha_imp");
|
|
}
|
|
rs.close();
|
|
}
|
|
catch (ExcepcionTarisan e) {
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
resultado.setTime(1);
|
|
LogTarisan.logger.log(NivelLog.ERROR, "PersistenciaTaDespla - UltimaVisita_Tadespla - Error: " + e.toString() + " (" + sqlSelect + ")");
|
|
} catch (SQLException e) {
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
resultado.setTime(1);
|
|
LogTarisan.logger.log(NivelLog.ERROR, "PersistenciaTaDespla - UltimaVisita_Tadespla - Error: " + e.toString() + " (" + sqlSelect + ")");
|
|
}
|
|
if(resultado == null)
|
|
{
|
|
resultado = new Date(Calendar.getInstance().getTimeInMillis());
|
|
resultado.setTime(1);
|
|
}
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "\nPersistenciaTaDespla - UltimaVisita_Tadespla - Final");
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
return resultado;
|
|
}
|
|
|
|
public boolean esPrimeraVisitaTarisan(int tarjeta, int medico, int espe)
|
|
{
|
|
boolean resultado = false;
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Inicio - esprimeravisitatarisan: tarjeta:"+tarjeta+" medico:"+medico+" espe:"+espe);
|
|
|
|
Calendar ultimavisita = Calendar.getInstance();
|
|
Calendar fechaAct = Calendar.getInstance();
|
|
try {
|
|
ultimavisita.setTime(UltimaVisita_Tadespla(tarjeta, medico, espe));
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "esprimeravisitatarisan - Tenemos la fecha de la ultima visita: ");
|
|
|
|
if(ultimavisita == null)
|
|
{
|
|
resultado = true;
|
|
}
|
|
else
|
|
{
|
|
if(fechaAct.get(Calendar.YEAR) != ultimavisita.get(Calendar.YEAR))
|
|
resultado = true;
|
|
else
|
|
resultado = false;
|
|
}
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error al calcular la PrimeravisitaTarisan"+e);
|
|
}
|
|
|
|
|
|
return resultado;
|
|
}
|
|
|
|
/**
|
|
* Funcion que inserta una línea en la tabla tadespla, recibe un objeto Tadespla
|
|
* @param tades
|
|
* @return Devuelve cierto o falso según si la inserción se ha realizado correctamente o no...
|
|
* @throws ExcepcionTarisan
|
|
*/
|
|
public boolean Insertar_Tadespla(Tadespla tades, int medico) throws ExcepcionTarisan
|
|
{
|
|
boolean exito = false;
|
|
StringBuffer sqlSelect = new StringBuffer();
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "\n\nPersistencaTaDespla - Insertar_Tadespla - Inicio");
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Valores: "+tades.getContrato()+" - "+tades.getEntidad_chipcard()+" - "+tades.getNombre()+" - "+tades.getTarjeta()+" - "+tades.getTroquelado());
|
|
Connection conexion = null;
|
|
/*Tadespla verify = Seleccionar_Tadespla(tades.getTarjeta());
|
|
if(verify.getTarjeta().length()>0)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.INFO, "Se ha vuelto a intentar insertar el desplazado : "+verify.getNombre());
|
|
|
|
java.sql.Date dtFecha = new java.sql.Date(Calendar.getInstance().getTime().getTime());
|
|
|
|
sqlSelect.append("UPDATE TADESPLAZ SET TRATADO = 0, FECHA_REGISTRO = ? ");
|
|
sqlSelect.append("WHERE TADESPLAZ.TARJETA_CHIPCARD = ?");
|
|
conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ParametrosConfiguracion.dataStore.iniciarTransaccion(conexion);
|
|
Object aCondiciones[] = new Object[1];
|
|
aCondiciones[0] = new String(tades.getTarjeta());
|
|
Object aValores[] = new Object[1];
|
|
aValores[0] = (String)Utilidades.formatear_fecha(dtFecha);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Update embosado: "+Utilidades.obtenerSentenciaSQL(sqlSelect, aValores, aCondiciones));
|
|
exito = ParametrosConfiguracion.dataStore.actualizar(sqlSelect.toString(), aValores, aCondiciones);
|
|
if (exito)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Actualizar tratado tadespla - Exito al ponerlo a cero");
|
|
ParametrosConfiguracion.dataStore.confirmarTransaccion(conexion);
|
|
}
|
|
else
|
|
{
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Actualizar tratado tadespla - Fallo al ponerlo a cero");
|
|
ParametrosConfiguracion.dataStore.deshacerTransaccion(conexion);
|
|
}
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
}
|
|
else
|
|
{*/
|
|
try
|
|
{
|
|
|
|
|
|
sqlSelect.append("insert into TADESPLAZ (TARJETA_CHIPCARD, NOMBRE_COMPLETO, FECHA_ALTA, ENTIDAD_CHIPCARD, CONTRATO_CHIPCARD, FECHA_REGISTRO, TRATADO, TROQUELADO) ");
|
|
sqlSelect.append("values (?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?, ");
|
|
sqlSelect.append("?) ");
|
|
|
|
Object aValores[] = new Object[8];
|
|
aValores[0] = new String(tades.getTarjeta());
|
|
aValores[1] = new String(tades.getNombre());
|
|
aValores[2] = new Date(tades.getFecha_Alta().getTime());
|
|
aValores[3] = Integer.valueOf(tades.getEntidad_chipcard());
|
|
aValores[4] = Integer.valueOf(tades.getContrato());
|
|
aValores[5] = new Date(tades.getFecha_Registro().getTime());
|
|
aValores[6] = Integer.valueOf(tades.getTratado());
|
|
aValores[7] = new String(tades.getTroquelado());
|
|
//LogTarisan.logger.log(NivelLog.DEBUG, "Insertar tadespla: " + Utilidades.obtenerSentenciaSQL(sqlSelect, null, aCondiciones));
|
|
conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Insertar tadespla - Se ha obtenido la conexion");
|
|
ParametrosConfiguracion.dataStore.iniciarTransaccion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Insertar tadespla - se inicia la transaccion");
|
|
|
|
PersistenciaTareglog pertareg = new PersistenciaTareglog();
|
|
Calendar fecha = Calendar.getInstance();
|
|
Timestamp fechaAcceso = new Timestamp(fecha.getTimeInMillis());
|
|
|
|
int intUltimoValorCorrelativo = pertareg.obtenerUltimoValorCorrelativo(medico, fechaAcceso);
|
|
pertareg.insertarLog(medico, fechaAcceso, fecha, intUltimoValorCorrelativo, "TADESPLAZ",Utilidades.obtenerSentenciaSQL(sqlSelect, aValores, null), "insert en tadesplaz", conexion);
|
|
/*pertareg.insertarLog(956, fechaAcceso, fecha, intUltimoValorCorrelativo, "taconaut", "insert into taconaut (autorizacion, especialidad, acto, cantidad, medico, informe, from_gesigu, tarjeta) values ", "autorizacion para ats insertada con exito");*/
|
|
exito = ParametrosConfiguracion.dataStore.insertar(sqlSelect.toString(), aValores, conexion);
|
|
|
|
if (exito)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Insertar tadespla - Exito al insertar");
|
|
ParametrosConfiguracion.dataStore.confirmarTransaccion(conexion);
|
|
}
|
|
else
|
|
{
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Insertar tadespla - Fallo al insertar");
|
|
ParametrosConfiguracion.dataStore.deshacerTransaccion(conexion);
|
|
}
|
|
}
|
|
catch (ExcepcionTarisan e) {
|
|
try {
|
|
ParametrosConfiguracion.dataStore.deshacerTransaccion(conexion);
|
|
} catch (ExcepcionTarisan e1) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error al deshacerlatransaccion");
|
|
}
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la insercion del desplazado: " + e.toString() + " (" + sqlSelect + ")");
|
|
}
|
|
// }
|
|
return exito;
|
|
}
|
|
|
|
public boolean troquelado_repe(String troquelado)
|
|
{
|
|
boolean resul=false;
|
|
/*
|
|
* troquelado like '%0015%3915%4315%0465%' encuentra:
|
|
* 0015 3915 4315 0465
|
|
* 0015391543150465
|
|
*/
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Vamos a comprobar que no repitan troquelados");
|
|
StringBuffer sqlSelect = new StringBuffer();
|
|
Connection conexion = null;
|
|
try
|
|
{
|
|
conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
sqlSelect.append("Select troquelado from tadesplaz where ");
|
|
sqlSelect.append("troquelado like '%'||?||'%'");
|
|
Object aCondiciones[] = new Object[1];
|
|
aCondiciones[0] = new String(troquelado.replace(' ', '%'));
|
|
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect.toString(), aCondiciones);
|
|
while(rs.next())
|
|
{
|
|
resul=true;
|
|
}
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
}
|
|
catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la verificacion de la duplicidad del troquelado: " + e.toString() + " (" + sqlSelect + ")");
|
|
} catch (SQLException e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la verificacion de la duplicidad del troquelado: " + e.toString());
|
|
}
|
|
return resul;
|
|
}
|
|
} |