Skip to content

Commit

Permalink
add writing of extra text files for PACS import
Browse files Browse the repository at this point in the history
  • Loading branch information
gschramm committed Apr 25, 2019
1 parent 26c2c80 commit d050c64
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions examples/fileio/convert_kul_ct_recon_to_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
parser.add_argument('--kul_var_name', help = 'name of recon variable in sav file', default = 'recon')
parser.add_argument('--series_desc_prefix', help = 'prefix for dcm series description',
default = '(KUL motion corrected)')
parser.add_argument('--importer_computer', help = 'PACS import computer', default = None)
parser.add_argument('--importer_login', help = 'PACS import login', default = None)

args = parser.parse_args()
output_dir = args.output_dir
Expand Down Expand Up @@ -54,8 +56,35 @@
# write the dicoms
# the number of tags to be copied from the original recon can be extented
new_series_desc = args.series_desc_prefix + ' ' + ref_dcm.firstdcmheader.SeriesDescription
pymf.write_3d_static_dicom(kul_recon, output_dir,
affine = ref_dcm.affine,
SeriesDescription = new_series_desc,
modality = ref_dcm.firstdcmheader.Modality,
**dcm_header_kwargs)
dcm_out_fnames = pymf.write_3d_static_dicom(kul_recon, output_dir,
affine = ref_dcm.affine,
SeriesDescription = new_series_desc,
modality = ref_dcm.firstdcmheader.Modality,
**dcm_header_kwargs)

# for PACS import we have to write two additional text files
if (args.importer_computer is not None) and (args.importer_login is not None):
dcm_props = {}
dcm_props['import.type'] = 'cd'
dcm_props['study.size'] = kul_recon.shape[2]
dcm_props['version'] = 2
dcm_props['study.uid'] = ref_dcm.firstdcmheader.StudyInstanceUID
dcm_props['institution'] = 'KUL'
dcm_props['importer.computer'] = args.importer_computer
dcm_props['study.date'] = ref_dcm.firstdcmheader.StudyDate[:8]
dcm_props['importer.login'] = args.importer_login
dcm_props['patient.ead'] = ref_dcm.firstdcmheader.PatientID
dcm_props['file.list'] = 'filelist.txt'
dcm_props['werkomgeving'] = 'UZL'
dcm_props['study.time'] = ref_dcm.firstdcmheader.StudyTime[:6]
dcm_props['modality'] = ref_dcm.firstdcmheader.Modality
dcm_props['study.description'] = ref_dcm.firstdcmheader.StudyDescription

with open(os.path.join(output_dir, 'dicomimport.properties'), 'w') as f:
for key, value in dcm_props.items():
f.write(key + '=' + str(value) + '\n')

with open(os.path.join(output_dir, 'filelist.txt'), 'w') as f:
for fname in dcm_out_fnames:
f.write(os.path.basename(fname) + '\n')
f.write('COMPLETED')

0 comments on commit d050c64

Please sign in to comment.