django_dicom.models package — django_dicom 0.1.0 documentation

# django_dicom.models package

## Module contents

Creates models to represent the various DICOM entities: `Image`, `Series`, `Study`, and `Patient` (see here and here for more information).

The relationship between entities in django_dicom:

## Submodules

## django_dicom.models.choice_enum module

class `django_dicom.models.choice_enum.` `ChoiceEnum`

  Bases: `enum.Enum`

  An enumeration.

  `choices` = <bound method ChoiceEnum.choices of <enum 'ChoiceEnum'>>

## django_dicom.models.dicom_entity module

class `django_dicom.models.dicom_entity.` `DicomEntity`(*args, **kwargs)

  Bases: `django_extensions.db.models.TimeStampedModel`

  An abstract model to represent a DICOM entity.

  `FIELD_TO_HEADER` = {}
  class `Meta`

    Bases: `object`

    `abstract` = False
  `NOT_HEADER_FIELD` = {'names': ('created', 'modified'), 'types': (<class 'django.db.models.fields.related.OneToOneField'>, <class 'django.db.models.fields.related.ForeignKey'>, <class 'django.db.models.fields.AutoField'>, <class 'django.db.models.fields.reverse_related.ManyToOneRel'>, <class 'django.db.models.fields.files.FileField'>, <class 'django.db.models.fields.TextField'>)}
  `get_header_fields`() → list

    Returns a list of the derived model’s fields which represent DICOM header information.

    Returns

      Fields representing DICOM header information.

    Return type

      list

  classmethod `get_header_keyword`(field_name: str) → str

    Returns the pydicom keyword to return the requested field’s value from header data. Relies on the derived model’s FIELD_TO_HEADER class attribute. If no matching key is found, will simply return the field’s name in CamelCase formatting (the formatting of pydicom’s header keywords).

    Returns

      pydicom header keyword.

    Return type

      str

  `get_next_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
  `get_next_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
  `get_previous_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
  `get_previous_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
  `is_header_field`(field: django.db.models.fields.Field) → bool

    Returns a boolean indicating whether this field represents DICOM header information or not.

    Parameters

      field (models.Field) – The field in question.

    Returns

      Whether this field represent DICOM header information or not.

    Return type

      bool

  `update_fields_from_header`(header: django_dicom.reader.header_information.HeaderInformation, exclude: list = []) → None

    Update model fields from header data.

    Parameters

      - header (HeaderInformation) – DICOM header data.

      - exclude (list, optional) – Field names to exclude (the default is [], which will not exclude any header fields).

## django_dicom.models.fields module

class `django_dicom.models.fields.` `ChoiceArrayField`(base_field, size=None, **kwargs)

  Bases: `django.contrib.postgres.fields.array.ArrayField`

  A field that allows us to store an array of choices.

  Uses Django 1.9’s postgres ArrayField and a MultipleChoiceField for its formfield.

  `formfield`(**kwargs)

    Return a django.forms.Field instance for this field.

## django_dicom.models.help_text module

## django_dicom.models.image module

class `django_dicom.models.image.` `Image`(*args, **kwargs)

  Bases: `django_dicom.models.dicom_entity.DicomEntity`

  A model to represent a single DICOM image. This model is meant to be instantiated with the file field set to some .dcm file, and then it is updated automatically by inspection of the file’s header information.

  exception `DoesNotExist`

    Bases: `django.core.exceptions.ObjectDoesNotExist`

  `FIELD_TO_HEADER` = {'date': 'InstanceCreationDate', 'number': 'InstanceNumber', 'time': 'InstanceCreationTime', 'uid': 'SOPInstanceUID'}
  exception `MultipleObjectsReturned`

    Bases: `django.core.exceptions.MultipleObjectsReturned`

  `date`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `dcm`

    The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

        >>> from myapp.models import MyModel
        >>> instance = MyModel.objects.get(pk=1)
        >>> instance.file.size

    Assign a file object on assignment so you can do:

        >>> with open('/path/to/hello.world', 'r') as f:
        ...     instance.file = File(f)

  `get_absolute_url`() → str
  `get_b_value`() → int

    Returns the b-value for diffusion weighted images (DWI). Currently only SIEMENS tags are supported.

    Returns

      Degree of diffusion weighting applied.

    Return type

      int

  `get_data`(as_json: bool = False) → numpy.ndarray

    Returns the image’s pixel array as a NumPy array or as a JSON-like string if as_json is True.

    Parameters

      as_json (bool) – Return the pixel array as a JSON formatted string.

    Returns

      Image’s pixel array.

    Return type

      `numpy.ndarray`

  `get_next_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
  `get_next_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
  `get_previous_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
  `get_previous_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
  `gradient_direction`

    Returns the gradient direction vector for this image. Currently only SIEMENS tags are supported.

    Returns

      This image’s gradient direction.

    Return type

      list

  `header`

    Caches the created `HeaderInformation` instance to prevent multiple reades.

    Returns

      The image’s header information.

    Return type

      `HeaderInformation`

  `id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `number`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `objects` = <django.db.models.manager.Manager object>
  `read_file`(header_only: bool = False) → pydicom.dataset.FileDataset

    Reads the DICOM image file to memory.

    Parameters

      header_only (bool, optional) – Exclude pixel data or not, by default False which will include pixel data.

    Returns

      DICOM image file as object.

    Return type

      `pydicom.dataset.FileDataset`

  `read_header`() → django_dicom.reader.header_information.HeaderInformation

    Reads the header information from the associated DICOM file.

    Returns

      Image’s header information.

    Return type

      `HeaderInformation`

  `series`

    Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Child.parent` is a `ForwardManyToOneDescriptor` instance.

  `series_id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `slice_timing`

    Returns the slice timing vector for this image. Currently only SIEMENS tags are supported.

    Returns

      This image’s slice times.

    Return type

      list

  `time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `uid`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

## django_dicom.models.patient module

class `django_dicom.models.patient.` `Patient`(*args, **kwargs)

  Bases: `django_dicom.models.dicom_entity.DicomEntity`

  A model to represent DICOM’s patient entity. Holds the corresponding attributes as discovered in created `django_dicom.Image` instances.

  exception `DoesNotExist`

    Bases: `django.core.exceptions.ObjectDoesNotExist`

  `FIELD_TO_HEADER` = {'date_of_birth': 'PatientBirthDate', 'sex': 'PatientSex', 'uid': 'PatientID'}
  exception `MultipleObjectsReturned`

    Bases: `django.core.exceptions.MultipleObjectsReturned`

  `NAME_PARTS` = ['given_name', 'family_name', 'middle_name', 'name_prefix', 'name_suffix']
  `date_of_birth`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `family_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `get_absolute_url`() → str
  `get_full_name`() → str

    Returns the first and last names of the patient.

    Returns

      Patient’s first and last names.

    Return type

      str

  `get_next_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
  `get_next_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
  `get_previous_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
  `get_previous_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
  `get_sex_display`(*, field=<django.db.models.fields.CharField: sex>)
  `given_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `middle_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `name_prefix`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `name_suffix`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `objects` = <django.db.models.manager.Manager object>
  `series_set`

    Accessor to the related objects manager on the reverse side of a many-to-one relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Parent.children` is a `ReverseManyToOneDescriptor` instance.

    Most of the implementation is delegated to a dynamically defined manager class built by `create_forward_many_to_many_manager()` defined below.

  `sex`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `uid`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `update_fields_from_header`(header: django_dicom.reader.header_information.HeaderInformation, exclude: list = []) → None

    Override `django_dicom.DicomEntity`’s `django_dicom.DicomEntity.update_fields_from_header()` in order to handle setting the name parts seperately.

    Parameters

      - header (HeaderInformation) – DICOM header data.

      - exclude (list, optional) – Field names to exclude (the default is [], which will not exclude any header fields).

  `update_patient_name`(header: django_dicom.reader.header_information.HeaderInformation) → None

    Parses the patient’s name from the DICOM header and updates the instance’s fields.

    Parameters

      header (`HeaderInformation`) – A DICOM image’s `HeaderInformation` instance.

## django_dicom.models.series module

class `django_dicom.models.series.` `Series`(*args, **kwargs)

  Bases: `django_dicom.models.dicom_entity.DicomEntity`

  A model to represent DICOM’s series entity. Holds the corresponding attributes as discovered in created `django_dicom.Image` instances.

  exception `DoesNotExist`

    Bases: `django.core.exceptions.ObjectDoesNotExist`

  `FIELD_TO_HEADER` = {'date': 'SeriesDate', 'description': 'SeriesDescription', 'mr_acquisition_type': 'MRAcquisitionType', 'number': 'SeriesNumber', 'time': 'SeriesTime', 'uid': 'SeriesInstanceUID'}
  `MR_ACQUISITION_2D` = '2D'
  `MR_ACQUISITION_3D` = '3D'
  `MR_ACQUISITION_TYPE_CHOICES` = (('2D', '2D'), ('3D', '3D'))
  exception `MultipleObjectsReturned`

    Bases: `django.core.exceptions.MultipleObjectsReturned`

  `body_part_examined`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `date`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `description`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `device_serial_number`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `echo_time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `echo_train_length`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `flip_angle`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `get_absolute_url`() → str
  `get_data`(as_json: bool = False) → numpy.ndarray

    Returns a NumPy array with the series data.

    Parameters

      as_json (bool) – Return the pixel array as a JSON formatted string.

    Returns

      Series pixel array.

    Return type

      np.ndarray

  `get_gradient_directions`() → list

    Returns the gradient directions (B-vectors) for SIEMENS originated DWI DICOM data.

    Returns

      B-vectors for the three dimensions.

    Return type

      list

  `get_modality_display`(*, field=<django.db.models.fields.CharField: modality>)
  `get_mr_acquisition_type_display`(*, field=<django.db.models.fields.CharField: mr_acquisition_type>)
  `get_next_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
  `get_next_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
  `get_path`() → str

    Returns the base directory containing the images composing this series.

    Returns

      This series’s base directory path.

    Return type

      str

  `get_patient_position_display`(*, field=<django.db.models.fields.CharField: patient_position>)
  `get_previous_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
  `get_previous_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
  `get_scanning_sequence_display`() → list

    Returns the `ScanningSequence` Enum values corresponding to the scanning_sequence field’s value.

    Returns

      `ScanningSequence` Enum values.

    Return type

      list

  `get_sequence_variant_display`() → list

    Returns the `SequenceVariant` Enum values corresponding to the sequence_variant field’s value.

    Returns

      `SequenceVariant` Enum values.

    Return type

      list

  `id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `image_set`

    Accessor to the related objects manager on the reverse side of a many-to-one relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Parent.children` is a `ReverseManyToOneDescriptor` instance.

    Most of the implementation is delegated to a dynamically defined manager class built by `create_forward_many_to_many_manager()` defined below.

  `institution_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `inversion_time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `magnetic_field_strength`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `manufacturer`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `manufacturer_model_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `modality`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `mr_acquisition_type`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `number`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `objects` = <django.db.models.manager.Manager object>
  `operators_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `patient`

    Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Child.parent` is a `ForwardManyToOneDescriptor` instance.

  `patient_id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `patient_position`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `pixel_spacing`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `protocol_name`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `repetition_time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `scanning_sequence`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `sequence_variant`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `slice_thickness`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `study`

    Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Child.parent` is a `ForwardManyToOneDescriptor` instance.

  `study_id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `uid`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

## django_dicom.models.study module

class `django_dicom.models.study.` `Study`(*args, **kwargs)

  Bases: `django_dicom.models.dicom_entity.DicomEntity`

  A model to represent DICOM’s study entity. Holds the corresponding attributes as discovered in created `django_dicom.Image` instances.

  exception `DoesNotExist`

    Bases: `django.core.exceptions.ObjectDoesNotExist`

  `FIELD_TO_HEADER` = {'date': 'StudyDate', 'description': 'StudyDescription', 'time': 'StudyTime', 'uid': 'StudyInstanceUID'}
  exception `MultipleObjectsReturned`

    Bases: `django.core.exceptions.MultipleObjectsReturned`

  `date`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `description`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `get_absolute_url`()
  `get_next_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=True, **kwargs)
  `get_next_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=True, **kwargs)
  `get_previous_by_created`(*, field=<django_extensions.db.fields.CreationDateTimeField: created>, is_next=False, **kwargs)
  `get_previous_by_modified`(*, field=<django_extensions.db.fields.ModificationDateTimeField: modified>, is_next=False, **kwargs)
  `id`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `objects` = <django.db.models.manager.Manager object>
  `series_set`

    Accessor to the related objects manager on the reverse side of a many-to-one relation.

    In the example:

        class Child(Model):
            parent = ForeignKey(Parent, related_name='children')

    `Parent.children` is a `ReverseManyToOneDescriptor` instance.

    Most of the implementation is delegated to a dynamically defined manager class built by `create_forward_many_to_many_manager()` defined below.

  `time`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

  `uid`

    A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

## django_dicom.models.validators module

`django_dicom.models.validators.` `validate_file_extension`(value)