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
82
83
84
|
# File 'app/models/renalware/letters/letter.rb', line 82
def self.effective_date_sort
Arel.sql("coalesce(completed_at, approved_at, submitted_for_approval_at, created_at)")
end
|
.for_event(event) ⇒ Object
78
79
80
|
# File 'app/models/renalware/letters/letter.rb', line 78
def self.for_event(event)
where(event: event).first
end
|
.policy_class ⇒ Object
74
75
76
|
# File 'app/models/renalware/letters/letter.rb', line 74
def self.policy_class
LetterPolicy
end
|
Instance Method Details
#archive_recipients! ⇒ Object
129
130
131
|
# File 'app/models/renalware/letters/letter.rb', line 129
def archive_recipients!
recipients.each(&:archive!)
end
|
#archived? ⇒ Boolean
121
122
123
|
# File 'app/models/renalware/letters/letter.rb', line 121
def archived?
archive.present?
end
|
#archived_by ⇒ Object
125
126
127
|
# File 'app/models/renalware/letters/letter.rb', line 125
def archived_by
archive.created_by
end
|
#determine_counterpart_ccs ⇒ Object
113
114
115
|
# File 'app/models/renalware/letters/letter.rb', line 113
def determine_counterpart_ccs
DetermineCounterpartCCs.new(self).call
end
|
#effective_date ⇒ Object
133
134
135
|
# File 'app/models/renalware/letters/letter.rb', line 133
def effective_date
completed_at || approved_at || submitted_for_approval_at || created_at
end
|
109
110
111
|
# File 'app/models/renalware/letters/letter.rb', line 109
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.
101
102
103
|
# File 'app/models/renalware/letters/letter.rb', line 101
def letter_event
EVENTS_MAP.fetch(event.class).new(event, clinical: clinical?)
end
|
#signed? ⇒ Boolean
117
118
119
|
# File 'app/models/renalware/letters/letter.rb', line 117
def signed?
signature.present?
end
|
#subject?(other_patient) ⇒ Boolean
105
106
107
|
# File 'app/models/renalware/letters/letter.rb', line 105
def subject?(other_patient)
patient.id == other_patient.id
end
|