@@ -18,6 +18,7 @@ import { TurnoService } from '../../../services/turnos/turno.service';
1818import { ConstantesService } from 'src/app/services/constantes.service' ;
1919import { SnomedService } from 'src/app/apps/mitos' ;
2020import { ECLQueriesService } from 'src/app/services/eclqueries.service' ;
21+ import { ConceptosTurneablesService } from 'src/app/services/conceptos-turneables.service' ;
2122
2223
2324@Component ( {
@@ -131,6 +132,7 @@ export class SolicitudesComponent implements OnInit {
131132 public check ;
132133 public collapse = false ;
133134 public loader = true ;
135+ private vigenciasMap : { [ conceptId : string ] : number } = { } ;
134136 public columns = [
135137 {
136138 key : 'fecha' ,
@@ -178,13 +180,21 @@ export class SolicitudesComponent implements OnInit {
178180 public motivosHudsService : MotivosHudsService ,
179181 public constantesService : ConstantesService ,
180182 public snomedService : SnomedService ,
181- public eclqueriesServicies : ECLQueriesService
183+ public eclqueriesServicies : ECLQueriesService ,
184+ private conceptosTurneablesService : ConceptosTurneablesService
182185 ) {
183186 }
184187
185188 ngOnInit ( ) {
186189 this . initFechas ( ) ;
187190
191+ // Precarga el mapa de tiempoVigencia por conceptId (con caché)
192+ this . conceptosTurneablesService . getAll ( ) . subscribe ( ( conceptos : any [ ] ) => {
193+ conceptos . forEach ( c => {
194+ this . vigenciasMap [ c . conceptId ] = c . tiempoVigencia || 365 ;
195+ } ) ;
196+ } ) ;
197+
188198 if ( ! this . auth . getPermissions ( 'solicitudes:?' ) . length ) {
189199 this . router . navigate ( [ this . auth . profesional ? '/solicitudes/asignadas' : 'inicio' ] ) ;
190200 } else if ( this . auth . getPermissions ( 'solicitudes:?' ) . length === 1 && this . auth . getPermissions ( 'solicitudes:reglas:?' ) [ 0 ] !== '*' && ! this . auth . getPermissions ( 'solicitudes:tipoPrestacion:?' ) . length ) {
@@ -466,7 +476,12 @@ export class SolicitudesComponent implements OnInit {
466476 } else if ( this . estadoEntrada . id === 'registroHUDS' ) {
467477 params [ 'estados' ] = [ 'validada' ] ;
468478 } else {
469- params [ 'estados' ] = [ this . estadoEntrada . id ] ;
479+ if ( this . estadoEntrada . id === 'vencida' ) {
480+ // Traer pendiente+auditoria+vencida para filtrar client-side
481+ params [ 'estados' ] = [ 'vencida' , 'pendiente' , 'auditoria' ] ;
482+ } else {
483+ params [ 'estados' ] = [ this . estadoEntrada . id ] ;
484+ }
470485 if ( this . estadoEntrada . id === 'pendiente' ) {
471486 params [ 'tieneTurno' ] = false ;
472487 }
@@ -512,7 +527,12 @@ export class SolicitudesComponent implements OnInit {
512527 } else if ( this . estadoSalida . id === 'registroHUDS' ) {
513528 params [ 'estados' ] = [ 'validada' ] ;
514529 } else {
515- params [ 'estados' ] = [ this . estadoSalida . id ] ;
530+ if ( this . estadoSalida . id === 'vencida' ) {
531+ // Traer pendiente+auditoria+vencida para filtrar client-side
532+ params [ 'estados' ] = [ 'vencida' , 'pendiente' , 'auditoria' ] ;
533+ } else {
534+ params [ 'estados' ] = [ this . estadoSalida . id ] ;
535+ }
516536 if ( this . estadoSalida . id === 'pendiente' ) {
517537 params [ 'tieneTurno' ] = false ;
518538 }
@@ -567,8 +587,20 @@ export class SolicitudesComponent implements OnInit {
567587
568588 @Unsubscribe ( )
569589 buscarSolicitudes ( ) {
590+ const estadoFiltro = this . tipoSolicitud === 'entrada' ? this . estadoEntrada ?. id : this . estadoSalida ?. id ;
570591 return this . servicioPrestacion . getSolicitudes ( this . getParams ( ) )
571- . pipe ( map ( ( resultado ) => resultado . filter ( ( solicitud ) => ! this . esPacienteRestringido ( solicitud . paciente ) ) ) )
592+ . pipe (
593+ map ( ( resultado ) => resultado . filter ( ( solicitud ) => ! this . esPacienteRestringido ( solicitud . paciente ) ) ) ,
594+ map ( ( resultado ) => {
595+ if ( estadoFiltro === 'vencida' ) {
596+ return resultado . filter ( s => s . estadoActual . tipo === 'vencida' || this . estaVencidaEnListado ( s ) ) ;
597+ }
598+ if ( estadoFiltro ) {
599+ return resultado . filter ( s => ! this . estaVencidaEnListado ( s ) ) ;
600+ }
601+ return resultado ;
602+ } )
603+ )
572604 . subscribe ( resultado => {
573605 if ( this . tipoSolicitud === 'entrada' ) {
574606 this . prestacionesEntrada = this . prestacionesEntrada . concat ( resultado ) ;
@@ -760,6 +792,17 @@ export class SolicitudesComponent implements OnInit {
760792 }
761793 }
762794
795+ estaVencidaEnListado ( prestacion : any ) : boolean {
796+ if ( ! prestacion ?. solicitud ?. fecha ) { return false ; }
797+ const estadoTipo = prestacion . estadoActual ?. tipo ;
798+ if ( estadoTipo === 'vencida' || estadoTipo === 'anulada' || estadoTipo === 'validada' ) { return false ; }
799+ const conceptId = prestacion . solicitud . tipoPrestacion ?. conceptId ;
800+ const vigencia = this . vigenciasMap [ conceptId ] ?? 365 ;
801+ const fechaVenc = new Date ( prestacion . solicitud . fecha ) ;
802+ fechaVenc . setDate ( fechaVenc . getDate ( ) + vigencia ) ;
803+ return fechaVenc < new Date ( ) ;
804+ }
805+
763806 onChange ( ) {
764807 this . actualizacion = ! this . actualizacion ;
765808 this . loader = true ;
0 commit comments