def invoice_record_query(browser, cache): login.select_workstation(browser, '门诊挂号收费工作台', cache) # 工作站是否打开 on_click(browser, (By.XPATH, '//div[contains(text(),"发票打印管理")]')) on_click(browser, (By.LINK_TEXT, '发票记录查询')) if element_wait(browser, (By.XPATH, '//span[contains(text(),"验证最小票据号窗口")]')): usename = get_text(browser, (By.XPATH, head.用户)).split('(')[0] bill_num = find_min_ticket(usename, '门诊收费发票') send_value(browser, (By.XPATH, verify_bill_window.票据号), bill_num) #输入票据号 on_click(browser, (By.XPATH, verify_bill_window.确定)) send_value(browser, (By.XPATH, query_area.刷卡), cache.get('patient_card') + '\n') end_time = time.time() + 1 while True: consume_collection = get_text( browser, (By.XPATH, invoice_history_list.发票记录)) if consume_collection != '暂无可显示票据记录...': break if time.time() > end_time: log.info('加载消费单失败') break return True else: log.info('验证最小票据号窗口弹出异常') return False
def test_arrearage_return_premium(browser, cache): log.info('开始运行欠费退费脚本') login.select_workstation(browser, '门诊挂号收费工作台', cache) # 工作站是否打开 on_click(browser, (By.XPATH, '//div[contains(text(),"欠费管理")]')) on_click(browser, (By.LINK_TEXT, '欠费结账/退费')) boolen = get_prompt(browser) if boolen: if re.sub('\D', '', boolen) == '0': log.info(boolen) return else: on_click(browser, (By.XPATH, "//button[contains(text(),'确定')]")) #刷卡 send_value(browser, (By.XPATH, patient_message.刷卡), cache.get('patient_card') + '\n') end_time = time.time() + 1 # arrearage_list_text = '' #欠费记账列表信息 while True: arrearage_list_text = get_text(browser, (By.XPATH, arrearage_list.欠费记账患者列表)) if '暂无可显示的欠费病人信息' not in arrearage_list_text: break if time.time() > end_time: log.info('欠费记账患者列表加载超时') return lists = ['处方单', '毒麻单', '检查单', '检验单', '治疗单', '皮试单', '输液单', '草药', '病理类'] applys = [] #所有申请单号 for appply_type in lists: applycation = cache.get(appply_type) if applycation: applys = applys + list(applycation) for apply_id in applys: if is_selected(browser, ((By.XPATH, arrearage_list.全选))): on_click(browser, (By.XPATH, arrearage_list.全选)) rek_no = find_rek_no(apply_id) if rek_no == []: log.info('%s申请单未计费或已退费' % rek_no) continue elif rek_no in arrearage_list_text: on_click(browser, (By.XPATH, '//div[contains(text(),"%s")]' % rek_no)) on_click(browser, (By.XPATH, '//div[contains(text(),"退 费")]')) element_wait(browser, (By.XPATH, '//span[contains(text(),"欠费记账退费窗口")]')) if '正常' in get_text(browser, (By.XPATH, arrearage_return_premium.退费列表)): webElement = browser.find_elements_by_xpath( arrearage_return_premium.退费列表 + '//label[contains(text(),"正常")]') for element in webElement: element.click() on_click(browser, (By.XPATH, '//button[contains(text(),"确定退费")]')) on_click(browser, (By.XPATH, '//button[contains(text(),"是")]')) microsoft_xps_document_writer('欠费退费单')
def test_arrearage_settle_accounts(browser, cache): log.info('开始运行欠费结账脚本') login.select_workstation(browser, '门诊挂号收费工作台', cache) # 工作站是否打开 on_click(browser, (By.XPATH, '//div[contains(text(),"欠费管理")]')) on_click(browser, (By.LINK_TEXT, '欠费结账/退费')) boolen = get_prompt(browser) if boolen: if re.sub('\D', '', boolen) == '0': log.info(boolen) return else: on_click(browser, (By.XPATH, "//button[contains(text(),'确定')]")) #刷卡 send_value(browser, (By.XPATH, patient_message.刷卡), cache.get('patient_card') + '\n') on_click(browser, (By.XPATH, '//button[contains(text(),"收 费")]')) on_click(browser, (By.XPATH, '//button[contains(text(),"是")]')) text = get_text(browser, (By.XPATH, "//label")) if "交款方式" not in text: microsoft_xps_document_writer('欠费结账单') else: send_value(browser, (By.XPATH, recharge_window.支付类型), '1') on_click(browser, (By.XPATH, '//button[contains(text(),"确认")]')) on_click(browser, (By.XPATH, '//button[contains(text(),"是")]')) microsoft_xps_document_writer('欠费结账充值单')
def click_application(browser, application_type_list, cache): for application_type in application_type_list: diction = cache.get(application_type) if diction: application_list = list(diction.keys()) executive_department_list = list(diction.values()) for t in list(set(executive_department_list)): # 刷卡 send_value(browser, (By.XPATH, head_button.刷卡), cache.get('patient_card') + '\n') # 判断弹出窗口是否正确弹出 if not is_text(browser, (By.XPATH, application_list_window.申请单列表), '申请单列表'): log.info('没有找到申请单列表窗口') return apply_messages = get_text( browser, (By.XPATH, application_list_window.申请单信息)) if application_type in ['处方单', '毒麻单', '草药']: on_click(browser, (By.XPATH, "//span[contains(text(),'全部药品')]")) date = time.strftime("%Y-%m-%d", time.localtime()) send_value(browser, (By.XPATH, application_list_window.开始时间), '2017-6-12') on_click(browser, (By.XPATH, "//button[contains(text(),'查询(Q)')]")) first_pos = 0 status = False #执行状态 for i in range(executive_department_list.count(t)): new_list = executive_department_list[first_pos:] next_pos = new_list.index(t) + 1 index = first_pos + new_list.index(t) print(application_list[index]) first_pos += next_pos locator = (By.XPATH, '//div[contains(text(),"' + application_list[index] + '")]') if application_list[index] in apply_messages: status = True focus(browser, locator) else: log.info('不存在%s申请单' % application_list[index]) if not status: on_click(browser, (By.XPATH, '//button[contains(text(),"取消(C)")]')) continue on_click(browser, (By.XPATH, "//button[contains(text(),'确定(S)')]")) time.sleep(0.5) send_value(browser, (By.XPATH, body.缴费方式), '\n') if get_prompt(browser): on_click(browser, (By.XPATH, "//button[contains(text(),'是')]")) microsoft_xps_document_writer(application_type) log.info('欠费记账脚本运行结束')
def test_pay_refund(browser, cache): log.info('开始运行预付费退费(窗口)脚本') login.select_workstation(browser, '门诊挂号收费工作台', cache) # 工作站是否打开 on_click(browser, (By.XPATH, '//div[contains(text(),"门诊退费管理")]')) on_click(browser, (By.LINK_TEXT, '预付费退费(窗口)')) boolen = get_prompt(browser) if boolen: if re.sub('\D', '', boolen) == '0': log.info(boolen) return else: on_click(browser, (By.XPATH, "//button[contains(text(),'确定')]")) lists = ['处方单', '毒麻单', '检查单', '检验单', '治疗单', '皮试单', '输液单', '草药', '病理类'] rek_no_list = [] for list_type in lists: applys = cache.get(list_type) if applys == None: continue for apply_id in list(applys.keys()): result = find_rek_no(apply_id) if result != []: rek_no_list.append(result.Rek.rek_no) else: log.info('%s申请单未收费或已退费' % apply_id) for rek_no in rek_no_list: # print(rek_no) send_value(browser, (By.XPATH, query_area.缴费流水号), rek_no + '\n') apply_status = get_text(browser, (By.XPATH, list_area.退费明细列表 + '//label')) if '正常' in apply_status: status_elements = browser.find_elements_by_xpath(list_area.退费明细列表 + '//label') for status_element in status_elements: status_element.click() if '取消' in get_text(browser, (By.XPATH, list_area.退费明细列表 + '//label')): on_click(browser, (By.XPATH, query_area.退费)) on_click(browser, (By.XPATH, '//button[contains(text(),"确定")]')) microsoft_xps_document_writer('退费单') on_click(browser, (By.XPATH, '//button[contains(text(),"确定")]')) log.info('运行预付费退费(窗口)脚本结束')
def test_invoice_obsolete(browser, cache): log.info('开始运行发票作废脚本') if not invoice_record_query(browser, cache): return consume_collection = get_text(browser, (By.XPATH, invoice_history_list.发票记录)) mechanism_numbe = find_mechanism_numbe(cache.get('rek_no_list')) if mechanism_numbe and (mechanism_numbe[0] in consume_collection): on_click(browser, (By.XPATH, '//div[contains(text(),"%s")]' % mechanism_numbe)) on_click(browser, (By.XPATH, "//button[contains(text(),'作废')]")) on_click(browser, (By.XPATH, "//button[contains(text(),'是')]")) microsoft_xps_document_writer('票据作废单') else: log.info('没有找到机制号') log.info('发票作废脚本运行结束')
def test_businessCard(browser, cache): #start login login.select_workstation(browser, '基础费用管理', cache) # 点击左边菜单 on_click(browser, (By.XPATH, "//span[contains(text(), '患者信息查询')]")) # 点击二级菜单 on_click(browser, (By.XPATH, "//span[contains(text(), '批量制卡')]")) # #清除垃圾数据 # elements = browser.find_elements_by_xpath("//button[contains(text(), '生成卡磁道')]") # print(len(elements)) # # for i in range(len(elements)): # if len(elements) >= 1: # browser.find_element_by_xpath("//button[contains(text(), '生成卡磁道')]").click() # browser.find_element_by_xpath("//button[contains(text(), '是')]").click() # time.sleep(1) # # else: # break # # time.sleep(2) # # elements2 = browser.find_elements_by_xpath("//button[contains(text(), '确认')]") # print(len(elements2)) # # for i in range(len(elements2)): # if len(elements2) >= 1: # browser.find_element_by_xpath("//button[contains(text(), '确认')]").click() # browser.find_element_by_xpath("//button[contains(text(), '是')]").click() # time.sleep(1) # # else: # break # 输入预计制卡数量,点击批量生成 send_value(browser, (By.XPATH, "//input"), '1') on_click(browser, (By.XPATH, "//button[contains(text(), '生成批次')]")) #获取压缩文件时间,用于匹配压缩文件 # now = time.strftime("%Y%m%d%H", time.localtime()) # time.sleep(1) # 点击生成磁道 time.sleep(1) browser.find_elements(By.XPATH, "//button[contains(text(), '生成卡磁道')]")[0].click() on_click(browser, (By.XPATH, "//button[contains(text(), '是')]")) # 点击下载 time.sleep(2) browser.find_elements(By.XPATH, "//button[contains(text(), '下载')]")[0].click() on_click(browser, (By.XPATH, "//button[contains(text(), '是')]")) # 点击确认 end_time = time.time() + 500 time.sleep(2) while True: time.sleep(1) text = get_text(browser, (By.XPATH, '//span')) if '提示' not in text: print('提示不存在') break if time.time() > end_time: log.info('页面加载超时') return on_click(browser, (By.XPATH, "//button[contains(text(), '确认')]")) on_click(browser, (By.XPATH, "//button[contains(text(), '是')]")) # 匹配下载文件 f = browser.find_element_by_xpath( "/html/body/div[1]/div/div[2]/div[1]/div[2]/div[2]/div/div/div[2]/div[2]/div/div[1]/div[1]/div[2]/div/div[1]/table/tbody/tr/td[1]/div" ) fname = f.text #使用获取页面的批次号来匹配压缩文件 for i in os.listdir(path.download_dir): #获取指定下载文件夹所有文件 if (i.split(".")[0].find(fname)) > 0: #使用字符串对比匹配到下载文件 fpath = os.path.join(path.download_dir, i) #生成解压文件路径 zip = zipfile.ZipFile(fpath) zipname = zip.namelist() #返回压缩包中所有文件的文件名 zip.extractall() #解压所有文件 zip.close() f = open(zipname[0]) lines = f.readline() # print(lines) f.close() # 拼写制卡卡号 card = '%E?;' + lines.rstrip('\n').split("|")[1] + '?+E?' cache.set('patient_card', card) log.info(card) Utility.writeFile(card) # 删除解压文件 if os.path.exists(zipname[0]): os.remove(zipname[0])
def test_apply_pharm(browser, cache): log.info('开始运行供药脚本') # 判断门诊挂号收费工作站是否打开 login.select_workstation(browser, '药房工作站', cache) if int(cache.get('resultType')) != 1: return # 获取申请单号及执行科室 application_list = list(cache.get('处方单').keys()) execute_list = list(set(list(cache.get('处方单').values()))) # 选取工作站 workstationElement = browser.find_element_by_xpath( PdsApplyPharmElement.button[0]['key']) workstationElement.click() time.sleep(1) workstationInputElement = browser.find_element_by_xpath( PdsApplyPharmElement.input[0]['key']) workstationInputElement.clear() time.sleep(1) if workstationInputElement.text == "": workstationInputElement.send_keys("光谷院区: " + execute_list[0]) else: workstationInputElement.clear() time.sleep(1) workstationInputElement.send_keys("光谷院区: " + execute_list[0]) time.sleep(1) workstationInputElement.send_keys(Keys.ENTER) on_click(browser, (By.XPATH, '//button[contains(text(),"确定")]')) browser.implicitly_wait(30) time.sleep(2) # 处方供药 reManageElement = browser.find_element_by_xpath( PdsApplyPharmElement.div[0]['key']) reManageElement.click() browser.find_element_by_link_text('处方供药').click() time.sleep(2) calendar_element = \ browser.find_element_by_xpath(PdsApplyPharmElement.fieldset[2]['key']).find_elements_by_tag_name('input')[3] js = "document.getElementsByTagName('fieldset')[0].getElementsByTagName('input')[3].removeAttribute('readonly')" browser.execute_script(js) calendar_element.clear() calendar_element.send_keys(time.strftime("%Y-%m-%d", time.localtime())) time.sleep(2) js = "document.getElementsByTagName('fieldset')[0].getElementsByTagName('input')[3].blur()" browser.execute_script(js) browser.find_element_by_xpath( PdsApplyPharmElement.fieldset[2]['key']).find_elements_by_tag_name( 'img')[1].click() browser.find_element_by_xpath("//button[contains(text(),'今天')]").send_keys( Keys.ENTER) cardElement = browser.find_element_by_xpath( PdsApplyPharmElement.input[1]['key']) cardElement.send_keys(cache.get('patient_card') + '\n') browser.implicitly_wait(30) receiveListElement = browser.find_element_by_xpath( PdsApplyPharmElement.div[3]['key']).find_elements_by_tag_name('tr') for i in range(0, len(receiveListElement)): applyElement = receiveListElement[i].find_elements_by_tag_name('div') for j in range(0, len(applyElement)): for appliction in application_list: if applyElement[j].text == appliction: applyElement[j].click() #获取处方药品信息 drug_detail = PdsApplyPharmElement.div[4]['key'] drug_detail_elements = browser.find_element_by_xpath( drug_detail).find_elements_by_tag_name('tr') verifys = [] pds_emr = cache.get('pds_emr') for i in range(0, len(drug_detail_elements)): pham = [] drug_elements = drug_detail_elements[i].find_elements_by_tag_name( 'div') for drug in drug_elements: pham.append(drug.text) verifys.append(pham) #验证药品库存数量 totals = [] #处方供药的药品总量的集合 pham_stocks = [] #药品库存集合 for verify in verifys: for i in range(0, len(pds_emr)): if pds_emr[i][cpoe_out_order['pham_name']] == verify[2]: pham_num = dao.find_pham_num(verify[2], verify[3], execute_list[0]) #药品库存数量 pham_basic_info = dao.find_pham_basic_info( verify[2], verify[3]) #药品基本信息 appy_pham_temp(pham_num, pham_basic_info, pds_emr[i]) #调用供药模板 total = math.ceil(pds_emr[i][cpoe_out_order['dosage']] / pham_basic_info.dose_per_unit * pham_basic_info.package_factor) #药品总量 totals.append(total) pham_stocks.append(pham_num[0]) else: log.info('未找到%s医嘱' % verify[2]) time.sleep(1) recSureElement = browser.find_element_by_xpath( PdsApplyPharmElement.button[2]['key']) recSureElement.click() on_click(browser, (By.XPATH, '//button[contains(text(),"是")]')) browser.implicitly_wait(30) time.sleep(2) listUrl = '处方单' Utility.microsoft_xps_document_writer(listUrl) browser.implicitly_wait(30) log.info('获取药品信息....') time.sleep(4) #验证 pham_stocks_after = [] #供药后,药品库存 for verify in verifys: for i in range(0, len(pds_emr)): if pds_emr[i][cpoe_out_order['pham_name']] == verify[2]: pham_num = dao.find_pham_num(verify[2], verify[3], execute_list[0]) pham_basic_info = dao.find_pham_basic_info( verify[2], verify[3]) appy_pham_temp(pham_num, pham_basic_info, pds_emr[i]) pham_stocks_after.append(pham_num[0]) else: log.info('未找到%s医嘱' % verify[2]) status = True for i in range(0, len(totals)): print(pham_stocks[i] - pham_stocks_after[i] == totals[i]) if not (pham_stocks[i] - pham_stocks_after[i] == totals[i]): status = False log.info('处方供药,药品库存数量验证fial') if status: log.info('处方供药,药品库存数量验证pass') #核对发药 receiveManagerElement = browser.find_element_by_xpath( PdsApplyPharmElement.div[0]['key']) receiveManagerElement.click() # sendMedElement=browser.find_element_by_xpath(PdsApplyPharmElement.a[6]['key']) # sendMedElement.click() browser.find_element_by_link_text('核对发药').click() sendCardElement = browser.find_element_by_xpath( PdsApplyPharmElement.fieldset[0]['key']).find_elements_by_tag_name( 'input')[1] sendCardElement.send_keys(str(cache.get('patient_card')) + '\n') end_time = time.time() + 3 while True: if '暂时没有您需要的数据...' not in get_text( browser, (By.XPATH, PdsApplyPharmElement.div[5]['key'])): break if time.time() > end_time: log.info('核对发药页面加载超时或没有找到发药单') return # browser.find_element_by_xpath(PdsApplyPharmElement.fieldset[0]['key']).find_elements_by_tag_name('button')[0].click() browser.find_element_by_xpath("//button[contains(text(),'发药(O)')]").click() browser.find_element_by_xpath("//button[contains(text(),'是')]").click() log.info('供药脚本运行结束')
def test_invoice_print(browser, cache): log.info('开始运行发票打印脚本') login.select_workstation(browser, '门诊挂号收费工作台', cache) # 工作站是否打开 on_click(browser, (By.XPATH, '//div[contains(text(),"发票打印管理")]')) on_click(browser, (By.LINK_TEXT, '发票打印')) if element_wait(browser, (By.XPATH, '//span[contains(text(),"验证最小票据号窗口")]')): usename = get_text(browser, (By.XPATH, head.用户)).split('(')[0] bill_num = find_min_ticket(usename, '门诊收费发票') send_value(browser, (By.XPATH, verify_bill_window.票据号), bill_num) #输入票据号 on_click(browser, (By.XPATH, verify_bill_window.确定)) send_value(browser, (By.XPATH, query_area.刷卡), cache.get('patient_card') + '\n') lists = ['处方单', '毒麻单', '检查单', '检验单', '治疗单', '皮试单', '输液单', '草药', '病理类'] rek_no_list = [] for list_type in lists: applys = cache.get(list_type) if applys == None: continue for apply_id in list(applys.keys()): result = find_rek_no(apply_id) if result != []: rek_no_list.append(result.Rek.rek_no) else: log.info('%s申请单未收费或已退费' % apply_id) end_time = time.time() + 1 while True: consume_collection = get_text(browser, (By.XPATH, consume_list.消费记录)) if consume_collection != '查询暂无结算消费记录': break if time.time() > end_time: log.info('加载消费单失败') break # print(rek_no_list) if rek_no_list == []: log.info('没有需要打印的单据') return status = False reks = [] for rek_no in rek_no_list: if rek_no in consume_collection: focus(browser, (By.XPATH, '//div[contains(text(),"%s")]' % rek_no)) reks.append(rek_no) status = True else: log.info('%s消费单不存在或已作废' % rek_no) cache.set('rek_no_list', reks) if status: for rek_no in rek_no_list: end_time = time.time() + 1 while True: if rek_no in get_text( browser, (By.XPATH, application_detail_list.费用明细)): break if time.time() > end_time: log.info('加载消费明细失败') break on_click(browser, (By.XPATH, '//button[contains(text(),"打印")]')) on_click(browser, (By.XPATH, '//button[contains(text(),"确 定")]')) on_click(browser, (By.XPATH, '//button[contains(text(),"是")]')) microsoft_xps_document_writer('发票单') else: log.info('验证最小票据号窗口弹出异常') log.info('发票打印脚本运行结束')