Sha256: 32c4dbb7fedab8388dda619b69dbf8f874cd2b77bce197d96d2b16a983f4c1d1

Contents?: true

Size: 1.56 KB

Versions: 103

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/letters/letter"

module Renalware
  module Letters
    class Letter::PendingReview < Letter
      def self.policy_class
        PendingReviewLetterPolicy
      end

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

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

      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

      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

      private

      def default_presenter
        LetterPresenterFactory.new(self)
      end
    end
  end
end

Version data entries

103 entries across 103 versions & 1 rubygems

Version Path
renalware-core-2.0.62 app/models/renalware/letters/letter/pending_review.rb
renalware-core-2.0.61 app/models/renalware/letters/letter/pending_review.rb
renalware-core-2.0.60 app/models/renalware/letters/letter/pending_review.rb