diff --git a/backend/main.py b/backend/main.py index d7a0e928..3a62cd1d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,6 +1,6 @@ from fastapi import FastAPI, HTTPException from pydantic import BaseModel -from .routers import docOffices, patients, patients_files, patients_notes, users, fileStorage +from .routers import docOffices, patients, patients_files, patients_notes, users, fileStorage, medicine from fastapi.middleware.cors import CORSMiddleware app = FastAPI() @@ -10,6 +10,7 @@ app.include_router(patients_files.router) app.include_router(patients_notes.router) app.include_router(users.router) app.include_router(fileStorage.router) +app.include_router(medicine.router) origins = [ "http://localhost", diff --git a/backend/medicines/Database-Of-Medicine-Prices-31-May-2024.xls b/backend/medicines/Database-Of-Medicine-Prices-31-May-2024.xls new file mode 100644 index 00000000..ea2e541a Binary files /dev/null and b/backend/medicines/Database-Of-Medicine-Prices-31-May-2024.xls differ diff --git a/backend/routers/medicine.py b/backend/routers/medicine.py new file mode 100644 index 00000000..6cd0c6f7 --- /dev/null +++ b/backend/routers/medicine.py @@ -0,0 +1,63 @@ +from fastapi import APIRouter, HTTPException +from pydantic import BaseModel +import os +import xlrd +#from pathlib import Path + + +router = APIRouter() + +class medicine(BaseModel): + name: str + unit: str + +#get user by email & doc Office ID +@router.get("/users/medicine/all", tags="medicine") +async def read_all_medicine(): + + return getMedicineData() + +def getMedicineData(): + # location = Path(__file__).parent() + # medFile = (location / 'medicines/Database-Of-Medicine-Prices-31-May-2024.xls').resolve() + path = os.getcwd() + parentDir = os.path.abspath(os.path.join(path, os.pardir)) + filePath = os.path.join(path, "backend/medicines", "Database-Of-Medicine-Prices-31-May-2024.xls") + # print(f"C Path : %s", path) + # print(f"P Path : %s", parentDir) + # print(f"F Path : %s", filePath) + book = xlrd.open_workbook_xls(filePath) + sh = book.sheet_by_index(0) + #print("{0} {1} {2}".format(sh.name, sh.nrows, sh.ncols)) + medlist = [] + + for rx in range(1,sh.nrows): + if(str(sh.cell_value(rx, 6)).strip() != ""): + medlist.append({ + "name": str(sh.cell_value(rx, 6)).strip(), + "unit": str(sh.cell_value(rx, 9)).strip(), + "dosage form": str(sh.cell_value(rx, 10)).strip(), + }) + seen = set() + medlist_noDuplicates = [] + for d in medlist: + t = tuple(d.items()) + #print(t[0][1]) + if t not in seen: + seen.add(t) + medlist_noDuplicates.append(d) + + #medlist_noDuplicates[:] = [d for d in thelist if d.get('id') != 2] + + + return sorted(medlist_noDuplicates, key=lambda d: d['name']) #qsort(medlist) + + +def qsort(inlist): + if inlist == []: + return [] + else: + pivot = inlist[0] + lesser = qsort([x for x in inlist[1:] if x < pivot]) + greater = qsort([x for x in inlist[1:] if x >= pivot]) + return lesser + [pivot] + greater \ No newline at end of file