Example #1
0
def upload_obj(patientid, post_data):
    """
    Upload an obj in the system. The post data is a dict.

    :param post_data: dict
    :returns: a status, a str( obj's info on success, err info on failure)
    """
    # print(post_data)
    obj = ''
    try:
        logger.debug('in upload_obj')
        logger.debug('auth_url:{}, account_username:{}, password:{}'.format(
            conf.auth_url, conf.account_username, conf.password))

        resp_dict = {}
        storage_url, auth_token = swiftclient.client.get_auth(
                                        conf.auth_url,
                                        conf.account_username,
                                      conf.password,
                                      auth_version=conf.auth_version)
        resp_dict['auth_token'] = auth_token
        resp_dict['storage_url'] = storage_url + '/' + \
                        conf.container + '/' + patientid + '/' + \
                        patientid + '-' + post_data['objname'] + '-' + post_data['datetime']
        with database.atomic():
            obj = ObjectModel.create_by_dict(patientid, post_data)
            logger.debug(obj)
            logger.debug('in database.atomic')
    # except peewee.IntegrityError:
    #     logger.warning('in doctor model create except')

        # # `username` is a unique column, so this username already exists,
        # # making it safe to call .get().
        # old_user = AccountModel.get(AccountModel.username == username)
        # logger.warning('user exists...')
        # resp_dict['info'] = 'user exists, did not create user:%s' % username
        # resp.status = falcon.HTTP_409
        # try:
        #     change_user = AccountModel.get(AccountModel.username==username,
        #                     AccountModel.password==password)
        # except:
        #     logger.debug('change user data failed...')
    except Exception as ex:
        logger.error('Exception: ', ex)
        q = ObjectModel.delete().where(ObjectModel.objid==
            patientid + '-' + post_data['objname'] + '-' + post_data['datetime'])
        q.execute()
        return 0, {'errinfo':'create obj failed, did not create obj'}

    else:
        resp_dict['info'] = 'make PUT request to storage_url with auth_token as "x-storage-token" in headers'
        return 1, resp_dict
Example #2
0
def upload_comment(patientid, doctorid, post_data):
    """
    Upload an comment in the system. The post data is a dict.

    :param post_data: dict
    :returns: a status, a str( comment's info on success, err info on failure)
    """
    # print(post_data)
    comment = ''
    try:
        logger.debug('in upload_comment')

        resp_dict = {}
        with database.atomic():
            comment = CommentModel.create_by_dict(patientid, doctorid, post_data)
            logger.debug('comment:{}'.format(comment))
            logger.debug('in database.atomic')
    # except peewee.IntegrityError:
    #     logger.warning('in doctor model create except')

        # # `username` is a unique column, so this username already exists,
        # # making it safe to call .get().
        # old_user = AccountModel.get(AccountModel.username == username)
        # logger.warning('user exists...')
        # resp_dict['info'] = 'user exists, did not create user:%s' % username
        # resp.status = falcon.HTTP_409
        # try:
        #     change_user = AccountModel.get(AccountModel.username==username,
        #                     AccountModel.password==password)
        # except:
        #     logger.debug('change user data failed...')
    except Exception as ex:
        logger.error('Exception: ', ex)
        q = CommentModel.delete().where(CommentModel.drug_id==
            patientid + '-' + doctorid + '-' + post_data['datetime'])
        q.execute()
        return 0, {'errinfo':'create comment failed, did not create comment'}

    else:
        # resp_dict['info'] = 'make PUT request to storage_url with auth_token as "x-storage-token" in headers'
        resp_dict['comment_id'] = comment.comment_id
        return 1, resp_dict
Example #3
0
def register_doctor(post_data):
    """
    Register a doctor in the system. The post data is a dict.

    :param post_data: dict
    :returns: a status, a str( doctor's info on success, err info on failure)
    """
    # print(post_data)
    doctor = ''
    try:
        logger.debug('in register_doctor')

        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')

        # # `username` is a unique column, so this username already exists,
        # # making it safe to call .get().
        # old_user = AccountModel.get(AccountModel.username == username)
        # logger.warning('user exists...')
        # resp_dict['info'] = 'user exists, did not create user:%s' % username
        # resp.status = falcon.HTTP_409
        # try:
        #     change_user = AccountModel.get(AccountModel.username==username,
        #                     AccountModel.password==password)
        # except:
        #     logger.debug('change user data failed...')
    except Exception as ex:
        logger.error('Exception: ', ex)
        q = DoctorModel.delete().where(DoctorModel.email==doctor)
        q.execute()
        return 0, 'create doctor failed, did not create doctor', ''
    try:
        with database.atomic():
            user = LoginModel.create_by_dict('doctor', post_data)
            logger.debug(doctor)
            logger.debug('in database.atomic')
    # except peewee.IntegrityError:
    #     logger.warning('in doctor model create except')

        # # `username` is a unique column, so this username already exists,
        # # making it safe to call .get().
        # old_user = AccountModel.get(AccountModel.username == username)
        # logger.warning('user exists...')
        # resp_dict['info'] = 'user exists, did not create user:%s' % username
        # resp.status = falcon.HTTP_409
        # try:
        #     change_user = AccountModel.get(AccountModel.username==username,
        #                     AccountModel.password==password)
        # except:
        #     logger.debug('change user data failed...')
    except Exception as ex:
        logger.error('Exception: ', ex)
        q = LoginModel.delete().where(LoginModel.username==doctor)
        q.execute()
        return 0, 'create doctor failed, did not create doctor', ''

    else:
        return 1, str(doctor), str(user.password)