Class: Renalware::Letters::Letter::PendingReview

Inherits:
Renalware::Letters::Letter show all
Defined in:
app/models/renalware/letters/letter/pending_review.rb

Constant Summary

Constants inherited from Renalware::Letters::Letter

EVENTS_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Renalware::Letters::Letter

#archive_recipients!, #archived?, #archived_by, #determine_counterpart_ccs, #effective_date, effective_date_sort, #find_cc_recipient_for_contact, for_event, #letter_event, #signed?, #subject?

Methods included from Accountable

#first_or_create_by!, #save_by, #save_by!, #update_by

Class Method Details

.policy_classObject



8
9
10
# File 'app/models/renalware/letters/letter/pending_review.rb', line 8

def self.policy_class
  PendingReviewLetterPolicy
end

Instance Method Details

#generate_archive(by:, presenter: default_presenter) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/renalware/letters/letter/pending_review.rb', line 29

def generate_archive(by:, presenter: default_presenter)
  becomes!(Approved).tap do |letter|
    letter.by = by
    # Note there is no need to set letter_id: id here but there is an
    # intermittent issue where (oddly) build_archive fails because letter_id not
    # present, so in attempt to fix this we are setting it here explicitly.
    # Using self.id rather than letter.id in case the becomes! has lost the id
    # for some reason. Also moved presenter.content to a new line so we can more easily see
    # if that is causing the error as it does a lot of processing to build the letter.
    # TODO: investigate
    achived_letter_content = presenter.content
    letter.build_archive(by: by, content: achived_letter_content, letter_id: id)
  end
end

#reject(by:) ⇒ Object



17
18
19
# File 'app/models/renalware/letters/letter/pending_review.rb', line 17

def reject(by:)
  becomes!(Draft).tap { |letter| letter.by = by }
end

#revise(params) ⇒ Object



12
13
14
15
# File 'app/models/renalware/letters/letter/pending_review.rb', line 12

def revise(params)
  params = LetterParamsProcessor.new(patient).call(params)
  self.attributes = params
end

#sign(by:) ⇒ Object



21
22
23
24
25
26
27
# File 'app/models/renalware/letters/letter/pending_review.rb', line 21

def sign(by:)
  build_signature(user: by, signed_at: Time.current)
  self.approved_by = by
  self.approved_at = Time.current
  self.by = by
  self
end