Module: HealthDataStandards::Export::ViewHelper
- Included in:
- RenderingContext
- Defined in:
- lib/health-data-standards/export/view_helper.rb
Instance Method Summary collapse
- #clean_hash_code_system(codes) ⇒ Object
- #clean_hash_id(codes, hashkey) ⇒ Object
- #code_display(entry, options = {}) ⇒ Object
- #convert_field_to_hash(field, codes) ⇒ Object
- #create_code_display_string(entry, preferred_code, options = {}) ⇒ Object
- #create_code_string(entry, preferred_code, options = {}) ⇒ Object
- #create_laterality_code_string(entry, options = {}) ⇒ Object
- #create_translations_code_string(entry, options = {}) ⇒ Object
- #dose_quantity(codes, dose) ⇒ Object
- #fulfillment_quantity(codes, fulfillmentHistory, dose) ⇒ Object
- #identifier_for(obj) ⇒ Object
- #is_bool?(str) ⇒ Boolean
- #is_num?(str) ⇒ Boolean
- #status_code_for(entry) ⇒ Object
- #time_if_not_nil(*args) ⇒ Object
- #ucum_for_dose_quantity(unit) ⇒ Object
- #value_or_null_flavor(time) ⇒ Object
Instance Method Details
#clean_hash_code_system(codes) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/health-data-standards/export/view_helper.rb', line 173 def clean_hash_code_system(codes) if codes['title'] return codes['code'] + " (#{codes['title']})" else return codes['code'] end end |
#clean_hash_id(codes, hashkey) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/health-data-standards/export/view_helper.rb', line 181 def clean_hash_id(codes, hashkey) value = codes[hashkey] if value.nil? return 'none' elsif value.is_a? Hash hash_result = convert_field_to_hash(hashkey, value) if hash_result.is_a? Hash return hash_result.map {|key, value| "#{key}: #{value}"}.join(' ') else return hash_result end elsif value.is_a? Array return value.join(', ') else return convert_field_to_hash(hashkey, value) end end |
#code_display(entry, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/health-data-standards/export/view_helper.rb', line 4 def code_display(entry, ={}) ['tag_name'] ||= 'code' ['attribute'] ||= :codes ['exclude_null_flavor'] ||= false # allowing wild card matching of any code system for generic templates # valueset filtering should filter out a decent code # TODO: Can we add nil? logic to the function? Make it so that we don't have to include the preferred_code_sets['*'] if we want all? pcs = if ['preferred_code_sets'] && ['preferred_code_sets'].index("*") # all of the code_systems that we know about HealthDataStandards::Util::CodeSystemHelper::CODE_SYSTEMS.values | HealthDataStandards::Util::CodeSystemHelper::CODE_SYSTEM_ALIASES.keys else ['preferred_code_sets'] end create_code_string(entry, entry.preferred_code(pcs, ['attribute'], ['value_set_map']), ) end |
#convert_field_to_hash(field, codes) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/health-data-standards/export/view_helper.rb', line 137 def convert_field_to_hash(field, codes) if codes.is_a? Array return codes.collect{ |code| convert_field_to_hash(field, convert_field_to_hash(field, code))}.join("<br>") end if (codes.is_a? Hash) clean_hash = {} if codes['codeSystem'] clean_hash[codes['codeSystem']] = clean_hash_code_system(codes) elsif codes['_id'] codes.keys.reject {|key| ['_id'].include? key}.each do |hashkey| clean_hash[hashkey.titleize] = clean_hash_id(codes, hashkey) end elsif codes['scalar'] return "#{codes['scalar']} #{codes['units']}" else return codes.map do |hashcode_set, hashcodes| if hashcodes.is_a? Hash "#{hashcode_set}: #{convert_field_to_hash(hashcode_set, hashcodes)}" else "#{hashcode_set}: #{(hashcodes.respond_to? :join) ? hashcodes.join(', ') : hashcodes.to_s}" end end.join(' ') end clean_hash else if codes && (field.match(/Time$/) || field.match(/\_time$/) || field.match(/Date$/)) Entry.time_to_s(codes) else codes.to_s end end end |
#create_code_display_string(entry, preferred_code, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/health-data-standards/export/view_helper.rb', line 37 def create_code_display_string(entry, preferred_code, ={}) code_string = nil if entry['negationInd'] == true code_string = "<#{options['tag_name']} nullFlavor=\"NA\" #{options['extra_content']}/>" elsif preferred_code code_system_oid = HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(preferred_code['code_set']) code_string = "<#{options['tag_name']} code=\"#{preferred_code['code']}\" codeSystem=\"#{code_system_oid}\" #{options['extra_content']}>" else code_string = "<#{options['tag_name']} " code_string += "nullFlavor=\"UNK\" " unless ["exclude_null_flavor"] code_string += "#{options['extra_content']}>" end code_string end |
#create_code_string(entry, preferred_code, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/health-data-standards/export/view_helper.rb', line 20 def create_code_string(entry, preferred_code, ={}) code_string = create_code_display_string(entry, preferred_code, ) unless entry['negationInd'] == true code_string += "<originalText>#{ERB::Util.html_escape entry.description}</originalText>" if entry.respond_to?(:description) code_string += create_laterality_code_string(entry, ) if ["laterality"] code_string += create_translations_code_string(entry, ) if ["attribute"] == :codes && entry.respond_to?(:translation_codes) code_string += "</#{options['tag_name']}>" end code_string end |
#create_laterality_code_string(entry, options = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/health-data-standards/export/view_helper.rb', line 52 def create_laterality_code_string(entry, ={}) code_string = "\n<!-- QDM Attribute: Laterality -->\n<qualifier>\n<name code='182353008' codeSystem='2.16.840.1.113883.6.96' displayName='Side' />\n" code_string += "<value xsi:type='CD' code='#{options['laterality']['code']}' displayName='#{options['laterality']['title']}' sdtc:valueSet='#{oid_for_code(entry.laterality,field_oids['LATERALITY'])}' codeSystem='#{HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(options['laterality']['code_system'])}'/>\n</qualifier>\n" end |
#create_translations_code_string(entry, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/health-data-standards/export/view_helper.rb', line 58 def create_translations_code_string(entry, ={}) code_string = '' 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 code_string end |
#dose_quantity(codes, dose) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/health-data-standards/export/view_helper.rb', line 94 def dose_quantity(codes, dose) if (codes["RxNorm"].present? || codes["CVX"].present?) if dose['unit'].present? return "value='1' unit='#{ucum_for_dose_quantity(dose['unit'])}'" else return "value='1'" end else return "value='#{dose['scalar']}' unit='#{dose['units']}'" end end |
#fulfillment_quantity(codes, fulfillmentHistory, dose) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/health-data-standards/export/view_helper.rb', line 77 def fulfillment_quantity(codes, fulfillmentHistory, dose) if (codes["RxNorm"].present?) doses = (fulfillmentHistory.quantity_dispensed['value'].to_f / dose['value'].to_f ).to_i return "value='#{doses}' unit='1'" else return "value='#{fulfillmentHistory.quantity_dispensed['value']}' unit='#{fulfillmentHistory.quantity_dispensed['unit']}'" end end |
#identifier_for(obj) ⇒ Object
133 134 135 |
# File 'lib/health-data-standards/export/view_helper.rb', line 133 def identifier_for(obj) Digest::MD5.hexdigest(obj.to_s).upcase end |
#is_bool?(str) ⇒ Boolean
129 130 131 |
# File 'lib/health-data-standards/export/view_helper.rb', line 129 def is_bool?(str) return ["true","false"].include? (str || "").downcase end |
#is_num?(str) ⇒ Boolean
121 122 123 124 125 126 127 |
# File 'lib/health-data-standards/export/view_helper.rb', line 121 def is_num?(str) Float(str || "") rescue ArgumentError false else true end |
#status_code_for(entry) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/health-data-standards/export/view_helper.rb', line 66 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
117 118 119 |
# File 'lib/health-data-standards/export/view_helper.rb', line 117 def time_if_not_nil(*args) args.compact.map {|t| Time.at(t).utc}.first end |
#ucum_for_dose_quantity(unit) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/health-data-standards/export/view_helper.rb', line 106 def ucum_for_dose_quantity(unit) case unit when 'capsule(s)' '{Capsule}' when 'tablet(s)' '{tbl}' else unit end end |
#value_or_null_flavor(time) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/health-data-standards/export/view_helper.rb', line 86 def value_or_null_flavor(time) if time return "value='#{Time.at(time).utc.to_formatted_s(:number)}'" else return "nullFlavor='UNK'" end end |