Compare commits

...

43 Commits

Author SHA1 Message Date
rockdrigo 18b25f0cef Bump WebApp: CaMa stratifiers break down BI-RADS and histology, in counts or percentages 2026-11-12 19:19:37 -06:00
rockdrigo 041a7997cb Bump WebApp: «Análisis epidemiológico» with chosen comparisons and drill-down to Seguimiento 2026-11-12 18:38:12 -06:00
rockdrigo 268703e272 Bump WebApp: «Análisis» by stage, development, recurrence and survival 2026-11-12 14:04:58 -06:00
rockdrigo ec6926601d Bump WebApp: «Análisis» in survival, subgroup explorer and cohort diagnostics 2026-11-12 13:49:20 -06:00
rockdrigo e51ce8b71e Merge origin/dashboard-test: the WebApp pointer at the reconciled CaMa dashboard
How:
- dashboard-test brings dev's line since the preliminary release (Core,
  Persistance, Transformation, the import of files in columns) and its
  WebApi, models and indicadores_kit pointers; this branch had changed none
  of them.
- The WebApp pointer, the only conflict, points to the WebApp merge of
  dashboard-test into features/cama-mock: dashboard-test's CaMa wiring with
  the mock's TEA, CaCu and Análisis views kept.

Implications:
- The deliverable tree on this branch is dashboard-test's plus the WebApp
  views the mock adds; nothing outside WebApp differs from dashboard-test.
2026-11-12 13:35:58 -06:00
rockdrigo 1bebec7f71 Bump WebApp: «Análisis» tab for breast cancer 2026-11-12 12:42:54 -06:00
Angel Capetillo Zavala 0f6da3d7db Pin integrated CaMa dashboard components 2026-11-12 12:17:02 -06:00
Angel Capetillo Zavala 175914891a chore: integrate WebApp history and indicators shell 2026-11-12 01:49:44 -06:00
Angel Capetillo Zavala 056ce791d8 chore: update WebApp CaMa dashboard integration 2026-11-12 00:40:05 -06:00
Angel Capetillo Zavala 907a8ce540 chore: update WebApp dashboard-test pointer 2026-11-11 23:59:53 -06:00
Angel Capetillo Zavala 621aafb6eb Pin models to dev revision 2026-11-11 20:44:25 -06:00
Roberto Treviño Cervantes 2188d7a5e8 Submodule pointers: WebApi and indicadores_kit at their dev with import files in columns 2026-11-11 11:20:13 -06:00
Roberto Treviño Cervantes d8ff604b6f import files in columns 2026-11-11 11:19:41 -06:00
rockdrigo f36b029072 chore(webapp): update submodule with fewer card texts and pins only from five indicators 2026-11-09 20:37:49 -06:00
rockdrigo 213f5c5bf1 chore(webapp): update submodule with the confirmation donut's outside labels 2026-11-09 20:26:24 -06:00
rockdrigo df3d902bf3 chore(webapp): update submodule with the detection-rate card without its interval 2026-11-09 20:15:12 -06:00
rockdrigo c22648b27a chore(webapp): update submodule with the expanding confirmation donut 2026-11-09 20:11:05 -06:00
rockdrigo 19dfb0c0de chore(webapp): update submodule with the clickable confirmation donut 2026-11-09 20:05:23 -06:00
rockdrigo 3c4ea1a753 chore(webapp): update submodule with the CaMa confirmation view and the paired BI-RADS counts 2026-11-09 19:56:36 -06:00
rockdrigo 85b0834c59 chore(webapp): update submodule with opportunity cards that fill their row 2026-11-09 19:30:25 -06:00
rockdrigo eb6e20e3f0 chore(webapp): update submodule with the previous Resumen design and four equal CaMa cards 2026-11-09 19:15:45 -06:00
rockdrigo 53b7eeefae chore(webapp): update submodule with the search threshold, Resumen as questions and equal card sizes 2026-11-09 19:09:36 -06:00
rockdrigo 8d2d6ec1d0 chore(webapp): update submodule with the four CaMa cards and cards without the Disponible state 2026-11-09 18:49:45 -06:00
rockdrigo 89c366a669 chore(webapp): update submodule with the CaMa cards, months, compact filters, texts and institutional styling
How: points WebApp to features/cama-mock at the commit that closes this round:
header domain menu, CaMa opportunity cards with the Wilson interval, compact
general filters, "cáncer de mama" wording and the institutional styling.

Implications: none beyond those of each WebApp commit, which describe them.
2026-11-09 18:26:52 -06:00
rockdrigo 2af9d6df1e chore(webapp): update submodule with the CaMa tabs, follow-up list and BI-RADS view 2026-11-09 17:55:34 -06:00
edgar c0979dd0ed chore(webapp): actualizar submódulo con los periodos personalizados de Histórico
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 15:21:18 -06:00
edgar 23f529e85c chore(webapp): actualizar submódulo con las alteraciones del EEG abiertas
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 13:46:26 -06:00
edgar 7ea755d3aa chore(webapp): actualizar submódulo con los cambios de la reunión del 5 de noviembre
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 13:38:53 -06:00
edgar 8802b804ac chore(webapp): actualizar submódulo con la calidad del EEG por criterios
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 12:46:01 -06:00
edgar 3b9099f6bf chore(webapp): actualizar submódulo con las nuevas alteraciones del EEG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 11:55:07 -06:00
edgar 35bcd2fdcc chore(webapp): actualizar submódulo con la dona de un anillo de M23
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:56:54 -06:00
edgar 6f656cec6d chore(webapp): actualizar submódulo con la nueva redacción del resumen de TEA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:48:19 -06:00
edgar 0c970b0080 chore(webapp): actualizar submódulo con los filtros de Seguimiento de TEA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:06:37 -06:00
edgar f318fb89da chore(webapp): actualizar submódulo con husos del sueño por etapa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 22:56:25 -06:00
edgar 6470e99ea5 chore(webapp): actualizar submódulo con Histórico y acordeón en Seguimiento
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 22:41:05 -06:00
edgar 0351476ec9 chore(webapp): actualizar submódulo con la pestaña Evolución y la nueva paleta
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 22:09:02 -06:00
edgar 444c806d5c chore(webapp): actualizar submódulo con botones para resaltar partes de las figuras de TEA 2026-11-03 21:22:51 +00:00
edgar 7fcc7bdfe9 chore(webapp): actualizar submódulo con ficha en tres columnas y dona de M21 2026-11-03 20:28:14 +00:00
edgar 4ab37f8433 chore(webapp): actualizar submódulo con la ficha de paciente de TEA 2026-11-03 19:58:30 +00:00
edgar 92eae777c9 chore(webapp): actualizar submódulo con dona y barras por grupo de edad de TEA 2026-11-03 19:45:32 +00:00
edgar 8b0c0c6733 chore(webapp): actualizar submódulo con enlace «Ir», seguimiento compacto y donas de TEA 2026-11-03 19:23:00 +00:00
edgar 798ba005cd chore(webapp): actualizar submódulo con intervalo de análisis y alteraciones del EEG de TEA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 00:07:22 +00:00
edgar abd056aa8a chore(webapp): actualizar submódulo con seguimiento, resumen de TEA, periodo único y selector de indicadores
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 23:28:09 +00:00
11 changed files with 190 additions and 10 deletions
+3
View File
@@ -1,3 +1,4 @@
from extraction.nlp.discovery import DiscoveredField, discover_captions
from extraction.nlp.extractors import (
DEFAULT_EXTRACTORS,
FieldExtractor,
@@ -11,6 +12,7 @@ from extraction.nlp.fields import Evidence, ExtractedValue, FieldKind, FieldSpec
__all__ = [
"DEFAULT_EXTRACTORS",
"DiscoveredField",
"Evidence",
"ExtractedValue",
"FieldExtractor",
@@ -21,4 +23,5 @@ __all__ = [
"PatternExtractor",
"RecordExtractor",
"SegmentLine",
"discover_captions",
]
+43
View File
@@ -0,0 +1,43 @@
"""Captions a document carries that no registered `FieldSpec` claims.
`LabeledValueExtractor` only looks for the labels a caller already knows
about. A source whose documents carry fields outside today's vocabulary
(a hospital's own report layout, a free-form note) still has captions in
the `"Campo: valor"` shape; this module finds them so a caller can decide,
per caption, whether it matches something in a catalog closely enough to
reuse, or is new (see `webapi.imports.schemas.catalog_matching`)."""
import re
from dataclasses import dataclass
from typing import Sequence
from extraction.nlp.extractors import LabelIndex, SegmentLine
from extraction.nlp.fields import Evidence, FieldSpec
_CAPTION_LINE = re.compile(r"^(?P<caption>[^:=]{2,60}?)\s*[:=]\s*(?P<value>\S.*)$")
@dataclass(frozen=True)
class DiscoveredField:
"""One `caption: value` line a known `FieldSpec` didn't already claim."""
caption: str
value: str
evidence: Evidence
def discover_captions(lines: Sequence[SegmentLine], specs: Sequence[FieldSpec]) -> list[DiscoveredField]:
"""Every undiscovered caption, in line order, duplicates kept (the
caller decides how to fold repeats across a record's lines)."""
index = LabelIndex(lines, specs)
found: list[DiscoveredField] = []
for line_index, line in enumerate(lines):
if index.hits[line_index]:
continue # a known label already explains this line
match = _CAPTION_LINE.match(line.text.strip())
if not match:
continue
caption, value = match.group("caption").strip(), match.group("value").strip()
if not caption or not value:
continue
found.append(DiscoveredField(caption, value, line.evidence()))
return found
+14 -4
View File
@@ -3,15 +3,23 @@ from extraction.errors import ExtractionError
from extraction.readers.base import DocumentReader, OcrMode
from extraction.readers.image import ImageReader
from extraction.readers.pdf import PdfReader, combine_pages
from extraction.readers.text import TextReader
READERS: tuple[type[DocumentReader], ...] = (PdfReader, ImageReader)
# Tried only once neither a signature nor the file name picked one of
# `READERS`: a SQL column or a plain string that isn't a PDF or an image,
# read as text as long as it decodes as one instead of being rejected.
FALLBACK_READERS: tuple[type[DocumentReader], ...] = (TextReader,)
def reader_for(name: str, raw: bytes, **options) -> DocumentReader:
"""The reader whose signature the bytes carry; the file extension only when none does."""
"""The reader whose signature the bytes carry, the file extension when
none does, and `FALLBACK_READERS` by content only when neither found one."""
head = raw[:16]
cls = next((c for c in READERS if c.matches_content(head)), None) or next(
(c for c in READERS if c.matches_name(name)), None
cls = (
next((c for c in READERS if c.matches_content(head)), None)
or next((c for c in READERS if c.matches_name(name)), None)
or next((c for c in FALLBACK_READERS if c.matches_content(head)), None)
)
if cls is None:
raise ExtractionError(f"unsupported document format: {name!r}")
@@ -23,14 +31,16 @@ def read_document(name: str, raw: bytes, *, ocr_mode: OcrMode = "auto") -> Docum
def supported_extensions() -> list[str]:
return sorted({extension for cls in READERS for extension in cls.extensions})
return sorted({extension for cls in (*READERS, *FALLBACK_READERS) for extension in cls.extensions})
__all__ = [
"FALLBACK_READERS",
"READERS",
"DocumentReader",
"ImageReader",
"PdfReader",
"TextReader",
"combine_pages",
"read_document",
"reader_for",
+70
View File
@@ -0,0 +1,70 @@
import io
from PIL import Image, ImageDraw
from extraction.document import BBox, Document, Line, Page
from extraction.errors import ExtractionError
from extraction.readers.base import DocumentReader
_LINE_HEIGHT_PX = 18
class TextReader(DocumentReader):
"""Plain text, one field's content carrying several of its own (a SQL
column that isn't a scanned PDF, a note pasted as a string). No OCR: the
bytes already are the text, one page, one line per newline.
The fallback reader, last in `extraction.readers.READERS`: it claims
whatever a format-specific reader didn't, as long as it decodes as
text, so a source that's neither a PDF nor an image still reaches the
same field extraction instead of failing as an unsupported format.
"""
media_type = "text/plain"
extensions = ("txt",)
@classmethod
def matches_content(cls, head: bytes) -> bool:
"""`head` is only a short prefix (`reader_for` passes 16 bytes), so
a multi-byte character can be cut mid-sequence; trimming up to 3
trailing bytes covers any such cut without accepting binary data.
Printable (plus common whitespace) is required too, so a binary
signature that happens to be valid UTF-8 (control bytes are) isn't
mistaken for text."""
if b"\x00" in head:
return False
text = None
for cut in range(4):
trimmed = head[: len(head) - cut] if cut else head
if not trimmed:
return False
try:
text = trimmed.decode("utf-8")
break
except UnicodeDecodeError:
continue
return text is not None and all(ch.isprintable() or ch in "\t\n\r" for ch in text)
def read(self, name: str, raw: bytes) -> Document:
try:
text = raw.decode("utf-8")
except UnicodeDecodeError as exc:
raise ExtractionError(f"not valid UTF-8 text: {exc}") from exc
rows = text.splitlines() or [""]
lines = [
Line(text=row, bbox=BBox(0, index / len(rows), 1, (index + 1) / len(rows)))
for index, row in enumerate(rows)
]
return Document(name=name, media_type=self.media_type, pages=[Page(number=1, lines=lines, source="text")], raw=raw)
def render_page(self, raw: bytes, page_number: int, *, dpi: int = 150) -> bytes:
if page_number != 1:
raise ExtractionError(f"page {page_number} out of range (1..1)")
rows = raw.decode("utf-8", errors="replace").splitlines() or [""]
image = Image.new("RGB", (900, max(1, len(rows)) * _LINE_HEIGHT_PX + 20), "white")
draw = ImageDraw.Draw(image)
for index, row in enumerate(rows):
draw.text((10, 10 + index * _LINE_HEIGHT_PX), row, fill="black")
buffer = io.BytesIO()
image.save(buffer, format="PNG")
return buffer.getvalue()
+9 -1
View File
@@ -4,6 +4,7 @@ from dataclasses import dataclass, field
from typing import Any, Sequence
from extraction.document import Document, EmbeddedImage
from extraction.nlp.discovery import DiscoveredField, discover_captions
from extraction.nlp.extractors import DEFAULT_EXTRACTORS, FieldExtractor, RecordExtractor
from extraction.nlp.fields import ExtractedValue, FieldSpec
from extraction.segmentation import AutoSegmenter, Segment, Segmenter, normalize_key
@@ -33,6 +34,10 @@ class ExtractedRecord:
images: list[tuple[str, EmbeddedImage]] = field(default_factory=list)
key: str | None = None
conflicts: list[FieldConflict] = field(default_factory=list)
# Captions no known `FieldSpec` claimed (`discover_captions`): what a
# source outside today's vocabulary carries, for a caller to match
# against a catalog or register as new (catalog_matching, in WebApi).
discovered: list[DiscoveredField] = field(default_factory=list)
def row(self) -> dict[str, Any]:
return {name: extracted.value for name, extracted in self.values.items()}
@@ -70,6 +75,7 @@ class RecordMerger:
target.sources.extend(record.sources)
target.images.extend(record.images)
target.conflicts.extend(record.conflicts)
target.discovered.extend(record.discovered)
for name, incoming in record.values.items():
current = target.values.get(name)
if current is None:
@@ -116,7 +122,8 @@ class DocumentExtractor:
return self.merger.merge(records) if self.merger else records
def extract_segment(self, segment: Segment) -> ExtractedRecord:
values = self.fields.extract(segment.lines())
lines = segment.lines()
values = self.fields.extract(lines)
key = segment.key
if self.key_spec is not None and self.key_spec.name in values:
key = normalize_key(values[self.key_spec.name].value)
@@ -125,4 +132,5 @@ class DocumentExtractor:
sources=[SegmentRef(segment.document.name, list(segment.page_numbers))],
images=[(segment.document.name, image) for image in segment.images],
key=key,
discovered=discover_captions(lines, self.specs),
)
+31
View File
@@ -0,0 +1,31 @@
"""`discover_captions`: fails if it stops finding fields a source carries
that no registered `FieldSpec` names, or starts re-reporting a field the
specs already cover as if it were new."""
from extraction.document import BBox, Line
from extraction.nlp import FieldKind, FieldSpec, SegmentLine, discover_captions
EXPEDIENTE = FieldSpec("pac_id_hospital", FieldKind.IDENTIFIER, labels=("expediente",))
def lines(*texts: str) -> list[SegmentLine]:
return [SegmentLine("doc.pdf", 1, Line(text, BBox(0, i / 10, 1, (i + 1) / 10))) for i, text in enumerate(texts)]
def test_a_caption_outside_the_known_specs_is_discovered():
found = discover_captions(lines("Tipo de muestra: Base líquida"), [EXPEDIENTE])
assert [(f.caption, f.value) for f in found] == [("Tipo de muestra", "Base líquida")]
def test_a_line_a_known_label_already_claims_is_not_rediscovered():
found = discover_captions(lines("Expediente: EXP-0001"), [EXPEDIENTE])
assert found == []
def test_a_line_without_the_caption_shape_is_ignored():
found = discover_captions(lines("Resultado negativo para lesión intraepitelial"), [EXPEDIENTE])
assert found == []
def test_several_undiscovered_captions_come_back_in_line_order():
found = discover_captions(lines("Instrumento: ADOS-2", "Módulo: 3", "Expediente: EXP-0001"), [EXPEDIENTE])
assert [(f.caption, f.value) for f in found] == [("Instrumento", "ADOS-2"), ("Módulo", "3")]
+16 -1
View File
@@ -4,7 +4,7 @@ import pytest
from extraction.testing import scanned_pdf, text_pdf
from extraction import DocumentExtractor, ExtractionError, FieldKind, FieldSpec, make_segmenter, read_document
from extraction.readers import ImageReader, PdfReader, combine_pages, reader_for
from extraction.readers import ImageReader, PdfReader, TextReader, combine_pages, reader_for
EXPEDIENTE = FieldSpec("pac_id_hospital", FieldKind.IDENTIFIER, labels=("expediente",))
NACIMIENTO = FieldSpec("pac_fecha_nacimiento", FieldKind.DATE, labels=("fecha de nacimiento",))
@@ -97,6 +97,21 @@ def test_unknown_format_is_rejected():
reader_for("notes.docx", b"PK\x03\x04")
def test_plain_text_is_read_as_a_one_page_document():
"""Fails if a source whose field bundle is a plain string (not a PDF or
an image) stops being readable, falling back to ExtractionError."""
document = read_document("fila_42", "Expediente: EXP-0099\nInstrumento: ADOS-2".encode("utf-8"))
assert isinstance(reader_for("fila_42", document.raw), TextReader)
assert document.page_count == 1
assert [line.text for line in document.pages[0].lines] == ["Expediente: EXP-0099", "Instrumento: ADOS-2"]
def test_plain_text_fallback_does_not_steal_a_known_signature_or_extension():
"""Fails if `TextReader` starts winning over a real PDF/image match."""
assert isinstance(reader_for("reporte.pdf", b"????"), PdfReader)
assert isinstance(reader_for("f.png", b"\x89PNG\r\n\x1a\n" + b"\x00" * 8), ImageReader)
def test_combine_pages_from_several_pdfs():
from extraction.readers import combine_pages
+1 -1
Submodule WebApi updated: f74ccf5496...102999c8de
+1 -1
Submodule WebApp updated: f4d2a3e85f...c076e1e7a9
+1 -1
Submodule models updated: 5d65730b98...a8bbdc88af