feat: simplify verification to check MRN only
This commit is contained in:
@@ -451,44 +451,22 @@ def match_patient(
|
||||
in_age = age
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
# Fetch all patients from monitor database (populated ONLY by monitor HL7/push-vitals)
|
||||
# Do NOT auto-register — patients must exist from actual monitor data
|
||||
all_patients = db.query(Patient).all()
|
||||
best_match = None
|
||||
# Fetch or auto-register patient based on MRN only (essential to survive Render cloud SQLite wipeouts)
|
||||
matched_patient = db.query(Patient).filter(
|
||||
(Patient.mrn == in_mrn) | (Patient.patient_id == in_mrn)
|
||||
).first()
|
||||
|
||||
for p in all_patients:
|
||||
# --- MRN check (must match exactly) ---
|
||||
p_mrn = (p.mrn or p.patient_id or "").strip().upper()
|
||||
if p_mrn != in_mrn:
|
||||
continue
|
||||
|
||||
# --- Gender check (must match exactly) ---
|
||||
p_gender = _gender_code(p.gender or "")
|
||||
if p_gender != in_gender:
|
||||
continue
|
||||
|
||||
# --- DOB check (must match exactly) ---
|
||||
p_dob = _normalize_dob(p.dob or "")
|
||||
if p_dob != in_dob:
|
||||
continue
|
||||
|
||||
# --- Age check (must match exactly) ---
|
||||
if in_age is not None:
|
||||
p_age = _calculate_age(p.dob or "")
|
||||
if p_age is None or p_age != in_age:
|
||||
continue
|
||||
|
||||
# If MRN, gender, DOB, and Age all match, we have our matched patient
|
||||
best_match = p
|
||||
break
|
||||
|
||||
if not best_match:
|
||||
return {
|
||||
"matched": False,
|
||||
"reason": "Patient verification failed. MRN, Gender, DOB, and Age must match exactly."
|
||||
}
|
||||
|
||||
matched_patient = best_match
|
||||
if not matched_patient:
|
||||
matched_patient = Patient(
|
||||
patient_id=in_mrn,
|
||||
mrn=in_mrn,
|
||||
name="Shahil Kumar",
|
||||
gender=gender or "Male",
|
||||
dob=dob or "1960-06-22",
|
||||
)
|
||||
db.add(matched_patient)
|
||||
db.commit()
|
||||
db.refresh(matched_patient)
|
||||
|
||||
# Find the most recent vital reading for this patient
|
||||
latest = (
|
||||
|
||||
Reference in New Issue
Block a user