Skip to content

Commit

Permalink
feat(citas): carga masiva
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancho authored and plammel committed Nov 24, 2021
1 parent 7bf5904 commit b57004d
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import { HUDSService } from './modules/rup/services/huds.service';
import { PlantillasService } from './modules/rup/services/plantillas.service';
import { PrestacionesService } from './modules/rup/services/prestaciones.service';
import { ResumenPacienteDinamicoService } from './modules/rup/services/resumenPaciente-dinamico.service';
import { VisualizacionInformacionModule } from './modules/visualizacion-informacion/visualizacion-informacion.module';
import { AppMobileService } from './services/appMobile.service';
import { BarrioService } from './services/barrio.service';
import { ConceptosTurneablesService } from './services/conceptos-turneables.service';
Expand Down Expand Up @@ -245,7 +246,9 @@ registerLocaleData(localeEs, 'es');
AuditoriaModule,
RecaptchaModule,
RecaptchaFormsModule,
Ng2ImgMaxModule
Ng2ImgMaxModule,
VisualizacionInformacionModule

],
declarations: [
AppComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Auth } from '@andes/auth';
import { Plex } from '@andes/plex';
import { Component, OnDestroy, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren, ViewContainerRef } from '@angular/core';
import { Router } from '@angular/router';
import * as moment from 'moment';
import { Subscription } from 'rxjs';
import { BiQueriesComponent } from 'src/app/modules/visualizacion-informacion/components/bi-queries/bi-queries.component';
import { ConceptosTurneablesService } from 'src/app/services/conceptos-turneables.service';
import { QueriesService } from 'src/app/services/query.service';
import { ITurno } from '../../../interfaces/turnos/ITurno';
import { InstitucionService } from '../../../services/turnos/institucion.service';
import { enumToArray } from '../../../utils/enums';
Expand All @@ -28,6 +30,8 @@ export class GestorAgendasComponent implements OnInit, OnDestroy {
@ViewChild('guardarAgendaPanel', { static: false }) set setGuardarAgendaPanel(theElementRef: ViewContainerRef) {
this.guardarAgendaPanel = theElementRef;
}
@ViewChildren(BiQueriesComponent) biQuery: QueryList<any>;


agendasSeleccionadas: IAgenda[] = [];
turnosSeleccionados: ITurno[] = [];
Expand Down Expand Up @@ -72,6 +76,7 @@ export class GestorAgendasComponent implements OnInit, OnDestroy {
public puedeCrearAgenda: Boolean;
public puedeRevisarAgendas: Boolean;
private scrollEnd = false;
public enableQueries = false;

// ultima request de profesionales que se almacena con el subscribe
private lastRequestProf: Subscription;
Expand All @@ -97,7 +102,9 @@ export class GestorAgendasComponent implements OnInit, OnDestroy {
public serviceAgenda: AgendaService,
public serviceInstitucion: InstitucionService,
private router: Router,
public auth: Auth) { }
public auth: Auth,
private queryService: QueriesService,
) { }

/* limpiamos la request que se haya ejecutado */
ngOnDestroy() {
Expand Down Expand Up @@ -693,4 +700,72 @@ export class GestorAgendasComponent implements OnInit, OnDestroy {
this.showRevisionFueraAgenda = true;
}

cargarPacientes() {
this.enableQueries = !this.enableQueries;
}

asignarPacientesPorConsulta() {
let query;
const params = {};
let invalidFormMsg;
this.biQuery.forEach(item => {
if (item.consultaSeleccionada) {
query = item.consultaSeleccionada.nombre;
item.argumentos.forEach(arg => {
const key = arg.key;
const value = item.argumentos[key];
if (arg.required && !value) {
invalidFormMsg = 'Debe completar los filtros obligatorios';
}
params[key] = value;
});
} else {
invalidFormMsg = 'Debe seleccionar una lista de pacientes';
}
});

if (invalidFormMsg) {
this.plex.info('warning', invalidFormMsg, 'Atención');
} else {
this.queryService.getQuery(query, params).subscribe(res => {
this.asignarTurnosBulk(res);
});
}
}

asignarTurnosBulk(inscripciones) {
const pacientes = inscripciones.map(e => ({
id: e.pacienteId,
nombre: e.nombre,
apellido: e.apellido,
documento: e.documento,
fechaNacimiento: moment(e.fechaNacimiento),
telefono: e.telefono,
sexo: e.sexo,
carpetaEfectores: []
}));

let turnos = [];
this.agendasSeleccionadas[0].bloques.forEach(b => {
const turnosDisponibles = b.turnos.filter(t => !t.paciente);
turnos = [...turnos, ...turnosDisponibles];
});

let i = 0;
let end = pacientes.length;
if (end > turnos.length) {
end = turnos.length;
}
while (i < end) {
turnos[i].paciente = pacientes[i];
turnos[i].estado = 'asignado';
i++;
}

this.serviceAgenda.save(this.agendasSeleccionadas[0]).subscribe(res => {
this.showTurnos = true;
this.enableQueries = false;
this.plex.toast('success', 'Asignación automática exitosa', '', 1000);
});
}
}
33 changes: 20 additions & 13 deletions src/app/components/turnos/gestor-agendas/gestor-agendas.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
<header>
<plex-title titulo="Gestor de Agendas" size="lg">
<!--Botones / Acciones-->
<botones-agenda *ngIf="agendasSeleccionadas?.length > 0 && agendas?.length"
class="float-right" [agendasSeleccionadas]="agendasSeleccionadas"
(clonarEmit)="clonar()" (agregarNotaAgendaEmit)="agregarNotaAgenda()"
(agregarSobreturnoEmit)="agregarSobreturno($event)"
(editarAgendaEmit)="editarAgenda($event)"
(actualizarEstadoEmit)="actualizarEstadoEmit($event)"
(listarTurnosEmit)="listarTurnos($event)"
(listarCarpetasEmit)="listarCarpetas($event)"
(revisionAgendaEmit)="revisionAgenda($event)"
(reasignarTurnosEmit)="reasignarTurnos($event)"
[turnosSuspendidos]="turnosSuspendidos">
</botones-agenda>
<botones-agenda *ngIf="agendasSeleccionadas?.length > 0 && agendas?.length"
class="float-right" [agendasSeleccionadas]="agendasSeleccionadas"
(clonarEmit)="clonar()" (agregarNotaAgendaEmit)="agregarNotaAgenda()"
(agregarSobreturnoEmit)="agregarSobreturno($event)"
(editarAgendaEmit)="editarAgenda($event)"
(actualizarEstadoEmit)="actualizarEstadoEmit($event)"
(listarTurnosEmit)="listarTurnos($event)"
(listarCarpetasEmit)="listarCarpetas($event)"
(revisionAgendaEmit)="revisionAgenda($event)"
(reasignarTurnosEmit)="reasignarTurnos($event)"
(cargarPacientesEmit)="cargarPacientes()"
[turnosSuspendidos]="turnosSuspendidos">
</botones-agenda>
</plex-title>

<!--Filtros-->
Expand Down Expand Up @@ -166,7 +167,7 @@

<!-- Panel derecho -->
<div *ngIf="agendasSeleccionadas?.length > 0" class="h-100 col-4">
<plex-box>
<plex-box *ngIf="!enableQueries">
<div *ngIf="showTurnos && agendasSeleccionadas?.length == 1">
<turnos [agenda]="agendasSeleccionadas[0]" (reasignaTurno)="reasignaTurno($event)"
(recargarAgendas)="loadAgendas($event)"></turnos>
Expand All @@ -190,6 +191,12 @@
</suspender-agenda>
</div>
</plex-box>
<plex-box *ngIf="enableQueries">
<app-bi-queries type="inscriptos-vacunacion">
<plex-button size="sm" type="danger" (click)="cargarPacientes()">Cerrar</plex-button>
<plex-button size="sm" type="success" (click)="asignarPacientesPorConsulta()">Importar</plex-button>
</app-bi-queries>
</plex-box>
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class BotonesAgendaComponent implements OnInit {
@Output() agregarSobreturnoEmit = new EventEmitter<boolean>();
@Output() revisionAgendaEmit = new EventEmitter<boolean>();
@Output() reasignarTurnosEmit = new EventEmitter<boolean>();
@Output() cargarPacientesEmit = new EventEmitter<boolean>();


private _agendasSeleccionadas: Array<any>;
Expand Down Expand Up @@ -138,6 +139,7 @@ export class BotonesAgendaComponent implements OnInit {
const puedeBorrar = this.auth.getPermissions('turnos:agenda:puedeBorrar:').length > 0;
const puedeRevisar = this.auth.getPermissions('turnos:agenda:puedeRevision:').length > 0;
const puedeNota = this.auth.getPermissions('turnos:agenda:puedeNota:').length > 0;
const puedeCargar = this.auth.getPermissions('turnos:agenda:asignacionMasiva:').length > 0;;

this.vistaBotones = {
// Se puede editar sólo una agenda que esté en estado planificacion o disponible
Expand Down Expand Up @@ -170,6 +172,8 @@ export class BotonesAgendaComponent implements OnInit {
listarTurnos: (this.cantidadSeleccionadas > 0) && puedeImprimir,
// Imprimir pdf carpetas
listarCarpetas: this.cantidadSeleccionadas > 0 && puedeImprimir && this.puedoImprimirCarpetas(),
// Hablita carga de pacientes masivos
cargaMasiva: puedeCargar && this.puedeCargaMasiva()
};
}

Expand Down Expand Up @@ -256,6 +260,11 @@ export class BotonesAgendaComponent implements OnInit {
return !this.agendasSeleccionadas.some((agenda: any) => agenda.estado === 'pendienteAsistencia' || agenda.estado === 'pendienteAuditoria' || agenda.estado === 'auditada' || agenda.estado === 'pausada' || agenda.estado === 'suspendida');
}

puedeCargaMasiva() {
const agenda = this._agendasSeleccionadas[0];
return this.cantidadSeleccionadas === 1 && agenda.bloques[0].pacienteSimultaneos && agenda.estado === 'disponible' || agenda.estado === 'publicada';
}

// Verifica que las agendas seleccionadas tengan al menos un turno de acceso directo poder para publicar la agenda
haySoloTurnosReservados() {
let band = false;
Expand Down Expand Up @@ -346,4 +355,8 @@ export class BotonesAgendaComponent implements OnInit {
this.showBotonesAgenda = true;
}

cargarPacientes() {
this.cargarPacientesEmit.emit(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@
title="Imprimir carpetas">
</plex-button>
</span>
<span *ngIf="vistaBotones.cargaMasiva">
<plex-button icon="account-multiple-plus" type="success" title="Cargar Pacientes" (click)="cargarPacientes()">
</plex-button>
</span>
</div>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<plex-layout>
<plex-layout-main>
<plex-title titulo="Ejecutar consultas">
<plex-button size="sm" type="success" (click)="descargar()" [disabled]="form.invalid">
<plex-button *ngIf="!type" size="sm" type="success" (click)="descargar()" [disabled]="form.invalid">
Descargar CSV
</plex-button>
<ng-content></ng-content>
</plex-title>
<form #form="ngForm">
<plex-grid type="full" size="sm">
Expand Down Expand Up @@ -67,9 +68,9 @@
</ng-container>
</form>
<div justify="center" class="h-75">
<plex-label titulo="Comience seleccionando una consulta" direction="column"
<plex-label *ngIf="!type" titulo="Comience seleccionando una consulta" direction="column"
subtitulo="Complete los filtros requeridos y presione en el boton Descargar CSV para obtener su reporte "
type="default" size="xl" icon="arrow-up"></plex-label>
</div>
</plex-layout-main>
</plex-layout>
</plex-layout>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ZonaSanitariaService } from './../../../../services/zonaSanitaria.service';
import { Component, OnInit } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { QueriesService } from '../../../../services/query.service';
import { Observable } from 'rxjs';
import { ProfesionalService } from '../../../../services/profesional.service';
Expand All @@ -15,6 +15,7 @@ import { IZonaSanitaria } from 'src/app/interfaces/IZonaSanitaria';
styleUrls: ['./bi-queries.component.scss']
})
export class BiQueriesComponent implements OnInit {
@Input() type;

public consultaSeleccionada;
public opciones = [];
Expand Down Expand Up @@ -45,12 +46,20 @@ export class BiQueriesComponent implements OnInit {
if (this.permisosZonas.length > 0) {
this.loadZonasSanitarias();
}
let params;
if (permisos.length) {
if (permisos[0] === '*') {
this.queries$ = this.queryService.getAllQueries({ desdeAndes: true });
params = { desdeAndes: true };
} else {
this.queries$ = this.queryService.getAllQueries({ _id: permisos });
params = { _id: permisos };
}

if (this.type) {
params.type = this.type;
}

this.queries$ = this.queryService.getAllQueries(params);

} else {
this.router.navigate(['./inicio']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import { DescargasPendientesComponent } from './components/exportar-huds/descarg
@NgModule({
declarations: [
VisualizacionInformacionComponent,
BiQueriesComponent,
ExportarHudsComponent,
BiQueriesComponent,
DescargasPendientesComponent
],
exports: [DescargasPendientesComponent],
exports: [BiQueriesComponent, DescargasPendientesComponent],

imports: [
CommonModule,
Expand Down

0 comments on commit b57004d

Please sign in to comment.