From bd92d460685c6f923ce531ecfefaf9cfd1bd9df9 Mon Sep 17 00:00:00 2001 From: WangSL Date: Fri, 17 May 2024 01:34:48 +0800 Subject: [PATCH] get_plan_by_id.py --- api/__init__.py | 1 + api/get_plan_by_id.py | 16 ++++++++++++++++ api/insert_client.py | 4 ++-- main.py | 3 ++- model/client.py | 32 ++------------------------------ periodic_task/__init__.py | 0 6 files changed, 23 insertions(+), 33 deletions(-) create mode 100644 api/get_plan_by_id.py delete mode 100644 periodic_task/__init__.py diff --git a/api/__init__.py b/api/__init__.py index 1fb1c69..d18d654 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -14,3 +14,4 @@ from .insert_client import router as insert_client_router from .manage_plan import router as manage_plan_router from .allocate_room import router as allocate_room_router +from .get_plan_by_id import router as get_plan_by_id_router diff --git a/api/get_plan_by_id.py b/api/get_plan_by_id.py new file mode 100644 index 0000000..9150a8a --- /dev/null +++ b/api/get_plan_by_id.py @@ -0,0 +1,16 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session + +import model +from database import get_db + +router = APIRouter() + + +@router.get("/get_meal_plan_by_id") +async def get_plan_by_id(meal_plan_id: int, db: Session = Depends(get_db)): + return db.query(model.MealPlan).filter(model.MealPlan.id == meal_plan_id).first() + +@router.get("/get_recovery_plan_by_id") +async def get_plan_by_id(recovery_plan_id: int, db: Session = Depends(get_db)): + return db.query(model.RecoveryPlan).filter(model.RecoveryPlan.id == recovery_plan_id).first() diff --git a/api/insert_client.py b/api/insert_client.py index 0397560..4836111 100644 --- a/api/insert_client.py +++ b/api/insert_client.py @@ -37,7 +37,7 @@ class InsertClientRecv(BaseModel): meal_plan_seller: Union[Dict, None] = {} recovery_plan_seller: Union[Dict, None] = {} due_date: Union[str, None] = None - + status: int class Config: orm_mode = True @@ -67,7 +67,7 @@ def update_client_and_room(db, insert_client_recv: InsertClientRecv): reserve_recv_dict = dict(insert_client_recv) reserve_recv_dict["meal_plan_seller"] = json.dumps(insert_client_recv.meal_plan_seller) reserve_recv_dict["recovery_plan_seller"] = json.dumps(insert_client_recv.recovery_plan_seller) - reserve_recv_dict["status"] = ClientStatus.manual_create_without_room.value + # reserve_recv_dict["status"] = ClientStatus.manual_create_without_room.value try: db.execute(create_client_sql, reserve_recv_dict) db.flush() diff --git a/main.py b/main.py index 4fd413a..1396046 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ check_out_router, get_room_by_room_name_router, get_all_clients_router, fault_registration_router, get_baby_nurse_router, insert_baby_nurse_router, reminder_router, get_client_by_room_number_router, product_router, insert_client_router, - manage_plan_router, allocate_room_router) + manage_plan_router, allocate_room_router, get_plan_by_id_router) from fastapi.middleware.cors import CORSMiddleware model.Base.metadata.create_all(bind=engine) @@ -41,6 +41,7 @@ app.include_router(insert_client_router) app.include_router(manage_plan_router) app.include_router(allocate_room_router) +app.include_router(get_plan_by_id_router) origins = [ "*" ] diff --git a/model/client.py b/model/client.py index 86ec69c..0800ae8 100644 --- a/model/client.py +++ b/model/client.py @@ -30,26 +30,6 @@ class Client(Base): babies = relationship("Baby", back_populates="client") -# class RemovedClient(Base): -# __tablename__ = "removed_client" -# -# id = Column(Integer, primary_key=True) -# meal_plan_id = Column(Integer) -# recovery_plan_id = Column(Integer) -# assigned_baby_nurse = Column(Integer) -# name = Column(String(255), nullable=False) -# tel = Column(String(255), nullable=False) -# age = Column(Integer, nullable=False) -# scheduled_date = Column(String(255), nullable=False) -# check_in_date = Column(String(255), nullable=False) -# hospital_for_childbirth = Column(String(255), nullable=False) -# contact_name = Column(String(255), nullable=False) -# contact_tel = Column(String(255), nullable=False) -# mode_of_delivery = Column(String(255), nullable=False) -# room = Column(String(255), ForeignKey("room.room_number"), unique=True) -# status = Column(String(255), nullable=False) - - class Baby(Base): __tablename__ = "baby" @@ -70,16 +50,6 @@ class Baby(Base): client = relationship("Client", back_populates="babies") -# class ClientBabyNurse(Base): -# __tablename__ = "client_baby_nurse" -# -# id = Column(Integer, primary_key=True) -# client_id = Column(Integer, ForeignKey("client.id")) -# baby_nurse_id = Column(Integer, ForeignKey("baby_nurse.baby_nurse_id")) -# start_date = Column(String(255), nullable=False) -# end_date = Column(String(255), nullable=False) -# status = Column(String(255), nullable=False) - class BabyNurse(Base): __tablename__ = "baby_nurse" @@ -103,6 +73,7 @@ class MealPlan(Base): details = Column(Text) duration = Column(Integer) name = Column(String(255)) + price = Column(DECIMAL(10, 2), default=0.00) class RecoveryPlan(Base): @@ -111,3 +82,4 @@ class RecoveryPlan(Base): details = Column(Text) duration = Column(Integer) name = Column(String(255)) + price = Column(DECIMAL(10, 2), default=0.00) diff --git a/periodic_task/__init__.py b/periodic_task/__init__.py deleted file mode 100644 index e69de29..0000000