def create_measure(measure_files)
      hqmf_xml = measure_files.hqmf_xml
      # update the valueset info in each elm (update version and remove urn:oid)
      measure_files.cql_libraries.each { |cql_lib_files| modify_elm_valueset_information(cql_lib_files.elm) }

      measure = CQM::Measure.new(HQMFMeasureLoader.extract_fields(hqmf_xml))
      measure.cql_libraries = create_cql_libraries(measure_files.cql_libraries, measure.main_cql_library)
      measure.composite = measure_files.components.present?
      measure.calculation_method = @measure_details[:episode_of_care] ? 'EPISODE_OF_CARE' : 'PATIENT'
      measure.calculate_sdes = @measure_details[:calculate_sdes]

      hqmf_model = HQMF::Parser::V2CQLParser.new.parse(hqmf_xml) # TODO: move away from using V2CQLParser

      elms = measure.cql_libraries.map(&:elm)
      elm_valuesets = ValueSetHelpers.unique_list_of_valuesets_referenced_by_elms(elms)
      verify_hqmf_valuesets_match_elm_valuesets(elm_valuesets, hqmf_model)

      value_sets_from_single_code_references = ValueSetHelpers.make_fake_valuesets_from_single_code_references(elms, @vs_model_cache)
      measure.source_data_criteria = SourceDataCriteriaLoader.new(hqmf_xml, value_sets_from_single_code_references).extract_data_criteria
      measure.value_sets = value_sets_from_single_code_references
      measure.value_sets.concat(@value_set_loader.retrieve_and_modelize_value_sets_from_vsac(elm_valuesets)) if @value_set_loader.present?

      ## this to_json is needed, it doesn't actually produce json, it just makes a hash that is better
      ## suited for our uses (e.g. source_data_criteria goes from an array to a hash keyed by id)
      hqmf_model_hash = hqmf_model.to_json.deep_symbolize_keys!
      HQMFMeasureLoader.add_fields_from_hqmf_model_hash(measure, hqmf_model_hash)

      return measure
    end
def create_measure(measure_files)
      hqmf_xml = measure_files.hqmf_xml
      # update the valueset info in each elm (update version and remove urn:oid)
      measure_files.cql_libraries.each { |cql_lib_files| modify_elm_valueset_information(cql_lib_files.elm) }

      measure = CQM::Measure.new(HQMFMeasureLoader.extract_fields(hqmf_xml))
      measure.cql_libraries = create_cql_libraries(measure_files.cql_libraries, measure.main_cql_library)
      measure.composite = measure_files.components.present?
      measure.calculation_method = @measure_details[:episode_of_care] ? 'EPISODE_OF_CARE' : 'PATIENT'
      measure.calculate_sdes = @measure_details[:calculate_sdes]

      hqmf_model = HQMF::Parser::V2CQLParser.new.parse(hqmf_xml) # TODO: move away from using V2CQLParser

      elms = measure.cql_libraries.map(&:elm)
      elm_valuesets = ValueSetHelpers.unique_list_of_valuesets_referenced_by_elms(elms)
      verify_hqmf_valuesets_match_elm_valuesets(elm_valuesets, hqmf_model)

      value_sets_from_single_code_references = ValueSetHelpers.make_fake_valuesets_from_single_code_references(elms, @vs_model_cache)
      measure.source_data_criteria = SourceDataCriteriaLoader.new(hqmf_xml, value_sets_from_single_code_references).extract_data_criteria
      measure.value_sets = value_sets_from_single_code_references
      measure.value_sets.concat(@value_set_loader.retrieve_and_modelize_value_sets_from_vsac(elm_valuesets)) if @value_set_loader.present?

      ## this to_json is needed, it doesn't actually produce json, it just makes a hash that is better
      ## suited for our uses (e.g. source_data_criteria goes from an array to a hash keyed by id)
      hqmf_model_hash = hqmf_model.to_json.deep_symbolize_keys!
      HQMFMeasureLoader.add_fields_from_hqmf_model_hash(measure, hqmf_model_hash)

      return measure
    end
Creates and returns a measure