-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUP - Filtrar recetas para renovar de receta
- Loading branch information
1 parent
e8b120c
commit 2d86def
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
src/app/modules/rup/components/elementos/renovacionRecetaMedica.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/app/modules/rup/components/elementos/renovacionRecetaMedica.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters