improve ingestion system to match isssteleon setup
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
(captions no known `FieldSpec` claimed, see `extraction.nlp.discovery`)
|
||||
into the silver layer directly: one synthetic `procedimiento` per record
|
||||
per estudio its resolved fields touch, with their `observacion`s matched
|
||||
or minted against the project's catalog (`catalog_matching`).
|
||||
against the project's catalog (`catalog_matching`). Only a source that
|
||||
asks for it (`catalog_fallback`) gets here, and only captions the catalog
|
||||
already knows are written: the catalog is versioned with the code, so a
|
||||
running import never adds to it. Captions nothing matches are counted;
|
||||
the import report lists them (`webapi.imports.audit`).
|
||||
|
||||
There is no staging row for these — the whole point is a field outside
|
||||
today's structured schemas — so this bypasses `DESDE_STAGING` and writes
|
||||
@@ -39,14 +43,16 @@ class CatalogCommitResult:
|
||||
records_without_patient: int = 0
|
||||
fields_matched: int = 0
|
||||
fields_minted: int = 0
|
||||
fields_unmatched: int = 0
|
||||
|
||||
|
||||
def commit_discovered_fields(
|
||||
records: list[ExtractedRecord], *, proyecto: str, estudio_id: str | None = None
|
||||
records: list[ExtractedRecord], *, proyecto: str, estudio_id: str | None = None, mint: bool = False
|
||||
) -> CatalogCommitResult:
|
||||
"""A patient without a row in `persona` is counted and skipped: this
|
||||
path only fills in fields for a patient already known, it doesn't
|
||||
create one."""
|
||||
create one. `mint` lets unmatched captions become new catalog entries,
|
||||
written to the catalog file; the import path never sets it."""
|
||||
dominio = import_module(f"persistance.{proyecto}")
|
||||
tablas = tablas_de(proyecto)
|
||||
ruta = ruta_de_catalogo(proyecto)
|
||||
@@ -63,7 +69,10 @@ def commit_discovered_fields(
|
||||
continue
|
||||
pac_id = patients[0].pac_id
|
||||
|
||||
matched = match_or_mint(record.discovered, proyecto=proyecto, catalogo=catalogo, estudio_id=estudio_id)
|
||||
matched = match_or_mint(record.discovered, proyecto=proyecto, catalogo=catalogo, estudio_id=estudio_id, mint=mint)
|
||||
result.fields_unmatched += len(record.discovered) - len(matched)
|
||||
if not matched:
|
||||
continue
|
||||
if any(field.is_new for field in matched):
|
||||
catalogo = catalogo_desde_toml(ruta, tablas=tablas) # so a later record in this batch can match it too
|
||||
matched = _fold_duplicates(matched)
|
||||
|
||||
Reference in New Issue
Block a user