module HQMF # Class for cleaning up references to specific occurrences in the tree class SpecificOccurrenceConverter def initialize(data_criteria_converter) @data_criteria_converter = data_criteria_converter end def convert_specific_occurrences(population_criteria) population_criteria.each do |population| walk_up_tree(population.preconditions) end end def walk_up_tree(preconditions) preconditions.each do |precondition| if (has_child_comparison(precondition)) walk_up_tree(precondition.preconditions) end unless (precondition.comparison?) occurrence_map = get_grouped_occurrences(precondition.preconditions) occurrence_map.each do |key, value| ## ##### figure out negations ## if (precondition.conjunction_code == 'atLeastOneTrue') group = @data_criteria_converter.build_group_data_criteria(value, "#{key}_union", precondition.id, HQMF::DataCriteria::UNION) binding.pry elsif (precondition.conjunction_code == 'allTrue') binding.pry end end end end end def get_grouped_occurrences(preconditions) result = {} preconditions.each do |precondition| if (precondition.preconditions and !precondition.preconditions.empty?) get_grouped_occurrences(precondition.preconditions).each do |key, value| if (result[key]) result[key].concat(value) else result[key] = value end end else data_criteria = @data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id] if is_specific_occurrence(data_criteria) binding.pry result[data_criteria.source_data_criteria] ||= [] result[data_criteria.source_data_criteria] << data_criteria preconditions.delete(precondition) binding.pry end end end result end def is_specific_occurrence(data_criteria) !data_criteria.specific_occurrence.nil? end def has_child_comparison(node) value = false node.preconditions.each do |precondition| if (precondition.comparison?) value ||= true elsif precondition.has_preconditions? value ||= has_child_comparison(precondition) end end if node.preconditions value end end end