Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/app/apps/rup/mapa-camas/mapa-camas.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { IngresoPacienteService } from './sidebar/ingreso/ingreso-paciente-workf
import { PeriodosCensablesComponent } from './sidebar/periodos-censables/periodos-censables.component';
import { ListadoMedicamentosCapasComponent } from './views/listado-internacion-capas/listado-medicamentos-capas.component';
import { CITASLibModule } from '../../../components/turnos/citas.module';
import { InformeEstadisticaService } from 'src/app/modules/rup/services/informe-estadistica.service';

export const INTERNACION_COMPONENTS = [
MapaCamasMainComponent,
Expand Down Expand Up @@ -128,7 +129,8 @@ export const INTERNACION_PROVIDERS = [
IntegridadService,
PermisosMapaCamasService,
PlanIndicacionesEventosServices,
IngresoPacienteService
IngresoPacienteService,
InformeEstadisticaService
];

@NgModule({
Expand Down
11 changes: 9 additions & 2 deletions src/app/apps/rup/mapa-camas/services/mapa-camas.http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import { Injectable } from '@angular/core';
import { Server } from '@andes/shared';
import { Observable } from 'rxjs';
import { Observable, tap } from 'rxjs';
import { ISnapshot } from '../interfaces/ISnapshot';
import { ICama } from '../interfaces/ICama';

Expand Down Expand Up @@ -117,6 +118,12 @@ export class MapaCamasHTTP {
}

censoDiario(fecha: Date, unidadOrganizativa: string): Observable<any[]> {
console.log('🌐 [MapaCamasHTTP] Request a censo-diario →', {
url: `${this.url}/censo-diario`,
fecha,
unidadOrganizativa
});

return this.server.get(`${this.url}/censo-diario`, {
params: { fecha, unidadOrganizativa },
showError: true
Expand All @@ -135,6 +142,6 @@ export class MapaCamasHTTP {
}

getPrestacionesInternacion(params: any): Observable<any[]> {
return this.server.get(`${this.url}/prestaciones`, { params: params, showError: true });
return this.server.get(`${this.url}/informe-estadistica`, { params: params, showError: true });
}
}
123 changes: 112 additions & 11 deletions src/app/apps/rup/mapa-camas/services/mapa-camas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Auth } from '@andes/auth';
import { cache, notNull } from '@andes/shared';
import { Injectable } from '@angular/core';
import { BehaviorSubject, combineLatest, Observable, of, timer } from 'rxjs';
import { catchError, map, multicast, pluck, startWith, switchMap } from 'rxjs/operators';
import { catchError, map, multicast, pluck, startWith, switchMap, tap } from 'rxjs/operators';
import { IPaciente } from '../../../../core/mpi/interfaces/IPaciente';
import { PacienteService } from '../../../../core/mpi/services/paciente.service';
import { ISectores } from '../../../../interfaces/IOrganizacion';
Expand All @@ -18,6 +18,8 @@ import { MapaCamasHTTP } from './mapa-camas.http';
import { MaquinaEstadosHTTP } from './maquina-estados.http';
import { InternacionResumenHTTP, IResumenInternacion } from './resumen-internacion.http';
import { PermisosMapaCamasService } from '../services/permisos-mapa-camas.service';
import { InformeEstadisticaService } from 'src/app/modules/rup/services/informe-estadistica.service';
import { IInformeEstadistica } from 'src/app/modules/rup/interfaces/informe-estadistica.interface';
@Injectable()
export class MapaCamasService {
public timer$;
Expand Down Expand Up @@ -45,7 +47,11 @@ export class MapaCamasService {
public view = new BehaviorSubject<'mapa-camas' | 'listado-internacion' | 'mapa-recursos'>('mapa-camas');

public prestacion$: Observable<IPrestacion>;
public informeEstadistica$: Observable<IInformeEstadistica>;

public selectedPrestacion = new BehaviorSubject<IPrestacion>({ id: null } as any);
public selectedInformeEstadistica = new BehaviorSubject<IInformeEstadistica>({ id: null } as any);

public camaSelectedSegunView$: Observable<ISnapshot>;

public maquinaDeEstado$: Observable<IMaquinaEstados>;
Expand Down Expand Up @@ -80,6 +86,7 @@ export class MapaCamasService {
constructor(
private camasHTTP: MapaCamasHTTP,
private prestacionService: PrestacionesService,
private informeEstadisticaService: InformeEstadisticaService,
private pacienteService: PacienteService,
private maquinaEstadosHTTP: MaquinaEstadosHTTP,
private salaComunService: SalaComunService,
Expand Down Expand Up @@ -135,6 +142,11 @@ export class MapaCamasService {
snap.diaEstada = 0;
}
});
// 👉 Aquí detectamos los casos sin sectores
const sinSectores = snapshot.filter(s => !s.sectores || s.sectores.length === 0);
if (sinSectores.length > 0) {
console.warn('⚠️ Snapshots sin sectores:', sinSectores.map(s => s.id));
}
return snapshot.sort((a, b) => (a.unidadOrganizativa.term.localeCompare(b.unidadOrganizativa.term)) ||
(a.sectores[a.sectores.length - 1].nombre.localeCompare(b.sectores[b.sectores.length - 1].nombre + '')) ||
(a.nombre.localeCompare('' + b.nombre)));
Expand Down Expand Up @@ -188,7 +200,7 @@ export class MapaCamasService {
return of(null);
}
if (capa === 'estadistica') {
return this.prestacionService.getById(cama.idInternacion, { showError: false });
return of(null);
}
return this.internacionResumenHTTP.get(cama.idInternacion).pipe(
switchMap(internacionResumen => {
Expand All @@ -203,6 +215,7 @@ export class MapaCamasService {
cache()
);


this.resumenInternacion$ = combineLatest([
this.selectedCama,
this.ambito2,
Expand All @@ -223,6 +236,50 @@ export class MapaCamasService {
cache()
) as Observable<IResumenInternacion>;

this.informeEstadistica$ = combineLatest([
this.selectedInformeEstadistica,
this.selectedCama,
this.view,
this.capa2
]).pipe(
switchMap(([informe, cama, view, capa]) => {

if (view === 'listado-internacion') {
if (informe?.id) {
return of(informe);
}

const pacienteId = cama?.paciente?.id;
if (pacienteId) {
return this.informeEstadisticaService.get({ paciente: pacienteId }).pipe(
map(informes => informes?.[0] || null)
);
}

return of(null);
}

if (!cama?.idInternacion) {
return of(null);
}

if (capa === 'estadistica') {
const id = informe?.id || cama?.idInternacion;
if (!id) {
console.warn('⚠️ No hay ID válido para obtener el informe estadístico');
return of(null);
}
return this.informeEstadisticaService.getById(id, { showError: false });
}

return of(null);
}),
catchError(err => {
return of(null);
}),
cache()
);


this.camaSelectedSegunView$ = this.view.pipe(
switchMap(view => {
Expand All @@ -231,7 +288,7 @@ export class MapaCamasService {
}
// Para conseguir la cama de la internación desde el listado
return combineLatest([
this.selectedPrestacion,
this.selectedInformeEstadistica,
this.selectedResumen
]).pipe(
switchMap(([prestacion, resumen]) => {
Expand Down Expand Up @@ -379,6 +436,16 @@ export class MapaCamasService {
this.selectedPrestacion.next(prestacion);
}

selectInformeEstadistica(informe: IInformeEstadistica) {
if (!informe) {
return this.selectedInformeEstadistica.next({ id: null } as any);
}

this.selectedInformeEstadistica.next(informe);

}


selectResumen(resumen: IResumenInternacion) {
if (!resumen) {
return this.selectedResumen.next({ id: null } as any);
Expand All @@ -396,8 +463,8 @@ export class MapaCamasService {
camasFiltradas = camasFiltradas.filter((snap: ISnapshot) =>
snap.paciente.documento.includes(paciente) || snap.paciente.numeroIdentificacion?.includes(paciente));
} else {
camasFiltradas = camasFiltradas.filter((snap: ISnapshot) =>
(snap.paciente.nombre.toLowerCase().includes(paciente.toLowerCase()) ||
camasFiltradas = camasFiltradas.filter((snap: ISnapshot) => (
snap.paciente.nombre.toLowerCase().includes(paciente.toLowerCase()) ||
snap.paciente.alias?.toLowerCase().includes(paciente.toLowerCase()) ||
snap.paciente.apellido.toLowerCase().includes(paciente.toLowerCase()))
);
Expand Down Expand Up @@ -526,6 +593,38 @@ export class MapaCamasService {
return listaInternacionFiltrada;
}

filtrarInformesEstadistica(
listaInformes: IInformeEstadistica[],
documento?: string,
apellido?: string,
estado?: string
): IInformeEstadistica[] {
let listaFiltrada = listaInformes;

if (documento) {
const doc = documento.toLowerCase();
listaFiltrada = listaFiltrada.filter((informe: IInformeEstadistica) =>
informe.paciente?.documento?.toLowerCase().includes(doc) ||
informe.paciente?.numeroIdentificacion?.toLowerCase().includes(doc)
);
}

if (apellido) {
const ape = apellido.toLowerCase();
listaFiltrada = listaFiltrada.filter((informe: IInformeEstadistica) =>
informe.paciente?.apellido?.toLowerCase().includes(ape)
);
}

if (estado) {
listaFiltrada = listaFiltrada.filter((informe: IInformeEstadistica) =>
informe.estadoActual?.tipo === estado
);
}

return listaFiltrada;
}

snapshot(fecha, idInternacion = null, ambito: string = null, capa: string = null, estado: string = null): Observable<ISnapshot[]> {
ambito = ambito || this.ambito;
capa = capa || this.capa;
Expand All @@ -541,11 +640,11 @@ export class MapaCamasService {
this.ambito2,
this.capa2,
this.selectedCama,
this.selectedPrestacion,
this.selectedInformeEstadistica,
this.selectedResumen,
this.view
]).pipe(
switchMap(([ambito, capa, selectedCama, selectedPrestacion, selectedResumen, view]) => {
switchMap(([ambito, capa, selectedCama, selectedInformeEstadistica, selectedResumen, view]) => {
hasta = hasta || new Date();
if (type === 'cama') {
return this.camasHTTP.historial(ambito, capa, desde, hasta, { idCama: cama ? cama.idCama : selectedCama.idCama });
Expand All @@ -556,11 +655,13 @@ export class MapaCamasService {

} else if (view === 'listado-internacion') {
if (!desde) {
desde = selectedPrestacion ? selectedPrestacion.solicitud.fecha : selectedResumen.fechaIngreso;
desde = selectedInformeEstadistica ? selectedInformeEstadistica.informeIngreso.fechaIngreso : selectedResumen.fechaIngreso;

}
if (this.capa === 'estadistica' && selectedPrestacion.id) {
desde = [desde, selectedPrestacion.solicitud.fecha].sort((a, b) => moment(a).diff(moment(b)))[0];
return this.camasHTTP.historialInternacion(ambito, capa, desde, hasta, selectedPrestacion.id);
if (this.capa === 'estadistica' && selectedInformeEstadistica.id) {
desde = [desde, selectedInformeEstadistica.informeIngreso.fechaIngreso].sort((a, b) => moment(a).diff(moment(b)))[0];

return this.camasHTTP.historialInternacion(ambito, capa, desde, hasta, selectedInformeEstadistica.id);
}
if (selectedResumen._id) {
desde = [desde, selectedResumen.fechaIngreso].sort((a, b) => moment(a).diff(moment(b)))[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { PermisosMapaCamasService } from '../../services/permisos-mapa-camas.ser
import { InternacionResumenHTTP } from '../../services/resumen-internacion.http';
import { OrganizacionService } from 'src/app/services/organizacion.service';
import { Auth } from '@andes/auth';


import { IInformeEstadistica } from 'src/app/modules/rup/interfaces/informe-estadistica.interface';
import { InformeEstadisticaService } from 'src/app/modules/rup/services/informe-estadistica.service';
@Component({
selector: 'app-cama-detalle',
templateUrl: 'cama-detalle.component.html'
Expand Down Expand Up @@ -69,6 +69,7 @@ export class CamaDetalleComponent implements OnInit, AfterViewChecked, OnDestroy
public unicoMovimiento = false;
public subscripcion: Subscription;
public prestacion;
public InformeEstadistica;

items = [
{
Expand All @@ -93,6 +94,7 @@ export class CamaDetalleComponent implements OnInit, AfterViewChecked, OnDestroy
private mapaCamasService: MapaCamasService,
private mapaCamasHTTP: MapaCamasHTTP,
private prestacionesService: PrestacionesService,
public InformeEstadisticaService: InformeEstadisticaService,
public permisosMapaCamasService: PermisosMapaCamasService,
private turneroService: TurneroService,
private motivoAccesoService: ModalMotivoAccesoHudsService,
Expand All @@ -115,8 +117,7 @@ export class CamaDetalleComponent implements OnInit, AfterViewChecked, OnDestroy
this.relaciones$ = this.cama$.pipe(switchMap(cama => this.mapaCamasService.getRelacionesPosibles(cama)));
this.accionesEstado$ = this.mapaCamasService.prestacionesPermitidas(this.mapaCamasService.selectedCama);
this.organizacionV2$ = this.organizacionService.usaCapasUnificadas(this.auth.organizacion.id);
this.subscripcion = this.mapaCamasService.prestacion$.subscribe(p => this.prestacion = p);

this.subscripcion = this.mapaCamasService.informeEstadistica$.subscribe(p => this.InformeEstadistica = p);
this.paciente$ = this.cama$.pipe(
filter(cama => !!cama.paciente),
switchMap(cama => cama.paciente ? this.mapaCamasService.getPaciente(cama.paciente) : of(null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<!-- ESTADISTICA -->
<ng-container *ngIf="capa === 'estadistica'">
<app-informe-ingreso (cancel)="activateOption('ingreso')">
<plex-button *ngIf="permisosMapaCamasService.ingreso" tooltip="Editar ingreso"
tooltipPosition="left" icon="pencil" type="warning" size="sm" (click)="toggleEdit()"
class="mr-1">
<plex-button *ngIf="permisosMapaCamasService.ingreso && estadoPrestacion !== 'validada'"
tooltip="Editar ingreso" tooltipPosition="left" icon="pencil" type="warning" size="sm"
(click)="toggleEdit()" class="mr-1">
</plex-button>
<ng-container *ngIf="anular$ | async">
<ng-container *ngIf="(anular$ | async) && estadoPrestacion !== 'validada'">
<plex-button size="sm" icon="account-off" type="danger" tooltip="Deshacer Internación"
tooltipPosition="left" (click)="onAnularInternacion()">
</plex-button>
Expand Down Expand Up @@ -52,7 +52,7 @@
<ng-container *ngIf="mostrar === 'egreso'">
<!-- informe (Debe tener un egreso cargado) -->
<app-informe-egreso *ngIf="!editarEgreso && existeEgreso" (cancel)="activateOption('egreso')">
<plex-button *ngIf="puedeEditarEgreso()" tooltip="Editar egreso" tooltipPosition="left" icon="pencil"
<plex-button *ngIf="puedeEditarEgreso()" tooltip="fdsfsd" tooltipPosition="left" icon="pencil"
type="warning" size="sm" (click)="toggleEdit()">
</plex-button>
</app-informe-egreso>
Expand Down
Loading