-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath_Parametrs.py
More file actions
35 lines (27 loc) · 906 Bytes
/
Path_Parametrs.py
File metadata and controls
35 lines (27 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI , Path , HTTPException
import json
app = FastAPI()
def get_data():
with open("patient.json", "r") as file:
data = json.load(file)
return data
@app.get("/")
def welcome_msg():
return {"message": "Welcome to the FastAPI application!"}
@app.get("/about")
def about():
return {"message": "This is a simple FastAPI application."}
@app.get("/view")
def view():
try:
return get_data()
except FileNotFoundError:
return {"error": "File not found. Please ensure 'patient.json' exists."}
@app.get("/patient/{patient_id}")
def get_patient(patient_id: str = Path(... , description="The ID of the patient to retrieve" , example= 'P001')):
# load all data
data = get_data()
if patient_id in data:
return data[patient_id]
else:
raise HTTPException(status_code=404, detail="Patient not found")