diff --git a/src/app/conceptos-turneables/components/conceptos-turneables.component.ts b/src/app/conceptos-turneables/components/conceptos-turneables.component.ts index 302ab71..2a6268a 100644 --- a/src/app/conceptos-turneables/components/conceptos-turneables.component.ts +++ b/src/app/conceptos-turneables/components/conceptos-turneables.component.ts @@ -1,10 +1,9 @@ -import { Component, Input, OnInit, OnDestroy } from '@angular/core'; +import { Auth } from '@andes/auth'; import { Plex } from '@andes/plex'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; import { IConceptoTurneable } from '../Interfaces/IConceptoTurneable'; import { ConceptoTruneableService } from '../services/concepto-turneable.service'; -import { Auth } from '@andes/auth'; -import { Router } from '@angular/router'; - @Component({ selector: 'app-conceptos-turneables', @@ -54,7 +53,7 @@ export class ConceptosTurneablesComponent implements OnInit, OnDestroy { this.timeoutHandle = null; this.conceptoTurneableService.get({ conceptId: this.conceptID, - term: '^' + this.term, + term: conceptID && !term ? this.term : '^' + this.term, }).subscribe( resultado => { this.loading = false; @@ -119,29 +118,4 @@ export class ConceptosTurneablesComponent implements OnInit, OnDestroy { this.buscar(); }); } - - onEliminarConceptoTurneable(conceptoTurneable) { - if (this.conceptoSeleccionado && this.conceptoSeleccionado.id) { - this.plex.confirm('Eliminar concepto turneable "' + conceptoTurneable.term + '"', '¿Desea eliminar?').then(confirmacion => { - if (confirmacion) { - this.conceptoTurneableService.delete(conceptoTurneable).subscribe(resultado => { - this.plex.info('info', 'El Concepto Turneable fue eliminado'); - this.conceptoSeleccionado = null; - let i = 0; - let index; - this.conceptosTurneables.forEach(concepto => { - if (concepto.id === conceptoTurneable.id) { - index = i; - } - i++; - }); - - this.conceptosTurneables.splice(index, 1); - }); - } - }); - } else { - this.plex.info('danger', 'No es posible dar de baja este Concepto Turneable'); - } - } } diff --git a/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.html b/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.html index 62555d0..b365e0c 100644 --- a/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.html +++ b/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.html @@ -97,7 +97,7 @@ + (click)="seleccionarConcepto(concepto)"> {{concepto.term}} diff --git a/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.ts b/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.ts index c84a39f..b8c1fb2 100644 --- a/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.ts +++ b/src/app/conceptos-turneables/components/nuevo-concepto-turneable.component.ts @@ -1,14 +1,18 @@ -import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core'; import { Plex } from '@andes/plex'; -import { SnomedService } from 'src/app/shared/snomed.service'; +import { PlexModalComponent } from '@andes/plex/src/lib/modal/modal.component'; +import { Component, EventEmitter, Output, ViewChild } from '@angular/core'; +import { Subject } from 'rxjs'; import { ISnomedConcept } from 'src/app/shared/ISnomedConcept'; +import { SnomedService } from 'src/app/shared/snomed.service'; import { IConceptoTurneable } from '../Interfaces/IConceptoTurneable'; +import { ConceptoTruneableService } from '../services/concepto-turneable.service'; @Component({ selector: 'app-concepto-turneable-nuevo', templateUrl: './nuevo-concepto-turneable.component.html', }) -export class NuevoConceptoTurneableComponent implements OnInit { +export class NuevoConceptoTurneableComponent { + @ViewChild('modal', { static: true }) modal: PlexModalComponent; @Output() agregarConceptoTurneable = new EventEmitter(); @Output() cancelarAgregarConceptoTurneable = new EventEmitter(); @@ -33,11 +37,25 @@ export class NuevoConceptoTurneableComponent implements OnInit { constructor( public plex: Plex, private snomedService: SnomedService, + private conceptoTurneableService: ConceptoTruneableService, ) { } - ngOnInit() { + mostrarMensaje() { + this.plex.info('warning', 'Ya existe un concepto turneable para el conceptId seleccionado. Para mayor información comunicarse con soporteandes@neuquen.gov.ar.', 'Información'); + } + + buscarConcepto(concepto: IConceptoTurneable) { + const existe = new Subject(); + + this.conceptoTurneableService.get({ + conceptId: concepto.conceptId + }).subscribe( + resultado => existe.next(resultado.length > 0), + () => existe.next(true) + ); + return existe.asObservable(); } buscar() { @@ -58,6 +76,7 @@ export class NuevoConceptoTurneableComponent implements OnInit { search: this.term, semanticTag: ['procedimiento'] }; + this.snomedService.get(query).subscribe((resultado: ISnomedConcept[]) => { this.loading = false; this.conceptosSnomed = resultado; @@ -68,16 +87,20 @@ export class NuevoConceptoTurneableComponent implements OnInit { } } - onRowClick(concepto: IConceptoTurneable) { - if (!this.conceptoSnomedSeleccionado || this.conceptoSnomedSeleccionado.id !== concepto.id) { - this.conceptoSnomedSeleccionado = concepto; - this.nuevoConceptoTurneable.conceptId = this.conceptoSnomedSeleccionado.conceptId; - this.nuevoConceptoTurneable.term = this.conceptoSnomedSeleccionado.term; - this.nuevoConceptoTurneable.fsn = this.conceptoSnomedSeleccionado.fsn; - this.nuevoConceptoTurneable.semanticTag = this.conceptoSnomedSeleccionado.semanticTag; - } else { - this.conceptoSnomedSeleccionado = null; - } + seleccionarConcepto(concepto: IConceptoTurneable) { + this.buscarConcepto(concepto).subscribe(existe => { + if (existe) { this.mostrarMensaje(); } else { + if (!this.conceptoSnomedSeleccionado || this.conceptoSnomedSeleccionado.id !== concepto.id) { + this.conceptoSnomedSeleccionado = concepto; + this.nuevoConceptoTurneable.conceptId = this.conceptoSnomedSeleccionado.conceptId; + this.nuevoConceptoTurneable.term = this.conceptoSnomedSeleccionado.term; + this.nuevoConceptoTurneable.fsn = this.conceptoSnomedSeleccionado.fsn; + this.nuevoConceptoTurneable.semanticTag = this.conceptoSnomedSeleccionado.semanticTag; + } else { + this.conceptoSnomedSeleccionado = null; + } + } + }); } agregar() { @@ -89,6 +112,4 @@ export class NuevoConceptoTurneableComponent implements OnInit { cancelarAgregar() { this.cancelarAgregarConceptoTurneable.emit(); } - - } diff --git a/src/app/conceptos-turneables/services/concepto-turneable.service.ts b/src/app/conceptos-turneables/services/concepto-turneable.service.ts index 5e582d3..748be12 100644 --- a/src/app/conceptos-turneables/services/concepto-turneable.service.ts +++ b/src/app/conceptos-turneables/services/concepto-turneable.service.ts @@ -28,8 +28,4 @@ export class ConceptoTruneableService { patch(id: string, cambios: any, options: any = {}): Observable { return this.server.patch(`${this.conceptoTurneableUrl}/${id}`, cambios); } - - delete(conceptoTurneable: IConceptoTurneable): Observable { - return this.server.delete(`${this.conceptoTurneableUrl}/${conceptoTurneable.id}`); - } }