Quitar el corte de periodo de las medidas

This commit is contained in:
2026-12-03 22:21:59 -06:00
parent 663d384032
commit fb2f3c1753
2 changed files with 2 additions and 54 deletions
-47
View File
@@ -78,50 +78,3 @@ def test_the_nci_operation_is_refused_while_the_flag_is_off(client, monkeypatch)
monkeypatch.delenv(fhir.NCI_REFERENCE, raising=False) monkeypatch.delenv(fhir.NCI_REFERENCE, raising=False)
response = client.get("/cacu/fhir/Patient/any/$reference-risk") response = client.get("/cacu/fhir/Patient/any/$reference-risk")
assert response.status_code == 404 assert response.status_code == 404
@pytest.mark.parametrize("domain,measure", [("cacu", "cacu-eu7"), ("cama", "cama-birads")])
@pytest.mark.parametrize("period", ["2026-02", "2026-S1"])
def test_measure_cutoff_recalculates_the_partial_period(
monkeypatch, domain, measure, period
):
from datetime import UTC, date, datetime
from fastapi import Request
from core.domains import Domain
def row(day, person):
if domain == "cacu":
return {
"sample_id": person, "person_id": person, "sample_date": day,
"valid": 1, "result": "NILM", "birth_date": "1990-01-01",
"screening_history": "never", "detection": "initial", "first_case": None, "first_treatment": None,
"first_colposcopy": None, "first_postcolposcopy_cytology": None,
"known_at": "2026-02-01", "report_known_at": "2026-02-01",
}
return {
"person_id": person, "exam_date": day, "birads": "4", "birads_rank": 4,
"report_date": day, "known_at": "2026-02-01", "report_known_at": "2026-02-01",
}
monkeypatch.setattr(fhir.measure_reads, "rows", lambda *args, **kwargs: [
row("2026-02-05", "a"), row("2026-02-20", "b"),
])
request = Request({"type": "http", "method": "GET", "scheme": "http", "server": ("test", 80),
"path": f"/{domain}/fhir/MeasureReport", "query_string": b"", "headers": []})
def count(cutoff):
answer = fhir.search_measure_report(
request=request, domain=Domain(domain), measure=measure, periods=period,
as_of=datetime(2026, 2, 15, 23, 59, 59, tzinfo=UTC) if cutoff else None,
event_cutoff=date(2026, 2, 15) if cutoff else None,
period_cutoff=date(2026, 2, 15) if cutoff else None, _count=None, _offset=0,
)
report = json.loads(answer.body)["entry"][0]["resource"]
return report["group"][0]["population"][0]["count"], report["period"]
uncut, original = count(False)
cut, reported = count(True)
assert (uncut, cut) == (2, 1)
assert original == reported # report retains the requested month or semester
+2 -7
View File
@@ -6,7 +6,7 @@ counting a few thousand rows (measures) and ordering the follow-up list."""
import operator import operator
import os import os
import unicodedata import unicodedata
from datetime import date, datetime, timedelta from datetime import date, datetime
from typing import Annotated, Any from typing import Annotated, Any
from dagster_graphql import DagsterGraphQLClient from dagster_graphql import DagsterGraphQLClient
@@ -540,9 +540,6 @@ def search_measure_report(
event_cutoff: date | None = Query( event_cutoff: date | None = Query(
None, alias="event-cutoff", description="durations count to this day" None, alias="event-cutoff", description="durations count to this day"
), ),
period_cutoff: date | None = Query(
None, alias="period-cutoff", description="Include period events through this day"
),
_count: int | None = Query(None), _count: int | None = Query(None),
_offset: int = Query(0), _offset: int = Query(0),
) -> Response: ) -> Response:
@@ -556,9 +553,7 @@ def search_measure_report(
rows = measure_reads.rows(domain.value, found.rows, **found.params) rows = measure_reads.rows(domain.value, found.rows, **found.params)
reports = [] reports = []
page = _sliced(asked, count, offset) page = _sliced(asked, count, offset)
evaluated = [m.Period(p.start, min(p.end, period_cutoff + timedelta(days=1))) results = m.evaluate_periods(found, rows, [p for _, p in page], as_of, event_cutoff)
if period_cutoff and period_cutoff < date.max else p for _, p in page]
results = m.evaluate_periods(found, rows, evaluated, as_of, event_cutoff)
for (text, period), result in zip(page, results, strict=True): for (text, period), result in zip(page, results, strict=True):
report = m.report(found, period, result, as_of) report = m.report(found, period, result, as_of)
report.id = f"{f.measure_id(found.id)}-{text.lower()}" report.id = f"{f.measure_id(found.id)}-{text.lower()}"