django_dicom.models.managers package¶
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 theDataElement
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: - header (
Header
) – The header instance with which the created data element should be associated. - definition (
DataElementDefinition
) – The data element definition of the created data element - data_element (
dicom_parser.data_element.DataElement
) – Object representing a single data element in memory
Returns: The created instance
Return type: - header (
-
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: - header (
Header
) – The header instance with which the created data element should be associated. - data_element (
dicom_parser.data_element.DataElement
) – Object representing a single data element in memory
Returns: The created instance
Return type: - header (
-
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 theDataElementDefinition
model.-
from_dicom_parser
(data_element: dicom_parser.data_element.DataElement) → tuple¶ Gets or creates a
DataElementDefinition
instance from a dicom_parserDataElement
.Parameters: data_element ( dicom_parser.data_element.DataElement
) – Object representing a single data element in memoryReturns: 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 aDataElementDefinition
instance.Parameters: data_element ( dicom_parser.data_element.DataElement
) – Object representing a single data element in memoryReturns: DataElementDefinition
instantiation keyword argumentsReturn 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 theDataElementValue
model.-
from_dicom_parser
(data_element: dicom_parser.data_element.DataElement) → Tuple¶ Get or create some
DataElementValue
subclass instances from a dicom_parserDataElement
.Parameters: data_element ( dicom_parser.data_element.DataElement
) – Object representing a single data element in memoryReturns: 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_parserDataElement
.Parameters: data_element ( dicom_parser.data_element.DataElement
) – Object representing a single data element in memoryReturns: 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
andvalue
set to None) and log the exception in thewarnings
field.Parameters: - ValueModel (
DataElementValue
) – SomeDataElementValue
subclass used to instatiate values - data_element (
dicom_parser.data_element.DataElement
) – Object representing a single data element in memory - error (Exception) – The raised exception
Returns: data_element_value, created
Return type: - ValueModel (
-
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: - ValueModel (
DataElementValue
) – SomeDataElementValue
subclass used to instatiate values - data_element (
dicom_parser.data_element.DataElement
) – Object representing a single data element in memory
Returns: data_element_values, any_created
Return type: Tuple[List[DataElementValue, ..], bool]
- ValueModel (
-
handle_no_value
(ValueModel) → Tuple¶ Handles data elements with a
value_multiplicity
of 0. Returns an “empty” instance of the ValueModel (i.e. withraw
andvalue
set to None).Parameters: ValueModel ( DataElementValue
) – SomeDataElementValue
subclass used to instatiate valuesReturns: 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: - ValueModel (
DataElementValue
) – SomeDataElementValue
subclass used to instatiate values - data_element (
dicom_parser.data_element.DataElement
) – Object representing a single data element in memory
Returns: data_element_value, created
Return type: Tuple[DataElementValue, bool]
- ValueModel (
-
handle_value_multiplicity
(ValueModel, data_element: dicom_parser.data_element.DataElement) → Tuple¶ Handles the creation of the
DataElementValue
subclass instances according to the dicom_parserDataElement
’svalue_multiplicity
attribute.Parameters: - ValueModel (
DataElementValue
) – SomeDataElementValue
subclass used to instatiate values - 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]
- ValueModel (
-
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 theDicomEntity
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 fromReturns: 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 theHeader
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 memoryReturns: 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 theImage
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: - path (
-
get_or_create
(*args, **kwargs) → Tuple¶ Overrides
get_or_create()
to callget_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: - path (
-
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
instancesReturn type: - path (
-
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.
- path (
-
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 dataReturns: Path of the created file Return type: pathlib.Path
-