ConceptMap editor, names and CURP shown, catalog codes read
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
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 { MatIconModule } from '@angular/material/icon';
|
||||
import { Api } from '../api/api';
|
||||
import { getConceptMap } from '../api/fn/ingest/get-concept-map';
|
||||
import { saveConceptMap } from '../api/fn/ingest/save-concept-map';
|
||||
|
||||
/** One translation: a site's code onto a platform code of one target system. */
|
||||
interface Row {
|
||||
target: string;
|
||||
code: string;
|
||||
platform: string;
|
||||
}
|
||||
|
||||
/** A site's codes in platform terms (a FHIR ConceptMap), edited as a table: a new
|
||||
* laboratory spelling is one more row. The API refuses a code no platform field allows. */
|
||||
@Component({
|
||||
selector: 'app-concept-map-editor',
|
||||
imports: [FormsModule, MatButtonModule, MatIconModule],
|
||||
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>
|
||||
<select [(ngModel)]="row.target" [attr.aria-label]="'Sistema destino ' + $index">
|
||||
@for (t of targets(); track t) {
|
||||
<option [value]="t">{{ short(t) }}</option>
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input [(ngModel)]="row.code" [attr.aria-label]="'Código del sitio ' + $index" />
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
[(ngModel)]="row.platform"
|
||||
[attr.aria-label]="'Código de la plataforma ' + $index"
|
||||
/>
|
||||
</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;
|
||||
}
|
||||
input,
|
||||
select {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
font: inherit;
|
||||
padding: 4px;
|
||||
}
|
||||
.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));
|
||||
}
|
||||
|
||||
/** The rows as a ConceptMap: one group per target system. */
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,9 @@
|
||||
[model]="model"
|
||||
(modelChange)="edited($event)"
|
||||
/>
|
||||
@if (conceptMap(d); as cm) {
|
||||
<app-concept-map-editor [id]="cm" />
|
||||
}
|
||||
<button mat-stroked-button (click)="show()">Vista previa</button>
|
||||
@if (preview(); as rows) {
|
||||
<div class="preview">
|
||||
|
||||
@@ -22,6 +22,7 @@ import { startRun } from '../api/fn/ingest/start-run';
|
||||
import { runStatus } from '../api/fn/runs/run-status';
|
||||
import type { Pipeline } from '../api/models/pipeline';
|
||||
import type { Source } from '../api/models/source';
|
||||
import { ConceptMapEditor } from './concept-map-editor';
|
||||
import { FORMLY_TYPES, nodeSchema } from './schema-form';
|
||||
|
||||
type Doc = Pipeline['nodes'][number];
|
||||
@@ -52,6 +53,7 @@ export const KINDS: Record<Kind, string> = {
|
||||
route: 'Filtrar',
|
||||
map: 'Mapear',
|
||||
extract: 'Extraer',
|
||||
fhir: 'FHIR',
|
||||
join: 'Unir',
|
||||
link: 'Vincular',
|
||||
target: 'Destino',
|
||||
@@ -73,6 +75,7 @@ const ID = /^[a-z][a-z0-9_]*$/;
|
||||
MatListModule,
|
||||
MatTableModule,
|
||||
Vflow,
|
||||
ConceptMapEditor,
|
||||
],
|
||||
// Forms are this page's only: Formly loads with it, not with the app.
|
||||
providers: [provideFormlyCore([...withFormlyMaterial(), FORMLY_TYPES])],
|
||||
@@ -304,6 +307,10 @@ export class Conectar {
|
||||
const run = this.run();
|
||||
return run ? `${location.protocol}//${location.hostname}:5712/runs/${run.id}` : '';
|
||||
});
|
||||
/** The ConceptMap a node names, if its kind takes one. */
|
||||
protected conceptMap(d: Doc): string | undefined {
|
||||
return 'concept_map' in d ? (d.concept_map ?? undefined) : undefined;
|
||||
}
|
||||
protected kindLabel(kind: Doc['kind']): string {
|
||||
return KINDS[kind ?? 'source'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user