Class: Renalware::Letters::LetterPresenter

Inherits:
DumbDelegator show all
Defined in:
app/presenters/renalware/letters/letter_presenter.rb

Direct Known Subclasses

Approved, Completed, Draft, PendingReview

Defined Under Namespace

Classes: Approved, Completed, Draft, PendingReview

Constant Summary collapse

ADHOC_PRINTING_CSS =
<<-STYLE
  <style>
    .footer .ccs h3 { margin-bottom: 4rem !important; }
    .footer .ccs .address { margin-bottom: 6rem !important; }
  </style>
STYLE

Instance Method Summary collapse

Methods inherited from DumbDelegator

#inspect, #public_send, #send, #try, #try!

Instance Method Details

#cc_recipientsObject



33
34
35
36
37
38
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 33

def cc_recipients
  @cc_recipients ||= begin
    recipients = build_cc_recipients
    present_cc_recipients(recipients)
  end
end

#cc_recipients_for_envelop_stuffingObject



40
41
42
43
44
45
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 40

def cc_recipients_for_envelop_stuffing
  @cc_recipients_for_envelop_stuffing ||= begin
    recipients = build_cc_recipients
    present_cc_recipients(recipients)
  end
end

#contentObject

rubocop:enable Rails/OutputSafety



82
83
84
85
86
87
88
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 82

def content
  if archived?
    archive.content
  else
    @content ||= HtmlRenderer.new.call(self)
  end
end

#descriptionObject



52
53
54
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 52

def description
  "(#{letterhead.site_code}) #{super}"
end

#electronic_cc_receiptsObject



47
48
49
50
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 47

def electronic_cc_receipts
  @electronic_cc_receipts ||=
    CollectionPresenter.new(super, Letters::ElectonicReceiptPresenter)
end

#event_descriptionObject



25
26
27
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 25

def event_description
  letter_event.description
end

#hospital_unit_codeObject



90
91
92
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 90

def hospital_unit_code
  letterhead.site_code
end

#hospital_unit_renal_registry_codeObject



94
95
96
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 94

def hospital_unit_renal_registry_code
  ::Renalware::Hospitals::Unit.find_by(unit_code: hospital_unit_code)&.renal_registry_code
end

#main_recipientObject



29
30
31
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 29

def main_recipient
  @main_recipient ||= recipient_presenter_class.new(super)
end

#part_for(part_name) ⇒ Object



70
71
72
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 70

def part_for(part_name)
  letter_event.part_classes[part_name].new(patient, self, letter_event)
end

#partsObject



60
61
62
63
64
65
66
67
68
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 60

def parts
  filtered_part_classes = PartClassFilter.new(
    part_classes: letter_event.part_classes,
    include_pathology_in_letter_body: letterhead.include_pathology_in_letter_body?
  )
  filtered_part_classes.to_h.values.map do |part_class|
    part_class.new(patient, self, letter_event)
  end
end

#patientObject



21
22
23
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 21

def patient
  @patient ||= PatientPresenter.new(super)
end

#pdf_filenameObject



102
103
104
105
106
107
108
109
110
111
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 102

def pdf_filename
  build_filename_from(
    [
      patient.family_name,
      patient.local_patient_id,
      id,
      state
    ]
  )
end

#pdf_stateless_filenameObject



113
114
115
116
117
118
119
120
121
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 113

def pdf_stateless_filename
  build_filename_from(
    [
      patient.family_name,
      patient.local_patient_id,
      id
    ]
  )
end

#state_descriptionObject



123
124
125
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 123

def state_description
  ::I18n.t(state.to_sym, scope: "enums.letter.state")
end

#titleObject



98
99
100
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 98

def title
  pdf_stateless_filename
end

#to_html(adhoc_printing: false) ⇒ Object

rubocop:disable Rails/OutputSafety



75
76
77
78
79
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 75

def to_html(adhoc_printing: false)
  html = content
  html << ADHOC_PRINTING_CSS.html_safe if adhoc_printing
  html
end

#typeObject



17
18
19
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 17

def type
  letter_event.to_link.call(patient)
end

#typistObject



127
128
129
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 127

def typist
  created_by
end

#view_labelObject



56
57
58
# File 'app/presenters/renalware/letters/letter_presenter.rb', line 56

def view_label
  "Preview"
end