def create_logbook(): error_msg = '' lb_type = request.args.get('lb_type') is_force = request.args.get('force') # '1': force to create new lgbk is_switch = request.args.get('switch') # '1': switch to new lgbk pathway ulvl = manager.getInfo(current_user.id)[3] if not develop_mode: # limit what logbooks can user create if ulvl == 'A' and lb_type != 'Certification': allowed = manager.check_finished_certification(current_user.id) if not allowed: error_msg = 'ERROR: Requirement not met. Have you passed your Certification training?' # print(error_msg) response_data = myResponse(400, "bad", error_msg) return response_data, 400 elif ulvl == 'B' and (lb_type == 'Certification' or lb_type == 'Conversion'): error_msg = f'ERROR: Level B user cannot create new {lb_type} logbooks.' response_data = myResponse(400, "bad", error_msg) return response_data, 400 ret, error_msg = manager.create_logbook(current_user.id, lb_type, is_force, is_switch) # conflict in creating recertification logbook pathways if ret == 1: # print(error_msg) response_data = myResponse(400, "swch", error_msg) return response_data, 400 # creating a logbook that already exist elif ret == 2: # print(error_msg) response_data = myResponse(400, "dup", error_msg) return response_data, 400 # set/update user's on-going training/logbook cur_lb_type = manager.getInfo(current_user.id)[4] # 1. start new conversion if lb_type == manager.lb_type['conv']: if lb_type not in cur_lb_type: manager.change_user_status(current_user.id, prog=cur_lb_type + ',' + lb_type) # 2. add new logbook into cur training string elif manager.lb_type['conv'] in cur_lb_type: if lb_type not in cur_lb_type: manager.change_user_status(current_user.id, prog=lb_type + ',' + cur_lb_type) # 3. change to new logbook type else: manager.change_user_status(current_user.id, prog=lb_type) response_data = myResponse(200, "OK", error_msg) return response_data, 200
def change_status(uid, lvl=None, prog=None): if not current_user.is_authenticated: return 'login first, bro' # verify admin to proceed mee = manager.getInfo(current_user.id)[3] if mee != 'admin': return f'Whoa stop! You are not allowed to do that! Lvl {mee} user' uid = 'CTCA' + uid if manager.getInfo(uid)[3] == 'admin': return "Hey! You can't just banish another admin.. " if manager.change_user_status(uid, lvl, prog): return f'OK: User {uid} changed to level {lvl} and program {prog}.' else: return f"Error: failed changing user {uid}'s status."
def erase_user(uid=None, yes=False): my_role = manager.getInfo(current_user.id)[3] if my_role != 'admin': return 'Hey! Only admin can do this!' print(f'[WARNING] Admin is tring to erase user {uid}! Take a look!') if yes: ret, error_msg = manager.erase_user(current_user.id, uid) return error_msg else: return f'Dear admin, are you sure you wanna erase user {uid}??'
def change_pswd(uid, pswd): # verify admin to proceed mee = manager.getInfo(current_user.id)[3] if mee != 'admin': return f'Whoa stop! You are not allowed to do that! Lvl {mee} user' uid = 'CTCA' + uid ret = manager.change_user_info(uid, 'pass', pswd) if ret[0]: return f'OK: Password of user {uid} is set to {pswd}' else: return f"Error: failed changing user {uid}'s password. {ret[1]}"
def change_date(uid, dat=None): # verify admin to proceed mee = manager.getInfo(current_user.id)[3] if mee != 'admin': return f'Whoa stop! You are not allowed to do that! Lvl {mee} user' uid = 'CTCA' + uid ##### temp use ##### dat = manager.db.child("Trainee").child(uid).child( "Date_of_attendance").get().val() #################### if manager.change_user_date(uid, dat): return f'OK: Set starting date to {dat} for user {uid}.' else: return f"Error: failed changing user {uid}'s starting date."
def mainpage(): if not current_user.is_authenticated: print('[WARN] Not signed in yet!') return redirect(url_for('index')) if use_react: user = {'username': current_user.name} ulvl = manager.getInfo(current_user.id, update=False)[3] user['supervision'] = '-Logbook Supervision' if ulvl == 'B' else '' return render_template('mainpage.html', user=user) else: user = {'username': current_user.name} user['userid'] = current_user.id return render_template('main.html', user=user)
def verify_logbook(): stuid = request.args.get('uid') lb_type = request.args.get('lb_type') error_msg = '' mee = manager.getInfo(current_user.id, update=False)[3] if mee != 'B' and mee != 'admin': error_msg = f'No way! You are not even a supervisor! Lvl {mee} user' # uid = 'CTCA'+uid # lb_type = manager.lb_type[lb_type] ret, error_msg = manager.verify_logbook(stuid, lb_type, develop_mode) if ret: return myResponse(200, "OK", message=error_msg), 200 else: return myResponse(400, "BAD", message=error_msg), 400
def send_message(): message = request.form['message'] print('message is ', message) project_id = os.getenv('DIALOGFLOW_PROJECT_ID') pdf_par = re.compile(r'PDF_PAR_*') uname = current_user.name uid = current_user.id urole = manager.getInfo(uid)[3] print('========loged in user is ', uname, uid, urole) fulfillment_text = detect_intent_texts(project_id, uname + '_' + uid + '_' + urole, message, 'en') response_text = {"message": fulfillment_text} return jsonify(response_text)
def get_user_name(): if request.method == 'GET': info = manager.getInfo(current_user.id) response_data = myResponse( 200, "OK", "ping success", "Get the userid and name.", { 'name': current_user.name, 'id': current_user.id, 'email': info[1], 'phone': info[2], 'usertype': info[3], # user level None/A/B # 'program': info[4], # active user logbook type }) return response_data, 200
def recruit_students(stuid, supid=None): mee = manager.getInfo(current_user.id)[3] if supid is None: # for supervisors choosing students if mee != 'B': return f'No way! You are not even a supervisor! Lvl {mee} user' supid = current_user.id else: # for admin allocating student to supervisor if mee != 'admin': return f'Stop it! Only admin can choose two sides! Lvl {mee} user' supid = 'CTCA' + supid stuid = 'CTCA' + stuid if manager.recruit(supid, stuid)[0]: return f'OK: Student {stuid} is now enslaved by supervisor {supid}.' else: return f'ERROR: Supervisor {supid} failed recruiting student {stuid}.'
def send_file(): #1.obtain current user infor project_id = os.getenv('DIALOGFLOW_PROJECT_ID') uname = current_user.name uid = current_user.id urole = manager.getInfo(uid)[3] match = re.search("\d{6}", uid) logbook_id = 'LB' + match[0] print('loged in user is ', uname, uid, urole) #2. do NLP on uploaded pdf message = request.form['message'] filename = request.form['fileName'] data = base64.b64decode(message) file = io.BytesIO(data) pp = nlpOperation.document(file) cor, car, native, aorta = '0', '0', '0', '0' if 'Coronary' in pp or 'coronary' in pp: native = '1' for j in pp.split('\n'): if re.findall( r"[Aa][Dd][Dd][Ii][Tt][Ii][Oo][Nn][Aa][Ll].*[Cc][Aa][Rr][Dd][Ii][Aa][Cc].*[Ff][Ii][Nn][Dd][Ii][Nn][Gg][Ss]", j): cor, car = '1', '1' break # target_date,tartget_fac,dlp_value,id_value,target_Dr = step_2._get_information(pp) sclass = nlpOperation.main_processing(file, sample=True) target_date, tartget_fac, dlp_value, id_value, target_Dr = sclass.execute() aorta = '1' if native == '0' else '0' target_date = target_date[0] if len(target_date) > 0 else "" co_reps = target_Dr['Co-report'] co_reps = co_reps.remove(uname) if uname in co_reps else co_reps co_rep = ','.join(co_reps) sup = ','.join(target_Dr['Supervisor']) #convert date format: try: target_date = datetime.strptime(target_date, '%d-%b-%Y') target_date = target_date.strftime('%d/%m/%Y') except: pass #3. put extracted info into database train_type = manager.db.child('Identification').child(uid).child( 'Upload').get().val() if '_' in train_type: recertf = train_type.split('_')[0] pathway = train_type.split('_')[1][-1] schema = schemaExtraction.logbook_entry("Recertification", path_way=pathway) train_type = recertf.capitalize() + '_Pathway' + str(pathway) else: schema = schemaExtraction.logbook_entry(train_type) if ' Supervising' in schema.keys(): schema['Supervising'] = schema.pop(' Supervising') keys = [ 'Date', 'Facility', 'DLP', 'UEN_OR_Patient_ID', 'Native_Coronary', 'Graft_Or_Thoracic_Aorta', 'Non-coronary_cardiac_findings', 'Non-cardiac_findings', 'Reporting_Doctor', 'Co_reporting', 'Supervising' ] values = [ target_date, tartget_fac, dlp_value, id_value, native, aorta, cor, car, co_rep, co_rep, sup ] for k, v in zip(keys, values): if k in schema: schema[k] = v n = manager.db.child('Logbook').child(logbook_id).child( train_type).get().each() number_cases = len(n) - 3 if number_cases < 0: manager.db.child('Logbook').child(logbook_id).child(train_type).child( 1).set(schema) else: manager.db.child("Logbook").child(logbook_id).child(train_type).child( int(n[number_cases].key()) + 1).set(schema) #update status total = manager.db.child('Status').child(uid).child(train_type).child( 'total').get().val() manager.db.child('Status').child(uid).child(train_type).child('total').set( total + 1) if train_type == 'Certification': cardiac_findings = manager.db.child('Status').child(uid).child( train_type).child('Non-cardiac_findings').get().val() coronary_cardiac_findings = manager.db.child('Status').child( uid).child(train_type).child( 'Non-coronary_cardiac_findings').get().val() manager.db.child('Status').child(uid).child(train_type).child( 'Non-cardiac_findings').set(cardiac_findings + int(car)) manager.db.child('Status').child(uid).child(train_type).child( 'Non-coronary_cardiac_findings').set(coronary_cardiac_findings + int(cor)) message = 'Upload_File_Analysis+' + filename fulfillment_text = detect_intent_texts(project_id, uname + '_' + uid + '_' + urole, message, 'en') response_text = {"message": fulfillment_text} return jsonify(response_text)