renalware-core 2.0.111 → 2.0.112

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -0
  3. data/app/assets/javascripts/renalware/application.js.erb +7 -8
  4. data/app/assets/javascripts/renalware/charting/charting.js.erb +4 -0
  5. data/app/assets/javascripts/renalware/dialogs.js.erb +0 -11
  6. data/app/assets/javascripts/renalware/hd.js +59 -9
  7. data/app/assets/stylesheets/renalware/application.scss +2 -3
  8. data/app/assets/stylesheets/renalware/modules/_hd.scss +19 -0
  9. data/app/assets/stylesheets/renalware/modules/_patients.scss +7 -0
  10. data/app/assets/stylesheets/renalware/print/pathology_request_forms.scss +26 -0
  11. data/app/assets/stylesheets/renalware/protocol_pdf.scss +9 -4
  12. data/app/controllers/renalware/hd/mdm_patients_controller.rb +17 -6
  13. data/app/controllers/renalware/hd/protocols_controller.rb +22 -31
  14. data/app/controllers/renalware/hd/session_forms/batches_controller.rb +82 -0
  15. data/app/controllers/renalware/pathology/requests/requests_controller.rb +20 -6
  16. data/app/controllers/renalware/surveys/dashboards_controller.rb +24 -0
  17. data/app/jobs/renalware/hd/session_forms/batch_print_job.rb +40 -0
  18. data/app/models/concerns/renalware/pdf_compilation.rb +60 -0
  19. data/app/models/renalware/clinical/allergy_status_form.rb +1 -1
  20. data/app/models/renalware/clinical/delete_allergy.rb +1 -1
  21. data/app/models/renalware/clinics/appointment_query.rb +1 -5
  22. data/app/models/renalware/hd.rb +6 -0
  23. data/app/models/renalware/hd/patient_listener.rb +1 -1
  24. data/app/models/renalware/hd/session_forms/batch.rb +26 -0
  25. data/app/models/renalware/hd/session_forms/batch_compile_pdfs.rb +86 -0
  26. data/app/models/renalware/hd/session_forms/batch_item.rb +15 -0
  27. data/app/models/renalware/hd/session_forms/form.rb +16 -0
  28. data/app/models/renalware/hd/session_forms/pdf_renderer.rb +74 -0
  29. data/app/models/renalware/letters/batch.rb +2 -0
  30. data/app/models/renalware/letters/printing/batch_compile_pdfs.rb +0 -3
  31. data/app/models/renalware/medications/patient_listener.rb +1 -1
  32. data/app/models/renalware/pathology/ordered_patient_query.rb +1 -1
  33. data/app/models/renalware/pathology/request_for_patient_request_description_query.rb +1 -1
  34. data/app/models/renalware/pd/apd/non_tidal_regime_calculations.rb +1 -1
  35. data/app/models/renalware/pd/apd/tidal_regime_calculations.rb +1 -1
  36. data/app/models/renalware/snippets/snippet_query.rb +1 -1
  37. data/app/models/renalware/surveys.rb +9 -0
  38. data/app/models/renalware/surveys/eq5d_pivoted_response.rb +11 -0
  39. data/app/models/renalware/surveys/eq5d_summary_part.rb +51 -0
  40. data/app/models/renalware/surveys/pos_s_pivoted_response.rb +11 -0
  41. data/app/models/renalware/surveys/pos_s_summary_part.rb +51 -0
  42. data/app/models/renalware/surveys/question.rb +22 -0
  43. data/app/models/renalware/surveys/response.rb +28 -0
  44. data/app/models/renalware/surveys/survey.rb +17 -0
  45. data/app/models/renalware/ukrdc.rb +3 -0
  46. data/app/models/renalware/ukrdc/incoming/file_list.rb +21 -0
  47. data/app/models/renalware/ukrdc/incoming/import_survey.rb +57 -0
  48. data/app/models/renalware/ukrdc/incoming/import_surveys.rb +77 -0
  49. data/app/models/renalware/ukrdc/incoming/paths.rb +30 -0
  50. data/app/models/renalware/ukrdc/incoming/xml_document.rb +68 -0
  51. data/app/models/renalware/ukrdc/transmission_log.rb +14 -3
  52. data/app/policies/renalware/hd/session_forms/batch_policy.rb +13 -0
  53. data/app/policies/renalware/surveys/survey_policy.rb +10 -0
  54. data/app/presenters/renalware/hd/session_presenter.rb +1 -1
  55. data/app/views/renalware/clinics/appointments/index.html.slim +22 -11
  56. data/app/views/renalware/hd/dashboards/_page_actions.html.slim +1 -1
  57. data/app/views/renalware/hd/diary_slots/_form.html.slim +0 -3
  58. data/app/views/renalware/hd/mdm_patients/_filters.html.slim +11 -0
  59. data/app/views/renalware/hd/mdm_patients/_page_actions.html.slim +0 -0
  60. data/app/views/renalware/hd/mdm_patients/index.html.slim +9 -1
  61. data/app/views/renalware/hd/protocols/{show.pdf.slim → _protocol.pdf.slim} +1 -7
  62. data/app/views/renalware/hd/protocols/index.pdf.slim +4 -0
  63. data/app/views/renalware/hd/session_forms/batches/_create.html.slim +25 -0
  64. data/app/views/renalware/hd/session_forms/batches/create.js.erb +3 -0
  65. data/app/views/renalware/hd/sessions/_row.html.slim +1 -1
  66. data/app/views/renalware/hd/sessions/_thead.html.slim +1 -1
  67. data/app/views/renalware/pathology/historical_observation_results/_table.html.slim +1 -1
  68. data/app/views/renalware/pathology/recent_observation_results/_table.html.slim +1 -1
  69. data/app/views/renalware/pathology/requests/requests/create.pdf.slim +2 -1
  70. data/app/views/renalware/pathology/requests/requests/new.html.slim +18 -13
  71. data/app/views/renalware/pathology/requests/requests/request_form/_crs.pdf.slim +1 -0
  72. data/app/views/renalware/pathology/requests/requests/request_form/_crs_form.html.slim +46 -45
  73. data/app/views/renalware/pathology/requests/requests/request_form/_manual_form_global.html.slim +9 -8
  74. data/app/views/renalware/pathology/requests/requests/request_form/_manual_form_patient.html.slim +9 -8
  75. data/app/views/renalware/pathology/requests/requests/show.pdf.slim +2 -1
  76. data/app/views/renalware/patients/side_menu/_general.html.slim +4 -0
  77. data/app/views/renalware/surveys/_eq5d_summary_part.html.slim +26 -0
  78. data/app/views/renalware/surveys/_pos_s_summary_part.html.slim +26 -0
  79. data/app/views/renalware/surveys/dashboards/show.html.slim +32 -0
  80. data/config/initializers/chartkick.rb +6 -0
  81. data/config/initializers/core_extensions.rb +4 -4
  82. data/config/initializers/inflections.rb +3 -0
  83. data/config/locales/renalware/patients/side_menu.en.yml +1 -0
  84. data/config/routes/hd.rb +5 -1
  85. data/config/routes/patients.rb +4 -0
  86. data/db/migrate/20190927124840_create_hd_session_form_batches.rb +16 -0
  87. data/db/migrate/20190927130911_create_hd_session_form_batch_items.rb +17 -0
  88. data/db/migrate/20191008010839_create_surveys.rb +70 -0
  89. data/db/migrate/20191008024636_create_eq5d_views.rb +8 -0
  90. data/db/migrate/20191008030154_add_validation_regex_to_patient_survey_questions.rb +7 -0
  91. data/db/migrate/20191008045159_allow_null_patient_in_ukrdc_transmission_logs.rb +8 -0
  92. data/db/seeds/default/patients/seeds.rb +2 -0
  93. data/db/seeds/default/patients/surveys/eq5d_5l.rb +22 -0
  94. data/db/seeds/default/patients/surveys/eq5d_5l_questions.csv +7 -0
  95. data/db/seeds/default/patients/surveys/pos_s.rb +22 -0
  96. data/db/seeds/default/patients/surveys/pos_s_questions.csv +23 -0
  97. data/db/views/survey_eq5d_pivoted_responses_v01.sql +41 -0
  98. data/db/views/survey_pos_s_pivoted_responses_v01.sql +36 -0
  99. data/lib/core_extensions/active_record/migration_helpers.rb +1 -1
  100. data/lib/core_extensions/active_support/duration.rb +1 -1
  101. data/lib/core_extensions/scenic.rb +1 -1
  102. data/lib/renalware/engine.rb +4 -4
  103. data/lib/renalware/version.rb +1 -1
  104. data/lib/tasks/ukrdc.rake +9 -0
  105. data/spec/factories/patients/surveys.rb +24 -0
  106. data/spec/support/ukrdc_helpers.rb +16 -0
  107. metadata +98 -59
  108. data/app/views/renalware/letters/batches/show.html.slim +0 -7
  109. data/app/views/renalware/pathology/requests/requests/_pdf_header.html.slim +0 -13
  110. data/vendor/assets/javascripts/renalware/masonry.min.js +0 -9
  111. data/vendor/assets/javascripts/renalware/print.min.js +0 -1
  112. data/vendor/assets/stylesheets/renalware/balloon.css +0 -383
  113. data/vendor/assets/stylesheets/renalware/print.min.css +0 -1
  114. data/vendor/assets/stylesheets/renalware/select2/css/select2.css +0 -431
  115. data/vendor/assets/stylesheets/renalware/select2/css/select2.min.css +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcb6fe2a9d36fece24e482f2cf318d89af11914dab2beb7b346bf3a6cba9c8b8
4
- data.tar.gz: ecde69203a3b74dacc87163bb1b19bf103eb79b2a7e34742fe824d6a53e62f7d
3
+ metadata.gz: d5ca791105ad77524bc53a491d593ca9871363fdd5b3c3b874755f1a3898ca8c
4
+ data.tar.gz: 770c7beab9d9369f637cf067ff7fe9a068a579805690aeb76ef77a080be3bf6d
5
5
  SHA512:
6
- metadata.gz: 878519c049773af3fe86eb79f5a20274b470d6cbc4c132c3db7c25c67f324bc32a77bb8d6e0d9a9c1270c5090adc6187031b366be4443d4d7df66e60f2d44742
7
- data.tar.gz: 0f3cf22ee16a7737816afd2a0245aa0676d3cb3d1ab7c10b85c5873250c90da20e91e7ca96e7b2a1d32ce51231a71b85cdb43e9f0c2ee944da1d8d9da67a3836
6
+ metadata.gz: a10238b66a41f3a73e924acf31ac1691194fefd2738764a52bc3bcef8a75872288f0dbb55835ceed2579a50f2357b214641c55cc5d37a89ffab289af065a8514
7
+ data.tar.gz: 1f17f033bd3a78c003e385500b4505bb3eb1ec452adcc6c8850a210f79d0a2a5616065581a5eb2f891553dcbc9cbc409abfcf2f2f95be707ce59ff8843ac1fb0
data/Rakefile CHANGED
@@ -35,6 +35,9 @@ namespace :assets do
35
35
 
36
36
  desc "Precompile assets within dummy app"
37
37
  task :precompile do
38
+ p "Here"
39
+ Rake::Task["app:yarn:install"].invoke
40
+ p "There"
38
41
  Rake::Task["app:assets:precompile"].invoke
39
42
  end
40
43
 
@@ -44,6 +47,12 @@ namespace :assets do
44
47
  end
45
48
  end
46
49
 
50
+ namespace :yarn do
51
+ task :install do
52
+ Rake::Task["app:yarn:install"].invoke
53
+ end
54
+ end
55
+
47
56
  # Default rake task to run all tests:
48
57
  # bundle exec rake
49
58
  task :engine_default_task do
@@ -17,7 +17,6 @@
17
17
  //= require jquery-ui/core
18
18
  //= require jquery-ui/widgets/autocomplete
19
19
  //= require jquery-ui/widgets/sortable
20
- //= require jquery-ui/widgets/tabs
21
20
  //= require jquery-ui/effects/effect-highlight
22
21
  //= require dataTables/jquery.dataTables
23
22
  //= require dataTables/jquery.dataTables.foundation
@@ -31,22 +30,22 @@
31
30
  //= require foundation/foundation.tab
32
31
  //= require foundation/foundation.tooltip
33
32
  //= require foundation/foundation.topbar
34
- //= require underscore
35
- //= require select2
33
+ //= require underscore/underscore
34
+ //= require select2/dist/js/select2
36
35
  //= require jquery_nested_form
37
36
  //= require foundation-datepicker
38
37
  //= require renalware/clockpicker
39
38
  //= require renalware/double_scroll
40
39
  //= require cocoon
41
- //= require mousetrap
40
+ //= require mousetrap/mousetrap
42
41
  //= require renalware/iframeResizer
43
42
  //= require clipboard
44
- //= require renalware/masonry.min
43
+ //= require masonry-layout/dist/masonry.pkgd
45
44
  //= require rails.validations
46
45
  //= require rails.validations.simple_form
47
- //= require renalware/print.min
48
- //= require moment
49
- //= require_tree .
46
+ //= require print-js/dist/print
47
+ //= require moment/moment
48
+ //= require_directory .
50
49
  //
51
50
 
52
51
  // Define a console.log if one does not yet exist - e.g. we in IE11
@@ -0,0 +1,4 @@
1
+ //= require chartkick
2
+ //= require Chart.bundle
3
+ //= require_tree .
4
+ //
@@ -24,18 +24,7 @@ $(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
24
24
 
25
25
  var resizeSelect2DropDownsToFitModal = function(){
26
26
  $('.select2', modal).css('width', "100%");
27
- $('#tabs').on('tabsactivate', function(event, ui) {
28
- $('.select2').css('width', "100%");
29
- });
30
27
  };
31
-
32
- var layoutTabs = function() {
33
- // Layout any JQueryUI tabs
34
- $("#tabs").tabs();
35
- resizeSelect2DropDownsToFitModal();
36
- };
37
-
38
- layoutTabs();
39
28
  });
40
29
 
41
30
  // If there was an error submitting a modal form, be sure to re-enable the submit button
@@ -17,18 +17,18 @@ $(document).ready(function() {
17
17
  $(".hd-drug-administered input[type='radio']").on("change", function(e) {
18
18
  var checked = ($(this).val() == "true");
19
19
  var container = $(this).closest(".hd-drug-administration");
20
- $(container).toggleClass("administered", checked)
21
- $(container).toggleClass("not-administered", !checked)
20
+ $(container).toggleClass("administered", checked);
21
+ $(container).toggleClass("not-administered", !checked);
22
22
  $(container).removeClass("undecided");
23
- $(".authentication", container).toggle(checked)
24
- $(".authentication", container).toggleClass("disabled-with-faded-overlay", !checked)
23
+ $(".authentication", container).toggle(checked);
24
+ $(".authentication", container).toggleClass("disabled-with-faded-overlay", !checked);
25
25
  $(".reason-why-not-administered", container).toggle(!checked)
26
26
  });
27
27
 
28
28
  $(".hd-drug-administration .authentication-user-id").on("select2:select", function(e) {
29
29
  var container = $(this).closest(".user-and-password");
30
- var topContainer = $(container).closest(".hd-drug-administration")
31
- $(container).find(".authentication-token").val("")
30
+ var topContainer = $(container).closest(".hd-drug-administration");
31
+ $(container).find(".authentication-token").val("");
32
32
  $("input.user-password", container).val("");
33
33
  $(container).removeClass("authorised");
34
34
  var tokenCount = $(topContainer).find(".authorised").length;
@@ -41,8 +41,8 @@ $(document).ready(function() {
41
41
  $(".hd-drug-administration .user-and-password .user-and-password--clear").on("click", function(e) {
42
42
  e.preventDefault();
43
43
  var container = $(this).closest(".user-and-password");
44
- var topContainer = $(container).closest(".hd-drug-administration")
45
- $(container).find(".authentication-token").val("")
44
+ var topContainer = $(container).closest(".hd-drug-administration");
45
+ $(container).find(".authentication-token").val("");
46
46
  $("input.user-password", container).val("");
47
47
  $(container).removeClass("authorised");
48
48
  var tokenCount = $(topContainer).find(".authorised").length;
@@ -55,7 +55,7 @@ $(document).ready(function() {
55
55
  // TODO: also do this if enter pressed while in the password field.
56
56
  $(".user-and-password input.user-password").on("blur", function(e) {
57
57
  var container = $(this).closest(".user-and-password");
58
- var topContainer = $(container).closest(".hd-drug-administration")
58
+ var topContainer = $(container).closest(".hd-drug-administration");
59
59
  var authUrl = $(container).closest(".authentication").data("authentication-url");
60
60
  var userSelect = $(container).find(".authentication-user-id");
61
61
  var userId = $(userSelect).find("option:selected").val();
@@ -106,3 +106,53 @@ $(document).ready(function() {
106
106
  }
107
107
  });
108
108
  });
109
+
110
+ var Renalware = typeof Renalware === 'undefined' ? {} : Renalware;
111
+
112
+ Renalware.HD = (function() {
113
+ // This is pretty much a duplicate of Letters.pollBatchStatus and we will merge them soon
114
+ var pollBatchStatus = function(url) {
115
+ var POLL_INTERVAL = 2000; // ms
116
+ var batch = {};
117
+
118
+ // Check the current status of the TaskStatus object.
119
+ var updateStatus = function() {
120
+ $.ajax({
121
+ method: 'GET',
122
+ url: url,
123
+ contentType: 'json'
124
+ }).fail(function(e, x, a) {
125
+ // Possible network glitch or perhaps a re-deploy causing the site to be down momentarily.
126
+ // Anyway, not enough for us to give up polling.
127
+ // TODO: examine the response code to see if we should in fact give up and show an
128
+ // appropriate message.
129
+ setTimeout(updateStatus, POLL_INTERVAL);
130
+ }).done(function(batch) {
131
+ $(".modal .percent_complete").html(batch.percent_complete + "%");
132
+
133
+ switch(batch.status) {
134
+ case 'awaiting_printing':
135
+ $(".batch_results_container .preparing").hide();
136
+ $(".batch_results_container .generated-batch-print-pdf-container").show();
137
+ break;
138
+ case 'failure':
139
+ $(".batch_results_container .preparing").html("Failed");
140
+ break;
141
+ default:
142
+ // Ask again in POLL_INTERVAL ms.
143
+ setTimeout(updateStatus, POLL_INTERVAL);
144
+ };
145
+ });
146
+ };
147
+ setTimeout(updateStatus, POLL_INTERVAL);
148
+ };
149
+
150
+ return {
151
+ init: function () {
152
+ // nothing here yet
153
+ },
154
+ pollBatchStatus: pollBatchStatus
155
+ };
156
+ }());
157
+
158
+ $(document).ready(Renalware.HD.init);
@@ -11,7 +11,7 @@
11
11
  @import "foundation-datepicker";
12
12
  @import "dataTables/jquery.dataTables.foundation";
13
13
  @import "trix";
14
- @import "renalware/balloon";
14
+ @import "balloon-css/src/balloon";
15
15
  @import "./lib/foundation_and_overrides";
16
16
  @import "./lib/clockpicker";
17
17
  @import "./base/variables";
@@ -19,6 +19,5 @@
19
19
  @import "renalware/select2-foundation5";
20
20
  @import "./lib/select2-foundation5-overrides";
21
21
  @import "./modules/**/*";
22
- @import "renalware/print.min";
23
- @import "./print/**/*";
22
+ @import "print-js/dist/print";
24
23
  @import "./partials/**/*";
@@ -1,3 +1,22 @@
1
+ #hd-session-form-batch-print-modal {
2
+ .cancel-link {
3
+ margin-bottom: 0.5em;
4
+ display: inline-block;
5
+ font-size: 1rem;
6
+ }
7
+
8
+ .percent_complete {
9
+ font-size: 1.3rem;
10
+ float: right;
11
+ }
12
+
13
+ .modal__footer {
14
+ .left {
15
+ color: $dashboard-muted-color;
16
+ }
17
+ }
18
+ }
19
+
1
20
  .hd_transmission_logs {
2
21
  tr {
3
22
  &.session_import_success {
@@ -369,6 +369,7 @@ form {
369
369
 
370
370
  .summary-part--events,
371
371
  .summary-part--admissions,
372
+ .summary-part--eq5d,
372
373
  .summary-part--consults {
373
374
  @include grid-column(12);
374
375
 
@@ -418,6 +419,12 @@ form {
418
419
  }
419
420
  }
420
421
  }
422
+
423
+ .summary-part--eq5d table {
424
+ td, th {
425
+ text-align: center;
426
+ }
427
+ }
421
428
  }
422
429
 
423
430
  #select2-practice-search-results {
@@ -31,3 +31,29 @@ hr.page_break {
31
31
  }
32
32
 
33
33
  div.alwaysbreak { page-break-before: always; }
34
+
35
+ .path-request-form {
36
+ table {
37
+ width: 100%;
38
+ td, th {
39
+ padding: .3rem;
40
+ }
41
+ }
42
+
43
+ h4, h3 {
44
+ font-size: 1.2rem;
45
+ }
46
+
47
+ .border_box_half {
48
+ width: 47%;
49
+ margin-top: .5rem;
50
+ padding: 0.5rem;
51
+
52
+ &.global_requests {
53
+ float: left;
54
+ }
55
+ &.patient_requests {
56
+ float: right;
57
+ }
58
+ }
59
+ }
@@ -138,11 +138,11 @@ h1 {
138
138
  &.col-width-date {
139
139
  min-width: 6rem;
140
140
  width: 6rem;
141
+ text-align: centre;
141
142
  }
142
143
 
143
144
  &.col-width-time {
144
- min-width: 5.6rem;
145
- width: 5.6rem;
145
+ width: 3rem;
146
146
  }
147
147
 
148
148
  &.col-width-minute {
@@ -155,6 +155,11 @@ h1 {
155
155
  width: 5rem;
156
156
  }
157
157
 
158
+ &.col-width-bp {
159
+ min-width: 3.7rem;
160
+ width: 3.7rem;
161
+ }
162
+
158
163
  &.col-width-drugs {
159
164
  min-width: 10rem;
160
165
  width: 10rem;
@@ -179,7 +184,7 @@ h1 {
179
184
  td {
180
185
  border-top: solid 1px #000;
181
186
  height: 2rem;
182
- padding: 3px;
187
+ padding: 1px;
183
188
  text-align: center;
184
189
 
185
190
  &.text-left {
@@ -188,7 +193,7 @@ h1 {
188
193
  }
189
194
 
190
195
  &.empty-session-row {
191
- height: 4rem;
196
+ height: 3.5rem;
192
197
  &.first {
193
198
  td {
194
199
  border-top: solid 2px #000;
@@ -6,11 +6,13 @@ module Renalware
6
6
  module HD
7
7
  class MDMPatientsController < Renalware::MDMPatientsController
8
8
  def index
9
- render_index(filter_form: filter_form,
10
- query: query,
11
- page_title: t(".page_title"),
12
- view_proc: ->(patient) { patient_hd_mdm_path(patient) },
13
- patient_presenter_class: HD::PatientPresenter)
9
+ render_index(
10
+ filter_form: filter_form,
11
+ query: query,
12
+ page_title: t(".page_title"),
13
+ view_proc: ->(patient) { patient_hd_mdm_path(patient) },
14
+ patient_presenter_class: HD::PatientPresenter
15
+ )
14
16
  end
15
17
 
16
18
  private
@@ -48,12 +50,21 @@ module Renalware
48
50
  params[:named_filter]
49
51
  end
50
52
 
53
+ def batch_print_form
54
+ patient_ids = query.call.pluck("patients.id").join(",")
55
+ SessionForms::Form.new(patient_ids: patient_ids)
56
+ end
57
+
51
58
  def render_index(filter_form:, **args)
52
59
  presenter = build_presenter(params: params, **args)
53
60
  authorize presenter.patients
54
61
  render(
55
62
  :index,
56
- locals: { presenter: presenter, filter_form: filter_form }
63
+ locals: {
64
+ presenter: presenter,
65
+ filter_form: filter_form,
66
+ batch_print_form: batch_print_form
67
+ }
57
68
  )
58
69
  end
59
70
  end
@@ -4,51 +4,42 @@ require_dependency "renalware/hd/base_controller"
4
4
 
5
5
  module Renalware
6
6
  module HD
7
+ # Responsible for rendering an HD Session Form PDF (aka Protocol) which has the patients
8
+ # past 3 sessions on it, and empty rows for their next three sessions.
7
9
  class ProtocolsController < BaseController
8
- before_action :load_patient
9
-
10
+ # Note that although rendering an individual PDF for a patient here, we use PdfRender
11
+ # which can handles multiple patients, and hence it uses the index.pdf.slim view.
12
+ # The show view is not used.
10
13
  def show
14
+ authorize Session, :show?
11
15
  respond_to do |format|
12
- format.pdf {
13
- disposition = params.fetch("disposition", "inline")
14
- render_pdf(disposition)
15
- }
16
+ format.html { render html: pdf_renderer.call }
17
+ format.pdf { send_pdf_data_as_inline_file }
16
18
  end
17
19
  end
18
20
 
19
21
  private
20
22
 
21
- def render_pdf(disposition)
22
- render(
23
- pdf_options.merge(
24
- pdf: pdf_filename,
25
- disposition: disposition,
26
- print_media_type: true,
27
- locals: {
28
- protocol: ProtocolPresenter.new(patient, view_context)
29
- }
30
- )
23
+ def send_pdf_data_as_inline_file
24
+ send_data(
25
+ pdf_renderer.call,
26
+ filename: pdf_filename,
27
+ type: "application/pdf",
28
+ disposition: "inline"
31
29
  )
32
30
  end
33
31
 
34
- # Other options to consider:
35
- # viewport_size: '1280x1024'
36
- # disable_smart_shrinking: true
37
- def pdf_options
38
- {
39
- page_size: "A4",
40
- orientation: "Landscape",
41
- layout: "renalware/layouts/pdf",
42
- margin: { top: 10, bottom: 10, left: 10, right: 10 },
43
- footer: {
44
- font_size: 8
45
- },
46
- show_as_html: (Rails.env.development? || Rails.env.test?) && params.key?("debug")
47
- }
32
+ def pdf_renderer
33
+ @pdf_renderer ||= begin
34
+ SessionForms::PdfRenderer.new(
35
+ patients: patient,
36
+ output_html_for_debugging: params.key?(:debug)
37
+ )
38
+ end
48
39
  end
49
40
 
50
41
  def pdf_filename
51
- "#{patient.family_name}-#{patient.hospital_identifier.id}-protocol".upcase
42
+ "#{patient.family_name}-#{patient.hospital_identifier.id}-protocol".upcase + ".pdf"
52
43
  end
53
44
  end
54
45
  end