class HQMF2JS::Generator::ErbContext
Utility class used to supply a binding to Erb. Contains utility functions used by the erb templates that are used to generate code.
Public Class Methods
new(vars)
click to toggle source
Create a new context @param [Hash] vars a hash of parameter names (String) and values (Object). Each entry is added as an accessor of the new Context
Calls superclass method
# File lib/generator/js.rb, line 19 def initialize(vars) super(vars) end
Public Instance Methods
conjunction_code_for(precondition)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
Get a binding that contains all the instance variables @return [Binding]
# File lib/generator/js.rb, line 25 def get_binding binding end
is_result_criteria(criteria)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Returns the JavaScript generated for a HQMF::Precondition
# 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)
click to toggle source
# 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)
click to toggle source
Returns a Javascript compatable name based on an entity's identifier
# 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)
click to toggle source
# File lib/generator/js.rb, line 159 def patient_api_method(criteria) criteria.patient_api_function end