Skip to content

Commit

Permalink
RUP - Filtrar recetas para renovar de receta
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio-Ramirez committed Feb 18, 2025
1 parent e8b120c commit 2d86def
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Component, Output, Input, EventEmitter, OnInit, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
import { RUPComponent } from '../core/rup.component';
import { RupElement } from '.';
import { Observable } from 'rxjs';
import { NgForm } from '@angular/forms';
@Component({
selector: 'rup-renovacionRecetaMedica',
templateUrl: 'renovacionRecetaMedica.html'
})


@RupElement('RenovacionRecetaMedicaComponent')
export class RenovacionRecetaMedicaComponent extends RUPComponent implements OnInit {

@ViewChild('formMedicamento') formMedicamento: NgForm;
intervalos$: Observable<any>;


public recetasFiltradas = [];
public medicamentoCargados = [];
public medicamentoSeleccionado: any = {
id: null,
nombre: null
};

ngOnInit() {

if (!this.registro.valor) {
this.registro.valor = {};
}
if (!this.registro.valor.medicamentos) {
this.registro.valor.medicamentos = [];
}
this.intervalos$ = this.constantesService.search({ source: 'plan-indicaciones:frecuencia' });
this.buscarHistorialReceta();
}

buscarHistorialReceta() {
this.prestacionesService.getByPaciente(this.paciente.id).subscribe(arrayPrestaciones => {

const fechaLimite = moment().subtract(6, 'months');
this.recetasFiltradas = arrayPrestaciones
.filter(prestacion => {
const fechaCreacion = moment(prestacion.createdAt);
return fechaCreacion.isAfter(fechaLimite) &&
prestacion.ejecucion?.registros?.some(registro =>
registro.concepto?.conceptId === '16076005'
);
})
.map(prestacion =>
(prestacion.ejecucion?.registros || []).map(registro => ({
medicamentos: registro.valor?.medicamentos || [],
fecha: moment(prestacion.createdAt)
}))
)
.reduce((acumulador, registros) => acumulador.concat(registros), [])
.reduce((acumulador, item) => acumulador.concat(
item.medicamentos.map(med => ({ ...med, fecha: item.fecha }))
), []);

// Mapa para almacenar el medicamento con la fecha más reciente
const medicamentosUnicos = new Map<string, any>();

this.recetasFiltradas.forEach(medicamento => {
const id = medicamento.generico?.conceptId;
if (id) {
if (!medicamentosUnicos.has(id) || medicamentosUnicos.get(id).fecha.isBefore(medicamento.fecha)) {
medicamentosUnicos.set(id, medicamento);
}
}
});
this.medicamentoCargados = Array.from(medicamentosUnicos.values()).map(medicamento => ({
id: medicamento.generico?.conceptId,
nombre: medicamento.generico?.term || 'Desconocido'
}));

});
}

agregarMedicamento() {
const index = this.medicamentoCargados.findIndex(med =>
med.id === this.medicamentoSeleccionado.id
);
if (index !== -1) {
const medSeleccionado = this.recetasFiltradas[index];
this.medicamentoCargados.splice(index, 1);
this.recetasFiltradas.splice(index, 1);
this.registro.valor.medicamentos.push(medSeleccionado);
this.medicamentoCargados = [...this.medicamentoCargados];

this.medicamentoSeleccionado = {
id: null,
nombre: null
};
}
}

borrarMedicamento(medicamento) {
this.plex.confirm('¿Está seguro que desea eliminar el medicamento de la receta?').then((resultado) => {
if (resultado) {
const index = this.registro.valor.medicamentos.indexOf(medicamento);

if (index !== -1) {
const medicamentoEliminar = this.registro.valor.medicamentos[index];
this.registro.valor.medicamentos.splice(index, 1);
this.recetasFiltradas.push(medicamentoEliminar);
this.medicamentoCargados.push({
id: medicamentoEliminar.generico.conceptId,
nombre: medicamentoEliminar.generico.term
});

this.medicamentoCargados = [...this.medicamentoCargados];
}
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ng-container *ngIf="!soloValores">
<form class="mt-1" #formMedicamento="ngForm">
<plex-select [(ngModel)]="medicamentoSeleccionado" name="term" [data]="medicamentoCargados"
placeholder="Seleccione medicamento" label="Medicamento" required="true">
</plex-select>
<div class="mt-4 d-flex justify-content-end">
<plex-button name="botonAgregar" type="info"
[disabled]="!formMedicamento.valid || medicamentoCargados?.length < 1"
(click)="agregarMedicamento($event)" [validateForm]="formMedicamento">
Agregar
</plex-button>
</div>
</form>
<plex-list size="md" *ngIf="registro.valor.medicamentos" class="mt-3">
<plex-item *ngFor="let item of registro.valor.medicamentos">
<plex-icon size="md" *ngIf="true" name="pildoras" class="icon icon--border--producto mr-2">
</plex-icon>
<plex-label [tituloBold]="true" titulo="{{ item.generico.term }}" subtitulo=" {{ item.cantEnvases}} envase(s) de {{ item.cantidad}} {{item.presentacion.term }}(s) {{ item.dosisDiaria.dosis? '| ' + item.dosisDiaria.dosis : '| ' }} {{ item.dosisDiaria.intervalo? ' cada ' + item.dosisDiaria.intervalo.nombre: '' }} {{ item.dosisDiaria.dias? ' durante ' + item.dosisDiaria.dias + ' día(s)':'' }}
"></plex-label>
<plex-button type="danger" size="sm" (click)="borrarMedicamento(item)" icon="delete"></plex-button>
</plex-item>
</plex-list>
</ng-container>
2 changes: 2 additions & 0 deletions src/app/modules/rup/elementos-rup.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { OdontogramaRefsetComponent } from './components/elementos/OdontogramaRe
import { PesoComponent } from './components/elementos/peso.component';
import { ProcedimientoDeEnfermeriaComponent } from './components/elementos/procedimientoDeEnfermeria.component';
import { RecetaMedicaComponent } from './components/elementos/recetaMedica.component';
import { RenovacionRecetaMedicaComponent } from './components/elementos/renovacionRecetaMedica.component';
import { RegistrarMedicamentoDefaultComponent } from './components/elementos/registrarMedicamentoDefault.component';
import { ResumenHistoriaClinicaComponent } from './components/elementos/resumenHistoriaClinica.component';
import { ChecklistComponent } from './components/elementos/rupers/check-list/checklist.component';
Expand Down Expand Up @@ -88,6 +89,7 @@ const RUPComponentsArray = [
ObservacionesComponent,
PesoComponent,
RecetaMedicaComponent,
RenovacionRecetaMedicaComponent,
RegistrarMedicamentoDefaultComponent,
SaturacionOxigenoComponent,
GraficoLinealComponent,
Expand Down

0 comments on commit 2d86def

Please sign in to comment.