still fixing timeout, but works most of the time
This commit is contained in:
parent
b55a361374
commit
b33be224cb
3 changed files with 100 additions and 15 deletions
64
src/icu-ventricle.py
Normal file
64
src/icu-ventricle.py
Normal file
|
@ -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()
|
50
src/pacs.py
50
src/pacs.py
|
@ -15,7 +15,11 @@ from settings import *
|
||||||
def mouse_click(ws):
|
def mouse_click(ws):
|
||||||
r = ws.rectangle()
|
r = ws.rectangle()
|
||||||
coords = (r.left + r.right)//2, (r.top + r.bottom)//2
|
coords = (r.left + r.right)//2, (r.top + r.bottom)//2
|
||||||
|
mouse.move(coords=coords)
|
||||||
|
time.sleep(1)
|
||||||
mouse.click(coords=coords)
|
mouse.click(coords=coords)
|
||||||
|
# mouse.press(coords=coords)
|
||||||
|
# mouse.release(coords=coords)
|
||||||
|
|
||||||
def login(id=USER_ID, pw=PASSWORD):
|
def login(id=USER_ID, pw=PASSWORD):
|
||||||
# Timings.fast()
|
# Timings.fast()
|
||||||
|
@ -78,13 +82,16 @@ def dump(pane):
|
||||||
|
|
||||||
def save_study(chartno, outdir):
|
def save_study(chartno, outdir):
|
||||||
|
|
||||||
while True:
|
# while True:
|
||||||
logging.warning('connecting '+chartno)
|
# logging.warning('connecting '+chartno)
|
||||||
try:
|
# try:
|
||||||
app = Application(backend="uia").connect(title_re='^%s.*'%chartno)
|
# app = Application(backend="uia").connect(title_re='^%s.*'%chartno)
|
||||||
break
|
# break
|
||||||
except:
|
# except:
|
||||||
time.sleep(1)
|
# time.sleep(1)
|
||||||
|
|
||||||
|
logging.warning('connecting '+chartno)
|
||||||
|
app = Application(backend="uia").connect(title_re='^%s.*'%chartno, timeout=200)
|
||||||
|
|
||||||
logging.warning(str(app))
|
logging.warning(str(app))
|
||||||
window = app.top_window()
|
window = app.top_window()
|
||||||
|
@ -112,10 +119,14 @@ def save_study(chartno, outdir):
|
||||||
|
|
||||||
mouse_click(window['註釋/標籤'])
|
mouse_click(window['註釋/標籤'])
|
||||||
TToolBar = window.child_window(class_name='TToolBar', found_index=2)
|
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 = window['輸出至檔案']
|
||||||
export_to_file.wait('ready')
|
export_to_file.wait('ready', 99)
|
||||||
export = export_to_file.wrapper_object()
|
export = export_to_file.wrapper_object()
|
||||||
export.click()
|
export.click()
|
||||||
|
|
||||||
|
@ -123,7 +134,7 @@ def save_study(chartno, outdir):
|
||||||
|
|
||||||
dlg_save = Desktop(backend="uia").window(title='另存新檔')
|
dlg_save = Desktop(backend="uia").window(title='另存新檔')
|
||||||
NEdit = dlg_save['檔案名稱(N):Edit']
|
NEdit = dlg_save['檔案名稱(N):Edit']
|
||||||
NEdit.wait('ready')
|
NEdit.wait('ready', 99)
|
||||||
edit = NEdit.wrapper_object()
|
edit = NEdit.wrapper_object()
|
||||||
pahtname = os.path.join(outdir, edit.get_value())
|
pahtname = os.path.join(outdir, edit.get_value())
|
||||||
for p in glob.glob(pahtname + '*'):
|
for p in glob.glob(pahtname + '*'):
|
||||||
|
@ -144,7 +155,12 @@ def save_study(chartno, outdir):
|
||||||
# logging.warning(str(datetime.datetime.now()))
|
# logging.warning(str(datetime.datetime.now()))
|
||||||
TFormSaveBitmap = window['選項']
|
TFormSaveBitmap = window['選項']
|
||||||
# TFormSaveBitmap.dump_tree(filename='z-%s-TFormSaveBitmap.txt'%chartno)
|
# 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()
|
TFormSaveBitmap.Button2.click()
|
||||||
|
|
||||||
logging.warning('button clicked')
|
logging.warning('button clicked')
|
||||||
|
@ -216,7 +232,7 @@ def save_patient(chartno, outdir, query = "CT,MR"):
|
||||||
# if i < 7:
|
# if i < 7:
|
||||||
# continue
|
# continue
|
||||||
bottom = False
|
bottom = False
|
||||||
logging.debug(str(items[i].rectangle()))
|
logging.warning(str(items[i].rectangle()))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if items[i+1].rectangle().top < 1:
|
if items[i+1].rectangle().top < 1:
|
||||||
|
@ -225,16 +241,20 @@ def save_patient(chartno, outdir, query = "CT,MR"):
|
||||||
bottom = True
|
bottom = True
|
||||||
|
|
||||||
if bottom:
|
if bottom:
|
||||||
|
logging.warning(str(item.get_properties()))
|
||||||
item.set_focus()
|
item.set_focus()
|
||||||
keyboard.send_keys('{DOWN}')
|
keyboard.send_keys('{DOWN}')
|
||||||
|
logging.warning('{DOWN}')
|
||||||
|
|
||||||
# r = item.rectangle()
|
# r = item.rectangle()
|
||||||
# coords = (r.left + r.right)//2, (r.top + r.bottom)//2
|
# coords = (r.left + r.right)//2, (r.top + r.bottom)//2
|
||||||
# mouse.scroll(coords=coords)
|
# mouse.scroll(coords=coords)
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(2)
|
||||||
logging.debug(str(item.rectangle()))
|
|
||||||
|
|
||||||
|
# item.wait('ready') # no attribute wait
|
||||||
|
time.sleep(1)
|
||||||
|
logging.warning(str(item.get_properties()))
|
||||||
mouse_click(item)
|
mouse_click(item)
|
||||||
|
|
||||||
save_study(chartno, outdir)
|
save_study(chartno, outdir)
|
||||||
|
|
|
@ -29,6 +29,7 @@ def get_pacs(series, outdir, max_patients=10):
|
||||||
if num_patients >= max_patients:
|
if num_patients >= max_patients:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
logging.warning('%d patients completed' % num_patients)
|
||||||
return num_patients
|
return num_patients
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue