Class: Renalware::Letters::Letter
Defined Under Namespace
Classes: Approved, Completed, Draft, PendingReview
Constant Summary
collapse
- EVENTS_MAP =
{
Clinics::ClinicVisit => Event::ClinicVisit,
NilClass => Event::Unknown
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#first_or_create_by!, #save_by, #save_by!, #update_by
Class Method Details
.effective_date_sort ⇒ Object
81
82
83
|
# File 'app/models/renalware/letters/letter.rb', line 81
def self.effective_date_sort
Arel.sql("coalesce(completed_at, approved_at, submitted_for_approval_at, created_at)")
end
|
.for_event(event) ⇒ Object
77
78
79
|
# File 'app/models/renalware/letters/letter.rb', line 77
def self.for_event(event)
where(event: event).first
end
|
.policy_class ⇒ Object
73
74
75
|
# File 'app/models/renalware/letters/letter.rb', line 73
def self.policy_class
LetterPolicy
end
|
Instance Method Details
#archive_recipients! ⇒ Object
128
129
130
|
# File 'app/models/renalware/letters/letter.rb', line 128
def archive_recipients!
recipients.each(&:archive!)
end
|
#archived? ⇒ Boolean
120
121
122
|
# File 'app/models/renalware/letters/letter.rb', line 120
def archived?
archive.present?
end
|
#archived_by ⇒ Object
124
125
126
|
# File 'app/models/renalware/letters/letter.rb', line 124
def archived_by
archive.created_by
end
|
#determine_counterpart_ccs ⇒ Object
112
113
114
|
# File 'app/models/renalware/letters/letter.rb', line 112
def determine_counterpart_ccs
DetermineCounterpartCCs.new(self).call
end
|
#effective_date ⇒ Object
132
133
134
|
# File 'app/models/renalware/letters/letter.rb', line 132
def effective_date
completed_at || approved_at || submitted_for_approval_at || created_at
end
|
108
109
110
|
# File 'app/models/renalware/letters/letter.rb', line 108
def find_cc_recipient_for_contact(contact)
cc_recipients.detect { |recipient| recipient.for_contact?(contact) }
end
|
#letter_event ⇒ Object
A Letter Event is unrelated to Events::Event. Instead it is an un-persisted decorator around the polymorphic event relationship (determined by event_class and event_id); each concrete Event class decorates that relationship with some helpers, for example #part_classes which determined which extra letter ‘parts’ should be rendered for that specific polymorphic relationship. Note that general clinical parts_classes are defined on Letter, because a relationship to say a ClinicVisit (the letter event) is not required for a letter to want to have clinical content (prescriptions etc.). Clinical parts will always be included if #clinical? is true. This for example enables us to create a ‘clinical letter’ which is a simple letter with the added clinical parts, but which is unrelated to a clinic_visit for instance.
100
101
102
|
# File 'app/models/renalware/letters/letter.rb', line 100
def letter_event
EVENTS_MAP.fetch(event.class).new(event, clinical: clinical?)
end
|
#signed? ⇒ Boolean
116
117
118
|
# File 'app/models/renalware/letters/letter.rb', line 116
def signed?
signature.present?
end
|
#subject?(other_patient) ⇒ Boolean
104
105
106
|
# File 'app/models/renalware/letters/letter.rb', line 104
def subject?(other_patient)
patient.id == other_patient.id
end
|