askdocs / components /getproblems.py
Junaidb's picture
Update components/getproblems.py
c70f2a7 verified
from components.mongoconnection import provideClient
mc=provideClient()
db=mc["askmydoc_db"]
coll=db["askmydoc_col"]
def GetProblems(owner,typeofmsg,files):
match typeofmsg:
case "legal":
document = coll.find_one({"owner": owner})
if document is None or "keypoints" not in document or len(document["keypoints"]) == 0:
return {"problems":[]}
else:
filtered=[]
for msg in document["keypoints"]:
if msg["type"] == typeofmsg and any(f in files for f in msg["files"]):
filtered.append(msg)
return {"problems":filtered}
case "medical":
document = coll.find_one({"owner": owner})
if document is None or "keypoints" not in document or len(document["keypoints"]) == 0:
return {"problems":[]}
else:
filtered=[]
for msg in document["keypoints"]:
if msg["type"] == typeofmsg and any(f in files for f in msg["files"]):
filtered.append(msg)
return {"problems":filtered}
case "research":
document = coll.find_one({"owner": owner})
if document is None or "keypoints" not in document or len(document["keypoints"]) == 0:
return {"problems":[]}
else:
filtered=[]
for msg in document["keypoints"]:
if msg["type"] == typeofmsg and any(f in files for f in msg["files"]):
filtered.append(msg)
return {"problems":filtered}