Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions cda-laboratorios/controller/import-labs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { conSql } from '../config.private';
import { conSql, userScheduler } from '../config.private';
import * as moment from 'moment';
import * as sql from 'mssql';
import { Matching } from '@andes/match';
import * as operations from './operations';
import * as fs from 'fs';
import { InformeLAB } from '../utils/informes/informe-lab';
import { userScheduler } from '../config.private';
import { msCDALaboratoriosLog } from '../logger/msCDALaboratorios';
const log = msCDALaboratoriosLog.startTrace();

Expand Down Expand Up @@ -81,27 +79,23 @@ export async function importarDatos(paciente) {

const resultados = await operations.getImpresionResultados(pool, lab.idProtocolo, lab.idEfector);
const informe = new InformeLAB(resultados.recordset[0], resultados.recordset, 'Laboratorio');
fs.readFile((await informe.informe() as string), async (err, data) => {

if (err) { return false; }

const file = 'data:application/pdf;base64,' + data.toString('base64');

const dto = {
id: lab.idProtocolo,
organizacion: organizacion._id,
fecha: fecha.toDate(),
tipoPrestacion: '4241000179101',
paciente,
confidencialidad: hiv ? 'R' : 'N',
profesional,
cie10: 'Z01.7',
file,
texto: 'Exámen de Laboratorio'
};

return await operations.postCDA(dto);
});
const base64 = await informe.informeBase64();
const file = 'data:application/pdf;base64,' + base64;

const dto = {
id: lab.idProtocolo,
organizacion: organizacion._id,
fecha: fecha.toDate(),
tipoPrestacion: '4241000179101',
paciente,
confidencialidad: hiv ? 'R' : 'N',
profesional,
cie10: 'Z01.7',
file,
texto: 'Exámen de Laboratorio'
};

return await operations.postCDA(dto);

}
} catch (e) {
Expand Down
20 changes: 10 additions & 10 deletions cda-laboratorios/utils/model/informe.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as pdf from 'html-pdf';
import { HTMLComponent } from './html-component.class';

export class InformePDF extends HTMLComponent {

template = `
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -39,19 +39,19 @@ export class InformePDF extends HTMLComponent {
style: string;
stylesUrl: string[];


async informe(options: pdf.CreateOptions = null) {
// devuelve buffer
async informeBase64(options: pdf.CreateOptions = null): Promise<string> {
const opciones = {
...this.getDefaultOptions(),
...(options || {})
};

const html = await this.render();
return new Promise((resolve, reject) => {
pdf.create(html, opciones).toFile((err, file) => {
if (err) {
return reject(err);
}
return resolve(file.filename);

return new Promise<string>((resolve, reject) => {
pdf.create(html, opciones).toBuffer((err: any, buffer: Buffer) => {
if (err) return reject(err);
resolve(buffer.toString('base64'));
});
});
}
Expand All @@ -73,7 +73,7 @@ export class InformePDF extends HTMLComponent {
data.css = this.renderSCSS();
}
this.data = data;
}
}

private renderSCSS() {
const styles = this.stylesUrl.map((file) => {
Expand Down
43 changes: 19 additions & 24 deletions cda-validator/controller/import-cdaValidators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { InformeCDA } from "../utils/informes/informe-cda";
import { getOrganizacion } from './../service/organizaciones.service';
import { postCDA } from './operations';
import { readFile } from 'fs';
import { userScheduler } from '../config.private';
import { msCDAValidatorLog } from '../logger/msCDAValidator';
const log = msCDAValidatorLog.startTrace();
Expand All @@ -13,30 +12,26 @@ export async function importarCDA(datosCDA, paciente) {
const organizacion: any = await getOrganizacion(datosEfector.efectorCodigoSisa, 'guardia');
if (organizacion && organizacion._id && organizacion.nombre) {
const informe = new InformeCDA(datosCDA, paciente, organizacion);
readFile((await informe.informe() as string), async (err, data) => {
if (err) {
await log.error('guardia:importarCDA:readFile_informe', { err, datosCDA, paciente }, err.message, userScheduler);
return null;
}
const adjunto64 = 'data:application/pdf;base64,' + data.toString('base64');
const profesional = {
nombre: datosCDA.medicoResp || 'Sin datos',
apellido: ' '
};
const base64 = await informe.informeBase64();
const adjunto64 = 'data:application/pdf;base64,' + base64;

const dto = {
id: datosCDA.id,
organizacion: organizacion._id,
fecha: datosCDA.fechaIngreso,
tipoPrestacion: '50849002',
paciente,
confidencialidad: 'N',
profesional,
cie10: datosCDA.diagnosticoPrincipal || '',
file: adjunto64
};
return await postCDA(dto);
});
const profesional = {
nombre: datosCDA.medicoResp || 'Sin datos',
apellido: ' '
};

const dto = {
id: datosCDA.id,
organizacion: organizacion._id,
fecha: datosCDA.fechaIngreso,
tipoPrestacion: '50849002',
paciente,
confidencialidad: 'N',
profesional,
cie10: datosCDA.diagnosticoPrincipal || '',
file: adjunto64
};
return await postCDA(dto);
}
else {
await log.info('guardia:importarCDA:organizacionInvalida', { info: "Organización Andes incorrecta", organizacionSIPS: datosEfector, organizacionAndes: organizacion }, userScheduler);
Expand Down
12 changes: 7 additions & 5 deletions cda-validator/utils/model/informeCDA.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ export class InformeCDAPDF extends HTMLComponent {
style: string;
stylesUrl: string[];


async informe(options: pdf.CreateOptions = null) {
// devuelve buffer
async informeBase64(options: pdf.CreateOptions = null): Promise<string> {
const opciones = {
...this.getDefaultOptions(),
...(options || {})
};

const html = await this.render();
return new Promise((resolve, reject) => {

return new Promise<string>((resolve, reject) => {
try {
pdf.create(html, opciones).toFile((err, file) => {
pdf.create(html, opciones).toBuffer((err: any, buffer: Buffer) => {
if (err) {
log.error('guardia:informe:pdf_toFile', { err }, err.message, userScheduler);
return reject(err);
}
return resolve(file.filename);
resolve(buffer.toString('base64'));
});
} catch (err) {
log.error('guardia:informe:pdf_create', { err }, err.message, userScheduler);
Expand Down