From d7c69765c6df0fd63312cb5b7a52b74f2f337272 Mon Sep 17 00:00:00 2001 From: Furen Xiao Date: Thu, 12 Dec 2024 17:01:35 +0800 Subject: [PATCH] add QueryInPatientByWard --- portal_selenium.py | 92 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/portal_selenium.py b/portal_selenium.py index 6047953..ede6a91 100755 --- a/portal_selenium.py +++ b/portal_selenium.py @@ -1410,6 +1410,95 @@ def QueryInPatientByMonth(ID, year, month, SESSION=None): ID, datetime.date(year, month, 1), datetime.date(year, month, number), SESSION ) +def QueryInPatientByWard(ward, SESSION=None): + """ + 病房作業 + 查詢條件輸入 + 病房查詢 + """ + if not SESSION: + SESSION = Login() + + url = ( + "http://ihisaw.ntuh.gov.tw/WebApplication/InPatient/Ward/OpenWard.aspx?SESSION=%s" + % SESSION + ) + driver.get(url) + + elem = driver.find_element(By.CSS_SELECTOR, + "#NTUHWeb1_QueryInPatientPersonAccountControl1_DropListWard" + ) + # print(elem.get_attribute('innerHTML')) + elem.send_keys(ward) + + elem = driver.find_element(By.CSS_SELECTOR, + "#NTUHWeb1_QueryInPatientPersonAccountControl1_QueryAccountNoByWardInput" + ) + elem.click() + + elem = driver.find_element(By.CSS_SELECTOR, + "#NTUHWeb1_QueryInPatientPersonAccountControl1_CheckBoxShowDrMainColumn" + ) + # if elem.get_attribute('checked'): + # elem.click() + # time.sleep(1) + + while elem.get_attribute("checked"): + elem.click() + time.sleep(1) + elem = driver.find_element(By.CSS_SELECTOR, + "#NTUHWeb1_QueryInPatientPersonAccountControl1_CheckBoxShowDrMainColumn" + ) + + # driver.save_screenshot('/tmp/screenshot2.png') + # exit() + # browser.snapshot().save("webpage3.png") + + html = driver.page_source + + # print html + + # browser.close() + + d = pyquery.PyQuery(html) + + PatientList = [] + + for tr in d( + "#NTUHWeb1_QueryInPatientPersonAccountControl1_DataGridAccountList > tbody" + )("tr")[1:]: + d2 = pyquery.PyQuery(tr) + # print d2.text() + # print d2('span') + # return + + Pat = {} + + for s in d2("span") + d2("a"): + if "id" in s.attrib: + key = s.attrib["id"].split("_")[-1] + Pat[key] = s.text + if "title" in s.attrib: + Pat[key + "Title"] = s.attrib["title"] + + Pat["主治"] = d2("span")[7].text + Pat["住院"] = d2("span")[8].text + Pat["科"] = d2("span")[9].text + Pat["入"] = d2("span")[10].text + Pat["住院總天數"] = d2("span")[10].attrib["title"].split(":")[-1].strip() + Pat["出"] = d2("span")[11].text + Pat["狀態"] = d2("span")[12].text + Pat["狀態2"] = d2("span")[13].text + + Pat["id"] = "%s-%s" % (Pat["入"], Pat["PatChartNo"]) + + # print Pat + + PatientList.append(Pat) + + return PatientList + + def QueryDrIDInfoByID(ID, SESSION=None): if not SESSION: @@ -2214,7 +2303,7 @@ def QueryCaseByChartNo(ChartNo, NhiOrderCode='37029B', ApplySDate='2017/01/01', if __name__ == "__main__": # a = Login() - a = OpenClinics('2024-12-10', AMPM='2', ClinicNo=9) + # a = OpenClinics('2024-12-10', AMPM='2', ClinicNo=9) # a = QueryModifyPatBase({'ChartNo': '3009684'}) # a = QueryModifyPatBase({'ChartNo': '8052734'}) # a = ElectronicMedicalReportViewer('3009684', startswith='T0', excluded=['T0_20181011630_T0186538260']) @@ -2223,6 +2312,7 @@ if __name__ == "__main__": # a = ReportPathology('2747688') # a = ReportPathology('6369113') # a = QueryInPatientByMonth('003160', 2017, 10) + a = QueryInPatientByWard('08D') # a = QueryDrIDInfoByID(settings.USER_ID) # a = WardQueryUncompletedChart() # a = WardQueryUncompletedChartCost()