### Installing deid-data Dependency (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md Installs the `deid-data` package, which provides test datasets necessary for running the examples. This is a prerequisite step. ```bash pip install deid-data ``` -------------------------------- ### Install from Setup Script Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/local.md Installs the package using the `setup.py` script located in the source directory. This method is commonly used when installing from source code after cloning the repository. ```bash python setup.py install ``` -------------------------------- ### Example Config.json with Get/Put Configurations Source: https://github.com/pydicom/deid/blob/master/docs/_docs/development/image-format.md Provides an example `config.json` demonstrating typical configurations for the 'get' and 'put' sections. It shows how to specify fields to skip during extraction ('get') and how to define actions like adding a field ('put'). ```json { "get": { "skip": ["PixelData"], "ids":{ "entity":"PatientID", "item":"SOPInstanceUID" } }, "put":{ "actions":[ {"action":"ADD","field":"PatientIdentityRemoved","value": "Yes"} ] } } ``` -------------------------------- ### Serve Jekyll Development Server Source: https://github.com/pydicom/deid/blob/master/docs/README.md Starts a local development server for the Jekyll site, allowing previewing changes in a web browser. The `bundle exec` command ensures the command runs within the context of the bundle's gems. ```Shell bundle exec jekyll serve ``` -------------------------------- ### Installing Deid Data Dependency - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Installs the `deid-data` package using pip, which provides necessary data files for running deid examples. This is a prerequisite for the subsequent examples. ```bash $ pip install deid-data ``` -------------------------------- ### Installing deid-data Dependency (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-loading.md Installs the required 'deid-data' package using pip, which provides example datasets necessary for running the code examples. ```bash pip install deid-data ``` -------------------------------- ### Install deid-data package (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-get.md This command installs the "deid-data" Python package using pip. This package provides necessary data files required to run the deid examples and functionality described in this documentation. It is a required step before proceeding with other examples. ```bash $ pip install deid-data ``` -------------------------------- ### Install Jekyll Dependencies (Bundle) Source: https://github.com/pydicom/deid/blob/master/docs/README.md Installs the necessary Ruby gem dependencies for the Jekyll site, as specified in the Gemfile, using Bundler. ```Shell bundle install ``` -------------------------------- ### Install Local Jekyll Dependencies - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/contributing/docs.md Installs Ruby using Homebrew, then installs the Jekyll and Bundler gems using `gem install`. Finally, `bundle install` installs any remaining dependencies specified in the project's Gemfile. This sets up the environment to run the documentation site locally. ```bash brew install ruby gem install jekyll gem install bundler bundle install ``` -------------------------------- ### Install deid-data Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Command to install the external deid-data package, which provides example DICOM datasets needed to run the Python examples. ```bash $ pip install deid-data ``` -------------------------------- ### Install Homebrew and Git (OS X) - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/contributing/docs.md Installs the Homebrew package manager and Git on macOS using a curl command for Homebrew and then `brew install` for Git. This is a prerequisite for contributing. ```bash /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install git ``` -------------------------------- ### Load example DICOM files Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Uses `get_dataset` to locate the 'dicom-cookies' example data directory and `get_files` to get a list of all DICOM file paths within that dataset. ```python base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) ``` -------------------------------- ### Install Git (Debian/Ubuntu) - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/contributing/docs.md Updates the package list and installs Git on Debian or Ubuntu systems using `apt-get`. This provides an alternative way to install Git compared to the macOS method. ```bash apt-get update && apt-get install -y git ``` -------------------------------- ### Installing Dependencies for Deidentification Example (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/deid-dataset.md Provides bash commands to set up a conda environment, activate it, navigate to the project directory, and install the required Python packages from `requirements.txt`. ```Bash conda create -n deid_example python=3.9 conda activate deid_example cd my_deid_example pip install -r requirements.txt ``` -------------------------------- ### Install Development Dependencies (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/development/linting-format.md Installs the development dependencies required for linting and formatting, including pre-commit, from the specified requirements file. ```bash pip install -r .github/dev-requirements.txt ``` -------------------------------- ### Install Deid Data Package (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md This command installs the `deid-data` Python package using pip. This package provides example datasets, such as the 'dicom-cookies' used in this tutorial, which are necessary to run the code examples. ```bash $ pip install deid-data ``` -------------------------------- ### Dependencies for Deidentification Example (requirements.txt) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/deid-dataset.md Lists the Python packages required to run the pydicom deidentification example, including `deid`, `pydicom`, and `pycryptodome`. ```Text deid pydicom pycryptodome ``` -------------------------------- ### Deid Recipe Action Syntax Examples Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md Illustrates the general syntax for actions within a deid recipe file, showing examples of actions that require a field and value, and those that only require a field. ```deid-recipe # ADD PatientIdentityRemoved YES # KEEP PixelData ``` -------------------------------- ### Clone Repository Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/local.md Clones the specified GitHub repository and changes the current directory into the cloned repository. This is typically the first step for local development or installation from source. ```bash git clone https://www.github.com/{{ site.repo }} cd {{ site.reponame }} ``` -------------------------------- ### Loading Example DICOM Files (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Imports required modules from `deid` and `os`, then loads a set of example DICOM files using `get_dataset` and `get_files` for subsequent processing. ```python from deid.dicom import get_files, replace_identifiers from deid.utils import get_installdir from deid.data import get_dataset import os # This will get a set of example cookie dicoms base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) ``` -------------------------------- ### Install from PyPI Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/local.md Installs the latest version of the 'deid' package from the Python Package Index (PyPI) using pip. This is the standard way to install published Python packages. ```bash pip install deid ``` -------------------------------- ### Basic Criteria Example Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-filters.md Illustrates a simple criterion definition starting with a LABEL identifier and a single 'contains' test applied to the 'ImageType' field. ```Configuration Syntax LABEL Burned In Annotation contains ImageType SAVE ``` -------------------------------- ### Serve Local Jekyll Site - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/contributing/docs.md Starts a local web server using Jekyll via Bundler (`bundle exec jekyll serve`). This command compiles the documentation and makes it accessible in a web browser, typically at `http://localhost:4000`, allowing contributors to preview their changes before committing. ```bash bundle exec jekyll serve ``` -------------------------------- ### Downloading Example Deid Recipe File - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Uses the `wget` command to download a sample `deid.dicom` recipe file from the pydicom/deid GitHub repository. This file can then be used to load a custom recipe. ```bash wget https://raw.githubusercontent.com/pydicom/deid/master/examples/deid/deid.dicom ``` -------------------------------- ### Retrieving Example Dataset Path (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-loading.md Uses the 'get_dataset' function from the 'deid.data' module to retrieve the absolute path to a bundled example dataset directory named "dicom-cookies". This function simplifies accessing included data. ```python from deid.data import get_dataset\ \ base = get_dataset(\"dicom-cookies\") ``` -------------------------------- ### Install deid-data Package Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-pixels.md Installs the external 'deid-data' package, which is required to provide data necessary for running the examples and cleaning processes described in this documentation section. ```bash pip install deid-data ``` -------------------------------- ### Load Example DICOM Dataset (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Retrieves the path to the 'dicom-cookies' example dataset using `get_dataset`. It then uses `get_files` to find all DICOM files within that directory and converts the generator output into a list. This list `dicom_files` serves as the input for subsequent processing steps. ```python base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) # todo : consider using generator functionality ``` -------------------------------- ### Install Development Version via Pip (Bash) Source: https://github.com/pydicom/deid/blob/master/README.md Installs the current development version of the deid library directly from the GitHub repository using the pip package manager. ```bash pip install git+git://github.com/pydicom/deid ``` -------------------------------- ### Finding Files with glob (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-loading.md Initializes the base directory path for the example data and demonstrates finding files within it using the 'glob' module, which supports pattern matching. ```python from glob import glob\ import os\ \ base = \"deid/data/dicom-cookies\"\ \ dicom_files = glob(\"%s/*\" %base) ``` -------------------------------- ### Install deid-data dependency (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Installs the required external dataset package 'deid-data' using the pip package manager. ```bash $ pip install deid-data ``` -------------------------------- ### Install Specific Version from PyPI Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/local.md Installs a specific version (0.1.19 in this case) of the 'deid' package from PyPI using pip. This is useful for reproducing environments or using features available only in a particular version. ```bash pip install deid==0.1.19 ``` -------------------------------- ### Basic DICOM Recipe Header Example Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-groups.md An example of a basic pydicom-deid recipe header section, demonstrating various commands like ADD, BLANK, KEEP, REPLACE, JITTER, and REMOVE for manipulating DICOM tags. ```text FORMAT dicom %header ADD PatientIdentityRemoved YES BLANK OrdValue KEEP Modality REPLACE id var:entity_id JITTER StudyDate var:entity_timestamp REMOVE ReferringPhysicianName ``` -------------------------------- ### Running deid inspect and Saving Results (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md Executes the `deid inspect` command on the `dicom-cookies` test dataset, similar to the previous example, but includes the `--save` flag to write the inspection results to a tab-separated file. ```bash deid inspect --deid examples/deid deid/data/dicom-cookies --save ``` -------------------------------- ### Install Pre-commit as a Git Hook (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/development/linting-format.md Installs pre-commit as a Git hook, causing it to automatically run checks before each commit. This ensures code is linted and formatted consistently. ```bash pre-commit install ``` -------------------------------- ### Install Stable Release via Pip (Bash) Source: https://github.com/pydicom/deid/blob/master/README.md Installs the latest stable version of the deid library from the Python Package Index (PyPI) using the pip package manager. ```bash pip install deid ``` -------------------------------- ### Example Output of 'value' Variable (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Shows an example of the string value passed as the `value` variable to a custom function, typically representing the original instruction for the field (e.g., 'func:generate_uid') from the de-identification configuration. ```python value # 'func:generate_uid' ``` -------------------------------- ### Shell into deid Docker Container (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/docker.md This command starts the Docker container and provides an interactive bash shell session inside it. This allows users to explore the container's environment, run `deid` commands directly within the container, or interact with the Python environment where `deid` is installed. ```bash $ docker run -it --entrypoint bash {{ site.docker }} (base) root@488f5e7f53a1:/code# ``` -------------------------------- ### Basic Config.json Structure Source: https://github.com/pydicom/deid/blob/master/docs/_docs/development/image-format.md Shows the minimal structure for the `config.json` file, defining the top-level keys 'get' and 'put' which correspond to the identifier extraction and modification steps, respectively. ```json { "get": {}, "put": {} } ``` -------------------------------- ### Example Private DICOM Tags Structure Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md This snippet shows a Python list representation of example private DICOM tags found in a file, including their tag numbers, creators, VRs, and values. ```python [(0011, 0003) Private Creator AE: 'Agfa DR', (0019, 0010) Private Creator LO: 'Agfa ADC NX', (0019, 1007) Private tag data CS: 'YES', (0019, 1021) Private tag data FL: 6.039999961853027, (0019, 1028) Private tag data CS: 'NO', (0019, 1030) Private tag data LT: '', (0019, 10f5) [Cassette Orientation] CS: 'LANDSCAPE', (0019, 10fa) Private tag data IS: "297", (0019, 10fb) Private tag data FL: 2.4000000953674316, (0019, 10fc) Private tag data IS: "171", (0019, 10fd) Private tag data CS: 'NO', (0019, 10fe) [Unknown] CS: 'MED'] ``` -------------------------------- ### Locating the deid Executable (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Demonstrates how to find the installation path of the deid command-line executable using the standard 'which' command in a bash shell. ```bash $ which deid /home/vanessa/anaconda3/bin/deid ``` -------------------------------- ### Loading DICOM Dataset in Python Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md Demonstrates how to load the `dicom-cookies` test dataset and retrieve a list of DICOM file paths using the `get_dataset` and `get_files` functions from the `deid.data` and `deid.dicom` modules. ```python from deid.data import get_dataset from deid.dicom import get_files dicom_files = list(get_files(get_dataset('dicom-cookies'))) ``` -------------------------------- ### Example Output of 'item' Variable (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Shows an example of the dictionary structure passed as the `item` variable to a custom function, containing extracted DICOM tags and potentially other function references available in the context. ```python item # {'(0008, 0005)': (0008, 0005) Specific Character Set CS: 'ISO_IR 100' [SpecificCharacterSet], # ... # 'generate_uid': } ``` -------------------------------- ### Example Output of 'dicom' Variable (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Shows an example of the `dicom` variable passed to a custom function, representing the full pydicom dataset object being processed, allowing access to all tags and values. ```python dicom # (0008, 0005) Specific Character Set CS: 'ISO_IR 100' # ... ``` -------------------------------- ### Sample Default Header Configuration Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md This configuration snippet illustrates a setup that mimics the default behavior of the de-identification tool, removing most header fields while keeping essential pixel data dimensions and adding a field indicating de-identification. ```De-identification Config FORMAT dicom %header ADD PatientIdentityRemoved YES REMOVE ALL KEEP PixelData KEEP SamplesPerPixel KEEP Columns KEEP Rows ``` -------------------------------- ### JITTER Action Examples Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md These examples demonstrate how to use the JITTER action to slightly modify date or time values. Jitter can be specified using a variable or a hardcoded integer value (positive or negative). ```De-identification Config JITTER StudyDate var:jitter JITTER Date 31 JITTER PatientBirthDate -31 ``` -------------------------------- ### Multi-Format De-identification Recipe (DICOM/NIfTI) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md An example recipe demonstrating how to define de-identification rules for multiple data formats (DICOM and NIfTI) within a single configuration file. ```deid-recipe FORMAT dicom %header ADD PatientIdentityRemoved YES REPLACE PatientID var:id REPLACE InstanceSOPUID var:source_id FORMAT nifti %header ADD PatientIdentityRemoved YES REPLACE PatientID var:id REPLACE InstanceSOPUID var:source_id ``` -------------------------------- ### Load DICOM Dataset using deid Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-get.md This snippet demonstrates how to load a sample DICOM dataset ('dicom-cookies') using the deid.data module and then obtain a list of file paths for the DICOM files within that dataset using deid.dicom.get_files. ```python from deid.data import get_dataset from deid.dicom import get_files base = get_dataset("dicom-cookies") dicom_files = list(get_files(base)) ``` -------------------------------- ### Loading DICOM Dataset (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Imports necessary functions from `deid` and loads a sample DICOM dataset ('dicom-cookies') to work with. It then gets a list of file paths from the dataset. ```python from deid.dicom import get_files from deid.data import get_dataset base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) ``` -------------------------------- ### Loading Example DICOM Data (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-pixels.md Retrieves a sample dataset named 'dicom-cookies' using `get_dataset` and then finds the path to the first DICOM file within that dataset using `get_files`. This prepares a specific file for processing. ```python dataset = get_dataset('dicom-cookies') dicom_file = list(get_files(dataset))[0] ``` -------------------------------- ### Loading De-identification Configuration in Python Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md Shows how to import the `load_deid` function from the `deid.config` module, which is used to load a de-identification specification file within a Python script. ```python from deid.config import load_deid ``` -------------------------------- ### Example Output of 'field' Variable (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Shows an example of the `field` variable passed to a custom function, which can be a DICOM element object containing tag, name, and value information for the specific field being processed. ```python field # (0020, 000d) Study Instance UID UI: 1.2.276.0.7230010.3.1.2.8323329.5329.1495927169.580350 [StudyInstanceUID] ``` -------------------------------- ### Nested Logic with Grouping Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-filters.md Presents an example demonstrating how criteria listed on the same line are evaluated together before being combined with criteria on other lines, simulating nested logical structures. ```Configuration Syntax LABEL Ct Dose Series contains Criteria1 + contains Criteria2 Value2 || contains Criteria3 Value3 coordinates 0,0,512,200 ``` -------------------------------- ### Sample DICOM Header Output Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-groups.md A sample output representation of a DICOM header, showing tag, VR, length, name, and value, used as an example for demonstrating recipe groups. ```text (0008,0050) : SH Len: 10 AccessionNumber Value: [999999999 ] (0008,0070) : LO Len: 8 Manufacturer Value: [SIEMENS ] (0008,1090) : LO Len: 22 ManufacturersModelName Value: [SOMATOM Definition AS+] (0009,0010) : LO Len: 20 PrivateCreator10xx Value: [SIEMENS CT VA1 DUMMY] (0010,0010) : PN Len: 14 PatientsName Value: [SIMPSON^HOMER^J^] (0010,0020) : LO Len: 12 PatientID Value: [000991991991 ] (0010,1000) : LO Len: 8 OtherPatientIDs Value: [E123456] (0010,1001) : PN Len: 8 OtherPatientNames Value: [E123456] (0010,21B0) : LT Len: 90 AdditionalPatientHistory Value: [MR SIMPSON LIKES DUFF BEER] (0019,1091) : DS Len: 6 Value: [E123456] (0019,1092) : DS Len: 6 Value: [M123456] ``` -------------------------------- ### Combining Multiple Deid Recipes - Python Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Demonstrates alternative ways to combine multiple recipe files. The first example shows loading a list of files directly. The second shows using a custom file with a different specified default base. Recipes are merged in the order provided, with later recipes overriding earlier ones. ```python recipe = DeidRecipe(deid=[deid_file1, deid_file2]) recipe = DeidRecipe(deid=deid_file1, base=True, default_base=deid_file2) ``` -------------------------------- ### Import necessary deid functions Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Imports the `get_files` function from `deid.dicom` to find DICOM files and `get_dataset` from `deid.data` to access example data. ```python from deid.dicom import get_files from deid.data import get_dataset ``` -------------------------------- ### Load sample DICOM data and recipe path (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Imports necessary functions from deid to retrieve a sample DICOM dataset and constructs the absolute path to a de-identification recipe file located within the deid examples directory. ```python # dicom from deid.data import get_dataset from deid.dicom import get_files base = get_dataset("dicom-cookies") dicom_file = next(get_files(base)) # recipe from deid.utils import get_installdir import os path = os.path.abspath("%s/../examples/deid/deid.dicom-groups" % get_installdir()) ``` -------------------------------- ### Running deid inspect Command (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md Executes the `deid inspect` command on the `dicom-cookies` test dataset using a specified de-identification configuration file (`examples/deid`). This command checks for potential PHI based on the configuration. ```bash deid inspect --deid examples/deid deid/data/dicom-cookies ``` -------------------------------- ### Example Deid Recipe for DICOM Headers Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md Demonstrates a sample deid recipe file (`deid.dicom`) defining rules for handling specific DICOM header fields using various actions like ADD, BLANK, KEEP, REPLACE, JITTER, and REMOVE. ```deid-recipe FORMAT dicom %header ADD PatientIdentityRemoved YES BLANK OrdValue KEEP Modality REPLACE id var:entity_id JITTER StudyDate var:entity_timestamp REMOVE ReferringPhysicianName ``` -------------------------------- ### CTP DicomPixelAnonymizer Rule Example Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-pixels.md Provides a concrete example of a rule from the CTP 'DicomPixelAnonymizer.script', showing a signature based on Modality, Manufacturer, and Model Name combined with specific pixel bounding boxes (0,0,100,20) and (480,200,32,250) that are candidates for cleaning. ```text { Modality.equals("CT") * Manufacturer.containsIgnoreCase("manufacturer1") * ManufacturerModelName.containsIgnoreCase("modelA") } (0,0,100,20) (480,200,32,250) ``` -------------------------------- ### Displaying DICOM Data Directory Structure (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-loading.md Uses the 'tree' command to show the file structure of the example 'dicom-cookies' directory, illustrating a typical flat directory layout for DICOM files. ```bash tree deid/data/dicom-cookies/\ deid/data/dicom-cookies/\ ├── image1.dcm\ ├── image2.dcm\ ├── image3.dcm\ ├── image4.dcm\ ├── image5.dcm\ ├── image6.dcm\ └── image7.dcm ``` -------------------------------- ### Execute Deid Get Action (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Runs the `deid` tool with the `get` action to extract identifiers from a demo DICOM dataset. By default, it saves the identifiers to a pickle file in a temporary directory and provides debug output. ```bash deid --action get ``` -------------------------------- ### Loading Specific Named Deid Bases - Python Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Provides examples of loading specific named base recipes from the library's data folder. This includes using a named base as the primary recipe, using it as a base combined with another recipe, or using it as a base on top of the default `deid.dicom`. ```python # Use dicom.xray.chest as a base recipe = DeidRecipe(deid=path, base=True, default_base='dicom.xray.chest') # Use dicom.xray.chest as the only one recipe = DeidRecipe(deid='dicom.xray.chest') # On top of the default base, deid.dicom recipe = DeidRecipe(deid='dicom.xray.chest', base=True) ``` -------------------------------- ### Executing deid Get and Put Action (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Shows how to perform both the `get` and `put` de-identification actions sequentially using the `--action all` flag. This is a shortcut for de-identifying data without manual intervention between extracting and applying identifiers. ```bash $ deid --action all ``` -------------------------------- ### Example Function for Conditional Removal (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md Provides a Python example of a function suitable for use with the 'REMOVE ALL func:...' recipe action. It checks if a field's value contains any part of the patient's name and returns True if it should be removed. ```Python def is_name(dicom, value, field): name = dicom.get('PatientName') currentvalue = dicom.get(field) splitvalues = name.split('^') for phi in splitvalues: if len(phi) > 4 and phi in currentvalue: return True return False ``` -------------------------------- ### Example Deid Recipe for DICOM Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-config.md This snippet shows a basic example of a deid recipe file. It defines a filter named 'dangerouscookie' based on patient sex and operator name, and specifies header actions to add a field and replace patient and SOP instance IDs using variables. ```deid recipe FORMAT dicom %filter dangerouscookie LABEL Criteria for Dangerous Cookie contains PatientSex M + notequals OperatorsName bold bread coordinates 0,0,512,110 %header ADD PatientIdentityRemoved YES REPLACE PatientID var:id REPLACE SOPInstanceUID var:source_id ``` -------------------------------- ### Example Custom DICOM De-identification Recipe (deid recipe) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-pixels.md Provides a more complete example of a deid recipe for DICOM files, including format declaration, whitelist/graylist filters, and custom rules for handling burned-in annotations and ultrasound regions. ```console FORMAT dicom %filter whitelist LABEL Marked as Clean Catch All # (Vanessa Sochat) contains BurnedInAnnotation No %filter graylist # Coordinates from fields LABEL Blank Image coordinates all LABEL Clean Ultrasound Regions present SequenceOfUltrasoundRegions keepcoordinates from:SequenceOfUltrasoundRegions ``` -------------------------------- ### Multiple Criteria and Mixed Logic Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-filters.md Provides an example combining multiple criterion lines under a single LABEL, using both '+' (AND) and '||' (OR) operators to define complex conditions. ```Configuration Syntax contains SeriesDescription SAVE + contains BurnedInAnnotation YES empty ImageType || empty DateOfSecondaryCapture ``` -------------------------------- ### Interacting with the DeidRecipe Instance (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-sequence-replace.md Demonstrates various ways to inspect the loaded de-identification recipe using methods like accessing the raw recipe dictionary (`recipe.deid`), getting the format (`recipe.get_format()`), and retrieving actions with optional filtering by action type or field name. ```python # To see an entire (raw in a dictionary) recipe just look at recipe.deid # What is the format? recipe.get_format() # dicom # What actions do we want to do on the header? recipe.get_actions() [{'action': 'REPLACE', 'field': 'InstanceCreationDate', 'value': 'func:generate_uid'}] # We can filter to an action type (not useful here, we only have one type) recipe.get_actions(action='REPLACE') # or we can filter to a field recipe.get_actions(field='InstanceCreationDate') [{'action': 'REPLACE', 'field': 'InstanceCreationDate', 'value': 'func:generate_uid'}] # and logically, both (not useful here) recipe.get_actions(field='PatientID', action="REMOVE") ``` -------------------------------- ### Blank fields starting with 'Patient' in deid recipe Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Example deid recipe line to blank all DICOM fields whose names start with 'Patient'. This uses the 'startswith' expander. ```text BLANK startswith:Patient ``` -------------------------------- ### Retrieving and Filtering Header Actions (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Shows how to get all header actions, filter actions by type or field, and retrieve defined field or value lists from a `DeidRecipe` object. ```python # We can get a complete list of actions recipe.get_actions() # We can filter to an action type recipe.get_actions(action='ADD') #[{'action': 'ADD', # 'field': 'IssuerOfPatientID', # 'value': 'STARR. In an effort to remove PHI all dates are offset from their original values.'}, # {'action': 'ADD', # 'field': 'PatientBirthDate', # 'value': 'var:entity_timestamp'}, # {'action': 'ADD', 'field': 'StudyDate', 'value': 'var:item_timestamp'}, # {'action': 'ADD', 'field': 'PatientID', 'value': 'var:entity_id'}, # {'action': 'ADD', 'field': 'AccessionNumber', 'value': 'var:item_id'}, # {'action': 'ADD', 'field': 'PatientIdentityRemoved', 'value': 'Yes'}] # or we can filter to a field recipe.get_actions(field='PatientID') #[{'action': 'REMOVE', 'field': 'PatientID'}, # {'action': 'ADD', 'field': 'PatientID', 'value': 'var:entity_id'}] # and logically, both recipe.get_actions(field='PatientID', action="REMOVE") # [{'action': 'REMOVE', 'field': 'PatientID'}] # If you have lists of fields or values defined, you can retrieve them too recipe.get_fields_lists() # OrderedDict([('instance_fields', # [{'action': 'FIELD', 'field': 'contains:Instance'}])]) recipe.get_values_lists() # OrderedDict([('cookie_names', # [{'action': 'SPLIT', # 'field': 'PatientID', # 'value': 'by="^";minlength=4'}]), # ('operator_names', # [{'action': 'FIELD', 'field': 'startswith:Operator'}])]) recipe.get_values_lists("cookie_names") # [{'action': 'SPLIT', 'field': 'PatientID', 'value': 'by="^";minlength=4'}] ``` -------------------------------- ### Read a single DICOM file Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Imports the `read_file` function from the `pydicom` library and reads the first file from the list of example DICOM files loaded previously. ```python from pydicom import read_file dicom = read_file(dicom_files[0]) ``` -------------------------------- ### Defining De-identification Filters (Deid Recipe) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md This snippet shows an example de-identification recipe file used by the `deid` library. It defines filters (`dangerouscookie`, `bigimage`) based on DICOM tag criteria and specifies header modifications (`%header`). The filters include criteria groups using `contains`, `notequals`, and `equals` operators, along with optional `coordinates` for burned-in pixel detection. ```deid-recipe FORMAT dicom %filter dangerouscookie LABEL Criteria for Dangerous Cookie contains PatientSex M + notequals OperatorsName bold bread coordinates 0,0,512,110 %filter bigimage LABEL Image Size Good for Machine Learning equals Rows 2048 + equals Columns 1536 coordinates 0,0,512,200 %header ADD PatientIdentityRemoved YES REPLACE PatientID var:id REPLACE SOPInstanceUID var:source_id ``` -------------------------------- ### Retrieving Filters from DeidRecipe (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Shows how to get all filters, list filter group names, and retrieve filters belonging to a specific group from a `DeidRecipe` object. ```python recipe.get_filters() # To get the group names recipe.ls_filters() # ['whitelist', 'blacklist'] # To get a list of specific filters under a group recipe.get_filters('blacklist') ``` -------------------------------- ### Loading Custom Deid Recipe File - Python Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Imports the `os` module to get the absolute path of a downloaded recipe file (`deid.dicom`) and then instantiates `DeidRecipe` by providing the file path to the `deid` parameter. This loads the specified custom recipe instead of the default. ```python deid_file = os.path.abspath('deid.dicom') recipe = DeidRecipe(deid=deid_file) ``` -------------------------------- ### Demonstrating startswith Expander Output Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/recipe-headers.md This snippet shows the 'REMOVE startswith:Patient' rule and the list of DICOM fields that are selected by this expander, illustrating which fields starting with 'Patient' are targeted for removal. ```deid config REMOVE startswith:Patient ['PatientAddress', 'PatientAge', 'PatientBirthDate', 'PatientID', 'PatientName', 'PatientPosition', 'PatientSex'] ``` -------------------------------- ### Loading Example DICOM Data - deid - Python Source: https://github.com/pydicom/deid/blob/master/examples/dicom/header-manipulation/README.md Retrieves the path to a sample DICOM dataset ('dicom-cookies') using `get_dataset` and then uses `get_files` to generate a list of all file paths within that dataset directory, storing them in the `dicom_files` variable. ```python base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) # todo : consider using generator functionality ``` -------------------------------- ### Inspect Cleaned DICOM File Output Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Displays an example of the output when inspecting the first cleaned DICOM file, showing that key identifiers like Study Instance UID, Series Instance UID, and Frame of Reference UID have been successfully replaced. ```Output cleaned_files[0] (0020, 000d) Study Instance UID UI: studyinstanceuid-1.2.826.0.1.3680043.10.188.1803528571851574950019323462792270863 (0020, 000e) Series Instance UID UI: seriesinstanceuid-1.2.826.0.1.3680043.10.188.1218768560803332968447018964651707696 (0020, 0052) Frame of Reference UID UI: frameofreferenceuid-1.2.826.0.1.3680043.10.188.3138524385829221974514732538424409758 ``` -------------------------------- ### Query Deid Recipe Object (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Demonstrates various ways to interact with the loaded `recipe` object. It shows how to access the raw recipe dictionary (`recipe.deid`), get the format (`recipe.get_format()`), retrieve all actions (`recipe.get_actions()`), and filter actions by type (`action='REPLACE'`) or field (`field='FrameOfReferenceUID'`). The expected outputs for some calls are included in the original text. ```python # To see an entire (raw in a dictionary) recipe just look at recipe.deid # What is the format? recipe.get_format() # dicom # What actions do we want to do on the header? recipe.get_actions() [{'action': 'REPLACE', 'field': 'StudyInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'SeriesInstanceUID', 'value': 'func:generate_uid'}, {'action': 'REPLACE', 'field': 'FrameOfReferenceUID', 'value': 'func:generate_uid'}] # We can filter to an action type (not useful here, we only have one type) recipe.get_actions(action='REPLACE') # or we can filter to a field recipe.get_actions(field='FrameOfReferenceUID') [{'action': 'REPLACE', 'field': 'FrameOfReferenceUID', 'value': 'func:generate_uid'}] # and logically, both (not useful here) recipe.get_actions(field='PatientID', action="REMOVE") ``` -------------------------------- ### Example Rule for Extracting Field Values (pydicom/deid, Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Illustrates a specific rule from the 'values' section of the de-identification recipe. This rule defines how to extract values from DICOM fields that start with 'Operator' and assign them to a list named 'operator_names' for later use in de-identification actions. ```Python {"operator_names": {'action': 'FIELD', 'field': 'startswith:Operator'}} ``` -------------------------------- ### Assigning Custom Function to Item (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md Demonstrates how to iterate through the `items` dictionary and assign the custom `generate_uid` function to a specific key ('generate_uid' in this example) for each item, making it callable during the de-identification process. ```python for item in items: items[item]['generate_uid'] = generate_uid ``` -------------------------------- ### Uninstall Package Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/local.md Uninstalls the 'deid' package using pip. This is useful for ensuring a clean installation or updating the package before installing a new version. ```bash pip uninstall deid ``` -------------------------------- ### Instantiating DicomCleaner Client (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-pixels.md Demonstrates how to create an instance of the `DicomCleaner` class. It shows both the default initialization (using a temporary output directory) and initialization with a specified output folder. ```python client = DicomCleaner() client = DicomCleaner(output_folder='/home/vanessa/Desktop') ``` -------------------------------- ### Inspecting DICOM Patient and Operator Info (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/client.md This Python snippet iterates through a list of DICOM files, reads each file using `pydicom.read_file`, and prints the filename, `OperatorsName`, and `PatientSex` tags. This is used to manually verify the values in the DICOM headers against the criteria defined in the de-identification recipe and confirm the flagging results. ```python for dicom_file in dicom_files: dicom = read_file(dicom_file) print("%s:%s - %s" %(os.path.basename(dicom_file), dicom.OperatorsName, dicom.PatientSex)) ``` -------------------------------- ### Initializing DeidRecipe Object (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md Demonstrates the basic initialization of a `DeidRecipe` object, typically loading a default or specified recipe file. ```python recipe = DeidRecipe() ``` -------------------------------- ### Downloading a deid Recipe File using Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Provides a bash command using `wget` to download a specific deid recipe file ('deid.dicom-pusheen') from a GitHub repository to the local filesystem. ```bash wget https://raw.githubusercontent.com/pydicom/deid/master/examples/deid/deid.dicom-pusheen ``` -------------------------------- ### Print Deid Get Output to Console (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Runs the `deid` tool with the `get` action and the `--print` flag to output the extracted identifiers directly to the standard output (console). ```bash deid --action get --print ``` -------------------------------- ### Clone Forked Repository - Bash Source: https://github.com/pydicom/deid/blob/master/docs/_docs/contributing/docs.md Clones a user's forked copy of the documentation repository from GitHub using `git clone` and then changes the current directory into the cloned repository using `cd`. Replace `meatball` and `{{ site.reponame }}` with your GitHub username and the repository name. ```bash git clone https://github.com/meatball/{{ site.reponame }} cd {{ site.reponame }}/ ``` -------------------------------- ### Initialize DicomParser instance (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Imports the DicomParser class from deid and creates an instance, passing the path to the DICOM file and the path to the de-identification recipe. ```python from deid.dicom.parser import DicomParser parser = DicomParser(dicom_file, recipe=path) ``` -------------------------------- ### Run Docker Container and Show Help (Bash) Source: https://github.com/pydicom/deid/blob/master/README.md Runs a new container based on the 'pydicom/deid' Docker image and executes the '--help' command within the container, typically displaying usage instructions. ```bash docker run pydicom/deid --help ``` -------------------------------- ### Listing Files with os.listdir (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-loading.md Demonstrates listing files directly within the previously defined base directory using the 'os.listdir' function, providing a simple list of file names. ```python os.listdir(base) ``` -------------------------------- ### Run deid --help via Docker (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/install/docker.md This command executes the `deid` tool inside the specified Docker container and displays its help output. It serves as a quick way to verify the container is working and see the available commands and options for `deid`. ```bash $ docker run {{ site.docker }} --help usage: deid [-h] [--quiet] [--debug] [--version] [--outfolder OUTFOLDER] [--format {dicom}] [--overwrite] {version,inspect,identifiers} ... ... ``` -------------------------------- ### Select fields starting with 'Patient' using expander Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/header-expanders.md Demonstrates using `expand_field_expression` with the 'startswith:Patient' expression and a DICOM dataset object to find fields whose names start with 'Patient'. The output list is shown. ```python # startswith:Patient fields = expand_field_expression("startswith:Patient", dicom) ['PatientBirthDate', 'PatientID', 'PatientName', 'PatientOrientation', 'PatientSex'] ``` -------------------------------- ### Execute Deid Get Action Quietly (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Runs the `deid` tool with the `get` action and the `--quiet` flag to reduce output verbosity. It still indicates where the output file is saved (INFO level). ```bash deid --action get --quiet ``` -------------------------------- ### Initialize Search Data Object (JavaScript/Liquid) Source: https://github.com/pydicom/deid/blob/master/docs/pages/search.html Initializes the `window.data` JavaScript object by iterating through site documents using Jekyll Liquid tags. It populates the object with document metadata like URL, title, category, and cleaned content, formatted for client-side search indexing. ```JavaScript window.data = { {% for item in site.docs %} {% if item.title %} {% unless item.excluded\_in\_search %} {% if added %},{% endif %} {% assign added = false %} "{{ item.url | slugify }}": { "id": "{{ item.url | slugify }}", "title": "{{ item.title | xml\_escape }}", "category": "{{ collection.title | xml\_escape }}", "url": " {{ item.url | xml\_escape }}", "content": {{ item.content | strip\_html | replace\_regex: "[\\s/\\n]+"," " | strip | jsonify }} } {% assign added = true %} {% endunless %} {% endif %} {% endfor %} }; ``` -------------------------------- ### Loading Sample DICOM Files with deid (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-put.md Imports necessary functions from the `deid` library to load a sample DICOM dataset and retrieve a list of file paths for processing. ```python from deid.dicom import get_files from deid.data import get_dataset base = get_dataset('dicom-cookies') dicom_files = list(get_files(base)) ``` -------------------------------- ### Example Expanded Sequence Output Structure Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/func-replace.md This snippet shows an example of how DICOM sequence data is represented when `get_identifiers` is used with the default `expand_sequences=True`. Nested fields within sequences are flattened into keys using double underscores (`__`) as separators. ```text 'ReferencedImageSequence__ReferencedSOPClassUID': '111111111111111111', 'ReferencedImageSequence__ReferencedSOPInstanceUID': '111111111111111', 'ReferencedPerformedProcedureStepSequence__InstanceCreationDate': '22222222', 'ReferencedPerformedProcedureStepSequence__InstanceCreationTime': '22222222', 'ReferencedPerformedProcedureStepSequence__InstanceCreatorUID': 'xxxxxxx', 'ReferencedPerformedProcedureStepSequence__ReferencedSOPClassUID': 'xxxxxxxxxx', 'ReferencedPerformedProcedureStepSequence__ReferencedSOPInstanceUID': 'xxxxxxxx', ``` -------------------------------- ### Redirect Deid Get Output to File (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Runs the `deid` tool with the `get` action and the `--print` flag, redirecting the standard output to a file named `deid-ids.txt`. Note that the output format is not guaranteed to be structured like JSON. ```bash deid --action get --print >> deid-ids.txt ``` -------------------------------- ### Extract Identifiers from DICOM Files using deid Source: https://github.com/pydicom/deid/blob/master/docs/_docs/getting-started/dicom-get.md This snippet shows how to use the get_identifiers function from deid.dicom to extract all identifiers from a list of DICOM file paths. The function returns a dictionary where keys are filenames and values are dictionaries containing tag information. ```python from deid.dicom import get_identifiers ids = get_identifiers(dicom_files) ``` -------------------------------- ### Loading and Inspecting a deid Recipe with Groups (Python) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/examples/recipe.md This Python snippet demonstrates how to load a deid recipe file using deid.config.DeidRecipe and then inspect the parsed recipe structure, showing how the defined groups and header actions are represented internally. ```python from deid.config import DeidRecipe recipe = DeidRecipe("examples/deid/deid.dicom-group") recipe.deid OrderedDict([('format', 'dicom'), ('values', OrderedDict([('cookie_names', [{'action': 'SPLIT', 'field': 'PatientID', 'value': 'by="^";minlength=4'}]), ('operator_names', [{'action': 'FIELD', 'field': 'startswith:Operator'}])])), ('fields', OrderedDict([('instance_fields', [{'action': 'FIELD', 'field': 'contains:Instance'}])])), ('header', [{'action': 'ADD', 'field': 'PatientIdentityRemoved', 'value': 'Yes'}, {'action': 'REPLACE', 'field': 'values:cookie_names', 'value': 'var:id'}, {'action': 'REPLACE', 'field': 'values:operator_names', 'value': 'var:source_id'}])]) ``` -------------------------------- ### Executing deid Get Action with Custom Input Folder (Bash) Source: https://github.com/pydicom/deid/blob/master/docs/_docs/user-docs/client.md Illustrates how to use the `deid` command with the `get` action to extract identifiers from DICOM files located in a specified input folder (`deid/data/dicom-cookies`). This allows processing data from a custom location instead of the default demo data. ```bash $ deid --action get --input deid/data/dicom-cookies ```