Files
WebApp/src/app/conectar/concept-map-editor.ts
T
alberto 7c98566579 T17: sweep of the WebApp after the feature-parity work
Removed the legacy indicator layout, unused chart helpers, styles and
exports, the card-actions component, fetch-all and explanatory comments;
one pager shared by the four worklists, shared filter-row styles, one
FHIR name and CURP reader, downloads through export/, the concept-map
editor on Material controls.
2026-12-01 06:48:57 -06:00

178 lines
5.4 KiB
TypeScript

import { HttpErrorResponse } from '@angular/common/http';
import { Component, inject, input, output, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { Api } from '../api/api';
import { getConceptMap } from '../api/fn/ingest/get-concept-map';
import { saveConceptMap } from '../api/fn/ingest/save-concept-map';
interface Row {
target: string;
code: string;
platform: string;
}
@Component({
selector: 'app-concept-map-editor',
imports: [
FormsModule,
MatButtonModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatSelectModule,
],
template: `
<h3>
Códigos del sitio · <span class="muted">{{ id() }}</span>
</h3>
<table class="plain">
<thead>
<tr>
<th>Sistema destino</th>
<th>Código del sitio</th>
<th>Código de la plataforma</th>
<th></th>
</tr>
</thead>
<tbody>
@for (row of rows(); track $index) {
<tr>
<td>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-select [(ngModel)]="row.target" [aria-label]="'Sistema destino ' + $index">
@for (t of targets(); track t) {
<mat-option [value]="t">{{ short(t) }}</mat-option>
}
</mat-select>
</mat-form-field>
</td>
<td>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<input
matInput
[(ngModel)]="row.code"
[attr.aria-label]="'Código del sitio ' + $index"
/>
</mat-form-field>
</td>
<td>
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<input
matInput
[(ngModel)]="row.platform"
[attr.aria-label]="'Código de la plataforma ' + $index"
/>
</mat-form-field>
</td>
<td>
<button mat-icon-button (click)="remove($index)" aria-label="Quitar fila">
<mat-icon>close</mat-icon>
</button>
</td>
</tr>
}
</tbody>
</table>
<div class="actions">
<button mat-stroked-button (click)="add()"><mat-icon>add</mat-icon> Fila</button>
<button mat-flat-button (click)="save()">Guardar códigos</button>
<span class="muted">{{ message() }}</span>
</div>
`,
styles: `
h3 {
font-size: 0.95rem;
font-weight: 500;
margin: 16px 0 8px;
}
mat-form-field {
width: 100%;
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-top: 8px;
}
`,
})
export class ConceptMapEditor {
private readonly api = inject(Api);
readonly id = input.required<string>();
readonly saved = output<number>();
protected readonly rows = signal<Row[]>([]);
protected readonly targets = signal<string[]>([]);
protected readonly message = signal('');
private source = 'urn:isssteleon:site';
async ngOnInit(): Promise<void> {
try {
const doc = (await this.api.invoke(getConceptMap, { map_id: this.id() })) as Record<
string,
any
>;
const groups = (doc['group'] ?? []) as any[];
this.source = groups[0]?.source ?? this.source;
this.targets.set([...new Set(groups.map((g) => g.target))]);
this.rows.set(
groups.flatMap((g) =>
(g.element ?? []).map((e: any) => ({
target: g.target,
code: e.code,
platform: e.target?.[0]?.code ?? '',
})),
),
);
} catch (e) {
this.message.set(
e instanceof HttpErrorResponse && e.status === 404 ? 'Nuevo: agregue filas.' : String(e),
);
}
}
protected short(url: string): string {
return url.split('/').pop() ?? url;
}
protected add(): void {
this.rows.update((r) => [...r, { target: this.targets()[0] ?? '', code: '', platform: '' }]);
}
protected remove(i: number): void {
this.rows.update((r) => r.filter((_, j) => j !== i));
}
protected async save(): Promise<void> {
const groups = new Map<string, Row[]>();
for (const r of this.rows().filter((r) => r.target && r.code && r.platform)) {
groups.set(r.target, [...(groups.get(r.target) ?? []), r]);
}
const doc = {
resourceType: 'ConceptMap',
status: 'active',
group: [...groups].map(([target, rows]) => ({
source: this.source,
target,
element: rows.map((r) => ({
code: r.code,
target: [{ code: r.platform, equivalence: 'equivalent' }],
})),
})),
};
try {
const { version } = await this.api.invoke(saveConceptMap, { map_id: this.id(), body: doc });
this.message.set(`Versión ${version} guardada.`);
this.saved.emit(version);
} catch (e) {
const detail = e instanceof HttpErrorResponse ? e.error?.detail : e;
this.message.set(Array.isArray(detail) ? detail.join('; ') : String(detail));
}
}
}