lib/generator/js.rb in hqmf2js-1.2.1 vs lib/generator/js.rb in hqmf2js-1.3.0
- old
+ new
@@ -164,38 +164,51 @@
# Entry point to JavaScript generator
def initialize(doc)
@doc = doc
end
+
+ def self.map_reduce_utils
+ File.read(File.expand_path(File.join('..', '..', "assets",'javascripts','libraries','map_reduce_utils.js'), __FILE__))
+ end
- def to_js(population_index=0, codes=nil)
+ def to_js(population_index=0, codes=nil, force_sources=nil)
population_index ||= 0
population = @doc.populations[population_index]
if codes
oid_dictionary = HQMF2JS::Generator::CodesToJson.hash_to_js(codes)
else
oid_dictionary = "<%= oid_dictionary %>"
end
+ sub_ids = ('a'..'zz').to_a
+ sub_id = @doc.populations.size > 1 ? "'#{sub_ids[population_index]}'" : "null";
+
+
"
// #########################
// ##### DATA ELEMENTS #####
// #########################
+ hqmfjs.nqf_id = '#{@doc.id}';
+ hqmfjs.hqmf_id = '#{@doc.hqmf_id}';
+ hqmfjs.sub_id = #{sub_id};
+ if (typeof(test_id) == 'undefined') hqmfjs.test_id = null;
+
OidDictionary = #{oid_dictionary};
- #{js_for_data_criteria()}
+ #{js_for_data_criteria(force_sources)}
// #########################
// ##### MEASURE LOGIC #####
// #########################
#{js_initialize_specifics(@doc.source_data_criteria)}
// INITIAL PATIENT POPULATION
- #{js_for(population[HQMF::PopulationCriteria::IPP], HQMF::PopulationCriteria::IPP, true)}
+ #{js_for(population[HQMF::PopulationCriteria::IPP], HQMF::PopulationCriteria::IPP)}
// DENOMINATOR
#{js_for(population[HQMF::PopulationCriteria::DENOM], HQMF::PopulationCriteria::DENOM, true)}
// NUMERATOR
#{js_for(population[HQMF::PopulationCriteria::NUMER], HQMF::PopulationCriteria::NUMER)}
#{js_for(population[HQMF::PopulationCriteria::DENEX], HQMF::PopulationCriteria::DENEX)}
@@ -234,44 +247,56 @@
"hqmfjs.#{type} = function(patient) { return new Boolean(#{when_not_found}); }"
end
end
# Generate JS for a HQMF2::DataCriteria
- def js_for_data_criteria
- HQMF2JS::Generator.render_template('data_criteria', {'all_criteria' => @doc.specific_occurrence_source_data_criteria.concat(@doc.all_data_criteria), 'measure_period' => @doc.measure_period})
+ def js_for_data_criteria(force_sources=nil)
+ HQMF2JS::Generator.render_template('data_criteria', {'all_criteria' => @doc.specific_occurrence_source_data_criteria(force_sources).concat(@doc.all_data_criteria), 'measure_period' => @doc.measure_period})
end
- def self.library_functions(check_crosswalk=false)
+ def self.library_functions(check_crosswalk=false, include_underscore=true)
ctx = Sprockets::Environment.new(File.expand_path("../../..", __FILE__))
Tilt::CoffeeScriptTemplate.default_bare = true
ctx.append_path "app/assets/javascripts"
- libraries = ["// #########################\n// ###### Underscore.js #######\n// #######################\n",
- ctx.find_asset('underscore').to_s,
- "// #########################\n// ###### PATIENT API #######\n// #########################\n",
- HqueryPatientApi::Generator.patient_api_javascript.to_s,
- "// #########################\n// ## SPECIFIC OCCURRENCES ##\n// #########################\n",
- ctx.find_asset('specifics').to_s,
- "// #########################\n// ### LIBRARY FUNCTIONS ####\n// #########################\n",
- ctx.find_asset('hqmf_util').to_s,
- "// #########################\n// ### PATIENT EXTENSION ####\n// #########################\n",
- ctx.find_asset('patient_api_extension').to_s,
- "// #########################\n// ## CUSTOM CALCULATIONS ###\n// #########################\n",
- ctx.find_asset('custom_calculations').to_s,
- "// #########################\n// ##### LOGGING UTILS ######\n// #########################\n",
- ctx.find_asset('logging_utils').to_s]
+ libraries = []
+ if include_underscore
+ libraries += ["// #########################\n// ###### Underscore.js #######\n// #######################\n",
+ ctx.find_asset('underscore').to_s]
+ end
+
+ libraries += ["// #########################\n// ###### PATIENT API #######\n// #########################\n",
+ HqueryPatientApi::Generator.patient_api_javascript.to_s,
+ "// #########################\n// ## SPECIFIC OCCURRENCES ##\n// #########################\n",
+ ctx.find_asset('specifics').to_s,
+ "// #########################\n// ### LIBRARY FUNCTIONS ####\n// #########################\n",
+ ctx.find_asset('hqmf_util').to_s,
+ "// #########################\n// ### PATIENT EXTENSION ####\n// #########################\n",
+ ctx.find_asset('patient_api_extension').to_s,
+ "// #########################\n// ## CUSTOM CALCULATIONS ###\n// #########################\n",
+ ctx.find_asset('custom_calculations').to_s,
+ "// #########################\n// ##### LOGGING UTILS ######\n// #########################\n",
+ ctx.find_asset('logging_utils').to_s]
+
# check for code set crosswalks
if (check_crosswalk)
libraries += ["// #########################\n// ##### CROSSWALK EXTENSION ######\n// #########################\n",
ctx.find_asset('crosswalk').to_s]
end
libraries.join("\n")
end
+ # Allow crosswalk functionality to be loaded separately from main JS libraries
+ def self.crosswalk_functions
+ ctx = Sprockets::Environment.new(File.expand_path("../../..", __FILE__))
+ Tilt::CoffeeScriptTemplate.default_bare = true
+ ctx.append_path "app/assets/javascripts"
+ ctx.find_asset('crosswalk').to_s
+ end
end
# Simple class to issue monotonically increasing integer identifiers
class Counter
def initialize
@@ -291,6 +316,6 @@
# Singleton to keep a count of template identifiers
class TemplateCounter < Counter
include Singleton
end
end
-end
\ No newline at end of file
+end