bsi-pipeline 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bsi-pipeline/models.rb +42 -27
- data/lib/bsi-pipeline/version.rb +1 -1
- data/spec/models_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1860307f4df0faa88344a07c7a67f1d8ea0f1f72
|
4
|
+
data.tar.gz: 8110bd05377d002f3e98ca08dc76145314ea45db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7263ac1a8020b32bf45686a778d133bed804769a925f30387671666406710ed227405837e29b36a0c3963f3fb4da0f2f24dcd53d7f40ab482840ba5047796aa8
|
7
|
+
data.tar.gz: 03398a38f92a438a7d89c39882c6bcdbcbd23252c366238380be4705c0029cec09712191d886d97e7067922953d6321cedfdb63eac20c10ad41c6abddacb3e3d
|
data/lib/bsi-pipeline/models.rb
CHANGED
@@ -5,9 +5,10 @@ module Pipeline
|
|
5
5
|
module BSI
|
6
6
|
module Models
|
7
7
|
class Specimen < Pipeline::Model::Base
|
8
|
-
attr_accessor :seminal_parent
|
9
|
-
|
10
|
-
|
8
|
+
attr_accessor :seminal_parent, :bfh_map
|
9
|
+
|
10
|
+
REQUIRED_FIELDS = %w(study_id subject_id specimen_type date_drawn date_received label_status billing_method thaws).map{|v| v.to_sym}
|
11
|
+
BSI_CORE_FIELDS = {
|
11
12
|
:study_id => 'vial.study_id',
|
12
13
|
:specimen_type => 'vial.mat_type',
|
13
14
|
:current_label => 'vial.current_label',
|
@@ -45,32 +46,46 @@ module Pipeline
|
|
45
46
|
:sample_modifiers => 'sample.sample_modifiers'
|
46
47
|
}
|
47
48
|
|
48
|
-
vial_props = (BFH_MAP.keys+REQUIRED_ATTRIBUTES).uniq
|
49
|
-
begin
|
50
|
-
vial_props = YAML::load(File.open(File.join(File.dirname(__FILE__), 'vial_props.yaml'))).map{|v| v.to_sym}
|
51
|
-
rescue Errno::ENOENT
|
52
|
-
end
|
53
|
-
|
54
|
-
(vial_props-BFH_MAP.keys+[:specimen_code]).each{|attr_string| attr_accessor attr_string.to_sym}
|
55
|
-
BFH_MAP.keys.each{ |attr| attr_accessor attr }
|
56
|
-
|
57
49
|
# Define Defaults
|
58
|
-
def initialize(
|
50
|
+
def initialize(options={})
|
51
|
+
@bfh_map = Hash.new
|
52
|
+
add_attributes(BSI_CORE_FIELDS)
|
53
|
+
add_attributes(REQUIRED_FIELDS)
|
54
|
+
add_attributes(options[:custom_required_fields]) if options[:custom_required_fields]
|
55
|
+
add_attributes(options[:custom_fields]) if options[:custom_fields]
|
56
|
+
self.thaws = '0'
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
def add_attributes(attributes)
|
60
|
+
new_attributes = Hash.new
|
61
|
+
case attributes.class.to_s
|
62
|
+
when Hash.to_s
|
63
|
+
attributes.each do |k,v|
|
64
|
+
new_attributes[k.to_sym] = v.to_s
|
65
|
+
end
|
66
|
+
when Array.to_s
|
67
|
+
attributes.each do |elem|
|
68
|
+
new_attributes[elem.to_sym] = "vial.#{elem}"
|
68
69
|
end
|
69
|
-
|
70
70
|
else
|
71
|
-
|
71
|
+
raise 'Please pass either an Array or Hash of attributes'
|
72
|
+
end
|
73
|
+
(new_attributes.keys - bfh_map.keys).each do |attr|
|
74
|
+
self.class.send(:attr_accessor, attr)
|
72
75
|
end
|
76
|
+
self.bfh_map.merge(new_attributes)
|
77
|
+
self
|
78
|
+
end
|
73
79
|
|
80
|
+
def build(bfh={})
|
81
|
+
self.seminal_parent = true
|
82
|
+
bfh.keys.each do |bfh_key|
|
83
|
+
if BFH_MAP.has_value?(bfh_key)
|
84
|
+
instance_eval("self.#{BFH_MAP.key(bfh_key)} = '#{bfh[bfh_key]}'")
|
85
|
+
else
|
86
|
+
instance_eval("self.#{bfh_key.gsub(/vial\./, '')} = '#{bfh[bfh_key]}'")
|
87
|
+
end
|
88
|
+
end
|
74
89
|
end
|
75
90
|
|
76
91
|
def bsi_id()
|
@@ -85,8 +100,8 @@ module Pipeline
|
|
85
100
|
bfh = Hash.new
|
86
101
|
# Add 1-1 matches/translations
|
87
102
|
formatted_attributes.each do |k,v|
|
88
|
-
if
|
89
|
-
bfh[
|
103
|
+
if bfh_map.has_key?(k)
|
104
|
+
bfh[bfh_map[k]] = v
|
90
105
|
else
|
91
106
|
bfh["vial.#{k}"] = v
|
92
107
|
end
|
@@ -95,11 +110,11 @@ module Pipeline
|
|
95
110
|
end
|
96
111
|
|
97
112
|
def valid?
|
98
|
-
incomplete_attrs =
|
113
|
+
incomplete_attrs = REQUIRED_FIELDS.find{|v| send(v).nil?}.nil?
|
99
114
|
end
|
100
115
|
|
101
116
|
def missing_attrs
|
102
|
-
|
117
|
+
REQUIRED_FIELDS.find_all{|a| send(a).nil?}
|
103
118
|
end
|
104
119
|
end # class Specimen < Pipeline::Model::Base
|
105
120
|
|
data/lib/bsi-pipeline/version.rb
CHANGED
data/spec/models_spec.rb
CHANGED
@@ -5,4 +5,14 @@ describe Specimen do
|
|
5
5
|
@specimen = build(:specimen)
|
6
6
|
end
|
7
7
|
|
8
|
+
describe '#new' do
|
9
|
+
it 'returns a new specimen object'
|
10
|
+
context 'when passed :custom_field => Hash' do
|
11
|
+
it 'adds fields and updates bfh_map' do
|
12
|
+
expect(@specimen.add_attributes({:stain_type => 'vial.field_268'})).to respond_to(:stain_type, :stain_type=)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
8
18
|
end
|