Files
WebApi/docs/cama-follow-up.md
Angel Capetillo Zavala b1bbbc25b4 Integrate CaMa follow-up, descriptive analysis and L3 with dev
Preserve dev risk batches and governance, individual patient selection, optional access and explicit cohort reader overrides. Register one CaMa implementation and retain legacy Python blueprint consumers. Validated with 681 WebApi tests on the integrated parent and submodules.
2026-11-17 10:44:07 -06:00

95 lines
6.2 KiB
Markdown

# CaMa follow-up list
Patient-level list of the BI-RADS cohort, and the file of the same selection. Every response carries
`simulado: true`: the list is for synthetic data and local use. Who may read it on real data is an access rule that does
not exist yet; nothing here authorizes it.
## Routes
`GET /cama/seguimiento` and `GET /cama/seguimiento/exportacion` (the second takes no `page` or `page_size`).
Compatibility with dev: `GET /cama/pacientes/<pac_id>` accepts the same selection as the export and returns
`item` instead of `items`. It applies suppression to the full selection before locating the patient (404 when absent),
and uses the list's revision. The existing optional `CAMA_COHORT_ACCESS` callback is honored on the new follow-up
and analysis routes; no new authentication mechanism is introduced. `cama_analysis_legacy` retains the former
blueprints for explicit consumers, while `create_app` registers only the new routes, without duplicates.
| Parameter | Meaning |
| --- | --- |
| `corte` | Cut-off date `AAAA-MM-DD`, not after today. Default: today. |
| `meses` | Window: `0` (the whole cohort, from its earliest mammogram), `1`, `3`, `6` or `12`. Default: `3`. |
| `page`, `page_size` | From 1; `page_size` from 1 to 200 (default 50). List only. |
| `birads`, `grupo_edad`, `biopsia` | Filters, combined with AND. The values are in `filtros_disponibles`. |
| `cohorte`, `escenario`, `revision` | The context of an earlier answer, the three together. |
Unknown, repeated or empty parameters are a 400, before anything is counted.
Response: `simulado`, `cohorte` (`cama_birads_v1`), `escenario` (`diagnostico`), `revision`, `corte`,
`ventana` (`meses`, `desde`, `hasta`), `filtros` (each filter, `null` when not applied), `filtros_disponibles`,
`columnas`, `paginacion` and `items`; the file has `total_items` instead of `paginacion`. Each item has `pac_id` (the
platform's key as decimal text), `grupo_edad`, `birads`, `mastografia_fecha`, `biopsia` and `biopsia_fecha`. Nothing
else: no status, priority, days to diagnosis or prognosis, because the data holds none of them.
| Code | When |
| --- | --- |
| 400 | A parameter outside the contract, or the context without all three parts |
| 403 | The selection has fewer patients than `comun.umbral_supresion` (`motivo: supresion`) |
| 404 | A page past the last one, with patients |
| 409 | The cohort, scenario or revision quoted is not the one the server holds (`motivo: revision`) |
| 413 | A file of more than 5000 patients |
| 503 | The cohort view is missing: the indicator cycle that creates the event views hasn't run (`motivo: cohorte`) |
## The cohort
`cama_cohorte_birads` (dbt, `models/cama/gold/seguimiento`) holds one row per mammogram with a reported BI-RADS and each
biopsy report that mammogram led to. A view takes no parameter, so the cut-off is applied by `webapi.cama_follow_up`:
* A patient counts once, through her latest mammogram whose report is dated on or before the cut-off (date taken, then
source id, then report date, then report id: the same data always gives the same cohort).
* She is in the cohort when that BI-RADS is one of `cama.birads_4_a_6`.
* The biopsy shown is the latest report of a biopsy that mammogram led to, dated on or before the cut-off and not before
the mammogram. `SIN_BIOPSIA`: none; `SIN_DATO`: a report without a result.
* The age group is `cama.grupos_edad` at the cut-off; `SIN_DATO` without a birth date.
* Facts are read as silver holds them now. The list is not a reconstruction of what was known on the cut-off.
## Suppression
A selection (window and filters applied) of 1 to `umbral_supresion` - 1 patients is never served, as a page or as a file.
A selection with a window or a filter and no patients is refused alike, so a refusal never tells a small group from an
empty one. The whole cohort (window `0`, no filter) is the only selection that can be empty. Combinations of window and
filters are evaluated on the final selection, so they cannot isolate a small group. The file applies the same rule.
## Revision
`sha256(cohorte | version | construcción | corte)`. The build is the last load that added or changed rows
(`carga-<id>`): a recalculation that changes nothing keeps it, new data changes it. A client that quotes another
revision gets a 409.
## Limits of the revision and of concurrent writes
The revision pins the cohort, its version, the last load that added or changed rows and the cut-off. It is a marker, not a
snapshot: nothing keeps the previous cohort. While no load writes, every page and the file of one selection come from the
same data, so pages concatenate to the file and repeated requests give the same answer. A load that adds or changes rows
between two requests changes the build, and the next request that quotes the old revision is a 409. A load that is still
running when a request arrives is not detected until it records its rows. Until snapshots exist, run reads and files with no
concurrent writes.
Two contradictory facts are resolved the same way whatever the row order: a report with two different BI-RADS counts
through the more severe (`cama.birads_gravedad`), and a biopsy report with two grades on the same date through the more
severe grade (benign, in situ, invasive). The synthetic data holds no such duplicates.
## Provisional decisions
These are working conventions for review, not clinical definitions.
1. Individual lists are served in the local environment with synthetic data only; the routes are registered like CaCu's and
marked `simulado`, with no access rule.
2. Threshold of 5 (`comun.umbral_supresion`, itself provisional).
3. The cohort rule above (latest reported mammogram, BI-RADS 4 to 6) and the biopsy that is shown.
4. The knowledge cut-off is the present: a mammogram or a biopsy loaded after the cut-off date still counts if its own date
is on or before it. Data loaded today would otherwise make every earlier cut-off empty.
5. Age groups and the BI-RADS list come from the platform parameters, not from this module.
6. Residual risk: the suppression rule bounds the size of each selection, not the differences between selections. Two
allowed selections can still reveal a small remainder by subtraction. Rows of allowed selections are individual
records by design.