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:.
-
#by_abstractor_suggestion_type(abstractor_suggestion_type, options = {}) ⇒ ActiveRecord::Relation
Returns all abstractable entities filtered by the parameter abstractor_suggestion_type:.
-
#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.
592 593 594 595 |
# File 'lib/abstractor/abstractable.rb', line 592 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
597 598 599 600 |
# File 'lib/abstractor/abstractable.rb', line 597 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.
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/abstractor/abstractable.rb', line 561 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).
-
‘partially reviewed’: Filter abstractable entites having both abstractions with determned values (value, unknown or not_applicable) and abstractions without determined values.
-
‘actually answered’: Filter abstractable entites having no abstractions without an actual value (exluding blank, unknown or not_applicable).
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/abstractor/abstractable.rb', line 403 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]) when Abstractor::Enum::ABSTRACTION_STATUS_PARTIALLY_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 (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 = ?) ) AND 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, '') != '' OR COALESCE(aa.unknown, ?) = ? OR COALESCE(aa.not_applicable, ?) = ?) )", [:namespace_type], [:namespace_id], false, false, [:namespace_type], [:namespace_id], false, true, false, true]) when Abstractor::Enum::ABSTRACTION_STATUS_ACTUALLY_ANSWERED 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, '') = '' )", [:namespace_type], [:namespace_id], [:namespace_type], [:namespace_id]]) 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]) when Abstractor::Enum::ABSTRACTION_STATUS_PARTIALLY_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 (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 = ?) ) AND 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, '') != '' OR COALESCE(aa.unknown, ?) = ? OR COALESCE(aa.not_applicable, ?) = ?) )", false, false, false, true, false, true]) when Abstractor::Enum::ABSTRACTION_STATUS_ACTUALLY_ANSWERED 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, '') = '')"]) else where(nil) end end end |
#by_abstractor_suggestion_type(abstractor_suggestion_type, options = {}) ⇒ ActiveRecord::Relation
Returns all abstractable entities filtered by the parameter abstractor_suggestion_type:
-
‘unknown’: Filter abstractable entites having at least one suggestion withat a suggested value of ‘unknown’
-
‘suggested’: Filter abstractable entites having at least one suggestion with an acutal value
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/abstractor/abstractable.rb', line 367 def by_abstractor_suggestion_type(abstractor_suggestion_type, = {}) = { namespace_type: nil, namespace_id: nil }.merge() = { abstractor_abstraction_schemas: abstractor_abstraction_schemas }.merge() if [:namespace_type] || [:namespace_id] case abstractor_suggestion_type when Abstractor::Enum::ABSTRACTION_SUGGESTION_TYPE_UNKNOWN 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 = ? AND sub.abstractor_abstraction_schema_id IN (?) JOIN abstractor_suggestions sug ON aa.id = sug.abstractor_abstraction_id WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND sug.unknown = ?)", [:namespace_type], [:namespace_id], [:abstractor_abstraction_schemas], true]) when Abstractor::Enum::ABSTRACTION_SUGGESTION_TYPE_SUGGESTED 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 = ? AND sub.abstractor_abstraction_schema_id IN (?) JOIN abstractor_suggestions sug ON aa.id = sug.abstractor_abstraction_id WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND COALESCE(sug.unknown, ?) = ? AND sug.suggested_value IS NOT NULL AND COALESCE(sug.suggested_value, '') != '' )", [:namespace_type], [:namespace_id], [:abstractor_abstraction_schemas], false, false]) 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 = ? AND sub.abstractor_abstraction_schema_id IN (?) 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], [:abstractor_abstraction_schemas]]) end else case abstractor_suggestion_type when Abstractor::Enum::ABSTRACTION_SUGGESTION_TYPE_UNKNOWN where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.abstractor_abstraction_schema_id IN (?) JOIN abstractor_suggestions sug ON aa.id = sug.abstractor_abstraction_id WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND sug.unknown = ?)", [:abstractor_abstraction_schemas], true]) when Abstractor::Enum::ABSTRACTION_SUGGESTION_TYPE_SUGGESTED where(["EXISTS (SELECT 1 FROM abstractor_abstractions aa JOIN abstractor_subjects sub ON aa.abstractor_subject_id = sub.id AND sub.abstractor_abstraction_schema_id IN (?) JOIN abstractor_suggestions sug ON aa.id = sug.abstractor_abstraction_id WHERE aa.deleted_at IS NULL AND aa.about_type = '#{self.to_s}' AND #{self.table_name}.id = aa.about_id AND COALESCE(sug.unknown, ?) = ? AND sug.suggested_value IS NOT NULL AND COALESCE(sug.suggested_value, '') != '' )", [:abstractor_abstraction_schemas], false, false]) 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’
618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/abstractor/abstractable.rb', line 618 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.
655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/abstractor/abstractable.rb', line 655 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 |