Spaces:
Runtime error
Runtime error
File size: 1,406 Bytes
ed0b977 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | from flask import Flask
from utils.db.db import init_db, mongo
import os
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
app.config["MONGO_URI"] = os.environ.get("MONGO_URI").replace("mongodb.net/?", "mongodb.net/swiftquery?")
init_db(app)
with app.app_context():
# 1. Find the patient
patient = mongo.db.patient.find_one({"id": 1001})
if not patient:
patient = mongo.db.patient.find_one({"id": "1001"})
if not patient:
print("Patient 1001 NOT FOUND")
else:
print(f"Found Patient: {patient.get('name')} (ID: {patient.get('id')}, Type: {type(patient.get('id'))})")
pid = patient.get('id')
# 2. Check collections
colls = ['consultation', 'medicalhistory', 'treatment', 'testreport', 'chatsession']
for c in colls:
count_int = mongo.db[c].count_documents({"patient_id": int(pid) if str(pid).isdigit() else pid})
count_str = mongo.db[c].count_documents({"patient_id": str(pid)})
print(f"Collection '{c}': Int-ID matches: {count_int}, Str-ID matches: {count_str}")
# Print one sample if exists
if count_int > 0:
print(f" Sample (Int): {mongo.db[c].find_one({'patient_id': int(pid)})}")
elif count_str > 0:
print(f" Sample (Str): {mongo.db[c].find_one({'patient_id': str(pid)})}")
|