Class: HQMF2JS::Generator::ErbContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HQMF2JS::Generator::ErbContext
- Defined in:
- lib/generator/js.rb
Overview
Utility class used to supply a binding to Erb. Contains utility functions used by the erb templates that are used to generate code.
Instance Method Summary collapse
- #conjunction_code_for(precondition) ⇒ Object
- #field_library_method(field_name, value = nil) ⇒ Object
- #field_method(field_name) ⇒ Object
-
#get_binding ⇒ Binding
Get a binding that contains all the instance variables.
-
#initialize(vars) ⇒ ErbContext
constructor
Create a new context Each entry is added as an accessor of the new Context.
- #is_result_criteria(criteria) ⇒ Object
- #js_for_bounds(bounds) ⇒ Object
- #js_for_characteristic(criteria) ⇒ Object
- #js_for_code_list(criteria) ⇒ Object
- #js_for_date_bound(criteria) ⇒ Object
- #js_for_derived_data(criteria) ⇒ Object
- #js_for_measure_period(measure_period) ⇒ Object
- #js_for_patient_data(criteria) ⇒ Object
-
#js_for_precondition(precondition, indent, context = false) ⇒ Object
Returns the JavaScript generated for a HQMF::Precondition.
- #js_for_value(value) ⇒ Object
-
#js_name(entity) ⇒ Object
Returns a Javascript compatable name based on an entity’s identifier.
- #patient_api_method(criteria) ⇒ Object
Constructor Details
#initialize(vars) ⇒ ErbContext
Create a new context Each entry is added as an accessor of the new Context
19 20 21 |
# File 'lib/generator/js.rb', line 19 def initialize(vars) super(vars) end |
Instance Method Details
#conjunction_code_for(precondition) ⇒ Object
163 164 165 |
# File 'lib/generator/js.rb', line 163 def conjunction_code_for(precondition) precondition.conjunction_code_with_negation end |
#field_library_method(field_name, value = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generator/js.rb', line 49 def field_library_method(field_name, value=nil) field_type = HQMF::DataCriteria::FIELDS[field_name][:field_type] if field_type == :value 'filterEventsByField' elsif field_type == :timestamp && !value.nil? && value.type == 'IVL_TS' # Handles static date comparisons 'filterEventsByField' elsif field_type == :timestamp 'adjustBoundsForField' elsif field_type == :nested_timestamp 'denormalizeEventsByLocation' elsif field_type == :reference 'filterEventsByReference' end end |
#field_method(field_name) ⇒ Object
45 46 47 |
# File 'lib/generator/js.rb', line 45 def field_method(field_name) HQMF::DataCriteria::FIELDS[field_name][:coded_entry_method].to_s.camelize(:lower) end |
#get_binding ⇒ Binding
Get a binding that contains all the instance variables
25 26 27 |
# File 'lib/generator/js.rb', line 25 def get_binding binding end |
#is_result_criteria(criteria) ⇒ Object
64 65 66 67 |
# File 'lib/generator/js.rb', line 64 def is_result_criteria(criteria) settings = HQMF::DataCriteria.get_settings_for_definition(criteria.definition, criteria.status) settings && settings['sub_category'] == 'result' end |
#js_for_bounds(bounds) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/generator/js.rb', line 103 def js_for_bounds(bounds) if (bounds.respond_to?(:low) && bounds.respond_to?(:high)) type = bounds.type || 'IVL_PQ' "new #{type}(#{js_for_value(bounds.low)}, #{js_for_value(bounds.high)})" elsif bounds.respond_to?(:reference) "hqmfjs.#{bounds.reference.gsub(/\W/, '_')}(patient,initialSpecificContext)" else "#{js_for_value(bounds)}" end end |
#js_for_characteristic(criteria) ⇒ Object
33 34 35 |
# File 'lib/generator/js.rb', line 33 def js_for_characteristic(criteria) HQMF2JS::Generator.render_template('characteristic', {'criteria' => criteria}) end |
#js_for_code_list(criteria) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/generator/js.rb', line 144 def js_for_code_list(criteria) if criteria.inline_code_list criteria.inline_code_list.to_json elsif criteria.code_list_id.nil? "null" else "getCodes(\"#{criteria.code_list_id}\")" end end |
#js_for_date_bound(criteria) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/generator/js.rb', line 114 def js_for_date_bound(criteria) bound = nil if criteria.effective_time if criteria.effective_time.high bound = criteria.effective_time.high elsif criteria.effective_time.low bound = criteria.effective_time.low end elsif criteria.temporal_references # this is a check for age against the measurement period measure_period_reference = criteria.temporal_references.select {|reference| reference.reference and reference.reference.id == HQMF::Document::MEASURE_PERIOD_ID}.first if (measure_period_reference) case measure_period_reference.type when 'SBS','SAS','EBS','EAS' return 'MeasurePeriod.low.asDate()' when 'SBE','SAE','EBE','EAE' return 'MeasurePeriod.high.asDate()' else raise "do not know how to get a date for this type" end end end if bound "#{js_for_value(bound)}.asDate()" else 'MeasurePeriod.high.asDate()' end end |
#js_for_derived_data(criteria) ⇒ Object
41 42 43 |
# File 'lib/generator/js.rb', line 41 def js_for_derived_data(criteria) HQMF2JS::Generator.render_template('derived_data', {'criteria' => criteria}) end |
#js_for_measure_period(measure_period) ⇒ Object
29 30 31 |
# File 'lib/generator/js.rb', line 29 def js_for_measure_period(measure_period) HQMF2JS::Generator.render_template('measure_period', {'measure_period' => measure_period}) end |
#js_for_patient_data(criteria) ⇒ Object
37 38 39 |
# File 'lib/generator/js.rb', line 37 def js_for_patient_data(criteria) HQMF2JS::Generator.render_template('patient_data', {'criteria' => criteria}) end |
#js_for_precondition(precondition, indent, context = false) ⇒ Object
Returns the JavaScript generated for a HQMF::Precondition
155 156 157 |
# File 'lib/generator/js.rb', line 155 def js_for_precondition(precondition, indent, context=false) HQMF2JS::Generator.render_template('precondition', {'doc' => doc, 'precondition' => precondition, 'indent' => indent, 'context' => context}) end |
#js_for_value(value) ⇒ Object
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 |
# File 'lib/generator/js.rb', line 69 def js_for_value(value) if value if value.respond_to?(:derived?) && value.derived? value.expression else if value.type=='CD' if value.code_list_id "new CodeList(getCodes(\"#{value.code_list_id}\"))" else "new CD(\"#{value.code}\", \"#{value.system}\")" end elsif value.type=='PQ' if value.unit != nil "new PQ(#{value.value}, \"#{value.unit}\", #{value.inclusive?})" else "new PQ(#{value.value}, null, #{value.inclusive?})" end elsif value.type=='TS' "new TS(\"#{value.value}\", #{value.inclusive?})" elsif value.type=='ANYNonNull' "new #{value.type}()" elsif value.respond_to?(:unit) && value.unit != nil "new #{value.type}(#{value.value}, \"#{value.unit}\", #{value.inclusive?})" elsif value.respond_to?(:inclusive?) and !value.inclusive?.nil? "new #{value.type}(\"#{value.value}\", null, #{value.inclusive?})" else "new #{value.type}(\"#{value.value}\")" end end else 'null' end end |
#js_name(entity) ⇒ Object
Returns a Javascript compatable name based on an entity’s identifier
168 169 170 171 172 173 |
# File 'lib/generator/js.rb', line 168 def js_name(entity) if !entity.id raise "No identifier for #{entity.to_json}" end entity.id.gsub(/\W/, '_') end |
#patient_api_method(criteria) ⇒ Object
159 160 161 |
# File 'lib/generator/js.rb', line 159 def patient_api_method(criteria) criteria.patient_api_function end |