Corrections of study fields; operator flow on ISSSTELEON's test source (SQL Server, two tables of PDFs)

This commit is contained in:
Roberto Treviño
2026-11-27 01:45:16 -06:00
parent 7dbb4b75fc
commit 9c89c9e10d
3 changed files with 113 additions and 78 deletions
+16 -7
View File
@@ -1,12 +1,12 @@
"""What waits for a person, and their decisions (append-only; the next run applies them)."""
from typing import Any, Literal
from typing import Any
from fastapi import APIRouter, Depends
from pydantic import BaseModel, model_validator
from core.pipeline import EntityName, Id, validate
from core.schema import Identity
from core.schema import ENTITIES
from persistance import nodes, review
from webapi.auth import Caller, caller
@@ -47,22 +47,31 @@ def decide_persons(decision: PersonDecision, who: Caller = Depends(caller)) -> d
class Correction(BaseModel):
"""One field of one record as a reviewer read it in the source document: an identity
field (a mistyped record number) or a study's (a stage the scan made unreadable)."""
entity: EntityName = "identity"
record: str
field: Literal[tuple(Identity.model_fields)] # type: ignore[valid-type]
field: str
value: str
@model_validator(mode="after")
def _a_valid_value(self):
if reasons := validate("identity", {self.field: self.value}):
if self.field not in ENTITIES[self.entity].model_fields:
raise ValueError(f"{self.entity} has no field {self.field}")
# only this field's own problems (a study's other required fields aren't given here)
reasons = [r for r in validate(self.entity, {self.field: self.value})
if r.split(":")[0] == self.field] # fmt: skip
if reasons:
raise ValueError("; ".join(reasons))
return self
@router.post("/corrections", status_code=201)
def correct(fix: Correction, who: Caller = Depends(caller)) -> dict[str, str]:
"""A corrected identity field of one record (e.g. a mistyped record number); linking
uses it on the next run. Fixing the source too is still worth it."""
nodes.correct(fix.record, fix.field, fix.value, who.id)
"""A corrected field of one record; the next run uses it (linking for identity fields,
the study's target for the others). Fixing the source too is still worth it."""
nodes.correct(fix.record, fix.field, fix.value, who.id, fix.entity)
return {"record": fix.record}