Class: Quincy::PCnet

Inherits:
Object
  • Object
show all
Defined in:
lib/quincy.rb

Overview

Interface to Frey Quincy PCNet (www.frey.de/q_pcnet.htm).

Extracts patient information by reading the folder containing the PATDATXX-subdirectories.

Usage:

# find the patient with the number 98
patient = Quincy::PCnet.new("/example/QUINCY").find(98)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ PCnet

Returns a new instance of PCnet.

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
# File 'lib/quincy.rb', line 34

def initialize(path = nil)
  path ||= ENV["QUINCY"]
  @@blocksize = 1024
  
  raise ArgumentError, "Quincy Path not set (use '-q' or ENV['QUINCY'])" unless path
  @quincy_path = Pathname.new(path)
end

Instance Attribute Details

#quincy_pathObject (readonly)

Returns the value of attribute quincy_path.



32
33
34
# File 'lib/quincy.rb', line 32

def quincy_path
  @quincy_path
end

Instance Method Details

#find(nr) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/quincy.rb', line 54

def find(nr)
  filename = Pathname.new(path_for(nr))
  return nil unless File.exists?(filename)

  filename.open { |f|
    while (record = f.read(@@blocksize,"rb")) 
      patient = read_record(record)
      return patient if patient and patient.nr == nr
    end
  }
end

#path_for(nr) ⇒ Object

returns the PATDAT-file for a given patient nr

path = Quincy::PCnet.new("foo").path_for("98")
#=> "foo/PATDAT00/0098.DAT"


47
48
49
50
51
52
# File 'lib/quincy.rb', line 47

def path_for(nr)
  dat_nr = nr % 0xa00
  dir_nr = dat_nr / 0x80
  patdat_path = @quincy_path + "PATDAT#{"%02d" % dir_nr}" + "#{"%04d"% dat_nr}.DAT"
  patdat_path.to_str
end