renalware-core 2.0.130 → 2.0.131

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/app/controllers/renalware/admin/users_controller.rb +1 -0
  4. data/app/controllers/renalware/medications/prescriptions_controller.rb +2 -2
  5. data/app/controllers/renalware/patients/patients_controller.rb +1 -1
  6. data/app/jobs/renalware/letters/calculate_page_count_job.rb +5 -0
  7. data/app/models/concerns/renalware/pdf_compilation.rb +2 -2
  8. data/app/models/renalware/events/lists/form.rb +1 -1
  9. data/app/models/renalware/letters/approve_letter.rb +3 -1
  10. data/app/models/renalware/letters/delivery/email_letter_to_practice.rb +6 -14
  11. data/app/models/renalware/letters/lists/form.rb +2 -2
  12. data/app/models/renalware/letters/pdf_renderer.rb +1 -0
  13. data/app/models/renalware/letters/printing/pdf_combining.rb +2 -2
  14. data/app/models/renalware/medications/dose_unit.rb +2 -0
  15. data/app/models/renalware/modalities/description.rb +10 -2
  16. data/app/models/renalware/pd/apd/glucose_calculator.rb +2 -2
  17. data/app/models/renalware/system/update_user.rb +3 -0
  18. data/app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb +15 -4
  19. data/app/models/renalware/ukrdc/create_patient_xml_file.rb +16 -3
  20. data/app/models/renalware/ukrdc/outgoing/rendering/address.rb +38 -0
  21. data/app/models/renalware/ukrdc/outgoing/rendering/allergy.rb +27 -0
  22. data/app/models/renalware/ukrdc/outgoing/rendering/base.rb +20 -0
  23. data/app/models/renalware/ukrdc/outgoing/rendering/cause_of_death.rb +38 -0
  24. data/app/models/renalware/ukrdc/outgoing/rendering/clinic_visit_observation.rb +24 -0
  25. data/app/models/renalware/ukrdc/outgoing/rendering/clinician.rb +12 -0
  26. data/app/models/renalware/ukrdc/outgoing/rendering/diagnoses.rb +63 -0
  27. data/app/models/renalware/ukrdc/outgoing/rendering/diagnosis.rb +52 -0
  28. data/app/models/renalware/ukrdc/outgoing/rendering/dialysis_session.rb +81 -0
  29. data/app/models/renalware/ukrdc/outgoing/rendering/document.rb +46 -0
  30. data/app/models/renalware/ukrdc/outgoing/rendering/entered_at.rb +26 -0
  31. data/app/models/renalware/ukrdc/outgoing/rendering/entered_by.rb +12 -0
  32. data/app/models/renalware/ukrdc/outgoing/rendering/family_doctor.rb +30 -0
  33. data/app/models/renalware/ukrdc/outgoing/rendering/hd_session_observations.rb +51 -0
  34. data/app/models/renalware/ukrdc/outgoing/rendering/hd_treatment.rb +26 -0
  35. data/app/models/renalware/ukrdc/outgoing/rendering/lab_order.rb +80 -0
  36. data/app/models/renalware/ukrdc/outgoing/rendering/lab_orders.rb +30 -0
  37. data/app/models/renalware/ukrdc/outgoing/rendering/medication.rb +77 -0
  38. data/app/models/renalware/ukrdc/outgoing/rendering/name.rb +29 -0
  39. data/app/models/renalware/ukrdc/outgoing/rendering/observation.rb +70 -0
  40. data/app/models/renalware/ukrdc/outgoing/rendering/observations.rb +58 -0
  41. data/app/models/renalware/ukrdc/outgoing/rendering/patient.rb +167 -0
  42. data/app/models/renalware/ukrdc/outgoing/rendering/patient_number.rb +27 -0
  43. data/app/models/renalware/ukrdc/outgoing/rendering/patient_numbers.rb +53 -0
  44. data/app/models/renalware/ukrdc/outgoing/rendering/pd_treatment.rb +27 -0
  45. data/app/models/renalware/ukrdc/outgoing/rendering/primary_language.rb +35 -0
  46. data/app/models/renalware/ukrdc/outgoing/rendering/procedures.rb +40 -0
  47. data/app/models/renalware/ukrdc/outgoing/rendering/renal_diagnosis.rb +35 -0
  48. data/app/models/renalware/ukrdc/outgoing/rendering/transplant.rb +69 -0
  49. data/app/models/renalware/ukrdc/outgoing/rendering/treatment.rb +78 -0
  50. data/app/models/renalware/ukrdc/outgoing/rendering/user.rb +33 -0
  51. data/app/models/renalware/ukrdc/pathology_observation_requests_query.rb +1 -0
  52. data/app/models/renalware/ukrdc/xml_renderer.rb +54 -75
  53. data/app/models/renalware/user.rb +4 -1
  54. data/app/presenters/renalware/hd/scheduling/diary_presenter.rb +2 -2
  55. data/app/presenters/renalware/system/users_presenter.rb +1 -1
  56. data/app/presenters/renalware/ukrdc/transplant_operation_presenter.rb +4 -0
  57. data/app/views/renalware/admin/users/edit.html.slim +6 -0
  58. data/app/views/renalware/admin/users/index.html.slim +6 -1
  59. data/app/views/renalware/api/ukrdc/patients/_clinic_visit_observation.xml.builder +3 -3
  60. data/app/views/renalware/api/ukrdc/patients/_documents.xml.builder +28 -24
  61. data/app/views/renalware/api/ukrdc/patients/_sending_facility.xml.builder +1 -1
  62. data/app/views/renalware/api/ukrdc/patients/_treatments.xml.builder +0 -27
  63. data/app/views/renalware/api/ukrdc/patients/show.xml.builder +1 -5
  64. data/app/views/renalware/medications/drug_types/prescriptions/_table.html.slim +1 -1
  65. data/app/views/renalware/patients/patients/_form.html.slim +1 -0
  66. data/app/views/renalware/patients/patients/show/_contact_details.html.slim +2 -1
  67. data/config/initializers/core_extensions.rb +1 -0
  68. data/config/initializers/devise.rb +1 -1
  69. data/config/locales/renalware/medications/prescription.yml +2 -0
  70. data/db/migrate/20170526060804_enable_uuid_extension.rb +1 -1
  71. data/db/migrate/20191219145651_add_hidden_to_users.rb +8 -0
  72. data/db/migrate/20200106073329_add_next_of_kin_to_patients.rb +7 -0
  73. data/db/migrate/20200106210851_create_case_insensitive_index_on_patients.rb +22 -0
  74. data/lib/core_extensions/active_record/migration_helpers.rb +7 -0
  75. data/lib/core_extensions/ox/element_additions.rb +18 -0
  76. data/lib/renalware/engine.rb +2 -1
  77. data/lib/renalware/version.rb +1 -1
  78. data/lib/tasks/spec.rake +33 -0
  79. data/spec/factories/accesses/assessments.rb +18 -0
  80. data/spec/factories/accesses/catheter_insertion_techniques.rb +8 -0
  81. data/spec/factories/accesses/plans.rb +1 -1
  82. data/spec/factories/accesses/plans_types.rb +1 -1
  83. data/spec/factories/accesses/procedures.rb +2 -2
  84. data/spec/factories/accesses/profiles.rb +1 -1
  85. data/spec/factories/accesses/sites.rb +1 -1
  86. data/spec/factories/accesses/types.rb +1 -1
  87. data/spec/factories/hd/hd_session_document.rb +8 -8
  88. data/spec/factories/transplants/donations.rb +1 -1
  89. data/spec/factories/transplants/recipient_followups.rb +1 -1
  90. data/spec/factories/transplants/recipient_operations.rb +1 -1
  91. data/spec/factories/transplants/registration_status_descriptions.rb +1 -1
  92. data/spec/factories/transplants/registration_statuses.rb +1 -1
  93. data/spec/factories/transplants/registrations.rb +1 -1
  94. data/spec/factories/transplants/rejection_episodes.rb +1 -1
  95. data/spec/factories/transplants/rejection_treatments.rb +1 -1
  96. data/spec/factories/ukrdc/modality_codes.rb +1 -1
  97. data/spec/support/capybara_helper.rb +6 -0
  98. data/spec/support/letters_spec_helper.rb +2 -2
  99. data/spec/support/pages/accesses/procedure_page.rb +53 -0
  100. data/spec/support/pages/accesses/profile_page.rb +45 -0
  101. data/spec/support/pages/clinical/allergy_page.rb +74 -0
  102. data/spec/support/pages/letters/form.rb +5 -3
  103. data/spec/support/shared_contexts/a_global_rule_set.rb +1 -1
  104. data/spec/support/xml_spec_helper.rb +9 -0
  105. metadata +60 -11
  106. data/app/views/renalware/api/ukrdc/patients/_clinical_relationships.xml.builder +0 -7
  107. data/app/views/renalware/api/ukrdc/patients/_family_histories.xml.builder +0 -7
  108. data/app/views/renalware/api/ukrdc/patients/_program_memberships.xml.builder +0 -7
  109. data/app/views/renalware/api/ukrdc/patients/_surveys.xml.builder +0 -7
  110. data/app/views/renalware/api/ukrdc/patients/observations/_blood_pressure.xml.builder +0 -0
  111. data/app/views/renalware/api/ukrdc/patients/observations/_standing_blood_pressure.xml.builder +0 -0
  112. data/app/views/renalware/api/ukrdc/patients/observations/_weight.xml.builder +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da57af35307fc3b61ecd3a63a06fbbc38bcf7b11a50e81b2def0333a5f9cd773
4
- data.tar.gz: dce6d2238587ebb06f9b25d2fb4dd90997255eb485af69df9fb0a2ad4ed080a4
3
+ metadata.gz: 35b6c3d73ccaf2718acd3d48e5982b3453521ca161126690a51af0de3bb08733
4
+ data.tar.gz: e0fcdc5ade9caf2e87745953b7d6c060fabb96720ac90e8978618b36a48d31b5
5
5
  SHA512:
6
- metadata.gz: 319282259cb9f86a3d0bbd343b236401accd2bc70be630e152e309de57199a02680f7c27e4f566ad2eb7c8523c18a31641610f683082965f3e6684991c99b65e
7
- data.tar.gz: 89d78ef44fc08a1de7e88ddb24f9e6c1f401c0d1481156d6cd3d967b01b130ba12aaf83006dc2183a12128ba702d37e663743776d4eb533ec3ef183be8788f39
6
+ metadata.gz: 645842282347e02444bdd310dc575b72137c3613139a7dee8543b21a085cd6437ec6b521aa66881f097ee17567a58048d118815926b81ca095b560cfe38b4a2c
7
+ data.tar.gz: 57b3894daa3d58de88660f763d8e4b4a61fb8cad3361210c6567d074d1b8c6ee71a75effaba63cb9ee0905aa9fce3b39d3d564e1de65bcc4ec8029d1833acf72
data/README.md CHANGED
@@ -54,8 +54,9 @@ psql template1
54
54
  At the psql prompt run the following (replacing `<username>` and `<password>` accordingly):
55
55
 
56
56
  ```sql
57
- CREATE USER <username> WITH PASSWORD '<password>';
58
- ALTER USER <username> SUPERUSER;
57
+ CREATE USER renalware WITH PASSWORD 'renalware';
58
+ ALTER USER renalware WITH SUPERUSER;
59
+ ALTER USER renalware WITH LOGIN;
59
60
  ```
60
61
 
61
62
  ### Configure Ruby
@@ -50,6 +50,7 @@ module Renalware
50
50
  :unexpire,
51
51
  :telephone,
52
52
  :consultant,
53
+ :hidden,
53
54
  role_ids: []
54
55
  )
55
56
  end
@@ -73,7 +73,7 @@ module Renalware
73
73
  render :index, locals: locals
74
74
  end
75
75
 
76
- # rubocop:disable Metrics/LineLength
76
+ # rubocop:disable Layout/LineLength
77
77
  def render_prescriptions_list_to_hand_to_patient
78
78
  render(
79
79
  pdf_options.merge(
@@ -89,7 +89,7 @@ module Renalware
89
89
  )
90
90
  )
91
91
  end
92
- # rubocop:enable Metrics/LineLength
92
+ # rubocop:enable Layout/LineLength
93
93
 
94
94
  def pdf_filename
95
95
  "#{patient.family_name}_#{patient.hospital_identifier&.id}" \
@@ -93,7 +93,7 @@ module Renalware
93
93
  :nhs_number, :family_name, :given_name, :sex, :country_of_birth_id,
94
94
  :ethnicity_id, :born_on, :paediatric_patient_indicator, :cc_on_all_letters,
95
95
  :title, :suffix, :marital_status, :telephone1, :telephone2, :email, :religion_id,
96
- :language_id, :cc_decision_on,
96
+ :language_id, :cc_decision_on, :next_of_kin,
97
97
  :local_patient_id, :local_patient_id_2, :local_patient_id_3,
98
98
  :local_patient_id_4, :local_patient_id_5, :external_patient_id,
99
99
  :send_to_renalreg, :send_to_rpv, :renalreg_decision_on, :rpv_decision_on,
@@ -29,6 +29,11 @@ module Renalware
29
29
 
30
30
  def call
31
31
  letter.update_column(:page_count, pdf_reader.page_count)
32
+ rescue StandardError => e
33
+ # In Wisper async jobs, rescue_from blocks defined on the ApplicationJob class
34
+ # do not seem to be called, so we need to invoke them ourselves with this call to a fn on
35
+ # ActiveSupport::Rescuable which is already mixed into ActiveJob::Base.
36
+ rescue_with_handler(e) || raise
32
37
  end
33
38
 
34
39
  private
@@ -22,7 +22,7 @@ module Renalware
22
22
  end
23
23
  end
24
24
 
25
- # rubocop:disable Metrics/LineLength
25
+ # rubocop:disable Layout/LineLength
26
26
  def shell_to_ghostscript_to_combine_files(filenames, dir, outputfile)
27
27
  outputfile = Pathname(outputfile)
28
28
  cmd = "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{outputfile} -dBATCH #{filenames.join(' ')}"
@@ -35,7 +35,7 @@ module Renalware
35
35
  raise "Error combining PDFs: #{[err, msg].join(' ')} command: #{cmd}"
36
36
  end
37
37
  end
38
- # rubocop:enable Metrics/LineLength
38
+ # rubocop:enable Layout/LineLength
39
39
 
40
40
  def move_tempfile_to_output_file(tmp_outfile, output_file)
41
41
  FileUtils.mv tmp_outfile.path, output_file
@@ -32,7 +32,7 @@ module Renalware
32
32
  end
33
33
 
34
34
  def created_by_options
35
- User.excluding_system_user.ordered
35
+ User.excluding_system_user.picklist
36
36
  end
37
37
  end
38
38
  end
@@ -19,7 +19,9 @@ module Renalware
19
19
  archive_recipients
20
20
  sign(by: by)
21
21
  archive_content(by: by)
22
- broadcast(:letter_approved, letter)
22
+ # Cast the letter to the base Letter class in case it becomes a Letters::Completed
23
+ # before any async listeners have time to process it.
24
+ broadcast(:letter_approved, letter.becomes(Letters::Letter))
23
25
  end
24
26
  end
25
27
 
@@ -28,23 +28,15 @@ module Renalware
28
28
 
29
29
  private
30
30
 
31
+ # Note we are already in a tx here from the letterlistener, so for safety we call
32
+ # call #deliver_later and not #deliver; its possible we could get a
33
+ # LetterIsNotApprovedOrCompletedError error in the mailer we and we don't want that to
34
+ # roll back the txn. We could possibly use an async Listener and remove the
35
+ # deliver_later here.
31
36
  def email_letter_to_the_patients_practice
32
- # Note we cast the letter back to the superclass Letters::Letter here to prevent
33
- # GlobalID from trying to load the letter using e.g. Letters::Approved.find(123), because
34
- # in the meantime the letter's class might have progressed to Letters::Completed in which
35
- # case GlobalId/ ActiveJob would not be able to find the letter!
36
- # Casting to Letters::Letter means in the delayed job the handler says e.g.
37
- # - letter:
38
- # _aj_globalid: gid://dummy/Renalware::Letters::Letter/3
39
- # which it turns out works fine when the letter is loaded by GlobalId/ActiveJob;
40
- # it correctly casts the letter to its STI type e.g. Letters::Approved in the job.
41
- # Note we are already in a tx here from the letterlistener so if we for instance
42
- # call deliver and not deliver_later, we will get a LetterIsNotApprovedOrCompletedError
43
- # error when it looks up the letter as its approved state has not yet been saved.
44
- # We could possibly use an async LetterListener and remove the async here.
45
37
  Letter.transaction do
46
38
  PracticeMailer.patient_letter(
47
- letter: letter.becomes(Letter),
39
+ letter: letter,
48
40
  to: practice_email_address
49
41
  ).deliver_later # ! see comment
50
42
 
@@ -43,11 +43,11 @@ module Renalware
43
43
  end
44
44
 
45
45
  def author_options
46
- @author_options ||= User.author.ordered
46
+ @author_options ||= User.author.picklist
47
47
  end
48
48
 
49
49
  def typist_options
50
- @typist_options ||= User.ordered
50
+ @typist_options ||= User.picklist
51
51
  end
52
52
 
53
53
  def letterhead_options
@@ -22,6 +22,7 @@ module Renalware
22
22
  letter = LetterPresenterFactory.new(letter)
23
23
  end
24
24
  PdfLetterCache.fetch(letter, **options) do
25
+ Rails.logger.info " Rendering PDF for letter #{letter.id}"
25
26
  WickedPdf.new.pdf_from_string(letter.to_html(**options), OPTIONS)
26
27
  end
27
28
  end
@@ -27,7 +27,7 @@ module Renalware
27
27
  end
28
28
  end
29
29
 
30
- # rubocop:disable Metrics/LineLength
30
+ # rubocop:disable Layout/LineLength
31
31
  def shell_to_ghostscript_to_combine_files(filenames, dir, outputfile)
32
32
  outputfile = Pathname(outputfile)
33
33
  cmd = "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=#{outputfile} -dBATCH #{filenames.join(' ')}"
@@ -40,7 +40,7 @@ module Renalware
40
40
  raise "Error combining PDFs: #{[err, msg].join(' ')} command: #{cmd}"
41
41
  end
42
42
  end
43
- # rubocop:enable Metrics/LineLength
43
+ # rubocop:enable Layout/LineLength
44
44
 
45
45
  def move_tempfile_to_output_file(tmp_outfile, output_file)
46
46
  FileUtils.mv tmp_outfile.path, output_file
@@ -16,7 +16,9 @@ module Renalware
16
16
  milligram
17
17
  millilitre
18
18
  nanogram
19
+ patch
19
20
  puff
21
+ sachet
20
22
  tab
21
23
  tablet
22
24
  unit
@@ -28,11 +28,19 @@ module Renalware
28
28
  end
29
29
 
30
30
  # For a ModalityDescription with type Renalware::HD::ModalityDescription
31
- # this will return "HD"
31
+ # this will return "hd"
32
32
  def namespace
33
33
  return if type.blank?
34
34
 
35
- type.gsub("::", "").gsub(/^Renalware/, "").gsub(/ModalityDescription$/, "").underscore
35
+ namespace_raw.underscore
36
+ end
37
+
38
+ # For a ModalityDescription with type Renalware::HD::ModalityDescription
39
+ # this will return "HD"
40
+ def namespace_raw
41
+ return if type.blank?
42
+
43
+ type.gsub("::", "").gsub(/^Renalware/, "").gsub(/ModalityDescription$/, "")
36
44
  end
37
45
  end
38
46
  end
@@ -44,11 +44,11 @@ module Renalware
44
44
  end
45
45
  end
46
46
 
47
- # rubocop:disable Metrics/LineLength
47
+ # rubocop:disable Layout/LineLength
48
48
  def glucose_for_bag(bag)
49
49
  (((bag.volume.to_f * bag.days_per_week.to_f) / available_overnight_volume.to_f) * overnight_volume) / 7
50
50
  end
51
- # rubocop:enable Metrics/LineLength
51
+ # rubocop:enable Layout/LineLength
52
52
 
53
53
  def available_overnight_volume
54
54
  @available_overnight_volume ||= AvailableOvernightVolume.new(regime: regime).value
@@ -20,11 +20,13 @@ module Renalware
20
20
 
21
21
  private
22
22
 
23
+ # rubocop:disable Metrics/AbcSize
23
24
  def update!(params)
24
25
  User.transaction do
25
26
  approve if can_approve?(params)
26
27
  unexpire if can_unexpire?(params)
27
28
  user.consultant = true?(params[:consultant])
29
+ user.hidden = true?(params[:hidden])
28
30
  authorise(params)
29
31
  user.telephone = params[:telephone]
30
32
  user.save!
@@ -32,6 +34,7 @@ module Renalware
32
34
  rescue ActiveRecord::RecordInvalid
33
35
  false
34
36
  end
37
+ # rubocop:enable Metrics/AbcSize
35
38
 
36
39
  def notify!
37
40
  notifications.each { |n| n.public_send(delivery_method) } if notifications.any?
@@ -10,7 +10,7 @@ module Renalware
10
10
  # about them. Encrypt the xml files and copy to an outgoing folder
11
11
  # which might for example be a symlink to an outgoing folder in /media/ukrdc which in turn
12
12
  # is mount on a remote share for example on an SFTP server.
13
- #
13
+ # rubocop:disable Metrics/ClassLength:
14
14
  class CreateEncryptedPatientXMLFiles
15
15
  attr_reader(
16
16
  :patient_ids,
@@ -34,6 +34,7 @@ module Renalware
34
34
  @force_send = force_send
35
35
  end
36
36
 
37
+ # rubocop:disable Metrics/MethodLength
37
38
  def call
38
39
  logger.tagged(request_uuid) do
39
40
  summary.milliseconds_taken = Benchmark.ms do
@@ -51,6 +52,7 @@ module Renalware
51
52
  Engine.exception_notifier.notify(e)
52
53
  raise e
53
54
  end
55
+ # rubocop:enable Metrics/MethodLength
54
56
 
55
57
  private
56
58
 
@@ -64,12 +66,20 @@ module Renalware
64
66
  end
65
67
  end
66
68
 
69
+ def schema
70
+ xsd_path = File.join(Renalware::Engine.root, "vendor/xsd/ukrdc/Schema/UKRDC.xsd")
71
+ xsddoc = Nokogiri::XML(File.read(xsd_path), xsd_path)
72
+ Nokogiri::XML::Schema.from_document(xsddoc)
73
+ end
74
+
75
+ # rubocop:disable Metrics/MethodLength
67
76
  def create_patient_xml_files
68
77
  count = 0
69
78
  patients = ukrdc_patients_who_have_changed_since_last_send
70
79
  summary.num_changed_patients = patients.count
71
80
  patients.find_each do |patient|
72
81
  count += 1
82
+ Rails.logger.info count
73
83
  CreatePatientXMLFile.new(
74
84
  patient: patient,
75
85
  dir: paths.timestamped_xml_folder,
@@ -77,13 +87,15 @@ module Renalware
77
87
  request_uuid: request_uuid,
78
88
  batch_number: batch_number,
79
89
  logger: logger,
80
- force_send: force_send
90
+ force_send: force_send,
91
+ schema: schema
81
92
  ).call
82
93
 
83
94
  # Every n patients, force the garbage collector to kick in
84
95
  GC.start if (count % 10).zero?
85
96
  end
86
97
  end
98
+ # rubocop:enable Metrics/MethodLength
87
99
 
88
100
  def build_summary
89
101
  summary.count_of_files_in_outgoing_folder = count_of_files_in_outgoing_folder
@@ -115,14 +127,12 @@ module Renalware
115
127
  end
116
128
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
117
129
 
118
- # rubocop:disable Metrics/AbcSize
119
130
  def print_summary
120
131
  logger.info("Files saved to #{summary.archive_folder}")
121
132
  logger.info "*** Summary ***"
122
133
  logger.info "Took #{summary.milliseconds_taken.to_i / 1000} seconds"
123
134
  summary.results.map { |key, value| logger.info("#{key}: #{value}") }
124
135
  end
125
- # rubocop:enable Metrics/AbcSize
126
136
 
127
137
  def email_summary
128
138
  UKRDC::SummaryMailer.export_summary(
@@ -166,5 +176,6 @@ module Renalware
166
176
  )
167
177
  end
168
178
  end
179
+ # rubocop:enable Metrics/ClassLength:
169
180
  end
170
181
  end
@@ -10,6 +10,7 @@ module Renalware
10
10
  :patient!,
11
11
  :dir!,
12
12
  :request_uuid!,
13
+ :schema,
13
14
  :changes_since,
14
15
  :logger,
15
16
  :batch_number,
@@ -18,7 +19,7 @@ module Renalware
18
19
  :force_send
19
20
  ]
20
21
 
21
- # rubocop:disable Metrics/AbcSize
22
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
22
23
  # If force_send is true then send all files even if they have not changed since the last
23
24
  # send. This is primarily for debugging and testing phases with UKRDC
24
25
  def call
@@ -39,7 +40,7 @@ module Renalware
39
40
  logger.info " Status: #{log.status}"
40
41
  end
41
42
  end
42
- # rubocop:enable Metrics/AbcSize
43
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
43
44
 
44
45
  private
45
46
 
@@ -101,8 +102,20 @@ module Renalware
101
102
  nil
102
103
  end
103
104
 
105
+ def schema
106
+ @schema ||= begin
107
+ Rails.logger.info "Creating Nokogiri::XML::Schema"
108
+ xsd_path = File.join(Renalware::Engine.root, "vendor/xsd/ukrdc/Schema/UKRDC.xsd")
109
+ xsddoc = Nokogiri::XML(File.read(xsd_path), xsd_path)
110
+ Nokogiri::XML::Schema.from_document(xsddoc)
111
+ end
112
+ end
113
+
104
114
  def default_renderer
105
- Renalware::UKRDC::XmlRenderer.new(locals: { patient: presenter_for(patient) })
115
+ Renalware::UKRDC::XmlRenderer.new(
116
+ schema: schema,
117
+ locals: { patient: presenter_for(patient) }
118
+ )
106
119
  end
107
120
 
108
121
  def presenter_for(patient)
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Renalware
4
+ module UKRDC
5
+ module Outgoing
6
+ module Rendering
7
+ class Address < Rendering::Base
8
+ pattr_initialize [:address!]
9
+
10
+ def xml
11
+ address_element
12
+ end
13
+
14
+ private
15
+
16
+ def address_element
17
+ create_node("Address") do |elem|
18
+ elem[:use] = "H"
19
+ elem << create_node("Street", address.street)
20
+ elem << create_node("Town", address.town)
21
+ elem << create_node("County", address.county)
22
+ elem << create_node("Postcode", address.postcode&.strip)
23
+ elem << country_element
24
+ end
25
+ end
26
+
27
+ def country_element
28
+ create_node("Country") do |elem|
29
+ elem << create_node(:CodingStandard, "ISO3166-1")
30
+ elem << create_node(:Code, address&.country&.alpha3)
31
+ elem << create_node(:Description, address&.country&.to_s)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Renalware
4
+ module UKRDC
5
+ module Outgoing
6
+ module Rendering
7
+ class Allergy < Rendering::Base
8
+ pattr_initialize [:allergy!]
9
+
10
+ def xml
11
+ allergy_element
12
+ end
13
+
14
+ private
15
+
16
+ def allergy_element
17
+ create_node("Allergy") do |elem|
18
+ create_node("Allergy") # this is correct, see schema
19
+ elem << Rendering::Clinician.new(user: allergy.updated_by).xml
20
+ elem << create_node("FreeTextAllergy", allergy.description)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end