renalware-core 2.0.13 → 2.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f58372406094a085ea5fd1ffe9a57724951450eb6db8adf1b2513513800479f3
4
- data.tar.gz: c7a49293b5baf36736b8dc90695721328b57b6402243b9970e352859d233948b
3
+ metadata.gz: 490bec33f80510335ad7d199d1b9e93f31cbe5f9c2131dd2d84c46a9cd1f93ec
4
+ data.tar.gz: 33884ab738728ba022b3c74c207dc0055eb062a149a9ca310c042067ac06bd07
5
5
  SHA512:
6
- metadata.gz: 3a92d4849645611cfc0fe10f06c27e38fbf7e75cf0c445751e94be9c978b04c217377064dd69bce6a0c817dfb085cf865d011fc8ed415ee8ea3a7f0ec2b2902d
7
- data.tar.gz: ad1af0c79116b59c41068e0f0dec65ab81c00da7842ef9c6acf1be37616ec3a829499683f292da0f3b25dad252e6120ccce2c91d51d988512beef7fb0ee3bb10
6
+ metadata.gz: 30a02abf77c960ae5dd41980e3e79ec46edb69564cb87b01973b99df83d98f0d745f532b599251b987d88e2cb380b3a3b30b6586ffaeceb6576adde825699e49
7
+ data.tar.gz: e345f0a78c9d67574be381c76efa75155331a025d108323df8d9966df6f7a4245dff11eaf8817078a013b2d82da71c5c1ef5df10ddeda9de932cb1ce00140ac3
@@ -28,3 +28,18 @@
28
28
  }
29
29
  }
30
30
  }
31
+
32
+ table.aki-alerts tr {
33
+ &:nth-of-type(even) {
34
+ background: $white;
35
+ }
36
+
37
+ &.aki_alert--hotlist {
38
+ background-color: $bookmark-urgent-colour;
39
+ }
40
+
41
+ td.notes {
42
+ text-align: right;
43
+ vertical-align: top;
44
+ }
45
+ }
@@ -6,10 +6,34 @@ module Renalware
6
6
  module V1
7
7
  module Patients
8
8
  class PatientsController < TokenAuthenticatedApiController
9
+ include Concerns::Pageable
10
+
9
11
  def show
10
12
  patient = Patient.find_by!(local_patient_id: params[:id])
11
13
  render locals: { patient: patient }
12
14
  end
15
+
16
+ def index
17
+ render locals: { patients: patients }
18
+ end
19
+
20
+ private
21
+
22
+ def patients
23
+ relation = last_patient_id.blank? ? Patient.none : Patient
24
+ relation
25
+ .where("id > ?", last_patient_id)
26
+ .order(id: :asc)
27
+ .page(page).per(per_page)
28
+ end
29
+
30
+ def last_patient_id
31
+ params[:last_patient_id]
32
+ end
33
+
34
+ def per_page
35
+ params[:per_page] || 100
36
+ end
13
37
  end
14
38
  end
15
39
  end
@@ -12,7 +12,8 @@ module Renalware
12
12
  render locals: {
13
13
  alerts: alerts,
14
14
  form: search_form,
15
- search: query.search
15
+ search: query.search,
16
+ path_params: path_params
16
17
  }
17
18
  end
18
19
 
@@ -24,7 +25,7 @@ module Renalware
24
25
  def update
25
26
  authorize alert
26
27
  if alert.update(aki_alert_params.merge(by: current_user))
27
- redirect_to renal_aki_alerts_path
28
+ redirect_to renal_filtered_aki_alerts_path(named_filter: :today)
28
29
  else
29
30
  render_edit(alert)
30
31
  end
@@ -35,6 +36,7 @@ module Renalware
35
36
  def search_form
36
37
  @search_form ||= begin
37
38
  options = params.key?(:q) ? search_params : {}
39
+ options[:named_filter] = named_filter
38
40
  AKIAlertSearchForm.new(options)
39
41
  end
40
42
  end
@@ -61,6 +63,14 @@ module Renalware
61
63
  .require(:q) {}
62
64
  .permit(:term, :on_hotlist, :action, :hospital_unit_id, :hospital_ward_id, :s)
63
65
  end
66
+
67
+ def path_params
68
+ params.permit([:controller, :action, :named_filter])
69
+ end
70
+
71
+ def named_filter
72
+ params[:named_filter]
73
+ end
64
74
  end
65
75
  end
66
76
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "renalware/hd"
4
+ require "attr_extras"
5
+
6
+ module Renalware
7
+ module HD
8
+ module Sessions
9
+ class CloseStaleOpenSessions
10
+ attr_reader :closed_session_ids, :unclosed_session_ids, :performed_before
11
+
12
+ class CloseableSessionQuery
13
+ pattr_initialize [:performed_before!]
14
+
15
+ def each
16
+ Session::Open
17
+ .where("performed_on <= ?", performed_before)
18
+ .where.not(signed_off_by: nil)
19
+ .find_each do |session|
20
+ # Note the bang in becomes! is crucial in copying the session attributes
21
+ # and setting the sti column appropriately
22
+ yield CloseableSession.new(session.becomes!(Session::Closed))
23
+ end
24
+ end
25
+ end
26
+
27
+ class CloseableSession < SimpleDelegator
28
+ include Renalware::Engine.routes.url_helpers
29
+ def close
30
+ self.profile = patient.hd_profile
31
+ self.signed_off_at = Time.zone.now
32
+ self.dry_weight = Renalware::Clinical::DryWeight.for_patient(patient).first
33
+ valid? && document.valid? && save_by(Renalware::SystemUser.find)
34
+ end
35
+
36
+ # rubocop:disable Metrics/AbcSize
37
+ def all_errors
38
+ [
39
+ errors.full_messages,
40
+ document.dialysis.errors.full_messages,
41
+ document.observations_before.errors.full_messages,
42
+ document.observations_after.errors.full_messages,
43
+ document.hdf.errors.full_messages,
44
+ document.info.errors.full_messages
45
+ ].flatten.uniq.compact
46
+ end
47
+ # rubocop:enable Metrics/AbcSize
48
+
49
+ def url
50
+ edit_patient_hd_session_path(patient, self)
51
+ end
52
+ end
53
+
54
+ def self.call(performed_before: 3.days.ago)
55
+ new(performed_before: performed_before).call
56
+ end
57
+
58
+ def initialize(performed_before:)
59
+ @performed_before = performed_before
60
+ @closed_session_ids = []
61
+ @unclosed_session_ids = []
62
+ end
63
+
64
+ # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
65
+ def call
66
+ log_start
67
+ results = OpenStruct.new(closed_ids: [], unclosed_ids: [])
68
+
69
+ CloseableSessionQuery.new(performed_before: performed_before).each do |session|
70
+ if session.close
71
+ results.closed_ids << session.id
72
+ log("[Session #{session.id}] - closed")
73
+ else
74
+ results.unclosed_ids << session.id
75
+ log("[Session #{session.id}] - unclosed: #{session.all_errors.join(', ')}")
76
+ log("[Session #{session.id}] - #{session.url}")
77
+ end
78
+ end
79
+ log_results(results)
80
+ results
81
+ end
82
+ # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
83
+
84
+ private
85
+
86
+ def log_start
87
+ log("Trying to close stale open sessions performed before #{performed_before}")
88
+ end
89
+
90
+ def log_results(results)
91
+ log("#{results.closed_ids.count} sessions closed")
92
+ log("#{results.unclosed_ids.count} sessions could not be closed")
93
+ end
94
+
95
+ def log(msg = "")
96
+ Rails.logger.info(msg)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -4,6 +4,8 @@ require_dependency "renalware"
4
4
 
5
5
  module Renalware
6
6
  module Renal
7
+ AKI_ALERT_FILTERS = %w(today all).freeze
8
+
7
9
  def self.table_name_prefix
8
10
  "renal_"
9
11
  end
@@ -14,6 +14,8 @@ module Renalware
14
14
  validates :patient, presence: true
15
15
  validates :max_aki, inclusion: 1..3, allow_nil: true
16
16
  alias_attribute :decided_by, :updated_by
17
+
18
+ scope :today, ->{ where(aki_date: Time.zone.today) }
17
19
  end
18
20
  end
19
21
  end
@@ -5,7 +5,7 @@ require_dependency "renalware/clinics"
5
5
  module Renalware
6
6
  module Renal
7
7
  class AKIAlertQuery
8
- DEFAULT_SORT = "aki_date :desc"
8
+ DEFAULT_SORT = "aki_date desc"
9
9
  attr_reader :query
10
10
 
11
11
  def initialize(query = nil)
@@ -26,6 +26,7 @@ module Renalware
26
26
  AKIAlert
27
27
  .joins(:patient) # required for PatientsRansackHelper - see Admission
28
28
  .includes(:patient, :updated_by, :action, hospital_ward: :hospital_unit)
29
+ .public_send(query[:named_filter].to_s)
29
30
  .ransack(query)
30
31
  end
31
32
  end
@@ -14,6 +14,7 @@ module Renalware
14
14
  attribute :term, String
15
15
  attribute :on_hotlist, String
16
16
  attribute :s, String
17
+ attribute :named_filter, String
17
18
 
18
19
  def query
19
20
  @query ||= begin
@@ -23,7 +24,8 @@ module Renalware
23
24
  hospital_ward_hospital_unit_id_eq: hospital_unit_id,
24
25
  action_id_eq: action,
25
26
  hotlist_eq: on_hotlist,
26
- s: s
27
+ s: s,
28
+ named_filter: named_filter
27
29
  }
28
30
  AKIAlertQuery.new(options)
29
31
  end
@@ -0,0 +1,33 @@
1
+ def modify_query(url, options={})
2
+ uri = URI(url)
3
+ query_hash = Rack::Utils.parse_query(uri.query)
4
+ query_hash.merge!(options)
5
+ uri.query = Rack::Utils.build_query(query_hash)
6
+ uri.to_s
7
+ end
8
+
9
+ json.links do
10
+ json.prev patients.prev_page && modify_query(request.url, "page" => patients.prev_page)
11
+ json.next patients.next_page && modify_query(request.url, "page" => patients.next_page)
12
+ json.total_pages patients.total_pages
13
+ json.next_page patients.next_page
14
+ json.current_page patients.current_page
15
+ json.prev_page patients.prev_page
16
+ end
17
+
18
+ json.data patients do |patient|
19
+ json.id patient.id
20
+ json.secure_id patient.secure_id
21
+ json.local_patient_id patient.local_patient_id
22
+ json.local_patient_id_2 patient.local_patient_id_2
23
+ json.local_patient_id_3 patient.local_patient_id_3
24
+ json.local_patient_id_4 patient.local_patient_id_4
25
+ json.nhs_number patient.nhs_number
26
+ json.family_name patient.family_name
27
+ json.given_name patient.given_name
28
+ json.title patient.title
29
+ json.born_on patient.born_on
30
+ json.sex patient.sex&.code
31
+ json.send_to_renalreg patient.send_to_renalreg
32
+ json.send_to_rpv patient.send_to_rpv
33
+ end
@@ -10,6 +10,6 @@ li.has-dropdown
10
10
  li= link_to t(".letters"), letters_list_path
11
11
  li= link_to t(".esa_prescriptions"), medications_esa_prescriptions_path
12
12
  li= link_to t(".audits"), reporting_audits_path
13
- li= link_to t(".aki_alerts"), renal_aki_alerts_path
13
+ li= link_to t(".aki_alerts"), renal_filtered_aki_alerts_path(named_filter: :today)
14
14
  li= link_to t(".studies"), research_studies_path
15
15
  li= link_to t(".renal_registry_checks"), patients_renal_registry_preflight_checks_path
@@ -0,0 +1,25 @@
1
+ - toggleable_id = "aki-alert-quick-preview-#{aki_alert.id}"
2
+ tr(class="#{'aki_alert--hotlist' if aki_alert.hotlist?}")
3
+ td
4
+ = link_to("Edit", edit_renal_aki_alert_path(aki_alert))
5
+ | &nbsp;|&nbsp;
6
+ = link_to("Toggle",
7
+ "##{toggleable_id}",
8
+ data: { behaviour: "toggler" })
9
+ td= default_patient_link(aki_alert.patient)
10
+ td= aki_alert.patient.hospital_identifiers
11
+ td= aki_alert.patient.sex
12
+ td= aki_alert.patient.age
13
+ td= aki_alert.action
14
+ td= [aki_alert.hospital_ward, aki_alert.hospital_ward&.hospital_unit&.unit_code]\
15
+ .compact.join(" - ")
16
+ td= yes_no aki_alert.hotlist?
17
+ td= aki_alert.max_aki
18
+ td= l(aki_alert.aki_date)
19
+ td= aki_alert.decided_by
20
+ = content_tag(:tr, id: "#{toggleable_id}", style: "display: none")
21
+ td.notes Notes
22
+ td(colspan=10)
23
+ .quick-preview
24
+ =aki_alert.notes
25
+
@@ -1,12 +1,26 @@
1
+ ruby:
2
+ filters = {
3
+ active: "Today",
4
+ suspended: "All"
5
+ }
6
+
7
+ h2.print-only= filters[path_params[:named_filter].to_sym]
8
+
9
+ dl.sub-nav
10
+ - Renalware::Renal::AKI_ALERT_FILTERS.each do |key|
11
+ - options = path_params.merge(named_filter: key).to_h.symbolize_keys
12
+ - path = Renalware::Engine.routes.url_for(options.merge!(only_path: true))
13
+ = sub_nav_item(key.to_s.humanize, path)
14
+
1
15
  .search-form.filters
2
16
  = simple_form_for form,
3
17
  as: :q,
4
- url: renal_aki_alerts_path,
18
+ url: renal_filtered_aki_alerts_path,
5
19
  method: :get do |f|
6
20
 
7
21
  .row
8
22
  .columns.medium-2.large-3
9
- = f.input :term
23
+ = f.input :term, label: "Hosp/NHS no or name"
10
24
  .columns.medium-1.large-1
11
25
  = f.input :on_hotlist,
12
26
  collection: [["Yes",true],["No",false]]
@@ -22,4 +36,4 @@
22
36
  .columns.medium-2.large-2.actions.end
23
37
  = f.submit "Filter", class: "button"
24
38
  span= " or "
25
- = link_to t("helpers.reset"), renal_aki_alerts_path
39
+ = link_to t("helpers.reset"), renal_filtered_aki_alerts_path
@@ -0,0 +1,15 @@
1
+ table.aki-alerts
2
+ thead
3
+ th.col-width-small
4
+ th.col-width-large Patient
5
+ th.col-width-reference-no Hosp. No.
6
+ th.col-width-tiny Sex
7
+ th.col-width-tiny Age
8
+ th= sort_link(search, :action_name, "Action")
9
+ th.col-width-medium Ward
10
+ th= sort_link(search, :hotlist, "Hotlist")
11
+ th= sort_link(search, :max_aki, "Max AKI")
12
+ th.col-width-date= sort_link(search, :aki_date, "AKI Date")
13
+ th Decided by
14
+ tbody
15
+ = render alerts
@@ -1,5 +1,5 @@
1
1
  = within_admin_layout(title: "Edit",
2
- breadcrumbs: breadcrumb_for("AKI Alerts", renal_aki_alerts_path)) do
2
+ breadcrumbs: breadcrumb_for("AKI Alerts", renal_filtered_aki_alerts_path(named_filter: :today))) do
3
3
 
4
4
  = simple_form_for(alert, wrapper: :horizontal_form) do |f|
5
5
  = f.association :action, wrapper: :horizontal_small
@@ -17,4 +17,4 @@
17
17
  = f.input :notes, wrapper: :horizontal_large, input_html: { rows: 5 }
18
18
  = f.submit class: "button"
19
19
  span= " or "
20
- = link_to "cancel", renal_aki_alerts_path
20
+ = link_to "cancel", renal_filtered_aki_alerts_path(named_filter: :today)
@@ -1,40 +1,5 @@
1
1
  = within_admin_layout(title: "AKI Alerts") do
2
- = render "filters", form: form
3
- table.aki-alerts
4
- thead
5
- th
6
- th.col-width-large Patient
7
- /th.col-width-nhs-no NHS No.
8
- th.col-width-reference-no Hosp. No.
9
- th.col-width-tiny Sex
10
- th.col-width-tiny Age
11
- /th.col-width-date= sort_link(search, :patient_born_on, "Born on")
12
- th= sort_link(search, :action_name, "Action")
13
- th.col-width-medium Ward
14
- th= sort_link(search, :hotlist, "Hotlist")
15
- th= sort_link(search, :max_cre, "Max CRE")
16
- th.col-width-date.col-width-date= sort_link(search, :cre_date, "CRE Date")
17
- th= sort_link(search, :max_aki, "Max AKI")
18
- th.col-width-date= sort_link(search, :aki_date, "AKI Date")
19
- th Decided by
20
- tbody
21
- - alerts.each do |alert|
22
- tr
23
- td= link_to("Edit", edit_renal_aki_alert_path(alert))
24
- td= default_patient_link(alert.patient)
25
- /td= alert.patient.nhs_number
26
- td= alert.patient.hospital_identifiers
27
- td= alert.patient.sex
28
- td= alert.patient.age
29
- /td= alert.patient.born_on
30
- td= alert.action
31
- td= [alert.hospital_ward, alert.hospital_ward&.hospital_unit&.unit_code]\
32
- .compact.join(" - ")
33
- td= yes_no alert.hotlist?
34
- td= alert.max_cre
35
- td= l(alert.cre_date)
36
- td= alert.max_aki
37
- td= l(alert.aki_date)
38
- td= alert.decided_by
2
+ = render "filters", form: form, path_params: path_params
3
+ = render "table", alerts: alerts, search: search
39
4
 
40
5
  = paginate alerts
data/config/routes.rb CHANGED
@@ -1,4 +1,3 @@
1
- # rubocop:disable Style/FormatStringToken
2
1
  Renalware::Engine.routes.draw do
3
2
  match "/404", to: "system/errors#not_found", via: :all
4
3
  match "/500", to: "system/errors#internal_server_error", via: :all
@@ -21,7 +20,7 @@ Renalware::Engine.routes.draw do
21
20
 
22
21
  super_admin_constraint = lambda do |request|
23
22
  current_user = request.env["warden"].user
24
- current_user && current_user.respond_to?(:has_role?) && current_user.has_role?(:super_admin)
23
+ current_user&.respond_to?(:has_role?) && current_user&.has_role?(:super_admin)
25
24
  end
26
25
 
27
26
  constraints super_admin_constraint do
@@ -81,7 +80,7 @@ Renalware::Engine.routes.draw do
81
80
  end
82
81
  # The JSON API
83
82
  namespace :v1, constraints: { format: :json }, defaults: { format: :json } do
84
- resources :patients, only: :show, controller: "patients/patients" do
83
+ resources :patients, only: [:show, :index], controller: "patients/patients" do
85
84
  resources :prescriptions, controller: "medications/prescriptions", only: [:index]
86
85
  namespace :hd do
87
86
  resource :current_profile,
@@ -244,7 +243,10 @@ Renalware::Engine.routes.draw do
244
243
  get :search
245
244
  end
246
245
  end
247
- resources :aki_alerts, except: [:new, :create, :destroy]
246
+ resources :aki_alerts, only: [:edit, :update]
247
+ constraints(named_filter: /#{Renalware::Renal::AKI_ALERT_FILTERS.join("|")}/) do
248
+ get "aki_alerts/:named_filter", to: "aki_alerts#index", as: :filtered_aki_alerts
249
+ end
248
250
  resources :registry_preflight_checks, only: [] do
249
251
  collection do
250
252
  get :patients
@@ -1,3 +1,3 @@
1
1
  module Renalware
2
- VERSION = "2.0.13".freeze
2
+ VERSION = "2.0.14".freeze
3
3
  end
data/lib/tasks/hd.rake ADDED
@@ -0,0 +1,13 @@
1
+ require "benchmark"
2
+
3
+ namespace :hd do
4
+ desc "Signs-off Open sessions that have a signed_off_by and are more than a few days old. "\
5
+ "A usability update may render this task redundant in the future but currently there are " \
6
+ "Save and Save and Sign-Off buttons, and user is not alwasy using the latter."
7
+ task close_stale_open_sessions: :environment do
8
+ Rails.logger = Logger.new(STDOUT)
9
+ Renalware::HD::Sessions::CloseStaleOpenSessions.call(
10
+ performed_before: 3.days.ago
11
+ )
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renalware-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.13
4
+ version: 2.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airslie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-05 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -1430,6 +1430,7 @@ files:
1430
1430
  - app/models/renalware/hd/sessions/auditable_patients_in_period_query.rb
1431
1431
  - app/models/renalware/hd/sessions/auditable_session.rb
1432
1432
  - app/models/renalware/hd/sessions/auditable_session_collection.rb
1433
+ - app/models/renalware/hd/sessions/close_stale_open_sessions.rb
1433
1434
  - app/models/renalware/hd/sessions/latest_patient_sessions_query.rb
1434
1435
  - app/models/renalware/hd/sessions/ongoing_query.rb
1435
1436
  - app/models/renalware/hd/sessions/patient_query.rb
@@ -2010,6 +2011,7 @@ files:
2010
2011
  - app/views/renalware/api/ukrdc/patients/observations/_weight.xml.builder
2011
2012
  - app/views/renalware/api/ukrdc/patients/show.xml.builder
2012
2013
  - app/views/renalware/api/v1/medications/prescriptions/index.json.jbuilder
2014
+ - app/views/renalware/api/v1/patients/patients/index.json.jbuilder
2013
2015
  - app/views/renalware/api/v1/patients/patients/show.json.jbuilder
2014
2016
  - app/views/renalware/base/_black_hole.html.slim
2015
2017
  - app/views/renalware/base/_modality_missing_warning.html.slim
@@ -2532,7 +2534,9 @@ files:
2532
2534
  - app/views/renalware/problems/problems/index.html.slim
2533
2535
  - app/views/renalware/problems/problems/new.html.slim
2534
2536
  - app/views/renalware/problems/problems/show.html.slim
2537
+ - app/views/renalware/renal/aki_alerts/_aki_alert.html.slim
2535
2538
  - app/views/renalware/renal/aki_alerts/_filters.html.slim
2539
+ - app/views/renalware/renal/aki_alerts/_table.html.slim
2536
2540
  - app/views/renalware/renal/aki_alerts/edit.html.slim
2537
2541
  - app/views/renalware/renal/aki_alerts/index.html.slim
2538
2542
  - app/views/renalware/renal/prd_descriptions/search.json.jbuilder
@@ -3356,6 +3360,7 @@ files:
3356
3360
  - lib/tasks/cucumber_web.rake
3357
3361
  - lib/tasks/db.rake
3358
3362
  - lib/tasks/feeds/files.rake
3363
+ - lib/tasks/hd.rake
3359
3364
  - lib/tasks/ukrdc.rake
3360
3365
  - lib/templates/slim/scaffold/_form.html.slim
3361
3366
  - lib/test_support/ajax_helpers.rb