One shell with the current look: indicators, follow-up list and patient view from FHIR; /conectar canvas; /revision; Playwright page tests
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
<section class="page">
|
||||
<h1>Revisión</h1>
|
||||
<p class="subtitle">
|
||||
Lo que la carga retuvo para que una persona decida. Cada decisión queda registrada y se aplica
|
||||
en la siguiente ejecución.
|
||||
</p>
|
||||
@if (message()) {
|
||||
<p class="message" role="status">{{ message() }}</p>
|
||||
}
|
||||
|
||||
<mat-tab-group animationDuration="0ms">
|
||||
<mat-tab [label]="'Retenidos (' + (held.value()?.length ?? 0) + ')'">
|
||||
<div class="bar">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Entidad</mat-label>
|
||||
<mat-select [value]="entity()" (selectionChange)="entity.set($event.value)">
|
||||
@for (e of entities; track e[0]) {
|
||||
<mat-option [value]="e[0]">{{ e[1] }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<table class="plain card">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Canalización</th>
|
||||
<th>Motivo</th>
|
||||
<th>Valores como llegaron</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of held.value() ?? []; track row['_record']) {
|
||||
<tr>
|
||||
<td>{{ row['_pipeline'] }} · {{ row['_target'] }}</td>
|
||||
<td>{{ reasons(row) }}</td>
|
||||
<td class="values">
|
||||
@for (v of values(row) | keyvalue; track v.key) {
|
||||
<span
|
||||
><b>{{ v.key }}</b
|
||||
>: {{ text(v.value) }}</span
|
||||
>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
mat-stroked-button
|
||||
[disabled]="decided().has($any(row['_record']))"
|
||||
(click)="rejectRow(entity(), $any(row['_record']), reasons(row))"
|
||||
>
|
||||
Rechazar
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="4" class="muted">Nada retenido.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab [label]="'Conflictos (' + (conflicts.value()?.length ?? 0) + ')'">
|
||||
<div class="bar">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Entidad</mat-label>
|
||||
<mat-select [value]="entity()" (selectionChange)="entity.set($event.value)">
|
||||
@for (e of entities; track e[0]) {
|
||||
<mat-option [value]="e[0]">{{ e[1] }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<span class="muted"
|
||||
>Registros de una misma paciente y fecha que no coinciden: rechace los equivocados.</span
|
||||
>
|
||||
</div>
|
||||
<table class="plain card">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paciente</th>
|
||||
<th>Valores</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of conflicts.value() ?? []; track row['_record']) {
|
||||
<tr>
|
||||
<td>
|
||||
<code>{{ text(row['person_id']).slice(0, 10) }}</code>
|
||||
</td>
|
||||
<td class="values">
|
||||
@for (v of values(row) | keyvalue; track v.key) {
|
||||
<span
|
||||
><b>{{ v.key }}</b
|
||||
>: {{ text(v.value) }}</span
|
||||
>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
mat-stroked-button
|
||||
[disabled]="decided().has($any(row['_record']))"
|
||||
(click)="rejectRow(entity(), $any(row['_record']), 'conflicto')"
|
||||
>
|
||||
Rechazar
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="3" class="muted">Sin conflictos.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</mat-tab>
|
||||
|
||||
<mat-tab label="Personas">
|
||||
<div class="bar">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Canalización</mat-label>
|
||||
<mat-select
|
||||
[value]="pipeline()"
|
||||
(selectionChange)="pipeline.set($event.value); node.set(undefined)"
|
||||
>
|
||||
@for (p of pipelines.value() ?? []; track p['pipeline_id']) {
|
||||
<mat-option [value]="p['pipeline_id']">{{ p['pipeline_id'] }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
@if ((links.value() ?? []).length > 1) {
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Nodo de vinculación</mat-label>
|
||||
<mat-select [value]="link()" (selectionChange)="node.set($event.value)">
|
||||
@for (l of links.value() ?? []; track l) {
|
||||
<mat-option [value]="l">{{ l }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
}
|
||||
@if (pipeline()) {
|
||||
<button
|
||||
mat-flat-button
|
||||
(click)="apply()"
|
||||
[disabled]="!!run() && !['SUCCESS', 'FAILURE', 'CANCELED'].includes(run())"
|
||||
>
|
||||
Aplicar decisiones (ejecutar)
|
||||
</button>
|
||||
@if (run()) {
|
||||
<span class="muted">Ejecución: {{ run() }}</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (persons.value(); as p) {
|
||||
<h2>Posibles pacientes duplicadas ({{ p['to_settle'].length }})</h2>
|
||||
@for (entry of p['to_settle']; track entry['person']) {
|
||||
<div class="card person">
|
||||
<div>
|
||||
<b>Registro</b> <code>{{ text(entry['person']).slice(0, 10) }}</code> ·
|
||||
{{ text(entry['record_number']) }} · {{ text(entry['full_name']) }} ·
|
||||
{{ text(entry['birth_date']) }}
|
||||
</div>
|
||||
@for (c of candidates(entry); track c['candidate']) {
|
||||
<div class="candidate">
|
||||
<span
|
||||
>¿Es <code>{{ text(c['candidate']).slice(0, 10) }}</code> ({{
|
||||
text(c['record_number'])
|
||||
}}
|
||||
· {{ text(c['full_name']) }} · {{ text(c['birth_date']) }})?
|
||||
<span class="muted"
|
||||
>{{ c['reason'] }}
|
||||
@if (c['probability'] !== null) {
|
||||
· p = {{ $any(c['probability']) | number: '1.2-2' }}
|
||||
}
|
||||
</span></span
|
||||
>
|
||||
<button
|
||||
mat-stroked-button
|
||||
[disabled]="decided().has(entry['person'] + '|' + c['candidate'])"
|
||||
(click)="decide($any(entry['person']), $any(c['candidate']), true)"
|
||||
>
|
||||
Misma paciente
|
||||
</button>
|
||||
<button
|
||||
mat-stroked-button
|
||||
[disabled]="decided().has(entry['person'] + '|' + c['candidate'])"
|
||||
(click)="decide($any(entry['person']), $any(c['candidate']), false)"
|
||||
>
|
||||
Distintas
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @empty {
|
||||
<p class="muted">Nada que decidir.</p>
|
||||
}
|
||||
|
||||
<h2>Registros que no coinciden en fecha de nacimiento o sexo ({{ p['torn'].length }})</h2>
|
||||
@for (entry of p['torn']; track entry['person']) {
|
||||
<div class="card person">
|
||||
@for (r of records(entry); track r['_record']) {
|
||||
<div class="candidate">
|
||||
<span class="values">
|
||||
@for (v of values(r) | keyvalue; track v.key) {
|
||||
<span
|
||||
><b>{{ v.key }}</b
|
||||
>: {{ text(v.value) }}</span
|
||||
>
|
||||
}
|
||||
</span>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="small">
|
||||
<mat-label>Campo</mat-label>
|
||||
<mat-select #field value="record_number">
|
||||
@for (f of fields; track f) {
|
||||
<mat-option [value]="f">{{ f }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="small">
|
||||
<mat-label>Valor correcto</mat-label>
|
||||
<input matInput #value />
|
||||
</mat-form-field>
|
||||
<button
|
||||
mat-stroked-button
|
||||
(click)="fix($any(r['_record']), field.value, value.value)"
|
||||
>
|
||||
Corregir
|
||||
</button>
|
||||
<button
|
||||
mat-stroked-button
|
||||
[disabled]="decided().has($any(r['_record']))"
|
||||
(click)="rejectRow('identity', $any(r['_record']), 'identidad equivocada')"
|
||||
>
|
||||
Rechazar
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @empty {
|
||||
<p class="muted">Nada que decidir.</p>
|
||||
}
|
||||
}
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
</section>
|
||||
@@ -0,0 +1,48 @@
|
||||
.bar {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
margin: var(--space-4) 0;
|
||||
}
|
||||
|
||||
.message {
|
||||
background: var(--color-action-hover);
|
||||
border-left: 3px solid var(--color-action);
|
||||
padding: var(--space-2) var(--space-3);
|
||||
}
|
||||
|
||||
.values span {
|
||||
display: inline-block;
|
||||
font-size: 13px;
|
||||
margin-right: var(--space-3);
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.05rem;
|
||||
font-weight: 500;
|
||||
margin: var(--space-6) 0 var(--space-2);
|
||||
}
|
||||
|
||||
.person {
|
||||
margin-bottom: var(--space-3);
|
||||
}
|
||||
|
||||
.candidate {
|
||||
align-items: center;
|
||||
border-top: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
margin-top: var(--space-2);
|
||||
padding-top: var(--space-2);
|
||||
}
|
||||
|
||||
.candidate > span:first-child {
|
||||
flex: 1;
|
||||
min-width: 280px;
|
||||
}
|
||||
|
||||
.small {
|
||||
width: 160px;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { DecimalPipe, KeyValuePipe } from '@angular/common';
|
||||
import { Component, computed, inject, linkedSignal, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { Api } from '../api/api';
|
||||
import { pipeline as getPipeline } from '../api/fn/ingest/pipeline';
|
||||
import { pipelines } from '../api/fn/ingest/pipelines';
|
||||
import { startRun } from '../api/fn/ingest/start-run';
|
||||
import { conflicts } from '../api/fn/review/conflicts';
|
||||
import { correct } from '../api/fn/review/correct';
|
||||
import { decidePersons } from '../api/fn/review/decide-persons';
|
||||
import { held } from '../api/fn/review/held';
|
||||
import { persons } from '../api/fn/review/persons';
|
||||
import { reject } from '../api/fn/review/reject';
|
||||
import { runStatus } from '../api/fn/runs/run-status';
|
||||
import type { Correction } from '../api/models/correction';
|
||||
import type { Rejection } from '../api/models/rejection';
|
||||
|
||||
type Entity = Rejection['entity'];
|
||||
type Row = Record<string, unknown>;
|
||||
|
||||
const ENTITIES: Record<Entity, string> = {
|
||||
cervical_cytology: 'Citología cervical',
|
||||
cervical_biopsy: 'Biopsia cervical',
|
||||
clinical_note: 'Nota médica',
|
||||
death: 'Defunción',
|
||||
identity: 'Identidad',
|
||||
mammography: 'Mastografía',
|
||||
breast_biopsy: 'Biopsia de mama',
|
||||
};
|
||||
const IDENTITY_FIELDS: Correction['field'][] = [
|
||||
'record_number',
|
||||
'full_name',
|
||||
'curp',
|
||||
'nss',
|
||||
'birth_date',
|
||||
'sex',
|
||||
'postal_code',
|
||||
];
|
||||
/** Bookkeeping columns, not values a reviewer judges. */
|
||||
const HIDDEN = [
|
||||
'_pipeline',
|
||||
'_target',
|
||||
'_record',
|
||||
'_held',
|
||||
'_raw',
|
||||
'_quotes',
|
||||
'_index',
|
||||
'rows_merged',
|
||||
'known_at',
|
||||
];
|
||||
|
||||
/** /revision: what ingestion held for a person to decide. Every decision is logged and
|
||||
* applied on the pipeline's next run. */
|
||||
@Component({
|
||||
selector: 'app-revision',
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
KeyValuePipe,
|
||||
FormsModule,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
MatTabsModule,
|
||||
],
|
||||
templateUrl: './revision.html',
|
||||
styleUrl: './revision.scss',
|
||||
})
|
||||
export class Revision {
|
||||
private readonly api = inject(Api);
|
||||
protected readonly entities = Object.entries(ENTITIES) as [Entity, string][];
|
||||
protected readonly fields = IDENTITY_FIELDS;
|
||||
|
||||
protected readonly entity = signal<Entity>('cervical_cytology');
|
||||
protected readonly held = resource({
|
||||
params: () => this.entity(),
|
||||
loader: ({ params }) => this.api.invoke(held, { entity: params }),
|
||||
});
|
||||
protected readonly conflicts = resource({
|
||||
params: () => this.entity(),
|
||||
loader: ({ params }) => this.api.invoke(conflicts, { entity: params }),
|
||||
});
|
||||
|
||||
/** The pipeline and link node whose persons are reviewed. */
|
||||
protected readonly pipelines = resource({ loader: () => this.api.invoke(pipelines) });
|
||||
/** The chosen pipeline; the first one until the reviewer picks another. */
|
||||
protected readonly pipeline = linkedSignal<string | undefined>(
|
||||
() => this.pipelines.value()?.[0]?.['pipeline_id'],
|
||||
);
|
||||
protected readonly links = resource({
|
||||
params: () => this.pipeline(),
|
||||
loader: async ({ params }) => {
|
||||
if (!params) return [];
|
||||
const saved = await this.api.invoke(getPipeline, { pipeline_id: params });
|
||||
return saved.pipeline.nodes.filter((n) => n.kind === 'link').map((n) => n.id);
|
||||
},
|
||||
});
|
||||
protected readonly node = signal<string | undefined>(undefined);
|
||||
protected readonly link = computed(() => this.node() ?? this.links.value()?.[0]);
|
||||
protected readonly persons = resource({
|
||||
params: () => ({ pipeline: this.pipeline(), node: this.link() }),
|
||||
loader: ({ params }) =>
|
||||
params.pipeline && params.node
|
||||
? this.api.invoke(persons, { pipeline: params.pipeline, node: params.node })
|
||||
: Promise.resolve({ to_settle: [], torn: [] } as Record<string, Row[]>),
|
||||
});
|
||||
|
||||
protected readonly message = signal('');
|
||||
protected readonly decided = signal(new Set<string>());
|
||||
protected readonly run = signal<string>('');
|
||||
protected readonly entityLabel = ENTITIES;
|
||||
|
||||
protected values(row: Row): Row {
|
||||
const raw = (row['_raw'] as Row | undefined) ?? row;
|
||||
return Object.fromEntries(
|
||||
Object.entries(raw).filter(([k]) => !HIDDEN.includes(k) && !k.startsWith('_dlt')),
|
||||
);
|
||||
}
|
||||
protected reasons(row: Row): string {
|
||||
const found = row['_held'];
|
||||
return Array.isArray(found) ? found.join('; ') : String(found ?? '');
|
||||
}
|
||||
protected text(value: unknown): string {
|
||||
return typeof value === 'object' && value !== null
|
||||
? JSON.stringify(value)
|
||||
: String(value ?? '—');
|
||||
}
|
||||
protected candidates(entry: Row): Row[] {
|
||||
return (entry['candidates'] as Row[]) ?? [];
|
||||
}
|
||||
protected records(entry: Row): Row[] {
|
||||
return (entry['records'] as Row[]) ?? [];
|
||||
}
|
||||
|
||||
private async done(key: string, call: Promise<unknown>, what: string): Promise<void> {
|
||||
try {
|
||||
await call;
|
||||
this.decided.update((s) => new Set(s).add(key));
|
||||
this.message.set(`${what} Se aplica en la siguiente ejecución.`);
|
||||
} catch (e) {
|
||||
this.message.set(
|
||||
e instanceof HttpErrorResponse ? JSON.stringify(e.error?.detail ?? e.message) : String(e),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected rejectRow(entity: Entity, record: string, reason: string): Promise<void> {
|
||||
return this.done(
|
||||
record,
|
||||
this.api.invoke(reject, { body: { entity, record, reason } }),
|
||||
'Registro rechazado.',
|
||||
);
|
||||
}
|
||||
|
||||
protected decide(person: string, candidate: string, same: boolean): Promise<void> {
|
||||
const body = { person, candidate, same };
|
||||
return this.done(
|
||||
`${person}|${candidate}`,
|
||||
this.api.invoke(decidePersons, { body }),
|
||||
'Decisión registrada.',
|
||||
);
|
||||
}
|
||||
|
||||
protected fix(record: string, field: Correction['field'], value: string): Promise<void> {
|
||||
return this.done(
|
||||
`${record}|${field}`,
|
||||
this.api.invoke(correct, { body: { record, field, value } }),
|
||||
'Corrección registrada.',
|
||||
);
|
||||
}
|
||||
|
||||
/** Runs the pipeline so the decisions apply, then reloads what is left. */
|
||||
protected async apply(): Promise<void> {
|
||||
const id = this.pipeline();
|
||||
if (!id) return;
|
||||
const { run_id } = await this.api.invoke(startRun, { pipeline_id: id, body: {} });
|
||||
let status = 'STARTING';
|
||||
while (!['SUCCESS', 'FAILURE', 'CANCELED'].includes(status)) {
|
||||
this.run.set(status);
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
status = (await this.api.invoke(runStatus, { run_id }))['status'];
|
||||
}
|
||||
this.run.set(status);
|
||||
this.decided.set(new Set());
|
||||
this.held.reload();
|
||||
this.conflicts.reload();
|
||||
this.persons.reload();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user