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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ruby_astm/result.rb', line 86

def initialize(args)
	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

#dilution ⇒ Object

Returns the value of attribute dilution.



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

def dilution
  @dilution
end

#flags ⇒ Object

Returns the value of attribute flags.



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

def flags
  @flags
end

#name ⇒ Object

Returns the value of attribute name.



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

def name
  @name
end

#reference_ranges ⇒ Object

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_name ⇒ Object

Returns the value of attribute report_name.



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

def report_name
  @report_name
end

#timestamp ⇒ Object

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

#units ⇒ Object

Returns the value of attribute units.



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

def units
  @units
end

#value ⇒ Object

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.



119
120
121
# File 'lib/ruby_astm/result.rb', line 119

def lookup_mapping(name)
	$mappings[name] ? $mappings[name]["LIS_CODE"] : name 
end

#lookup_report_name(name) ⇒ Object



127
128
129
# File 'lib/ruby_astm/result.rb', line 127

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

#lookup_transform(name) ⇒ Object



123
124
125
# File 'lib/ruby_astm/result.rb', line 123

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

#set_dilution(args) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/ruby_astm/result.rb', line 75

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

#set_flags(args) ⇒ Object



49
50
51
52
53
# File 'lib/ruby_astm/result.rb', line 49

def set_flags(args)
	if line = args[:line]
		self.flags = line.fields[6].strip
	end 
end

#set_name(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_astm/result.rb', line 11

def set_name(args)
	if line = args[:line]
		
		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)

		}

		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

#set_reference_ranges(args) ⇒ Object



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

def set_reference_ranges(args)
	if line = args[:line]
		self.reference_ranges = line.fields[5].strip
	end
end

#set_timestamp(args) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/ruby_astm/result.rb', line 59

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



55
56
57
# File 'lib/ruby_astm/result.rb', line 55

def set_units(args)

end

#set_value(args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ruby_astm/result.rb', line 35

def set_value(args)
	if line = args[:line]
		self.value = line.fields[3].strip
		self.value.scan(/(?<flag>\d+)\^(?<value>\d?\.?\d+)/) {|flag,value|
			self.value = value
		}
		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