Module: Abstractor::Abstractable::ClassMethods
- Included in:
- Abstractor::Abstractable
- Defined in:
- lib/abstractor/abstractable.rb
Instance Method Summary collapse
-
#abstractor_abstraction_schemas(options = {}) ⇒ Object
Returns the abstractor abstraction schemas associated with the abstractable entity.
- #abstractor_subject_groups(options = {}) ⇒ Object
-
#abstractor_subjects(options = {}) ⇒ Object
Returns the abstractor subjects associated with the abstractable entity.
-
#by_abstractor_abstraction_status(abstractor_abstraction_status, options = {}) ⇒ ActiveRecord::Relation
Returns all abstractable entities filtered by the parameter abstractor_abstraction_status:.
-
#pivot_abstractions(options = {}) ⇒ Object
Pivot abstractions to simulate regular columns on an abstractable entity.
-
#pivot_grouped_abstractions(abstractor_subject_groups_name, options = {}) ⇒ Object
Pivot grouped abstractions to simulate regular columns on an abstractable entity.
Instance Method Details
#abstractor_abstraction_schemas(options = {}) ⇒ Object
Returns the abstractor abstraction schemas associated with the abstractable entity.
By default, the method will return all abstractor abstraction schemas.
273 274 275 276 |
# File 'lib/abstractor/abstractable.rb', line 273 def abstractor_abstraction_schemas( = {}) = { grouped: nil, namespace_type: nil, namespace_id: nil }.merge() abstractor_subjects().map(&:abstractor_abstraction_schema) end |
#abstractor_subject_groups(options = {}) ⇒ Object
278 279 280 281 |
# File 'lib/abstractor/abstractable.rb', line 278 def abstractor_subject_groups( = {}) = { grouped: true, namespace_type: nil, namespace_id: nil }.merge() Abstractor::AbstractorSubjectGroup.find(abstractor_subjects().map{|s| s.abstractor_subject_group.id}) end |
#abstractor_subjects(options = {}) ⇒ Object
Returns the abstractor subjects associated with the abstractable entity.
By default, the method will return all abstractor subjects.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/abstractor/abstractable.rb', line 242 def abstractor_subjects( = {}) = { grouped: nil, namespace_type: nil, namespace_id: nil, abstractor_abstraction_schema_ids: [] }.merge() subjects = Abstractor::AbstractorSubject.where(subject_type: self.to_s) if [:namespace_type] || [:namespace_id] subjects = subjects.where(namespace_type: [:namespace_type], namespace_id: [:namespace_id]) end if [:abstractor_abstraction_schema_ids].any? subjects = subjects.where(abstractor_abstraction_schema_id: [:abstractor_abstraction_schema_ids]) end subjects = case [:grouped] when true subjects.joins(:abstractor_subject_group).includes(:abstractor_subject_group) when false subjects.where("not exists (select 'a' from abstractor_subject_group_members where abstractor_subject_id = abstractor_subjects.id)") when nil subjects end end |
#by_abstractor_abstraction_status(abstractor_abstraction_status, options = {}) ⇒ ActiveRecord::Relation
Returns all abstractable entities filtered by the parameter abstractor_abstraction_status:
-
‘needs_review’: Filter abstractable entites having at least one abstraction without a determined value (value, unknown or not_applicable).
-
‘reviewed’: Filter abstractable entites having no abstractions without a determined value (value, unknown or not_applicable).
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/abstractor/abstractable.rb', line 208 def by_abstractor_abstraction_status(abstractor_abstraction_status, = {}) = { namespace_type: nil, namespace_id: nil }.merge() if [:namespace_type] || [:namespace_id] case abstractor_abstraction_status when Abstractor::Enum::ABSTRACTION_STATUS_NEEDS_REVIEW where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.namespace_type = ? AND sub.namespace_id = ? WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND (aa.value IS NULL OR aa.value = '') AND (aa.unknown IS NULL OR aa.unknown = ?) AND (aa.not_applicable IS NULL OR aa.not_applicable = ?))", [:namespace_type], [:namespace_id], false, false]) when Abstractor::Enum::ABSTRACTION_STATUS_REVIEWED where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.namespace_type = ? AND sub.namespace_id = ? WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id) AND NOT EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.namespace_type = ? AND sub.namespace_id = ? WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND COALESCE(aa.value, '') = '' AND COALESCE(aa.unknown, ?) != ? AND COALESCE(aa.not_applicable, ?) != ?)", [:namespace_type], [:namespace_id], [:namespace_type], [:namespace_id], false, true, false, true]) else where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.namespace_type = ? AND sub.namespace_id = ? WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id)", [:namespace_type], [:namespace_id]]) end else case abstractor_abstraction_status when Abstractor::Enum::ABSTRACTION_STATUS_NEEDS_REVIEW where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND (aa.value IS NULL OR aa.value = '') AND (aa.unknown IS NULL OR aa.unknown = ?) AND (aa.not_applicable IS NULL OR aa.not_applicable = ?))", false, false]) when Abstractor::Enum::ABSTRACTION_STATUS_REVIEWED where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id) AND NOT EXISTS (SELECT 1 FROM abstractor_abstractions aa WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND COALESCE(aa.value, '') = '' AND COALESCE(aa.unknown, ?) != ? AND COALESCE(aa.not_applicable, ?) != ?)", false, true, false, true]) else where(nil) end end end |
#pivot_abstractions(options = {}) ⇒ Object
Pivot abstractions to simulate regular columns on an abstractable entity.
Example: an ActiveRecod model PathologyCaseReport with the columns
-
‘collection_date’
-
‘report_text’
And the abstraction ‘has_cancer_diagnosis’.
This method allows for the querying of the pathology_cases table as if it was strucutred like so: ‘select id, collection_date, report_text, has_cancer_diagnosis from pathology_cases’
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/abstractor/abstractable.rb', line 299 def pivot_abstractions( = {}) = { grouped: false, namespace_type: nil, namespace_id: nil }.merge() select = prepare_pivot_select() adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter] j = case adapter when 'sqlite3' prepare_pivot_joins(select, "'t'", ) when 'sqlserver' prepare_pivot_joins(select, '1', ) when 'postgresql' prepare_pivot_joins(select, 'true', ) end joins(j).select("#{self.table_name}.*, pivoted_abstractions.*") end |
#pivot_grouped_abstractions(abstractor_subject_groups_name, options = {}) ⇒ Object
Pivot grouped abstractions to simulate regular columns on an abstractable entity.
Example: an ActiveRecod model RadationTreatment with the columns
-
‘treatment_date’
-
‘total_dose’
And the abstractions grouped together with the name ‘has_treatment_target’:
-
‘has_anatomical_location’.
-
‘has_laterality’
This method allows for the querying of the radiation_treatments table as if it was strucutred like so: ‘select id, treatment_date, toatl_dose, has_anatomical_location, has_laterality from radiation_treatments’
If an abstractable entity has multiple instances of grouped abstractions the entity will be returned mutlple times.
336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/abstractor/abstractable.rb', line 336 def pivot_grouped_abstractions(abstractor_subject_groups_name, = {}) = { grouped: true, namespace_type: nil, namespace_id: nil }.merge() select = prepare_pivot_select() adapter = ActiveRecord::Base.connection.instance_values["config"][:adapter] j = case adapter when 'sqlite3' prepare_grouped_pivot_joins(select, "'t'", abstractor_subject_groups_name, ) when 'sqlserver' prepare_grouped_pivot_joins(select, '1', abstractor_subject_groups_name, ) when 'postgresql' prepare_grouped_pivot_joins(select, 'true', abstractor_subject_groups_name, ) end joins(j).select("#{self.table_name}.*, pivoted_abstractions.*") end |