Class: Renalware::UKRDC::PatientPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Renalware::UKRDC::PatientPresenter
- Defined in:
- app/presenters/renalware/ukrdc/patient_presenter.rb
Instance Attribute Summary collapse
-
#changes_since ⇒ Object
readonly
Returns the value of attribute changes_since.
-
#changes_up_until ⇒ Object
readonly
Returns the value of attribute changes_up_until.
Instance Method Summary collapse
- #allergies ⇒ Object
- #clinic_visits ⇒ Object
- #contact_details? ⇒ Boolean
- #current_modality_hd? ⇒ Boolean
- #current_registration_status_rr_code ⇒ Object
- #dead? ⇒ Boolean
- #finished_hd_sessions ⇒ Object
- #hospital_unit_code ⇒ Object
-
#initialize(patient, changes_since: nil) ⇒ PatientPresenter
constructor
A new instance of PatientPresenter.
- #language ⇒ Object
- #letters ⇒ Object
- #observation_requests ⇒ Object
- #prescriptions ⇒ Object
- #smoking_history ⇒ Object
Constructor Details
#initialize(patient, changes_since: nil) ⇒ PatientPresenter
Returns a new instance of PatientPresenter.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 14 def initialize(patient, changes_since: nil) if changes_since.present? && changes_since.is_a?(String) changes_since = Time.zone.parse(changes_since) end # TODO: document what's happening here with dates @changes_since = changes_since || patient.sent_to_ukrdc_at || Renalware.config.ukrdc_default_changes_since_date if @changes_since.blank? raise( ArgumentError, "No date for comparison: patient#sent_to_ukrdc_at and changes_since are nil" ) end @changes_up_until = Time.zone.now super(patient) end |
Instance Attribute Details
#changes_since ⇒ Object (readonly)
Returns the value of attribute changes_since.
8 9 10 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 8 def changes_since @changes_since end |
#changes_up_until ⇒ Object (readonly)
Returns the value of attribute changes_up_until.
8 9 10 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 8 def changes_up_until @changes_up_until end |
Instance Method Details
#allergies ⇒ Object
84 85 86 87 88 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 84 def allergies clinical_patient .allergies .where("recorded_at >= ?", changes_since) end |
#clinic_visits ⇒ Object
90 91 92 93 94 95 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 90 def clinic_visits clinics_patient .clinic_visits .where("date >= ?", changes_since) .includes(:updated_by) end |
#contact_details? ⇒ Boolean
80 81 82 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 80 def contact_details? email.present? || home_telephone.present? || mobile_telephone.present? end |
#current_modality_hd? ⇒ Boolean
42 43 44 45 46 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 42 def current_modality_hd? return false if current_modality.blank? current_modality.description.is_a?(Renalware::HD::ModalityDescription) end |
#current_registration_status_rr_code ⇒ Object
69 70 71 72 73 74 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 69 def current_registration_status_rr_code @current_registration_status_rr_code ||= begin status = transplant_patient.current_registration_status status&.description&.rr_code end end |
#dead? ⇒ Boolean
38 39 40 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 38 def dead? current_modality_death? end |
#finished_hd_sessions ⇒ Object
62 63 64 65 66 67 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 62 def finished_hd_sessions hd_patient .finished_hd_sessions .includes(:patient, :dialysate) .where("hd_sessions.updated_at > ?", changes_since) end |
#hospital_unit_code ⇒ Object
76 77 78 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 76 def hospital_unit_code letter_head.site_code end |
#language ⇒ Object
32 33 34 35 36 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 32 def language return if super.nil? || super.name == "Unknown" super end |
#letters ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 52 def letters CollectionPresenter.new( letters_patient .letters .approved_or_completed .where("updated_at > ?", changes_since), Renalware::Letters::LetterPresenterFactory ) end |
#observation_requests ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 103 def observation_requests pathology_patient .observation_requests .eager_load( :description, observations: { description: :measurement_unit } ) .where(patient_id: id) .where("requested_at >= ?", changes_since) .where("loinc_code is not null") end |
#prescriptions ⇒ Object
97 98 99 100 101 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 97 def prescriptions __getobj__.prescriptions .includes(:termination, :medication_route, :drug) .where("updated_at > ?", changes_since) end |
#smoking_history ⇒ Object
48 49 50 |
# File 'app/presenters/renalware/ukrdc/patient_presenter.rb', line 48 def smoking_history @smoking_history ||= document.history&.smoking&.upcase end |