Class: Study::Metadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/study.rb

Instance Method Summary collapse

Instance Method Details

#data_release_prevention_reason_other?Boolean

Returns:

  • (Boolean)


644
645
646
# File 'app/models/study.rb', line 644

def data_release_prevention_reason_other?
  data_release_prevention_reason == DATA_RELEASE_PREVENTION_REASON_OTHER
end

#data_release_timing_must_be_never?Boolean

Returns:

  • (Boolean)


673
674
675
676
# File 'app/models/study.rb', line 673

def data_release_timing_must_be_never?
  Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
    strategy_not_applicable?
end

#data_release_timing_must_not_be_never?Boolean

Returns:

  • (Boolean)


678
679
680
681
# File 'app/models/study.rb', line 678

def data_release_timing_must_not_be_never?
  Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
    !strategy_not_applicable?
end

#delayed_for_long_time?Boolean

Returns:

  • (Boolean)


648
649
650
# File 'app/models/study.rb', line 648

def delayed_for_long_time?
  DATA_RELEASE_DELAY_PERIODS.include?(data_release_delay_period)
end

#delayed_for_other_reasons?Boolean

Returns:

  • (Boolean)


640
641
642
# File 'app/models/study.rb', line 640

def delayed_for_other_reasons?
  [DATA_RELEASE_DELAY_FOR_OTHER, OLD_DATA_RELEASE_DELAY_FOR_OTHER].include?(data_release_delay_reason)
end

#delayed_release?Boolean

Returns:

  • (Boolean)


632
633
634
# File 'app/models/study.rb', line 632

def delayed_release?
  data_release_timing == DATA_RELEASE_TIMING_DELAYED
end

#managed?Boolean

Returns:

  • (Boolean)


624
625
626
# File 'app/models/study.rb', line 624

def managed?
  data_release_strategy == DATA_RELEASE_STRATEGY_MANAGED
end

#never_release?Boolean

Returns:

  • (Boolean)


636
637
638
# File 'app/models/study.rb', line 636

def never_release?
  data_release_timing == DATA_RELEASE_TIMING_NEVER
end

#non_standard_agreement?Boolean

Returns:

  • (Boolean)


697
698
699
# File 'app/models/study.rb', line 697

def non_standard_agreement?
  data_release_standard_agreement == NO
end

#remove_x_and_autosomes?Boolean

Returns:

  • (Boolean)


620
621
622
# File 'app/models/study.rb', line 620

def remove_x_and_autosomes?
  remove_x_and_autosomes == YES
end

#sanity_check_y_separationObject



683
684
685
686
687
688
# File 'app/models/study.rb', line 683

def sanity_check_y_separation
  if remove_x_and_autosomes?
    errors.add(:separate_y_chromosome_data, 'cannot be selected with remove x and autosomes.')
  end
  !remove_x_and_autosomes?
end

#snp_child_studiesObject



743
744
745
746
747
# File 'app/models/study.rb', line 743

def snp_child_studies
  return nil if snp_study_id.nil?

  self.class.where(snp_parent_study_id: snp_study_id).includes(:study).map(&:study)
end

#snp_parent_studyObject



737
738
739
740
741
# File 'app/models/study.rb', line 737

def snp_parent_study
  return nil if snp_parent_study_id.nil?

  self.class.where(snp_study_id: snp_parent_study_id).includes(:study).try(:study)
end

#strategy_not_applicable?Boolean

Returns:

  • (Boolean)


628
629
630
# File 'app/models/study.rb', line 628

def strategy_not_applicable?
  data_release_strategy == DATA_RELEASE_STRATEGY_NOT_APPLICABLE
end

#study_type_valid?Boolean

Returns:

  • (Boolean)


701
702
703
# File 'app/models/study.rb', line 701

def study_type_valid?
  errors.add(:study_type, 'is not specified') if study_type.name == 'Not specified'
end

#valid_policy_url?Boolean

rubocop:todo Metrics/MethodLength

Returns:

  • (Boolean)


706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'app/models/study.rb', line 706

def valid_policy_url? # rubocop:todo Metrics/AbcSize
  # Rails 2.3 has no inbuilt URL validation, but rather than rolling our own, we'll
  # use the inbuilt ruby URI parser, a bit like here:
  # http://www.simonecarletti.com/blog/2009/04/validating-the-format-of-an-url-with-rails/
  return true if dac_policy.blank?

  dac_policy.insert(0, 'http://') unless dac_policy.include?('://') # Add an http protocol if no protocol is defined
  begin
    uri = URI.parse(dac_policy)
    if configatron.invalid_policy_url_domains.include?(uri.host)
      errors.add(
        :dac_policy,
        ": #{dac_policy} is not an acceptable URL. Please ensure you haven't provided an internal URL."
      )
    end
  rescue URI::InvalidURIError
    errors.add(:dac_policy, ": #{dac_policy} is not a valid URL")
  end
end