renalware-core 2.0.0.pre.beta8 → 2.0.0.pre.beta9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -1
  3. data/app/assets/stylesheets/renalware/lib/_select2-foundation5-overrides.scss +2 -2
  4. data/app/controllers/renalware/directory/people_controller.rb +1 -1
  5. data/app/controllers/renalware/letters/contacts_controller.rb +1 -1
  6. data/app/controllers/renalware/letters/letters_controller.rb +1 -1
  7. data/app/controllers/renalware/patients/patients_controller.rb +3 -5
  8. data/app/controllers/renalware/patients/primary_care_physicians_controller.rb +1 -1
  9. data/app/controllers/renalware/renal/aki_alerts_controller.rb +44 -0
  10. data/app/controllers/renalware/renal/profiles_controller.rb +1 -1
  11. data/app/controllers/renalware/reporting/audits_controller.rb +9 -3
  12. data/app/documents/renalware/patient_document.rb +0 -13
  13. data/app/jobs/hl7_message_example.yml +1 -1
  14. data/app/jobs/renalware/reporting/refresh_audit_data_job.rb +7 -3
  15. data/app/models/renalware/clinical/create_allergy.rb +4 -2
  16. data/app/models/renalware/clinics/create_clinic_visit.rb +6 -2
  17. data/app/models/renalware/hd/session.rb +12 -0
  18. data/app/models/renalware/hospitals/unit.rb +4 -0
  19. data/app/models/renalware/hospitals/ward.rb +22 -0
  20. data/app/models/renalware/modalities/change_patient_modality.rb +4 -2
  21. data/app/models/renalware/patient.rb +1 -0
  22. data/app/models/renalware/patients/language.rb +1 -0
  23. data/app/models/renalware/pd/create_regime.rb +4 -2
  24. data/app/models/renalware/pd/revise_regime.rb +5 -3
  25. data/app/models/renalware/renal/aki_alert.rb +15 -0
  26. data/app/models/renalware/renal/aki_alert_action.rb +10 -0
  27. data/app/models/renalware/reporting/audit.rb +2 -3
  28. data/app/models/renalware/reporting/generate_audit_json.rb +21 -5
  29. data/app/models/renalware/system/country.rb +21 -0
  30. data/app/models/renalware/transplants/create_donor_stage.rb +4 -2
  31. data/app/policies/renalware/base_policy.rb +4 -0
  32. data/app/policies/renalware/renal/aki_alert_policy.rb +9 -0
  33. data/app/presenters/renalware/hd/patient_presenter.rb +5 -0
  34. data/app/presenters/renalware/reporting/audit_presenter.rb +1 -0
  35. data/app/presenters/renalware/transplants/patient_presenter.rb +2 -1
  36. data/app/presenters/renalware/ukrdc/patient_presenter.rb +27 -0
  37. data/app/values/renalware/address.rb +2 -13
  38. data/app/views/renalware/addresses/_form.html.slim +4 -2
  39. data/app/views/renalware/api/ukrdc/patients/_address.xml.builder +2 -2
  40. data/app/views/renalware/api/ukrdc/patients/_diagnoses.xml.builder +5 -2
  41. data/app/views/renalware/api/ukrdc/patients/_encounters.xml.builder +8 -1
  42. data/app/views/renalware/api/ukrdc/patients/_medications.xml.builder +30 -0
  43. data/app/views/renalware/api/ukrdc/patients/_patient.xml.builder +36 -4
  44. data/app/views/renalware/api/ukrdc/patients/_sending_facility.xml.builder +1 -0
  45. data/app/views/renalware/api/ukrdc/patients/diagnoses/_cause_of_death.xml.builder +10 -0
  46. data/app/views/renalware/api/ukrdc/patients/encounters/_hd_session.xml.builder +40 -0
  47. data/app/views/renalware/api/ukrdc/patients/show.xml.builder +1 -0
  48. data/app/views/renalware/directory/people/_address_form.html.slim +1 -1
  49. data/app/views/renalware/hd/sessions/_form.html.slim +43 -33
  50. data/app/views/renalware/letters/contacts/_person_form.html.slim +1 -1
  51. data/app/views/renalware/navigation/_renal.html.slim +1 -0
  52. data/app/views/renalware/patients/patients/_form.html.slim +5 -2
  53. data/app/views/renalware/patients/patients/show.html.slim +0 -5
  54. data/app/views/renalware/patients/patients/show/_patient_demographics.html.slim +3 -3
  55. data/app/views/renalware/patients/side_menu/_actions.html.slim +3 -0
  56. data/app/views/renalware/renal/aki_alerts/_filters.html.slim +0 -0
  57. data/app/views/renalware/renal/aki_alerts/edit.html.slim +17 -0
  58. data/app/views/renalware/renal/aki_alerts/index.html.slim +28 -0
  59. data/app/views/renalware/reporting/audits/edit.html.slim +1 -1
  60. data/app/views/renalware/reporting/audits/index.html.slim +11 -7
  61. data/app/views/renalware/reporting/audits/show.html.slim +2 -17
  62. data/app/views/renalware/shared/documents/_blood_pressure_input.html.slim +6 -7
  63. data/config/initializers/inflections.rb +3 -2
  64. data/config/locales/renalware/navigation/renal.en.yml +1 -0
  65. data/config/locales/renalware/renal/aki_alerts.en.yml +5 -0
  66. data/config/locales/renalware/renal/{profile.yml → profile.en.yml} +0 -0
  67. data/config/locales/renalware/reporting/audit.en.yml +1 -1
  68. data/config/routes.rb +1 -0
  69. data/db/migrate/20150312113937_create_drug_types_drugs.rb +2 -2
  70. data/db/migrate/20170925161033_add_code_to_patient_langauges.rb +6 -0
  71. data/db/migrate/20170925182738_add_rr_code_to_medication_routes.rb +5 -0
  72. data/db/migrate/20170926081426_create_countries.rb +14 -0
  73. data/db/migrate/20170926132845_add_country_of_birth_to_patients.rb +6 -0
  74. data/db/migrate/20171002175804_add_rr_columns_to_transplant_registration_status_descriptions.rb +12 -0
  75. data/db/migrate/20171003093347_create_hospital_wards.rb +17 -0
  76. data/db/migrate/20171003111228_create_aki_alert_actions.rb +10 -0
  77. data/db/migrate/20171003122425_create_renal_aki_alerts.rb +22 -0
  78. data/db/migrate/20171005081224_create_reporting_bone_audit.rb +5 -0
  79. data/db/migrate/20171005091202_reporting_audit_changes.rb +7 -0
  80. data/db/migrate/20171005130109_create_medication_current_prescriptions.rb +5 -0
  81. data/db/migrate/20171005144505_create_reporting_anaemia_audit.rb +5 -0
  82. data/db/migrate/20171009104106_add_legacy_patient_id_to_patients.rb +6 -0
  83. data/db/seeds/default/events/{event_types_required.csv → event_types.csv} +0 -0
  84. data/db/seeds/default/events/{event_types_required.rb → event_types.rb} +2 -2
  85. data/db/seeds/default/events/seeds.rb +1 -2
  86. data/db/seeds/default/medications/medication_routes.rb +23 -13
  87. data/db/seeds/default/patients/patients_languages.csv +192 -102
  88. data/db/seeds/default/patients/patients_languages.rb +1 -1
  89. data/db/seeds/default/patients/patients_religions.csv +2 -0
  90. data/db/seeds/default/reporting/audits.rb +4 -3
  91. data/db/seeds/default/reporting/audits.yml +47 -4
  92. data/db/seeds/default/system/countries.csv +250 -0
  93. data/db/seeds/default/system/countries.rb +12 -0
  94. data/db/seeds/default/system/seeds.rb +1 -0
  95. data/db/seeds/default/transplants/transplant_registration_statuses.rb +30 -19
  96. data/db/views/medication_current_prescriptions_v01.sql +28 -0
  97. data/db/views/reporting_anaemia_audit_v01.sql +41 -0
  98. data/db/views/reporting_bone_audit_v01.sql +32 -0
  99. data/lib/renalware/version.rb +1 -1
  100. data/spec/factories/deaths/cause.rb +1 -1
  101. data/spec/factories/drugs/drug.rb +6 -0
  102. data/spec/factories/drugs/drug_types.rb +5 -0
  103. data/spec/factories/hospitals/wards.rb +9 -0
  104. data/spec/factories/modalities/modality_descriptions.rb +10 -8
  105. data/spec/factories/patients/ethnicities.rb +3 -0
  106. data/spec/factories/patients/languages.rb +12 -1
  107. data/spec/factories/renal/aki_alert_actions.rb +5 -0
  108. data/spec/factories/renal/aki_alerts.rb +9 -0
  109. data/spec/factories/reporting/audits.rb +1 -1
  110. data/spec/factories/system/addresses.rb +1 -1
  111. data/spec/factories/system/countries.rb +15 -0
  112. metadata +42 -13
  113. data/app/values/renalware/country.rb +0 -19
  114. data/config/countries.csv +0 -250
  115. data/db/migrate/20170706120643_create_reporting_data_sources.rb +0 -5
  116. data/db/seeds/default/events/event_types_blt.csv +0 -109
  117. data/db/seeds/default/events/event_types_local.rb +0 -10
  118. data/db/views/reporting_data_sources_v01.sql +0 -17
@@ -0,0 +1,15 @@
1
+ require_dependency "renalware/renal"
2
+
3
+ module Renalware
4
+ module Renal
5
+ class AKIAlert < ApplicationRecord
6
+ include Accountable
7
+ scope :ordered, ->{ order(created_at: :desc) }
8
+ belongs_to :patient, class_name: "Renal::Patient"
9
+ belongs_to :action, class_name: "Renal::AKIAlertAction"
10
+ belongs_to :hospital_ward, class_name: "Hospitals::Ward"
11
+ validates :patient, presence: true
12
+ alias_attribute :decided_by, :updated_by
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require_dependency "renalware/renal"
2
+
3
+ module Renalware
4
+ module Renal
5
+ class AKIAlertAction < ApplicationRecord
6
+ validates :name, presence: true, uniqueness: true
7
+ delegate :to_s, to: :name
8
+ end
9
+ end
10
+ end
@@ -4,12 +4,11 @@ module Renalware
4
4
  module Reporting
5
5
  class Audit < ApplicationRecord
6
6
  validates :name, presence: true
7
- validates :materialized_view_name, presence: true
8
- validates :refresh_schedule, presence: true
7
+ validates :view_name, presence: true
9
8
 
10
9
  def self.available_audit_materialized_views
11
10
  result = connection.execute("SELECT oid::regclass::text FROM pg_class
12
- WHERE relkind = 'm' and relname like 'reporting_%';")
11
+ WHERE relkind in ('m', 'v') and relname like 'reporting_%';")
13
12
  result.values.flatten
14
13
  end
15
14
  end
@@ -3,17 +3,33 @@ require_dependency "renalware/reporting"
3
3
  module Renalware
4
4
  module Reporting
5
5
  class GenerateAuditJson
6
- def self.call(materialized_view_name)
7
- result = ActiveRecord::Base.connection.execute(
8
- "select * from #{materialized_view_name};"
9
- )
10
- # Build a datatables compatible columnDefs hash
6
+ def self.call(view_name)
7
+ conn = ActiveRecord::Base.connection
8
+ result = conn.execute("select * from #{conn.quote_column_name(view_name)};")
9
+
10
+ # Build a JS DataTables-compatible columnDefs hash
11
11
  columns = result.fields.each_with_index.inject([]) do |array, data|
12
12
  column_name, index = data
13
13
  array << { title: column_name, target: index }
14
14
  end
15
15
  [columns.to_json, result.values]
16
16
  end
17
+
18
+ # A WIP to translate audit column names into human friendly ones.
19
+ # May need to establish guidelines for instance apply text case in the view itself so
20
+ # eg pct_HGB = % HGB without having to know to upcase certain bits of the name but
21
+ # capitalise others etc.
22
+ # def self.humanize_column_name(column)
23
+ # column
24
+ # .gsub("pct_", "% ")
25
+ # .gsub("count_", "No.")
26
+ # .gsub("avg_", "Avg ")
27
+ # .gsub("max", "Max ")
28
+ # .gsub("gt_eq_", "≥ ")
29
+ # .gsub("lt_eq_", "≤ ")
30
+ # .gsub("gt_", "> ")
31
+ # .gsub("lt_", "< ")
32
+ # end
17
33
  end
18
34
  end
19
35
  end
@@ -0,0 +1,21 @@
1
+ require_dependency "renalware/system"
2
+
3
+ module Renalware
4
+ module System
5
+ class Country < ApplicationRecord
6
+ validates :name, presence: true, uniqueness: true
7
+ validates :alpha2, presence: true, uniqueness: true
8
+ validates :alpha3, presence: true, uniqueness: true
9
+
10
+ default_scope ->{ order(position: :asc) }
11
+
12
+ def to_s
13
+ name
14
+ end
15
+
16
+ def uk?
17
+ (alpha3 || "").casecmp("GBR").zero?
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,6 @@
1
1
  require_dependency "renalware/transplants"
2
+ require_dependency "renalware/success"
3
+ require_dependency "renalware/failure"
2
4
 
3
5
  # Service object responsible for creating a new DonorStage and terminated the previous one
4
6
  # if found.
@@ -15,9 +17,9 @@ module Renalware
15
17
  terminate_current_stage if current_stage.present?
16
18
  stage = build_new_stage
17
19
  if stage.save
18
- Success.new(stage)
20
+ ::Renalware::Success.new(stage)
19
21
  else
20
- Failure.new(stage)
22
+ ::Renalware::Failure.new(stage)
21
23
  end
22
24
  end
23
25
  end
@@ -45,6 +45,10 @@ module Renalware
45
45
  update?
46
46
  end
47
47
 
48
+ def debug?
49
+ user_is_super_admin?
50
+ end
51
+
48
52
  protected
49
53
 
50
54
  # For each role define e.g. user_is_admin?
@@ -0,0 +1,9 @@
1
+ require_dependency "renalware/renal"
2
+
3
+ module Renalware
4
+ module Renal
5
+ class AKIAlertPolicy < BasePolicy
6
+
7
+ end
8
+ end
9
+ end
@@ -16,6 +16,11 @@ module Renalware
16
16
  super(HD.cast_patient(patient.__getobj__))
17
17
  end
18
18
 
19
+ def finished_hd_sessions
20
+ # TODO: standardise on a way to get closed sessions - a scope on patient maybe?
21
+ hd_sessions.eager_load(:hospital_unit).where(type: "Renalware::HD::Session::Closed")
22
+ end
23
+
19
24
  private
20
25
 
21
26
  def hd_profile
@@ -5,6 +5,7 @@ module Renalware
5
5
  module Reporting
6
6
  class AuditPresenter < SimpleDelegator
7
7
  def refresh_schedule
8
+ return if super.blank?
8
9
  Cronex::ExpressionDescriptor.new(super).description
9
10
  end
10
11
  end
@@ -3,7 +3,8 @@ module Renalware
3
3
  class PatientPresenter < SimpleDelegator
4
4
 
5
5
  def initialize(patient)
6
- super(Transplants.cast_patient(patient.__getobj__))
6
+ patient = patient.__getobj__ if patient.respond_to?(:__getobj__)
7
+ super(Transplants.cast_patient(patient))
7
8
  end
8
9
 
9
10
  def current_registration_status
@@ -6,6 +6,14 @@ module Renalware
6
6
  delegate :allergies, to: :clinical_patient
7
7
  delegate :clinic_visits, to: :clinics_patient
8
8
  delegate :observation_requests, to: :pathology_patient
9
+ delegate :profile, to: :renal_patient, allow_nil: true
10
+ delegate :first_seen_on, to: :profile, allow_nil: true
11
+ alias_attribute :home_telephone, :telephone1
12
+ alias_attribute :mobile_telephone, :telephone2
13
+
14
+ def dead?
15
+ current_modality_death?
16
+ end
9
17
 
10
18
  def smoking_history
11
19
  @smoking_history ||= document.history&.smoking&.upcase
@@ -18,10 +26,21 @@ module Renalware
18
26
  )
19
27
  end
20
28
 
29
+ def current_registration_status_rr_code
30
+ @current_registration_status_rr_code ||= begin
31
+ status = transplant_patient.current_registration_status
32
+ status&.description&.rr_code
33
+ end
34
+ end
35
+
21
36
  def hospital_unit_code
22
37
  letter_head.site_code
23
38
  end
24
39
 
40
+ def contact_details?
41
+ email || home_telephone || mobile_telephone
42
+ end
43
+
25
44
  private
26
45
 
27
46
  def clinical_patient
@@ -39,6 +58,14 @@ module Renalware
39
58
  def pathology_patient
40
59
  @pathology_patient ||= Renalware::Pathology.cast_patient(__getobj__)
41
60
  end
61
+
62
+ def renal_patient
63
+ @renal_patient ||= Renalware::Renal.cast_patient(__getobj__)
64
+ end
65
+
66
+ def transplant_patient
67
+ @transplant_patient ||= Transplants::PatientPresenter.new(__getobj__)
68
+ end
42
69
  end
43
70
  end
44
71
  end
@@ -1,14 +1,8 @@
1
1
  module Renalware
2
2
  class Address < ApplicationRecord
3
- UK_COUNTRIES = [
4
- "united kingdom",
5
- "england",
6
- "scotland",
7
- "wales",
8
- "northern ireland"
9
- ].freeze
10
-
3
+ belongs_to :country, class_name: "System::Country"
11
4
  validates :email, email: true, allow_blank: true
5
+ delegate :uk?, to: :country, allow_nil: true
12
6
  validates_with AddressValidator
13
7
 
14
8
  belongs_to :addressable, polymorphic: true
@@ -20,11 +14,6 @@ module Renalware
20
14
  }
21
15
  end
22
16
 
23
- def uk?
24
- return if country.blank?
25
- UK_COUNTRIES.include?(country.downcase)
26
- end
27
-
28
17
  def copy_from(source)
29
18
  self.name = source.name
30
19
  self.organisation_name = source.organisation_name
@@ -7,8 +7,10 @@
7
7
  = a.input :town, wrapper: :horizontal_medium
8
8
  = a.input :county, wrapper: :horizontal_small
9
9
  = a.input :postcode, wrapper: :horizontal_small
10
- = a.input :country,
11
- collection: Renalware::Country.all.map(&:name),
10
+ = a.input :country_id,
11
+ collection: Renalware::System::Country.pluck(:name, :id),
12
12
  wrapper: :horizontal_small
13
13
  = a.input :telephone, wrapper: :horizontal_medium
14
14
  = a.input :email, wrapper: :horizontal_medium
15
+
16
+
@@ -10,7 +10,7 @@ xml.Address(use: "H") do
10
10
  xml.Postcode address.postcode
11
11
  xml.Country do
12
12
  xml.CodingStandard "ISO3166-1"
13
- xml.Code Renalware::Country.code_for(address.country)
14
- xml.Description address.country
13
+ xml.Code address&.country&.alpha3
14
+ xml.Description address&.country&.to_s
15
15
  end
16
16
  end
@@ -1,7 +1,10 @@
1
1
  # https://github.com/renalreg/ukrdc/blob/6d95e364dd8de857839fe6cdbd4e7fc3fb4c1d42/Schema/Diagnoses/Diagnosis.xsd
2
2
  # This is snomed-based, so might not be possible?
3
3
  xml = builder
4
-
5
4
  xml.Diagnoses do
6
- xml.comment! "TODO"
5
+ if patient.dead?
6
+ [patient.first_cause, patient.second_cause].compact.each do |cause|
7
+ render "renalware/api/ukrdc/patients/diagnoses/cause_of_death", builder: xml, cause: cause
8
+ end
9
+ end
7
10
  end
@@ -1,5 +1,12 @@
1
1
  xml = builder
2
+ hd_patient = Renalware::HD::PatientPresenter.new(patient)
2
3
 
3
4
  xml.Encounters do
4
- xml.comment! "TODO"
5
+ hd_patient.finished_hd_sessions.each do |session|
6
+ render "renalware/api/ukrdc/patients/encounters/hd_session",
7
+ builder: xml,
8
+ patient: patient,
9
+ hd_patient: hd_patient,
10
+ session: Renalware::HD::SessionPresenter.new(session)
11
+ end
5
12
  end
@@ -0,0 +1,30 @@
1
+ xml = builder
2
+
3
+ xml.Medications do
4
+ patient.prescriptions.each do |prescription|
5
+ xml.Medication do
6
+ xml.PrescriptionNumber
7
+ xml.FromTime prescription.prescribed_on.to_datetime
8
+ if prescription.terminated_or_marked_for_termination?
9
+ xml.ToTime prescription.terminated_on&.to_datetime
10
+ end
11
+ xml.OrderedBy
12
+ xml.Route do
13
+ xml.CodingStandard "RR22"
14
+ xml.Code prescription.medication_route&.rr_code
15
+ xml.Description prescription.medication_route&.name
16
+ end
17
+ xml.DrugProduct do
18
+ xml.Id do
19
+ xml.CodingStandard "DM+D"
20
+ xml.Code "dm + d code for the drug - coming soon"
21
+ xml.Description prescription.drug
22
+ end
23
+ end
24
+ xml.Frequency prescription.frequency
25
+ xml.Comments prescription.notes
26
+ # xml.DoseUoM
27
+ # xml.Indication
28
+ end
29
+ end
30
+ end
@@ -2,7 +2,6 @@
2
2
  # Things we are not going to include in RW2.0
3
3
  # - PersonToContact
4
4
  # - Occupation
5
- # - CountryOfBirth
6
5
  #
7
6
  xml = builder
8
7
  path = "renalware/api/ukrdc/patients" # or "."
@@ -30,7 +29,7 @@ xml.Patient do
30
29
 
31
30
  xml.BirthTime patient.born_on.to_datetime
32
31
 
33
- if patient.current_modality_death? && patient.died_on.present?
32
+ if patient.dead? && patient.died_on.present?
34
33
  xml.DeathTime(patient.died_on.to_datetime)
35
34
  end
36
35
 
@@ -57,9 +56,41 @@ xml.Patient do
57
56
  end
58
57
  end
59
58
 
60
- xml.PrimaryLanguage patient.language
59
+ if patient.language.present?
60
+ xml.PrimaryLanguage do
61
+ xml.CodingStandard "NHS_DATA_DICTIONARY_LANGUAGE_CODE" # ISO 639-1 plus braille an sign
62
+ xml.Code patient.language&.code
63
+ xml.Description patient.language
64
+ end
65
+ end
66
+
67
+ if patient.contact_details?
68
+ xml.ContactDetails do
69
+ if patient.email.present?
70
+ xml.ContactDetail(use: "NET") do
71
+ xml.Value patient.email
72
+ end
73
+ end
74
+ if patient.home_telephone.present?
75
+ xml.ContactDetail(use: "PRN") do
76
+ xml.Value patient.home_telephone
77
+ end
78
+ end
79
+ if patient.mobile_telephone.present?
80
+ xml.ContactDetail(use: "PRS") do
81
+ xml.Value patient.mobile_telephone
82
+ end
83
+ end
84
+ end
85
+ end
61
86
 
62
- if patient.current_modality_death?
87
+ xml.comment! "Inclusion of CountryOfBirth causes XSD error so temporarily excluded"
88
+ # Inclusion strangley causes an XSD error
89
+ # if patient.country_of_birth.present?
90
+ # xml.CountryOfBirth patient.country_of_birth.alpha3
91
+ # end
92
+
93
+ if patient.dead?
63
94
  xml.Death true
64
95
  end
65
96
 
@@ -67,4 +98,5 @@ xml.Patient do
67
98
  xml.UpdatedOn patient.updated_at&.to_datetime
68
99
  xml.ActionCode "A" # A = added/updated. If we are posting this XML isn't only going to be 'A'?
69
100
  xml.ExternalId patient.ukrdc_external_id
101
+
70
102
  end
@@ -5,3 +5,4 @@ xml.SendingFacility(
5
5
  channelId: "TODO",
6
6
  time: Time.zone.now.to_datetime) do
7
7
  end
8
+ xml.SendingExtract "???"
@@ -0,0 +1,10 @@
1
+ xml = builder
2
+
3
+ xml.CauseOfDeath do
4
+ xml.DiagnosisType "final"
5
+ xml.Diagnosis do
6
+ xml.CodingStandard "EDTA"
7
+ xml.Code cause.code
8
+ end
9
+ xml.EnteredOn cause.created_at.to_datetime
10
+ end
@@ -0,0 +1,40 @@
1
+ xml = builder
2
+
3
+ xml.Treatment do
4
+ xml.EncounterNumber "?can supply uuid if required?"
5
+ xml.comment! "What EncounterType for HD Session?"
6
+ xml.EncounterType "R"
7
+ xml.FromTime session.start_datetime&.to_datetime
8
+ xml.ToTime session.stop_datetime&.to_datetime
9
+ xml.HealthCareFacility
10
+ xml.EnteredAt do
11
+ xml.Code session.hospital_unit.renal_registry_code
12
+ end
13
+
14
+ xml.Attributes do
15
+ xml.HDP01 "Times per week - to confirm"
16
+ xml.HDP02 session.duration
17
+ xml.HDP03 session.document.dialysis.flow_rate
18
+ xml.comment! "HDP04 Sodium in Dialysate - to follow."
19
+ xml.HDP04 ""
20
+ xml.QBL05 session.access_type
21
+ xml.QBL06 ""
22
+ xml.comment! "QBL06 HD Shared Care - not implemented yet"
23
+ xml.QBL07 ""
24
+ xml.comment! "QBL07 HD Shared Care - not implemented yet"
25
+ xml.comment! "ERF61 - defaulting to 5 if not present, as element is required"
26
+ xml.ERF61 patient.current_registration_status_rr_code || "5" # 5= not assessed
27
+ xml.PAT35 patient.first_seen_on
28
+ end
29
+ xml.comment! "TODO: AdmitReason fails xsd validation with "\
30
+ "Element 'AdmitReason': This element is not expected. Expected is one of "\
31
+ "( VisitDescription, Attributes, UpdatedOn, ActionCode, ExternalId )."
32
+ # xml.AdmitReason do
33
+ # xml.comment! "I think AdmitReason 1 is Haemodialysis"
34
+ # xml.CodingStandard "CF_RR7_TREATMENT"
35
+ # xml.Code "1"
36
+ # end
37
+ # xml.UpdatedOn
38
+ # xml.ActionCode
39
+ # xml.ExternalId
40
+ end