TheQuantEd commited on
Commit
bf49c73
·
1 Parent(s): bfeb61b

Fix 500: use 'or' fallback for env vars, guard eligible-patient query against Neo4j not ready

Browse files
backend/graphrag.py CHANGED
@@ -44,10 +44,10 @@ def _get_graph():
44
  global _graph
45
  if _graph is None:
46
  _graph = Neo4jGraph(
47
- url=os.getenv("NEO4J_URI", "bolt://127.0.0.1:7687"),
48
- username=os.getenv("NEO4J_USERNAME", "neo4j"),
49
- password=os.getenv("NEO4J_PASSWORD", "clinicalmatch2024"),
50
- database=os.getenv("NEO4J_DATABASE", "neo4j"),
51
  )
52
  return _graph
53
 
 
44
  global _graph
45
  if _graph is None:
46
  _graph = Neo4jGraph(
47
+ url=os.getenv("NEO4J_URI") or "bolt://127.0.0.1:7687",
48
+ username=os.getenv("NEO4J_USERNAME") or "neo4j",
49
+ password=os.getenv("NEO4J_PASSWORD") or "clinicalmatch2024",
50
+ database=os.getenv("NEO4J_DATABASE") or "neo4j",
51
  )
52
  return _graph
53
 
backend/neo4j_setup.py CHANGED
@@ -47,10 +47,10 @@ class Neo4jConnection:
47
 
48
 
49
  neo4j_conn = Neo4jConnection(
50
- uri=os.getenv("NEO4J_URI", "bolt://127.0.0.1:7687"),
51
- user=os.getenv("NEO4J_USERNAME", "neo4j"),
52
- password=os.getenv("NEO4J_PASSWORD", "clinicalmatch2024"),
53
- database=os.getenv("NEO4J_DATABASE", "neo4j"),
54
  )
55
 
56
 
 
47
 
48
 
49
  neo4j_conn = Neo4jConnection(
50
+ uri=os.getenv("NEO4J_URI") or "bolt://127.0.0.1:7687",
51
+ user=os.getenv("NEO4J_USERNAME") or "neo4j",
52
+ password=os.getenv("NEO4J_PASSWORD") or "clinicalmatch2024",
53
+ database=os.getenv("NEO4J_DATABASE") or "neo4j",
54
  )
55
 
56
 
backend/trial_enrichment.py CHANGED
@@ -172,15 +172,18 @@ def get_eligible_patient_counts(nct_ids: list[str]) -> dict[str, int]:
172
  """Batch version — returns {nct_id: count} for a list of trials."""
173
  if not nct_ids:
174
  return {}
175
- rows = neo4j_conn.run_query(
176
- """
177
- MATCH (p:Patient)-[:ELIGIBLE_FOR]->(t:Trial)
178
- WHERE t.id IN $ids
179
- RETURN t.id AS nct_id, count(p) AS n
180
- """,
181
- {"ids": nct_ids},
182
- )
183
- return {row["nct_id"]: row["n"] for row in rows}
 
 
 
184
 
185
 
186
  def get_similar_trials(nct_id: str, limit: int = 5) -> list[dict]:
 
172
  """Batch version — returns {nct_id: count} for a list of trials."""
173
  if not nct_ids:
174
  return {}
175
+ try:
176
+ rows = neo4j_conn.run_query(
177
+ """
178
+ MATCH (p:Patient)-[:ELIGIBLE_FOR]->(t:Trial)
179
+ WHERE t.id IN $ids
180
+ RETURN t.id AS nct_id, count(p) AS n
181
+ """,
182
+ {"ids": nct_ids},
183
+ )
184
+ return {row["nct_id"]: row["n"] for row in rows}
185
+ except Exception:
186
+ return {}
187
 
188
 
189
  def get_similar_trials(nct_id: str, limit: int = 5) -> list[dict]: