Use source patient identity for breast follow-up

This commit is contained in:
Angel Capetillo Zavala
2026-11-13 17:38:19 -06:00
parent 2ca86232c9
commit eeb55c4255
11 changed files with 73 additions and 110 deletions
+5 -9
View File
@@ -1,4 +1,4 @@
"""Configure the opt-in synthetic breast cohort for the application."""
"""Configure the breast cohort using the shared persistence settings."""
import hmac
import os
@@ -9,19 +9,15 @@ from webapi.cama_cohort import CamaCohort
def configure_cama_cohort(app):
if os.environ.get('CAMA_COHORT_SYNTHETIC') != '1':
return
secret = os.environ.get('CAMA_COHORT_SECRET', '').encode('utf-8')
token = os.environ.get('CAMA_COHORT_ACCESS_TOKEN', '')
if len(secret) < 32 or not re.fullmatch(r'[A-Za-z0-9_-]{32,}', token):
raise ValueError('Synthetic cohort requires a stable secret and a URL-safe access token of at least 32 characters')
def read(cutoff):
with get_cama_session() as session:
return CamaCohort(session, secret).rows(cutoff)
return CamaCohort(session).rows(cutoff)
def access(req):
supplied = req.headers.get('X-Cama-Cohort-Token', '')
return hmac.compare_digest(supplied.encode('utf-8'), token.encode('utf-8'))
return bool(re.fullmatch(r'[A-Za-z0-9_-]{32,}', token)) and hmac.compare_digest(
supplied.encode('utf-8'), token.encode('utf-8'))
app.config.update(CAMA_COHORT_SYNTHETIC=True, CAMA_COHORT_READER=read, CAMA_COHORT_ACCESS=access)
app.config.update(CAMA_COHORT_READER=read, CAMA_COHORT_ACCESS=access)