renalware-core 2.0.0.pre.beta7 → 2.0.0.pre.beta8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
module Renalware
|
|
4
|
-
module Messaging
|
|
5
|
-
class MessagesController < BaseController
|
|
6
|
-
include Renalware::Concerns::Pageable
|
|
7
|
-
include PresenterHelper
|
|
8
|
-
|
|
9
|
-
def sent
|
|
10
|
-
messages = author.messages.page(page).per(per_page)
|
|
11
|
-
authorize messages
|
|
12
|
-
render locals: { messages: present(messages, Messaging::InternalMessagePresenter) }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def new
|
|
16
|
-
authorize Message, :new?
|
|
17
|
-
form = MessageFormBuilder.new(patient: patient, params: params).call
|
|
18
|
-
render_new(form)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def create
|
|
22
|
-
authorize Message, :create?
|
|
23
|
-
form = MessageForm.new(message_params)
|
|
24
|
-
|
|
25
|
-
if form.valid?
|
|
26
|
-
message = SendMessage.call(author: author, patient: patient, form: form)
|
|
27
|
-
flash.now[:notice] = "Message was successfully sent"
|
|
28
|
-
render_create(message)
|
|
29
|
-
else
|
|
30
|
-
render_new(form)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
|
|
36
|
-
def message_we_are_replying_to(message)
|
|
37
|
-
return if message.replying_to_message_id.blank?
|
|
38
|
-
InternalMessagePresenter.new(message.replying_to_message)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def render_new(form)
|
|
42
|
-
render :new,
|
|
43
|
-
locals: {
|
|
44
|
-
form: form,
|
|
45
|
-
recipient_options: RecipientOptions.new(patient, current_user).to_a,
|
|
46
|
-
patient: patient
|
|
47
|
-
},
|
|
48
|
-
layout: false
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def render_create(message)
|
|
52
|
-
render locals: {
|
|
53
|
-
message: InternalMessagePresenter.new(message),
|
|
54
|
-
original_message: message_we_are_replying_to(message)
|
|
55
|
-
}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def author
|
|
59
|
-
Messaging.cast_author(current_user)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def patient
|
|
63
|
-
Messaging.cast_patient(Patient.find(params[:patient_id]))
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def message_params
|
|
67
|
-
params
|
|
68
|
-
.require(:messaging_message_form)
|
|
69
|
-
.permit(:subject, :body, :urgent, :replying_to_message_id, recipient_ids: [])
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
# A Receipt is cross reference between Message and Recipient.
|
|
4
|
-
# We can for instance mark on a receipt if/when it was read or viewed.
|
|
5
|
-
module Renalware
|
|
6
|
-
module Messaging
|
|
7
|
-
class ReceiptsController < BaseController
|
|
8
|
-
include Renalware::Concerns::Pageable
|
|
9
|
-
include PresenterHelper
|
|
10
|
-
|
|
11
|
-
# GET aka inbox
|
|
12
|
-
def unread
|
|
13
|
-
render_receipts(receipts.unread)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# GET
|
|
17
|
-
def read
|
|
18
|
-
render_receipts(receipts)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# PATCH
|
|
22
|
-
def mark_as_read
|
|
23
|
-
authorize receipt
|
|
24
|
-
receipt.update(read_at: Time.zone.now)
|
|
25
|
-
render locals: {
|
|
26
|
-
receipt: Messaging::ReceiptPresenter.new(receipt)
|
|
27
|
-
}
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
def render_receipts(receipts)
|
|
33
|
-
authorize receipts
|
|
34
|
-
render locals: {
|
|
35
|
-
receipts: present(receipts, Messaging::ReceiptPresenter)
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def receipts
|
|
40
|
-
@receipts ||= recipient.receipts.page(page).per(per_page)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def receipt
|
|
44
|
-
@receipt ||= recipient.receipts.find_by!(
|
|
45
|
-
message_id: params[:message_id],
|
|
46
|
-
id: params[:id]
|
|
47
|
-
)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def recipient
|
|
51
|
-
Messaging.cast_recipient(current_user)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
require "collection_presenter"
|
|
3
|
-
|
|
4
|
-
module Renalware
|
|
5
|
-
module Messaging
|
|
6
|
-
class SentMessagesController < BaseController
|
|
7
|
-
include Renalware::Concerns::Pageable
|
|
8
|
-
|
|
9
|
-
def index
|
|
10
|
-
messages = author.messages.page(page).per(per_page)
|
|
11
|
-
authorize messages
|
|
12
|
-
render locals: {
|
|
13
|
-
messages: CollectionPresenter.new(messages, Messaging::InternalMessagePresenter)
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def author
|
|
18
|
-
Messaging.cast_author(current_user)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
module Renalware
|
|
4
|
-
module Messaging
|
|
5
|
-
class MessageFactory
|
|
6
|
-
def self.build(**attributes)
|
|
7
|
-
attributes[:sent_at] ||= Time.zone.now
|
|
8
|
-
recipient_ids = attributes.delete(:recipient_ids) || []
|
|
9
|
-
|
|
10
|
-
Message.new(attributes).tap do |message|
|
|
11
|
-
recipient_ids.each do |recipient_id|
|
|
12
|
-
message.receipts.build(recipient_id: recipient_id)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
class MessageForm
|
|
9
|
-
include ActiveModel::Model
|
|
10
|
-
include Virtus::Model
|
|
11
|
-
|
|
12
|
-
attribute :body, String
|
|
13
|
-
attribute :subject, String
|
|
14
|
-
attribute :urgent, Boolean, default: false
|
|
15
|
-
attribute :recipient_ids, Array, default: []
|
|
16
|
-
attribute :replying_to_message_id
|
|
17
|
-
|
|
18
|
-
validates :body, presence: true
|
|
19
|
-
validates :subject, presence: true
|
|
20
|
-
validates :recipient_ids, presence: true, length: { minimum: 1 }
|
|
21
|
-
|
|
22
|
-
def initialize(attributes = {})
|
|
23
|
-
remove_blank_recipient_ids_from(attributes)
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def remove_blank_recipient_ids_from(params)
|
|
30
|
-
params[:recipient_ids].reject!(&:blank?) if params.key?(:recipient_ids)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
class MessageFormBuilder
|
|
11
|
-
attr_reader :patient, :params
|
|
12
|
-
|
|
13
|
-
def initialize(patient:, params:)
|
|
14
|
-
@patient = patient
|
|
15
|
-
@params = params
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def call
|
|
19
|
-
MessageForm.new(
|
|
20
|
-
subject: build_subject,
|
|
21
|
-
recipient_ids: build_recipient_ids,
|
|
22
|
-
replying_to_message_id: replying_to_message_id
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def build_subject
|
|
29
|
-
replying? ? "Re: #{replying_to_message.subject}" : patient.to_s
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def build_recipient_ids
|
|
33
|
-
replying? ? Array(replying_to_message.author_id) : []
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def replying_to_message
|
|
37
|
-
return NullObject.instance unless replying?
|
|
38
|
-
@replying_to_message ||= Message.find(replying_to_message_id)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def replying_to_message_id
|
|
42
|
-
params[:replying_to_message_id]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def replying?
|
|
46
|
-
replying_to_message_id.present?
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
module Renalware
|
|
4
|
-
module Messaging
|
|
5
|
-
class Receipt < ApplicationRecord
|
|
6
|
-
validates :recipient, presence: true
|
|
7
|
-
validates :message, presence: true
|
|
8
|
-
|
|
9
|
-
belongs_to :message
|
|
10
|
-
belongs_to :recipient
|
|
11
|
-
|
|
12
|
-
scope :unread, -> { where(read_at: nil) }
|
|
13
|
-
|
|
14
|
-
def read?
|
|
15
|
-
read_at.present?
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
-
class RecipientOptions
|
|
15
|
-
attr_reader :patient, :author
|
|
16
|
-
|
|
17
|
-
class Group
|
|
18
|
-
include Virtus.model
|
|
19
|
-
attribute :name, String
|
|
20
|
-
attribute :users, Array, default: []
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def initialize(patient, author)
|
|
24
|
-
@patient = patient
|
|
25
|
-
@author = author
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def to_a
|
|
29
|
-
[
|
|
30
|
-
users_having_previously_received_a_message_about_patient,
|
|
31
|
-
users_having_recently_received_messages_from_author,
|
|
32
|
-
all_other_users
|
|
33
|
-
]
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def users_having_previously_received_a_message_about_patient
|
|
39
|
-
Group.new(
|
|
40
|
-
name: "Previous patient recipients",
|
|
41
|
-
users: Recipient.where(id: ids_of_users_having_received_a_message_about_patient)
|
|
42
|
-
)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def users_having_recently_received_messages_from_author
|
|
46
|
-
Group.new(
|
|
47
|
-
name: "Other recent recipients",
|
|
48
|
-
users: Recipient.where(id: ids_of_users_having_received_messages_from_author)
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def all_other_users
|
|
53
|
-
ids_to_exclude = ids_of_users_having_received_a_message_about_patient +
|
|
54
|
-
ids_of_users_having_received_messages_from_author
|
|
55
|
-
Group.new(
|
|
56
|
-
name: "KCH",
|
|
57
|
-
users: Recipient.where.not(id: ids_to_exclude)
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def ids_of_users_having_received_a_message_about_patient
|
|
62
|
-
@ids_of_users_having_received_a_message_about_patient ||= begin
|
|
63
|
-
Message
|
|
64
|
-
.includes(:receipts)
|
|
65
|
-
.eager_load(:receipts)
|
|
66
|
-
.where(patient: patient)
|
|
67
|
-
.limit(20)
|
|
68
|
-
.pluck(:author_id, :recipient_id)
|
|
69
|
-
.flatten.uniq.compact
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def ids_of_users_having_received_messages_from_author
|
|
74
|
-
@ids_of_users_having_received_messages_from_author ||= begin
|
|
75
|
-
ids = Message
|
|
76
|
-
.includes(:receipts).eager_load(:receipts)
|
|
77
|
-
.where(author: author)
|
|
78
|
-
.limit(20)
|
|
79
|
-
.pluck(:recipient_id).uniq.compact
|
|
80
|
-
ids - ids_of_users_having_received_a_message_about_patient
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
module Renalware
|
|
4
|
-
module Messaging
|
|
5
|
-
class SendMessage
|
|
6
|
-
|
|
7
|
-
def self.call(*args)
|
|
8
|
-
new.call(*args)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def call(author:, patient:, form:)
|
|
12
|
-
Message.transaction do
|
|
13
|
-
message = MessageFactory.build(patient: patient,
|
|
14
|
-
author: author,
|
|
15
|
-
**form.attributes)
|
|
16
|
-
message.save!
|
|
17
|
-
message
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require_dependency "renalware/messaging"
|
|
2
|
-
|
|
3
|
-
module Renalware
|
|
4
|
-
module Messaging
|
|
5
|
-
class InternalMessagePresenter < SimpleDelegator
|
|
6
|
-
def age_in_days
|
|
7
|
-
(Time.zone.now.to_date - sent_at.to_date).to_i
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def html_identifier
|
|
11
|
-
"message-#{id}"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def html_preview_identifier
|
|
15
|
-
"message-preview-#{id}"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|