Snippets

osimis List all key values from all worklists files in a folder

Created by Alain Mazy last modified
import argparse
import dicom # = pydicom
import glob
import os

# useage:
# python3 dumpWorklists.py --folder=/var/lib/orthanc/db/worklists/

if __name__ == "__main__":

    try:
        parser = argparse.ArgumentParser("Dumps info from a set of worklists contained in a folder (i.e a folder that the Orthanc modality worklist plugin is serving)")
        parser.add_argument('-f', '--folder', help = "the folder containing the worklidsts (.wl) files.url of the orthanc to monitor")
        args = parser.parse_args()

        fileFilter = os.path.join("{folder}".format(folder = args.folder), "*.wl")
        for wlFile in glob.glob(fileFilter):
            try:
                wl = dicom.read_file(wlFile)
                values = [wl.PatientID, str(wl.PatientName), wl.AccessionNumber, wl.ScheduledProcedureStepSequence[0].ScheduledProcedureStepStartDate, wl.ScheduledProcedureStepSequence[0].Modality, wlFile]
                print(", ".join(values))
            except Exception as ex:
                print(wlFile + ": " + str(ex))

    except Exception as ex:
        print("Unhandled exception: " + str(ex))

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.