renalware-core 2.0.0.pre.beta7 → 2.0.0.pre.beta8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/renalware/searchables.js +3 -0
- data/app/assets/javascripts/renalware/select2-ajax-search.js +86 -0
- data/app/assets/javascripts/renalware/sortable.js +12 -1
- data/app/assets/stylesheets/renalware/base/_variables.scss +7 -1
- data/app/assets/stylesheets/renalware/modules/_admissions.scss +39 -0
- data/app/assets/stylesheets/renalware/modules/_letters.scss +12 -0
- data/app/assets/stylesheets/renalware/modules/_messaging.scss +0 -4
- data/app/assets/stylesheets/renalware/partials/_animations.scss +12 -0
- data/app/assets/stylesheets/renalware/partials/_modal_window.scss +44 -0
- data/app/assets/stylesheets/renalware/partials/_tables.scss +6 -0
- data/app/controllers/renalware/admissions/requests_controller.rb +100 -0
- data/app/controllers/renalware/devise/passwords_controller.rb +6 -0
- data/app/controllers/renalware/letters/electronic_receipts_controller.rb +81 -0
- data/app/controllers/renalware/letters/letters_controller.rb +18 -3
- data/app/controllers/renalware/messaging/internal/messages_controller.rb +75 -0
- data/app/controllers/renalware/messaging/internal/receipts_controller.rb +74 -0
- data/app/controllers/renalware/patients/patients_controller.rb +11 -1
- data/app/controllers/renalware/session_timeout_controller.rb +1 -1
- data/app/documents/renalware/hd/profile_document.rb +1 -1
- data/app/helpers/renalware/application_helper.rb +5 -0
- data/app/helpers/renalware/xhr_helper.rb +7 -0
- data/app/models/concerns/renalware/deviseable.rb +1 -1
- data/app/models/renalware/admissions.rb +7 -0
- data/app/models/renalware/admissions/request.rb +23 -0
- data/app/models/renalware/admissions/request_reason.rb +11 -0
- data/app/models/renalware/feeds/message_processor.rb +2 -2
- data/app/models/renalware/feeds/persist_message.rb +2 -0
- data/app/models/renalware/hd/sessions/auditable_session.rb +4 -0
- data/app/models/renalware/hd/sessions/auditable_session_collection.rb +5 -0
- data/app/models/renalware/hd/update_rolling_patient_statistics.rb +2 -2
- data/app/models/renalware/letters/electronic_receipt.rb +35 -0
- data/app/models/renalware/letters/electronic_recipient_options.rb +78 -0
- data/app/models/renalware/letters/letter.rb +4 -0
- data/app/models/renalware/letters/letter_factory.rb +21 -1
- data/app/models/renalware/messaging.rb +21 -5
- data/app/models/renalware/messaging/internal/author.rb +11 -0
- data/app/models/renalware/messaging/internal/message.rb +15 -0
- data/app/models/renalware/messaging/internal/message_factory.rb +20 -0
- data/app/models/renalware/messaging/internal/message_form.rb +36 -0
- data/app/models/renalware/messaging/internal/message_form_builder.rb +52 -0
- data/app/models/renalware/messaging/internal/receipt.rb +26 -0
- data/app/models/renalware/messaging/internal/recipient.rb +12 -0
- data/app/models/renalware/messaging/internal/recipient_options.rb +87 -0
- data/app/models/renalware/messaging/internal/send_message.rb +24 -0
- data/app/models/renalware/messaging/message.rb +4 -3
- data/app/models/renalware/pathology.rb +1 -1
- data/app/models/renalware/pathology/message_param_parser.rb +2 -0
- data/app/models/renalware/patients/search_filter.rb +32 -0
- data/app/models/renalware/patients/search_form.rb +17 -0
- data/app/models/renalware/patients/search_query.rb +20 -21
- data/app/models/renalware/patients/summary.rb +1 -1
- data/app/models/renalware/user.rb +18 -2
- data/app/policies/renalware/admissions/request_policy.rb +8 -0
- data/app/policies/renalware/letters/electronic_receipt_policy.rb +23 -0
- data/app/policies/renalware/messaging/{message_policy.rb → internal/message_policy.rb} +2 -3
- data/app/policies/renalware/messaging/internal/receipt_policy.rb +25 -0
- data/app/presenters/renalware/dashboard/dashboard_presenter.rb +9 -2
- data/app/presenters/renalware/hd/station_presenter.rb +0 -1
- data/app/presenters/renalware/letters/electronic_receipt_presenter.rb +15 -0
- data/app/presenters/renalware/letters/letter_presenter.rb +5 -0
- data/app/presenters/renalware/mdm_presenter.rb +2 -0
- data/app/presenters/renalware/messaging/internal/message_presenter.rb +21 -0
- data/app/presenters/renalware/messaging/internal/receipt_presenter.rb +13 -0
- data/app/presenters/renalware/pathology/observation_presenter.rb +4 -0
- data/app/presenters/renalware/ukrdc/patient_presenter.rb +5 -0
- data/app/views/renalware/admissions/requests/_create_request_link.html.slim +10 -0
- data/app/views/renalware/admissions/requests/_form.html.slim +31 -0
- data/app/views/renalware/admissions/requests/_modal_dialog_placeholder.html.slim +2 -0
- data/app/views/renalware/admissions/requests/_request.html.slim +34 -0
- data/app/views/renalware/admissions/requests/_table.html.slim +19 -0
- data/app/views/renalware/admissions/requests/create.js.erb +3 -0
- data/app/views/renalware/admissions/requests/destroy.js.erb +3 -0
- data/app/views/renalware/admissions/requests/edit.html.slim +4 -0
- data/app/views/renalware/admissions/requests/edit.js.erb +4 -0
- data/app/views/renalware/admissions/requests/index.html.slim +3 -0
- data/app/views/renalware/admissions/requests/new.html.slim +4 -0
- data/app/views/renalware/admissions/requests/new.js.erb +4 -0
- data/app/views/renalware/admissions/requests/update.js.erb +9 -0
- data/app/views/renalware/api/ukrdc/patients/_allergies.xml.builder +1 -1
- data/app/views/renalware/api/ukrdc/patients/_clinical_relationships.xml.builder +0 -1
- data/app/views/renalware/api/ukrdc/patients/_lab_orders.xml.builder +7 -2
- data/app/views/renalware/api/ukrdc/patients/_observations.xml.builder +1 -1
- data/app/views/renalware/api/ukrdc/patients/_patient.xml.builder +2 -0
- data/app/views/renalware/api/ukrdc/patients/_sending_facility.xml.builder +1 -1
- data/app/views/renalware/api/ukrdc/patients/lab_orders/_lab_order.xml.builder +46 -0
- data/app/views/renalware/api/ukrdc/patients/lab_orders/_result_item.xml.builder +14 -0
- data/app/views/renalware/clinical/allergies/_mini.html.slim +1 -0
- data/app/views/renalware/dashboard/dashboards/_content.html.slim +6 -2
- data/app/views/renalware/dashboard/letters/_letter.html.slim +7 -7
- data/app/views/renalware/dashboard/letters/_table.html.slim +2 -2
- data/app/views/renalware/devise/passwords/edit.html.erb +27 -0
- data/app/views/renalware/devise/passwords/new.html.erb +18 -0
- data/app/views/renalware/devise/registrations/new.html.slim +25 -0
- data/app/views/renalware/letters/electronic_receipts/_table.html.slim +45 -0
- data/app/views/renalware/letters/electronic_receipts/mark_as_read.js.erb +6 -0
- data/app/views/renalware/letters/electronic_receipts/read.html.slim +5 -0
- data/app/views/renalware/letters/electronic_receipts/sent.html.slim +40 -0
- data/app/views/renalware/letters/electronic_receipts/unread.html.slim +5 -0
- data/app/views/renalware/letters/formatted_letters/_letter.html.slim +12 -1
- data/app/views/renalware/letters/letters/_actions.html.slim +1 -1
- data/app/views/renalware/letters/letters/_electronic_ccs.html.slim +16 -0
- data/app/views/renalware/letters/letters/_form.html.slim +8 -3
- data/app/views/renalware/letters/letters/edit.html.slim +7 -1
- data/app/views/renalware/letters/letters/new.html.slim +6 -1
- data/app/views/renalware/letters/shared/_electronic_cc_type_tabs.html.slim +7 -0
- data/app/views/renalware/messaging/{messages → internal/messages}/_form.html.slim +2 -1
- data/app/views/renalware/messaging/{messages → internal/messages}/_modal_dialog_placeholder.html.slim +0 -0
- data/app/views/renalware/messaging/{messages → internal/messages}/_send_message_link.html.slim +1 -1
- data/app/views/renalware/messaging/{messages → internal/messages}/_send_reply_link.html.slim +3 -3
- data/app/views/renalware/messaging/{messages → internal/messages}/create.js.erb +0 -0
- data/app/views/renalware/messaging/{messages → internal/messages}/new.html.slim +0 -0
- data/app/views/renalware/messaging/{messages → internal/messages}/new.js.erb +0 -0
- data/app/views/renalware/messaging/{receipts → internal/receipts}/_receipt.html.slim +2 -2
- data/app/views/renalware/messaging/{messages/_message.html.slim → internal/receipts/_sent_receipt.html.slim} +2 -1
- data/app/views/renalware/messaging/internal/receipts/_sent_table.html.slim +12 -0
- data/app/views/renalware/messaging/{receipts → internal/receipts}/_table.html.slim +2 -2
- data/app/views/renalware/messaging/{receipts → internal/receipts}/mark_as_read.js.erb +0 -0
- data/app/views/renalware/messaging/{receipts → internal/receipts}/read.html.slim +2 -1
- data/app/views/renalware/messaging/internal/receipts/sent.html.slim +7 -0
- data/app/views/renalware/messaging/{receipts → internal/receipts}/unread.html.slim +2 -1
- data/app/views/renalware/messaging/shared/_messages_type_tabs.html.slim +3 -3
- data/app/views/renalware/navigation/_main.html.slim +1 -1
- data/app/views/renalware/navigation/_patients_admin.html.slim +2 -0
- data/app/views/renalware/navigation/_user.html.slim +2 -1
- data/app/views/renalware/patients/_search_form.html.slim +12 -0
- data/app/views/renalware/patients/side_menu/_actions.html.slim +6 -2
- data/app/views/renalware/renal/profiles/_form.html.slim +0 -1
- data/app/views/renalware/renal/profiles/_mini.html.slim +1 -0
- data/app/views/renalware/{snippets/snippets → shared}/_modal_close_link.html.slim +0 -0
- data/app/views/renalware/snippets/snippets/_list.html.slim +1 -1
- data/app/views/renalware/transplants/donations/_form.html.slim +17 -16
- data/config/initializers/simple_form_foundation.rb +0 -1
- data/config/locales/renalware/admissions/requests.en.yml +12 -0
- data/config/locales/renalware/letters/contact.en.yml +3 -0
- data/config/locales/renalware/messaging/internal/messages.en.yml +33 -0
- data/config/locales/renalware/patients/search_form.en.yml +5 -0
- data/config/locales/renalware/patients/side_menu.en.yml +1 -0
- data/config/routes.rb +32 -10
- data/db/migrate/20170908155011_add_shortfall_column_to_hd_patient_statistics.rb +7 -0
- data/db/migrate/20170908160250_update_hd_overall_audit_to_version4.rb +8 -0
- data/db/migrate/20170911133224_add_type_to_messaging_messages.rb +16 -0
- data/db/migrate/20170912092135_create_letters_electronic_receipts.rb +11 -0
- data/db/migrate/20170920113628_create_admissions_requests.rb +31 -0
- data/db/seeds/default/reporting/audits.yml +1 -0
- data/db/views/reporting_hd_overall_audit_v04.sql +13 -0
- data/lib/renalware/version.rb +1 -1
- data/lib/subscription_registry.rb +1 -1
- data/spec/factories/accesses/plans.rb +2 -3
- data/spec/factories/accesses/profiles.rb +1 -2
- data/spec/factories/admissions/request_reasons.rb +8 -0
- data/spec/factories/admissions/requests.rb +9 -0
- data/spec/factories/clinical/body_compositions.rb +2 -5
- data/spec/factories/clinical/dry_weights.rb +2 -3
- data/spec/factories/clinics/clinic_visits.rb +2 -3
- data/spec/factories/directory/people.rb +1 -2
- data/spec/factories/events/events.rb +1 -2
- data/spec/factories/hd/preference_sets.rb +1 -2
- data/spec/factories/hd/profiles.rb +2 -3
- data/spec/factories/hd/sessions.rb +4 -3
- data/spec/factories/letters/electronic_receipts.rb +6 -0
- data/spec/factories/letters/letters.rb +3 -3
- data/spec/factories/medications/prescription.rb +1 -2
- data/spec/factories/medications/prescription_terminations.rb +1 -2
- data/spec/factories/messaging/internal/authors.rb +5 -0
- data/spec/factories/messaging/{message.rb → internal/messages.rb} +1 -1
- data/spec/factories/messaging/internal/receipts.rb +7 -0
- data/spec/factories/messaging/internal/recipients.rb +5 -0
- data/spec/factories/modalities/modalities.rb +1 -3
- data/spec/factories/pathology/requests/request.rb +1 -3
- data/spec/factories/patients/alerts.rb +1 -2
- data/spec/factories/patients/patients.rb +5 -3
- data/spec/factories/pd/assessments.rb +1 -2
- data/spec/factories/pd/fluid_descriptions.rb +0 -1
- data/spec/factories/pd/training_sessions.rb +1 -2
- data/spec/factories/problems/problems.rb +1 -2
- data/spec/factories/shared/accountable.rb +35 -0
- data/spec/factories/system/roles.rb +2 -4
- data/spec/factories/system/users.rb +30 -15
- data/spec/factories/transplants/donor_stage.rb +1 -2
- data/spec/factories/transplants/registration_statuses.rb +2 -4
- data/spec/support/login_macros.rb +1 -1
- metadata +108 -40
- data/app/controllers/renalware/messaging/messages_controller.rb +0 -73
- data/app/controllers/renalware/messaging/receipts_controller.rb +0 -55
- data/app/controllers/renalware/messaging/sent_messages_controller.rb +0 -22
- data/app/models/renalware/messaging/author.rb +0 -9
- data/app/models/renalware/messaging/message_factory.rb +0 -18
- data/app/models/renalware/messaging/message_form.rb +0 -34
- data/app/models/renalware/messaging/message_form_builder.rb +0 -50
- data/app/models/renalware/messaging/receipt.rb +0 -19
- data/app/models/renalware/messaging/recipient.rb +0 -10
- data/app/models/renalware/messaging/recipient_options.rb +0 -85
- data/app/models/renalware/messaging/send_message.rb +0 -22
- data/app/policies/renalware/messaging/receipt_policy.rb +0 -19
- data/app/presenters/renalware/messaging/internal_message_presenter.rb +0 -19
- data/app/presenters/renalware/messaging/receipt_presenter.rb +0 -11
- data/app/views/renalware/devise/registrations/new.html.erb +0 -46
- data/app/views/renalware/messaging/messages/_table.html.slim +0 -13
- data/app/views/renalware/messaging/messages/sent.html.slim +0 -4
- data/config/locales/renalware/messaging/messages.en.yml +0 -29
- data/spec/factories/messaging/authors.rb +0 -5
- data/spec/factories/messaging/receipt.rb +0 -7
- data/spec/factories/messaging/recipients.rb +0 -5
@@ -20,6 +20,10 @@ module Renalware
|
|
20
20
|
dependent: :destroy,
|
21
21
|
inverse_of: :letter
|
22
22
|
has_many :recipients, dependent: :destroy
|
23
|
+
has_many :electronic_receipts, dependent: :destroy
|
24
|
+
has_many :electronic_cc_recipients,
|
25
|
+
through: :electronic_receipts,
|
26
|
+
source: :recipient
|
23
27
|
has_one :signature, dependent: :destroy
|
24
28
|
has_one :archive, foreign_key: "letter_id"
|
25
29
|
|
@@ -10,7 +10,9 @@ module Renalware
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
+
@electronic_cc_recipient_ids = params.delete(:electronic_cc_recipient_ids)
|
13
14
|
@letter = build_letter
|
15
|
+
build_electronic_ccs
|
14
16
|
include_primary_care_physician_as_default_main_recipient
|
15
17
|
assign_default_ccs
|
16
18
|
build_salutation
|
@@ -25,7 +27,7 @@ module Renalware
|
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
attr_reader :patient, :letter, :params
|
30
|
+
attr_reader :patient, :letter, :params, :electronic_cc_recipient_ids
|
29
31
|
|
30
32
|
def build_letter
|
31
33
|
# We should not have to set the STI type manually here but in some circumstances
|
@@ -48,6 +50,24 @@ module Renalware
|
|
48
50
|
patient.contacts.default_ccs
|
49
51
|
end
|
50
52
|
|
53
|
+
# Deal with wiring up new electronic CCs in the new, unsaved letter.
|
54
|
+
# NB: The way electronic CCs are handled on building a new Letter and on updating an existing
|
55
|
+
# one is different: when updating an existing letter (see code elsewhere) we lean on rails
|
56
|
+
# doing some magic for us; as long as we have an array of electronic_cc_recipients in the
|
57
|
+
# params, it will add/remove an associated electronic_receipt object for us (assigning the
|
58
|
+
# letter_id to them in the process), because we used
|
59
|
+
# has_many :electronic_cc_recipients, through: :electronic_receipts
|
60
|
+
# However, here, as we have no letter.id (letter is unsaved), Rails cannot yet create the
|
61
|
+
# implied electronic_receipt object for each electronic_cc_recipient for us - we must do it
|
62
|
+
# ourselves using electronic_receipts.build so rails will update the letter id in each when
|
63
|
+
# the parent letter is saved.
|
64
|
+
def build_electronic_ccs
|
65
|
+
return if electronic_cc_recipient_ids.blank?
|
66
|
+
electronic_cc_recipient_ids.reject(&:blank?).map do |user_id|
|
67
|
+
letter.electronic_receipts.build(recipient_id: user_id)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
51
71
|
def build_salutation
|
52
72
|
letter.salutation ||= begin
|
53
73
|
main_recipient = letter.main_recipient
|
@@ -2,20 +2,36 @@ require_dependency "renalware"
|
|
2
2
|
|
3
3
|
module Renalware
|
4
4
|
module Messaging
|
5
|
-
|
5
|
+
module_function
|
6
|
+
def table_name_prefix
|
6
7
|
"messaging_"
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
+
def cast_patient(patient)
|
10
11
|
ActiveType.cast(patient, ::Renalware::Messaging::Patient)
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
+
def cast_author(author)
|
14
15
|
ActiveType.cast(author, ::Renalware::Messaging::Author)
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
18
|
+
# def cast_recipient(recipient)
|
19
|
+
# ActiveType.cast(recipient, ::Renalware::Messaging::Recipient)
|
20
|
+
# end
|
21
|
+
|
22
|
+
module Internal
|
23
|
+
module_function
|
24
|
+
def cast_patient(patient)
|
25
|
+
ActiveType.cast(patient, ::Renalware::Messaging::Internal::Patient)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cast_author(author)
|
29
|
+
ActiveType.cast(author, ::Renalware::Messaging::Internal::Author)
|
30
|
+
end
|
31
|
+
|
32
|
+
def cast_recipient(recipient)
|
33
|
+
ActiveType.cast(recipient, ::Renalware::Messaging::Internal::Recipient)
|
34
|
+
end
|
19
35
|
end
|
20
36
|
end
|
21
37
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
module Renalware
|
4
|
+
module Messaging
|
5
|
+
module Internal
|
6
|
+
class Message < Renalware::Messaging::Message
|
7
|
+
belongs_to :author, class_name: "Internal::Author"
|
8
|
+
has_many :receipts
|
9
|
+
has_many :recipients, through: :receipts
|
10
|
+
belongs_to :replying_to_message, class_name: name
|
11
|
+
scope :ordered, ->{ order(sent_at: :desc) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
module Renalware
|
4
|
+
module Messaging
|
5
|
+
module Internal
|
6
|
+
class MessageFactory
|
7
|
+
def self.build(**attributes)
|
8
|
+
attributes[:sent_at] ||= Time.zone.now
|
9
|
+
recipient_ids = attributes.delete(:recipient_ids) || []
|
10
|
+
|
11
|
+
Message.new(attributes).tap do |message|
|
12
|
+
recipient_ids.each do |recipient_id|
|
13
|
+
message.receipts.build(recipient_id: recipient_id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
# A form object used behind the html messages#new form, and serving to helps us capture
|
4
|
+
# attributes for a Message and its Recipients. The MessageForm is passed to the SendMessage
|
5
|
+
# object where it is persisted as a Message with many Recipients through Receipts.
|
6
|
+
module Renalware
|
7
|
+
module Messaging
|
8
|
+
module Internal
|
9
|
+
class MessageForm
|
10
|
+
include ActiveModel::Model
|
11
|
+
include Virtus::Model
|
12
|
+
|
13
|
+
attribute :body, String
|
14
|
+
attribute :subject, String
|
15
|
+
attribute :urgent, Boolean, default: false
|
16
|
+
attribute :recipient_ids, Array, default: []
|
17
|
+
attribute :replying_to_message_id
|
18
|
+
|
19
|
+
validates :body, presence: true
|
20
|
+
validates :subject, presence: true
|
21
|
+
validates :recipient_ids, presence: true, length: { minimum: 1 }
|
22
|
+
|
23
|
+
def initialize(attributes = {})
|
24
|
+
remove_blank_recipient_ids_from(attributes)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def remove_blank_recipient_ids_from(params)
|
31
|
+
params[:recipient_ids].reject!(&:blank?) if params.key?(:recipient_ids)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
# Builds a new MessageForm form object. MessageForm is used behind the html form when displaying a
|
4
|
+
# `Send Message` Dialog the first time. Note that we don't use this builder again on e.g.
|
5
|
+
# form submission - at that point all the required params are in the form payload - this is
|
6
|
+
# only for the initial MesageForm creation.
|
7
|
+
#
|
8
|
+
module Renalware
|
9
|
+
module Messaging
|
10
|
+
module Internal
|
11
|
+
class MessageFormBuilder
|
12
|
+
attr_reader :patient, :params
|
13
|
+
|
14
|
+
def initialize(patient:, params:)
|
15
|
+
@patient = patient
|
16
|
+
@params = params
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
MessageForm.new(
|
21
|
+
subject: build_subject,
|
22
|
+
recipient_ids: build_recipient_ids,
|
23
|
+
replying_to_message_id: replying_to_message_id
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_subject
|
30
|
+
replying? ? "Re: #{replying_to_message.subject}" : patient.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_recipient_ids
|
34
|
+
replying? ? Array(replying_to_message.author_id) : []
|
35
|
+
end
|
36
|
+
|
37
|
+
def replying_to_message
|
38
|
+
return NullObject.instance unless replying?
|
39
|
+
@replying_to_message ||= Message.find(replying_to_message_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def replying_to_message_id
|
43
|
+
params[:replying_to_message_id]
|
44
|
+
end
|
45
|
+
|
46
|
+
def replying?
|
47
|
+
replying_to_message_id.present?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
module Renalware
|
4
|
+
module Messaging
|
5
|
+
module Internal
|
6
|
+
class Receipt < ApplicationRecord
|
7
|
+
validates :recipient, presence: true
|
8
|
+
validates :message, presence: true
|
9
|
+
|
10
|
+
belongs_to :message
|
11
|
+
belongs_to :recipient
|
12
|
+
|
13
|
+
scope :unread, -> { where(read_at: nil) }
|
14
|
+
scope :read, -> { where.not(read_at: nil) }
|
15
|
+
scope :ordered, -> { joins(:message).merge(Message.ordered) }
|
16
|
+
scope :sent_by, lambda{ |user_id|
|
17
|
+
joins(:message).where(messaging_messages: { author_id: user_id })
|
18
|
+
}
|
19
|
+
|
20
|
+
def read?
|
21
|
+
read_at.present?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
# Builds grouped drop down options for potential private message recipients.
|
4
|
+
# The groups are:
|
5
|
+
# - users who have recently received a message about the current patient
|
6
|
+
# - users who have recently received a message from the current author (excluding those already
|
7
|
+
# listed in the above group)
|
8
|
+
# - all remaining users
|
9
|
+
#
|
10
|
+
# The author is excluded from all lists so they cannot send to themselves
|
11
|
+
#
|
12
|
+
module Renalware
|
13
|
+
module Messaging
|
14
|
+
module Internal
|
15
|
+
class RecipientOptions
|
16
|
+
attr_reader :patient, :author
|
17
|
+
|
18
|
+
class Group
|
19
|
+
include Virtus.model
|
20
|
+
attribute :name, String
|
21
|
+
attribute :users, Array, default: []
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(patient, author)
|
25
|
+
@patient = patient
|
26
|
+
@author = author
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_a
|
30
|
+
[
|
31
|
+
users_having_previously_received_a_message_about_patient,
|
32
|
+
users_having_recently_received_messages_from_author,
|
33
|
+
all_other_users
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def users_having_previously_received_a_message_about_patient
|
40
|
+
Group.new(
|
41
|
+
name: "Previous patient recipients",
|
42
|
+
users: Recipient.where(id: ids_of_users_having_received_a_message_about_patient)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def users_having_recently_received_messages_from_author
|
47
|
+
Group.new(
|
48
|
+
name: "Other recent recipients",
|
49
|
+
users: Recipient.where(id: ids_of_users_having_received_messages_from_author)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def all_other_users
|
54
|
+
ids_to_exclude = ids_of_users_having_received_a_message_about_patient +
|
55
|
+
ids_of_users_having_received_messages_from_author
|
56
|
+
Group.new(
|
57
|
+
name: "All other users",
|
58
|
+
users: Recipient.where.not(id: ids_to_exclude)
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def ids_of_users_having_received_a_message_about_patient
|
63
|
+
@ids_of_users_having_received_a_message_about_patient ||= begin
|
64
|
+
Message
|
65
|
+
.includes(:receipts)
|
66
|
+
.eager_load(:receipts)
|
67
|
+
.where(patient: patient)
|
68
|
+
.limit(20)
|
69
|
+
.pluck(:author_id, :recipient_id)
|
70
|
+
.flatten.uniq.compact
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def ids_of_users_having_received_messages_from_author
|
75
|
+
@ids_of_users_having_received_messages_from_author ||= begin
|
76
|
+
ids = Message
|
77
|
+
.includes(:receipts).eager_load(:receipts)
|
78
|
+
.where(author: author)
|
79
|
+
.limit(20)
|
80
|
+
.pluck(:recipient_id).uniq.compact
|
81
|
+
ids - ids_of_users_having_received_a_message_about_patient
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_dependency "renalware/messaging"
|
2
|
+
|
3
|
+
module Renalware
|
4
|
+
module Messaging
|
5
|
+
module Internal
|
6
|
+
class SendMessage
|
7
|
+
|
8
|
+
def self.call(*args)
|
9
|
+
new.call(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(author:, patient:, form:)
|
13
|
+
Message.transaction do
|
14
|
+
message = MessageFactory.build(patient: patient,
|
15
|
+
author: author,
|
16
|
+
**form.attributes)
|
17
|
+
message.save!
|
18
|
+
message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require_dependency "renalware/messaging"
|
2
2
|
|
3
|
+
#
|
4
|
+
# Abstract Message base class.
|
5
|
+
# Use Internal::Message etc. subclasses (stored via STI).
|
6
|
+
#
|
3
7
|
module Renalware
|
4
8
|
module Messaging
|
5
9
|
class Message < ApplicationRecord
|
@@ -11,9 +15,6 @@ module Renalware
|
|
11
15
|
|
12
16
|
belongs_to :patient
|
13
17
|
belongs_to :author
|
14
|
-
belongs_to :replying_to_message, class_name: name
|
15
|
-
has_many :receipts
|
16
|
-
has_many :recipients, through: :receipts
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Works in concert with Patients::SearchQuery and Patients::SearchForm.
|
2
|
+
# Example usage in a controller:
|
3
|
+
#
|
4
|
+
# my_relation = Thing.all.joins(:patient)
|
5
|
+
# filter = Patients::SearchFilter.new(search_term, request)
|
6
|
+
# my_relation = patient_filter.call(my_relation)
|
7
|
+
# render locals: { search_form: filter.search_form }
|
8
|
+
require_dependency "renalware/patients"
|
9
|
+
|
10
|
+
module Renalware
|
11
|
+
module Patients
|
12
|
+
class SearchFilter
|
13
|
+
attr_reader :search_form
|
14
|
+
|
15
|
+
def initialize(search_term, request)
|
16
|
+
@search_form = build_search_form(search_term, request)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(relation)
|
20
|
+
matching_patients = Patients::SearchQuery.new(term: search_form.term).call
|
21
|
+
relation.merge(matching_patients)
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_search_form(search_term, request)
|
25
|
+
Patients::SearchForm.new(
|
26
|
+
term: search_term,
|
27
|
+
url: request.path
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|