Class: Renalware::MDMPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/renalware/mdm_presenter.rb

Constant Summary collapse

NullAccess =
Naught.build do |config|
  config.black_hole
  config.define_explicit_conversions
  config.singleton
  config.predicates_return false
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patient:, view_context:) ⇒ MDMPresenter

Returns a new instance of MDMPresenter.



17
18
19
20
# File 'app/presenters/renalware/mdm_presenter.rb', line 17

def initialize(patient:, view_context:)
  @patient = patient
  @view_context = view_context
end

Instance Attribute Details

#patientObject (readonly)

Returns the value of attribute patient.



15
16
17
# File 'app/presenters/renalware/mdm_presenter.rb', line 15

def patient
  @patient
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



15
16
17
# File 'app/presenters/renalware/mdm_presenter.rb', line 15

def view_context
  @view_context
end

Instance Method Details

#accessObject



136
137
138
139
140
141
142
143
144
145
# File 'app/presenters/renalware/mdm_presenter.rb', line 136

def access
  @access ||= begin
    access_profile = Renalware::Accesses.cast_patient(patient).current_profile
    if access_profile.present?
      Accesses::ProfilePresenter.new(access_profile)
    else
      NullAccess.instance
    end
  end
end

#clinic_visits(limit: 6) ⇒ Object



35
36
37
38
39
40
41
# File 'app/presenters/renalware/mdm_presenter.rb', line 35

def clinic_visits(limit: 6)
  @clinic_visits ||= Clinics::ClinicVisit.for_patient(patient)
                                         .includes(:clinic)
                                         .with_created_by
                                         .ordered
                                         .limit(limit)
end

#clinic_visits_having_measurements(limit: 3) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/presenters/renalware/mdm_presenter.rb', line 43

def clinic_visits_having_measurements(limit: 3)
  @clinic_visits_having_measurements ||= begin
    Clinics::ClinicVisit
      .for_patient(patient)
      .where("height is not null "\
             "or weight is not null "\
             "or systolic_bp is not null "\
             "or diastolic_bp is not null")
      .ordered
      .limit(limit)
  end
end

#current_immunosuppressant_prescriptionsObject



66
67
68
69
70
71
72
# File 'app/presenters/renalware/mdm_presenter.rb', line 66

def current_immunosuppressant_prescriptions
  @current_immunosuppressant_prescriptions ||= begin
    execute_prescriptions_query(
      patient.prescriptions.having_drug_of_type(:immunosuppressant).current
    )
  end
end

#current_pathology_for_code(code) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'app/presenters/renalware/mdm_presenter.rb', line 118

def current_pathology_for_code(code)
  result = OpenStruct.new(value: nil, date: nil)
  hash = patient.current_observation_set&.values_for_codes(code) || {}
  obs = hash[code]
  if obs.present?
    result.value = obs["result"]
    result.date = obs["observed_at"]
    result.date = Date.parse(result.date)
  end
  result
end

#current_prescriptionsObject



60
61
62
63
64
# File 'app/presenters/renalware/mdm_presenter.rb', line 60

def current_prescriptions
  @current_prescriptions ||= begin
    execute_prescriptions_query(patient.prescriptions.current)
  end
end

#current_problemsObject



93
94
95
# File 'app/presenters/renalware/mdm_presenter.rb', line 93

def current_problems
  @current_problems ||= patient.problems.current.limit(6).with_created_by.ordered
end

#current_transplant_statusObject



130
131
132
133
134
# File 'app/presenters/renalware/mdm_presenter.rb', line 130

def current_transplant_status
  @current_transplant_status ||= begin
    Renalware::Transplants::Registration.for_patient(patient).first&.current_status
  end
end

#esa_prescriptionsObject

Note we sort prescriptions by prescribed_on desc here manually because the prescriptions query is currently too complex to add another sql sort into (defaults) to sorting by drug name



85
86
87
88
89
90
91
# File 'app/presenters/renalware/mdm_presenter.rb', line 85

def esa_prescriptions
  @esa_prescriptions ||= begin
    execute_prescriptions_query(
      patient.prescriptions.having_drug_of_type("esa")
    ).sort_by(&:prescribed_on).reverse!
  end
end

#events_of_type(type: nil) ⇒ Object Also known as: events

rubocop:disable Lint/UnusedMethodArgument



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

def events_of_type(type: nil)
  Events::Event.for_patient(patient).includes([:created_by, :event_type]).limit(6).ordered
end

#historical_immunosuppressant_prescriptionsObject



74
75
76
77
78
79
80
# File 'app/presenters/renalware/mdm_presenter.rb', line 74

def historical_immunosuppressant_prescriptions
  @historical_immunosuppressant_prescriptions ||= begin
    execute_prescriptions_query(
      patient.prescriptions.having_drug_of_type(:immunosuppressant)
    )
  end
end

#historical_prescriptionsObject



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

def historical_prescriptions
  @historical_prescriptions ||= execute_prescriptions_query(patient.prescriptions)
end

#lettersObject



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/presenters/renalware/mdm_presenter.rb', line 104

def letters
  patient_ = Renalware::Letters.cast_patient(patient)
  letters_ = patient_.letters
                     .ordered
                     .with_main_recipient
                     .with_letterhead
                     .with_author
                     .with_event
                     .with_patient
                     .limit(6)

  CollectionPresenter.new(letters_, Renalware::Letters::LetterPresenterFactory)
end

#pathologyObject



22
23
24
# File 'app/presenters/renalware/mdm_presenter.rb', line 22

def pathology
  @pathology ||= pathology_for_codes
end

#pathology_for_codes(codes = nil, per_page: 10, page: 1) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/presenters/renalware/mdm_presenter.rb', line 26

def pathology_for_codes(codes = nil, per_page: 10, page: 1)
  Pathology::CreateObservationsGroupedByDateTable.new(
    patient: patient,
    observation_descriptions: pathology_descriptions_for_codes(codes),
    page: page,
    per_page: per_page
  ).call
end