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) ⇒ 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.
- #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) ⇒ 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
149 150 151 |
# File 'lib/generator/js.rb', line 149 def conjunction_code_for(precondition) precondition.conjunction_code_with_negation end |
#field_library_method(field_name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generator/js.rb', line 49 def field_library_method(field_name) field_type = HQMF::DataCriteria::FIELDS[field_name][:field_type] if field_type == :value 'filterEventsByField' elsif field_type == :timestamp 'adjustBoundsForField' elsif field_type == :nested_timestamp 'denormalizeEventsByLocation' 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 |
#js_for_bounds(bounds) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/generator/js.rb', line 92 def js_for_bounds(bounds) if (bounds.respond_to?(:low) && bounds.respond_to?(:high)) "new IVL_PQ(#{js_for_value(bounds.low)}, #{js_for_value(bounds.high)})" 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
130 131 132 133 134 135 136 137 138 |
# File 'lib/generator/js.rb', line 130 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/generator/js.rb', line 100 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) ⇒ Object
Returns the JavaScript generated for a HQMF::Precondition
141 142 143 |
# File 'lib/generator/js.rb', line 141 def js_for_precondition(precondition, indent) HQMF2JS::Generator.render_template('precondition', {'doc' => doc, 'precondition' => precondition, 'indent' => indent}) end |
#js_for_value(value) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/generator/js.rb', line 60 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=='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
154 155 156 157 158 159 |
# File 'lib/generator/js.rb', line 154 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
145 146 147 |
# File 'lib/generator/js.rb', line 145 def patient_api_method(criteria) criteria.patient_api_function end |