Class: NcsNavigator::Warehouse::Filters::NoSsuOutreachAllSsusFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/ncs_navigator/warehouse/filters/no_ssu_outreach_all_ssus_filter.rb

Overview

A filter which duplicates outreach event records that don't have an SSU ID across all of a center's SSUs.

This filter is intended for use when reading a center's VDR XML into the warehouse for eventual import into a new NCS Navigator instance. Some centers have outreach events which are not associated with any SSUs in their XML. They intend this in indicate that the outreach events are associated with all the center's SSUs. This filter makes that happen.

This filter is stateful and so needs to be instantiated when being added to the warehouse configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, options = {}) ⇒ NoSsuOutreachAllSsusFilter

Returns a new instance of NoSsuOutreachAllSsusFilter.

Parameters:

  • configuration (Configuration)

    the warehouse configuration.

  • options (Hash<Symbol, Object>) (defaults to: {})

Options Hash (options):

  • :ssu_ids (Array<String>)

    by default, full set of SSU IDs is derived from the navigator suite configuration. It can be overridden with this option.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ncs_navigator/warehouse/filters/no_ssu_outreach_all_ssus_filter.rb', line 27

def initialize(configuration, options={})
  @configuration = configuration
  @ssu_ids = options[:ssu_ids] || default_ssu_ids

  @outreach_model = configuration.models_module.const_get(:Outreach)
  @outreach_associated_models = configuration.models_module.mdes_order.select { |model|
    model.relationships.detect { |rel| rel.parent_model == @outreach_model }
  }

  @replicated_outreach_event_ids = {}
end

Instance Attribute Details

#ssu_idsObject (readonly)

Returns the value of attribute ssu_ids.



18
19
20
# File 'lib/ncs_navigator/warehouse/filters/no_ssu_outreach_all_ssus_filter.rb', line 18

def ssu_ids
  @ssu_ids
end

Instance Method Details

#call(records) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ncs_navigator/warehouse/filters/no_ssu_outreach_all_ssus_filter.rb', line 39

def call(records)
  [].tap do |result|
    records.each do |rec|
      if is_no_ssu_outreach?(rec)
        result.concat replicate_outreach_across_ssus(rec)
      elsif is_replicated_oe_associate?(rec)
        result.concat replicate_associated_record(rec)
      else
        result << rec
      end
    end
  end
end