Spaces:
Sleeping
Sleeping
Commit ·
6eca038
1
Parent(s): 7f88333
Fixed hardcoded workspace paths and disabled Streamlit CORS/XSRF for HF iframe support
Browse files
backend/api/claims_router.py
CHANGED
|
@@ -22,7 +22,9 @@ router = APIRouter(prefix="/api")
|
|
| 22 |
policy_service = PolicyService()
|
| 23 |
|
| 24 |
# Uploads directory
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 27 |
|
| 28 |
@router.post("/seed", status_code=200)
|
|
|
|
| 22 |
policy_service = PolicyService()
|
| 23 |
|
| 24 |
# Uploads directory
|
| 25 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 26 |
+
WORKSPACE_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, "..", ".."))
|
| 27 |
+
UPLOAD_DIR = os.path.join(WORKSPACE_ROOT, "uploads")
|
| 28 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 29 |
|
| 30 |
@router.post("/seed", status_code=200)
|
backend/services/policy_service.py
CHANGED
|
@@ -14,7 +14,10 @@ logging.basicConfig(level=logging.INFO)
|
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
class PolicyService:
|
| 17 |
-
def __init__(self, workspace_root: str =
|
|
|
|
|
|
|
|
|
|
| 18 |
self.workspace_root = workspace_root
|
| 19 |
self.policy_terms_path = os.path.join(workspace_root, "policy_terms.json")
|
| 20 |
self.adjudication_rules_path = os.path.join(workspace_root, "adjudication_rules.md")
|
|
|
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
class PolicyService:
|
| 17 |
+
def __init__(self, workspace_root: str = None):
|
| 18 |
+
if not workspace_root:
|
| 19 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 20 |
+
workspace_root = os.path.abspath(os.path.join(current_dir, "..", ".."))
|
| 21 |
self.workspace_root = workspace_root
|
| 22 |
self.policy_terms_path = os.path.join(workspace_root, "policy_terms.json")
|
| 23 |
self.adjudication_rules_path = os.path.join(workspace_root, "adjudication_rules.md")
|
backend/tests/test_adjudication.py
CHANGED
|
@@ -11,8 +11,11 @@ from backend.repositories import claim_repository, member_repository
|
|
| 11 |
from backend.services.policy_service import PolicyService
|
| 12 |
from backend.services.confidence_calculator import evaluate_confidence
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
# Use a separate test SQLite database
|
| 15 |
-
TEST_DB_URL = "sqlite:///
|
| 16 |
|
| 17 |
@pytest.fixture(scope="module")
|
| 18 |
def test_db():
|
|
@@ -49,18 +52,19 @@ def test_db():
|
|
| 49 |
db.close()
|
| 50 |
Base.metadata.drop_all(bind=engine)
|
| 51 |
engine.dispose()
|
| 52 |
-
|
|
|
|
| 53 |
try:
|
| 54 |
-
os.remove(
|
| 55 |
except Exception:
|
| 56 |
pass
|
| 57 |
|
| 58 |
@pytest.fixture(scope="module")
|
| 59 |
def policy_service():
|
| 60 |
-
return PolicyService(workspace_root=
|
| 61 |
|
| 62 |
def load_test_cases():
|
| 63 |
-
test_cases_path = "
|
| 64 |
with open(test_cases_path, "r", encoding="utf-8") as f:
|
| 65 |
return json.load(f).get("test_cases", [])
|
| 66 |
|
|
|
|
| 11 |
from backend.services.policy_service import PolicyService
|
| 12 |
from backend.services.confidence_calculator import evaluate_confidence
|
| 13 |
|
| 14 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
+
WORKSPACE_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, "..", ".."))
|
| 16 |
+
|
| 17 |
# Use a separate test SQLite database
|
| 18 |
+
TEST_DB_URL = f"sqlite:///{os.path.join(WORKSPACE_ROOT, 'backend', 'database', 'test_plum.db')}"
|
| 19 |
|
| 20 |
@pytest.fixture(scope="module")
|
| 21 |
def test_db():
|
|
|
|
| 52 |
db.close()
|
| 53 |
Base.metadata.drop_all(bind=engine)
|
| 54 |
engine.dispose()
|
| 55 |
+
test_db_file = os.path.join(WORKSPACE_ROOT, 'backend', 'database', 'test_plum.db')
|
| 56 |
+
if os.path.exists(test_db_file):
|
| 57 |
try:
|
| 58 |
+
os.remove(test_db_file)
|
| 59 |
except Exception:
|
| 60 |
pass
|
| 61 |
|
| 62 |
@pytest.fixture(scope="module")
|
| 63 |
def policy_service():
|
| 64 |
+
return PolicyService(workspace_root=WORKSPACE_ROOT)
|
| 65 |
|
| 66 |
def load_test_cases():
|
| 67 |
+
test_cases_path = os.path.join(WORKSPACE_ROOT, "test_cases.json")
|
| 68 |
with open(test_cases_path, "r", encoding="utf-8") as f:
|
| 69 |
return json.load(f).get("test_cases", [])
|
| 70 |
|
backend/utils/mock_doc_generator.py
CHANGED
|
@@ -11,7 +11,9 @@ from reportlab.lib.units import inch
|
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
os.makedirs(TEST_DATA_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
def generate_prescription_pdf(case_id: str, patient_name: str, date_str: str, rx_data: dict, output_path: str):
|
|
@@ -290,7 +292,7 @@ def generate_bill_pdf(case_id: str, patient_name: str, date_str: str, bill_data:
|
|
| 290 |
|
| 291 |
def generate_all_mock_documents():
|
| 292 |
"""Reads test_cases.json and creates mock files for all cases in workspace."""
|
| 293 |
-
test_cases_path = "
|
| 294 |
if not os.path.exists(test_cases_path):
|
| 295 |
logger.error(f"Cannot generate mock documents - test_cases.json not found at {test_cases_path}")
|
| 296 |
return
|
|
|
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
+
WORKSPACE_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, "..", ".."))
|
| 16 |
+
TEST_DATA_DIR = os.path.join(WORKSPACE_ROOT, "test_data")
|
| 17 |
os.makedirs(TEST_DATA_DIR, exist_ok=True)
|
| 18 |
|
| 19 |
def generate_prescription_pdf(case_id: str, patient_name: str, date_str: str, rx_data: dict, output_path: str):
|
|
|
|
| 292 |
|
| 293 |
def generate_all_mock_documents():
|
| 294 |
"""Reads test_cases.json and creates mock files for all cases in workspace."""
|
| 295 |
+
test_cases_path = os.path.join(WORKSPACE_ROOT, "test_cases.json")
|
| 296 |
if not os.path.exists(test_cases_path):
|
| 297 |
logger.error(f"Cannot generate mock documents - test_cases.json not found at {test_cases_path}")
|
| 298 |
return
|
start.sh
CHANGED
|
@@ -11,5 +11,5 @@ sleep 3
|
|
| 11 |
TARGET_PORT=${PORT:-7860}
|
| 12 |
echo "Starting Streamlit frontend on port $TARGET_PORT..."
|
| 13 |
|
| 14 |
-
# Run Streamlit in the foreground
|
| 15 |
-
streamlit run frontend/streamlit_app.py --server.port $TARGET_PORT --server.address 0.0.0.0
|
|
|
|
| 11 |
TARGET_PORT=${PORT:-7860}
|
| 12 |
echo "Starting Streamlit frontend on port $TARGET_PORT..."
|
| 13 |
|
| 14 |
+
# Run Streamlit in the foreground with CORS and XSRF disabled for iframe hosting
|
| 15 |
+
streamlit run frontend/streamlit_app.py --server.port $TARGET_PORT --server.address 0.0.0.0 --server.enableCORS=false --server.enableXsrfProtection=false
|