lib/measures/loading/cql_loader.rb in bonnie_bundler-2.0.3 vs lib/measures/loading/cql_loader.rb in bonnie_bundler-2.1.0
- old
+ new
@@ -20,11 +20,11 @@
false
end
end
end
- def self.load_mat_cql_exports(user, zip_file, out_dir, measure_details, vsac_user, vsac_password, overwrite_valuesets=false, cache=false, includeDraft=false, ticket_granting_ticket=nil)
+ def self.load_mat_cql_exports(user, zip_file, out_dir, measure_details, vsac_options, vsac_ticket_granting_ticket)
measure = nil
cql = nil
hqmf_path = nil
# Grabs the cql file contents, the elm_xml contents, elm_json contents and the hqmf file path
files = get_files_from_zip(zip_file, out_dir)
@@ -33,11 +33,11 @@
hqmf_model = Measures::Loader.parse_hqmf_model(files[:HQMF_XML_PATH])
# Get main measure from hqmf parser
main_cql_library = hqmf_model.cql_measure_library
- cql_artifacts = process_cql(files, main_cql_library, user, vsac_user, vsac_password, overwrite_valuesets, cache, includeDraft, ticket_granting_ticket, hqmf_model.hqmf_set_id)
+ cql_artifacts = process_cql(files, main_cql_library, user, vsac_options, vsac_ticket_granting_ticket, hqmf_model.hqmf_set_id)
# Create CQL Measure
hqmf_model.backfill_patient_characteristics_with_codes(cql_artifacts[:all_codes_and_code_names])
json = hqmf_model.to_json
json.convert_keys_to_strings
@@ -81,32 +81,35 @@
end
end
return json['source_data_criteria'], json['data_criteria']
end
- def self.load(file, user, measure_details, vsac_user=nil, vsac_password=nil, overwrite_valuesets=false, cache=false, includeDraft=false, ticket_granting_ticket=nil)
+ def self.load(file, user, measure_details, vsac_options, vsac_ticket_granting_ticket)
measure = nil
Dir.mktmpdir do |dir|
- measure = load_mat_cql_exports(user, file, dir, measure_details, vsac_user, vsac_password, overwrite_valuesets, cache, includeDraft, ticket_granting_ticket)
+ measure = load_mat_cql_exports(user, file, dir, measure_details, vsac_options, vsac_ticket_granting_ticket)
end
measure
end
# Manages all of the CQL processing that is not related to the HQMF.
- def self.process_cql(files, main_cql_library, user, vsac_user=nil, vsac_password=nil, overwrite_valuesets=nil, cache=nil, includeDraft=nil, ticket_granting_ticket=nil, measure_id=nil)
+ def self.process_cql(files, main_cql_library, user, vsac_options, vsac_ticket_granting_ticket, measure_id=nil)
elm_strings = files[:ELM_JSON]
# Removes 'urn:oid:' from ELM for Bonnie and Parse the JSON
elm_strings.each { |elm_string| elm_string.gsub! 'urn:oid:', '' }
elms = elm_strings.map{ |elm| JSON.parse(elm, :max_nesting=>1000)}
elm_annotations = parse_elm_annotations(files[:ELM_XML])
# Hash of define statements to which define statements they use.
cql_definition_dependency_structure = populate_cql_definition_dependency_structure(main_cql_library, elms)
# Go back for the library statements
cql_definition_dependency_structure = populate_used_library_dependencies(cql_definition_dependency_structure, main_cql_library, elms)
+ # Add unused libraries to structure and set the value to empty hash
+ cql_definition_dependency_structure = populate_unused_included_libraries(cql_definition_dependency_structure, elms)
- # fix up statement names in cql_statement_dependencies to not use periods
+ # fix up statement names in cql_statement_dependencies to not use periods <<WRAP 1>>
+ # this is matched with an UNWRAP in MeasuresController in the bonnie project
Measures::MongoHashKeyWrapper::wrapKeys cql_definition_dependency_structure
# Depening on the value of the value set version, change it to null, strip out a substring or leave it alone.
modify_value_set_versions(elms)
@@ -120,16 +123,13 @@
end
end
end
# Get Value Sets
value_set_models = []
- if (vsac_user && vsac_password) || ticket_granting_ticket
- begin
- value_set_models = Measures::ValueSetLoader.load_value_sets_from_vsac(elm_value_sets, vsac_user, vsac_password, user, overwrite_valuesets, includeDraft, ticket_granting_ticket, cache, measure_id)
- rescue Exception => e
- raise VSACException.new "Error Loading Value Sets from VSAC: #{e.message}"
- end
+ # Only load value sets from VSAC if there is a ticket_granting_ticket.
+ if !vsac_ticket_granting_ticket.nil?
+ value_set_models = Measures::ValueSetLoader.load_value_sets_from_vsac(elm_value_sets, vsac_options, vsac_ticket_granting_ticket, user, measure_id)
else
# No vsac credentials were provided grab the valueset and valueset versions from the 'value_set_oid_version_object' on the existing measure
db_measure = CqlMeasure.by_user(user).where(hqmf_set_id: measure_id).first
unless db_measure.nil?
measure_value_set_version_map = db_measure.value_set_oid_version_objects
@@ -418,9 +418,22 @@
starting_hash[main_cql_library][key].each do |statement|
create_hash_for_all(starting_hash, statement, elms)
end
end
starting_hash
+ end
+
+ # add the unused libraries and set them to have empty hashes.
+ def self.populate_unused_included_libraries(cql_definition_dependency_structure, elms)
+ if elms.count > cql_definition_dependency_structure.keys.count
+ elms.each do |elm|
+ # If the number of libraries included in the elm is greater than
+ # the number of libraries included in the dependency structure
+ library_name = elm['library']['identifier']['id']
+ cql_definition_dependency_structure[library_name] = {} if cql_definition_dependency_structure[library_name].nil?
+ end
+ end
+ cql_definition_dependency_structure
end
# Traverse list, create keys and drill down for each key.
# If key is already in place, skip.
def self.create_hash_for_all(starting_hash, key_statement, elms)