django_dicom.models.managers package

Module contents

Manager subclasses for some of the app’s models.

References

Subpackages

Submodules

django_dicom.models.managers.data_element module

Definition of a custom Manager for the DataElement model.

class django_dicom.models.managers.data_element.DataElementManager

Bases: django.db.models.manager.Manager

Custom Manager for the DataElement model.

create_from_dicom_parser(header, definition, data_element: dicom_parser.data_element.DataElement)

Creates a new instance under header using the provided definition and data_element.

Parameters:
Returns:

The created instance

Return type:

DataElement

from_dicom_parser(header, data_element: dicom_parser.data_element.DataElement)

Creates a new instance under header using the provided dicom_parser.data_element.DataElement instance.

Parameters:
Returns:

The created instance

Return type:

DataElement

django_dicom.models.managers.data_element_definition module

Definition of a custom Manager for the DataElementDefinition model.

class django_dicom.models.managers.data_element_definition.DataElementDefinitionManager

Bases: django.db.models.manager.Manager

Custom Manager for the DataElementDefinition model.

from_dicom_parser(data_element: dicom_parser.data_element.DataElement) → tuple

Gets or creates a DataElementDefinition instance from a dicom_parser DataElement.

Parameters:data_element (dicom_parser.data_element.DataElement) – Object representing a single data element in memory
Returns:data_element_definition, created
Return type:tuple
django_dicom.models.managers.data_element_definition.data_element_to_definition(data_element: dicom_parser.data_element.DataElement) → dict

Converts a dicom_parser DataElement to a dictionary of keyword arguments that may be used to instantiate a DataElementDefinition instance.

Parameters:data_element (dicom_parser.data_element.DataElement) – Object representing a single data element in memory
Returns:DataElementDefinition instantiation keyword arguments
Return type:dict

django_dicom.models.managers.data_element_value module

Definition of a custom InheritanceManager for the DataElementValue model.

For more information about the InheritanceManager class, see django-model-utils’s InheritanceManager documentation.

class django_dicom.models.managers.data_element_value.DataElementValueManager

Bases: model_utils.managers.InheritanceManager

Custom InheritanceManager for the DataElementValue model.

from_dicom_parser(data_element: dicom_parser.data_element.DataElement) → Tuple

Get or create some DataElementValue subclass instances from a dicom_parser DataElement.

Parameters:data_element (dicom_parser.data_element.DataElement) – Object representing a single data element in memory
Returns:data_element_value or data_element_values, created
Return type:Tuple[Union[DataElementValue, List[DataElementValue, ..]], bool]
get_or_create_from_nonsequence(data_element: dicom_parser.data_element.DataElement) → Tuple

Get or create some DataElementValue subclass instances from a non-Sequence of Items dicom_parser DataElement.

Parameters:data_element (dicom_parser.data_element.DataElement) – Object representing a single data element in memory
Returns:data_element_value or data_element_values, created
Return type:Tuple[Union[DataElementValue, List[DataElementValue, ..]], bool]
handle_invalid_data(ValueModel, data_element: dicom_parser.data_element.DataElement, error: Exception) → Tuple

If reading the value from the data element using dicom_parser raises an exception, this method is called to create an “empty” instance of the ValueModel (i.e. with raw and value set to None) and log the exception in the warnings field.

Parameters:
Returns:

data_element_value, created

Return type:

tuple

handle_multiple_values(ValueModel, data_element: dicom_parser.data_element.DataElement) → Tuple[list, bool]

Handles data elements with a value_multiplicity greater than 1.

Parameters:
Returns:

data_element_values, any_created

Return type:

Tuple[List[DataElementValue, ..], bool]

handle_no_value(ValueModel) → Tuple

Handles data elements with a value_multiplicity of 0. Returns an “empty” instance of the ValueModel (i.e. with raw and value set to None).

Parameters:ValueModel (DataElementValue) – Some DataElementValue subclass used to instatiate values
Returns:dicom_data_element, created
Return type:Tuple[DicomDataElement, bool]
handle_single_value(ValueModel, data_element: dicom_parser.data_element.DataElement) → tuple

Handles data elements with a value_multiplicity of 1.

Parameters:
Returns:

data_element_value, created

Return type:

Tuple[DataElementValue, bool]

handle_value_multiplicity(ValueModel, data_element: dicom_parser.data_element.DataElement) → Tuple

Handles the creation of the DataElementValue subclass instances according to the dicom_parser DataElement’s value_multiplicity attribute.

Parameters:
Returns:

data_element_value or data_element_values, created

Return type:

Tuple[Union[DataElementValue, List[DataElementValue, ..]], bool]

django_dicom.models.managers.dicom_entity module

Definition of a custom Manager for the DicomEntity model.

class django_dicom.models.managers.dicom_entity.DicomEntityManager

Bases: django.db.models.manager.Manager

Custom Manager for the DicomEntity model.

from_header(header) → Tuple

Get or create an instance using the provided header.

Parameters:header (django_dicom.models.header.Header) – Header instance to query this entity’s information from
Returns:dicom_entity, created
Return type:Tuple[DicomEntity, bool]

django_dicom.models.managers.header module

Definition of a custom Manager for the Header model.

class django_dicom.models.managers.header.HeaderManager

Bases: django.db.models.manager.Manager

Custom Manager for the Header model.

from_dicom_parser(header: dicom_parser.header.Header, **kwargs)

Creates a new instance from a dicom_parser dicom_parser.header.Header.

Parameters:header (dicom_parser.header.Header) – Object representing an entire DICOM header in memory
Returns:Created instance
Return type:django_dicom.models.header.Header
Raises:DicomImportError – DICOM header read error

django_dicom.models.managers.image module

Definition of the ImageManager class.

class django_dicom.models.managers.image.ImageManager

Bases: django_dicom.models.managers.dicom_entity.DicomEntityManager

Custom Manager for the Image model.

TEMP_DCM_FILE_NAME = 'tmp.dcm'

Name given to DICOM files that need to be saved locally in order to be read.

create_from_dcm(path: pathlib.Path, autoremove: bool = True)

Creates an Image instance from a given path.

Parameters:
  • path (pathlib.Path) – Local .dcm file path
  • autoremove (bool, optional) – Whether to remove the local copy of the .dcm file under MEDIA_ROOT if creation fails, by default True
Returns:

The created image

Return type:

Image

get_or_create(*args, **kwargs) → Tuple

Overrides get_or_create() to call get_or_create_from_dcm() in case the dcm keyword argument is provided.

Returns:image, created
Return type:Tuple[Image, bool]
get_or_create_from_dcm(path: pathlib.Path, autoremove: bool = True) → Tuple

Gets or creates an Image instance based on the contents of the provided .dcm path.

Parameters:
  • path (pathlib.Path) – Local .dcm file path
  • autoremove (bool, optional) – Whether to remove the local copy of the .dcm file under MEDIA_ROOT if creation fails, by default True
Returns:

image, created

Return type:

Tuple[Image, bool]

import_path(path: pathlib.Path, progressbar: bool = True, report: bool = True, persistent: bool = True, pattern: bool = '*.dcm', autoremove: bool = True) → django.db.models.query.QuerySet

Iterates the given directory tree and imports any .dcm files found within it.

Parameters:
  • path (pathlib.Path) – Base path for recursive .dcm import
  • progressbar (bool, optional) – Whether to display a progressbar or not, by default True
  • report (bool, optional) – Whether to print out a summary report when finished or not, by default True
  • persistent (bool, optional) – Whether to continue and raise a warning or to raise an exception when failing to read a DICOM file’s header
  • pattern (str, optional) – Globbing pattern to use for file import
Returns:

The created Image instances

Return type:

QuerySet

report_import_path_results(path: pathlib.Path, counter: dict) → None

Reports the result of a recursive path import.

Parameters:
  • path (pathlib.Path) – Base path of DICOM data import
  • counter (dict) – Dictionary containing created and existing keys containing the number of files which fit in each category.
store_image_data(image_data: _io.BufferedReader) → pathlib.Path

Stores binary image data to a temporary local path under the project’s MEDIA_ROOT.

Parameters:image_data (io.BufferedReader) – Binary DICOM image data
Returns:Path of the created file
Return type:pathlib.Path