django_dicom.reader package — django_dicom 0.1.0 documentation

# django_dicom.reader package

## Module contents

Facilitates retrieval of DICOM header information using the `HeaderInformation` class. This functionality relies on a DICOM parser with a callable `parser()` method which accepts a `DataElement` instance and returns a parsed value. By default, the provided `DicomParser` class will be used.

## Subpackages

- django_dicom.reader.code_strings package
  - Module contents
  - Submodules
  - django_dicom.reader.code_strings.modality module
  - django_dicom.reader.code_strings.patient_position module
  - django_dicom.reader.code_strings.scanning_sequence module
  - django_dicom.reader.code_strings.sequence_variant module
  - django_dicom.reader.code_strings.sex module

## Submodules

## django_dicom.reader.header_information module

class `django_dicom.reader.header_information.` `HeaderInformation`(raw: pydicom.dataset.FileDataset, parser: type = <class 'django_dicom.reader.parser.DicomParser'>)

  Bases: `object`

  Facilitates access to DICOM header information from pydicom’s FileDataset.

  `get_element`(tag_or_keyword) → pydicom.dataelem.DataElement

    Returns a pydicom DataElement from the associated FileDataset either by tag (passed as a tuple) or a keyword (passed as a string). If none found or the tag or keyword are invalid, returns None.

    Parameters

      tag_or_keyword (tuple or str) – Tag or keyword representing the requested data element.

    Returns

      The requested data element.

    Return type

      DataElement

  `get_element_by_keyword`(keyword: str) → pydicom.dataelem.DataElement

    Returns a pydicom DataElement from the header (FileDataset isntance) by keyword.

    Parameters

      keyword (str) – The keyword representing the DICOM data element in pydicom.

    Returns

      The requested data element.

    Return type

      DataElement

  `get_element_by_tag`(tag: tuple) → pydicom.dataelem.DataElement

    Returns a pydicom DataElement from the header (FileDataset isntance) by tag.

    Parameters

      tag (tuple) – The DICOM tag of the desired data element.

    Returns

      The requested data element..

    Return type

      DataElement

  `get_parsed_value`(tag_or_keyword)

    Returns the parsed value of pydicom data element using the this class’s parser attribute. The data element may be represented by tag or by its pydicom keyword. If none is found will return None.

    Parameters

      tag_or_keyword (tuple or str) – Tag or keyword representing the requested data element.

    Returns

      Parsed data element value.

    Return type

      type

  `get_raw_value`(tag_or_keyword)

    Returns the raw value for the requested data element, as returned by pydicom. If none is found will return None.

    Parameters

      tag_or_keyword (tuple or str) – Tag or keyword representing the requested data element.

    Returns

      The raw value of the data element.

    Return type

      type

  `get_value`(tag_or_keyword, parsed: bool = True)

    Returns the value of a pydicom data element, selected by tag (tuple) or keyword (str).

    Parameters

      - tag_or_keyword (tuple or str) – Tag or keyword representing the requested data element.

      - parsed (bool, optional) – Whether to return a parsed or raw value (the default is True, which will return the parsed value).

    Returns

      The requested data element value.

    Return type

      type

## django_dicom.reader.parser module

class `django_dicom.reader.parser.` `DicomParser`

  Bases: `object`

  `CODE_STRINGS_DICT` = {'(0008, 0060)': <enum 'Modality'>, '(0010, 0040)': <enum 'Sex'>, '(0018, 0020)': <enum 'ScanningSequence'>, '(0018, 0021)': <enum 'SequenceVariant'>, '(0018, 5100)': <enum 'PatientPosition'>}
  `N_IN_YEAR` = {'D': 365.2422, 'M': 12, 'W': 52.1429, 'Y': 1}
  `PARSING_METHOD` = {<ValueRepresentation.AGE_STRING: 'AS'>: 'parse_age_string', <ValueRepresentation.DATE: 'DA'>: 'parse_date', <ValueRepresentation.TIME: 'TM'>: 'parse_time', <ValueRepresentation.DATE_TIME: 'DT'>: 'parse_datetime', <ValueRepresentation.INTEGER_STRING: 'IS'>: 'parse_integer_string', <ValueRepresentation.DECIMAL_STRING: 'DS'>: 'parse_decimal_string', <ValueRepresentation.UNKNOWN: 'UN'>: 'parse_unknown', <ValueRepresentation.CODE_STRING: 'CS'>: 'parse_code_string'}
  `SINGLE_VALUE_CODE_STRINGS` = ['(0010, 0040)', '(0018, 5100)', '(0008, 0060)']
  `parse`(element: pydicom.dataelem.DataElement)

    Tries to parse a pydicom DICOM data element using its value-representation (VR) attribute. If no parser method is registered for the VR under the PARSING_METHOD dictionary, will simply return the raw value.

    Parameters

      element (DataElement) – DICOM data element as represented by pydicom.

    Returns

      Parsed DICOM data element value.

    Return type

      type

  `parse_age_string`(element: pydicom.dataelem.DataElement) → float

    Parses Age String (AS) data elements into a float representation of the age in years.

    Parameters

      element (DataElement) – DICOM Age String (AS) data element.

    Returns

      The age in years.

    Return type

      float

  `parse_code_string`(element: pydicom.dataelem.DataElement)

    Parses Code String (CS) data elements to a more readable string or list of strings. This method relies on an Enum representation of the data element’s possible values to be registered in the Parser’s CODE_STRINGS_DICT by tag. If no Enum is registered, will return None.

    Parameters

      element (DataElement) – DICOM Code String (CS) data element.

    Returns

      Parsed value/s.

    Return type

      str or list

  `parse_date`(element: pydicom.dataelem.DataElement) → None.datetime.date

    Parses Date (DA) data elements to date objects.

    Parameters

      element (DataElement) – DICOM Date (DA) data element.

    Returns

      Native python date object.

    Return type

      datetime.date

  `parse_datetime`(element: pydicom.dataelem.DataElement) → datetime.datetime

    Parses Date Time (DT) data elements to datetime objects.

    Parameters

      element (DataElement) – DICOM Date Time (DT) data element.

    Returns

      Native python datetime object.

    Return type

      datetime.time

  `parse_decimal_string`(element: pydicom.dataelem.DataElement)

    Parses Decimal String (DS) data elements to floats. In case the Value Multiplicity (VM) is greater than one, returns a list of floats.

    Parameters

      element (DataElement) – DICOM Decimal String (DS) data element.

    Returns

      Data element value/s.

    Return type

      float or list

  `parse_integer_string`(element: pydicom.dataelem.DataElement) → int

    Parses DICOM Integer String (IS) data elements to integers.

    Parameters

      element (DataElement) – DICOM Integer String (IS) data element.

    Returns

      Data element value.

    Return type

      int

  `parse_siemens_gradient_direction`(value: bytes) → list

    Parses a SIEMENS MR image’s B-vector as represented in the private (0019, 100E) DiffusionGradientDirection DICOM tag.

    Parameters

      value (bytes) – SIEMENS private DiffusionGradientDirection data element.

    Returns

      Gradient directions (B-vector).

    Return type

      list

  `parse_siemens_slice_timing`(value: bytes) → list

    Parses a SIEMENS MR image’s slice timing as saved in the private (0019, 1029) MosaicRefAcqTimes tag to a list of floats representing slice times in milliseconds.

    Parameters

      value (bytes) – SIEMENS private MosaicRefAcqTimes data element.

    Returns

      Slice times in milliseconds.

    Return type

      list

  `parse_time`(element: pydicom.dataelem.DataElement) → None.datetime.time

    Parses Time (TM) data elements to time objects.

    Parameters

      element (DataElement) – DICOM Time (TM) data element.

    Returns

      Native python time object.

    Return type

      datetime.time

  `parse_unknown`(element: pydicom.dataelem.DataElement)

    Parses private tags and other Unknown (UN) data elememts.

    Parameters

      element (DataElement) – DICOM Unknown (UN) data element.

## django_dicom.reader.value_representation module

class `django_dicom.reader.value_representation.` `ValueRepresentation`

  Bases: `enum.Enum`

  DICOM value-representations (VRs).

  `AGE_STRING` = 'AS'
  `APPLICATION_ENTITY` = 'AE'
  `ATTRIBUTE_TAG` = 'AT'
  `CODE_STRING` = 'CS'
  `DATE` = 'DA'
  `DATE_TIME` = 'DT'
  `DECIMAL_STRING` = 'DS'
  `FLOATING_POINT_DOUBLE` = 'FD'
  `FLOATING_POINT_SINGLE` = 'FL'
  `INTEGER_STRING` = 'IS'
  `LONG_STRING` = 'LO'
  `LONG_TEXT` = 'LT'
  `OTHER_64_BIT_VERY_LONG` = 'OV'
  `OTHER_BYTE` = 'OB'
  `OTHER_DOUBLE` = 'OD'
  `OTHER_FLOAT` = 'OF'
  `OTHER_LONG` = 'OL'
  `OTHER_WORD` = 'OW'
  `PERSON_NAME` = 'PN'
  `SEQUENCE_OF_ITEMS` = 'SQ'
  `SHORT_STRING` = 'SH'
  `SHORT_TEXT` = 'ST'
  `SIGNED_64_BIT_VERY_LONG` = 'SV'
  `SIGNED_LONG` = 'SL'
  `SIGNED_SHORT` = 'SS'
  `TIME` = 'TM'
  `UNIQUE_IDENTIFIER` = 'UI'
  `UNIVERSAL_RESOURCE` = 'UR'
  `UNKNOWN` = 'UN'
  `UNLIMITED_CHARACTERS` = 'UC'
  `UNLIMITED_TEXT` = 'UT'
  `UNSIGNED_64_BIT_VERY_LONG` = 'UV'
  `UNSIGNED_LONG` = 'UL'
  `UNSIGNED_SHORT` = 'US'