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
143 changes: 138 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, 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;
private cantidadRegistros;

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.cantidadRegistros = Number(this.laboratorios.lenght);

this.cdaService.regenerarCDA(this.paciente).subscribe(
() => {
this.plex.toast('success', 'Esta acción requiere algunos segundos de espera.', 'BUSCANDO NUEVOS REGISTROS', 5000);
this.secondsToUpdate = 15;
if (this.intervalUpdate) {
clearInterval(this.intervalUpdate);
}
this.intervalUpdate = setInterval(() => {
this.secondsToUpdate--;
if (this.secondsToUpdate <= 0) {
clearInterval(this.intervalUpdate);
this.refreshLaboratorios(this.token);
}
}, 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,48 @@ 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);

const nuevosRegistros = this.laboratorios.length - this.cantidadRegistros;
const notificacion = nuevosRegistros > 0 ? 'Se encontraron ' + nuevosRegistros + ' nuevos registros.' : 'No se encontraron nuevos registros. Puede intentar regenerar/actualizar el listado nuevamente en unos minutos.';
this.plex.toast('info', notificacion, 'Información', 6000);
this.disabledBtnCDA = false;
}
});
}


getCantidadResultados(type: any) {
switch (type) {
case 'todos':
Expand Down
78 changes: 51 additions & 27 deletions src/app/modules/rup/components/ejecucion/hudsBusqueda.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@
</plex-card>
</div>
</div>
<div class="menu-titulo">
<div class="menu-titulo mt-1">

<h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercase }}</h6>

<div *ngIf="filtroActual === 'laboratorios'" justify="end">
<plex-button class="mr-1" icon="refresh" type="primary" size="sm" tooltip="Actualizar listado"
[autodisabled]="true" (click)="refreshLaboratorios(token)">
</plex-button>
<plex-button icon="database-search" type="success" size="sm" tooltipPosition="left"
tooltip="Buscar nuevos registros" [disabled]="disabledBtnCDA" (click)="regenerarCDA()">
</plex-button>
</div>

<suspender-medicacion *ngIf="filtroActual==='recetas' && seleccionRecetas.length > 0"
[seleccionRecetas]="seleccionSuspender" [motivoSelector]="motivoSuspensionSelector"
[motivosSuspension]="motivosSuspension" [profesional]="profesional"
(reset)="resetSeleccionRecetas()"></suspender-medicacion>
(reset)="resetSeleccionRecetas()">
</suspender-medicacion>
</div>
<div class="grow" *ngIf="filtroActual === 'planes'">
<plex-options class="filtros-ambitos" (activated)='setAmbitoOrigen($event)' [items]="filtrosAmbitos">
Expand All @@ -38,6 +50,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 +81,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 +106,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 +123,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,8 +746,11 @@ <h6 class="titulo-filtro {{filtroActual}}">{{ getTitulo(filtroActual) | uppercas

<!-- Vista: LABORATORIOS -->
<ng-container *ngIf="filtroActual === 'laboratorios'">
<div *ngIf="laboratorios.length" class="conceptos hover list-unstyled">
<ul class="listado list-unstyled">
<plex-loader *ngIf="disabledBtnCDA" class="sidebar-loader" type="ball-pulse"></plex-loader>

<div *ngIf="laboratorios.length" class="conceptos hover list-unstyled mt-1">

<ul class="listado list-unstyled" [ngClass]="{ 'opacity-35' : disabledBtnCDA }">
<ng-container *ngFor="let laboratorio of laboratorios; let iLaboratorio = index">
<li>
<div class="rup-card mini laboratorio"
Expand Down
12 changes: 12 additions & 0 deletions src/app/modules/rup/components/ejecucion/hudsBusqueda.scss
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,22 @@
font-size: 80%;

}

.total {
width: 100% !important;
}

.item-lista-vacia {
margin-top: 10%
}

.sidebar-loader {
position: absolute;
top: 180px;
right: 45%;
z-index: 100;
}

.opacity-35 {
opacity: 0.35;
}
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
Loading