@@ -44,6 +44,7 @@ export class DarTurnosComponent implements OnInit {
4444 public link : String = '' ;
4545 public changeCarpeta = false ;
4646 public financiador ;
47+ public todaysdate : Date ;
4748 hideDarTurno : boolean ;
4849 @HostBinding ( 'class.plex-layout' ) layout = true ; // Permite el uso de flex-box en el componente
4950 autocitado = false ;
@@ -67,6 +68,10 @@ export class DarTurnosComponent implements OnInit {
6768 set demandaInsatisfecha ( value : any ) {
6869 this . desdeDemanda = value ;
6970 }
71+ turnosPaciente : any ;
72+ get paciente ( ) : any {
73+ return this . _paciente ;
74+ }
7075
7176 @Input ( 'solicitudPrestacion' )
7277 set solicitudPrestacion ( value : any ) {
@@ -127,7 +132,7 @@ export class DarTurnosComponent implements OnInit {
127132 public organizacion = this . auth . organizacion ;
128133 public _pacienteSeleccionado : any ;
129134 public _solicitudPrestacion : any ; // TODO: cambiar por IPrestacion cuando esté
130- public paciente : IPaciente ;
135+ public _paciente : IPaciente ;
131136 public opciones : any = { } ;
132137 public agenda : IAgenda ;
133138 public agendas : IAgenda [ ] ;
@@ -216,6 +221,8 @@ export class DarTurnosComponent implements OnInit {
216221 ) { }
217222
218223 ngOnInit ( ) {
224+ this . todaysdate = new Date ( ) ;
225+ this . todaysdate . setHours ( 0 , 0 , 0 , 0 ) ;
219226 this . hoy = new Date ( ) ;
220227 this . autorizado = this . auth . getPermissions ( 'turnos:darTurnos:?' ) . length > 0 ;
221228 this . puedeDarSobreturno = this . auth . check ( 'turnos:puntoInicio:darSobreturno' ) ;
@@ -251,11 +258,24 @@ export class DarTurnosComponent implements OnInit {
251258 this . actualizar ( ) ;
252259 }
253260
261+ cargarTurnos ( ) {
262+ if ( this . _paciente ?. id ) {
263+ this . serviceTurno . getHistorial ( { pacienteId : this . _paciente . id } ) . subscribe ( turnos => {
264+ const turnosFiltrados = turnos . filter ( t => t . estado !== 'liberado' && moment ( t . horaInicio ) . isSameOrAfter ( this . todaysdate , 'day' ) ) ;
265+ this . turnosPaciente = turnosFiltrados . sort ( ( a , b ) => {
266+ const inia = a . horaInicio ? new Date ( a . horaInicio ) : null ;
267+ const inib = b . horaInicio ? new Date ( b . horaInicio ) : null ;
268+ return ( ( inia && inib ) ? ( inib . getTime ( ) - inia . getTime ( ) ) : 0 ) ;
269+ } ) ;
270+ } ) ;
271+ }
272+ }
254273 actualizarDatosPaciente ( paciente ) {
255274 const idPaciente = paciente . _id || paciente . id ;
256275 this . servicePaciente . getById ( idPaciente ) . subscribe (
257276 pacienteMPI => {
258- this . paciente = pacienteMPI ;
277+ this . _paciente = pacienteMPI ;
278+ this . cargarTurnos ( ) ;
259279 this . verificarTelefono ( pacienteMPI ) ;
260280 this . obtenerCarpetaPaciente ( ) ;
261281 if ( this . paciente . documento ) {
0 commit comments