Class: CaTissue::Migrator

Inherits:
CaRuby::Migrator
  • Object
show all
Defined in:
lib/catissue/migration/migrator.rb

Overview

Migrates a CSV extract to caTissue. See the #initialize documentation for usage options.

See the Galena migration example for further information about to tailor the migration, esp. the use of the field mappings and shims.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Migrator

Creates a new Migrator with the given options.

This migrator must include sufficient information to build a well-formed migration target object. For example, if the target object is a new SpecimenCollectionGroup, then the migration must also be able to build that SCG’s CollectionProtocolRegistration. The CPR in turn must either exist in the database or the migration must build a Participant and a CollectionProtocol.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :controlled_values (Boolean)

    enable controlled value lookup

  • :database (CaRuby::Database)

    the target application database

  • :target (String)

    required target domain class name

  • :input (String)

    required source file to migrate

  • :shims (String)

    optional array of shim files to load

  • :unique (String)

    makes migrated objects unique object for testing mix-in do not conflict with existing or future objects

  • :bad (String)

    write each invalid record to the given file and continue migration

  • :offset (String)

    zero-based starting source record number to process (default 0)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/catissue/migration/migrator.rb', line 27

def initialize(opts={})
  # tailor the options
  opts[:name] ||= NAME
  opts[:database] ||= CaTissue::Database.current
  # the shims file(s)
  opts[:shims] ||= []
  shims = opts[:shims] ||= []
  # make a single shims file into an array
  shims = opts[:shims] = [shims] unless shims.collection?
  # prepend this migrator's shims
  shims.unshift(MIGRATABLE_SHIM)
  # If the unique option is set, then prepend the CaTissue-specific uniquifier shim.
  if opts[:unique] then
    shims.unshift(UNIQUIFY_SHIM)
    logger.debug { "Migrator added uniquification shim #{UNIQUIFY_SHIM}." }
  end

  # call the Jinx::Migrator initializer with the augmented options
  super

  # The remaining options are handled by this CaTissue::Migrator subclass.

  # The CV look-up option.
  if opts[:controlled_values] then
    CaTissue::SpecimenCharacteristics.enable_cv_finder
    CaTissue::SpecimenCollectionGroup.enable_cv_finder
    logger.info("Migrator enabled tissue site and clinical diagnosis controlled value lookup.")
  end
end