Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HUDS - Implementar descarga en PDF de laboratorios #1983

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
feat(HUDS-104): Implementar descarga en PDF de laboratorios
  • Loading branch information
MarianoCampetella authored and MCele committed Nov 15, 2024
commit 11cf7697a817935e27bb154efe8f40827b6cf312
100 changes: 100 additions & 0 deletions modules/descargas/laboratorio/laboratorio-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { HTMLComponent } from '../model/html-component.class';
import * as moment from 'moment';

export class FarmaciaBody extends HTMLComponent {
template = `
<main>
<table border="1" width="100%" class="tabla-header">
<tr>
<td width="35%"><b>Paciente: </b>{{encabezado.data.apellido }} {{encabezado.data.nombre}}</td>
<td width="15%"><b>Fecha de Nacimiento: </b>{{encabezado.data.fechanacimiento}}</td>
<td width="15%"><b>Género: </b>{{encabezado.data.sexo}}</td>
<td width="15%"><b>DNI: </b>{{encabezado.data.documento}}</td>
</tr>
<tr>
<td width="35%"><b>Solicitante: </b>{{encabezado.data.medicoSolicitante}}</td>
<td width="15%"><b>Orden Nro: </b> {{encabezado.data.numero}}</td>
<td width="15%"><b>Fecha: </b>{{encabezado.data.fecha}}</td>
<td width="15%"><b>Origen: </b>{{encabezado.data.origen}}</td>
</tr>
<td colspan="1"><b>Efector solicitante: </b>{{encabezado.data.efectorSolicitante}}</td>
<td colspan="3"><b>Laboratorio: </b>{{encabezado.data.Laboratorio}}</td>
</table>

{{#each areas}}
<div class="tituloGeneral"><u>{{area}}</u> </div>
{{#each grupos}}
<div class="tituloSecundario"><b> {{grupo}}</b></div>
{{#each items}}
{{#if esTitulo}}
<div class="tituloTabla"><u>{{nombre}}</u></div>
{{else}}
<table class="tituloTabla">
<tr>
<td width="25%">{{nombre}}</td>
<td width="25%"><i>{{resultado }}{{ unidadMedida}}</i></td>
<td width="25%">{{valorReferencia }}{{metodo}}</td>
<td width="25%"><i>{{userValida}}</i></td>
</tr>
</table>
{{/if}}
{{/each}}
{{/each}}
{{/each}}
</main>
`;

constructor(public encabezado, public paciente, public detalle) {
super();
}

public async process() {
const setAreas = new Set(this.detalle.map(d => d.area));
const areasStr = Array.from(setAreas);

const areas = [];
areasStr.forEach(area => {
const detallesArea = this.detalle.filter(d => d.area === area);
const setGrupos = new Set(detallesArea.map(d => d.grupo));
const grupos = Array.from(setGrupos);

const item = {
area,
grupos: grupos.map(g => {
const detallesAreaGrupo = detallesArea.filter(da => da.grupo === g);
const res: any = {};
const toItem = (e) => ({
nombre: e.item,
esTitulo: e.esTitulo === 'True' ? true : false,
resultado: e.resultado,
metodo: e.Metodo,
valorReferencia: e.valorReferencia,
unidadMedida: e.unidadMedida,
userValida: e.userValida
});
if (detallesAreaGrupo.length === 1 && detallesAreaGrupo[0].grupo === g) {
res.item = toItem(detallesAreaGrupo[0]);
} else {
res.grupo = g;
res.items = detallesAreaGrupo.map(toItem);
}

return res;
})
};

areas.push(item);
});

this.encabezado.data.fecha = moment(this.encabezado.data.fecha).format('DD-MM-YYYY');
this.encabezado.data.fechanacimiento = moment(this.encabezado.data.fechanacimiento).format('DD-MM-YYYY');
this.encabezado.data.sexo = this.paciente[0].genero;
if (this.paciente[0].alias) {
this.encabezado.data.nombre = this.paciente[0].alias;
}
this.data = {
areas,
encabezado: this.encabezado
};
}
}
19 changes: 19 additions & 0 deletions modules/descargas/laboratorio/laboratorio-footer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HTMLComponent } from '../model/html-component.class';
import * as moment from 'moment';

export class LaboratorioFooter extends HTMLComponent {
template = `
<hr>
<div class="foot"> Fecha y hora de impresión: {{fecha}} </div>
<div class="foot"> Impreso por: {{usuario}} </div>
`;

constructor(public usuario) {
super();
this.data = {
fecha: moment().format('DD/MM/YYYY HH:mm:ss'),
usuario
};
}

}
22 changes: 22 additions & 0 deletions modules/descargas/laboratorio/laboratorio-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HTMLComponent } from '../model/html-component.class';

export class FarmaciaHeader extends HTMLComponent {
template = `
<div class="contenedor-secundario">
Resultados de Laboratorio
<h3>{{encabezado.data.Laboratorio}}"</h3>
</div>
<div class="contenedor-secundario">
<hr/>
`;

constructor(public encabezado) {
super();
}

public async process() {
this.data = {
encabezado: this.encabezado
};
}
}
22 changes: 22 additions & 0 deletions modules/descargas/laboratorio/laboratorio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { InformePDF, getAssetsURL } from '../model/informe.class';
import { FarmaciaBody } from './laboratorio-body';
import { FarmaciaHeader } from './laboratorio-header';
import { LaboratorioFooter } from './laboratorio-footer';

export class Laboratorio extends InformePDF {
constructor(private encabezado, private detalle, private paciente, private usuario) {
super();
}

stylesUrl = [
getAssetsURL('templates/laboratorio/laboratorio.scss')
];

public async process() {
this.header = new FarmaciaHeader(this.encabezado);
this.body = new FarmaciaBody(this.encabezado, this.paciente, this.detalle);
this.footer = new LaboratorioFooter(this.usuario);

await super.process();
}
}
38 changes: 38 additions & 0 deletions modules/descargas/routes/descargas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { Agenda } from '../agenda/agenda';
import { getArchivoAdjunto } from '../../../modules/rup/controllers/rup';
import { CertificadoEtica } from '../matriculaciones/certificado-etica';
import { CredencialProfesional } from '../matriculaciones/credencial-profesional';
import { Laboratorio } from '../laboratorio/laboratorio';
import * as laboratorioController from './../../rup/laboratorios.controller';
import { laboratorioLog } from './../../rup/laboratorio.log';
import { Paciente } from './../../../core-v2/mpi';

const router = express.Router();

Expand Down Expand Up @@ -165,6 +169,40 @@ router.post('/constanciaPuco/:tipo?', Auth.authenticate(), async (req: any, res)
res.download(fileName);
});

router.post('/laboratorio/:tipo?', Auth.authenticate(), async (req: any, res, next) => {
let dataSearch;
if (req.body.protocolo.data.idProtocolo) {
try {
const paciente = await Paciente.find({ documento: req.body.protocolo.data.documento });
dataSearch = { idProtocolo: req.body.protocolo.data.idProtocolo };
const response = await laboratorioController.search(dataSearch);
if (!response.length || !paciente) {
throw new Error('Error al generar laboratorio.');
}
const docLaboratorio = new Laboratorio(req.body.protocolo, response[0].Data, paciente, req.body.usuario);
const opciones = { header: { height: '2cm' } };
const fileName: any = await docLaboratorio.informe(opciones);
res.download(fileName);

} catch (err) {
const dataError = {
id: req.params.id,
estado: req.query.estado,
documento: req.query.dni,
fechaNacimiento: req.query.fecNac,
apellido: req.query.apellido,
fechaDesde: req.query.fechaDde,
fechaHasta: req.query.fechaHta
};
await laboratorioLog.error('laboratorio-descargas', dataError, err, req);
return next(err);
}

} else {
return next(500);
}
});

router.post('/arancelamiento/:tipo?', Auth.authenticate(), async (req: any, res) => {
const provincia = configPrivate.provincia || 'neuquen';
const opciones = { header: { height: '3cm' } };
Expand Down
17 changes: 17 additions & 0 deletions modules/rup/laboratorios.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { services } from './../../services';

export async function search(data) {
let params;
const service = 'get-LABAPI';
if (data.idProtocolo) {
params = {
parametros: `nombre=LABAPI_GetResultadoProtocolo&parametros=${data.idProtocolo}`
};
} else {
params = {
parametros: `nombre=LABAPI_GetProtocolos&parametros=${data.estado}|${data.dni}|${data.fechaNac}|${data.apellido}|${data.fechaDesde}|${data.fechaHasta}`
};
}
const response = await services.get(service).exec(params);
return response;
}
31 changes: 13 additions & 18 deletions modules/rup/routes/protocolosLab.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
import * as express from 'express';
import { services } from '../../../services';
import { laboratorioLog } from '../laboratorio.log';
import * as laboratorioController from '../laboratorios.controller';

const router = express.Router();

router.get('/protocolosLab/:id?', async (req, res, next) => {
let params;
let dataSearch = {};
const service = 'get-LABAPI';
if (req.params.id) {
params = {
parametros: `nombre=LABAPI_GetResultadoProtocolo&parametros=${req.params.id}`
};
dataSearch = { idProtocolo: req.params.id };
} else {
params = {
parametros: `nombre=LABAPI_GetProtocolos&parametros=${req.query.estado}|${req.query.dni}|${req.query.fecNac}|${req.query.apellido}|${req.query.fechaDde}|${req.query.fechaHta}`
dataSearch = {
estado: req.query.estado,
dni: req.query.dni,
fechaNac: req.query.fecNac,
apellido: req.query.apellido,
fechaDesde: req.query.fechaDde,
fechaHasta: req.query.fechaHta
};
}
try {
const response = await services.get(service).exec(params);
const response = await laboratorioController.search(dataSearch);
if (!response.length) {
throw new Error(response || service);
}
res.json(response);
} catch (err) {
const data = {
id: req.params.id,
estado: req.query.estado,
documento: req.query.dni,
fechaNacimiento: req.query.fecNac,
apellido: req.query.apellido,
fechaDesde: req.query.fechaDde,
fechaHasta: req.query.fechaHta
};
await laboratorioLog.error('resultado-protocolo', data, err, req);
dataSearch['id'] = req.params.id;
await laboratorioLog.error('resultado-protocolo', dataSearch, err, req);
res.json('error:' + err.message);
}
});
Expand Down
51 changes: 51 additions & 0 deletions templates/laboratorio/laboratorio.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.contenedor-secundario {
display: block;
text-align: center;
font-size: .25cm;
}

.tabla-header {
border-color: black;
border-collapse: collapse;
font-size: .25cm;
}

td {
text-align: left;
}

.tabla-header {
border-color: black;
border-collapse: collapse;
font-size: .20cm;
}

.tituloGeneral {
text-align: left;
margin-top: 20px;
font-size: .25cm;
}

.tituloSecundario {
text-align: left;
margin-top: 8px;
font-size: .25cm;
}

.tituloTabla {
text-align: left;
margin-top: 8px;
margin-left: 20px;
font-size: .25cm;
}

body {
padding-left: 0.5cm;
padding-right: 0.5cm;
font-family: Arial, sans-serif;
}

.foot {
font-family: Arial, sans-serif;
font-size: 10px;
}
Loading