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