keep partial study
This commit is contained in:
parent
d070c38106
commit
2c2a5d2416
3 changed files with 135 additions and 26 deletions
52
src/list-pituitary.py
Normal file
52
src/list-pituitary.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import pandas as pd
|
||||
|
||||
def hashptid(mrn, hosp='NTUH'):
|
||||
|
||||
ptsalt = (mrn+hosp).upper().encode()
|
||||
hash_in_bytes = hashlib.md5(ptsalt)
|
||||
|
||||
md5 = hash_in_bytes.hexdigest()
|
||||
hash = base64.b32encode(hash_in_bytes.digest())[:8].decode()
|
||||
|
||||
|
||||
# hash32 = base64.b32encode(hash_in_bytes)[:8].decode()
|
||||
# hash10 = str(int(hashlib.md5(ptsalt).hexdigest(), 16))[-8:]
|
||||
|
||||
return md5, hash
|
||||
|
||||
|
||||
|
||||
|
||||
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-op.xlsx')
|
||||
# series = df['PatChartNo'].drop_duplicates().iloc[-1000:].iloc[::-1]
|
||||
# outdir = r'T:\pituitary-op'
|
||||
|
||||
df = pd.read_excel('pituitary-srs.xlsx', sheet_name='NFA Data (n=178)', header=1)
|
||||
series = df[~df['Patient ID'].isna()]['Patient ID'].drop_duplicates()
|
||||
|
||||
for index, row in series.items():
|
||||
if isinstance(row, float):
|
||||
row = int(row)
|
||||
chartno = str(int(row)).zfill(7)
|
||||
md5, hash = hashptid(chartno)
|
||||
|
||||
print(chartno, hash)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
105
src/pacs.py
105
src/pacs.py
|
@ -1,4 +1,6 @@
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
import datetime
|
||||
import glob
|
||||
import logging
|
||||
|
@ -18,7 +20,7 @@ def mouse_click(ws):
|
|||
mouse.move(coords=coords)
|
||||
time.sleep(0.1)
|
||||
mouse.click(coords=coords)
|
||||
time.sleep(0.2)
|
||||
time.sleep(0.1)
|
||||
# mouse.press(coords=coords)
|
||||
# mouse.release(coords=coords)
|
||||
|
||||
|
@ -78,13 +80,20 @@ def dump(pane):
|
|||
print(pane.print_control_identifiers())
|
||||
# print(len(pane.children()))
|
||||
|
||||
# TDicomTagListForm = None
|
||||
|
||||
def save_tag(window, outdir):
|
||||
global TDicomTagListForm
|
||||
mouse_click(window['註釋/標籤'])
|
||||
TToolBar = window.child_window(class_name='TToolBar', found_index=2)
|
||||
|
||||
TDicomTagListForm = window['DICOM 標籤清單Dialog']
|
||||
if TDicomTagListForm.exists():
|
||||
TDicomTagListForm.close()
|
||||
TDicomTagListForm.wait_not('exists', 20)
|
||||
|
||||
TToolBar = window.child_window(class_name='TToolBar', found_index=2)
|
||||
Button5 = TToolBar.Button5
|
||||
Button5.wait('ready', 9)
|
||||
Button5.wait('ready', 10)
|
||||
# time.sleep(2)
|
||||
mouse_click(Button5)
|
||||
|
||||
|
@ -93,6 +102,7 @@ def save_tag(window, outdir):
|
|||
export = export_to_file.wrapper_object()
|
||||
export.click()
|
||||
|
||||
|
||||
TDicomTagListForm = window['DICOM 標籤清單Dialog']
|
||||
|
||||
dlg_save = Desktop(backend="uia").window(title='另存新檔')
|
||||
|
@ -106,7 +116,9 @@ def save_tag(window, outdir):
|
|||
dlg_save['存檔(S)Button'].wrapper_object().click()
|
||||
|
||||
TDicomTagListForm.close()
|
||||
TDicomTagListForm.wait_not('exists', 9)
|
||||
# logging.warning("TDicomTagListForm closing")
|
||||
# TDicomTagListForm.wait_not('exists', 60)
|
||||
# logging.warning("TDicomTagListForm not exists")
|
||||
|
||||
return pahtname
|
||||
|
||||
|
@ -123,7 +135,10 @@ def save_study(chartno, outdir, only_tag):
|
|||
# time.sleep(1)
|
||||
|
||||
logging.warning('connecting '+chartno)
|
||||
app = Application(backend="uia").connect(title_re='^%s.*'%chartno, timeout=200)
|
||||
app = Application(backend="uia").connect(title_re='.*%s.*'%chartno, timeout=200)
|
||||
|
||||
shutil.rmtree(outdir, ignore_errors=True)
|
||||
os.makedirs(outdir, exist_ok=True)
|
||||
|
||||
logging.warning(str(app))
|
||||
window = app.top_window()
|
||||
|
@ -152,16 +167,17 @@ def save_study(chartno, outdir, only_tag):
|
|||
for c in series:
|
||||
|
||||
logging.warning(str(c.element_info))
|
||||
# c.wait('ready') #AttributeError: 'UIAWrapper' object has no attribute 'wait'
|
||||
c.set_focus()
|
||||
|
||||
mouse_click(c)
|
||||
keyboard.send_keys('^{HOME}')
|
||||
time.sleep(1)
|
||||
time.sleep(.1)
|
||||
p = save_tag(window, outdir)
|
||||
|
||||
mouse_click(c)
|
||||
keyboard.send_keys('^{END}')
|
||||
time.sleep(1)
|
||||
time.sleep(.1)
|
||||
p = save_tag(window, outdir)
|
||||
|
||||
# mouse_click(c)
|
||||
|
@ -180,6 +196,7 @@ def save_study(chartno, outdir, only_tag):
|
|||
# logging.warning(str(datetime.datetime.now()))
|
||||
TFormSaveBitmap = window['選項']
|
||||
# TFormSaveBitmap.dump_tree(filename='z-%s-TFormSaveBitmap.txt'%chartno)
|
||||
TFormSaveBitmap.wait('ready')
|
||||
|
||||
Edit5 = TFormSaveBitmap.Edit5
|
||||
Edit5.wait('ready')
|
||||
|
@ -189,7 +206,7 @@ def save_study(chartno, outdir, only_tag):
|
|||
TFormSaveBitmap.Button2.click()
|
||||
|
||||
logging.warning('button clicked')
|
||||
time.sleep(1)
|
||||
time.sleep(.1)
|
||||
logging.warning('saving started')
|
||||
saving = window.child_window(title_re='^另存新檔.*')
|
||||
logging.warning('saving exists')
|
||||
|
@ -199,6 +216,7 @@ def save_study(chartno, outdir, only_tag):
|
|||
c.set_focus()
|
||||
mouse_click(c)
|
||||
keyboard.send_keys('^q')
|
||||
# window.wait_not('exists', 9)
|
||||
|
||||
# while True:
|
||||
# try:
|
||||
|
@ -242,25 +260,68 @@ def save_patient(chartno, outdir, query = "CT,MR", only_tag=False):
|
|||
|
||||
ListView = ListItem.parent()
|
||||
|
||||
shutil.rmtree(outdir, ignore_errors=True)
|
||||
os.makedirs(outdir, exist_ok=True)
|
||||
# shutil.rmtree(outdir, ignore_errors=True)
|
||||
# os.makedirs(outdir, exist_ok=True)
|
||||
|
||||
items =[]
|
||||
|
||||
rows = []
|
||||
row = None
|
||||
|
||||
LeftUpper = ListView.items()[0]
|
||||
mouse_click(LeftUpper)
|
||||
|
||||
for item in ListView.items():
|
||||
if item.texts()[0] != '開啟影像':
|
||||
continue
|
||||
items.append(item)
|
||||
logging.debug(str(item.rectangle()))
|
||||
# logging.warning(str(item))
|
||||
# logging.warning(str(dir(item)))
|
||||
# logging.warning(str(item.texts()))
|
||||
|
||||
if item.texts()[0] == '開啟影像':
|
||||
if row:
|
||||
rows.append(row)
|
||||
# logging.warning(str(row))
|
||||
items.append(item)
|
||||
row = []
|
||||
|
||||
if row is not None:
|
||||
row.append(item.texts()[0])
|
||||
|
||||
# if item.texts()[0] != '開啟影像':
|
||||
# continue
|
||||
# items.append(item)
|
||||
# logging.debug(str(item.rectangle()))
|
||||
|
||||
rows.append(row)
|
||||
# logging.warning(str(row))
|
||||
|
||||
# logging.warning(str(len(items)))
|
||||
# logging.warning(str(items))
|
||||
|
||||
# exit()
|
||||
|
||||
for i, item in enumerate(items):
|
||||
# if i < 7:
|
||||
# continue
|
||||
|
||||
series_name = '%s_%s_%s' % (rows[i][5], rows[i][9], rows[i][10])
|
||||
series_name = series_name.replace('/', '').replace(' ', '')
|
||||
complete_file = Path(f'{outdir}\\{series_name}.complete')
|
||||
|
||||
if complete_file.is_file():
|
||||
logging.warning('skip '+str(complete_file))
|
||||
else:
|
||||
|
||||
subdir = Path(f'{outdir}\\{series_name}')
|
||||
|
||||
time.sleep(.1)
|
||||
logging.warning(str(item.get_properties()))
|
||||
mouse_click(item)
|
||||
|
||||
save_study(chartno, subdir, only_tag)
|
||||
complete_file.touch()
|
||||
|
||||
bottom = False
|
||||
logging.warning(str(items[i].rectangle()))
|
||||
|
||||
try:
|
||||
if items[i+1].rectangle().top < 1:
|
||||
if items[i+2].rectangle().top < 1:
|
||||
bottom = True
|
||||
except:
|
||||
bottom = True
|
||||
|
@ -275,14 +336,8 @@ def save_patient(chartno, outdir, query = "CT,MR", only_tag=False):
|
|||
# coords = (r.left + r.right)//2, (r.top + r.bottom)//2
|
||||
# mouse.scroll(coords=coords)
|
||||
|
||||
time.sleep(2)
|
||||
time.sleep(.1)
|
||||
|
||||
# item.wait('ready') # no attribute wait
|
||||
time.sleep(1)
|
||||
logging.warning(str(item.get_properties()))
|
||||
mouse_click(item)
|
||||
|
||||
save_study(chartno, outdir, only_tag)
|
||||
logging.warning(chartno+" completed "+query)
|
||||
return 0
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ def get_pacs(series, outdir, max_patients=100):
|
|||
continue
|
||||
|
||||
logging.warning('saving '+chartno)
|
||||
pacs.save_patient(chartno, f'{outdir}\\{chartno}', query="CT,MR", only_tag=True)
|
||||
pacs.save_patient(chartno, f'{outdir}\\{chartno}', query="CT,MR",
|
||||
# only_tag=True
|
||||
)
|
||||
|
||||
complete_file.touch()
|
||||
num_patients += 1
|
||||
|
|
Loading…
Reference in a new issue