Class: HQMF2::Generator::ErbContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HQMF2::Generator::ErbContext
- Defined in:
- lib/hqmf-generator/hqmf-generator.rb
Overview
Utility class used to supply a binding to Erb. Contains utility functions used by the erb templates that are used to generate the HQMF document.
Instance Method Summary collapse
- #code_for_characteristic(characteristic) ⇒ Object
- #data_criteria_template_name(data_criteria) ⇒ Object
- #element_name_prefix(data_criteria) ⇒ Object
-
#get_binding ⇒ Binding
Get a binding that contains all the instance variables.
-
#initialize(vars) ⇒ ErbContext
constructor
A new instance of ErbContext.
- #oid_for_characteristic(characteristic) ⇒ Object
- #oid_for_name(code_system_name) ⇒ Object
- #population_element_prefix(population_criteria_code) ⇒ Object
- #reference_element_name(id) ⇒ Object
- #reference_type_name(id) ⇒ Object
- #section_name(data_criteria) ⇒ Object
- #xml_for_attribute(attribute) ⇒ Object
- #xml_for_code(criteria, element_name = 'code', include_type = true) ⇒ Object
- #xml_for_data_criteria(data_criteria, is_source_data_criteria) ⇒ Object
- #xml_for_derivation(data_criteria) ⇒ Object
- #xml_for_description(data_criteria) ⇒ Object
- #xml_for_effective_time(data_criteria) ⇒ Object
- #xml_for_fields(criteria) ⇒ Object
- #xml_for_population_criteria(population, criteria_id) ⇒ Object
- #xml_for_precondition(precondition) ⇒ Object
- #xml_for_reason(data_criteria) ⇒ Object
- #xml_for_reference(reference) ⇒ Object
- #xml_for_reference_id(id) ⇒ Object
- #xml_for_subsets(data_criteria) ⇒ Object
- #xml_for_template(data_criteria, is_source_data_criteria) ⇒ Object
- #xml_for_temporal_references(criteria) ⇒ Object
- #xml_for_value(value, element_name = 'value', include_type = true) ⇒ Object
Constructor Details
#initialize(vars) ⇒ ErbContext
Returns a new instance of ErbContext.
26 27 28 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 26 def initialize(vars) super(vars) end |
Instance Method Details
#code_for_characteristic(characteristic) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 197 def code_for_characteristic(characteristic) case characteristic when :birthtime '21112-8' when :age '424144002' when :gender '263495000' when :languages '102902016' when :maritalStatus '125680007' when :race '103579009' else raise "Unknown demographic code [#{characteristic}]" end end |
#data_criteria_template_name(data_criteria) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 225 def data_criteria_template_name(data_criteria) case data_criteria.definition when 'diagnosis', 'diagnosis_family_history' 'condition_criteria' when 'encounter' 'encounter_criteria' when 'procedure', 'risk_category_assessment', 'physical_exam', 'communication_from_patient_to_provider', 'communication_from_provider_to_provider', 'device', 'diagnostic_study', 'intervention' if data_criteria.value.nil? 'procedure_criteria' else 'observation_criteria' end when 'medication' case data_criteria.status when 'dispensed', 'ordered' 'supply_criteria' else # active or administered 'substance_criteria' end when 'patient_characteristic', 'patient_characteristic_birthdate', 'patient_characteristic_clinical_trial_participant', 'patient_characteristic_expired', 'patient_characteristic_gender', 'patient_characteristic_age', 'patient_characteristic_languages', 'patient_characteristic_marital_status', 'patient_characteristic_race' 'characteristic_criteria' when 'variable' 'variable_criteria' else 'observation_criteria' end end |
#element_name_prefix(data_criteria) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 257 def element_name_prefix(data_criteria) type = data_criteria ? data_criteria.type : :observation case type when :encounters 'encounter' when :procedures 'procedure' when :medications, :allMedications 'substanceAdministration' when :medication_supply 'supply' else 'observation' end end |
#get_binding ⇒ Binding
Get a binding that contains all the instance variables
32 33 34 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 32 def get_binding binding end |
#oid_for_characteristic(characteristic) ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 216 def oid_for_characteristic(characteristic) case characteristic when :birthtime '2.16.840.1.113883.6.1' else '2.16.840.1.113883.6.96' end end |
#oid_for_name(code_system_name) ⇒ Object
163 164 165 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 163 def oid_for_name(code_system_name) HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(code_system_name) end |
#population_element_prefix(population_criteria_code) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 273 def population_element_prefix(population_criteria_code) case population_criteria_code when HQMF::PopulationCriteria::IPP 'patientPopulation' when HQMF::PopulationCriteria::DENOM 'denominator' when HQMF::PopulationCriteria::NUMER 'numerator' when HQMF::PopulationCriteria::DENEXCEP 'denominatorException' when HQMF::PopulationCriteria::DENEX 'denominatorExclusion' else raise "Unknown population criteria type #{population_criteria_code}" end end |
#reference_element_name(id) ⇒ Object
167 168 169 170 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 167 def reference_element_name(id) referenced_criteria = doc.data_criteria(id) element_name_prefix(referenced_criteria) end |
#reference_type_name(id) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 172 def reference_type_name(id) referenced_criteria = doc.data_criteria(id) type = nil if referenced_criteria type = referenced_criteria.type elsif id=="MeasurePeriod" type = :observation end if !type raise "No data criteria with ID: #{id}" end case type when :encounters 'ENC' when :procedures 'PROC' when :medications, :allMedications 'SBADM' when :medication_supply 'SPLY' else 'OBS' end end |
#section_name(data_criteria) ⇒ Object
253 254 255 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 253 def section_name(data_criteria) data_criteria.definition.to_s end |
#xml_for_attribute(attribute) ⇒ Object
45 46 47 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 45 def xml_for_attribute(attribute) HQMF2::Generator.render_template('attribute', {'attribute' => attribute}) end |
#xml_for_code(criteria, element_name = 'code', include_type = true) ⇒ Object
70 71 72 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 70 def xml_for_code(criteria, element_name='code', include_type=true) HQMF2::Generator.render_template('code', {'doc' => doc, 'criteria' => criteria, 'name' => element_name, 'include_type' => include_type}) end |
#xml_for_data_criteria(data_criteria, is_source_data_criteria) ⇒ Object
140 141 142 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 140 def xml_for_data_criteria(data_criteria, is_source_data_criteria) HQMF2::Generator.render_template(data_criteria_template_name(data_criteria), {'doc' => doc, 'criteria' => data_criteria, 'is_source_data_criteria' => is_source_data_criteria}) end |
#xml_for_derivation(data_criteria) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 74 def xml_for_derivation(data_criteria) xml = '' if data_criteria.derivation_operator xml = HQMF2::Generator.render_template('derivation', {'doc' => doc, 'criteria' => data_criteria}) end xml end |
#xml_for_description(data_criteria) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 118 def xml_for_description(data_criteria) xml = '' if data_criteria.description xml = HQMF2::Generator.render_template('description', {'text' => data_criteria.description}) end xml end |
#xml_for_effective_time(data_criteria) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 82 def xml_for_effective_time(data_criteria) xml = '' if data_criteria.effective_time xml = HQMF2::Generator.render_template('effective_time', {'doc' => doc, 'effective_time' => data_criteria.effective_time}) end xml end |
#xml_for_fields(criteria) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 49 def xml_for_fields(criteria) fields = [] if criteria.field_values criteria.field_values.each_pair do |key, value| details = HQMF::DataCriteria::FIELDS[key] details[:code_system_name] = HealthDataStandards::Util::CodeSystemHelper.code_system_for(details[:code_system]) fields << HQMF2::Generator.render_template('field', {'details' => details, 'value' => value}) end end if criteria.specific_occurrence fields << HQMF2::Generator.render_template('specific_occurrence', {'source_criteria_id' => criteria.source_data_criteria, 'type' => criteria.specific_occurrence_const, 'id' => criteria.specific_occurrence}) elsif criteria.source_data_criteria fields << HQMF2::Generator.render_template('source', {'source_criteria_id' => criteria.source_data_criteria}) end fields.join end |
#xml_for_population_criteria(population, criteria_id) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 144 def xml_for_population_criteria(population, criteria_id) xml = '' population_criteria = doc.population_criteria(population[criteria_id]) if population_criteria xml = HQMF2::Generator.render_template('population_criteria', {'doc' => doc, 'population' => population, 'criteria_id' => criteria_id, 'population_criteria' => population_criteria}) end xml end |
#xml_for_precondition(precondition) ⇒ Object
136 137 138 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 136 def xml_for_precondition(precondition) HQMF2::Generator.render_template('precondition', {'doc' => doc, 'precondition' => precondition}) end |
#xml_for_reason(data_criteria) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 90 def xml_for_reason(data_criteria) xml = '' if data_criteria.negation && data_criteria.negation_code_list_id xml = HQMF2::Generator.render_template('reason', {'doc' => doc, 'code_list_id' => data_criteria.negation_code_list_id}) end xml end |
#xml_for_reference(reference) ⇒ Object
41 42 43 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 41 def xml_for_reference(reference) HQMF2::Generator.render_template('reference', {'doc' => doc, 'reference' => reference}) end |
#xml_for_reference_id(id) ⇒ Object
36 37 38 39 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 36 def xml_for_reference_id(id) reference = HQMF::Reference.new(id) xml_for_reference(reference) end |
#xml_for_subsets(data_criteria) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 126 def xml_for_subsets(data_criteria) subsets_xml = [] if data_criteria.subset_operators subsets_xml = data_criteria.subset_operators.collect do |operator| HQMF2::Generator.render_template('subset', {'doc' => doc, 'subset' => operator, 'criteria' => data_criteria}) end end subsets_xml.join() end |
#xml_for_template(data_criteria, is_source_data_criteria) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 98 def xml_for_template(data_criteria, is_source_data_criteria) xml = '' templates = [] # Add a template ID if one is defined for this data criteria template_id = HQMF::DataCriteria.template_id_for_definition(data_criteria.definition, data_criteria.status, data_criteria.negation) if template_id templates << {:id => template_id, :title => HQMF::DataCriteria.title_for_template_id(template_id)} end # Add our own template id if this is a source data criteria from HQMF V1. Source # data criteria are the 'raw' HQMF V1 data criteria before any restrictions are applied # they are only used for negating specific occurrences if is_source_data_criteria templates << {:id => HQMF::DataCriteria::SOURCE_DATA_CRITERIA_TEMPLATE_ID, :title => HQMF::DataCriteria::SOURCE_DATA_CRITERIA_TEMPLATE_TITLE} end if templates.length > 0 xml = HQMF2::Generator.render_template('template_id', {'templates' => templates}) end xml end |
#xml_for_temporal_references(criteria) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 153 def xml_for_temporal_references(criteria) refs = [] if criteria.temporal_references refs = criteria.temporal_references.collect do |reference| HQMF2::Generator.render_template('temporal_relationship', {'doc' => doc, 'relationship' => reference}) end end refs.join end |
#xml_for_value(value, element_name = 'value', include_type = true) ⇒ Object
66 67 68 |
# File 'lib/hqmf-generator/hqmf-generator.rb', line 66 def xml_for_value(value, element_name='value', include_type=true) HQMF2::Generator.render_template('value', {'doc' => doc, 'value' => value, 'name' => element_name, 'include_type' => include_type}) end |