add bitacora page, self-hosted fonts/icons, review fixes for the install package

This commit is contained in:
Roberto Treviño Cervantes
2026-10-30 11:19:34 -06:00
parent 8c63ed83ac
commit f4d2a3e85f
39 changed files with 275 additions and 721 deletions
@@ -1,61 +0,0 @@
<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>
@@ -1,32 +0,0 @@
.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;
}
}
@@ -1,51 +0,0 @@
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.'));
},
});
}
}
@@ -1,79 +0,0 @@
<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>
@@ -1,45 +0,0 @@
.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;
}
@@ -1,110 +0,0 @@
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;
}
}
@@ -12,11 +12,6 @@
<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>
@@ -1,18 +1,17 @@
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
* The "Gobernanza de modelos" page (route `/gobernanza`): model versions
* 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],
imports: [MatTabsModule, MatToolbarModule, ModelVersionsPanel, OcrReviewPanel],
templateUrl: './governance-page.html',
styleUrl: './governance-page.scss',
})
@@ -58,18 +58,23 @@
<section aria-labelledby="cohort-title">
<h3 id="cohort-title">Cohorte de entrenamiento</h3>
@if (l.cohort_version; as cohort) {
@if (l.cohorte_armado; as armado) {
<p>
{{ cohort.domain }} · {{ cohort.scenario }} · criterio {{ cohort.criteria_version }} ·
{{ cohort.n_included | number }} de {{ cohort.n_source | number }} episodios
{{ armado.url }} · versión {{ armado.version }} · {{ armado.n_miembros | number }} miembros ·
datos al {{ armado.datos_as_of | date: 'mediumDate' }}
</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>
<p class="hash" [matTooltip]="armado.huella">huella {{ armado.huella.slice(0, 12) }}… · armado {{ armado.armado_id }}</p>
@if (l.cohorte_exclusiones.length) {
<table class="exclusions">
<thead>
<tr><th>#</th><th>Paso</th><th>Quedan</th></tr>
</thead>
<tbody>
@for (paso of l.cohorte_exclusiones; track paso.orden) {
<tr><td>{{ paso.orden }}</td><td>{{ paso.paso }}</td><td>{{ paso.n | number }}</td></tr>
}
</tbody>
</table>
}
} @else {
<p class="muted">Sin cohorte enlazada.</p>
@@ -49,8 +49,7 @@
}
.checks,
.artifacts,
.exclusions {
.artifacts {
display: flex;
flex-direction: column;
gap: var(--space-1);
@@ -111,3 +110,19 @@
justify-self: start;
}
}
.exclusions {
border-collapse: collapse;
font-size: 0.875rem;
th,
td {
padding: var(--space-1) var(--space-2);
text-align: left;
}
td:last-child,
th:last-child {
text-align: right;
}
}
@@ -26,7 +26,7 @@ export const ARTIFACT_KINDS: { id: string; label: string }[] = [
];
/**
* One model version: what it was trained on (cohort hash and exclusions),
* One model version: what it was trained on (the kit's cohort build and its attrition),
* 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.
@@ -45,9 +45,9 @@
</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 matColumnDef="armado">
<th mat-header-cell *matHeaderCellDef>Armado de cohorte</th>
<td mat-cell *matCellDef="let v">{{ v.tags['kit.armado_id'] ?? 'Sin enlazar' }}</td>
</ng-container>
<ng-container matColumnDef="status">
@@ -51,7 +51,7 @@ export class ModelVersionsPanel implements OnInit {
readonly loading = signal(false);
readonly loadError = signal<string | null>(null);
readonly displayedColumns = ['version', 'scenario', 'environment', 'cohort_version_id', 'status', 'created_at', 'acciones'];
readonly displayedColumns = ['version', 'scenario', 'environment', 'armado', 'status', 'created_at', 'acciones'];
ngOnInit(): void {
this.reload();