diff --git a/src/icu-ventricle.py b/src/icu-ventricle.py new file mode 100644 index 0000000..c8bcb58 --- /dev/null +++ b/src/icu-ventricle.py @@ -0,0 +1,64 @@ + +from pathlib import Path + +import datetime +import logging + +import pandas as pd + +import pacs + +def get_pacs(series, outdir, max_patients=10): + app, window = pacs.login() + num_patients = 0 + for index, row in series.iterrows(): + chartno = str(row.CHARTNO).zfill(7) + # chartno = str(int(row.CHARTNO)).zfill(7) + # print(chartno) + # continue + # exit() + + # if isinstance(row, float): + # row = int(row) + # chartno = str(int(row)).zfill(7) + + complete_file = Path(f'{outdir}\\{chartno}.complete') + if complete_file.is_file(): + logging.warning('skip '+chartno) + continue + + logging.warning('saving '+chartno) + pacs.save_patient(chartno, f'{outdir}\\{chartno}', query="CT,MR") + + complete_file.touch() + num_patients += 1 + if num_patients >= max_patients: + break + + logging.warning('%d patients completed' % num_patients) + return num_patients + + +def main(): + FORMAT = '%(asctime)s %(message)s' + logging.basicConfig(filename=__file__.replace('.py','.%s.log'%str(datetime.datetime.now()).replace(':','')), + format=FORMAT) + + + + # df = pd.read_excel('pituitary-srs.xlsx', sheet_name='NFA Data (n=178)', header=1) + df = pd.read_csv('C1053_01_CHARTNO_1.txt', sep="\t", header=0) + # print(df) + # exit() + series=df.reindex(index=df.index[::-1]) + # print(series) + # exit() + + outdir = r'T:\icu_ventricle' + + get_pacs(series, outdir) + return 0 + + +if __name__ == '__main__': + main() diff --git a/src/pacs.py b/src/pacs.py index e29107d..ae210be 100644 --- a/src/pacs.py +++ b/src/pacs.py @@ -15,7 +15,11 @@ from settings import * def mouse_click(ws): r = ws.rectangle() coords = (r.left + r.right)//2, (r.top + r.bottom)//2 + mouse.move(coords=coords) + time.sleep(1) mouse.click(coords=coords) + # mouse.press(coords=coords) + # mouse.release(coords=coords) def login(id=USER_ID, pw=PASSWORD): # Timings.fast() @@ -78,13 +82,16 @@ def dump(pane): def save_study(chartno, outdir): - while True: - logging.warning('connecting '+chartno) - try: - app = Application(backend="uia").connect(title_re='^%s.*'%chartno) - break - except: - time.sleep(1) + # while True: + # logging.warning('connecting '+chartno) + # try: + # app = Application(backend="uia").connect(title_re='^%s.*'%chartno) + # break + # except: + # time.sleep(1) + + logging.warning('connecting '+chartno) + app = Application(backend="uia").connect(title_re='^%s.*'%chartno, timeout=200) logging.warning(str(app)) window = app.top_window() @@ -112,10 +119,14 @@ def save_study(chartno, outdir): mouse_click(window['註釋/標籤']) TToolBar = window.child_window(class_name='TToolBar', found_index=2) - mouse_click(TToolBar.Button5) - time.sleep(1) + + Button5 = TToolBar.Button5 + Button5.wait('ready', 9) + time.sleep(2) + mouse_click(Button5) + export_to_file = window['輸出至檔案'] - export_to_file.wait('ready') + export_to_file.wait('ready', 99) export = export_to_file.wrapper_object() export.click() @@ -123,7 +134,7 @@ def save_study(chartno, outdir): dlg_save = Desktop(backend="uia").window(title='另存新檔') NEdit = dlg_save['檔案名稱(N):Edit'] - NEdit.wait('ready') + NEdit.wait('ready', 99) edit = NEdit.wrapper_object() pahtname = os.path.join(outdir, edit.get_value()) for p in glob.glob(pahtname + '*'): @@ -144,7 +155,12 @@ def save_study(chartno, outdir): # logging.warning(str(datetime.datetime.now())) TFormSaveBitmap = window['選項'] # TFormSaveBitmap.dump_tree(filename='z-%s-TFormSaveBitmap.txt'%chartno) - TFormSaveBitmap.Edit5.set_text(outdir) + + Edit5 = TFormSaveBitmap.Edit5 + Edit5.wait('ready') + Edit5.set_text(outdir) + + # TFormSaveBitmap.Edit5.set_text(outdir) TFormSaveBitmap.Button2.click() logging.warning('button clicked') @@ -216,7 +232,7 @@ def save_patient(chartno, outdir, query = "CT,MR"): # if i < 7: # continue bottom = False - logging.debug(str(items[i].rectangle())) + logging.warning(str(items[i].rectangle())) try: if items[i+1].rectangle().top < 1: @@ -225,16 +241,20 @@ def save_patient(chartno, outdir, query = "CT,MR"): bottom = True if bottom: + logging.warning(str(item.get_properties())) item.set_focus() keyboard.send_keys('{DOWN}') + logging.warning('{DOWN}') # r = item.rectangle() # coords = (r.left + r.right)//2, (r.top + r.bottom)//2 # mouse.scroll(coords=coords) - time.sleep(1) - logging.debug(str(item.rectangle())) + time.sleep(2) + # item.wait('ready') # no attribute wait + time.sleep(1) + logging.warning(str(item.get_properties())) mouse_click(item) save_study(chartno, outdir) diff --git a/src/pituitary.py b/src/pituitary.py index 62b96be..7b44552 100644 --- a/src/pituitary.py +++ b/src/pituitary.py @@ -29,6 +29,7 @@ def get_pacs(series, outdir, max_patients=10): if num_patients >= max_patients: break + logging.warning('%d patients completed' % num_patients) return num_patients