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
138 changes: 133 additions & 5 deletions src/app/modules/rup/components/ejecucion/hudsBusqueda.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Auth } from '@andes/auth';
import { Plex } from '@andes/plex';
import { AfterContentInit, Component, EventEmitter, Input, OnInit, Optional, Output, ViewEncapsulation } from '@angular/core';
import { AfterContentInit, Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Optional, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core';
import * as moment from 'moment';
import { LaboratorioService } from 'src/app/services/laboratorio.service';
import { RecetaService } from 'src/app/services/receta.service';
Expand All @@ -19,14 +19,16 @@ import { getSemanticClass } from '../../pipes/semantic-class.pipes';
import { EmitConcepto, RupEjecucionService } from '../../services/ejecucion.service';
import { HUDSService } from '../../services/huds.service';
import { PrestacionesService } from './../../services/prestaciones.service';
import { CDAService } from '../../services/CDA.service';


@Component({
selector: 'rup-hudsBusqueda',
templateUrl: 'hudsBusqueda.html',
styleUrls: ['hudsBusqueda.scss', 'buscador.scss'],
encapsulation: ViewEncapsulation.None
})
export class HudsBusquedaComponent implements AfterContentInit, OnInit {
export class HudsBusquedaComponent implements AfterContentInit, OnInit, OnDestroy, OnChanges {
laboratoriosFS: any;
laboratorios: any = [];
vacunas: any = [];
Expand All @@ -36,6 +38,11 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
hallazgosNoActivosAux: any;
filtroActual;
filtroTrastornos = true;
public disabledBtnCDA = false;
public token: string;
public secondsToUpdate = 0;
private intervalUpdate: any;


solicitudesMezcladas = [];

Expand Down Expand Up @@ -178,6 +185,8 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
public permisosLab;
public permisosVac;
public permisosRec;
public pacienteSelected = null;


constructor(
public servicioPrestacion: PrestacionesService,
Expand All @@ -190,6 +199,7 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
private pacienteService: PacienteService,
private laboratorioService: LaboratorioService,
private recetasService: RecetaService,
private cdaService: CDAService,
private profesionalService: ProfesionalService,
) {
}
Expand All @@ -205,11 +215,11 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
this.listarPrestaciones();
this.listarConceptos();
}
const token = this.huds.getHudsToken();
this.token = this.huds.getHudsToken();
// Cuando se inicia una prestación debemos volver a consultar si hay CDA nuevos al ratito.
// [TODO] Ser notificado via websockets
setTimeout(() => {
this.buscarCDAPacientes(token);
this.buscarCDAPacientes(this.token);
}, 1000 * 30);
}

Expand All @@ -226,6 +236,23 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
(this.permisosParciales || this.permisosLab) ? 'laboratorios' :
this.permisosVac ? 'vacunas' :
'recetas';
this.pacienteSelected = this.paciente;
}

ngOnChanges(changes: SimpleChanges) {
if (changes.paciente?.currentValue) {
const pac = changes.paciente.currentValue;
if (pac.idPaciente) {
this.paciente = pac.idPaciente;
}
this.pacienteSelected = this.paciente;
}
}

ngOnDestroy() {
if (this.intervalUpdate) {
clearInterval(this.intervalUpdate);
}
}

getTitulo(filtroactual) {
Expand Down Expand Up @@ -259,6 +286,70 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {

}

textoTratamientoProlongado(grupo: any): string {
const medicamento = grupo?.recetaVisible?.medicamento;

if (!medicamento) {
return '';
}

const orden =
medicamento.ordenTratamiento != null
? medicamento.ordenTratamiento + 1
: 0;

const tiempo = medicamento.tiempoTratamiento?.id ?? '';

return `Tratamiento prolongado: ${orden} de ${tiempo}`;
}

refreshCDA() {
forkJoin([
this.cdaService.getCDAList(this.pacienteSelected.id),
this.laboratorioService.getLaboratorios(this.pacienteSelected.id)
]).subscribe(([cda, laboratorios]) => {
const listado = [];

cda.forEach(itemCda => {
const laboratorioCorrespondiente = laboratorios.find(
laboratorio => laboratorio.id.toString() === itemCda.extras.id
);

listado.push({
cda: itemCda,
laboratorio: laboratorioCorrespondiente
});
});

this.cdas = listado;
});
}

regenerarCDA() {
this.disabledBtnCDA = true;

this.cdaService.regenerarCDA(this.paciente).subscribe(
() => {
this.plex.toast('success', 'CDA regenerado correctamente', 'TIEMPO DE ESPERA 15 SEGUNDOS');
this.secondsToUpdate = 15;
if (this.intervalUpdate) {
clearInterval(this.intervalUpdate);
}
this.intervalUpdate = setInterval(() => {
this.secondsToUpdate--;
if (this.secondsToUpdate <= 0) {
clearInterval(this.intervalUpdate);
this.buscarCDAPacientes(this.token);
this.disabledBtnCDA = false;
}
}, 1000);
},
(err) => {
this.plex.toast('danger', 'Error al regenerar CDA');
this.disabledBtnCDA = false;
}
);
}
agregarRegistro(registro) {
if (this.ejecucionService) {
const data: EmitConcepto = {
Expand Down Expand Up @@ -548,7 +639,7 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
});
}

buscarFichasEpidemiologicas() {
private buscarFichasEpidemiologicas() {
this.formEpidemiologiaService.search({ paciente: this.paciente.id }).subscribe(fichas => {
if (fichas.length) {
const fichasEpidemiologia = fichas.map(f => {
Expand Down Expand Up @@ -576,6 +667,43 @@ export class HudsBusquedaComponent implements AfterContentInit, OnInit {
});
}

refreshLaboratorios(token) {
forkJoin({
protocolos: this.laboratorioService.getProtocolos(this.paciente.id),
cdaByPaciente: this.servicioPrestacion.getCDAByPaciente(this.paciente.id, token)
}).subscribe({
next: ({ protocolos, cdaByPaciente }) => {

// Mapeamos igual que antes
const cdasMapeados = cdaByPaciente.map(cda => {
cda.id = cda.cda_id;
return {
data: cda,
tipo: 'cda',
prestacion: cda.prestacion.snomed,
profesional: cda.profesional
? `${cda.profesional.apellido} ${cda.profesional.nombre}`
: '',
fecha: cda.fecha,
estado: 'validada',
ambito: 'ambulatorio',
organizacion: cda.organizacion.id
};
});

// 🔹 SOLO LABORATORIOS
this.laboratorios = cdasMapeados.filter(cda =>
cda.prestacion.conceptId === ConceptosTurneablesService.Laboratorio_CDA_ID ||
cda.prestacion.conceptId === ConceptosTurneablesService.Laboratorio_SISA_CDA_ID
);

// 🔹 Orden especial de laboratorios
this.laboratorios = this.ordenarLaboratorios(this.laboratorios, protocolos);
}
});
}


getCantidadResultados(type: any) {
switch (type) {
case 'todos':
Expand Down
63 changes: 40 additions & 23 deletions src/app/modules/rup/components/ejecucion/hudsBusqueda.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas
</div>
</div>
</div>


<ng-container
*ngIf="filtroActual !== 'solicitudes' && filtroActual !== 'planes' && filtroActual !== 'laboratorios' && filtroActual !== 'vacunas' && filtroActual !== 'dominios'">
<div *ngIf="hasRegistrosTotales(filtroActual)" class="mb-2">
Expand Down Expand Up @@ -67,15 +69,18 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas
(change)="seleccionarReceta($event, grupo.recetas, iReceta)">
</plex-bool>
<div class="total">
<div class="row vista-badges" *ngIf="grupo.recetaVisible?.medicamento?.tratamientoProlongado">
<span class="pl-2 pr-2 mr-3 upTag" [ngClass]="{'active': huds.isOpen(grupo, 'receta')}">
Tratamiento prolongado: {{ (grupo.recetaVisible?.medicamento?.ordenTratamiento !== null && grupo.recetaVisible?.medicamento?.ordenTratamiento !== undefined) ? (grupo.recetaVisible.medicamento.ordenTratamiento + 1) : 0 }} de {{grupo.recetaVisible?.medicamento.tiempoTratamiento?.id}}</span>
</div>
<div class="rup-card mini recetas total" [ngClass]="{'active': huds.isOpen(grupo, 'receta')}"
(click)="emitTabs(grupo, 'receta', iReceta)">
<div class="row vista-badges"
*ngIf="grupo.recetaVisible?.medicamento?.tratamientoProlongado">
<span class="pl-2 pr-2 mr-3 upTag" [ngClass]="{'active': huds.isOpen(grupo, 'receta')}">
{{ textoTratamientoProlongado(grupo) }}
</span>
</div>
<div class="rup-card mini recetas total"
[ngClass]="{'active': huds.isOpen(grupo, 'receta')}"
(click)="emitTabs(grupo, 'receta', iReceta)">
<div class="rup-header">
<div class="rup-border rup-border-recetas"
[ngClass]="{'active': huds.isOpen(grupo, 'receta')}">
[ngClass]="{'active': huds.isOpen(grupo, 'receta')}">
<div class="row p-0 m-0 border-secondary border-left-0">
<div class="col-9 p-0 m-0">
<div class="row m-0 p-0">
Expand All @@ -89,13 +94,14 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas
<div class="col-10 p-0 m-0">
<div class="sugerido">
<small>Fecha de Registro:
{{ grupo.recetaVisible?.fechaRegistro | date:'short' }}
</small>
<br>
<small>Profesional: {{
grupo.recetaVisible?.profesional.nombre }} {{
grupo.recetaVisible?.profesional.apellido }}
</small>
{{ grupo.recetaVisible?.fechaRegistro |
date:'short' }}
</small>
<br>
<small>Profesional: {{
grupo.recetaVisible?.profesional.nombre }} {{
grupo.recetaVisible?.profesional.apellido }}
</small>
</div>
</div>
</div>
Expand All @@ -105,15 +111,18 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas
<div class="col-3 p-0 m-0">
<div class="p-0 pt-1 pr-1 float-right">
<div class="vista-badges">
<plex-badge size="sm"
[type]="estadoReceta[grupo.recetaVisible?.estadoActual.tipo]">
{{ grupo.recetaVisible?.estadoActual?.tipo.replace('-', ' ') }}
</plex-badge>
<plex-badge size="sm"
[type]="estadoDispensa[grupo.recetaVisible?.estadoDispensaActual.tipo]">
{{ grupo.recetaVisible?.estadoDispensaActual?.tipo.replace('-', ' ')
}}
</plex-badge>
<plex-badge size="sm"
[type]="estadoReceta[grupo.recetaVisible?.estadoActual.tipo]">
{{ grupo.recetaVisible?.estadoActual?.tipo.replace('-', ' ')
}}
</plex-badge>
<plex-badge size="sm"
[type]="estadoDispensa[grupo.recetaVisible?.estadoDispensaActual.tipo]">
{{
grupo.recetaVisible?.estadoDispensaActual?.tipo.replace('-',
' ')
}}
</plex-badge>
</div>
</div>
</div>
Expand Down Expand Up @@ -725,6 +734,14 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas

<!-- Vista: LABORATORIOS -->
<ng-container *ngIf="filtroActual === 'laboratorios'">
<plex-title titulo="Registros del paciente" size="sm" main>
<plex-button label="Refrescar laboratorios" style="margin-right: 7px;" type="primary" size="sm"
[autodisabled]="true" (click)="refreshLaboratorios(token)">
</plex-button>
<plex-button icon="refresh" type="success" size="sm" tooltipPosition="left" tooltip="Regenerar"
[disabled]="disabledBtnCDA" (click)="regenerarCDA()">
</plex-button>
</plex-title>
<div *ngIf="laboratorios.length" class="conceptos hover list-unstyled">
<ul class="listado list-unstyled">
<ng-container *ngFor="let laboratorio of laboratorios; let iLaboratorio = index">
Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/rup/services/CDA.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export class CDAService {
return this.server.get(this.CDAUrl + 'paciente/' + idPaciente);
}

regenerarCDA(paciente) {
return this.server.post(this.CDAUrl + 'paciente', {
paciente
});
}

protected extractData(res: Response) {
return res.blob();
}
Expand Down