// Author: Jose Ramon Pascual Fecha: 03/03/2019 // Descripcion: // Ejemplo de cómo exportar a excel en Mirth Connect utilizando el API Apache POI // Código correspondiente a Transformer en Source try { // Se crea el libro excel class HSSFWorkbook var libro = new Packages.org.apache.poi.hssf.usermodel.HSSFWorkbook(); // Se crea una hoja dentro del libro class HSSFSheet var hoja = libro.createSheet(); // Se crea una fila dentro de la hoja class HSSFRow var fila = hoja.createRow(0); // Celda 0 Cabecera de la hoja // Se crean celdas dentro de la fila class HSSFCell var celda = fila.createCell(0).setCellValue("Fecha"); celda = fila.createCell(1).setCellValue("NHC"); celda = fila.createCell(2).setCellValue("Nombre y Apellidos"); celda = fila.createCell(3).setCellValue("CódigoNacional"); celda = fila.createCell(4).setCellValue("Descripcion Medicamento"); celda = fila.createCell(5).setCellValue("Unidades"); celda = fila.createCell(6).setCellValue("Orden"); celda = fila.createCell(7).setCellValue("PMF"); celda = fila.createCell(8).setCellValue("Precio Unitario"); // Insertar los datos de cada fila desde la lectura de BD var i = 1; // Insertar todas las filas leidas desde BD for each(registro in msg['result']) { var fila = hoja.createRow(i++); celda = fila.createCell(0).setCellValue(registro['fecha'].toString()); celda = fila.createCell(1).setCellValue(registro['nhc'].toString()); celda = fila.createCell(2).setCellValue(registro['paciente'].toString()); celda = fila.createCell(3).setCellValue(registro['cn'].toString()); celda = fila.createCell(4).setCellValue(registro['descripcion'].toString()); celda = fila.createCell(5).setCellValue(registro['cantidadunidades'].toString()); celda = fila.createCell(6).setCellValue(registro['orden'].toString()); celda = fila.createCell(7).setCellValue(registro['pmf'].toString()); celda = fila.createCell(8).setCellValue(registro['costeunitario'].toString()); } channelMap.put('NombreFichero',configurationMap.get('ruta') + "Dispensador_" + DateUtil.getCurrentDate('yyyyMMdd') + ".xls"); var fichero = new java.io.FileOutputStream(channelMap.get('NombreFichero')); libro.write(fichero); fichero.close(); } catch (e) { // Aquí procesaremos la excepcion segun nos interese. // Para este ejemplo no procede mas que pasar la descripcion channelMap.put('error_descripcion' , "Error en Source Transformer Paso 0: " + e); }