Using dcm4che2 from JRuby

Here is a quick example on how to access the dcm4che2 Toolkit with JRuby.

# dcm4che2 Toolkit with the elegance of Ruby
# Read File Example - Ron Sweeney

require 'java'
include_class 'java.io.BufferedInputStream'
include_class 'java.io.FileInputStream'
include_class 'org.dcm4che2.io.DicomInputStream'
include_class 'org.dcm4che2.data.BasicDicomObject'

def PrintTag(tagvalue)

dcm = BasicDicomObject.new
din = DicomInputStream.new(BufferedInputStream.new(FileInputStream.new("c:\\MR.dcm")))
din.readDicomObject(dcm, -1)
dicomvalue = dcm.getString(tagvalue)
return dicomvalue
end

puts "Patient Name: " + PrintTag(0x00100010)
puts "Modality Type: " + PrintTag(0x00080060)

Try to use code similar to below if you get class loading errors:

jardir = File.expand_path(File.dirname(__FILE__) + "/jar")
Dir.glob("#{jardir}/*.{jar,zip}").each {|jar| require jar}  

You should require all the dcm4che toolkit jars before including any class as jruby doesn't include them automatically.