Recortar el periodo de las medidas a la fecha de corte
This commit is contained in:
@@ -78,3 +78,50 @@ def test_the_nci_operation_is_refused_while_the_flag_is_off(client, monkeypatch)
|
||||
monkeypatch.delenv(fhir.NCI_REFERENCE, raising=False)
|
||||
response = client.get("/cacu/fhir/Patient/any/$reference-risk")
|
||||
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
|
||||
|
||||
+7
-2
@@ -6,7 +6,7 @@ counting a few thousand rows (measures) and ordering the follow-up list."""
|
||||
import operator
|
||||
import os
|
||||
import unicodedata
|
||||
from datetime import date, datetime
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Annotated, Any
|
||||
|
||||
from dagster_graphql import DagsterGraphQLClient
|
||||
@@ -540,6 +540,9 @@ def search_measure_report(
|
||||
event_cutoff: date | None = Query(
|
||||
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),
|
||||
_offset: int = Query(0),
|
||||
) -> Response:
|
||||
@@ -553,7 +556,9 @@ def search_measure_report(
|
||||
rows = measure_reads.rows(domain.value, found.rows, **found.params)
|
||||
reports = []
|
||||
page = _sliced(asked, count, offset)
|
||||
results = m.evaluate_periods(found, rows, [p for _, p in page], as_of, event_cutoff)
|
||||
evaluated = [m.Period(p.start, min(p.end, period_cutoff + timedelta(days=1)))
|
||||
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):
|
||||
report = m.report(found, period, result, as_of)
|
||||
report.id = f"{f.measure_id(found.id)}-{text.lower()}"
|
||||
|
||||
Reference in New Issue
Block a user