Module: Abstractor::Abstractable::InstanceMethods

Included in:
Abstractor::Abstractable
Defined in:
lib/abstractor/abstractable.rb

Instance Method Summary collapse

Instance Method Details

#abstract(options = {}) ⇒ void

This method returns an undefined value.

The method for generating abstractions from the abstractable entity.

The generation of abstactions is based on the setup of Abstactor::AbstractorAbstactionSchema, Abstractor::AbstractorSubject, Abstractor::AbstractorSubjectGroup and Abstractor::AbstractorAbstractionSource associated to the abstractable entity.

Namespacing allows for different sets data points to be associated to the same abstractable entity.

Namespacing is achieved by setting the Abstractor::AbstractorSubject#namespace_type and Abstractor::AbstractorSubject#namespace_id attributes.

Passing a namespace to this method will restrict the generation of abstractions to the given namespace. Otherwise, all configured abstractions associated to the abstractable entity will be generated.

A practical example of the use of a namespace would be two different clincal departments wanting to chart abstract two distinct sets of datapoints for progress notes extracted from an electronic medical record system.

Parameters:

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

    the options to filter the generation of abstractions to a namespace.

Options Hash (options):

  • :namespace_type (String)

    The type parameter of the namespace.

  • :namespace_id (Integer)

    The instance parameter of the namespace.

  • :abstractor_abstraction_schema_ids (List of integers)

    List of abstractor_abstraction_schema_ids to limit abstraction.



89
90
91
92
93
94
# File 'lib/abstractor/abstractable.rb', line 89

def abstract(options = {})
  options = { namespace_type: nil, namespace_id: nil, abstractor_abstraction_schema_ids: [] }.merge(options)
  self.class.abstractor_subjects(options).each do |abstractor_subject|
    abstractor_subject.abstract(self)
  end
end

#abstractor_abstraction_groups_by_namespace(options = {}) ⇒ ActiveRecord::Relation

Returns all abstraction groups for the abstractable entity by a namespace.

Parameters:

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

    the options to filter the list of abstraction groups to a namespace.

Options Hash (options):

  • :namespace_type (String)

    The type parameter of the namespace.

  • :namespace_id (Integer)

    The instance parameter of the namespace.

Returns:

  • (ActiveRecord::Relation)

    List of [Abstractor::AbstractorAbstractionGroup].



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/abstractor/abstractable.rb', line 57

def abstractor_abstraction_groups_by_namespace(options = {})
  options = { namespace_type: nil, namespace_id: nil }.merge(options)
  if options[:namespace_type] || options[:namespace_id]
    groups = abstractor_abstraction_groups.find(abstractor_abstractions_by_namespace(options).joins(:abstractor_abstraction_group).includes(:abstractor_abstraction_group).map{|s| s.abstractor_abstraction_group.id})
  else
    groups = abstractor_abstraction_groups.not_deleted
  end
  if options[:abstractor_subject_group_id]
    groups.select{|g| g.abstractor_subject_group_id == options[:abstractor_subject_group_id]}
  else
    groups
  end
end

#abstractor_abstractions_by_abstraction_schemas(options = {}) ⇒ ActiveRecord::Relation

Returns all abstractions for the abstractable entity by abstraction schemas.

Parameters:

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

    the options to filter the list of abstractions to a namespace.

Options Hash (options):

  • :abstractor_abstraction_schema_ids (Array)

    List of [Abstractor::AbstractorAbstractionSchema] ids

  • List (ActiveRecord::Relation)

    of [Abstractor::AbstractorAbstraction].

Returns:

  • (ActiveRecord::Relation)

    List of [Abstractor::AbstractorAbstraction].



41
42
43
44
45
46
47
48
# File 'lib/abstractor/abstractable.rb', line 41

def abstractor_abstractions_by_abstraction_schemas(options = {})
  options = { abstractor_abstraction_schema_ids: [], abstractor_abstractions: abstractor_abstractions.not_deleted }.merge(options)
  if options[:abstractor_abstraction_schema_ids].any?
    options[:abstractor_abstractions].joins(:abstractor_subject).where(abstractor_subjects: { abstractor_abstraction_schema_id: options[:abstractor_abstraction_schema_ids]})
  else
    options[:abstractor_abstractions]
  end
end

#abstractor_abstractions_by_abstractor_abstraction_status(abstractor_abstraction_status, options = {}) ⇒ ActiveRecord::Relation

Returns all abstraction for the abstractable entity by abstractor_abstraction_status:

  • ‘needs_review’: Filter abstractions without a determined value (value, unknown or not_applicable).

  • ‘reviewed’: Filter abstractions having a determined value (value, unknown or not_applicable).

Parameters:

  • abstractor_abstraction_status (String)

    Filter abstractions that need review or are reviews.

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

    the options to filter abstractions to a namespace.

Options Hash (options):

  • :namespace_type (String)

    the type parameter of the namespace.

  • :namespace_id (Integer)

    the instance parameter of the namespace.

Returns:

  • (ActiveRecord::Relation)

    list of [Abstractor::AbstractorAbstraction].



154
155
156
157
158
159
160
161
162
# File 'lib/abstractor/abstractable.rb', line 154

def abstractor_abstractions_by_abstractor_abstraction_status(abstractor_abstraction_status, options = {})
  options = { namespace_type: nil, namespace_id: nil }.merge(options)
  case abstractor_abstraction_status
  when Abstractor::Enum::ABSTRACTION_STATUS_NEEDS_REVIEW
    abstractor_abstractions_by_namespace(options).select { |abstractor_abstraction| abstractor_abstraction.value.blank? && abstractor_abstraction.unknown.blank? && abstractor_abstraction.not_applicable.blank? }
  when Abstractor::Enum::ABSTRACTION_STATUS_REVIEWED
    abstractor_abstractions_by_namespace(options).select { |abstractor_abstraction| !abstractor_abstraction.value.blank? || !abstractor_abstraction.unknown.blank? || !abstractor_abstraction.not_applicable.blank? }
  end
end

#abstractor_abstractions_by_namespace(options = {}) ⇒ ActiveRecord::Relation

Returns all abstractions for the abstractable entity by a namespace.

Parameters:

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

    the options to filter the list of abstractions to a namespace.

Options Hash (options):

  • :namespace_type (String)

    The type parameter of the namespace.

  • :namespace_id (Integer)

    The instance parameter of the namespace.

Returns:

  • (ActiveRecord::Relation)

    List of [Abstractor::AbstractorAbstraction].



25
26
27
28
29
30
31
32
# File 'lib/abstractor/abstractable.rb', line 25

def abstractor_abstractions_by_namespace(options = {})
  options = { namespace_type: nil, namespace_id: nil }.merge(options)
  abstractions = abstractor_abstractions.not_deleted
  if options[:namespace_type] || options[:namespace_id]
    abstractions = abstractions.where(abstractor_subject_id: self.class.abstractor_subjects(options).map(&:id))
  end
  abstractions
end

#abstractor_subject_group_complete?(abstractor_subject_group_id, options = {}) ⇒ boolean

Determines if provided abstractor_subject_group reached number of abstractor_abstraction_groups defined by abstractor_subject_group cardinality

Parameters:

  • abstractor_subject_group_id (Integer)

    the id of abstractor_subject_group of interest.

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

    a customizable set of options

Options Hash (options):

  • :namespace_type (String)

    the type parameter of the namespace.

  • :namespace_id (Integer)

    the instance parameter of the namespace.

Returns:

  • (boolean)


132
133
134
135
136
137
138
139
140
141
# File 'lib/abstractor/abstractable.rb', line 132

def abstractor_subject_group_complete?(abstractor_subject_group_id, options = {})
  abstractor_subject_group = Abstractor::AbstractorSubjectGroup.find(abstractor_subject_group_id)
  if abstractor_subject_group.cardinality.blank?
    false
  else
    options = { namespace_type: nil, namespace_id: nil, abstractor_subject_group_id: abstractor_subject_group_id }.merge(options)
    abstractor_abstraction_groups = abstractor_abstraction_groups_by_namespace(options)
    abstractor_abstraction_groups.length == abstractor_subject_group.cardinality
  end
end

#detect_abstractor_abstraction(abstractor_subject) ⇒ Object



96
97
98
# File 'lib/abstractor/abstractable.rb', line 96

def detect_abstractor_abstraction(abstractor_subject)
  abstractor_abstractions(true).not_deleted.detect { |abstractor_abstraction| abstractor_abstraction.abstractor_subject_id == abstractor_subject.id }
end

#detect_abstractor_abstraction_group(abstractor_subject_group) ⇒ Object



113
114
115
# File 'lib/abstractor/abstractable.rb', line 113

def detect_abstractor_abstraction_group(abstractor_subject_group)
  abstractor_abstraction_groups(true).detect { |abstractor_abstraction_group| abstractor_abstraction_group.abstractor_subject_group_id ==  abstractor_subject_group.id }
end

#find_or_create_abstractor_abstraction(abstractor_abstraction_schema, abstractor_subject) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/abstractor/abstractable.rb', line 100

def find_or_create_abstractor_abstraction(abstractor_abstraction_schema, abstractor_subject)
  if abstractor_abstraction = detect_abstractor_abstraction(abstractor_subject)
  else
    abstractor_abstraction = Abstractor::AbstractorAbstraction.create!(abstractor_subject: abstractor_subject, about: self)
    if abstractor_subject.groupable?
      abstractor_abstraction_group = find_or_initialize_abstractor_abstraction_group(abstractor_subject.abstractor_subject_group)
      abstractor_abstraction_group.abstractor_abstractions << abstractor_abstraction
      abstractor_abstraction_group.save!
    end
  end
  abstractor_abstraction
end

#find_or_initialize_abstractor_abstraction_group(abstractor_subject_group) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/abstractor/abstractable.rb', line 117

def find_or_initialize_abstractor_abstraction_group(abstractor_subject_group)
  if abstractor_abstraction_group = detect_abstractor_abstraction_group(abstractor_subject_group)
  else
    abstractor_abstraction_group = Abstractor::AbstractorAbstractionGroup.new(abstractor_subject_group: abstractor_subject_group, about: self, system_generated: true)
  end
  abstractor_abstraction_group
end

#remove_abstractions(options = {}) ⇒ void

This method returns an undefined value.

Removes all abstractions, suggestions and indirect sources for the abstractable entity. Optionally filtred to only ‘unreviewed’ abstractions and to a given namespace.

Parameters:

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

    the options to filter the removal of abstractions.

Options Hash (options):

  • :only_unreviewed (Booelan)

    Instructs whether to confine removal to only ‘unreviewed’ abstractions.

  • :namespace_type (String)

    The type parameter of the namespace to remove.

  • :namespace_id (Integer)

    The instance parameter of the namespace to remove.

  • :abstractor_abstraction_schema_ids (List of integers)

    List of abstractor_abstraction_schema_ids to limit abstraction removal.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/abstractor/abstractable.rb', line 173

def remove_abstractions(options = {})
  options = { only_unreviewed: true, namespace_type: nil, namespace_id: nil, abstractor_abstraction_schema_ids: [] }.merge(options)
  abstractor_abstractions = abstractor_abstractions_by_namespace(options)
  if options[:abstractor_abstraction_schema_ids].any?
    options = { abstractor_abstractions: abstractor_abstractions }.merge(options)
    abstractor_abstractions = abstractor_abstractions_by_abstraction_schemas(options)
  end
  abstractor_abstractions.each do |abstractor_abstraction|
    if !options[:only_unreviewed] || (options[:only_unreviewed] && abstractor_abstraction.unreviewed?)
      abstractor_abstraction.abstractor_suggestions.each do |abstractor_suggestion|
        abstractor_suggestion.abstractor_suggestion_sources.destroy_all
        abstractor_suggestion.abstractor_suggestion_object_value.destroy if abstractor_suggestion.abstractor_suggestion_object_value
        abstractor_suggestion.destroy
      end
      abstractor_abstraction.abstractor_indirect_sources.each do |abstractor_indirect_source|
        abstractor_indirect_source.destroy
      end
      abstractor_abstraction.destroy
    end
  end
end