integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<h2 mat-dialog-title>Cargar a la base de datos · {{ store.domain().toUpperCase() }}</h2>
|
||||
<mat-dialog-content>
|
||||
@if (validating()) {
|
||||
<p class="lead">Validando todas las filas de {{ flows().length }} flujo(s)…</p>
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Validando"></mat-progress-bar>
|
||||
} @else {
|
||||
@if (!batch()) {
|
||||
<p class="lead">
|
||||
Se escribirán <strong>{{ totals().valid | number }}</strong> filas válidas de {{ totals().rows | number }} en
|
||||
{{ flows().length }} flujo(s), en una sola transacción: si algo falla en la base, no se escribe nada.
|
||||
@if (totals().errors > 0) {
|
||||
<strong class="warn">{{ totals().errors | number }} fila(s) con errores se omitirán.</strong>
|
||||
}
|
||||
</p>
|
||||
} @else if (outcome(); as o) {
|
||||
<p class="lead lead--done">
|
||||
<mat-icon aria-hidden="true">cloud_done</mat-icon>
|
||||
Carga completa: {{ o.created | number }} insertadas, {{ o.updated | number }} actualizadas, {{ o.rejected | number }} omitidas.
|
||||
@if (o.merged) {
|
||||
{{ o.merged | number }} combinadas con registros de otras fuentes@if (o.warnings) {, {{ o.warnings | number }} valor(es) en desacuerdo}.
|
||||
}
|
||||
</p>
|
||||
}
|
||||
|
||||
<table mat-table [dataSource]="flows()" class="flows">
|
||||
<ng-container matColumnDef="flow">
|
||||
<th mat-header-cell *matHeaderCellDef>Flujo</th>
|
||||
<td mat-cell *matCellDef="let flow">
|
||||
<span class="flows__name">{{ flow.table.name }}</span>
|
||||
<span class="flows__target">→ {{ flow.target.table }}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="status">
|
||||
<th mat-header-cell *matHeaderCellDef>Estado</th>
|
||||
<td mat-cell *matCellDef="let flow"><app-flow-status [status]="flow.status()"></app-flow-status></td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="rows">
|
||||
<th mat-header-cell *matHeaderCellDef>Filas</th>
|
||||
<td mat-cell *matCellDef="let flow">{{ flow.validation()?.total_rows | number }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="valid">
|
||||
<th mat-header-cell *matHeaderCellDef>Válidas</th>
|
||||
<td mat-cell *matCellDef="let flow">{{ flow.validation()?.valid_count | number }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="errors">
|
||||
<th mat-header-cell *matHeaderCellDef>Con error</th>
|
||||
<td mat-cell *matCellDef="let flow" [class.warn]="flow.validation()?.error_count">{{ flow.validation()?.error_count | number }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="outcome">
|
||||
<th mat-header-cell *matHeaderCellDef>Resultado</th>
|
||||
<td mat-cell *matCellDef="let flow">
|
||||
@if (resultOf(flow); as result) {
|
||||
+{{ result.created }} · ↻{{ result.updated }} · ✕{{ result.rejected }}@if (result.merged) { · ⧉{{ result.merged }} }
|
||||
} @else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="columns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: columns"></tr>
|
||||
</table>
|
||||
|
||||
@if (skipped().length > 0) {
|
||||
<p class="note">
|
||||
<mat-icon aria-hidden="true">info</mat-icon>
|
||||
{{ skipped().length }} flujo(s) no se cargarán porque no están listos (faltan obligatorios o la fuente falló).
|
||||
</p>
|
||||
}
|
||||
|
||||
@if (!batch()) {
|
||||
<section class="policy" aria-labelledby="policy-title">
|
||||
<h3 id="policy-title">Si un registro ya existe en la base</h3>
|
||||
<mat-radio-group [value]="store.upsertAvailable() ? store.onConflict() : 'reject'" (change)="setStrategy($event.value)">
|
||||
<mat-radio-button value="reject">Omitirlo (se reporta como conflicto)</mat-radio-button>
|
||||
<mat-radio-button value="upsert" [disabled]="!store.upsertAvailable()">
|
||||
Actualizarlo con los campos mapeados (los demás campos no se tocan)
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
@if (!store.upsertAvailable()) {
|
||||
<p class="note">Actualizar solo es posible cuando todas las tablas destino tienen clave natural (p. ej. Paciente).</p>
|
||||
}
|
||||
</section>
|
||||
@if (mergeAvailable()) {
|
||||
<section class="policy" aria-labelledby="merge-title">
|
||||
<h3 id="merge-title">Datos de un mismo paciente en varias fuentes</h3>
|
||||
<mat-checkbox [checked]="store.mergeDuplicates()" (change)="toggleMerge($event.checked)">
|
||||
Combinar las filas con la misma clave en un solo registro antes de validar
|
||||
</mat-checkbox>
|
||||
<p class="note">
|
||||
Cada fuente completa los campos que a las demás les faltan; si dos fuentes no coinciden en un valor se conserva
|
||||
el del primer flujo y se reporta. La validación previa por flujo no considera esta combinación.
|
||||
</p>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
@if (store.committing()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Cargando"></mat-progress-bar>
|
||||
}
|
||||
@if (store.commitError(); as error) {
|
||||
<p class="error" role="alert"><mat-icon aria-hidden="true">error</mat-icon>{{ error }}</p>
|
||||
}
|
||||
}
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
@if (batch()) {
|
||||
<button mat-button mat-dialog-close type="button">Cerrar</button>
|
||||
<button mat-flat-button type="button" (click)="explore()"><mat-icon aria-hidden="true">travel_explore</mat-icon>Explorar la base</button>
|
||||
} @else {
|
||||
<button mat-button mat-dialog-close type="button">Cancelar</button>
|
||||
<button mat-flat-button type="button" [disabled]="validating() || store.committing() || !canLoad()" (click)="load()">
|
||||
<mat-icon aria-hidden="true">cloud_upload</mat-icon>Cargar {{ totals().valid | number }} filas
|
||||
</button>
|
||||
}
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,60 @@
|
||||
.lead {
|
||||
font: var(--mat-sys-body-large);
|
||||
margin-top: 0;
|
||||
max-width: 760px;
|
||||
}
|
||||
|
||||
.lead--done {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-primary);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.warn {
|
||||
color: #9a5b00;
|
||||
}
|
||||
|
||||
.flows {
|
||||
--mat-table-row-item-container-height: 44px;
|
||||
margin-bottom: var(--space-3);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.flows__name {
|
||||
font: var(--mat-sys-title-small);
|
||||
}
|
||||
|
||||
.flows__target {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
margin-left: var(--space-2);
|
||||
}
|
||||
|
||||
.note,
|
||||
.error {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
font: var(--mat-sys-body-small);
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.error {
|
||||
color: var(--mat-sys-error);
|
||||
}
|
||||
|
||||
.policy {
|
||||
border-top: 1px solid var(--mat-sys-outline-variant);
|
||||
margin-top: var(--space-3);
|
||||
padding-top: var(--space-3);
|
||||
|
||||
h3 {
|
||||
font: var(--mat-sys-title-small);
|
||||
margin: 0 0 var(--space-2);
|
||||
}
|
||||
|
||||
mat-radio-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, OnInit, computed, inject, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { ConflictStrategy } from '../../api/api.types';
|
||||
import { ImportFlow } from '../../domain/import-flow';
|
||||
import { ConnectWorkspaceStore } from '../../state/connect-workspace.store';
|
||||
import { FlowStatusChip } from '../shared/flow-status';
|
||||
|
||||
export type LoadDialogResult = 'explore' | undefined;
|
||||
|
||||
/**
|
||||
* "Cargar a la base": validates every flow, shows what will be written,
|
||||
* sets the batch options (conflict policy, merging a patient's data spread
|
||||
* across sources) and loads the batch in one request and one transaction.
|
||||
* Rows failing validation are skipped and reported, never written.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-load-dialog',
|
||||
imports: [DecimalPipe, FlowStatusChip, MatButtonModule, MatCheckboxModule, MatDialogModule, MatIconModule, MatProgressBarModule, MatRadioModule, MatTableModule],
|
||||
templateUrl: './load-dialog.html',
|
||||
styleUrl: './load-dialog.scss',
|
||||
})
|
||||
export class LoadDialog implements OnInit {
|
||||
readonly store = inject(ConnectWorkspaceStore);
|
||||
private readonly dialogRef = inject<MatDialogRef<LoadDialog, LoadDialogResult>>(MatDialogRef);
|
||||
|
||||
readonly columns = ['flow', 'status', 'rows', 'valid', 'errors', 'outcome'];
|
||||
readonly validating = signal(true);
|
||||
/** Whether merging is even possible here; independent of the checkbox itself. */
|
||||
readonly mergeAvailable = this.store.mergeAvailable;
|
||||
/** With merging, rows incomplete on their own may be completed by another source. */
|
||||
readonly canLoad = computed(() => this.totals().valid > 0 || (this.store.mergeDuplicates() && this.totals().rows > 0));
|
||||
|
||||
/**
|
||||
* The flows the next batch would write. Reactive to the merge checkbox
|
||||
* while nothing has loaded yet, so ticking it reveals the flow it
|
||||
* completes; frozen the moment a batch starts, so the results table
|
||||
* keeps listing exactly what was sent.
|
||||
*/
|
||||
private readonly _frozenFlows = signal<ImportFlow[] | null>(null);
|
||||
readonly flows = computed(() => this._frozenFlows() ?? this.store.submittableFlows());
|
||||
readonly skipped = computed(() => this.store.flows().filter((flow) => !this.flows().includes(flow) && !flow.canSubmit));
|
||||
|
||||
readonly totals = computed(() =>
|
||||
this.flows().reduce(
|
||||
(acc, flow) => {
|
||||
const validation = flow.validation();
|
||||
acc.rows += validation?.total_rows ?? 0;
|
||||
acc.valid += validation?.valid_count ?? 0;
|
||||
acc.errors += validation?.error_count ?? 0;
|
||||
return acc;
|
||||
},
|
||||
{ rows: 0, valid: 0, errors: 0 },
|
||||
),
|
||||
);
|
||||
|
||||
readonly batch = this.store.lastBatch;
|
||||
readonly outcome = computed(() => {
|
||||
const batch = this.batch();
|
||||
if (!batch) return null;
|
||||
return batch.results.reduce(
|
||||
(acc, result) => ({
|
||||
created: acc.created + result.created,
|
||||
updated: acc.updated + result.updated,
|
||||
rejected: acc.rejected + result.rejected,
|
||||
merged: acc.merged + (result.merged ?? 0),
|
||||
warnings: acc.warnings + (result.warnings?.length ?? 0),
|
||||
}),
|
||||
{ created: 0, updated: 0, rejected: 0, merged: 0, warnings: 0 },
|
||||
);
|
||||
});
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
await Promise.all(this.flows().filter((flow) => !flow.validation()).map((flow) => this.store.validate(flow)));
|
||||
this.validating.set(false);
|
||||
}
|
||||
|
||||
setStrategy(strategy: ConflictStrategy): void {
|
||||
this.store.setOnConflict(strategy);
|
||||
}
|
||||
|
||||
/** Toggling may bring an until-now-skipped flow into `flows()`; preview its rows too. */
|
||||
toggleMerge(merge: boolean): void {
|
||||
this.store.setMergeDuplicates(merge);
|
||||
Promise.all(this.flows().filter((flow) => !flow.validation()).map((flow) => this.store.validate(flow)));
|
||||
}
|
||||
|
||||
load(): void {
|
||||
this._frozenFlows.set(this.store.submittableFlows());
|
||||
this.store.commit().subscribe();
|
||||
}
|
||||
|
||||
explore(): void {
|
||||
this.dialogRef.close('explore');
|
||||
}
|
||||
|
||||
resultOf(flow: ImportFlow) {
|
||||
return flow.result();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user