renalware-core 2.0.51 → 2.0.52

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/assets/stylesheets/renalware/application.scss +2 -1
  4. data/app/assets/stylesheets/renalware/base/_mixins.scss +3 -3
  5. data/app/assets/stylesheets/renalware/base/_variables.scss +33 -33
  6. data/app/assets/stylesheets/renalware/clipboard.scss +2 -2
  7. data/app/assets/stylesheets/renalware/hd_diary_pdf.scss +8 -8
  8. data/app/assets/stylesheets/renalware/lib/_foundation_and_overrides.scss +25 -25
  9. data/app/assets/stylesheets/renalware/lib/_select2-foundation5-overrides.scss +12 -0
  10. data/app/assets/stylesheets/renalware/modules/_admissions.scss +3 -3
  11. data/app/assets/stylesheets/renalware/modules/_clinical.scss +34 -33
  12. data/app/assets/stylesheets/renalware/modules/_clipboard.scss +3 -3
  13. data/app/assets/stylesheets/renalware/modules/_dashboard.scss +2 -2
  14. data/app/assets/stylesheets/renalware/modules/_events.scss +1 -1
  15. data/app/assets/stylesheets/renalware/modules/_feeds.scss +1 -1
  16. data/app/assets/stylesheets/renalware/modules/_hd.scss +44 -39
  17. data/app/assets/stylesheets/renalware/modules/_letters.scss +6 -6
  18. data/app/assets/stylesheets/renalware/modules/_medications.scss +15 -4
  19. data/app/assets/stylesheets/renalware/modules/_messaging.scss +2 -2
  20. data/app/assets/stylesheets/renalware/modules/_pathology.scss +24 -15
  21. data/app/assets/stylesheets/renalware/modules/_patients.scss +35 -29
  22. data/app/assets/stylesheets/renalware/modules/_pd.scss +10 -6
  23. data/app/assets/stylesheets/renalware/modules/_problems.scss +1 -1
  24. data/app/assets/stylesheets/renalware/modules/_renal.scss +3 -3
  25. data/app/assets/stylesheets/renalware/modules/_snippets.scss +29 -20
  26. data/app/assets/stylesheets/renalware/modules/_system.scss +11 -3
  27. data/app/assets/stylesheets/renalware/modules/_users.scss +5 -5
  28. data/app/assets/stylesheets/renalware/partials/_animation.scss +1 -0
  29. data/app/assets/stylesheets/renalware/partials/_animations.scss +1 -0
  30. data/app/assets/stylesheets/renalware/partials/_autocomplete.scss +5 -5
  31. data/app/assets/stylesheets/renalware/partials/_beta_banner.scss +1 -1
  32. data/app/assets/stylesheets/renalware/partials/_button.scss +2 -2
  33. data/app/assets/stylesheets/renalware/partials/_components.scss +1 -1
  34. data/app/assets/stylesheets/renalware/partials/_datepicker.scss +1 -1
  35. data/app/assets/stylesheets/renalware/partials/_disabled_block.scss +2 -2
  36. data/app/assets/stylesheets/renalware/partials/_document.scss +6 -6
  37. data/app/assets/stylesheets/renalware/partials/_editor.scss +11 -11
  38. data/app/assets/stylesheets/renalware/partials/_errors.scss +8 -6
  39. data/app/assets/stylesheets/renalware/partials/_forms.scss +27 -27
  40. data/app/assets/stylesheets/renalware/partials/_highlight.scss +1 -1
  41. data/app/assets/stylesheets/renalware/partials/_iframe.scss +1 -1
  42. data/app/assets/stylesheets/renalware/partials/_layout.scss +25 -23
  43. data/app/assets/stylesheets/renalware/partials/_lists.scss +8 -7
  44. data/app/assets/stylesheets/renalware/partials/_mdm.scss +3 -3
  45. data/app/assets/stylesheets/renalware/partials/_modal_window.scss +23 -21
  46. data/app/assets/stylesheets/renalware/partials/_navigation.scss +36 -36
  47. data/app/assets/stylesheets/renalware/partials/_patient_search.scss +2 -2
  48. data/app/assets/stylesheets/renalware/partials/_simple_form.scss +2 -2
  49. data/app/assets/stylesheets/renalware/partials/_tables.scss +48 -46
  50. data/app/assets/stylesheets/renalware/partials/_tabs.scss +8 -8
  51. data/app/assets/stylesheets/renalware/partials/_toggle.scss +3 -3
  52. data/app/assets/stylesheets/renalware/partials/_tooltip.scss +1 -342
  53. data/app/assets/stylesheets/renalware/partials/_typography.scss +4 -4
  54. data/app/assets/stylesheets/renalware/pdf.scss +7 -7
  55. data/app/assets/stylesheets/renalware/print/pathology_request_forms.scss +4 -4
  56. data/app/assets/stylesheets/renalware/protocol_pdf.scss +50 -42
  57. data/app/assets/stylesheets/renalware/table_pdf.scss +27 -24
  58. data/app/assets/stylesheets/renalware/watermark.scss +3 -3
  59. data/app/controllers/renalware/accesses/assessments_controller.rb +12 -19
  60. data/app/controllers/renalware/base_controller.rb +2 -0
  61. data/app/controllers/renalware/events/events_controller.rb +12 -11
  62. data/app/controllers/renalware/hd/current_profile_controller.rb +2 -8
  63. data/app/controllers/renalware/hd/mdm_patients_controller.rb +9 -3
  64. data/app/controllers/renalware/letters/electronic_receipts_controller.rb +0 -5
  65. data/app/controllers/renalware/letters/letters_controller.rb +0 -6
  66. data/app/controllers/renalware/low_clearance/profiles_controller.rb +1 -8
  67. data/app/controllers/renalware/patients/patients_controller.rb +5 -15
  68. data/app/controllers/renalware/pd/assessments_controller.rb +3 -16
  69. data/app/controllers/renalware/pd/training_sessions_controller.rb +6 -20
  70. data/app/controllers/renalware/renal/profiles_controller.rb +1 -9
  71. data/app/controllers/renalware/research/studies_controller.rb +3 -2
  72. data/app/controllers/renalware/research/study_participants_controller.rb +9 -3
  73. data/app/controllers/renalware/transplants/donor_workups_controller.rb +1 -10
  74. data/app/controllers/renalware/virology/dashboards_controller.rb +1 -1
  75. data/app/controllers/renalware/virology/profiles_controller.rb +1 -14
  76. data/app/helpers/renalware/admin_helper.rb +4 -0
  77. data/app/models/concerns/renalware/ordered_set_scope.rb +1 -1
  78. data/app/models/concerns/renalware/patient_pathology_scopes.rb +8 -2
  79. data/app/models/concerns/renalware/supersedeable.rb +10 -3
  80. data/app/models/renalware/admissions/consult_query.rb +14 -0
  81. data/app/models/renalware/hd/mdm_patients_form.rb +8 -1
  82. data/app/models/renalware/letters/electronic_recipient_options.rb +11 -3
  83. data/app/models/renalware/letters/letter.rb +3 -3
  84. data/app/models/renalware/letters/printing/create_pdf_by_interleaving_address_sheet_and_letter_for_each_recipient.rb +1 -0
  85. data/app/models/renalware/letters/recipient.rb +12 -1
  86. data/app/models/renalware/low_clearance.rb +1 -1
  87. data/app/models/renalware/low_clearance/mdm_patients_query.rb +3 -1
  88. data/app/models/renalware/messaging.rb +0 -4
  89. data/app/models/renalware/messaging/internal/recipient_options.rb +14 -4
  90. data/app/models/renalware/pathology/observation_descriptions_by_code_query.rb +1 -1
  91. data/app/models/renalware/pathology/ordered_patient_query.rb +1 -1
  92. data/app/models/renalware/research/study_participant.rb +2 -0
  93. data/app/models/renalware/research/study_participants_query.rb +20 -0
  94. data/app/models/renalware/transplants/registrations/wait_list_query.rb +14 -0
  95. data/app/models/renalware/ukrdc/send_patients.rb +1 -13
  96. data/app/models/renalware/user.rb +4 -1
  97. data/app/policies/renalware/virology/{dasboard_policy.rb → dashboard_policy.rb} +0 -0
  98. data/app/presenters/renalware/letters/letter_presenter.rb +24 -6
  99. data/app/presenters/renalware/transplants/consent_presenter.rb +2 -1
  100. data/app/values/renalware/address.rb +1 -1
  101. data/app/views/renalware/admin/users/_tabs.html.slim +4 -2
  102. data/app/views/renalware/admissions/consults/_table.html.slim +1 -2
  103. data/app/views/renalware/api/ukrdc/patients/_allergies.xml.builder +1 -1
  104. data/app/views/renalware/api/ukrdc/patients/_diagnoses.xml.builder +8 -3
  105. data/app/views/renalware/api/ukrdc/patients/_documents.xml.builder +1 -1
  106. data/app/views/renalware/events/swabs/_list.html.slim +1 -1
  107. data/app/views/renalware/hd/current_profile/_form.html.slim +25 -21
  108. data/app/views/renalware/hd/mdm_patients/_filters.html.slim +9 -4
  109. data/app/views/renalware/letters/letters/_additional_ccs.html.slim +5 -4
  110. data/app/views/renalware/letters/letters/edit.html.slim +1 -0
  111. data/app/views/renalware/letters/letters/new.html.slim +1 -1
  112. data/app/views/renalware/patients/patients/edit.html.slim +2 -2
  113. data/app/views/renalware/renal/registry_preflight_checks/_filters.html.slim +3 -3
  114. data/app/views/renalware/renal/registry_preflight_checks/_table.html.slim +9 -5
  115. data/app/views/renalware/renal/registry_preflight_checks/deaths.html.slim +1 -1
  116. data/app/views/renalware/reporting/report_mailer/daily_summary.html.slim +2 -1
  117. data/app/views/renalware/research/studies/_filters.html.slim +14 -0
  118. data/app/views/renalware/research/studies/index.html.slim +7 -4
  119. data/app/views/renalware/research/study_participants/_filters.html.slim +13 -0
  120. data/app/views/renalware/research/study_participants/_table.html.slim +2 -2
  121. data/app/views/renalware/research/study_participants/create.js.erb +1 -1
  122. data/app/views/renalware/research/study_participants/index.html.slim +4 -1
  123. data/app/views/renalware/research/study_participants/update.js.erb +1 -1
  124. data/app/views/renalware/shared/documents/_year_dated_confirmation_input.html.slim +1 -1
  125. data/app/views/renalware/transplants/wait_lists/show.html.slim +2 -2
  126. data/db/migrate/20181008144324_update_daily_letters_report_view_to_version_2.rb +13 -0
  127. data/db/migrate/20181008145159_create_reporting_daily_ukrdc_view.rb +11 -0
  128. data/db/migrate/20181013115138_update_reporting_daily_pathology_view_to_v2.rb +13 -0
  129. data/db/views/reporting_daily_letters_v02.sql +4 -0
  130. data/db/views/reporting_daily_pathology_v02.sql +18 -0
  131. data/db/views/reporting_daily_ukrdc_v01.sql +2 -0
  132. data/lib/migration_helper.rb +11 -0
  133. data/lib/renalware/version.rb +1 -1
  134. data/lib/sql/{index_case_stmt.rb → indexed_case_stmt.rb} +2 -2
  135. data/lib/tasks/ukrdc.rake +2 -1
  136. data/spec/factories/patients/practices.rb +2 -1
  137. data/spec/factories/patients/primary_care_physicians.rb +1 -1
  138. data/spec/support/pages/admissions/consults_page.rb +26 -0
  139. data/spec/support/pages/page_object.rb +10 -0
  140. data/spec/support/shared_examples/paranoia_examples.rb +2 -2
  141. data/vendor/assets/stylesheets/renalware/balloon.css +383 -0
  142. data/{app/assets/stylesheets/renalware/lib/_select2-foundation5.scss → vendor/assets/stylesheets/renalware/select2-foundation5.css} +180 -78
  143. metadata +26 -37
  144. data/app/models/renalware/clinics/consultant.rb +0 -10
  145. data/app/models/renalware/events/patient_listener.rb +0 -10
  146. data/app/models/renalware/letters/discharge_summary.rb +0 -10
  147. data/app/presenters/renalware/clinical/body_composition_presenter.rb +0 -11
  148. data/app/presenters/renalware/pathology/patient_presenter.rb +0 -13
  149. data/app/presenters/renalware/pathology/requests/global_rule_presenter.rb +0 -15
  150. data/app/views/renalware/events/types/_header.html.slim.dead +0 -4
  151. data/app/views/renalware/modalities/descriptions/_header.html.slim.dead +0 -5
  152. data/app/views/renalware/transplants/mdm_patients/_filters.html.slim.dead +0 -8
  153. data/config/locales/renalware/reporting/reporting_daily.en.yml +0 -7
@@ -36,16 +36,7 @@ module Renalware
36
36
  private
37
37
 
38
38
  def workup_params
39
- params
40
- .require(:transplants_donor_workup)
41
- .permit
42
- .merge(document: document_attributes)
43
- end
44
-
45
- def document_attributes
46
- params
47
- .require(:transplants_donor_workup)
48
- .fetch(:document, nil).try(:permit!)
39
+ params.require(:transplants_donor_workup).permit(document: {})
49
40
  end
50
41
  end
51
42
  end
@@ -6,7 +6,7 @@ module Renalware
6
6
  module Virology
7
7
  class DashboardsController < BaseController
8
8
  def show
9
- authorize patient
9
+ authorize [:renalware, :virology, :dashboard], :show?
10
10
  render locals: {
11
11
  patient: patient,
12
12
  vaccinations: Vaccination.for_patient(patient)
@@ -42,20 +42,7 @@ module Renalware
42
42
  end
43
43
 
44
44
  def profile_params
45
- params
46
- .require(:virology_profile)
47
- .permit(attributes)
48
- .merge(document: document_attributes)
49
- end
50
-
51
- def attributes
52
- [
53
- document: []
54
- ]
55
- end
56
-
57
- def document_attributes
58
- params.require(:virology_profile).fetch(:document, nil).try(:permit!)
45
+ params.require(:virology_profile).permit(document: {})
59
46
  end
60
47
  end
61
48
  end
@@ -9,5 +9,9 @@ module Renalware
9
9
  def admin_inactive_users_path
10
10
  admin_users_path(q: { inactive: true })
11
11
  end
12
+
13
+ def admin_expired_users_path
14
+ admin_users_path(q: { expired: true })
15
+ end
12
16
  end
13
17
  end
@@ -32,7 +32,7 @@ module Renalware
32
32
  verified_values = verify_values(attribute, values.map(&:to_s))
33
33
 
34
34
  where(attribute => verified_values)
35
- .order("CASE #{generate_conditions(attribute, values.uniq)} END")
35
+ .order(Arel.sql("CASE #{generate_conditions(attribute, values.uniq)} END"))
36
36
  end
37
37
 
38
38
  private
@@ -43,15 +43,21 @@ module Renalware
43
43
  # so should rise above them when sorted
44
44
  # 3. Nulls (mapped to -1)
45
45
  def self.pathology_result_sort_predicate(column)
46
+ sanitized_column = Arel.sql(sanitize(column.to_s.upcase))
46
47
  Arel.sql(
47
- "coalesce(convert_to_float(values -> '#{column.upcase}' ->> 'result'), -1)"
48
+ "coalesce(convert_to_float(values -> #{sanitized_column} ->> 'result'), -1)"
48
49
  )
49
50
  end
50
51
 
51
52
  def self.pathology_date_sort_predicate(column)
53
+ sanitized_column = Arel.sql(sanitize(column.to_s.upcase))
52
54
  Arel.sql(
53
- "cast(values -> '#{column.upcase}' ->> 'observed_at' as date)"
55
+ "cast(values -> #{sanitized_column} ->> 'observed_at' as date)"
54
56
  )
55
57
  end
58
+
59
+ def self.sanitize(sql)
60
+ ActiveRecord::Base.connection.quote(sql)
61
+ end
56
62
  end
57
63
  end
@@ -23,18 +23,26 @@ module Renalware
23
23
  with_deleted
24
24
  end
25
25
 
26
+ # Make a deep copy of the current object (self) into a successor, and update it with any
27
+ # changes. Mark self as deleted.
28
+ # Note 'update' callbacks will not be called on our successor until it has been saved first.
29
+ # So we save the copy without any modifictions first, so that on a subsequent update!
30
+ # the update callbacks in the Accountable module will be called and if the
31
+ # caller of this fn has supplied :by in attrs, it will cause the updated_by_id
32
+ # column to be updated. Its a bit odd saving twice, but required here.
33
+ # Without this 2 phase save, updated_by_id (if present) will remain at whatever it was
34
+ # set at to in the object we are superceding.
26
35
  def supersede!(attrs = {})
27
36
  attrs = attrs.to_h unless attrs.is_a?(Hash)
28
37
  transaction do
29
38
  successor = dup
30
39
  destroy!
31
- successor.assign_attributes(attrs) if attrs.any?
32
40
  successor.save!
41
+ successor.update!(attrs) if attrs.any?
33
42
  successor
34
43
  end
35
44
  end
36
45
 
37
- # Unused?
38
46
  def paranoia_restore_attributes
39
47
  {
40
48
  deactivated_at: nil,
@@ -42,7 +50,6 @@ module Renalware
42
50
  }
43
51
  end
44
52
 
45
- # Unused
46
53
  def paranoia_destroy_attributes
47
54
  {
48
55
  deactivated_at: current_time_from_proper_timezone,
@@ -23,9 +23,11 @@ module Renalware
23
23
  # included in the model file.
24
24
  # note that adding .includes(:created_by) her creates an ambigous column
25
25
  # 'family_name' error
26
+ # rubocop:disable Metrics/MethodLength
26
27
  def search
27
28
  @search ||= begin
28
29
  Consult
30
+ .extend(RansackScopes)
29
31
  .joins(:patient)
30
32
  .eager_load(patient: [current_modality: :description])
31
33
  .includes(
@@ -37,6 +39,18 @@ module Renalware
37
39
  .ransack(query)
38
40
  end
39
41
  end
42
+ # rubocop:enable Metrics/MethodLength
43
+
44
+ module RansackScopes
45
+ def self.extended(base)
46
+ # Using a custom ransacker here in order to sort by modality description name
47
+ # because using a predicate like :patient_current_modality_description_name
48
+ # results in an INNER JOIN onto modalities.
49
+ base.ransacker :modality_desc do
50
+ Arel.sql("modality_descriptions.name")
51
+ end
52
+ end
53
+ end
40
54
  end
41
55
  end
42
56
  end
@@ -12,16 +12,23 @@ module Renalware
12
12
  include Virtus::Model
13
13
 
14
14
  attribute :hospital_unit_id, Integer
15
+ attribute :named_nurse_id, Integer
15
16
  attribute :schedule_definition_ids, String # an Integer array in string form e.g. "[1 ,2]"
16
17
 
17
18
  # The hash returned here is passed into the Ransack #search method later i the ouery object.
18
19
  def ransacked_parameters
19
20
  {
20
21
  hd_profile_hospital_unit_id_eq: hospital_unit_id,
21
- hd_profile_schedule_definition_id_in: schedule_definition_ids_array
22
+ hd_profile_schedule_definition_id_in: schedule_definition_ids_array,
23
+ hd_profile_named_nurse_id_eq: named_nurse_id
22
24
  }
23
25
  end
24
26
 
27
+ # StrongParameter support. Called by a controller when whitelisting params.
28
+ def self.permittable_attributes
29
+ attribute_set.map(&:name)
30
+ end
31
+
25
32
  private
26
33
 
27
34
  # Convert e.g. "[1,2,3]" to [1,2,3]
@@ -46,7 +46,8 @@ module Renalware
46
46
 
47
47
  def all_other_users
48
48
  ids_to_exclude = ids_of_users_having_previously_received_been_cced_about_this_patient +
49
- ids_of_users_having_recently_been_cced_by_author
49
+ ids_of_users_having_recently_been_cced_by_author +
50
+ ids_of_excludable_users
50
51
  Group.new(
51
52
  name: "All other user",
52
53
  users: User.where.not(id: ids_to_exclude)
@@ -55,13 +56,14 @@ module Renalware
55
56
 
56
57
  def ids_of_users_having_previously_received_been_cced_about_this_patient
57
58
  @ids_of_users_having_previously_received_been_cced_about_this_patient ||= begin
58
- Letter
59
+ ids = Letter
59
60
  .includes(:electronic_receipts)
60
61
  .eager_load(:electronic_receipts)
61
62
  .where(patient: patient)
62
63
  .limit(20)
63
64
  .pluck(:recipient_id)
64
65
  .flatten.uniq.compact
66
+ ids - ids_of_excludable_users
65
67
  end
66
68
  end
67
69
 
@@ -72,9 +74,15 @@ module Renalware
72
74
  .where(author: author)
73
75
  .limit(20)
74
76
  .pluck(:recipient_id).uniq.compact
75
- ids - ids_of_users_having_previously_received_been_cced_about_this_patient
77
+ ids -
78
+ ids_of_users_having_previously_received_been_cced_about_this_patient -
79
+ ids_of_excludable_users
76
80
  end
77
81
  end
82
+
83
+ def ids_of_excludable_users
84
+ User.excludable.pluck(:id)
85
+ end
78
86
  end
79
87
  end
80
88
  end
@@ -56,8 +56,8 @@ module Renalware
56
56
  }
57
57
  singleton_class.send(:alias_method, :in_progress, :pending)
58
58
 
59
- scope :reversed, -> { order("#{effective_date_sort} asc") }
60
- scope :ordered, -> { order("#{effective_date_sort} desc") }
59
+ scope :reversed, -> { order(Arel.sql(effective_date_sort) => :asc) }
60
+ scope :ordered, -> { order(Arel.sql(effective_date_sort) => :desc) }
61
61
  scope :with_letterhead, -> { includes(:letterhead) }
62
62
  scope :with_main_recipient, -> { includes(main_recipient: [:address, :addressee]) }
63
63
  scope :with_author, -> { includes(:author) }
@@ -79,7 +79,7 @@ module Renalware
79
79
  end
80
80
 
81
81
  def self.effective_date_sort
82
- "coalesce(completed_at, approved_at, submitted_for_approval_at, created_at)"
82
+ Arel.sql("coalesce(completed_at, approved_at, submitted_for_approval_at, created_at)")
83
83
  end
84
84
 
85
85
  EVENTS_MAP = {
@@ -64,6 +64,7 @@ module Renalware
64
64
  if letter.page_count.to_i < 1
65
65
  raise(ArgumentError, "letter.page_count not set on letter.id=#{letter.id}")
66
66
  end
67
+
67
68
  letter_filename = create_letter_pdf_in(dir, letter)
68
69
  files << letter_filename
69
70
  end
@@ -20,7 +20,18 @@ module Renalware
20
20
 
21
21
  validates :addressee_id, presence: { if: :contact? }
22
22
 
23
- delegate :primary_care_physician?, :patient?, :contact?, to: :person_role
23
+ validate :person_role_present?
24
+
25
+ # Check we have a person_role. If we don't add an error to the parent letter if one is
26
+ # present, otherwise add to our errors.
27
+ def person_role_present?
28
+ return if person_role.present?
29
+
30
+ errs = letter&.errors || errors
31
+ errs.add(:base, "Please select a main recipient")
32
+ end
33
+
34
+ delegate :primary_care_physician?, :patient?, :contact?, to: :person_role, allow_nil: true
24
35
 
25
36
  def to_s
26
37
  (address || current_address).to_s
@@ -4,7 +4,7 @@ require_dependency "renalware"
4
4
 
5
5
  module Renalware
6
6
  module LowClearance
7
- MDM_FILTERS = %w(urea hgb_low hgb_high on_worryboard supportive_care).freeze
7
+ MDM_FILTERS = %w(urea hgb_low hgb_high on_worryboard supportive_care tx_candidates).freeze
8
8
 
9
9
  def self.table_name_prefix
10
10
  "low_clearance_"
@@ -20,6 +20,7 @@ module Renalware
20
20
  search.result
21
21
  end
22
22
 
23
+ # rubocop:disable Metrics/MethodLength
23
24
  def search
24
25
  @search ||= begin
25
26
  relation
@@ -35,6 +36,7 @@ module Renalware
35
36
  .search(query)
36
37
  end
37
38
  end
39
+ # rubocop:enable Metrics/MethodLength
38
40
 
39
41
  module NamedFilterScopes
40
42
  def none
@@ -51,7 +53,7 @@ module Renalware
51
53
  end
52
54
 
53
55
  def tx_candidates
54
- self
56
+ where("transplant_registration_status_descriptions.code not ilike '%permanent'")
55
57
  end
56
58
 
57
59
  def urea
@@ -18,10 +18,6 @@ module Renalware
18
18
  ActiveType.cast(author, ::Renalware::Messaging::Author)
19
19
  end
20
20
 
21
- # def cast_recipient(recipient)
22
- # ActiveType.cast(recipient, ::Renalware::Messaging::Recipient)
23
- # end
24
-
25
21
  module Internal
26
22
  module_function
27
23
 
@@ -54,7 +54,9 @@ module Renalware
54
54
 
55
55
  def all_other_users
56
56
  ids_to_exclude = ids_of_users_having_received_a_message_about_patient +
57
- ids_of_users_having_received_messages_from_author
57
+ ids_of_users_having_received_messages_from_author +
58
+ ids_of_excludable_users
59
+
58
60
  Group.new(
59
61
  name: "All other users",
60
62
  users: Recipient.where.not(id: ids_to_exclude)
@@ -63,26 +65,34 @@ module Renalware
63
65
 
64
66
  def ids_of_users_having_received_a_message_about_patient
65
67
  @ids_of_users_having_received_a_message_about_patient ||= begin
66
- Message
68
+ ids = Message
67
69
  .includes(:receipts)
68
70
  .eager_load(:receipts)
69
71
  .where(patient: patient)
70
72
  .limit(20)
71
73
  .pluck(:author_id, :recipient_id)
72
74
  .flatten.uniq.compact
75
+ ids - ids_of_excludable_users
73
76
  end
74
77
  end
75
78
 
76
79
  def ids_of_users_having_received_messages_from_author
77
80
  @ids_of_users_having_received_messages_from_author ||= begin
78
81
  ids = Message
79
- .includes(:receipts).eager_load(:receipts)
82
+ .includes(:receipts)
83
+ .eager_load(:receipts)
80
84
  .where(author: author)
81
85
  .limit(20)
82
86
  .pluck(:recipient_id).uniq.compact
83
- ids - ids_of_users_having_received_a_message_about_patient
87
+ ids -
88
+ ids_of_users_having_received_a_message_about_patient -
89
+ ids_of_excludable_users
84
90
  end
85
91
  end
92
+
93
+ def ids_of_excludable_users
94
+ User.excludable.pluck(:id)
95
+ end
86
96
  end
87
97
  end
88
98
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_dependency "renalware/pathology"
4
- require "sql/index_case_stmt"
4
+ require "sql/indexed_case_stmt"
5
5
 
6
6
  module Renalware
7
7
  module Pathology
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_dependency "renalware/pathology"
4
- require "sql/index_case_stmt"
4
+ require "sql/indexed_case_stmt"
5
5
 
6
6
  module Renalware
7
7
  module Pathology
@@ -6,6 +6,8 @@ module Renalware
6
6
  module Research
7
7
  class StudyParticipant < ApplicationRecord
8
8
  include Accountable
9
+ include PatientsRansackHelper
10
+
9
11
  acts_as_paranoid
10
12
  validates :participant_id, presence: true, uniqueness: { scope: :study }
11
13
  validates :study, presence: true
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "renalware/research"
4
+ require "attr_extras"
5
+
6
+ module Renalware
7
+ module Research
8
+ class StudyParticipantsQuery
9
+ pattr_initialize [:study!, :options!]
10
+
11
+ def call
12
+ search.result
13
+ end
14
+
15
+ def search
16
+ study.participants.joins(:patient).eager_load(:patient).ransack(options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -123,6 +123,20 @@ module Renalware
123
123
  Arel.sql("renal_profiles.esrf_on")
124
124
  end
125
125
 
126
+ # TODO: move ransacker to Renal namespace
127
+ ransacker :patient_current_status_description_name do
128
+ Arel.sql("transplant_registration_status_descriptions.name")
129
+ end
130
+
131
+ ransacker :ukt_status do
132
+ Arel.sql(<<-SQL)
133
+ COALESCE(
134
+ transplant_registrations.document -> 'uk_transplant_centre' ->> 'status',
135
+ ''
136
+ )
137
+ SQL
138
+ end
139
+
126
140
  private_class_method :ransackable_scopes
127
141
 
128
142
  def self.ransackable_scopes(_auth_object = nil)