Use source patient identity for breast follow-up
This commit is contained in:
+3
-11
@@ -6,8 +6,6 @@ restore a previous value after an update.
|
||||
"""
|
||||
|
||||
from datetime import date, datetime, time, timedelta, timezone
|
||||
import hashlib
|
||||
import hmac
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
@@ -49,14 +47,8 @@ def _age_group(birth, cutoff):
|
||||
class CamaCohort:
|
||||
"""Materialize one row per eligible patient, using a caller-owned session."""
|
||||
|
||||
def __init__(self, session, secret: bytes):
|
||||
if not secret or len(secret) < 32:
|
||||
raise ValueError("A stable secret of at least 32 bytes is required")
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
self.secret = secret
|
||||
|
||||
def _id(self, patient):
|
||||
return hmac.new(self.secret, f"cama:{patient}".encode(), hashlib.sha256).hexdigest()
|
||||
|
||||
def rows(self, cutoff: date):
|
||||
t = TABLAS
|
||||
@@ -128,7 +120,7 @@ class CamaCohort:
|
||||
order = found_order[1] if found_order and _date(found_order[1].fecha) >= _date(m['fecha_toma']) else None
|
||||
grade = b['grado'] if b and observation_known(b['procedimiento_id'], 'biopsia.grado', patient) else None
|
||||
rows.append({
|
||||
'id_seudonimo': self._id(patient), 'mastografia_fecha': _date(m['fecha_toma']).isoformat(),
|
||||
'pac_id': str(patient), 'mastografia_fecha': _date(m['fecha_toma']).isoformat(),
|
||||
'mastografia_reporte_fecha': _date(m['fecha_reporte']).isoformat(),
|
||||
'birads': code, 'grupo_edad': _age_group(people[patient].fecha_nacimiento, cutoff),
|
||||
'biopsia': grade, 'biopsia_fecha': _date(b['fecha_reporte']).isoformat() if b else None,
|
||||
@@ -141,4 +133,4 @@ class CamaCohort:
|
||||
'biopsia_resultado_carga_inicio': load_time(observations.get((b['procedimiento_id'], 'biopsia.grado')))
|
||||
if b and observation_known(b['procedimiento_id'], 'biopsia.grado', patient) else None,
|
||||
})
|
||||
return sorted(rows, key=lambda row: (-date.fromisoformat(row['mastografia_fecha']).toordinal(), row['id_seudonimo']))
|
||||
return sorted(rows, key=lambda row: (-date.fromisoformat(row['mastografia_fecha']).toordinal(), int(row['pac_id'])))
|
||||
|
||||
Reference in New Issue
Block a user