Class: HQMF2JS::Generator::Execution

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/execution.rb

Class Method Summary collapse

Class Method Details

.logic(hqmf_document, population_index = 0, options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
91
92
93
94
95
96
97
98
99
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/generator/execution.rb', line 43

def self.logic(hqmf_document, population_index=0, options)

  value_sets=options[:value_sets]
  episode_ids=options[:episode_ids]
  continuous_variable=options[:continuous_variable]
  force_sources=options[:force_sources]
  custom_functions=options[:custom_functions]
  check_crosswalk=options[:check_crosswalk]

  gen = HQMF2JS::Generator::JS.new(hqmf_document)
  codes = HQMF2JS::Generator::CodesToJson.from_value_sets(value_sets) if value_sets
  force_sources = force_sources

  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);
  }
  var exclusion = function() {
    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() {
    #{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;
    } else {
      return false;
    }
  }

  #{crosswalk_instrument}
  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, msrpoplex, observ, occurrenceId,#{continuous_variable},stratification, variables, numex);
  } catch(err) {
    print(err.stack);
    throw err;
  }

  "
end

.measure_js(hqmf_document, population_index, options) ⇒ Object

Note that the JS returned by this function is not included when using the in-browser debugger. See app/views/measures/debug.js.erb for the in-browser equivalent.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generator/execution.rb', line 17

def self.measure_js(hqmf_document, population_index, options)
  "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;
  <% end %>

    hqmfjs = {}
    <%= init_js_frameworks %>

    hqmfjs.effective_date = effective_date;
    hqmfjs.test_id = test_id;

    #{logic(hqmf_document, population_index, options)}
  };
  "
end

.msrpopl_function(custom_functions, population_index) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/generator/execution.rb', line 164

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

.observation_function(custom_functions, population_index) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/generator/execution.rb', line 147

def self.observation_function(custom_functions, population_index)

  result = "
    var observFunc = hqmfjs.#{HQMF::PopulationCriteria::OBSERV}
    if (typeof(observFunc)==='function')
      return observFunc(patient_api, specific_context);
    else
      return [];"

  if (custom_functions && custom_functions[HQMF::PopulationCriteria::OBSERV])
    result = "return #{custom_functions[HQMF::PopulationCriteria::OBSERV]}(patient_api, hqmfjs)"
  end

  result

end

.quoted_string_array_or_null(arr) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/generator/execution.rb', line 6

def self.quoted_string_array_or_null(arr)
  if arr
    quoted = arr.map {|e| "\"#{e}\""}
    "[#{quoted.join(',')}]"
  else
    "null"
  end
end