From b4cebaee163f8c46a27e9d1059ab74eb0d4613cc Mon Sep 17 00:00:00 2001 From: MarianoCampetella Date: Thu, 12 Mar 2026 12:44:14 -0300 Subject: [PATCH] =?UTF-8?q?No=20se=20deber=C3=ADa=20suspeder=20turno=20con?= =?UTF-8?q?=20registro=20en=20curso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../turnos/gestor-agendas/turnos.component.ts | 91 +++++++++++- .../turnos/gestor-agendas/turnos.html | 130 +++++++++--------- 2 files changed, 152 insertions(+), 69 deletions(-) diff --git a/src/app/components/turnos/gestor-agendas/turnos.component.ts b/src/app/components/turnos/gestor-agendas/turnos.component.ts index 0ddb2c3e1c..974ee16f7c 100644 --- a/src/app/components/turnos/gestor-agendas/turnos.component.ts +++ b/src/app/components/turnos/gestor-agendas/turnos.component.ts @@ -9,6 +9,7 @@ import { ListaEsperaService } from '../../../services/turnos/listaEspera.service import { EstadosAgenda } from './../enums'; import * as moment from 'moment'; import { TurnoService } from 'src/app/services/turnos/turno.service'; +import { PrestacionesService } from 'src/app/modules/rup/services/prestaciones.service'; @Component({ selector: 'turnos', @@ -102,7 +103,12 @@ export class TurnosComponent implements OnInit { public arrayDelDia = []; public sortBy: string; public sortOrder = 'desc'; + public prestacionTurno = []; + puedeSuspenderLiberar = true; + validSuspensionLiberacion = false; botonera = true; + private validacionesPendientesSuspension = 0; + private turnosConPrestacionEnEjecucion = new Set(); public columns = [ { @@ -136,7 +142,8 @@ export class TurnosComponent implements OnInit { public serviceAgenda: AgendaService, public listaEsperaService: ListaEsperaService, public auth: Auth, - public serviceTurno: TurnoService) { } + public serviceTurno: TurnoService, + public prestacionService: PrestacionesService) { } ngOnInit() { const agendaActualizar = this.agenda; @@ -147,17 +154,77 @@ export class TurnosComponent implements OnInit { this.showSeleccionarTodos = (this.bloqueSelected.turnos.length > 0); } + private getTurnoId(turno: any): string { + return String(turno?.id || turno?._id || ''); + } + + private actualizarEstadoSuspension() { + if (!this.turnosSeleccionados.length) { + this.puedeSuspenderLiberar = true; + return; + } + this.puedeSuspenderLiberar = this.turnosConPrestacionEnEjecucion.size === 0; + } + + private validarPrestacionEnEjecucion(turno: any) { + const turnoId = this.getTurnoId(turno); + if (!turnoId) { + this.actualizarEstadoSuspension(); + return; + } + + this.validacionesPendientesSuspension++; + this.validSuspensionLiberacion = true; + + const params: any = { + solicitudTurno: turno._id + }; + + this.prestacionService.getSolicitudes(params).subscribe({ + next: resultado => { + const sigueSeleccionado = this.turnosSeleccionados.some(x => this.getTurnoId(x) === turnoId); + if (!sigueSeleccionado) { + return; + } + + const enEjecucion = resultado?.some(item => item?.estadoActual?.tipo === 'ejecucion'); + if (enEjecucion) { + this.turnosConPrestacionEnEjecucion.add(turnoId); + } else { + this.turnosConPrestacionEnEjecucion.delete(turnoId); + } + this.actualizarEstadoSuspension(); + }, + error: () => { + const sigueSeleccionado = this.turnosSeleccionados.some(x => this.getTurnoId(x) === turnoId); + if (sigueSeleccionado) { + this.puedeSuspenderLiberar = false; + } + }, + complete: () => { + this.validacionesPendientesSuspension = Math.max(0, this.validacionesPendientesSuspension - 1); + this.validSuspensionLiberacion = this.validacionesPendientesSuspension > 0; + } + }); + } + seleccionarTurno(turno, multiple = false, sobreturno) { turno.sobreturno = sobreturno; + const turnoId = this.getTurnoId(turno); + const estabaSeleccionado = this.turnosSeleccionados.some(x => this.getTurnoId(x) === turnoId); + if (!multiple) { - this.turnosSeleccionados = []; - this.turnosSeleccionados = [...this.turnosSeleccionados, turno]; + this.turnosSeleccionados = [turno]; + this.turnosConPrestacionEnEjecucion.clear(); + this.validarPrestacionEnEjecucion(turno); } else { - if (this.turnosSeleccionados.find(x => x.id === turno._id)) { - this.turnosSeleccionados.splice(this.turnosSeleccionados.indexOf(turno), 1); - this.turnosSeleccionados = [... this.turnosSeleccionados]; + if (estabaSeleccionado) { + this.turnosSeleccionados = this.turnosSeleccionados.filter(x => this.getTurnoId(x) !== turnoId); + this.turnosConPrestacionEnEjecucion.delete(turnoId); + this.actualizarEstadoSuspension(); } else { this.turnosSeleccionados = [... this.turnosSeleccionados, turno]; + this.validarPrestacionEnEjecucion(turno); } } @@ -438,4 +505,16 @@ export class TurnosComponent implements OnInit { } return false; } + + puedeSuspenderTurno(botonSuspender) { + return botonSuspender && !this.validSuspensionLiberacion && this.puedeSuspenderLiberar; + } + + puedeLiberarTurno(botonLiberar, turnoSeleccionado, turno) { + return botonLiberar && turnoSeleccionado?.id === turno.id && !this.validSuspensionLiberacion && this.puedeSuspenderLiberar; + } + + puedeLiberarSobreturno(botonLiberar, turnoSeleccionado, sobreturno) { + return botonLiberar && turnoSeleccionado?.id === sobreturno.id && !this.validSuspensionLiberacion && this.puedeSuspenderLiberar; + } } diff --git a/src/app/components/turnos/gestor-agendas/turnos.html b/src/app/components/turnos/gestor-agendas/turnos.html index 1d8867e7d0..b538a5c540 100644 --- a/src/app/components/turnos/gestor-agendas/turnos.html +++ b/src/app/components/turnos/gestor-agendas/turnos.html @@ -14,39 +14,39 @@ + subtitulo="{{countBloques[mostrar]?.profesional}}"> + titulo="BLOQUE | {{ bloqueSelected.horaInicio | date: 'HH:mm'}} a {{ bloqueSelected.horaFin |date:'HH:mm'}} hs"> + ariaLabel="Registrar inasistencia" size="sm" type="warning" icon="account-remove" + (click)="eventosTurno('sacarAsistencia')" tooltip="Registrar inasistencia" tooltipPosition="top"> + ariaLabel="Registrar asistencia" size="sm" type="success" icon="account-check" + (click)="eventosTurno('darAsistencia')" tooltip="Registrar asistencia" tooltipPosition="top"> + icon="comment-outline" tooltip="Agregar nota" tooltipPosition="top"> + (saveAgregarNotaTurno)="saveAgregarNotaTurno()"> - + + + [turnosSeleccionados]="turnosSeleccionados" (saveSuspenderTurno)="saveSuspenderTurno()" + (reasignarTurnoSuspendido)="reasignarTurnoSuspendido($event)"> + size="sm" icon="undo" tooltip="Cambiar a disponible" tooltipPosition="top" + (click)="cambiarADisponible()"> @@ -123,19 +123,19 @@

+ type="default"> + type="warning"> Autocitado Con llave + type="warning"> Programado Reasignado @@ -150,7 +150,7 @@

suspendido(sin paciente) + tooltipPosition="right" size="sm" cardSize="half">
{{ turno.nota }}
@@ -158,10 +158,10 @@

+ titulo="{{ turno.horaInicio | date: 'HH:mm' }}hs"> + titulo="{{turno.horaInicio | date: 'HH:mm' }}hs | {{turno.paciente | nombre }}"> @@ -178,61 +178,63 @@

+ class="mr-1" size="sm" type="info" tooltip="Ya reasignado" tooltipPosition="left"> - + - + - + + title="Notificación pendiente" class="mr-1" tooltipPosition="left"> + title="Notificación enviada"> + ariaLabel="Turno doble" size="sm" type="default" icon="numeric-2-box-multiple-outline" + (click)="asignarTurnoDoble('darTurnoDoble')" tooltip="Turno doble" tooltipPosition="top"> + ariaLabel="Quitar Turno doble" size="sm" type="default" icon="numeric-1-box-outline" + (click)="eventosTurno('quitarTurnoDoble', agenda)" tooltip="Quitar Turno doble" + tooltipPosition="top"> + btnType="info" icon="folder-account" tooltip="Editar Carpeta" tooltipPosition="top"> + subtitulo="{{turnosSeleccionados[0].paciente | nombre }}" icon="paciente"> + (guardarCarpetaEmit)="afterComponenteCarpeta($event)" + (cancelarCarpetaEmit)="afterComponenteCarpeta($event)"> - + + [desdeAgenda]="true" (saveLiberarTurno)="saveLiberarTurno($event)" + (reasignarTurnoLiberado)="reasignarTurnoLiberado($event)" + (cancelaLiberarTurno)="cancelaLiberarTurno()"> @@ -257,7 +259,7 @@

+ size="sm" type="default"> @@ -267,12 +269,12 @@

Suspendido + tooltipPosition="right">

+ titulo="{{sobreturno.horaInicio | date: 'HH:mm' }}hs | {{sobreturno.paciente | nombre }}"> @@ -289,34 +291,36 @@

- + - + + btnType="info" icon="folder-account" tooltip="Editar Carpeta" tooltipPosition="top"> + subtitulo="{{turnosSeleccionados[0].paciente | nombre }}" icon="paciente"> + (guardarCarpetaEmit)="afterComponenteCarpeta($event)" + (cancelarCarpetaEmit)="afterComponenteCarpeta($event)"> - + + [desdeAgenda]="true" (saveLiberarTurno)="saveLiberarTurno($event)" + (reasignarTurnoLiberado)="reasignarTurnoLiberado($event)" + (cancelaLiberarTurno)="cancelaLiberarTurno()">