def create(request: schemas.User, db: session):
    new_user = models.User(name=request.name,
                           email=request.email,
                           password=Hash.bcrypt(request.password))
    db.add(new_user)
    db.commit()
    db.refresh(new_user)
    return new_user
示例#2
0
def pillboxes_create(how_many: int, db: session) -> list[dict]:

    for _ in range(how_many):
        pillbox_model = models.Pillbox()

        db.add(pillbox_model)
        db.commit()
        db.refresh(pillbox_model)

        yield pillbox_model
示例#3
0
def create_task(db: session, task: schemas.TaskCreate):
    db_task = models.Task(**task.dict(), added=datetime.now())
    db.add(db_task)
    db.commit()
    db.refresh(db_task)
    db_task.notes_path = f"notes/{db_task.id}_{db_task.name.replace(' ', '_')}.md"
    db.add(db_task)
    db.commit()
    db.refresh(db_task)
    return db_task
示例#4
0
def update_task(db: session, task_id: int, task: schemas.TaskCreate):
    updated = db.query(models.Task).filter(models.Task.id == task_id).update(
        task.dict())
    if (updated == 0):
        db_task = models.Task(**task.dict(), added=datetime.now())
        db.add(db_task)
        db.commit()
        db.refresh(db_task)
        db_task.notes_path = f"notes/{db_task.id}_{db_task.name.replace(' ', '_')}.md"
        db.add(db_task)
        db.commit()
        return db_task
    db.commit()
    return get_task(db, task_id)
示例#5
0
def doctors_updated_by_id(id: int, doctor: schemas.DoctorBase,
                          db: session) -> dict:
    db_doctor = db.query(models.Doctor).filter(models.Doctor.id == id).first()

    if not db_doctor:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                            detail=f"doctor with the id '{id}' not found")

    db_doctor.first_name = doctor.first_name
    db_doctor.last_name = doctor.last_name
    db_doctor.email = doctor.email
    db_doctor.phone_number = doctor.phone_number

    db.commit()
    db.refresh(db_doctor)

    return db_doctor
示例#6
0
def doctors_create(doctor: schemas.DoctorCreateIn, db: session) -> dict:
    password = pg.generate()

    doctor_model = models.Doctor(
        first_name=doctor.first_name,
        last_name=doctor.last_name,
        email=doctor.email,
        phone_number=doctor.phone_number,
        hashed_password=hashing.get_password_hash(password),
    )

    db.add(doctor_model)
    db.commit()
    db.refresh(doctor_model)

    doctor_model.__dict__['password'] = password

    return doctor_model
示例#7
0
def patients_create(patient: schemas.PatientCreateIn, db: session) -> dict:
    password = pg.generate()

    patient_model = models.Patient(
        first_name=patient.first_name,
        last_name=patient.last_name,
        email=patient.email,
        phone_number=patient.phone_number,
        hashed_password=hashing.get_password_hash(password),
        doctor_id=patient.doctor_id)

    db.add(patient_model)
    db.commit()
    db.refresh(patient_model)

    patient_model.__dict__['password'] = password

    return patient_model
示例#8
0
def patients_updated_by_id(id: int, patient: schemas.PatientBase,
                           db: session) -> dict:
    db_patient = db.query(
        models.Patient).filter(models.Patient.id == id).first()

    if not db_patient:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                            detail=f"patient with the id '{id}' not found")

    db_patient.first_name = patient.first_name
    db_patient.last_name = patient.last_name
    db_patient.email = patient.email
    db_patient.phone_number = patient.phone_number
    db_patient.doctor_id = patient.doctor_id

    db.commit()
    db.refresh(db_patient)

    return db_patient
示例#9
0
def pillboxes_updated_by_id(id: int, pillbox: schemas.PillboxBase,
                            db: session) -> dict:
    db_pillbox = db.query(
        models.Pillbox).filter(models.Pillbox.id == id).first()

    if not db_pillbox:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                            detail=f"pillbox with the id '{id}' not found")

    db_owner = db.query(
        models.Patient).filter(models.Patient.id == pillbox.owner_id).first()

    if not db_owner:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
                            detail=f"patient with the id '{id}' not found")

    db_pillbox.owner_id = pillbox.owner_id

    db.commit()
    db.refresh(db_pillbox)

    return db_pillbox
示例#10
0
def create(request: schemas.Blog, db: session):
    new_blog = models.Blog(title=request.title, body=request.body, user_id=1)
    db.add(new_blog)
    db.commit()
    db.refresh(new_blog)
    return new_blog