Class: Effective::CpdAuditReview

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/cpd_audit_review.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_stepObject

Returns the value of attribute current_step.



4
5
6
# File 'app/models/effective/cpd_audit_review.rb', line 4

def current_step
  @current_step
end

#current_userObject

Returns the value of attribute current_user.



3
4
5
# File 'app/models/effective/cpd_audit_review.rb', line 3

def current_user
  @current_user
end

Instance Method Details

#auditee_cpd_statementsObject

The dynamic CPD Statement review steps



114
115
116
117
118
# File 'app/models/effective/cpd_audit_review.rb', line 114

def auditee_cpd_statements
  cpd_audit.user.cpd_statements.select do |cpd_statement|
    cpd_statement.completed? && (.blank? || cpd_statement. < )
  end
end

#can_visit_step?(step) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
150
# File 'app/models/effective/cpd_audit_review.rb', line 147

def can_visit_step?(step)
  return (step == :complete) if completed?  # Can only view complete step once submitted
  can_revisit_completed_steps(step)
end

#completed?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'app/models/effective/cpd_audit_review.rb', line 201

def completed?
  .present?
end

#cpd_audit_level_section(wizard_step) ⇒ Object

The dynamic CPD Audit Level Sections steps



132
133
134
135
# File 'app/models/effective/cpd_audit_review.rb', line 132

def cpd_audit_level_section(wizard_step)
  position = (wizard_step.to_s.split('section').last.to_i rescue false)
  cpd_audit_level.cpd_audit_level_sections.find { |section| (section.position + 1) == position }
end

#cpd_audit_review_item(item) ⇒ Object

Find or build



104
105
106
107
108
109
110
111
# File 'app/models/effective/cpd_audit_review.rb', line 104

def cpd_audit_review_item(item)
  unless item.kind_of?(CpdAuditResponse) || item.kind_of?(CpdStatementActivity)
    raise("expected a cpd_audit_response or cpd_statement_activity")
  end

  cpd_audit_review_item = cpd_audit_review_items.find { |cari| cari.item == item }
  cpd_audit_review_item ||= cpd_audit_review_items.build(item: item)
end

#cpd_statement(wizard_step) ⇒ Object



120
121
122
123
# File 'app/models/effective/cpd_audit_review.rb', line 120

def cpd_statement(wizard_step)
  cpd_cycle_id = (wizard_step.to_s.split('statement').last.to_i rescue false)
  auditee_cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle_id }
end

#deadline_to_conflict_of_interestObject



214
215
216
# File 'app/models/effective/cpd_audit_review.rb', line 214

def deadline_to_conflict_of_interest
  cpd_audit.deadline_to_conflict_of_interest
end

#deadline_to_reviewObject



218
219
220
221
222
223
224
225
# File 'app/models/effective/cpd_audit_review.rb', line 218

def deadline_to_review
  return nil unless cpd_audit_level&.days_to_review.present?

  date = cpd_audit.deadline_to_submit
  return nil unless date.present?

  EffectiveResources.advance_date(date, business_days: cpd_audit_level.days_to_review)
end

#dynamic_wizard_questionnaire_stepsObject



137
138
139
140
141
# File 'app/models/effective/cpd_audit_review.rb', line 137

def dynamic_wizard_questionnaire_steps
  @questionnaire_steps ||= cpd_audit_level.cpd_audit_level_sections.each_with_object({}) do |section, h|
    h["section#{section.position+1}".to_sym] = section.title
  end
end

#dynamic_wizard_statement_stepsObject



125
126
127
128
129
# File 'app/models/effective/cpd_audit_review.rb', line 125

def dynamic_wizard_statement_steps
  @statement_steps ||= auditee_cpd_statements.each_with_object({}) do |cpd_statement, h|
    h["statement#{cpd_statement.cpd_cycle_id}".to_sym] = "#{cpd_statement.cpd_cycle.to_s} Activities"
  end
end

#dynamic_wizard_stepsObject



143
144
145
# File 'app/models/effective/cpd_audit_review.rb', line 143

def dynamic_wizard_steps
  dynamic_wizard_statement_steps.merge(dynamic_wizard_questionnaire_steps)
end

#email_form_defaults(action) ⇒ Object



205
206
207
# File 'app/models/effective/cpd_audit_review.rb', line 205

def email_form_defaults(action)
  { from: EffectiveCpd.mailer_sender }
end

#extension_granted!Object

Called by CpdAudit.extension_granted



175
176
177
# File 'app/models/effective/cpd_audit_review.rb', line 175

def extension_granted!
  self.due_date = deadline_to_review()
end

#in_progress?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'app/models/effective/cpd_audit_review.rb', line 197

def in_progress?
  .blank?
end

#ready!Object

Called by CpdAudit.submit!



180
181
182
# File 'app/models/effective/cpd_audit_review.rb', line 180

def ready!
  send_email(:cpd_audit_review_ready)
end

#ready?Boolean

When ready, the applicant review wizard hides the waiting step

Returns:

  • (Boolean)


193
194
195
# File 'app/models/effective/cpd_audit_review.rb', line 193

def ready?
  cpd_audit&.
end

#reportable_scopesObject

effective_reports



77
78
79
# File 'app/models/effective/cpd_audit_review.rb', line 77

def reportable_scopes
  { available: nil, completed: nil }
end

#required_stepsObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/models/effective/cpd_audit_review.rb', line 152

def required_steps
  steps = [:start, :information, :instructions]

  steps << :conflict if cpd_audit_level.conflict_of_interest?

  if conflict_of_interest?
    return steps + [:submit, :complete]
  end

  steps += [:waiting] unless ready?

  steps += [:statements] + dynamic_wizard_statement_steps.keys
  steps += [:questionnaire] + dynamic_wizard_questionnaire_steps.keys
  steps += [:recommendation, :submit, :complete]

  steps
end

#send_email(email) ⇒ Object



209
210
211
212
# File 'app/models/effective/cpd_audit_review.rb', line 209

def send_email(email)
  EffectiveCpd.send_email(email, self, email_form_params) unless email_form_skip?
  true
end

#submit!Object

Called by review wizard submit step



185
186
187
188
189
190
# File 'app/models/effective/cpd_audit_review.rb', line 185

def submit!
  update!(submitted_at: Time.zone.now)
  cpd_audit.review! # maybe go from submitted->removed

  send_email(:cpd_audit_review_submitted)
end

#to_sObject



95
96
97
# File 'app/models/effective/cpd_audit_review.rb', line 95

def to_s
  'audit review'
end

#wizard_step_title(step) ⇒ Object



170
171
172
# File 'app/models/effective/cpd_audit_review.rb', line 170

def wizard_step_title(step)
  WIZARD_STEPS[step] || dynamic_wizard_steps.fetch(step)
end