Review persons: settle possible splits, correct identity fields; operator test settles everything
This commit is contained in:
+42
-7
@@ -1,11 +1,12 @@
|
||||
"""What waits for a person, and their decisions (append-only; the next run applies them)."""
|
||||
|
||||
from typing import Any
|
||||
from typing import Any, Literal
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
from core.pipeline import EntityName, Id
|
||||
from core.pipeline import EntityName, Id, validate
|
||||
from core.schema import Identity
|
||||
from persistance import nodes, review
|
||||
from webapi.auth import Caller, caller
|
||||
|
||||
@@ -25,10 +26,44 @@ def conflicts(entity: EntityName) -> Rows:
|
||||
return review.conflicts(entity)
|
||||
|
||||
|
||||
@router.get("/links")
|
||||
def links(pipeline: Id, node: Id) -> Rows:
|
||||
"""Records that may be the same person but were left apart."""
|
||||
return review.links(pipeline, node)
|
||||
@router.get("/persons")
|
||||
def persons(pipeline: Id, node: Id) -> dict[str, Rows]:
|
||||
"""Persons to settle (with their possible owners) and torn persons (with their
|
||||
records) left by a pipeline's link node."""
|
||||
return review.persons(pipeline, node)
|
||||
|
||||
|
||||
class PersonDecision(BaseModel):
|
||||
person: str
|
||||
candidate: str
|
||||
same: bool
|
||||
|
||||
|
||||
@router.post("/persons", status_code=201)
|
||||
def decide_persons(decision: PersonDecision, who: Caller = Depends(caller)) -> dict[str, str]:
|
||||
"""Whether a person and a possible owner are one patient; applied on the next run."""
|
||||
nodes.decide_persons(decision.person, decision.candidate, decision.same, who.id)
|
||||
return {"person": decision.person}
|
||||
|
||||
|
||||
class Correction(BaseModel):
|
||||
record: str
|
||||
field: Literal[tuple(Identity.model_fields)] # type: ignore[valid-type]
|
||||
value: str
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _a_valid_value(self):
|
||||
if reasons := validate("identity", {self.field: self.value}):
|
||||
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)
|
||||
return {"record": fix.record}
|
||||
|
||||
|
||||
class Rejection(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user