lib/measures/loading/cql_loader.rb in bonnie_bundler-2.0.2 vs lib/measures/loading/cql_loader.rb in bonnie_bundler-2.0.3

- old
+ new

@@ -127,35 +127,26 @@ 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 else - # if VSAC credentials aren't provided, find the value sets in the database - elm_value_sets.each do |elm_value_set| - version = elm_value_set[:version] || "N/A" # 'N/A' is what is stored in the DB for value sets without versions - query_params = {user_id: user.id, oid: elm_value_set[:oid]} - - if (elm_value_set[:profile]) - query_params[:profile] = elm_value_set[:profile] - else - query_params[:version] = version - end - - value_set = HealthDataStandards::SVS::ValueSet.where(query_params).first() - if value_set - value_set_models << value_set - elsif version == "N/A" - # if the version is "N/A" and a value set doesn't exist with that version, just grab the existing value set - value_set = HealthDataStandards::SVS::ValueSet.where({user_id: user.id, oid: elm_value_set[:oid]}).first() + # 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 + measure_value_set_version_map.each do |value_set| + query_params = {user_id: user.id, oid: value_set['oid'], version: value_set['version']} + value_set = HealthDataStandards::SVS::ValueSet.where(query_params).first() if value_set value_set_models << value_set + else + raise MeasureLoadingException.new "Value Set not found in database: #{query_params}" end end end end - # Get code systems and codes for all value sets in the elm. all_codes_and_code_names = HQMF2JS::Generator::CodesToJson.from_value_sets(value_set_models) # Replace code system oids with friendly names # TODO: preferred solution would be to continue using OIDs in the ELM and enable Bonnie to supply those OIDs # to the calculation engine in patient data and value sets. @@ -165,11 +156,14 @@ single_code_references, all_codes_and_code_names = generate_single_code_references(elms, all_codes_and_code_names, user) # Add our new fake oids to measure value sets. all_value_set_oids = value_set_models.collect{|vs| vs.oid} single_code_references.each do |single_code| - all_value_set_oids << single_code[:guid] + # Only add unique Direct Reference Codes + unless all_value_set_oids.include?(single_code[:guid]) + all_value_set_oids << single_code[:guid] + end end # Add a list of value set oids and their versions value_set_oid_version_objects = get_value_set_oid_version_objects(value_set_models, single_code_references) @@ -190,11 +184,15 @@ value_set_oid_version_objects = [] value_sets.each do |vs| value_set_oid_version_objects << {:oid => vs.oid, :version => vs.version} end single_code_references.each do |single_code| - value_set_oid_version_objects << {:oid => single_code[:guid], :version => ""} + # Only add unique Direct Reference Codes to the object + unless value_set_oid_version_objects.include?({:oid => single_code[:guid], :version => ""}) + value_set_oid_version_objects << {:oid => single_code[:guid], :version => ""} + end end + # Return a list of unique objects only value_set_oid_version_objects end # Replace all the code system ids that are oids with the friendly name of the code system # TODO: preferred solution would be to continue using OIDs in the ELM and enable Bonnie to supply those OIDs