Class: Result

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

Direct Known Subclasses

Hl7Observation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Result

here will call mappings and check the result correlation



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ruby_astm/result.rb', line 122

def initialize(args={})
	#puts "called initialize result"
	set_name(args)
	set_flags(args)
	set_value(args)
	set_timestamp(args)
	set_dilution(args)
	set_units(args)


=begin
	if args[:line]
		line = args[:line]
		transform_expression = nil
		line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|  
			self.name = lookup_mapping(name)
			self.dilution = dilution
			transform_expression = lookup_transform(name)
		}
		self.value = line.fields[3].strip
		if transform_expression
			self.value = eval(transform_expression)
		end
		self.reference_ranges = line.fields[5].strip
		self.flags = line.fields[6].strip 
		line.fields[12].strip.scan(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hours>\d{2})(?<minutes>\d{2})(?<seconds>\d{2})/) {|year,month,day,hours,minutes,seconds|
			self.timestamp = Time.new(year,month,day,hours,minutes,seconds)
		}
	else
		super
	end
=end

end

Instance Attribute Details

#dilutionObject

Returns the value of attribute dilution.



9
10
11
# File 'lib/ruby_astm/result.rb', line 9

def dilution
  @dilution
end

#flagsObject

Returns the value of attribute flags.



6
7
8
# File 'lib/ruby_astm/result.rb', line 6

def flags
  @flags
end

#machine_nameObject

sometimes we customize the lis code based on the machine which is sending it, so we need this.



12
13
14
# File 'lib/ruby_astm/result.rb', line 12

def machine_name
  @machine_name
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/ruby_astm/result.rb', line 2

def name
  @name
end

#reference_rangesObject

Returns the value of attribute reference_ranges.



8
9
10
# File 'lib/ruby_astm/result.rb', line 8

def reference_ranges
  @reference_ranges
end

#report_nameObject

Returns the value of attribute report_name.



3
4
5
# File 'lib/ruby_astm/result.rb', line 3

def report_name
  @report_name
end

#timestampObject

Returns the value of attribute timestamp.



7
8
9
# File 'lib/ruby_astm/result.rb', line 7

def timestamp
  @timestamp
end

#unitsObject

Returns the value of attribute units.



5
6
7
# File 'lib/ruby_astm/result.rb', line 5

def units
  @units
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/ruby_astm/result.rb', line 4

def value
  @value
end

Instance Method Details

#lookup_mapping(name) ⇒ Object

@return the name defined in the mappings.json file, or the name that wqs passed in.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ruby_astm/result.rb', line 158

def lookup_mapping(name)
	unless $mappings[name].blank?
		unless self.machine_name.blank?
			unless $mappings[name]["MACHINE_SPECIFIC_LIS_CODES"].blank?
				unless $mappings[name]["MACHINE_SPECIFIC_LIS_CODES"][self.machine_name].blank?
					redirect = $mappings[name]["MACHINE_SPECIFIC_LIS_CODES"][self.machine_name]
					unless $mappings[redirect].blank?
						$mappings[redirect]["LIS_CODE"]
					end
				end
			end		
		else
			$mappings[name]["LIS_CODE"]
		end
	else
		name
	end
	#$mappings[name] ? $mappings[name]["LIS_CODE"] : name 
end

#lookup_report_name(name) ⇒ Object



182
183
184
# File 'lib/ruby_astm/result.rb', line 182

def lookup_report_name(name)
	$mappings[name] ? $mappings[name]["REPORT_NAME"] : name
end

#lookup_transform(name) ⇒ Object



178
179
180
# File 'lib/ruby_astm/result.rb', line 178

def lookup_transform(name)
	$mappings[name] ? $mappings[name]["TRANSFORM"] : nil
end

#set_dilution(args) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ruby_astm/result.rb', line 103

def set_dilution(args)
	if line = args[:line]

		unless line.fields[2].blank?
			line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|  
				self.dilution = dilution unless self.dilution
			}
		end

	end
end

#set_flags(args) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/ruby_astm/result.rb', line 69

def set_flags(args)
	if line = args[:line]

		unless line.fields[6].blank?
			self.flags = line.fields[6].strip
		end

	end 
end

#set_machine_name(args) ⇒ Object



115
116
117
# File 'lib/ruby_astm/result.rb', line 115

def set_machine_name(args)
	self.machine_name = args[:machine_name]
end

#set_name(args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_astm/result.rb', line 14

def set_name(args)
	puts "came to set name"
	if line = args[:line]
		puts "line fields is: #{line.fields}"
		unless line.fields[2].blank?
			puts "line fields 2 is:"
			puts line.fields[2]
			line.fields[2].scan(/^\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|  
				
				self.name = lookup_mapping(name)
				
				self.report_name = lookup_report_name(name)

			}
		end

		unless self.name.blank?
			self.name.scan(/(?<test_name>\d+)\/(?<dilution>\d+)\/(?<pre_dilution>[a-zA-Z0-9]+)/) { |test_name,dilution,pre_dilution|

				self.name = lookup_mapping(test_name)

				self.report_name = lookup_report_name(test_name)

				self.dilution = dilution

			}
		end


	end
end

#set_reference_ranges(args) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/ruby_astm/result.rb', line 93

def set_reference_ranges(args)
	if line = args[:line]

		unless line.fields[5].blank?
			self.reference_ranges = line.fields[5].strip
		end

	end
end

#set_timestamp(args) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/ruby_astm/result.rb', line 83

def set_timestamp(args)
	if line = args[:line]
		unless line.fields[12].blank?
			line.fields[12].strip.scan(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hours>\d{2})(?<minutes>\d{2})(?<seconds>\d{2})/) {|year,month,day,hours,minutes,seconds|
				self.timestamp = Time.new(year,month,day,hours,minutes,seconds)
			}
		end
	end
end

#set_units(args) ⇒ Object



79
80
81
# File 'lib/ruby_astm/result.rb', line 79

def set_units(args)

end

#set_value(args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby_astm/result.rb', line 46

def set_value(args)
	if line = args[:line]

		unless line.fields[3].blank?
			self.value = line.fields[3].strip
			self.value.scan(/(?<flag>\d+)\^(?<value>\d?\.?\d+)/) {|flag,value|
				self.value = value
			}
		end
		unless line.fields[2].blank?
			puts "line fields 2 is:"
			puts line.fields[2]
			puts "----------------------------"
			line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|  
				if transform_expression = lookup_transform(name)
					self.value = eval(transform_expression)
				end
			}
		end

	end
end