Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
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