Skip to content

Commit

Permalink
vital signs import from remote host, refresh link on record page
Browse files Browse the repository at this point in the history
  • Loading branch information
ssayer committed Aug 28, 2012
1 parent 8124be6 commit dac87a4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
32 changes: 11 additions & 21 deletions app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def latest_matching_vital(record, name)
name.downcase!
vitals = record.get_recent_vitals
record.vital_signs.each do |result|
if result.description.downcase.start_with?(name)
if result.description && result.description.downcase.start_with?(name)
return show_value result.values.first
end
end
Expand All @@ -40,28 +40,18 @@ def most_recent_vital_date(record)
end
end

def show_values(values)
show_value(values.first)
end

# Takes the value portion of a record and formats it
def show_value(value, low = -1E99, high = 1E99)
return "" unless value
s = value.scalar
units = value.units
if s.class == Fixnum || s.class == Float
n = s;
n = n.round(2) if n.class == Float
s = n.to_s;
elsif s =~ /[+-]?[[:digit:]]+\.?[[:digit:]]*/
n = s.to_f.round(2)
s = n.to_s
else
n = 0
end
return "" unless s
oor = ""
oor = " out-of-range-value" if n < low || n > high
u = ""
u = "&nbsp;(" + units + ")" if units
return ("<span class='lab_value" + oor + "'>" + s + u + "</span>").html_safe
return "" unless value && value.scalar
scalar = value.scalar
output = scalar.is_a?(Integer) ? scalar.to_s : number_with_precision(scalar, precision: 2)
output << " (#{value.units})" if value.units
"<span class='lab_value'>#{output}</span>"
end


end
end
14 changes: 11 additions & 3 deletions app/views/records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</td>
<td>
<%= render :layout => "section", :locals => {:record => @record, :section => :results, :earliest => earliest} do |x| %>
<%= labeled_field(x['description'] + show_value(x['value']), date(x['time'])) %>
<%= labeled_field(x['description'] + show_values(x.values), date(x['time'])) %>
<% end %>
</td>
</tr>
Expand All @@ -48,6 +48,15 @@
<%= labeled_field x['description'], date(x['time']) %>
<% end %>
</td>


</tr>
<tr>
<td>
<%= render :layout => "section", :locals => {:record => @record, :section => :vital_signs, :earliest => earliest} do |x| %>
<%= labeled_field("#{x['description']}#{show_values(x.values)}", date(x['time'])) %>
<% end %>
</td>
</tr>
<tr>
<td>
Expand All @@ -59,10 +68,9 @@
<div class='history_link'><%= link_to(('<<&nbsp;Past ' + I18n.t("section.vital_signs")).html_safe, record_path(@record.medical_record_number) + "/vital_signs") %></div>
</td>
<td>

</td>
</tr>
</table>

<div class="footer">Last updated on 11/11/11 by <a href='link'>Dr Rick Jones</a></div>
<div class="footer">Last updated on <%= @record.updated_at.strftime("%m/%d/%Y") %> by <a href='link'>Dr Rick Jones</a> (<%=link_to "Refresh", record_path(@record.medical_record_number), method: :get %>)</div>
</div>
3 changes: 2 additions & 1 deletion lib/tatrc/vital_signs_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def import(xml_string)
vital_signs_xml.map do |vs_el|
vs = VitalSign.new
code = extract_code(vs_el, './gc32:resultType')
vs.description = code['name']
vs.add_code(code['code'], code['codeSystem'])
set_interval(vs, vs_el)
set_values(vs, vs_el)
Expand All @@ -21,7 +22,7 @@ def extract_code(vs_element, xpath)
code_element = vs_element.at_xpath(xpath)
return unless code_element
{'code' => code_element['code'],
'codeSystemOid' => code_element['codeSystem'],
'name' => code_element['displayName'],
'codeSystem' => HealthDataStandards::Util::CodeSystemHelper.code_system_for(code_element['codeSystem'])}
end

Expand Down
6 changes: 3 additions & 3 deletions test/unit/helpers/record_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RecordHelperTest < ActionView::TestCase
vs3 = FactoryGirl.create(:lab_result)
rec.vital_signs.concat([ vs1, vs2, vs3 ])
v = latest_matching_vital rec, 'ldl'
assert_equal "<span class='lab_value'>127&nbsp;(mg/dL)</span>", v
assert_equal "<span class='lab_value'>127 (mg/dL)</span>", v

v = latest_matching_vital rec, 'xyz'
assert_equal "", v
Expand All @@ -59,7 +59,7 @@ class RecordHelperTest < ActionView::TestCase

test "format a value" do
r = FactoryGirl.create(:lab_result)
assert_equal "<span class='lab_value'>127&nbsp;(mg/dL)</span>", show_value(r.values.first)
assert_equal "<span class='lab_value'>127 (mg/dL)</span>", show_value(r.values.first)
end

test "format a value 2" do
Expand All @@ -78,4 +78,4 @@ class RecordHelperTest < ActionView::TestCase
assert_equal "", show_value(OpenStruct.new())
end

end
end
1 change: 1 addition & 0 deletions test/unit/vital_signs_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_import
assert_equal 6, vital_signs.size
vs = vital_signs.first
assert_equal "8480-6", vs.codes["LOINC"].first
assert_equal "Systolic BP", vs.description
assert_equal 115.0, vs.values.first.scalar
assert_equal "mm[Hg]", vs.values.first['units']
end
Expand Down

0 comments on commit dac87a4

Please sign in to comment.