Skip to content

Commit

Permalink
feat(CIT): chequea turnos antes de asignar demanda
Browse files Browse the repository at this point in the history
  • Loading branch information
ma7payne committed Nov 27, 2024
1 parent fadd959 commit 9a03ead
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 11 deletions.
60 changes: 59 additions & 1 deletion src/app/components/turnos/dashboard/demandaInsatisfecha.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,62 @@
</plex-select>
<plex-select label="Motivo" [(ngModel)]="motivo" [required]="true" [data]="motivos" name="motivos"
placeholder="Seleccione motivo"></plex-select>
</form>
</form>

<plex-modal size="sm" #modalSolicitudes [allowEscClose]="true" [allowBackdropClose]="false">
<plex-icon name="check-circle" type="success"></plex-icon>
<plex-modal-subtitle class="font-title text-center" type="success" size="sm"><b>¡Demanda insatisfecha guardada
exitosamente!</b></plex-modal-subtitle>
<main>
<div class="modal-contents">
<p class="text-center">
Existen solicitudes asociadas a la prestación:
</p>
<ng-container *ngFor="let registro of solicitudesAsociadas">
<small>
Fecha de solicitud: {{ registro.solicitud.fecha | fecha }} {{ registro.solicitud.fecha | hora }}
</small>
<div class="content-row">
<plex-label size="sm" style="width: 100%;" color="#0070cc" icon="mano-corazon"
titulo="Tipos de solicitud"
subtitulo="{{ registro.solicitud.tipoPrestacion.term }}"></plex-label>

<plex-label size="sm" style="width: 100%;" color="#0070cc" icon="hospital"
titulo="Organización destino"
subtitulo="{{ registro.solicitud.organizacion.nombre }}"></plex-label>
</div>
</ng-container>
</div>
</main>
<plex-button modal center type="success" (click)="cerrar()">
ACEPTAR
</plex-button>
</plex-modal>

<plex-modal size="sm" #modalTurno [allowEscClose]="true" [allowBackdropClose]="false">
<plex-icon name="check-circle" type="warning"></plex-icon>
<plex-modal-subtitle class="font-title text-center" type="warning"
size="sm"><b>Información</b></plex-modal-subtitle>
<main>
<div class="modal-contents">
<p class="text-center">
Existe un turno pendiente para la prestacíon seleccionada:
</p>
<div *ngIf="turnoAsociado">
<p class="text-center"><b>{{turnoAsociado?.dia}}</b> a las <b>{{turnoAsociado?.horario}}</b> hs.</p>
<div class="text-center" *ngIf="turnoAsociado.profesionales.length">
<p>Profesionales: <br>
{{turnoAsociado?.profesionales}}</p>
</div>
<div class="text-center" *ngIf="!turnoAsociado.profesionales.length">
<p>
- Sin profesionales asignados -
</p>
</div>
</div>
</div>
</main>
<plex-button modal center type="warning" (click)="modalTurno.close()">
ACEPTAR
</plex-button>
</plex-modal>
16 changes: 16 additions & 0 deletions src/app/components/turnos/dashboard/demandaInsatisfecha.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
main {
min-height: auto !important;
}

.modal-contents {
.content-row:last-child {
border-bottom: none;
}
}

.content-row {
display: flex;
align-items: center;
margin-bottom: 10px;
border-bottom: 1px solid #999;
}
78 changes: 69 additions & 9 deletions src/app/components/turnos/dashboard/demandaInsatisfecha.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Auth } from '@andes/auth';
import { Plex } from '@andes/plex';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { PlexModalComponent } from '@andes/plex/src/lib/modal/modal.component';
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { catchError, switchMap, throwError } from 'rxjs';
import { IPaciente } from 'src/app/core/mpi/interfaces/IPaciente';
import { PrestacionesService } from 'src/app/modules/rup/services/prestaciones.service';
import { ConceptosTurneablesService } from 'src/app/services/conceptos-turneables.service';
import { ListaEsperaService } from 'src/app/services/turnos/listaEspera.service';
import { ProfesionalService } from './../../../services/profesional.service';

@Component({
selector: 'demandaInsatisfecha',
templateUrl: 'demandaInsatisfecha.html',
styleUrls: ['demandaInsatisfecha.scss']
})

export class demandaInsatisfechaComponent {
Expand All @@ -17,6 +21,8 @@ export class demandaInsatisfechaComponent {
@Input() origen = 'citas';
@Input() estado = 'pendiente';
@Output() demandaCerrada = new EventEmitter<any>();
@ViewChild('modalSolicitudes', { static: true }) modalSolicitudes: PlexModalComponent;
@ViewChild('modalTurno', { static: true }) modalTurno: PlexModalComponent;

tipoPrestacion: any;
permisos = [];
Expand All @@ -28,13 +34,16 @@ export class demandaInsatisfechaComponent {
];
motivo: any;
organizacion = this.auth.organizacion;
solicitudesAsociadas;
turnoAsociado;

constructor(
public auth: Auth,
public plex: Plex,
public conceptosTurneablesService: ConceptosTurneablesService,
public profesionalService: ProfesionalService,
public listaEsperaService: ListaEsperaService,
public servicioPrestacion: PrestacionesService,
) { }

loadTipoPrestaciones(event) {
Expand All @@ -53,18 +62,69 @@ export class demandaInsatisfechaComponent {

guardar() {
if (this.motivo && this.tipoPrestacion) {
this.listaEsperaService.save({ id: this.paciente.id }, this.tipoPrestacion, this.estado, this.profesional, this.organizacion, this.motivo.nombre, this.origen).subscribe({
complete: () => {
this.plex.toast('success', 'Demanda insatisfecha guardada exitosamente!');
this.cerrar();
},
error: (e) => this.plex.toast('danger', e.message, 'Ha ocurrido un error al guardar')
});
const params = {
idPaciente: this.paciente.id,
prestacionDestino: this.tipoPrestacion?.conceptId,
estados: [
'auditoria',
'pendiente',
]
};

const listaEsperaService$ = this.listaEsperaService.save(
{ id: this.paciente.id },
this.tipoPrestacion,
this.estado,
this.profesional,
this.organizacion,
this.motivo.nombre,
this.origen
);

listaEsperaService$
.pipe(
catchError((err) => {
if (err.code === 'turno_existente') {
const { data } = err;
const dia = moment(data.horaInicio).format('LL');
const horario = moment(data.horaInicio).format('HH:mm');
const profesionales = data.profesionales?.map(prof => ` ${prof.nombre} ${prof.apellido}`);

this.turnoAsociado = { dia, horario, profesionales };
} else {
this.plex.info('danger', err, 'No se pudo conectar con el servidor');
}

return throwError(() => err);
}),
switchMap(() =>
this.servicioPrestacion.getSolicitudes(params).pipe(
catchError(() => {
this.plex.toast('success', 'Demanda insatisfecha guardada exitosamente!');
this.cerrar();

return throwError(() => new Error('Error al obtener solicitudes'));
})
)
),
)
.subscribe({
next: (solicitudes) => {
if (solicitudes?.length) {
this.solicitudesAsociadas = solicitudes;
this.modalSolicitudes.show();
} else {
this.plex.toast('success', 'Demanda insatisfecha guardada exitosamente!');
this.cerrar();
}
},
error: () => this.modalTurno.show()
});
}
}

cerrar() {
this.demandaCerrada.emit();
this.modalSolicitudes.close();
}

}
2 changes: 1 addition & 1 deletion src/app/services/turnos/listaEspera.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ListaEsperaService {
}

post(listaEspera: IListaEspera): Observable<IListaEspera> {
return this.server.post(this.listaEsperaUrl, listaEspera);
return this.server.post(this.listaEsperaUrl, listaEspera, { showError: false });
}

postXIdAgenda(id: String, cambios: any): Observable<IListaEspera> {
Expand Down

0 comments on commit 9a03ead

Please sign in to comment.