SuriRaja commited on
Commit
bb354ca
·
verified ·
1 Parent(s): bf80fcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -51
app.py CHANGED
@@ -1,52 +1,37 @@
1
- import sys
 
 
2
  import os
3
-
4
- # Add the current directory to the Python path
5
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
6
-
7
- # Import models
8
- from models.user_model import User
9
- from models.appointment_model import Appointment
10
- from models.prescription_model import Prescription
11
- from models.report_model import Report
12
- from models.medical_history_model import MedicalHistory
13
-
14
- # Define the directory for CSV files
15
- DATA_DIR = 'data'
16
-
17
- # Define paths to each CSV file
18
- USER_CSV = os.path.join(DATA_DIR, 'users.csv')
19
- APPOINTMENT_CSV = os.path.join(DATA_DIR, 'appointments.csv')
20
- PRESCRIPTION_CSV = os.path.join(DATA_DIR, 'prescriptions.csv')
21
- REPORT_CSV = os.path.join(DATA_DIR, 'reports.csv')
22
- MEDICAL_HISTORY_CSV = os.path.join(DATA_DIR, 'medical_history.csv')
23
-
24
- def load_all_data():
25
- # Load data from each model's CSV file
26
- users = User.load_from_csv(USER_CSV)
27
- appointments = Appointment.load_from_csv(APPOINTMENT_CSV)
28
- prescriptions = Prescription.load_from_csv(PRESCRIPTION_CSV)
29
- reports = Report.load_from_csv(REPORT_CSV)
30
- medical_history = MedicalHistory.load_from_csv(MEDICAL_HISTORY_CSV)
31
-
32
- # Print out the loaded data for verification
33
- print(f"Loaded {len(users)} users.")
34
- print(f"Loaded {len(appointments)} appointments.")
35
- print(f"Loaded {len(prescriptions)} prescriptions.")
36
- print(f"Loaded {len(reports)} reports.")
37
- print(f"Loaded {len(medical_history)} medical history records.")
38
-
39
- # Return all the data for further processing
40
- return users, appointments, prescriptions, reports, medical_history
41
-
42
- def main():
43
- print("Initializing MediConsult App...")
44
-
45
- # Load all data from CSV files
46
- users, appointments, prescriptions, reports, medical_history = load_all_data()
47
-
48
- # Additional logic to handle the application workflow
49
- # For example, managing user authentication, processing appointment requests, etc.
50
-
51
- if __name__ == "__main__":
52
- main()
 
1
+ from fastapi import FastAPI, File, UploadFile, HTTPException
2
+ from fastapi.responses import HTMLResponse
3
+ import shutil
4
  import os
5
+ from pathlib import Path
6
+
7
+ app = FastAPI()
8
+
9
+ # Use absolute path for the upload directory
10
+ BASE_DIR = Path(__file__).resolve().parent
11
+ UPLOAD_DIR = BASE_DIR / "uploads"
12
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
13
+
14
+ @app.post("/uploadfile/")
15
+ async def create_upload_file(file: UploadFile = File(...)):
16
+ # Sanitize the file name
17
+ filename = os.path.basename(file.filename)
18
+ file_location = UPLOAD_DIR / filename
19
+
20
+ try:
21
+ with open(file_location, "wb") as buffer:
22
+ shutil.copyfileobj(file.file, buffer)
23
+ return {"info": f"file '{filename}' saved at '{file_location}'"}
24
+ except Exception as e:
25
+ raise HTTPException(status_code=500, detail=str(e))
26
+
27
+ @app.get("/")
28
+ async def main():
29
+ content = """
30
+ <body>
31
+ <form action="/uploadfile/" enctype="multipart/form-data" method="post">
32
+ <input name="file" type="file">
33
+ <input type="submit">
34
+ </form>
35
+ </body>
36
+ """
37
+ return HTMLResponse(content)