Skip to content

Commit

Permalink
Merge pull request #1826 from sparc-request/kg-survey_send_bug
Browse files Browse the repository at this point in the history
KG - Fix Survey Distribution
  • Loading branch information
Stuart-Johnson committed Apr 16, 2019
2 parents 4c366b4 + 361e4f5 commit d6679b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Organization < ApplicationRecord
has_many :org_children, class_name: "Organization", foreign_key: :parent_id

has_many :protocols, through: :sub_service_requests
has_many :surveys, through: :associated_surveys

validates :abbreviation,
:order,
Expand Down
13 changes: 2 additions & 11 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Service < ApplicationRecord
has_many :related_services, :through => :service_relations
has_many :required_services, -> { where("required = ? and is_available = ?", true, true) }, :through => :service_relations, :source => :related_service
has_many :optional_services, -> { where("required = ? and is_available = ?", false, true) }, :through => :service_relations, :source => :related_service
has_many :surveys, through: :associated_surveys

has_many :depending_services, :through => :depending_service_relations, :source => :service# Services that depend on this service

Expand Down Expand Up @@ -126,17 +127,7 @@ def institution

# do i have any available surveys, otherwise, look up tree and return first available surveys
def available_surveys
available = nil

#TODO: Should we get all parent surveys instead of the closest parent's surveys?
parents.reverse.each do |parent|
next if parent.type == 'Institution' # Institutions can't define associated surveys
available = parent.associated_surveys.map(&:survey) unless parent.associated_surveys.empty?
end

available = associated_surveys.map(&:survey) unless associated_surveys.empty? # i have available surveys, use those instead

available
(self.surveys + self.parents.map{ |parent| parent.surveys }.flatten).compact.uniq
end

# Given a dollar amount as a String, return an integer number of
Expand Down

0 comments on commit d6679b1

Please sign in to comment.