56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
|
|
from pathlib import Path
|
|
|
|
import datetime
|
|
import logging
|
|
|
|
import pandas as pd
|
|
|
|
import pacs
|
|
|
|
def get_pacs(series, outdir, max_patients=100):
|
|
app, window = pacs.login()
|
|
num_patients = 0
|
|
for index, row in series.items():
|
|
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",
|
|
# only_tag=True
|
|
)
|
|
|
|
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-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()
|
|
outdir = r'T:\pituitary-srs'
|
|
|
|
get_pacs(series, outdir)
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|