dylanglenister commited on
Commit
5733813
·
1 Parent(s): f51c900

Fixing exception oversights

Browse files

Get collection is called in the try block

src/data/repositories/patient.py CHANGED
@@ -65,7 +65,6 @@ def create_patient(
65
  collection_name: str = Collections.PATIENT
66
  ) -> str:
67
  """Creates a new patient record, raising ActionFailed on error."""
68
- collection = get_collection(collection_name)
69
  now = datetime.now(timezone.utc)
70
  patient_data = {
71
  "name": name,
@@ -83,6 +82,7 @@ def create_patient(
83
  if past_assessment_summary: patient_data["past_assessment_summary"] = past_assessment_summary
84
 
85
  try:
 
86
  if assigned_doctor_id:
87
  patient_data["assigned_doctor_id"] = ObjectId(assigned_doctor_id)
88
 
@@ -160,11 +160,11 @@ def search_patients(
160
  if not query:
161
  return []
162
 
163
- collection = get_collection(collection_name)
164
  logger().info(f"Searching patients with query: '{query}', limit: {limit}")
165
  pattern = re.compile(re.escape(query), re.IGNORECASE)
166
 
167
  try:
 
168
  cursor = collection.find({
169
  "name": {"$regex": pattern}
170
  }).sort("name", ASCENDING).limit(limit)
 
65
  collection_name: str = Collections.PATIENT
66
  ) -> str:
67
  """Creates a new patient record, raising ActionFailed on error."""
 
68
  now = datetime.now(timezone.utc)
69
  patient_data = {
70
  "name": name,
 
82
  if past_assessment_summary: patient_data["past_assessment_summary"] = past_assessment_summary
83
 
84
  try:
85
+ collection = get_collection(collection_name)
86
  if assigned_doctor_id:
87
  patient_data["assigned_doctor_id"] = ObjectId(assigned_doctor_id)
88
 
 
160
  if not query:
161
  return []
162
 
 
163
  logger().info(f"Searching patients with query: '{query}', limit: {limit}")
164
  pattern = re.compile(re.escape(query), re.IGNORECASE)
165
 
166
  try:
167
+ collection = get_collection(collection_name)
168
  cursor = collection.find({
169
  "name": {"$regex": pattern}
170
  }).sort("name", ASCENDING).limit(limit)
src/data/repositories/session.py CHANGED
@@ -56,9 +56,9 @@ def create_session(
56
  collection_name: str = Collections.SESSION
57
  ) -> dict[str, Any]:
58
  """Creates a new chat session, raising ActionFailed on error."""
59
- collection = get_collection(collection_name)
60
  now = datetime.now(timezone.utc)
61
  try:
 
62
  session_data: dict[str, Any] = {
63
  "account_id": ObjectId(account_id),
64
  "patient_id": ObjectId(patient_id),
 
56
  collection_name: str = Collections.SESSION
57
  ) -> dict[str, Any]:
58
  """Creates a new chat session, raising ActionFailed on error."""
 
59
  now = datetime.now(timezone.utc)
60
  try:
61
+ collection = get_collection(collection_name)
62
  session_data: dict[str, Any] = {
63
  "account_id": ObjectId(account_id),
64
  "patient_id": ObjectId(patient_id),