feat: match MRN, Gender, DOB, and Age only (removed Name check)

This commit is contained in:
2026-07-15 11:58:20 +05:30
parent e21ed72634
commit d7a8e1910f
2 changed files with 13 additions and 22 deletions
+10 -18
View File
@@ -324,7 +324,6 @@ def _calculate_age(dob_str: str) -> Optional[int]:
@router.get("/match-patient")
def match_patient(
mrn: str = None,
name: str = None,
gender: str = None,
dob: str = None,
age: int = None,
@@ -332,15 +331,16 @@ def match_patient(
):
"""
Match incoming patient demographics to an active Contec monitor.
Uses 4-point verification: MRN, Gender, DOB, Age.
Call this from the dashboard iframe URL:
/api/dashboard?minimal=true&mrn=MRN001&name=John+Doe&gender=M&dob=19900115&age=36
/api/dashboard?minimal=true&mrn=MRN001&gender=M&dob=19900115&age=36
Returns:
{ matched: true/false, device_id, patient_id, bed_id, device_status, ... }
"""
if not mrn and not name:
return {"matched": False, "reason": "No patient identifiers supplied"}
if not mrn:
return {"matched": False, "reason": "No MRN supplied"}
# Fetch all patients
all_patients = db.query(Patient).all()
@@ -348,7 +348,6 @@ def match_patient(
# Normalize incoming params
in_mrn = (mrn or "").strip().upper()
in_name = _normalize_name(name or "")
in_gender = _gender_code(gender or "")
in_dob = _normalize_dob(dob or "")
in_age = age
@@ -359,23 +358,17 @@ def match_patient(
for p in all_patients:
score = 0
# --- MRN check (primary) ---
# --- MRN check (primary, required) ---
p_mrn = (p.mrn or p.patient_id or "").strip().upper()
if in_mrn and p_mrn == in_mrn:
score += 10
elif in_mrn:
continue # MRN supplied but doesn't match → skip
# --- Name check ---
if in_name:
p_name = _normalize_name(p.name or "")
if p_name and any(w in p_name for w in in_name):
score += 3
else:
continue # MRN must match
# --- Gender check ---
if in_gender and p.gender:
if _gender_code(p.gender) == in_gender:
score += 2
score += 3
# --- DOB check ---
if in_dob and p.dob:
@@ -392,10 +385,9 @@ def match_patient(
match_score = score
matched_patient = p
# To be matched, MRN must be found, and name/gender/dob must also be validated
# (Require at least a score of 12: MRN + Name, or MRN + Gender, etc.)
# Require MRN match (10) + at least one secondary attribute (gender/dob/age)
if not matched_patient or match_score < 12:
return {"matched": False, "reason": "No matching patient found in monitor database with 4-point verification"}
return {"matched": False, "reason": "No matching patient found in monitor database with 4-point verification (MRN + Gender + DOB + Age)"}
# Find the most recent vital reading for this patient
latest = (