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
11 changes: 11 additions & 0 deletions projects/auth/src/lib/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ export class Auth {
return this.shiro.permissions(string);
}

hasExactPermission(perm: string): boolean {
const parts = perm.split(':');
const last = parts.pop();

const query = [...parts, '?'].join(':');
const perms = this.shiro.permissions(query);

return perms.includes(last);

}

loggedIn() {
return this.estado === Estado.active;
}
Expand Down
81 changes: 81 additions & 0 deletions src/app/components/top/solicitudes/detallePedido.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Input, Component, ChangeDetectorRef, OnDestroy, ViewChild } from '@angular/core';
import { Subject } from 'rxjs';
import { filter, take, takeUntil } from 'rxjs/operators';
import { RUPComponent } from 'src/app/modules/rup/components/core/rup.component';
import { ElementosRUPService } from 'src/app/modules/rup/services/elementosRUP.service';

@Component({
selector: 'detalle-pedido',
templateUrl: './detallePedido.html'
})

export class DetallePedidoComponent implements OnDestroy {
@ViewChild('prescripcion') prescripcion: RUPComponent;
turno;
prestacion;
itemsHistorial = [];
registroPrincipal = null;
elementoRUPPrincipal = null;
mostrarRup = true;
private destroy$ = new Subject<void>();

@Input('prestacion')
set _prestacion(value) {
this.prestacion = value;
this.cargarDetalle();
}

constructor(
private elementosRUPService: ElementosRUPService,
private cd: ChangeDetectorRef
) { }


cargarDetalle() {
if (!this.prestacion) {
// Si no hay prestacion, ocultamos <rup> para que no quede el anterior montado
this.mostrarRup = false;
this.elementoRUPPrincipal = null;
this.registroPrincipal = null;
this.cd.detectChanges();
return;
}

// Forzamos desmontaje temporal del <rup> para evitar que quede la instancia anterior
this.mostrarRup = false;
this.elementoRUPPrincipal = null;
this.registroPrincipal = null;
this.cd.detectChanges();

// Esperar a que el servicio esté listo y luego usarlo (una sola vez)
this.elementosRUPService.ready.pipe(
filter(v => !!v),
take(1),
takeUntil(this.destroy$)
).subscribe({
next: () => {
this.registroPrincipal = this.prestacion.solicitud?.registros?.[0] || null;
if (!this.registroPrincipal) {
console.warn('DetallePedido: no hay registroPrincipal en la prestacion', this.prestacion);
this.elementoRUPPrincipal = null;
// restaurar flag (no mostrar)
this.mostrarRup = false;
this.cd.detectChanges();
return;
}
this.elementoRUPPrincipal = this.elementosRUPService.buscarElemento(this.registroPrincipal.concepto, true);
// Restauramos flag para volver a montar <rup> con los nuevos inputs
this.mostrarRup = true;
// Forzar detección para que Angular renderice el <rup>
this.cd.detectChanges();

}
});

}

ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
9 changes: 9 additions & 0 deletions src/app/components/top/solicitudes/detallePedido.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="content">
<div class="row" *ngIf="prestacion && elementoRUPPrincipal && registroPrincipal">
<div class="col-12">
<rup #prescripcion [elementoRUP]="elementoRUPPrincipal" [registro]="registroPrincipal"
[prestacion]="prestacion" [paciente]="prestacion.paciente" [soloValores]="true" [vistaHUDS]="false">
</rup>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Input, Component, SimpleChanges, OnChanges, OnDestroy, Output, EventEmitter } from '@angular/core';
import { AdjuntosService } from '../../../modules/rup/services/adjuntos.service';
import { PacienteService } from 'src/app/core/mpi/services/paciente.service';
import { Auth } from '@andes/auth';

@Component({
selector: 'detalle-solicitud',
Expand All @@ -20,24 +21,23 @@ export class DetalleSolicitudComponent implements OnChanges, OnDestroy {

public internacion = null;
public organizacionInternacion;
public permisoDetalle = false;

public items = [];

public items = [
{ key: 'solicitud', label: 'SOLICITUD' },
{ key: 'historial', label: 'HISTORIAL' },
{ key: 'turnos', label: 'TURNOS' }
];
public mostrar = 'solicitud';
public verIndicaciones = false;

constructor(
public adjuntosService: AdjuntosService,
private pacienteService: PacienteService
private pacienteService: PacienteService,
private auth: Auth
) { }

fotos: any[] = [];

ngOnChanges(changes: SimpleChanges) {
if (changes.prestacionSeleccionada) {
this.permisoDetalle = this.auth.hasExactPermission('solicitudes:verDetalles');
this.adjuntosService.token$.subscribe((payload) => {
const { token } = payload;
const solicitudRegistros = this.prestacionSeleccionada.solicitud.registros;
Expand All @@ -58,9 +58,27 @@ export class DetalleSolicitudComponent implements OnChanges, OnDestroy {
this.internacionPaciente.emit(this.internacion);
});
}
this.buildItems();
}
}

private buildItems() {
const base = [
{ key: 'solicitud', label: 'SOLICITUD' },
{ key: 'historial', label: 'HISTORIAL' },
{ key: 'turnos', label: 'TURNOS' }
];

// Ejemplo de condición: agregar 'turnos' solo si se cumple permisoDetalle
// o si el tipo de solicitud es un valor específico. Ajusta aquí.
if (this.permisoDetalle) {
base.splice(1, 0, { key: 'pedido', label: 'PEDIDO' });
}

this.items = base;
}


cambiarOpcion(opcion) {
this.mostrar = opcion;
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/components/top/solicitudes/detalleSolicitud.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<plex-options [items]="items" (activated)="cambiarOpcion($event)"></plex-options>
<div *ngIf="mostrar === 'solicitud'" class="mt-3">
<div *ngIf="mostrar === 'solicitud'" class="mt-4">
<paciente-detalle [paciente]="prestacionSeleccionada.paciente" reload="true" orientacion="horizontal">
</paciente-detalle>
<plex-title size="sm" titulo="Solicitud">
Expand Down Expand Up @@ -106,11 +106,15 @@
<shared-galeria-archivos [files]="fotos" [readonly]="true"></shared-galeria-archivos>
</div>
</div>
<div *ngIf="mostrar === 'historial'" class="mt-3">
<div *ngIf="permisoDetalle && mostrar === 'pedido'" class="mt-4">
<detalle-pedido [prestacion]="prestacionSeleccionada" [turno]='turnoSeleccionado'>
</detalle-pedido>
</div>
<div *ngIf="mostrar === 'historial'" class="mt-4">
<historial-solicitud [prestacion]="prestacionSeleccionada" [turno]='turnoSeleccionado'>
</historial-solicitud>
</div>
<div *ngIf="mostrar === 'turnos'" class="mt-3">
<div *ngIf="mostrar === 'turnos'" class="mt-4">
<turnos-solicitud [prestacionSeleccionada]="prestacionSeleccionada" [turnoSeleccionado]="turnoSeleccionado">
</turnos-solicitud>
</div>
12 changes: 9 additions & 3 deletions src/app/components/top/top.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import { TurnosSolicitudComponent } from './solicitudes/turnosSolicitud.componen
import { VisualizacionReglasTopComponent } from './reglas/visualizacionReglasTop.component';
import { RouterService } from 'src/app/services/router.service';
import { MotivosHudsService } from 'src/app/services/motivosHuds.service';
import { DetallePedidoComponent } from './solicitudes/detallePedido.component';
import { ElementosRUPModule } from 'src/app/modules/rup/elementos-rup.module';

export const TOP_COMPONENTS = [
VisualizacionReglasTopComponent,
VisualizacionReglasComponent,
HistorialSolicitudComponent,
FormNuevaSolicitudComponent,
TurnosSolicitudComponent
TurnosSolicitudComponent,
DetallePedidoComponent
];

export const TOP_PROVIDERS = [
Expand All @@ -35,21 +38,24 @@ export const TOP_PROVIDERS = [
RouterModule,
HttpClientModule,
SharedModule,
DirectiveLibModule
DirectiveLibModule,
ElementosRUPModule
],
declarations: [
...TOP_COMPONENTS
],
providers: [
MotivosHudsService,

...TOP_PROVIDERS
],
exports: [
VisualizacionReglasTopComponent,
VisualizacionReglasComponent,
HistorialSolicitudComponent,
FormNuevaSolicitudComponent,
TurnosSolicitudComponent
TurnosSolicitudComponent,
DetallePedidoComponent
],
})
export class TOPLibModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class MoleculaBaseComponent extends RUPComponent implements OnInit {
];
public consultaTrastornoOriginal: any;
public evoluciones;
public organizaciones: any[] = [];
public reglasMatch = [];
public reglaSelected = null;

ngOnInit() {
if (this.registro.concepto.semanticTag === 'trastorno') {
Expand Down Expand Up @@ -67,6 +70,56 @@ export class MoleculaBaseComponent extends RUPComponent implements OnInit {
this.contentLoaded = true;
}
this.createRules();

if (this.elementoRUP.esSolicitud) {

if (!this.registro.valor) {
this.registro.valor = {
solicitudPrestacion: {}
};
this.registro.valor.solicitudPrestacion['autocitado'] = false;
this.registro.valor.solicitudPrestacion['prestacionSolicitada'] = this.registro.concepto;
}

this.servicioReglas.get({
organizacionOrigen: this.auth.organizacion.id,
prestacionOrigen: this.prestacion?.solicitud?.tipoPrestacion.conceptId,
prestacionDestino: this.registro.concepto?.conceptId
}).subscribe(reglas => {
this.reglasMatch = reglas;
this.organizaciones = reglas.map(elem => {
return {
id: elem.destino.organizacion.id,
nombre: elem.destino.organizacion.nombre
};
});

if (this.organizaciones.length === 1) {
this.registro.valor.solicitudPrestacion.organizacionDestino = this.organizaciones[0];
this.onOrganizacionChange();
}
});
}
}

onOrganizacionChange() {
const org = this.registro.valor.solicitudPrestacion.organizacionDestino;
if (org) {
this.reglaSelected = this.reglasMatch.find(r => r.destino.organizacion.id === org.id);

if (this.reglaSelected) {
this.reglaSelected.destino.informe = this.reglaSelected.destino.informe || 'none';

if (this.reglaSelected.destino.informe === 'required') {
this.registro.valor.solicitudPrestacion.informe = true;
}

this.registro.valor.solicitudPrestacion.reglaID = this.reglaSelected.id;
if (this.reglaSelected.destino.formulario) {
this.registro.valor.template = this.reglaSelected.destino.formulario;
}
}
}
}

onChange(value) {
Expand Down
23 changes: 23 additions & 0 deletions src/app/modules/rup/components/elementos/moleculaBase.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,27 @@
</ng-container>
</div>
</ng-container>
<ng-container *ngIf="elementoRUP.esSolicitud">
<div class="row">
<div class="col-md">
<hr />
</div>
</div>
<div class="row">
<div class="col-md">
<plex-select *ngIf="organizaciones.length"
[(ngModel)]="registro.valor.solicitudPrestacion.organizacionDestino"
name="organizacionDestino" [data]="organizaciones" label="Organización destino"
placeholder="Seleccione la organización" labelField="nombre" [required]="true"
(change)="onOrganizacionChange()">
</plex-select>
</div>
</div>
<div class="row" *ngIf="!soloValores && !organizaciones.length">
<div class="col-md">
<plex-label titulo="Esta solicitud NO se regitrará en ninguna bandeja de entrada y no podrá ser resuelta desde el módulo de solicitudes"
subtitulo="" type="warning" size="md" icon="alert"></plex-label>
</div>
</div>
</ng-container>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ export class SelectBaseComponent extends RUPComponent implements OnInit, AfterVi
this.params = {};
}
if (this.registro && this.registro.valor) {

const value = this.registro.valor;

if (!value || (Array.isArray(value) && value.length === 0)) {
this.otherEnabled = true;
this.otherText = 'S/D';
}

if (Array.isArray(value)) {
this.itemSelected = value;
} else {
Expand Down
12 changes: 9 additions & 3 deletions src/app/modules/rup/components/elementos/ultimaFecha.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
<plex-datetime *ngIf="!soloValores" [(ngModel)]="registro.valor" [label]="params.title ? params.title : registro.concepto.term" name="DateFormat" [type]="params.type ? params.type : 'date'"
placeholder="DD/MM/AAAA" (change)="onChange()" [required]="params.required ? params.required : false" [min]="min" [max]="max">
</plex-datetime>
<p *ngIf="soloValores && registro.valor" class="readonly">
<span>{{registro.concepto.term}}</span> {{DateFormat}}
</p>
<ng-template *ngIf="soloValores && registro.valor">
<div *ngIf="params?.title; else showTerm">
<label class="text-capitalize">{{ params.title }}</label>
</div>
<ng-template #showTerm>
<label class="text-capitalize">{{ registro.concepto.term }}</label>
</ng-template>
{{DateFormat}}
</ng-template>
<p *ngIf="soloValores && !registro.valor" class="readonly">
<span>{{registro.concepto.term}}</span> sin valor
</p>
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/rup/interfaces/elementoRUP.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ export interface IElementoRUPRequeridos {
};
// Indica parámetros para la instancia del elementoRUP en formato {key: value}
params: { [key: string]: any };
esSolicitud?: boolean;
sexo: string;
}
1 change: 1 addition & 0 deletions src/app/modules/rup/services/elementosRUP.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class ElementosRUPService {
}
elemento.requeridos.forEach((elem) => {
if (!elem.elementoRUP) {
esSolicitud = elem.esSolicitud ?? esSolicitud;
elem.elementoRUP = this.buscarElemento(elem.concepto, esSolicitud);
elem.params = { ...elem.elementoRUP.params, ...(elem.params || {}) };
elem.style = { ...(elem.elementoRUP.style || {}), ...(elem.style || {}) } as any;
Expand Down
Loading