Spaces:
No application file
No application file
Create services/clinical-brain/app/main.py
Browse files
services/clinical-brain/app/main.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
# Import our new modules
|
| 6 |
+
from .schemas import ConsultRequest, AIResponse
|
| 7 |
+
from .engine import ClinicalEngine
|
| 8 |
+
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
|
| 11 |
+
# Allow Next.js (port 3000) to talk to us
|
| 12 |
+
app.add_middleware(
|
| 13 |
+
CORSMiddleware,
|
| 14 |
+
allow_origins=["*"], # In production, set this to the specific domain
|
| 15 |
+
allow_methods=["*"],
|
| 16 |
+
allow_headers=["*"],
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
clinical_engine = ClinicalEngine()
|
| 20 |
+
|
| 21 |
+
@app.get("/")
|
| 22 |
+
def read_root():
|
| 23 |
+
return {"status": "Vitalis Brain is Online 🧠"}
|
| 24 |
+
|
| 25 |
+
@app.post("/api/v1/generate-note", response_model=AIResponse)
|
| 26 |
+
async def generate_clinical_note(request: ConsultRequest):
|
| 27 |
+
print(f"☕️ Processing Consult for Patient: {request.patient_id}")
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
# Call the logic engine
|
| 31 |
+
soap_note = await clinical_engine.generate_soap(request.audio_segments)
|
| 32 |
+
|
| 33 |
+
return AIResponse(
|
| 34 |
+
success=True,
|
| 35 |
+
generated_at=datetime.now(),
|
| 36 |
+
data=soap_note
|
| 37 |
+
)
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"Error: {e}")
|
| 40 |
+
raise HTTPException(status_code=500, detail="AI Processing Failed")
|