integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<h2 mat-dialog-title>Exclusiones · {{ data.cohort.scenario }} ({{ data.cohort.version_hash.slice(0, 12) }}…)</h2>
|
||||
<mat-dialog-content class="exclusions">
|
||||
@if (loading()) {
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
}
|
||||
@if (error(); as message) {
|
||||
<p class="exclusions__alert" role="alert">{{ message }}</p>
|
||||
}
|
||||
|
||||
@if (!loading() && !error()) {
|
||||
<h3>Conteo por criterio</h3>
|
||||
<table mat-table [dataSource]="counts()" class="exclusions__table">
|
||||
<ng-container matColumnDef="criterion_code">
|
||||
<th mat-header-cell *matHeaderCellDef>Criterio</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.criterion_code }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="reason_code">
|
||||
<th mat-header-cell *matHeaderCellDef>Razón</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.reason_code }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="count">
|
||||
<th mat-header-cell *matHeaderCellDef>Conteo</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.count }}</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="countColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: countColumns"></tr>
|
||||
</table>
|
||||
@if (counts().length === 0) {
|
||||
<p class="exclusions__empty">Ningún episodio fue excluido al construir esta cohorte.</p>
|
||||
}
|
||||
|
||||
<h3>Bitácora por episodio</h3>
|
||||
<table mat-table [dataSource]="detail()" class="exclusions__table">
|
||||
<ng-container matColumnDef="pac_id_hospital">
|
||||
<th mat-header-cell *matHeaderCellDef>Paciente</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.pac_id_hospital }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="episodio_id">
|
||||
<th mat-header-cell *matHeaderCellDef>Episodio</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.episodio_id ?? '—' }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="criterion_code">
|
||||
<th mat-header-cell *matHeaderCellDef>Criterio</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.criterion_code }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="reason_code">
|
||||
<th mat-header-cell *matHeaderCellDef>Razón</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.reason_code }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="excluded_at">
|
||||
<th mat-header-cell *matHeaderCellDef>Fecha</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.excluded_at | date: 'short' }}</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="detailColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: detailColumns"></tr>
|
||||
</table>
|
||||
}
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" mat-dialog-close>Cerrar</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,32 @@
|
||||
.exclusions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
max-height: 70vh;
|
||||
min-width: 560px;
|
||||
|
||||
h3 {
|
||||
font: var(--mat-sys-title-small);
|
||||
margin: var(--space-3) 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.exclusions__table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.exclusions__alert {
|
||||
color: var(--mat-sys-error);
|
||||
}
|
||||
|
||||
.exclusions__empty {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.exclusions {
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, OnInit, inject, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { CohortExclusionCount, CohortExclusionDetail, CohortVersion } from '../../api/governance.types';
|
||||
|
||||
export interface CohortExclusionsDialogData {
|
||||
cohort: CohortVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclusion counts per criterion for a cohort version, plus the
|
||||
* per-episode log behind them. Both are written when the cohort is built;
|
||||
* this dialog only displays them.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-cohort-exclusions-dialog',
|
||||
imports: [DatePipe, MatButtonModule, MatDialogModule, MatProgressBarModule, MatTableModule],
|
||||
templateUrl: './cohort-exclusions-dialog.html',
|
||||
styleUrl: './cohort-exclusions-dialog.scss',
|
||||
})
|
||||
export class CohortExclusionsDialog implements OnInit {
|
||||
readonly data = inject<CohortExclusionsDialogData>(MAT_DIALOG_DATA);
|
||||
private readonly api = inject(GovernanceApi);
|
||||
|
||||
readonly loading = signal(true);
|
||||
readonly error = signal<string | null>(null);
|
||||
readonly counts = signal<CohortExclusionCount[]>([]);
|
||||
readonly detail = signal<CohortExclusionDetail[]>([]);
|
||||
|
||||
readonly countColumns = ['criterion_code', 'reason_code', 'count'];
|
||||
readonly detailColumns = ['pac_id_hospital', 'episodio_id', 'criterion_code', 'reason_code', 'excluded_at'];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.api.getCohortExclusions(this.data.cohort.cohort_version_id).subscribe({
|
||||
next: ({ counts, detail }) => {
|
||||
this.loading.set(false);
|
||||
this.counts.set(counts);
|
||||
this.detail.set(detail);
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudieron cargar las exclusiones.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<div class="cohorts">
|
||||
<div class="cohorts__toolbar">
|
||||
<mat-button-toggle-group hideSingleSelectionIndicator [value]="domain()" (change)="setDomain($event.value)" aria-label="Dominio">
|
||||
@for (option of domains; track option.id) {
|
||||
<mat-button-toggle [value]="option.id">{{ option.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
<span class="cohorts__spacer"></span>
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
[matMenuTriggerFor]="scenarioMenu"
|
||||
[disabled]="building() || scenarios().length === 0"
|
||||
[matTooltip]="scenarios().length ? '' : 'No hay escenarios con un constructor de cohorte registrado (models.cohort)'"
|
||||
>
|
||||
<mat-icon aria-hidden="true">add</mat-icon>Construir versión
|
||||
</button>
|
||||
<mat-menu #scenarioMenu="matMenu">
|
||||
@for (scenario of scenarios(); track scenario.domain + scenario.scenario) {
|
||||
<button mat-menu-item type="button" (click)="build(scenario)">
|
||||
{{ scenario.domain }} · {{ scenario.scenario }} ({{ scenario.criteria_version }}, {{ scenario.criteria.length }} criterio(s))
|
||||
</button>
|
||||
}
|
||||
</mat-menu>
|
||||
<button mat-icon-button type="button" (click)="reload()" aria-label="Recargar" matTooltip="Recargar">
|
||||
<mat-icon aria-hidden="true">refresh</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (loading() || building()) {
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
}
|
||||
@if (loadError(); as error) {
|
||||
<p class="cohorts__alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="cohorts()" class="cohorts__table">
|
||||
<ng-container matColumnDef="scenario">
|
||||
<th mat-header-cell *matHeaderCellDef>Dominio · escenario</th>
|
||||
<td mat-cell *matCellDef="let c">{{ c.domain }} · {{ c.scenario }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="version_hash">
|
||||
<th mat-header-cell *matHeaderCellDef>Hash de versión</th>
|
||||
<td mat-cell *matCellDef="let c"><code class="cohorts__hash" [matTooltip]="c.version_hash">{{ c.version_hash.slice(0, 16) }}…</code></td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="criteria_version">
|
||||
<th mat-header-cell *matHeaderCellDef>Criterio</th>
|
||||
<td mat-cell *matCellDef="let c">{{ c.criteria_version }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="counts">
|
||||
<th mat-header-cell *matHeaderCellDef>Participantes</th>
|
||||
<td mat-cell *matCellDef="let c">{{ c.n_included }} incluido(s) · {{ excludedCount(c) }} excluido(s) de {{ c.n_source }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="created_at">
|
||||
<th mat-header-cell *matHeaderCellDef>Creada</th>
|
||||
<td mat-cell *matCellDef="let c">{{ c.created_at | date: 'short' }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="acciones">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell *matCellDef="let c">
|
||||
<button mat-button type="button" (click)="openExclusions(c)">
|
||||
<mat-icon aria-hidden="true">rule</mat-icon>Exclusiones
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading() && cohorts().length === 0) {
|
||||
<p class="cohorts__empty"><mat-icon aria-hidden="true">dataset</mat-icon>Aún no hay cohortes construidas para este filtro.</p>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
.cohorts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.cohorts__toolbar {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.cohorts__spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.cohorts__alert {
|
||||
align-items: center;
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
|
||||
.cohorts__table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cohorts__hash {
|
||||
background: var(--mat-sys-surface-variant);
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
padding: 2px 6px;
|
||||
}
|
||||
|
||||
.cohorts__empty {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { CohortScenario, CohortVersion } from '../../api/governance.types';
|
||||
import { CohortExclusionsDialog, CohortExclusionsDialogData } from '../cohort-exclusions-dialog/cohort-exclusions-dialog';
|
||||
|
||||
/**
|
||||
* Frozen, hashed cohort versions with their exclusion counts and log.
|
||||
* Scenarios with a registered builder can produce a
|
||||
* new version from here.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-cohort-versions-panel',
|
||||
imports: [
|
||||
DatePipe,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatIconModule,
|
||||
MatMenuModule,
|
||||
MatProgressBarModule,
|
||||
MatSnackBarModule,
|
||||
MatTableModule,
|
||||
MatTooltipModule,
|
||||
],
|
||||
templateUrl: './cohort-versions-panel.html',
|
||||
styleUrl: './cohort-versions-panel.scss',
|
||||
})
|
||||
export class CohortVersionsPanel implements OnInit {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
|
||||
readonly domains = [{ id: null, label: 'Todos' }, ...DOMAINS.map((d) => ({ id: d.id as string | null, label: d.label }))];
|
||||
readonly domain = signal<string | null>(null);
|
||||
readonly cohorts = signal<CohortVersion[]>([]);
|
||||
readonly loading = signal(false);
|
||||
readonly loadError = signal<string | null>(null);
|
||||
readonly scenarios = signal<CohortScenario[]>([]);
|
||||
readonly building = signal(false);
|
||||
|
||||
readonly displayedColumns = ['scenario', 'version_hash', 'criteria_version', 'counts', 'created_at', 'acciones'];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.reload();
|
||||
this.api.listCohortScenarios().subscribe({ next: ({ scenarios }) => this.scenarios.set(scenarios), error: () => this.scenarios.set([]) });
|
||||
}
|
||||
|
||||
build(scenario: CohortScenario): void {
|
||||
this.building.set(true);
|
||||
this.api.buildCohortVersion(scenario.domain, scenario.scenario).subscribe({
|
||||
next: (cohort) => {
|
||||
this.building.set(false);
|
||||
this.snackBar.open(`Cohorte ${cohort.scenario} construida: ${cohort.n_included} de ${cohort.n_source} episodios.`, 'OK', { duration: 5000 });
|
||||
this.reload();
|
||||
},
|
||||
error: (error) => {
|
||||
this.building.set(false);
|
||||
this.snackBar.open(apiErrorMessage(error, 'No se pudo construir la cohorte.'), 'OK', { duration: 6000 });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
setDomain(domain: string | null): void {
|
||||
this.domain.set(domain);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
this.loading.set(true);
|
||||
this.loadError.set(null);
|
||||
this.api
|
||||
.listCohortVersions(this.domain() ? { domain: this.domain()! } : {})
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: ({ cohort_versions }) => {
|
||||
this.loading.set(false);
|
||||
this.cohorts.set(cohort_versions);
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar las versiones de cohorte.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openExclusions(cohort: CohortVersion): void {
|
||||
this.dialog.open<CohortExclusionsDialog, CohortExclusionsDialogData>(CohortExclusionsDialog, {
|
||||
width: '720px',
|
||||
maxWidth: '96vw',
|
||||
data: { cohort },
|
||||
});
|
||||
}
|
||||
|
||||
excludedCount(cohort: CohortVersion): number {
|
||||
return cohort.n_source - cohort.n_included;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<div class="governance">
|
||||
<mat-toolbar class="governance__toolbar">
|
||||
<div class="governance__title">
|
||||
<span class="governance__eyebrow">Análisis de información</span>
|
||||
<h1>Gobernanza de modelos</h1>
|
||||
</div>
|
||||
</mat-toolbar>
|
||||
|
||||
<mat-tab-group class="governance__tabs" animationDuration="0ms">
|
||||
<mat-tab label="Versiones de modelo">
|
||||
<div class="governance__panel">
|
||||
<app-model-versions-panel></app-model-versions-panel>
|
||||
</div>
|
||||
</mat-tab>
|
||||
<mat-tab label="Cohortes">
|
||||
<div class="governance__panel">
|
||||
<app-cohort-versions-panel></app-cohort-versions-panel>
|
||||
</div>
|
||||
</mat-tab>
|
||||
<mat-tab label="Revisión de OCR">
|
||||
<div class="governance__panel">
|
||||
<app-ocr-review-panel></app-ocr-review-panel>
|
||||
</div>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
</div>
|
||||
@@ -0,0 +1,59 @@
|
||||
:host {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.governance {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
height: calc(100dvh - var(--site-header-height));
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.governance__toolbar {
|
||||
--mat-toolbar-container-background-color: var(--mat-sys-surface);
|
||||
--mat-toolbar-standard-height: 68px;
|
||||
border-bottom: 1px solid var(--mat-sys-outline-variant);
|
||||
height: auto;
|
||||
min-height: 68px;
|
||||
padding: var(--space-2) var(--space-4);
|
||||
}
|
||||
|
||||
.governance__title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.1;
|
||||
|
||||
h1 {
|
||||
color: var(--color-primary);
|
||||
font-family: var(--font-heading);
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.governance__eyebrow {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-label-small);
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.governance__tabs {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
::ng-deep .mat-mdc-tab-body-wrapper {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.governance__panel {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
padding: var(--space-4);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { CohortVersionsPanel } from '../cohort-versions-panel/cohort-versions-panel';
|
||||
import { ModelVersionsPanel } from '../model-versions-panel/model-versions-panel';
|
||||
import { OcrReviewPanel } from '../ocr-review-panel/ocr-review-panel';
|
||||
|
||||
/**
|
||||
* The "Gobernanza de modelos" page (route `/gobernanza`): model versions,
|
||||
* cohorts and the OCR review queue, one tab each. Every tab is a
|
||||
* self-contained panel that loads its own data.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-governance-page',
|
||||
imports: [CohortVersionsPanel, MatTabsModule, MatToolbarModule, ModelVersionsPanel, OcrReviewPanel],
|
||||
templateUrl: './governance-page.html',
|
||||
styleUrl: './governance-page.scss',
|
||||
})
|
||||
export class GovernancePage {}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { ModelStatus } from '../../api/governance.types';
|
||||
|
||||
const PRESENTATION: Record<ModelStatus, { label: string; icon: string }> = {
|
||||
desarrollo: { label: 'Desarrollo', icon: 'science' },
|
||||
candidata: { label: 'Candidata', icon: 'pending' },
|
||||
produccion: { label: 'En producción', icon: 'verified' },
|
||||
retirada: { label: 'Retirada', icon: 'history' },
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-model-status',
|
||||
imports: [MatIconModule],
|
||||
template: `<span class="status" [class]="'status status--' + status()"
|
||||
><mat-icon aria-hidden="true">{{ view().icon }}</mat-icon>{{ view().label }}</span
|
||||
>`,
|
||||
styles: `
|
||||
.status {
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
display: inline-flex;
|
||||
font: var(--mat-sys-label-medium);
|
||||
gap: 4px;
|
||||
padding: 2px 10px 2px 6px;
|
||||
}
|
||||
mat-icon {
|
||||
font-size: 16px;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
}
|
||||
.status--desarrollo,
|
||||
.status--retirada {
|
||||
background: var(--mat-sys-surface-container-high);
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
.status--candidata {
|
||||
background: var(--mat-sys-secondary-container);
|
||||
color: var(--mat-sys-on-secondary-container);
|
||||
}
|
||||
.status--produccion {
|
||||
background: var(--mat-sys-primary-container);
|
||||
color: var(--mat-sys-on-primary-container);
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class ModelStatusChip {
|
||||
readonly status = input.required<ModelStatus>();
|
||||
readonly view = computed(() => PRESENTATION[this.status()]);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<h2 mat-dialog-title class="title">
|
||||
{{ title }}
|
||||
@if (lineage(); as l) {
|
||||
<app-model-status [status]="l.model_version.status"></app-model-status>
|
||||
}
|
||||
</h2>
|
||||
|
||||
<mat-dialog-content class="content">
|
||||
@if (busy()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Cargando"></mat-progress-bar>
|
||||
}
|
||||
@if (error(); as message) {
|
||||
<p class="alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ message }}</p>
|
||||
}
|
||||
|
||||
@if (lineage(); as l) {
|
||||
@let v = l.model_version;
|
||||
<section class="summary">
|
||||
<dl>
|
||||
<dt>Dominio · escenario</dt>
|
||||
<dd>{{ v.tags.domain }} · {{ v.tags.scenario }}</dd>
|
||||
<dt>Entorno</dt>
|
||||
<dd>{{ v.tags.environment }}</dd>
|
||||
<dt>Creada</dt>
|
||||
<dd>{{ v.created_at | date: 'medium' }}</dd>
|
||||
@if (v.tags.promovida_en) {
|
||||
<dt>Promovida</dt>
|
||||
<dd>{{ v.tags.promovida_en | date: 'medium' }}</dd>
|
||||
}
|
||||
<dt>Predicciones registradas</dt>
|
||||
<dd>{{ l.predictions | number }}</dd>
|
||||
</dl>
|
||||
@if (metrics(v).length) {
|
||||
<dl class="metrics">
|
||||
@for (metric of metrics(v); track metric[0]) {
|
||||
<dt>{{ metric[0] }}</dt>
|
||||
<dd>{{ metric[1] }}</dd>
|
||||
}
|
||||
</dl>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="checks-title">
|
||||
<h3 id="checks-title">Requisitos para producción</h3>
|
||||
<ul class="checks">
|
||||
@for (check of l.checks; track $index) {
|
||||
<li [class.checks__fail]="!check.passed">
|
||||
<mat-icon aria-hidden="true">{{ check.passed ? 'check_circle' : 'cancel' }}</mat-icon>
|
||||
<span class="checks__code">{{ check.code }}</span>
|
||||
<span>{{ check.requirement }}</span>
|
||||
@if (check.detail) {
|
||||
<span class="checks__detail">{{ check.detail }}</span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="cohort-title">
|
||||
<h3 id="cohort-title">Cohorte de entrenamiento</h3>
|
||||
@if (l.cohort_version; as cohort) {
|
||||
<p>
|
||||
{{ cohort.domain }} · {{ cohort.scenario }} · criterio {{ cohort.criteria_version }} ·
|
||||
{{ cohort.n_included | number }} de {{ cohort.n_source | number }} episodios
|
||||
</p>
|
||||
<p class="hash" [matTooltip]="cohort.version_hash">hash {{ cohort.version_hash.slice(0, 16) }}…</p>
|
||||
@if (l.cohort_exclusions.length) {
|
||||
<ul class="exclusions">
|
||||
@for (count of l.cohort_exclusions; track count.cohort_exclusion_count_id) {
|
||||
<li>{{ count.criterion_code }} ({{ count.reason_code }}): {{ count.count | number }} excluidos</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
} @else {
|
||||
<p class="muted">Sin cohorte enlazada.</p>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="artifacts-title">
|
||||
<h3 id="artifacts-title">Artefactos</h3>
|
||||
<p class="muted">Guardados en la corrida de MLflow; ábrelos desde el servidor de MLflow.</p>
|
||||
<ul class="artifacts">
|
||||
@for (artifact of l.artifacts; track artifact) {
|
||||
<li>
|
||||
<mat-icon aria-hidden="true">description</mat-icon>
|
||||
<span class="artifacts__kind">{{ artifactKindOf(artifact) }}</span>
|
||||
<span class="artifacts__name">{{ artifactName(artifact) }}</span>
|
||||
</li>
|
||||
} @empty {
|
||||
<li class="muted">Sin artefactos.</li>
|
||||
}
|
||||
</ul>
|
||||
<div class="upload">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Tipo</mat-label>
|
||||
<mat-select [value]="artifactKind()" (valueChange)="artifactKind.set($event)">
|
||||
@for (kind of artifactKinds; track kind.id) {
|
||||
<mat-option [value]="kind.id">{{ kind.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button mat-stroked-button type="button" [disabled]="busy()" (click)="fileInput.click()">
|
||||
<mat-icon aria-hidden="true">upload_file</mat-icon>Subir artefacto
|
||||
</button>
|
||||
<input #fileInput type="file" hidden (change)="uploadArtifact($event)" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="reports-title">
|
||||
<h3 id="reports-title">Reportes de validación</h3>
|
||||
<form [formGroup]="reports" class="reports" (ngSubmit)="saveReports()">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Pruebas técnicas (MLD-01)</mat-label>
|
||||
<input matInput formControlName="technical_validation_report_uri" placeholder="Ruta o URL del reporte" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Validación clínica (MLD-01b)</mat-label>
|
||||
<input matInput formControlName="clinical_validation_report_uri" placeholder="Ruta o URL del reporte" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Interpretabilidad (MLD-03)</mat-label>
|
||||
<input matInput formControlName="interpretability_report_uri" placeholder="Ruta o URL del reporte" />
|
||||
</mat-form-field>
|
||||
<button mat-stroked-button type="submit" [disabled]="busy() || reports.pristine">Guardar reportes</button>
|
||||
</form>
|
||||
</section>
|
||||
}
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" (click)="close()">Cerrar</button>
|
||||
@if (lineage(); as l) {
|
||||
@if (l.model_version.status === 'produccion') {
|
||||
<button mat-stroked-button type="button" [disabled]="busy()" (click)="retire()">
|
||||
<mat-icon aria-hidden="true">pause_circle</mat-icon>Retirar de producción
|
||||
</button>
|
||||
} @else {
|
||||
<button
|
||||
mat-flat-button
|
||||
type="button"
|
||||
[disabled]="busy() || !ready(l.checks)"
|
||||
[matTooltip]="ready(l.checks) ? '' : 'Faltan requisitos para producción'"
|
||||
(click)="promote()"
|
||||
>
|
||||
<mat-icon aria-hidden="true">rocket_launch</mat-icon>Promover a producción
|
||||
</button>
|
||||
}
|
||||
}
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,113 @@
|
||||
.title {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-4);
|
||||
|
||||
h3 {
|
||||
font: var(--mat-sys-title-small);
|
||||
margin: 0 0 var(--space-2);
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0 0 var(--space-1);
|
||||
}
|
||||
}
|
||||
|
||||
.alert {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-error);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-6, 24px);
|
||||
|
||||
dl {
|
||||
display: grid;
|
||||
gap: var(--space-1) var(--space-3);
|
||||
grid-template-columns: auto auto;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
dt {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-label-medium);
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.checks,
|
||||
.artifacts,
|
||||
.exclusions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
li {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
}
|
||||
|
||||
.checks mat-icon {
|
||||
color: var(--mat-sys-primary);
|
||||
}
|
||||
|
||||
.checks__fail mat-icon {
|
||||
color: var(--mat-sys-error);
|
||||
}
|
||||
|
||||
.checks__code,
|
||||
.artifacts__kind {
|
||||
font: var(--mat-sys-label-medium);
|
||||
min-width: 64px;
|
||||
}
|
||||
|
||||
.checks__detail,
|
||||
.hash,
|
||||
.muted {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
|
||||
.hash {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.artifacts__name {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.upload {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
|
||||
.reports {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
button {
|
||||
justify-self: start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import { DatePipe, DecimalPipe } from '@angular/common';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { Observable } from 'rxjs';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { ModelLineage, ModelVersion, PromotionCheck } from '../../api/governance.types';
|
||||
import { ModelStatusChip } from '../model-status-chip/model-status-chip';
|
||||
|
||||
export const ARTIFACT_KINDS: { id: string; label: string }[] = [
|
||||
{ id: 'ONNX_CHECKPOINT', label: 'Checkpoint ONNX' },
|
||||
{ id: 'MUESTREO', label: 'Muestreo' },
|
||||
{ id: 'DATOS_FALTANTES', label: 'Datos faltantes' },
|
||||
{ id: 'METODO_ANALITICO', label: 'Método analítico' },
|
||||
{ id: 'BALANCE_CLASES', label: 'Balance de clases' },
|
||||
{ id: 'CONFIANZA_SALIDA', label: 'Confianza de la salida' },
|
||||
{ id: 'OTRO', label: 'Otro' },
|
||||
];
|
||||
|
||||
/**
|
||||
* One model version: what it was trained on (cohort hash and exclusions),
|
||||
* its artifacts and their integrity, its validation reports, and the
|
||||
* checklist that must pass before it can serve predictions. Closes with
|
||||
* `true` when the version changed.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-model-version-dialog',
|
||||
imports: [
|
||||
DatePipe,
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
MatTooltipModule,
|
||||
ModelStatusChip,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
templateUrl: './model-version-dialog.html',
|
||||
styleUrl: './model-version-dialog.scss',
|
||||
})
|
||||
export class ModelVersionDialog {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialogRef = inject<MatDialogRef<ModelVersionDialog, boolean>>(MatDialogRef);
|
||||
private readonly version = inject<ModelVersion>(MAT_DIALOG_DATA);
|
||||
|
||||
readonly artifactKinds = ARTIFACT_KINDS;
|
||||
readonly lineage = signal<ModelLineage | null>(null);
|
||||
readonly busy = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
private changed = false;
|
||||
|
||||
readonly reports = inject(FormBuilder).nonNullable.group({
|
||||
technical_validation_report_uri: [''],
|
||||
clinical_validation_report_uri: [''],
|
||||
interpretability_report_uri: [''],
|
||||
});
|
||||
readonly artifactKind = signal('ONNX_CHECKPOINT');
|
||||
|
||||
constructor() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
private get domain(): string {
|
||||
return this.version.tags.domain!;
|
||||
}
|
||||
|
||||
private get scenario(): string {
|
||||
return this.version.tags.scenario!;
|
||||
}
|
||||
|
||||
get title(): string {
|
||||
const v = this.lineage()?.model_version ?? this.version;
|
||||
return `${v.name}:${v.version}`;
|
||||
}
|
||||
|
||||
ready(checks: PromotionCheck[]): boolean {
|
||||
return checks.every((check) => check.passed);
|
||||
}
|
||||
|
||||
metrics(version: ModelVersion): [string, unknown][] {
|
||||
return Object.entries(version.metrics ?? {});
|
||||
}
|
||||
|
||||
artifactName(path: string): string {
|
||||
return path.split('/').pop() ?? path;
|
||||
}
|
||||
|
||||
artifactKindOf(path: string): string {
|
||||
return path.split('/')[0] ?? path;
|
||||
}
|
||||
|
||||
saveReports(): void {
|
||||
const values = this.reports.getRawValue();
|
||||
this.run(this.api.attachReports(this.domain, this.scenario, this.version.version, {
|
||||
technical_validation_report_uri: values.technical_validation_report_uri.trim() || null,
|
||||
clinical_validation_report_uri: values.clinical_validation_report_uri.trim() || null,
|
||||
interpretability_report_uri: values.interpretability_report_uri.trim() || null,
|
||||
}));
|
||||
}
|
||||
|
||||
uploadArtifact(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (file) this.run(this.api.uploadArtifact(this.domain, this.scenario, this.version.version, this.artifactKind(), file));
|
||||
}
|
||||
|
||||
promote(): void {
|
||||
this.run(this.api.promoteModelVersion(this.domain, this.scenario, this.version.version));
|
||||
}
|
||||
|
||||
retire(): void {
|
||||
this.run(this.api.retireModelVersion(this.domain, this.scenario, this.version.version));
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.dialogRef.close(this.changed);
|
||||
}
|
||||
|
||||
private run(request: Observable<unknown>): void {
|
||||
this.busy.set(true);
|
||||
this.error.set(null);
|
||||
request.subscribe({
|
||||
next: () => {
|
||||
this.changed = true;
|
||||
this.load();
|
||||
},
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'La operación no se pudo completar.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private load(): void {
|
||||
this.busy.set(true);
|
||||
this.api.lineage(this.domain, this.scenario, this.version.version).subscribe({
|
||||
next: (lineage) => {
|
||||
this.lineage.set(lineage);
|
||||
const tags = lineage.model_version.tags;
|
||||
this.reports.setValue({
|
||||
technical_validation_report_uri: tags.technical_validation_report_uri ?? '',
|
||||
clinical_validation_report_uri: tags.clinical_validation_report_uri ?? '',
|
||||
interpretability_report_uri: tags.interpretability_report_uri ?? '',
|
||||
});
|
||||
this.reports.markAsPristine();
|
||||
this.busy.set(false);
|
||||
},
|
||||
error: (error) => {
|
||||
this.busy.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudo cargar la versión.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<div class="models">
|
||||
<div class="models__toolbar">
|
||||
<mat-button-toggle-group hideSingleSelectionIndicator [value]="domain()" (change)="setDomain($event.value)" aria-label="Dominio">
|
||||
@for (option of domains; track option.id) {
|
||||
<mat-button-toggle [value]="option.id">{{ option.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
<span class="models__spacer"></span>
|
||||
<button mat-icon-button type="button" (click)="reload()" aria-label="Recargar" matTooltip="Recargar">
|
||||
<mat-icon aria-hidden="true">refresh</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (loading()) {
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
}
|
||||
@if (loadError(); as error) {
|
||||
<p class="models__alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="versions()" class="models__table">
|
||||
<ng-container matColumnDef="version">
|
||||
<th mat-header-cell *matHeaderCellDef>Versión</th>
|
||||
<td mat-cell *matCellDef="let v">
|
||||
<div class="models__tag">{{ v.name }}:{{ v.version }}</div>
|
||||
@if (metrics(v).length) {
|
||||
<mat-chip-set>
|
||||
@for (metric of metrics(v); track metric.key) {
|
||||
<mat-chip>{{ metric.key }}: {{ metric.value }}</mat-chip>
|
||||
}
|
||||
</mat-chip-set>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="scenario">
|
||||
<th mat-header-cell *matHeaderCellDef>Dominio · escenario</th>
|
||||
<td mat-cell *matCellDef="let v">{{ v.tags.domain }} · {{ v.tags.scenario }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="environment">
|
||||
<th mat-header-cell *matHeaderCellDef>Entorno</th>
|
||||
<td mat-cell *matCellDef="let v">
|
||||
<span class="models__env" [class.models__env--prod]="v.tags.environment === 'PROD'">{{ v.tags.environment }}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="cohort_version_id">
|
||||
<th mat-header-cell *matHeaderCellDef>Cohorte</th>
|
||||
<td mat-cell *matCellDef="let v">{{ v.tags.cohort_version_id ?? '— (sin enlazar)' }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="status">
|
||||
<th mat-header-cell *matHeaderCellDef>Estatus</th>
|
||||
<td mat-cell *matCellDef="let v"><app-model-status [status]="v.status"></app-model-status></td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="created_at">
|
||||
<th mat-header-cell *matHeaderCellDef>Creada</th>
|
||||
<td mat-cell *matCellDef="let v">{{ v.created_at | date: 'short' }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="acciones">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell *matCellDef="let v">
|
||||
<button mat-button type="button" (click)="open(v)">
|
||||
<mat-icon aria-hidden="true">info</mat-icon>Detalle
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading() && versions().length === 0) {
|
||||
<p class="models__empty"><mat-icon aria-hidden="true">model_training</mat-icon>Aún no hay versiones entrenadas para este filtro.</p>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,72 @@
|
||||
.models {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.models__toolbar {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.models__spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.models__alert {
|
||||
align-items: center;
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
|
||||
.models__table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.models__tag {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.models__env {
|
||||
background: var(--mat-sys-surface-variant);
|
||||
border-radius: 999px;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-label-small);
|
||||
padding: 2px 10px;
|
||||
}
|
||||
|
||||
.models__env--prod {
|
||||
background: #d8f0da;
|
||||
color: #1e5c25;
|
||||
}
|
||||
|
||||
.models__production {
|
||||
align-items: center;
|
||||
color: #1e5c25;
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
|
||||
mat-icon {
|
||||
font-size: 18px;
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.models__inactive {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
|
||||
.models__empty {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { ModelVersion } from '../../api/governance.types';
|
||||
import { ModelStatusChip } from '../model-status-chip/model-status-chip';
|
||||
import { ModelVersionDialog } from '../model-version-dialog/model-version-dialog';
|
||||
|
||||
/**
|
||||
* Every registered model version with its status (desarrollo, candidata,
|
||||
* en producción, retirada). The detail dialog holds the promotion
|
||||
* checklist, lineage, artifacts and reports.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-model-versions-panel',
|
||||
imports: [
|
||||
DatePipe,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatChipsModule,
|
||||
MatIconModule,
|
||||
MatProgressBarModule,
|
||||
MatSnackBarModule,
|
||||
MatTableModule,
|
||||
MatTooltipModule,
|
||||
ModelStatusChip,
|
||||
],
|
||||
templateUrl: './model-versions-panel.html',
|
||||
styleUrl: './model-versions-panel.scss',
|
||||
})
|
||||
export class ModelVersionsPanel implements OnInit {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
readonly domains = [{ id: null, label: 'Todos' }, ...DOMAINS.map((d) => ({ id: d.id as string | null, label: d.label }))];
|
||||
readonly domain = signal<string | null>(null);
|
||||
readonly versions = signal<ModelVersion[]>([]);
|
||||
readonly loading = signal(false);
|
||||
readonly loadError = signal<string | null>(null);
|
||||
|
||||
readonly displayedColumns = ['version', 'scenario', 'environment', 'cohort_version_id', 'status', 'created_at', 'acciones'];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
setDomain(domain: string | null): void {
|
||||
this.domain.set(domain);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
this.loading.set(true);
|
||||
this.loadError.set(null);
|
||||
this.api
|
||||
.listModelVersions(this.domain() ? { domain: this.domain()! } : {})
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: ({ model_versions }) => {
|
||||
this.loading.set(false);
|
||||
this.versions.set(model_versions);
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar las versiones de modelo.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
open(version: ModelVersion): void {
|
||||
this.dialog
|
||||
.open<ModelVersionDialog, ModelVersion, boolean>(ModelVersionDialog, { data: version, width: '880px', maxWidth: '96vw', autoFocus: false })
|
||||
.afterClosed()
|
||||
.subscribe((changed) => {
|
||||
if (!changed) return;
|
||||
this.snackBar.open(`${version.name}:${version.version} actualizada.`, 'OK', { duration: 3000 });
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
|
||||
metrics(version: ModelVersion): { key: string; value: unknown }[] {
|
||||
return Object.entries(version.metrics ?? {}).map(([key, value]) => ({ key, value }));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<h2 mat-dialog-title>{{ data.title }}</h2>
|
||||
<mat-dialog-content class="correction">
|
||||
<div class="correction__viewer">
|
||||
<app-pdf-page-viewer
|
||||
[file]="data.file"
|
||||
[pageNumber]="page()"
|
||||
[pageCount]="pageCount()"
|
||||
(pageNumberChange)="page.set($event)"
|
||||
(regionDrawn)="onRegionDrawn($event)"
|
||||
></app-pdf-page-viewer>
|
||||
</div>
|
||||
|
||||
<aside class="correction__side">
|
||||
<p class="correction__hint">
|
||||
Selecciona un campo y dibuja un recuadro sobre el valor en el PDF. El texto leído llena el campo — puedes
|
||||
corregirlo a mano antes de guardar.
|
||||
@if (extracting()) {
|
||||
<mat-progress-spinner diameter="16" mode="indeterminate" class="correction__spinner"></mat-progress-spinner>
|
||||
}
|
||||
</p>
|
||||
|
||||
@for (field of data.fields; track field.name) {
|
||||
<div class="correction__field" [class.correction__field--active]="activeField() === field.name">
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
class="correction__pick"
|
||||
(click)="selectField(field.name)"
|
||||
[attr.aria-pressed]="activeField() === field.name"
|
||||
>
|
||||
<mat-icon aria-hidden="true">crop</mat-icon>{{ field.label }}
|
||||
</button>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="correction__input">
|
||||
<input matInput [value]="values()[field.name]" (input)="setValue(field.name, $any($event.target).value)" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
}
|
||||
</aside>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button type="button" mat-dialog-close>Cancelar</button>
|
||||
<button mat-flat-button type="button" [disabled]="!canSave()" (click)="save()">Guardar corrección</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,57 @@
|
||||
.correction {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: minmax(0, 1fr) 300px;
|
||||
max-height: 78vh;
|
||||
}
|
||||
|
||||
.correction__viewer {
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.correction__side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.correction__hint {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.correction__spinner {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.correction__field {
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
|
||||
.correction__field--active {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: inset 0 0 0 1px var(--color-primary);
|
||||
}
|
||||
|
||||
.correction__pick {
|
||||
margin-bottom: var(--space-2);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.correction__input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.correction {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { PdfSourceApi } from '../../../connect/api/pdf-source.api';
|
||||
import { PdfPageViewer } from '../../../connect/components/pdf-page-viewer/pdf-page-viewer';
|
||||
import { DrawnRegionBox } from '../../../connect/components/pdf-page-viewer/region-draw-overlay.directive';
|
||||
|
||||
export interface OcrCorrectionField {
|
||||
name: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface OcrCorrectionDialogData {
|
||||
title: string;
|
||||
/** The row's stored PDF, already fetched by the caller and wrapped as a browser File. */
|
||||
file: File;
|
||||
fields: OcrCorrectionField[];
|
||||
currentValues: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface OcrCorrectionResult {
|
||||
values: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual correction of an OCR row. The user picks a field and draws a box
|
||||
* over its value on the stored PDF; the text read from that box fills an
|
||||
* editable input. What gets saved is the input's value, so a bad read can
|
||||
* be fixed by hand.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-ocr-correction-dialog',
|
||||
imports: [
|
||||
MatButtonModule,
|
||||
MatDialogModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSnackBarModule,
|
||||
PdfPageViewer,
|
||||
],
|
||||
templateUrl: './ocr-correction-dialog.html',
|
||||
styleUrl: './ocr-correction-dialog.scss',
|
||||
})
|
||||
export class OcrCorrectionDialog {
|
||||
readonly data = inject<OcrCorrectionDialogData>(MAT_DIALOG_DATA);
|
||||
private readonly dialogRef = inject<MatDialogRef<OcrCorrectionDialog, OcrCorrectionResult>>(MatDialogRef);
|
||||
private readonly pdfApi = inject(PdfSourceApi);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
|
||||
readonly page = signal(1);
|
||||
readonly pageCount = signal(1);
|
||||
readonly activeField = signal<string | null>(this.data.fields[0]?.name ?? null);
|
||||
readonly extracting = signal(false);
|
||||
|
||||
readonly values = signal<Record<string, string>>(
|
||||
Object.fromEntries(
|
||||
this.data.fields.map((field) => [
|
||||
field.name,
|
||||
this.data.currentValues[field.name] == null ? '' : String(this.data.currentValues[field.name]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
readonly canSave = computed(() => Object.values(this.values()).some((value) => value.trim() !== ''));
|
||||
|
||||
constructor() {
|
||||
this.pdfApi.detect(this.data.file).subscribe({
|
||||
next: (detection) => this.pageCount.set(detection.page_count || 1),
|
||||
error: () => this.pageCount.set(1),
|
||||
});
|
||||
}
|
||||
|
||||
selectField(name: string): void {
|
||||
this.activeField.set(name);
|
||||
}
|
||||
|
||||
setValue(name: string, value: string): void {
|
||||
this.values.update((values) => ({ ...values, [name]: value }));
|
||||
}
|
||||
|
||||
onRegionDrawn(box: DrawnRegionBox): void {
|
||||
const field = this.activeField();
|
||||
if (!field) return;
|
||||
this.extracting.set(true);
|
||||
this.pdfApi
|
||||
.extractRegions(this.data.file, [{ target_field: field, page_numbers: [this.page()], bbox: [box.x0, box.y0, box.x1, box.y1] }], null)
|
||||
.subscribe({
|
||||
next: (result) => {
|
||||
this.extracting.set(false);
|
||||
const extracted = result.rows[0]?.[field];
|
||||
if (extracted != null && String(extracted).trim() !== '') {
|
||||
this.setValue(field, String(extracted));
|
||||
} else {
|
||||
this.snackBar.open('No se encontró texto en la región marcada — edita el campo a mano.', 'OK', { duration: 4000 });
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
this.extracting.set(false);
|
||||
this.snackBar.open(apiErrorMessage(error, 'No se pudo leer esa región.'), 'OK', { duration: 4000 });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
save(): void {
|
||||
const values = Object.fromEntries(Object.entries(this.values()).filter(([, value]) => value.trim() !== ''));
|
||||
this.dialogRef.close({ values });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<div class="ocr">
|
||||
<div class="ocr__toolbar">
|
||||
@if (jobs().length) {
|
||||
<mat-button-toggle-group
|
||||
class="ocr__jobs"
|
||||
hideSingleSelectionIndicator
|
||||
[value]="selectedJob()"
|
||||
(change)="selectJob($event.value)"
|
||||
aria-label="Tipo de extracción OCR"
|
||||
>
|
||||
@for (job of jobs(); track job.entity) {
|
||||
<mat-button-toggle [value]="job">{{ job.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
}
|
||||
|
||||
<span class="ocr__spacer"></span>
|
||||
|
||||
<button mat-stroked-button type="button" [disabled]="!selectedJob() || running()" (click)="runOcr()">
|
||||
<mat-icon aria-hidden="true">auto_fix_high</mat-icon>Ejecutar OCR automático
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<mat-button-toggle-group class="ocr__status" hideSingleSelectionIndicator [value]="status()" (change)="setStatus($event.value)" aria-label="Filtro de estatus">
|
||||
@for (option of statusOptions; track option.value) {
|
||||
<mat-button-toggle [value]="option.value">{{ option.label }}</mat-button-toggle>
|
||||
}
|
||||
</mat-button-toggle-group>
|
||||
|
||||
@if (loading() || running()) {
|
||||
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
|
||||
}
|
||||
@if (loadError(); as error) {
|
||||
<p class="ocr__alert" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="rows()" class="ocr__table">
|
||||
<ng-container matColumnDef="pac_id_hospital">
|
||||
<th mat-header-cell *matHeaderCellDef>Paciente</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.pac_id_hospital ?? '—' }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="values">
|
||||
<th mat-header-cell *matHeaderCellDef>Valores extraídos</th>
|
||||
<td mat-cell *matCellDef="let row">
|
||||
<mat-chip-set>
|
||||
@for (entry of rowValueEntries(row); track entry.field) {
|
||||
<mat-chip>{{ entry.field }}: {{ entry.value }}</mat-chip>
|
||||
}
|
||||
</mat-chip-set>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="confianza">
|
||||
<th mat-header-cell *matHeaderCellDef>Confianza</th>
|
||||
<td mat-cell *matCellDef="let row">{{ row.confianza === null ? '—' : (row.confianza | number: '1.0-2') }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="estatus">
|
||||
<th mat-header-cell *matHeaderCellDef>Estatus</th>
|
||||
<td mat-cell *matCellDef="let row">
|
||||
<span class="ocr__status-chip" [class]="'ocr__status-chip--' + (row.estatus ?? 'pendiente').toLowerCase()">
|
||||
{{ row.estatus ?? 'PENDIENTE' }}
|
||||
</span>
|
||||
@if (row.requiere_revision) {
|
||||
<mat-icon aria-hidden="true" matTooltip="Requiere revisión manual" class="ocr__review-flag">flag</mat-icon>
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="acciones">
|
||||
<th mat-header-cell *matHeaderCellDef></th>
|
||||
<td mat-cell *matCellDef="let row">
|
||||
<button mat-button type="button" [disabled]="correctingId() === row.id" (click)="correct(row)">
|
||||
<mat-icon aria-hidden="true">crop</mat-icon>Corregir
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
|
||||
@if (!loading() && rows().length === 0) {
|
||||
<p class="ocr__empty"><mat-icon aria-hidden="true">task_alt</mat-icon>No hay filas en este filtro.</p>
|
||||
}
|
||||
|
||||
<p class="ocr__total">{{ total() }} fila(s) en total.</p>
|
||||
</div>
|
||||
@@ -0,0 +1,69 @@
|
||||
.ocr {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.ocr__toolbar {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.ocr__spacer {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.ocr__status {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ocr__alert {
|
||||
align-items: center;
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
|
||||
.ocr__table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ocr__status-chip {
|
||||
background: var(--mat-sys-surface-variant);
|
||||
border-radius: 999px;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-label-small);
|
||||
padding: 2px 10px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ocr__status-chip--realizado {
|
||||
background: #d8f0da;
|
||||
color: #1e5c25;
|
||||
}
|
||||
|
||||
.ocr__status-chip--fallido {
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
}
|
||||
|
||||
.ocr__review-flag {
|
||||
color: #b8860b;
|
||||
margin-left: var(--space-1);
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ocr__empty,
|
||||
.ocr__total {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, DestroyRef, OnInit, inject, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { apiErrorMessage } from '../../../connect/api/api.types';
|
||||
import { GovernanceApi } from '../../api/governance.api';
|
||||
import { OcrJob, OcrRow, OcrRowStatus } from '../../api/governance.types';
|
||||
import {
|
||||
OcrCorrectionDialog,
|
||||
OcrCorrectionDialogData,
|
||||
OcrCorrectionResult,
|
||||
} from '../ocr-correction-dialog/ocr-correction-dialog';
|
||||
|
||||
const STATUS_OPTIONS: { value: OcrRowStatus; label: string }[] = [
|
||||
{ value: 'review', label: 'Requieren revisión' },
|
||||
{ value: 'pending', label: 'Pendientes' },
|
||||
{ value: 'failed', label: 'Fallidas' },
|
||||
{ value: 'done', label: 'Completadas' },
|
||||
{ value: 'all', label: 'Todas' },
|
||||
];
|
||||
|
||||
/**
|
||||
* Review queue for OCR-derived fields. The toggle group picks the OCR job,
|
||||
* the run button starts the automatic batch (rows already done are
|
||||
* skipped), and "Corregir" opens `OcrCorrectionDialog` for one row.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-ocr-review-panel',
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatChipsModule,
|
||||
MatIconModule,
|
||||
MatProgressBarModule,
|
||||
MatSnackBarModule,
|
||||
MatTableModule,
|
||||
MatTooltipModule,
|
||||
],
|
||||
templateUrl: './ocr-review-panel.html',
|
||||
styleUrl: './ocr-review-panel.scss',
|
||||
})
|
||||
export class OcrReviewPanel implements OnInit {
|
||||
private readonly api = inject(GovernanceApi);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
readonly statusOptions = STATUS_OPTIONS;
|
||||
readonly jobs = signal<OcrJob[]>([]);
|
||||
readonly selectedJob = signal<OcrJob | null>(null);
|
||||
readonly status = signal<OcrRowStatus>('review');
|
||||
readonly rows = signal<OcrRow[]>([]);
|
||||
readonly total = signal(0);
|
||||
readonly loading = signal(false);
|
||||
readonly running = signal(false);
|
||||
readonly correctingId = signal<number | null>(null);
|
||||
readonly loadError = signal<string | null>(null);
|
||||
|
||||
/** The same for every job: each job's result fields render as chips in the "values" column. */
|
||||
readonly displayedColumns = ['pac_id_hospital', 'values', 'confianza', 'estatus', 'acciones'];
|
||||
|
||||
rowValueEntries(row: OcrRow): { field: string; value: string }[] {
|
||||
return Object.entries(row.values).map(([field, value]) => ({ field, value: this.valueOf(row, field) }));
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.api
|
||||
.listOcrJobs()
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: ({ jobs }) => {
|
||||
this.jobs.set(jobs);
|
||||
if (jobs.length) this.selectJob(jobs[0]);
|
||||
},
|
||||
error: (error) => this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar los tipos de extracción OCR.')),
|
||||
});
|
||||
}
|
||||
|
||||
selectJob(job: OcrJob): void {
|
||||
this.selectedJob.set(job);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
setStatus(status: OcrRowStatus): void {
|
||||
this.status.set(status);
|
||||
this.reload();
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
const job = this.selectedJob();
|
||||
if (!job) return;
|
||||
this.loading.set(true);
|
||||
this.loadError.set(null);
|
||||
this.api.listOcrRows(job.domain, job.entity, this.status()).subscribe({
|
||||
next: ({ rows, total }) => {
|
||||
this.loading.set(false);
|
||||
this.rows.set(rows);
|
||||
this.total.set(total);
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar las filas.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
runOcr(): void {
|
||||
const job = this.selectedJob();
|
||||
if (!job) return;
|
||||
this.running.set(true);
|
||||
this.api.runOcr(job.domain, job.entity).subscribe({
|
||||
next: (summary) => {
|
||||
this.running.set(false);
|
||||
this.snackBar.open(
|
||||
`OCR: ${summary.processed} leída(s), ${summary.needs_review} por revisar, ${summary.failed} fallida(s), ${summary.skipped_already_done} ya hechas.`,
|
||||
'OK',
|
||||
{ duration: 5000 },
|
||||
);
|
||||
this.reload();
|
||||
},
|
||||
error: (error) => {
|
||||
this.running.set(false);
|
||||
const message = apiErrorMessage(error, 'No se pudo correr la extracción.');
|
||||
this.snackBar.open(message, 'OK', { duration: 5000 });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
correct(row: OcrRow): void {
|
||||
const job = this.selectedJob();
|
||||
if (!job) return;
|
||||
this.correctingId.set(row.id);
|
||||
this.api.getOcrBlob(job.domain, job.entity, row.id).subscribe({
|
||||
next: (blob) => {
|
||||
this.correctingId.set(null);
|
||||
const file = new File([blob], `${job.entity}-${row.id}.pdf`, { type: 'application/pdf' });
|
||||
this.dialog
|
||||
.open<OcrCorrectionDialog, OcrCorrectionDialogData, OcrCorrectionResult>(OcrCorrectionDialog, {
|
||||
width: '1200px',
|
||||
maxWidth: '98vw',
|
||||
autoFocus: false,
|
||||
disableClose: true,
|
||||
data: {
|
||||
title: `Corregir · ${job.label} · ${row.pac_id_hospital ?? 'fila ' + row.id}`,
|
||||
file,
|
||||
fields: job.result_fields.map((name) => ({ name, label: name })),
|
||||
currentValues: row.values,
|
||||
},
|
||||
})
|
||||
.afterClosed()
|
||||
.subscribe((result) => {
|
||||
if (!result || Object.keys(result.values).length === 0) return;
|
||||
this.api.correctOcrRow(job.domain, job.entity, row.id, result.values).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Corrección guardada.', 'OK', { duration: 3000 });
|
||||
this.reload();
|
||||
},
|
||||
error: (error) => this.snackBar.open(apiErrorMessage(error, 'No se pudo guardar la corrección.'), 'OK', { duration: 5000 }),
|
||||
});
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
this.correctingId.set(null);
|
||||
this.snackBar.open(apiErrorMessage(error, 'No se pudo cargar el PDF de esta fila.'), 'OK', { duration: 5000 });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
valueOf(row: OcrRow, field: string): string {
|
||||
const value = row.values[field];
|
||||
return value === null || value === undefined || value === '' ? '—' : String(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user