deid.config package

Submodules

deid.config.standards module

deid.config.utils module

deid.config.utils.add_section(config, section, section_name=None)[source]

add section will add a section (and optionally) section name to a config

Parameters:
  • config (the config (dict) parsed thus far) –
  • section (the section name to add) –
  • section_name (an optional name, added as a level) –
deid.config.utils.find_deid(path=None)[source]

find_deid is a helper function to load_deid to find a deid file.

It can be in a folder, or return the path provided if it is the file.

Parameters:path (a path on the filesystem. If not provided, will assume PWD.) –
deid.config.utils.get_deid(tag=None, exit_on_fail=True, quiet=False, load=False)[source]

get deid is intended to retrieve the full path of a deid file provided with the software, based on a tag. For example, under deid/data if a file is called “deid.dicom”, the tag would be “dicom”.

Parameters:
  • tag (the text that comes after deid to indicate the tag of the file in deid/data) –
  • exit_on_fail (if None is an acceptable return value, this should be set to False) – (default is True).
  • quiet (Default False. If None is acceptable, quiet can be set to True) –
  • load (also load the deid, if resulting path (from path or tag) is not None) –
deid.config.utils.load_combined_deid(deids)[source]

load one or more deids, either based on a path or a tag

Parameters:deids (should be a custom list of deids) –
deid.config.utils.load_deid(path=None)[source]

Load_deid will return a loaded in (user) deid configuration file.

This can be used to update a default config.json. If a file path is specified, it is loaded directly. If a folder is specified, we look for a deid file in the folder. If nothing is specified, we assume the user wants to load a deid file in the present working directory. If the user wants to have multiple deid files in a directory, this can be done with an extension that specifies the module, eg;

deid.dicom deid.nifti
Parameters:path (a path to a deid file) –
Returns:config
Return type:a parsed deid (dictionary) with valid sections
deid.config.utils.parse_config_action(section, line, config, section_name=None)[source]

add action will take a line from a deid config file, a config (dictionary), and an active section name (eg header) and add an entry to the config file to perform the action.

Parameters:
  • section (a valid section name from the deid config file) –
  • line (the line content to parse for the section/action) –
  • config (the growing/current config dictionary) –
  • section_name (optionally, a section name) –
deid.config.utils.parse_filter_group(spec)[source]

given the specification (a list of lines) continue parsing lines until the filter group ends, as indicated by the start of a new LABEL, (case 1), the start of a new section (case 2) or the end of the spec file (case 3). Returns a list of members (lines) that belong to the filter group. The list (by way of using pop) is updated in the calling function.

Parameters:spec (unparsed lines of the deid recipe file) –
deid.config.utils.parse_format(line)[source]

given a line that starts with FORMAT, parse the file.

This means checking the format of the file and checking that it is supported. If not, exit on error. If yes, return the format.

Parameters:line (the line that starts with format.) –
deid.config.utils.parse_group_action(section, line, config, section_name)[source]

parse a group action, either FIELD or SPLIT, which must belong to either a fields or values section.

Parameters:
  • section (a valid section name from the deid config file) –
  • line (the line content to parse for the section/action) –
  • config (the growing/current config dictionary) –
  • section_name (optionally, a section name) –
deid.config.utils.parse_label(section, config, section_name, members, label=None)[source]

Add a named label to the filter section, including one or more criteria

Parameters:
  • section (the section name (e.g., header) must be one in sections) –
  • config (the config (dictionary) parsed thus far) –
  • section_name (an optional name for a section) –
  • members (the lines belonging to the section/section_name) –
  • label (an optional name for the group of commands) –
deid.config.utils.parse_member(members, operator=None)[source]

a parsing function for a filter member. Will return a single member with fields, values, and an operator. In the case of multiple and/or statements that are chained, will instead return a list.

Module contents

class deid.config.DeidRecipe(deid=None, base=False, default_base='dicom')[source]

Bases: object

Create a deid recipe to filter and perform operations on a dicom header.

Usage typically looks like:

deid = ‘dicom.deid’ recipe = DeidRecipe(deid)

If deid is None, the default provided by the application is used.

Parameters:
  • deid (the deid recipe (or recipes) files to use. If more than one) – is provided, should be done in order of preference for load (later in the list overrides earlier loaded).
  • base (if True, load a default base (default_base) before custom) –
  • default_base (the default base to load if "base" is True) –
get_actions(action=None, field=None)[source]

Get deid actions to perform on a header, or a subset based on a type

A header action is a list with the following: {‘action’: ‘REMOVE’, ‘field’: ‘AssignedLocation’},

Parameters:
  • action (if not None, filter to action specified) –
  • field (if not None, filter to field specified) –
get_fields_lists(name=None)[source]

Return a values list by name

get_filters(name=None)[source]

Return all filters for a deid recipe, or a set based on a name

get_format()[source]

Return the format of the loaded deid, if one exists

get_values_lists(name=None)[source]

Return a values list by name

has_actions()[source]
has_fields_lists()[source]
has_values_lists()[source]
listof(section)[source]

Return a list of keys for a section

load(deid)[source]

Load a deid recipe into the object.

If a deid configuration is already defined, append to that.

ls_fieldlists()[source]
ls_filters()[source]
ls_valuelists()[source]