Spaces:
No application file
No application file
Upload main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from database import db
|
| 3 |
+
from models.patient import Patient # On importe ton modèle
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.get("/")
|
| 8 |
+
async def bonjour():
|
| 9 |
+
return {"message": "Serveur MedConnect actif !"}
|
| 10 |
+
|
| 11 |
+
# Nouvelle route pour enregistrer un patient
|
| 12 |
+
@app.post("/patients")
|
| 13 |
+
async def creer_patient(patient: Patient):
|
| 14 |
+
# On transforme les données en dictionnaire pour MongoDB
|
| 15 |
+
nouveau_patient = patient.model_dump()
|
| 16 |
+
|
| 17 |
+
# On l'insère dans une collection nommée "liste_patients"
|
| 18 |
+
resultat = await db.liste_patients.insert_one(nouveau_patient)
|
| 19 |
+
|
| 20 |
+
return {"id": str(resultat.inserted_id), "status": "Patient enregistré !"}
|