Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - Fix Survey Distribution #1826

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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