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



42
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
# File 'lib/generator/execution.rb', line 42

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 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 msrpopl = function() {
    return executeIfAvailable(hqmfjs.#{HQMF::PopulationCriteria::MSRPOPL}, patient_api);
  }
  var observ = function(specific_context) {
    #{observation_function(custom_functions, population_index)}
  }
  
  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);
    } 
  }

  try {
    map(patient, population, denominator, numerator, exclusion, denexcep, msrpopl, observ, occurrenceId,#{continuous_variable});
  } 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
# 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 %>;

  <% 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

.observation_function(custom_functions, population_index) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/generator/execution.rb', line 125

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