Spaces:
Running
Running
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 +4 -4
- backend/neo4j_setup.py +4 -4
- backend/trial_enrichment.py +12 -9
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"
|
| 48 |
-
username=os.getenv("NEO4J_USERNAME"
|
| 49 |
-
password=os.getenv("NEO4J_PASSWORD"
|
| 50 |
-
database=os.getenv("NEO4J_DATABASE"
|
| 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"
|
| 51 |
-
user=os.getenv("NEO4J_USERNAME"
|
| 52 |
-
password=os.getenv("NEO4J_PASSWORD"
|
| 53 |
-
database=os.getenv("NEO4J_DATABASE"
|
| 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 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
| 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]:
|