lib/generator/execution.rb in hqmf2js-1.3.0 vs lib/generator/execution.rb in hqmf2js-1.4.0
- old
+ new
@@ -1,10 +1,10 @@
module HQMF2JS
module Generator
class Execution
-
+
def self.quoted_string_array_or_null(arr)
if arr
quoted = arr.map {|e| "\"#{e}\""}
"[#{quoted.join(',')}]"
else
@@ -18,10 +18,11 @@
"function() {
var patient = this;
var effective_date = <%= effective_date %>;
var enable_logging = <%= enable_logging %>;
var enable_rationale = <%= enable_rationale %>;
+ var short_circuit = <%= short_circuit %>;
<% if (!test_id.nil? && test_id.class==Moped::BSON::ObjectId) %>
var test_id = new ObjectId(\"<%= test_id %>\");
<% else %>
var test_id = null;
@@ -30,11 +31,11 @@
hqmfjs = {}
<%= init_js_frameworks %>
hqmfjs.effective_date = effective_date;
hqmfjs.test_id = test_id;
-
+
#{logic(hqmf_document, population_index, options)}
};
"
end
@@ -55,23 +56,29 @@
if check_crosswalk
crosswalk_check = "result = hqmf.SpecificsManager.maintainSpecifics(new Boolean(result.isTrue() && patient_api.validateCodeSystems()), result);"
crosswalk_instrument = "instrumentTrueCrosswalk(hqmfjs);"
end
-
+
"
var patient_api = new hQuery.Patient(patient);
#{gen.to_js(population_index, codes, force_sources)}
-
+
var occurrenceId = #{quoted_string_array_or_null(episode_ids)};
hqmfjs.initializeSpecifics(patient_api, hqmfjs)
-
+
var population = function() {
return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::IPP}, patient_api);
}
+ var stratification = null;
+ if (hqmfjs.#{HQMF::PopulationCriteria::STRAT}) {
+ stratification = function() {
+ return hqmf.SpecificsManager.setIfNull(executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::STRAT}, patient_api));
+ }
+ }
var denominator = function() {
return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::DENOM}, patient_api);
}
var numerator = function() {
return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::NUMER}, patient_api);
@@ -80,17 +87,29 @@
return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::DENEX}, patient_api);
}
var denexcep = function() {
return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::DENEXCEP}, patient_api);
}
+ var numex = function() {
+ return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::NUMEX}, patient_api);
+ }
var msrpopl = function() {
- return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::MSRPOPL}, patient_api);
+ #{msrpopl_function(custom_functions, population_index)}
}
+ var msrpoplex = function() {
+ return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::MSRPOPLEX}, patient_api);
+ }
var observ = function(specific_context) {
#{observation_function(custom_functions, population_index)}
}
-
+
+ var variables = function() {
+ if (Logger.enable_rationale) {
+ return executeIfAvailable(hqmfjs.VARIABLES, patient_api);
+ }
+ }
+
var executeIfAvailable = function(optionalFunction, patient_api) {
if (typeof(optionalFunction)==='function') {
result = optionalFunction(patient_api);
#{crosswalk_check}
return result;
@@ -103,19 +122,22 @@
if (typeof Logger != 'undefined') {
// clear out logger
Logger.logger = [];
Logger.rationale={};
if (typeof short_circuit == 'undefined') short_circuit = true;
-
+
// turn on logging if it is enabled
if (enable_logging || enable_rationale) {
injectLogger(hqmfjs, enable_logging, enable_rationale, short_circuit);
- }
+ } else {
+ Logger.enable_rationale = false;
+ Logger.short_circuit = short_circuit;
+ }
}
try {
- map(patient, population, denominator, numerator, exclusion, denexcep, msrpopl, observ, occurrenceId,#{continuous_variable});
+ map(patient, population, denominator, numerator, exclusion, denexcep, msrpopl, msrpoplex, observ, occurrenceId,#{continuous_variable},stratification, variables, numex);
} catch(err) {
print(err.stack);
throw err;
}
@@ -137,8 +159,16 @@
result
end
+ def self.msrpopl_function(custom_functions, population_index)
+ if (custom_functions && custom_functions[HQMF::PopulationCriteria::MSRPOPL])
+ "return #{custom_functions[HQMF::PopulationCriteria::MSRPOPL]}(patient_api, hqmfjs)"
+ else
+ "return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::MSRPOPL}, patient_api);"
+ end
+ end
+
end
end
-end
\ No newline at end of file
+end