def create_medicine( name: str, storage_time: date, amount: float, price: float, type: MedicineType, cooking_method: CookingMethod, ingredients_ids: t.List[int] = [], ) -> Medicine: med = Medicine( name=name, storage_time=storage_time, amount=amount, price=price, type=type, ) ingredients = (session.query(Ingredient).filter( Ingredient.id.in_(ingredients_ids))) if ingredients: med.ingredients.extend(ingredients) session.add(med) session.commit() cb_service.create_cooking_book(med.id, cooking_method) return med
def add_ingredient( component_id: int, dose: int, ) -> Ingredient: ingredient_record = Ingredient( component_id=component_id, dose=dose ) session.add(ingredient_record) session.commit() return ingredient_record
def create_critical_norm( component_id: int, amount: float, ) -> CriticalNorm: component = session.query(Component).filter( Component.id == component_id).first() if not component: return None crit_norm = CriticalNorm(component_id=component_id, amount=amount) session.add(crit_norm) session.commit() return crit_norm
def create_supply_request( component_id: int, client_id: int, ) -> SupplyRequest: component = session.query(Component).filter( Component.id == component_id).first() if not component: return None sup_request = SupplyRequest( component_id=component_id, client_id=client_id, ) session.add(sup_request) session.commit() return sup_request
def create_client( first_name: str, last_name: str, phone: str, address: str, age: int, ) -> Client: client = Client( first_name=first_name, last_name=last_name, phone=phone, address=address, age=age, ) session.add(client) session.commit() return client
def create_recipe( doctor: str, client_id: int, diagnosis: str, amount: float, consumption_type: ConsumptionType, medicine_name: str, order_id: Optional[int] = None, ) -> Recipe: client = session.query(Client).filter(Client.id == client_id).first() if not client: return None recipe = Recipe( doctor=doctor, client_id=client_id, diagnosis=diagnosis, amount=amount, consumption_type=consumption_type, order_id=order_id, medicine_name=medicine_name, ) session.add(recipe) session.commit() return recipe
def create_component(name: str, price: float, amount: float) -> Component: com = Component(name=name, price=price, amount=amount) session.add(com) session.commit() return com
def create_cooking_book(medicine_id: int, method: CookingMethod) -> CookingBook: cooking_book = CookingBook(medicine_id=medicine_id, method=method) session.add(cooking_book) session.commit() return cooking_book