quincy 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGES +17 -0
- data/History.txt +3 -0
- data/Manifest.txt +9 -0
- data/README.txt +1 -0
- data/Rakefile +13 -0
- data/bin/quincy +43 -0
- data/lib/quincy.rb +92 -0
- data/quincy.gemspec +26 -0
- data/spec/quincy_spec.rb +70 -0
- data/spec/sample/PATDAT00/0098.DAT +0 -0
- data/spec/sample/PATDAT10/1317.DAT +0 -0
- metadata +105 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/CHANGES
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
current
|
2
|
+
- Quincy::PCnet(nil) takes path from ENV
|
3
|
+
- rake test now runs tests with specrb
|
4
|
+
|
5
|
+
0.3.3
|
6
|
+
- Pathname() -> Pathname.new() (ruby 1.8.4)
|
7
|
+
- raise an Exception if no path is given explicitly or via the
|
8
|
+
Environment
|
9
|
+
|
10
|
+
0.3.1
|
11
|
+
- changed package generation script to use Hoe
|
12
|
+
- changed unit tests to use test/spec
|
13
|
+
|
14
|
+
0.2.0
|
15
|
+
- Changed handling of Version Numbers (Quincy::VERSION::STRING)
|
16
|
+
- added "-V" switch
|
17
|
+
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
this is a small library to extract patient information from Frey Quincy PCNet
|
data/Rakefile
ADDED
data/bin/quincy
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'quincy'
|
5
|
+
|
6
|
+
USAGE = "usage: #{$0} PATNR"
|
7
|
+
|
8
|
+
quincy_path = nil # defaults to ENV["QUINCY"]
|
9
|
+
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.on "-q", "--quincy-path PATHNAME",
|
12
|
+
"Location of PATDAT directory",
|
13
|
+
"Defaults to ENV[\"QUINCY\"]" do |arg|
|
14
|
+
quincy_path = arg
|
15
|
+
end
|
16
|
+
opts.on "-V","--version","Display version and exit" do
|
17
|
+
puts Quincy::VERSION
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
opts.on_tail("-h","--help","Show this Message") do
|
21
|
+
puts opts
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.parse!
|
26
|
+
end
|
27
|
+
|
28
|
+
if ARGV.empty?
|
29
|
+
puts USAGE
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
ARGV.each { |i|
|
35
|
+
patnr = Integer(i)
|
36
|
+
pat = Quincy::PCnet.new(quincy_path).find(patnr)
|
37
|
+
puts pat if pat
|
38
|
+
}
|
39
|
+
rescue Exception => e
|
40
|
+
warn e.message
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
data/lib/quincy.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'iconv'
|
5
|
+
|
6
|
+
module Quincy
|
7
|
+
VERSION = "0.4.0"
|
8
|
+
|
9
|
+
# a Struct containing patient information
|
10
|
+
#
|
11
|
+
class Patient < Struct.new( :nr, :last_name, :first_name )
|
12
|
+
def to_s
|
13
|
+
"#{"%6d"%nr}: #{name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
[last_name, first_name].join(", ");
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Interface to Frey Quincy PCNet (http://www.frey.de/q_pcnet.htm).
|
22
|
+
#
|
23
|
+
# Extracts patient information by reading the folder containing
|
24
|
+
# the PATDATXX-subdirectories.
|
25
|
+
#
|
26
|
+
# Usage:
|
27
|
+
#
|
28
|
+
# # find the patient with the number 98
|
29
|
+
# patient = Quincy::PCnet.new("/example/QUINCY").find(98)
|
30
|
+
#
|
31
|
+
class PCnet
|
32
|
+
attr_reader :quincy_path
|
33
|
+
|
34
|
+
def initialize(path = nil)
|
35
|
+
path ||= ENV["QUINCY"]
|
36
|
+
@@blocksize = 1024
|
37
|
+
|
38
|
+
raise ArgumentError, "Quincy Path not set (use '-q' or ENV['QUINCY'])" unless path
|
39
|
+
@quincy_path = Pathname.new(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
# returns the PATDAT-file for a given patient nr
|
43
|
+
#
|
44
|
+
# path = Quincy::PCnet.new("foo").path_for("98")
|
45
|
+
# #=> "foo/PATDAT00/0098.DAT"
|
46
|
+
#
|
47
|
+
def path_for(nr)
|
48
|
+
dat_nr = nr % 0xa00
|
49
|
+
dir_nr = dat_nr / 0x80
|
50
|
+
patdat_path = @quincy_path + "PATDAT#{"%02d" % dir_nr}" + "#{"%04d"% dat_nr}.DAT"
|
51
|
+
patdat_path.to_str
|
52
|
+
end
|
53
|
+
|
54
|
+
def find(nr)
|
55
|
+
filename = Pathname.new(path_for(nr))
|
56
|
+
return nil unless File.exists?(filename)
|
57
|
+
|
58
|
+
filename.open { |f|
|
59
|
+
while (record = f.read(@@blocksize,"rb"))
|
60
|
+
patient = read_record(record)
|
61
|
+
return patient if patient and patient.nr == nr
|
62
|
+
end
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def read_record(record) #:nodoc:
|
69
|
+
return unless record[4] == 0xf6
|
70
|
+
|
71
|
+
read_str = lambda { |pattern| lambda { |chunk|
|
72
|
+
str = chunk.unpack(pattern).first.strip
|
73
|
+
Iconv.new("UTF-8","CP850").iconv(str)
|
74
|
+
}}
|
75
|
+
|
76
|
+
fields = {
|
77
|
+
:nr => lambda { |s| s.unpack("@10A5").first.to_i },
|
78
|
+
:last_name => read_str["@15A30"],
|
79
|
+
:first_name => read_str["@45A30"]
|
80
|
+
}
|
81
|
+
|
82
|
+
pat = Patient.new
|
83
|
+
|
84
|
+
fields.each { |k,v|
|
85
|
+
pat[k] = v.call(record)
|
86
|
+
}
|
87
|
+
|
88
|
+
pat
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
data/quincy.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'quincy'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{quincy}
|
7
|
+
s.version = Quincy::VERSION
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = ["Levin Alexander"]
|
11
|
+
s.description = %q{}
|
12
|
+
s.email = %q{mail@levinalex.net}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
|
18
|
+
s.homepage = %q{http://github.com/levinalex/quincy}
|
19
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.summary = %q{extract patient data from QuincyPCnet data files, <http://www.frey.de/q_pcnet.htm>}
|
22
|
+
|
23
|
+
s.add_dependency "rake"
|
24
|
+
s.add_development_dependency "rspec"
|
25
|
+
end
|
26
|
+
|
data/spec/quincy_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'quincy'
|
2
|
+
|
3
|
+
describe "With Patdat-Files in the current directory" do
|
4
|
+
before do
|
5
|
+
@q = Quincy::PCnet.new('.')
|
6
|
+
end
|
7
|
+
|
8
|
+
specify "file for patient 0 should be PATDAT00/0000.DAT" do
|
9
|
+
@q.path_for(0).should == "PATDAT00/0000.DAT"
|
10
|
+
end
|
11
|
+
specify "file for patient 98 should be PATDAT00/0098.DAT" do
|
12
|
+
@q.path_for(98).should == "PATDAT00/0098.DAT"
|
13
|
+
end
|
14
|
+
specify "file for patient 128 should be PATDAT00/0098.DAT" do
|
15
|
+
@q.path_for(128).should == "PATDAT01/0128.DAT"
|
16
|
+
end
|
17
|
+
specify "file for patient 19237 should be PATDAT10/1317.DAT" do
|
18
|
+
@q.path_for(19237).should == "PATDAT10/1317.DAT"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "generated path to the patdat files" do
|
23
|
+
specify "absolute pahs should be preserved" do
|
24
|
+
@q = Quincy::PCnet.new("/absolute/path")
|
25
|
+
@q.path_for(300).should == "/absolute/path/PATDAT02/0300.DAT"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "reading of patients" do
|
30
|
+
before do
|
31
|
+
@q = Quincy::PCnet.new( File.dirname(__FILE__) + "/sample")
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "name of patient 98 should be Sierra, Rudolph" do
|
35
|
+
patient = @q.find(98)
|
36
|
+
patient.name.should == ("Sierra, Rudolph")
|
37
|
+
patient.nr.should be_equal(98)
|
38
|
+
end
|
39
|
+
|
40
|
+
specify "searching for nonexistent patient should return nil" do
|
41
|
+
@q.find(140898).should be_nil
|
42
|
+
@q.find(12345).should be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when ENV['QUINCY'] is set" do
|
47
|
+
before do
|
48
|
+
ENV["QUINCY"] = "/some/path"
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "path should default to this value" do
|
52
|
+
Quincy::PCnet.new.quincy_path.to_s.should == "/some/path"
|
53
|
+
end
|
54
|
+
|
55
|
+
specify "Path should be taken from ENV even if Quincy is constructed with 'nil' as argument" do
|
56
|
+
Quincy::PCnet.new(nil).quincy_path.to_s.should == "/some/path"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when ENV['QUINCY'] is not set" do
|
62
|
+
before do
|
63
|
+
ENV["QUINCY"] = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
specify "PCnet should raise an error if it is constructed without an argument" do
|
67
|
+
lambda { @q = Quincy::PCnet.new() }.should raise_error(ArgumentError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
Binary file
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quincy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Levin Alexander
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-30 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: ""
|
49
|
+
email: mail@levinalex.net
|
50
|
+
executables:
|
51
|
+
- quincy
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
56
|
+
files:
|
57
|
+
- .gitignore
|
58
|
+
- CHANGES
|
59
|
+
- History.txt
|
60
|
+
- Manifest.txt
|
61
|
+
- README.txt
|
62
|
+
- Rakefile
|
63
|
+
- bin/quincy
|
64
|
+
- lib/quincy.rb
|
65
|
+
- quincy.gemspec
|
66
|
+
- spec/quincy_spec.rb
|
67
|
+
- spec/sample/PATDAT00/0098.DAT
|
68
|
+
- spec/sample/PATDAT10/1317.DAT
|
69
|
+
homepage: http://github.com/levinalex/quincy
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: extract patient data from QuincyPCnet data files, <http://www.frey.de/q_pcnet.htm>
|
102
|
+
test_files:
|
103
|
+
- spec/quincy_spec.rb
|
104
|
+
- spec/sample/PATDAT00/0098.DAT
|
105
|
+
- spec/sample/PATDAT10/1317.DAT
|