Exemplo n.º 1
0
def get_equipment(equipmentId):
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        res = DBQuery.get_equipment(equipmentId)
        return res
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 2
0
def get_disease_categories():
    '''
    :return: all disease categories
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_disease_categories()
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 3
0
def get_flow(flowId):
    '''
    :param flowId
    :return: the details of the flow
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_flow(flowId)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 4
0
def get_role_job(roleName):
    '''
    :param roleName:
    :return: the jobs the role should do
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_role_job(roleName)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 5
0
def get_prescription(id):
    '''
    :param id: prescription's id
    :return: the detail of the prescription
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_prescription(id)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 6
0
def get_case_detail(caseId):
    '''
    :param caseId
    :return: the detail of the case
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_case_detail(caseId)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 7
0
def get_operation(operationName):
    '''
    :param operationName
    :return: the detail of the operation
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_operation(operationName)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 8
0
def get_examination_result(id):
    '''
    :param id
    :return: the detail of the examination result
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_examination_result(id)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 9
0
def get_cases(diseaseName):
    '''
    :param diseaseName
    :return: all the cases of the disease
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_cases(diseaseName)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 10
0
def get_medicine(approveNumber):
    '''
    :param approveNumber
    :return: the details of the medicine
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_medicine(approveNumber)
    else:
        return json.dumps({'code': 403, 'data': ''})
Exemplo n.º 11
0
def get_job_detail(roleName, jobName):
    '''
    :param roleName:
    :param jobName
    :return: the details of the jobs that staffs in this role may care about
    '''
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_job_detail(jobName)
    else:
        return json.dumps({'code': 403, 'data': ''})
def login(userID, hash):
    token = ''
    if userID is None or hash is None:
        return json.dumps({'code': 403, 'data': {'result': False}}), None
    else:
        if redis_conn.exists('user_%s' % userID):
            res = redis_conn.get('user_%s' % userID)
            user_info = json.loads(res)
        else:
            user_info = DBQuery.get_user(userID)
            if user_info is None:
                return json.dumps({
                    'code': 403,
                    'data': {
                        'result': False
                    }
                }), None
            redis_conn.set('user_%s' % userID, json.dumps(user_info))

        validate_hash = sha1((user_info['id'] + '_' +
                              user_info['passwd']).encode('utf8')).hexdigest()

        if validate_hash == hash:
            token = sha1(
                (str(random.getrandbits(64)) + user_info['name'] + '_' +
                 user_info['passwd']).encode('utf8')).hexdigest()

            redis_conn.set(
                'token_%s' % token, value=userID, ex=LOGIN_EXPIRE_TIME
            )  # expired after LOGIN_EXPIRE_TIME seconds  without any request
            if redis_conn.exists('user_token_%s' % userID):
                old_token = redis_conn.get('user_token_%s' %
                                           userID).decode('utf8')
                redis_conn.delete('token_%s' % old_token)
            redis_conn.set('user_token_%s' % userID,
                           value=token,
                           ex=LOGIN_EXPIRE_TIME
                           )  # expired after 30 min without any request

            return json.dumps({
                'code': 1000,
                'data': {
                    'result': True,
                    'token': token
                }
            }), token
        else:
            return json.dumps({'code': 403, 'data': {'result': False}}), None
Exemplo n.º 13
0
def get_department_info(departmentName):
    token = request.cookies.get('token')
    if token is not None and validate.validate(token):
        return DBQuery.get_department_info(departmentName)
    else:
        return json.dumps({'code': 403, 'data': ''})