Module: Dcm4chee::HasDicomObject

Extended by:
ActiveSupport::Concern
Included in:
DicomFile, Instance, Patient, Series, Study, TrashedDicomFile, TrashedInstance, TrashedPatient, TrashedSeries, TrashedStudy
Defined in:
lib/dcm4chee/models/has_dicom_object.rb

Defined Under Namespace

Modules: ClassMethods Classes: Element

Instance Method Summary collapse

Instance Method Details

#as_json(opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/dcm4chee/models/has_dicom_object.rb', line 53

def as_json(opts = {})
  opts[:exclude] ||= []
  opts[:exclude] << :dicom_attributes

  opts[:methods] ||= []
  opts[:methods] << :dcm_elements

  super(opts)
end

#dcmObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dcm4chee/models/has_dicom_object.rb', line 19

def dcm
  tsuid = defined?(dicom_file) ? dicom_file.transfer_syntax_uid : ::DICOM::EXPLICIT_LITTLE_ENDIAN

  return nil unless dicom_attributes

  # TODO Cache it
  adapter = repository.adapter.options[:adapter]
  attrs = nil
  if adapter == 'postgres'
    attrs = dicom_attributes.gsub(/\\x/, '').to_byte_string
  elsif adapter == 'mysql'
    attrs = dicom_attributes.to_hex_string.to_byte_string
  end

  ::DICOM::DObject.parse(attrs, syntax: tsuid) if attrs
end

#dcm_elementsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dcm4chee/models/has_dicom_object.rb', line 36

def dcm_elements
  return [] unless dcm

  @elements ||= begin
                  @elements = []
                  dcm.elements.each do |e|
                    @elements << Element.new(name: e.name,
                                             value: e.value.to_s,
                                             tag: e.tag,
                                             value_representation: e.vr,
                                             length: e.length)
                  end

                  @elements
                end
end