Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIT - Verifica turnos y solicitudes al asignar demanda #3091

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
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="alert-outline" type="warning"></plex-icon>
<plex-modal-subtitle class="font-title text-center" type="warning" size="sm"><b>No es posible registrar la
demanda</b></plex-modal-subtitle>
<main>
<div class="modal-contents">
<div *ngIf="turnoAsociado">
<p class="text-center"> <b>Existe un turno pendiente para la prestacíon seleccionada.</b>
</p>
<plex-label size="sm" icon="calendar-clock" titulo="Fecha" color="#FF8C00"
subtitulo="{{ turnoAsociado.dia}} a las {{ turnoAsociado.horario}}">
</plex-label>

<plex-label size="sm" color="#FF8C00" icon="hospital" titulo="Organización"
subtitulo="{{ turnoAsociado.organizacion}}">
</plex-label>

<plex-label size="sm" color="#FF8C00" icon="circulo-medico" titulo="Profesional/es"
subtitulo="{{ turnoAsociado.profesionales}}">
</plex-label>
</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;
}
80 changes: 71 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,71 @@ 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,
false
);

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.profesionale ? data.profesionales.map(prof => ` ${prof.nombre} ${prof.apellido}`) : 'Sin profesionales asignados';
const organizacion = data.organizacion?.nombre || null;

this.turnoAsociado = { dia, horario, profesionales, organizacion };
} 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();
}

}
8 changes: 4 additions & 4 deletions src/app/services/turnos/listaEspera.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class ListaEsperaService {
return this.server.get(this.listaEsperaUrl, { params: params, showError: true });
}

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

postXIdAgenda(id: String, cambios: any): Observable<IListaEspera> {
Expand All @@ -42,7 +42,7 @@ export class ListaEsperaService {
return this.server.patch(this.listaEsperaUrl + '/' + id + '/' + datoMod, cambios);
}

save(paciente, tipoPrestacion, estado: String, profesional, organizacion, motivo: String, origen: String) {
save(paciente, tipoPrestacion, estado: String, profesional, organizacion, motivo: String, origen: String, showError?: boolean) {
const datosProfesional = !profesional ? null : {
id: profesional.id,
nombre: profesional.nombre,
Expand All @@ -64,6 +64,6 @@ export class ListaEsperaService {
tipoPrestacion,
resolucion: null
};
return this.post(listaEspera);
return this.post(listaEspera, showError);
}
}
Loading