How to use the deid.dicom.get_identifiers function in deid

To help you get started, we’ve selected a few deid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / deid / deid / main.py View on Github external
elif args.action == "get":
        do_get = True
        bot.info("GET and PUT identifiers from %s" %(basename))
    
    elif args.action == "put":
        bot.info("PUT identifiers from %s" %(basename))
        do_put = True
        if args.ids is None:
            bot.error("To PUT without GET you must provide a json file with ids.")
            sys.exit(1)
        ids = args.ids

    # GET identifiers
    if do_get is True:
        from deid.dicom import get_identifiers
        ids = get_identifiers(dicom_files)
        if args.do_print is True:
            print(ids)
        else:
            from deid.identifiers import save_identifiers
            save_identifiers(ids,output_folder)

    if do_put is True:           
       from deid.dicom import replace_identifiers
       cleaned_files = replace_identifiers(dicom_files=dicom_files,
                                           ids=ids,
                                           deid=args.deid,
                                           overwrite=args.overwrite,
                                           output_folder=output_folder)
       bot.info("%s %s files at %s" %(len(cleaned_files),
                                      args.format,
                                      output_folder))
github pydicom / deid / examples / dicom / header-manipulation / func-replacement.py View on Github external
from deid.utils import get_installdir
from deid.data import get_dataset
import os

# This is an example of replacing fields in dicom headers,
# but via a function instead of a preset identifier.

# This will get a set of example cookie dicoms
base = get_dataset("dicom-cookies")
dicom_files = list(get_files(base))  # todo : consider using generator functionality


# This is the function to get identifiers
from deid.dicom import get_identifiers

items = get_identifiers(dicom_files)

# **
# The function performs an action to generate a uid, but you can also use
# it to communicate with databases, APIs, or do something like
# save the original (and newly generated one) in some (IRB approvied) place
# **

################################################################################
# The Deid Recipe
#
# The process of updating header values means writing a series of actions
# in the deid recipe, in this folder the file "deid.dicom" that has the
# following content:
#
# FORMAT dicom
github pydicom / deid / examples / dicom / recipe / deid-dicom-example.py View on Github external
from deid.data import get_dataset
import os

# This is a complete example of doing de-identifiction. For details, see our docs
# https://pydicom.github.io/deid


# This will get a set of example cookie dicoms
base = get_dataset("dicom-cookies")
dicom_files = list(get_files(base))  # todo : consider using generator functionality


# This is the function to get identifiers
from deid.dicom import get_identifiers

ids = get_identifiers(dicom_files)

# **
# Here you might save them in your special (IRB approvied) places
# And then provide replacement anonymous ids to put back in the data
# A cookie tumor example is below
# **

################################################################################
# The Deid Recipe
#
# The process of flagging images comes down to writing a set of filters to
# check if each image meets some criteria of interest. For example, I might
# create a filter called "xray" that is triggered when the Modality is CT or XR.
# We specify these fliters in a simple text file called a "deid recipe." When
# you work with the functions, you have the choice to instantiate the object
# in advance, or just provide a path to a recipe file. We will walk through
github pydicom / deid / examples / dicom / header-manipulation / func-sequence-replace / example.py View on Github external
#!/usr/bin/env python
from deid.dicom import get_identifiers, replace_identifiers
from deid.config import DeidRecipe

# This is supported for deid.dicom version 0.1.34

# This dicom has nested InstanceCreationDate fields

dicom_files = ["MR.dcm"]

# They are extracted, and flattened in items
# 'ReferencedPerformedProcedureStepSequence__InstanceCreationDate': '20091124',

items = get_identifiers(dicom_files)

# Load in the recipe, we want to REPLACE InstanceCreationDate with a function

recipe = DeidRecipe("deid.dicom")

# Here is our function


def generate_date(item, value, field, dicom):
    """This function will generate a dicom uid! You can expect it to be passed
       the dictionary of items extracted from the dicom (and your function)
       and variables, the original value (func:generate_uid) and the field
       object you are applying it to.
    """
    return "20200608"