module DICOM

Copyright 2008-2018 Christoffer Lervag

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Constants

ABSTRACT_SYNTAX_REJECTED

Presentation context rejected by abstract syntax.

ACCEPTANCE

Network proposition accepted.

APPLICATION_CONTEXT

Application context SOP class UID.

COMMAND_LAST_FRAGMENT
COMMAND_MORE_FRAGMENTS
CPU_ENDIAN

System (CPU) Endianness.

C_CANCEL_RQ
C_ECHO_RQ
C_ECHO_RSP
C_FIND_RQ
C_FIND_RSP
C_GET_RQ
C_GET_RSP
C_MOVE_RQ
C_MOVE_RSP
C_STORE_RQ

Some network command element codes:

C_STORE_RSP
DATA_LAST_FRAGMENT
DATA_MORE_FRAGMENTS

The network communication flags:

DATA_SET_PRESENT
DEFAULT_MESSAGE_ID
DELIMITER_TAGS

All delimiter tags.

ENCAPSULATED_PIXEL_NAME

Name of the pixel tag when holding encapsulated data.

ENCODING_NAME

The relationship between DICOM Character Set and Encoding name.

EXPLICIT_BIG_ENDIAN

Explicit, big endian transfer syntax.

EXPLICIT_LITTLE_ENDIAN

Explicit, little endian transfer syntax.

GROUP_LENGTH

Group length element.

IMPLICIT_LITTLE_ENDIAN

Implicit, little endian (the default transfer syntax).

ITEM_ABSTRACT_SYNTAX
ITEM_APPLICATION_CONTEXT

Network communication item types:

ITEM_DELIMITER

Item delimiter tag.

ITEM_IMPLEMENTATION_UID
ITEM_IMPLEMENTATION_VERSION
ITEM_MAX_LENGTH
ITEM_MAX_OPERATIONS_INVOKED
ITEM_PRESENTATION_CONTEXT_REQUEST
ITEM_PRESENTATION_CONTEXT_RESPONSE
ITEM_ROLE_NEGOTIATION
ITEM_TAG

Item tag.

ITEM_TAGS

All Item related tags (includes both types of delimitation items).

ITEM_TRANSFER_SYNTAX
ITEM_USER_INFORMATION
ITEM_VR

The VR used for the item elements.

LIBRARY

The library instance (data dictionary) of the DICOM module.

META_GROUP

File meta group.

NAME

Ruby DICOM name & version (max 16 characters).

NO_DATA_SET_PRESENT
PDU_ABORT
PDU_ASSOCIATION_ACCEPT
PDU_ASSOCIATION_REJECT
PDU_ASSOCIATION_REQUEST

Network communication PDU types:

PDU_DATA
PDU_RELEASE_REQUEST
PDU_RELEASE_RESPONSE
PIXEL_ITEM_NAME

Name of encapsulated items.

PIXEL_TAG

Pixel tag.

PI_ARGB
PI_CMYK
PI_HSV

Retired Photometric Interpretations, are those needed to be supported?

PI_MONOCHROME1

Photometric Interpretations Taken from DICOM Specification PS 3.3 C.7.6.3.1.2 Photometric Interpretation

PI_MONOCHROME2
PI_PALETTE_COLOR
PI_RGB
PI_YBR_FULL
PI_YBR_FULL_422
PI_YBR_ICT
PI_YBR_PARTIAL_420
PI_YBR_PARTIAL_422
PI_YBR_RCT
ROOT_DIR

Defines the gem root directory in the file system.

SEQUENCE_DELIMITER

Sequence delimiter tag.

SUCCESS

Network transmission successful.

TRANSFER_SYNTAX_REJECTED

Presentation context rejected by transfer syntax.

TXS_DEFLATED_LITTLE_ENDIAN
TXS_EXPLICIT_BIG_ENDIAN
TXS_EXPLICIT_LITTLE_ENDIAN
TXS_IMPLICIT_LITTLE_ENDIAN

General

TXS_JPEG_2000_PART1_LOSSLESS
TXS_JPEG_2000_PART1_LOSSLESS_OR_LOSSY
TXS_JPEG_2000_PART2_LOSSLESS
TXS_JPEG_2000_PART2_LOSSLESS_OR_LOSSY
TXS_JPEG_BASELINE

TRANSFER SYNTAXES FOR ENCAPSULATION OF ENCODED PIXEL DATA

TXS_JPEG_EXTENDED
TXS_JPEG_LOSSLESS_NH
TXS_JPEG_LOSSLESS_NH_FOP
TXS_JPEG_LS_LOSSLESS
TXS_JPEG_LS_NEAR_LOSSLESS
TXS_JPIP
TXS_JPIP_DEFLATE
TXS_MPEG2_MP_HL
TXS_MPEG2_MP_ML
TXS_RLE
UID_ROOT

Ruby DICOM's registered DICOM UID root (Implementation Class UID).

VALUE_CONVERSION

The type conversion (method) used for the various value representations.

VERIFICATION_SOP

Verification SOP class UID.

VERSION

The ruby-dicom version string.

Attributes

image_processor[RW]

The ruby-dicom image processor to be used.

key_representation[RW]

The key representation for hashes, json, yaml.

source_app_title[RW]

Source Application Entity Title (gets written to the DICOM header in files where it is undefined).

Public Class Methods

generate_uid(root=UID_ROOT, prefix=1) click to toggle source

Generates a unique identifier string. The UID is composed of a DICOM root UID, a type prefix, a datetime part and a random number part.

@param [String] root the DICOM root UID to be used for generating the UID string @param [String] prefix an integer string which is placed between the dicom root and the time/random part of the UID @return [String] the generated unique identifier @example Create a random UID with specified root and prefix

uid = DICOM.generate_uid('1.2.840.999', '5')
# File lib/dicom/general/methods.rb, line 19
def generate_uid(root=UID_ROOT, prefix=1)
  # NB! For UIDs, leading zeroes immediately after a dot is not allowed.
  date = Time.now.strftime("%Y%m%d").to_i.to_s
  time = Time.now.strftime("%H%M%S").to_i.to_s
  random = rand(99999) + 1 # (Minimum 1, max. 99999)
  uid = [root, prefix, date, time, random].join('.')
  return uid
end
key_use_method_names() click to toggle source

Use method names as key. Example: :patients_name

# File lib/dicom/general/methods.rb, line 93
def key_use_method_names
  @key_representation = :name_as_method
end
key_use_names() click to toggle source

Use names as key. Example: “Patient's Name”

# File lib/dicom/general/methods.rb, line 87
def key_use_names
  @key_representation = :name
end
key_use_tags() click to toggle source

Use tags as key. Example: '0010,0010'

# File lib/dicom/general/methods.rb, line 81
def key_use_tags
  @key_representation = :tag
end
load(data) click to toggle source

Loads DICOM data to DObject instances and returns them in an array. Invalid DICOM sources (files) are ignored. If no valid DICOM source is given, an empty array is returned.

@param [String, DObject, Array<String, DObject>] data single or multiple DICOM data (directories, file paths, binary strings, DICOM objects) @return [Array<DObject>] an array of successfully loaded DICOM objects

# File lib/dicom/general/methods.rb, line 35
def load(data)
  data = Array[data] unless data.respond_to?(:to_ary)
  ary = Array.new
  data.each do |element|
    if element.is_a?(String)
      begin
        if File.directory?(element)
          files = Dir[File.join(element, '**/*')].reject {|f| File.directory?(f) }
          dcms = files.collect {|f| DObject.read(f)}
        elsif File.file?(element)
          dcms = [DObject.read(element)]
        else
          dcms = [DObject.parse(element)]
        end
      rescue
        dcms = [DObject.parse(element)]
      end
      ary += dcms.keep_if {|dcm| dcm.read?}
    else
      # The element was not a string, and the only remaining valid element type is a DICOM object:
      raise ArgumentError, "Invalid element (#{element.class}) given. Expected string or DObject." unless element.respond_to?(:to_dcm)
      element.was_dcm_on_input = true
      ary << element.to_dcm
    end
  end
  ary
end
load_files(path) click to toggle source

Loads DICOM files from a given path (which points to either a directory or a file).

@param [String] path a file or directory path @return [Array<String>] an array of individual file paths

# File lib/dicom/general/methods.rb, line 68
def load_files(path)
  files = Array.new
  if File.directory?(path)
    files = Dir[File.join(path, '**/*')].reject {|f| File.directory?(f) }
  else
    # This path is presumably a file.
    files << path
  end
  files
end