Module: HealthDataStandards::Export::ViewHelper
- Included in:
- RenderingContext
- Defined in:
- lib/health-data-standards/export/view_helper.rb
Instance Method Summary collapse
- #code_display(entry, options = {}) ⇒ Object
- #convert_field_to_hash(field, codes) ⇒ Object
- #is_bool?(str) ⇒ Boolean
- #is_num?(str) ⇒ Boolean
- #status_code_for(entry) ⇒ Object
- #time_if_not_nil(*args) ⇒ Object
- #value_or_null_flavor(time) ⇒ Object
Instance Method Details
#code_display(entry, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/health-data-standards/export/view_helper.rb', line 4 def code_display(entry, ={}) ['tag_name'] ||= 'code' ['attribute'] ||= :codes ['exclude_null_flavor'] ||= false code_string = nil preferred_code = entry.preferred_code(['preferred_code_sets'], ['attribute'], ['value_set_map']) if preferred_code code_system_oid = HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(preferred_code['code_set']) code_string = "<#{['tag_name']} code=\"#{preferred_code['code']}\" codeSystem=\"#{code_system_oid}\" #{['extra_content']}>" else code_string = "<#{['tag_name']} " code_string += "nullFlavor=\"UNK\" " unless ["exclude_null_flavor"] code_string += "#{['extra_content']}>" end if ["attribute"] == :codes && entry.respond_to?(:translation_codes) code_string += "<originalText>#{ERB::Util.html_escape entry.description}</originalText>" if entry.respond_to?(:description) entry.translation_codes(['preferred_code_sets'], ['value_set_map']).each do |translation| code_string += "<translation code=\"#{translation['code']}\" codeSystem=\"#{HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(translation['code_set'])}\"/>\n" end end code_string += "</#{['tag_name']}>" code_string end |
#convert_field_to_hash(field, codes) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 |
# File 'lib/health-data-standards/export/view_helper.rb', line 68 def convert_field_to_hash(field, codes) if (codes.is_a? Hash) clean_hash = {} if codes['codeSystem'] if codes['title'] clean_hash[codes['codeSystem']] = codes['code'] + " (#{codes['title']})" else clean_hash[codes['codeSystem']] = codes['code'] end elsif codes['_id'] codes.keys.reject {|key| ['_id'].include? key}.each do |hashkey| value = codes[hashkey] if value.nil? clean_hash[hashkey.titleize] = 'none' elsif value.is_a? Hash hash_result = convert_field_to_hash(hashkey, value) if hash_result.is_a? Hash clean_hash[hashkey.titleize] = hash_result.map {|key, value| "#{key}: #{value}"}.join(' ') else clean_hash[hashkey.titleize] = hash_result end elsif value.is_a? Array clean_hash[hashkey.titleize] = value.join(', ') else clean_hash[hashkey.titleize] = convert_field_to_hash(hashkey, value) end end elsif codes['scalar'] return "#{codes['scalar']} #{codes['units']}" else return codes.map {|hashcode_set, hashcodes| "#{hashcode_set}: #{(hashcodes.respond_to? :join) ? hashcodes.join(', ') : hashcodes.to_s}"}.join(' ') end clean_hash else if codes && (field.match(/Time$/) || field.match(/\_time$/)) Entry.time_to_s(codes) else codes.to_s end end end |
#is_bool?(str) ⇒ Boolean
64 65 66 |
# File 'lib/health-data-standards/export/view_helper.rb', line 64 def is_bool?(str) return ["true","false"].include? (str || "").downcase end |
#is_num?(str) ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/health-data-standards/export/view_helper.rb', line 56 def is_num?(str) Float(str || "") rescue ArgumentError false else true end |
#status_code_for(entry) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/health-data-standards/export/view_helper.rb', line 32 def status_code_for(entry) case entry.status.to_s.downcase when 'active' '55561003' when 'inactive' '73425007' when 'resolved' '413322009' end end |
#time_if_not_nil(*args) ⇒ Object
52 53 54 |
# File 'lib/health-data-standards/export/view_helper.rb', line 52 def time_if_not_nil(*args) args.compact.map {|t| Time.at(t).utc}.first end |
#value_or_null_flavor(time) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/health-data-standards/export/view_helper.rb', line 44 def value_or_null_flavor(time) if time return "value='#{Time.at(time).utc.to_formatted_s(:number)}'" else return "nullFlavor='UNK'" end end |