Añado los fuentes de java
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Created on 22-nov-2005
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
package com.tarisan.servlets;
|
||||
|
||||
import com.tarisan.util.*;
|
||||
import com.tarisan.control.Constantes;
|
||||
import com.tarisan.data.Usuario;
|
||||
import com.tarisan.data.Paciente;
|
||||
import com.tarisan.log.*;
|
||||
import com.tarisan.util.Utilidades;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import jakarta.servlet.http.*;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
//import com.lowagie.text.Chunk;
|
||||
//import com.lowagie.text.Document;
|
||||
//import com.lowagie.text.DocumentException;
|
||||
//import com.lowagie.text.pdf.PdfWriter;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import com.itextpdf.text.pdf.PdfPTable;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//import com.lowagie.text.*;
|
||||
//import com.lowagie.text.pdf.PdfWriter;
|
||||
//import com.lowagie.text.pdf.PdfPTable;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* @author Roumen
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class GestorImpresion extends HttpServlet {
|
||||
|
||||
/** a possible status */
|
||||
public static final int ACT_INIT = 0;
|
||||
|
||||
/** a possible status */
|
||||
public static final int ACT_REPORT_1 = 1;
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doWork(request, response);
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doWork(request, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The actual business logic.
|
||||
*
|
||||
* @param requ the request object
|
||||
* @param resp the response object
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
System.out.println("Dentro de Servlet: 1");
|
||||
|
||||
LogTarisan.logger.log(NivelLog.INFO, "Inicio página de impresion de analitica (imp/impAnalitica.jsp)");
|
||||
response.setHeader("Expires", "0");
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
HttpSession sesion = request.getSession(true);
|
||||
|
||||
int opcion = 0;
|
||||
if (request.getParameter("opcion") != null) {
|
||||
opcion = Integer.parseInt((String)request.getParameter("opcion"));
|
||||
System.out.println("opcion: " + opcion);
|
||||
|
||||
switch(opcion)
|
||||
{
|
||||
case Constantes.OPC_PAC_PRESCRIPCION_ANALITICA:
|
||||
{
|
||||
try
|
||||
{
|
||||
// Definicion de variables
|
||||
SimpleDateFormat sdfFormateadorFecha=new SimpleDateFormat("dd/MM/yyyy");
|
||||
java.sql.Date dtFecha = new java.sql.Date(Calendar.getInstance().getTime().getTime());
|
||||
String strMensajeSinElementos="No ha seleccionado ningún acto médico.";
|
||||
|
||||
// ArrayList que contedrá las descripciones de analíticas
|
||||
ArrayList arrayListaElementosPrescripcion = null;
|
||||
|
||||
String strAutorizacion = "CSM";
|
||||
if ((String)request.getAttribute("autorizacion") != null) {
|
||||
strAutorizacion = (String)request.getAttribute("autorizacion");
|
||||
System.out.println("Dentro de impAnalitica.jsp: " + strAutorizacion);
|
||||
}
|
||||
String strInforme = "INFORME";
|
||||
if (request.getParameter("informePrescripcion") != null) {
|
||||
strInforme =(String)request.getParameter("informePrescripcion");
|
||||
System.out.println("Informe: " + strInforme);
|
||||
}
|
||||
|
||||
// String strInforme = (String)request.getParameter("informe");
|
||||
String strListaElementosPrescripcion = "";
|
||||
String strListaElementosPrescripcionAux = "";
|
||||
if (request.getParameter("listaElementosPrescripcion") != null ) {
|
||||
// Lista de elementos de Prescripción
|
||||
strListaElementosPrescripcion = (String)request.getParameter("listaElementosPrescripcion");
|
||||
System.out.println("1");
|
||||
if (strListaElementosPrescripcion != null && strListaElementosPrescripcion.length() > 0) {
|
||||
System.out.println("listaElementosPrescripcion original" + strListaElementosPrescripcion);
|
||||
}
|
||||
System.out.println("2");
|
||||
|
||||
if (strListaElementosPrescripcion != null && strListaElementosPrescripcion.length() > 0) {
|
||||
System.out.println("listaElementosPrescripcion original" + strListaElementosPrescripcion);
|
||||
strListaElementosPrescripcionAux = strListaElementosPrescripcion.replace('\'', '~');
|
||||
}
|
||||
System.out.println("3");
|
||||
|
||||
strListaElementosPrescripcion = strListaElementosPrescripcionAux;
|
||||
System.out.println("4");
|
||||
System.out.println("listaElementosPrescripcion tras replace " + strListaElementosPrescripcion);
|
||||
System.out.println("5");
|
||||
|
||||
|
||||
while(strListaElementosPrescripcion.indexOf("~") != -1) {
|
||||
System.out.println("aaaa");
|
||||
strListaElementosPrescripcion = strListaElementosPrescripcion.replace('~','\'');
|
||||
}
|
||||
|
||||
System.out.println("6");
|
||||
System.out.println("listaElementosPrescripcion tras replace " + strListaElementosPrescripcion);
|
||||
System.out.println("7");
|
||||
|
||||
// Vector vElementosPrescripcion = new Vector();
|
||||
arrayListaElementosPrescripcion = new ArrayList();
|
||||
System.out.println("8");
|
||||
|
||||
if (strListaElementosPrescripcion != null && strListaElementosPrescripcion.length() > 0) {
|
||||
// Lista no vacía
|
||||
System.out.println("9");
|
||||
strListaElementosPrescripcion = strListaElementosPrescripcion.substring(strListaElementosPrescripcion.indexOf("¬") + 1);
|
||||
System.out.println("10");
|
||||
|
||||
//Separamos las diferentes determinaciones
|
||||
int i = 0;
|
||||
while (strListaElementosPrescripcion.indexOf("¬") != -1) {
|
||||
System.out.println("BUCLE i: " + i);
|
||||
//vElementosPrescripcion.add(strListaElementosPrescripcion.substring(0, strListaElementosPrescripcion.indexOf("¬")));
|
||||
arrayListaElementosPrescripcion.add(strListaElementosPrescripcion.substring(0, strListaElementosPrescripcion.indexOf("¬")));
|
||||
//System.out.println("11");
|
||||
strListaElementosPrescripcion = strListaElementosPrescripcion.substring(strListaElementosPrescripcion.indexOf("¬") + 1);
|
||||
//System.out.println("12");
|
||||
i++;
|
||||
}
|
||||
|
||||
/*
|
||||
for (int j=0;j<arrayListaElementosPrescripcion.size();j++) {
|
||||
System.out.println("Elem: " + (String)arrayListaElementosPrescripcion.get(j));
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
String strListaCodigoElementos = "";
|
||||
if (request.getParameter("listaCodigoElementos")!=null) {
|
||||
strListaCodigoElementos=(String)request.getParameter("listaCodigoElementos");
|
||||
System.out.println("ListaCodigoElementos" + strListaCodigoElementos);
|
||||
}
|
||||
|
||||
|
||||
//Creamos el documento
|
||||
Document document = new Document();
|
||||
|
||||
|
||||
//Fijamos Márgenes
|
||||
document.setMargins(40, 40, 5, 5);
|
||||
|
||||
// we create a writer that listens to the document
|
||||
String strFile = "../webapps/tarisan/peticiones/" + strAutorizacion + ".pdf";
|
||||
FileOutputStream foStream = new FileOutputStream(strFile);
|
||||
PdfWriter.getInstance(document,foStream);
|
||||
//ByteArrayOutputStream baOS = new
|
||||
|
||||
// step 3: we open the document
|
||||
document.open();
|
||||
|
||||
//Definición de tabla
|
||||
PdfPTable table = new PdfPTable(2); //Numero de columnas
|
||||
|
||||
//Fijar anchura de la tabla
|
||||
table.setWidthPercentage(100);
|
||||
|
||||
//Creamos el objeto generador de PDF
|
||||
Print generadorPDF = new Print();
|
||||
|
||||
//AÑADIR CABECERA
|
||||
table = generadorPDF.anadirCabecera(table, "IMQ");
|
||||
|
||||
//AÑADIR MEDICOPRESCRIPTOR
|
||||
String strMedico = ((Usuario)sesion.getAttribute("USUARIO")).getNombreCab().toString();
|
||||
String strDireccion = ((Usuario)sesion.getAttribute("USUARIO")).getDireccionCab().toString();
|
||||
String strEspecialidad = ((Usuario)sesion.getAttribute("USUARIO")).getEspecialidadCab().toString();
|
||||
String strPoblacion = ((Usuario)sesion.getAttribute("USUARIO")).getPoblacionCab();
|
||||
String strNumColegiado = "Núm.Colegiado: " + ((Usuario)sesion.getAttribute("USUARIO")).getColegiadoCab().toString();
|
||||
String strTelefono = ((Usuario)sesion.getAttribute("USUARIO")).getTelefonoCab().toString();
|
||||
table = generadorPDF.anadirMedicoPrescriptor(table, strMedico, strDireccion, strEspecialidad, strPoblacion, strNumColegiado, strTelefono);
|
||||
|
||||
//AÑADIR PACIENTE
|
||||
|
||||
String strNomPaciente = ((Paciente)sesion.getAttribute("PACIENTE")).getNombre();
|
||||
String strColectivo = Long.toString( ((Paciente)sesion.getAttribute("PACIENTE")).getTarjeta().getColectivo()) + Utilidades.formatearEntero( ((Paciente)sesion.getAttribute("PACIENTE")).getTarjeta().getPoliza(), 12, 0);
|
||||
String strBeneficiario = Integer.toString(((Paciente)sesion.getAttribute("PACIENTE")).getTarjeta().getBeneficiario());
|
||||
String strPoliza = strColectivo + " " + strBeneficiario;
|
||||
|
||||
sdfFormateadorFecha = new SimpleDateFormat("dd/MM/yyyy");
|
||||
dtFecha = new java.sql.Date(Calendar.getInstance().getTime().getTime());
|
||||
|
||||
strPoblacion += ", " + sdfFormateadorFecha.format(dtFecha);
|
||||
table = generadorPDF.anadirPaciente(table, strNomPaciente, strPoliza, "Núm.Autorización: " + strAutorizacion, strPoblacion);
|
||||
|
||||
//AÑADIR ANALISIS
|
||||
table = generadorPDF.anadirAnalisis(table,arrayListaElementosPrescripcion, "IMQ");
|
||||
|
||||
//AÑADIR INFORME
|
||||
//strInforme = strInforme.substring(1000);
|
||||
table = generadorPDF.anadirInforme(table, strInforme, "IMQ");
|
||||
|
||||
|
||||
//AÑADIR TABLA
|
||||
table.setHorizontalAlignment(Element.ALIGN_CENTER);
|
||||
document.add(table);
|
||||
|
||||
//CERRAR DOCUMENTO
|
||||
// step 5: we close the document
|
||||
document.close();
|
||||
|
||||
System.out.println("GestorImpresion antes del forward");
|
||||
//request.getRequestDispatcher("/jsp/imp/impAnalitica.jsp").forward(request,response);
|
||||
//response.sendRedirect("../jsp/imp/impAnalitica.jsp");
|
||||
System.out.println("GestorImpresion despues del forward");
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Excepcion1" + ex);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("opcion nula");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void htmlHeader(ServletOutputStream out, HttpServletRequest request,
|
||||
HttpServletResponse response) throws IOException {
|
||||
|
||||
response.setContentType("text/html; charset=ISO-8859-1");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out
|
||||
.println("<meta http-equiv='Content-Type' content='text/html;charset=iso-8859-1'>");
|
||||
out.println("<meta http-equiv='expires' content='0'>");
|
||||
out.println("<meta http-equiv='cache-control' content='no-cache'>");
|
||||
out.println("<meta http-equiv='pragma' content='no-cache'>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
}
|
||||
|
||||
private void formular(ServletOutputStream out, HttpServletRequest request,HttpServletResponse response, int sub) throws IOException {
|
||||
out.print("<form method='post' action='");
|
||||
out.print(request.getRequestURI());
|
||||
out.print("?action=");
|
||||
out.print(ACT_INIT);
|
||||
out.print("&sub=");
|
||||
out.print(ACT_REPORT_1);
|
||||
out.println("'>");
|
||||
out.print("<input type='checkbox' name='preview' value='Y'");
|
||||
if (request.getParameter("preview") != null)
|
||||
out.print(" checked ");
|
||||
out.println(">preview<br>");
|
||||
|
||||
out.println("<input type=submit value='Report 1'>");
|
||||
out.println("</form>");
|
||||
if (sub != ACT_INIT) {
|
||||
if (request.getParameter("preview") != null) {
|
||||
out.println("<script language='JavaScript'>");
|
||||
out.print("w = window.open(\"");
|
||||
out.print(request.getRequestURI());
|
||||
out.print("?action=");
|
||||
out.print(sub);
|
||||
out.print("&preview=Y\", \"Printing\", \"width=800,height=450,scrollbars,menubar=yes,resizable=yes\");");
|
||||
out.println("</script>");
|
||||
} else {
|
||||
out.print("<iframe src='");
|
||||
out.print(request.getRequestURI());
|
||||
out.print("?action=");
|
||||
out.print(sub);
|
||||
out.println("' width='10' height='10' name='pdf_box'>");
|
||||
}
|
||||
}
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user