Пример #1
0
def delete_appointment(doctorid, datetimeslot, patientid):
    """
    delete_appointment in the system. The post data is in json format.

    :param post_data: dict
    :returns: a status, a str( appointment's url on success, err info on failure)

    with database.atomic():
                doctor = DoctorModel.create_by_dict(post_data)
                logger.debug(doctor)
                logger.debug('in database.atomic')
        except peewee.IntegrityError:
            logger.warning('in doctor model create except')

    1. check if patient and doctor exist in db
    2. check if the appointment exist in redis
    3. make appointment if 1 and 2 ok
    3.2 add the appointment to the doctor's that day's schedule
    4. return if appointment exists, with reason if fail

    """
    # print(post_data)
    try:
        logger.debug('in delete_appointment')

    # check db when patient is ok
        rediscli.delete_data(doctorid + '/' + datetimeslot + '/' + patientid)
        schedule = rediscli.get_data(doctorid + '/' + datetimeslot[:8])
        if schedule:
            schedule = ast.literal_eval(schedule)
            del schedule[datetimeslot[8:]]
            rediscli.set_data(doctorid + '/' + datetimeslot[:8],
                json.dumps(schedule))


    except Exception as ex:
        logger.error('Exception: ', ex)
        # q = DoctorModel.delete().where(DoctorModel.uid==doctor)
        # q.execute()
        return 0, 'delete_appointment failed, did not delete_appointment'

    else:
        return 1, str(doctorid + '/' + datetimeslot + '/' + patientid)
Пример #2
0
def get_token(username, role):
    if role == 'admin':
        token = uuid.uuid4().hex
        rediscli.set_data('auth/admin', token)
        return token
    elif role == 'doctor':
        logger.debug('in doctor get_token, username:{}, role:{}'.format(username, role))
        user = DoctorModel.get(DoctorModel.email==username)
        logger.debug('user.patients:{}, type:{}'.format(user.patients, type(user.patients)))
        # patient_list = json.loads(str(user.patients))
        if user.patients:
            patient_list = ast.literal_eval(user.patients)
        else:
            patient_list = []
        logger.debug('patient_list:{}, type:{}'.format(patient_list, type(patient_list)))
        token = uuid.uuid4().hex
        rediscli.set_data('auth/{}'.format(username), token)
        for patient in patient_list:
            rediscli.set_data('auth/{}/{}'.format(username, patient), token)
        return token
    elif role == 'patient':
        token = uuid.uuid4().hex
        rediscli.set_data('auth/{}'.format(username), token)
        return token