renalware-core 2.0.89 → 2.0.90

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/renalware/hd/profile_for_modality.rb +20 -0
  3. data/app/models/renalware/hd/profiles_in_date_range_query.rb +32 -0
  4. data/app/models/renalware/hd/revise_hd_profile.rb +3 -5
  5. data/app/models/renalware/modalities/description.rb +8 -0
  6. data/app/models/renalware/pd/regime_for_modality.rb +21 -0
  7. data/app/models/renalware/pd/regimes_in_date_range_query.rb +30 -0
  8. data/app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb +6 -1
  9. data/app/models/renalware/ukrdc/treatment.rb +5 -0
  10. data/app/models/renalware/ukrdc/treatment_timeline/generate_timeline.rb +13 -7
  11. data/app/models/renalware/ukrdc/treatment_timeline/generate_treatments.rb +9 -4
  12. data/app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb +1 -1
  13. data/app/models/renalware/ukrdc/treatment_timeline/generic/generator.rb +45 -0
  14. data/app/models/renalware/ukrdc/treatment_timeline/hd/generator.rb +128 -0
  15. data/app/models/renalware/ukrdc/treatment_timeline/hd/modality_code_map.rb +29 -0
  16. data/app/models/renalware/ukrdc/treatment_timeline/hd/profile_decorator.rb +45 -0
  17. data/app/models/renalware/ukrdc/treatment_timeline/pd/generator.rb +119 -0
  18. data/app/models/renalware/ukrdc/treatment_timeline/pd/modality_code_map.rb +35 -0
  19. data/app/models/renalware/ukrdc/treatment_timeline/pd/regime_decorator.rb +37 -0
  20. data/app/models/renalware/ukrdc/treatment_timeline/prepare_tables.rb +1 -0
  21. data/app/presenters/renalware/hd/session_presenter.rb +6 -0
  22. data/app/presenters/renalware/ukrdc/patient_presenter.rb +17 -6
  23. data/app/views/renalware/api/ukrdc/patients/_medications.xml.builder +1 -8
  24. data/app/views/renalware/api/ukrdc/patients/_treatments.xml.builder +84 -45
  25. data/app/views/renalware/api/ukrdc/patients/procedures/_dialysis_session.xml.builder +1 -1
  26. data/app/views/renalware/api/ukrdc/patients/treatments/_generic.xml.builder +15 -0
  27. data/app/views/renalware/api/ukrdc/patients/treatments/_hd.xml.builder +30 -0
  28. data/app/views/renalware/api/ukrdc/patients/treatments/_pd.xml.builder +13 -0
  29. data/db/migrate/20190705083727_alter_ukrdc_treatments.rb +8 -0
  30. data/db/migrate/20190705105921_create_hd_profile_for_modalites.rb +7 -0
  31. data/db/migrate/20190709101610_create_pd_regime_for_modalities.rb +7 -0
  32. data/db/views/hd_profile_for_modalities_v01.sql +63 -0
  33. data/db/views/pd_regime_for_modalities_v01.sql +60 -0
  34. data/lib/renalware/version.rb +1 -1
  35. data/lib/tasks/ukrdc.rake +2 -1
  36. data/spec/factories/hd/profiles.rb +24 -0
  37. data/spec/factories/pd/pd_regimes.rb +8 -0
  38. data/spec/factories/ukrdc/modality_codes.rb +30 -0
  39. metadata +21 -9
  40. data/app/models/renalware/ukrdc/treatment_timeline/generators/deaths_timeline.rb +0 -17
  41. data/app/models/renalware/ukrdc/treatment_timeline/generators/generic_timeline.rb +0 -17
  42. data/app/models/renalware/ukrdc/treatment_timeline/generators/hd_timeline.rb +0 -145
  43. data/app/models/renalware/ukrdc/treatment_timeline/generators/low_clearance_timelinex.rb +0 -17
  44. data/app/models/renalware/ukrdc/treatment_timeline/generators/pd_timeline.rb +0 -18
  45. data/app/models/renalware/ukrdc/treatment_timeline/generators/transplants_donor_timeline.rb +0 -17
  46. data/app/models/renalware/ukrdc/treatment_timeline/generators/transplants_recipient_timeline.rb +0 -17
@@ -1,145 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency "renalware/ukrdc"
4
-
5
- # rubocop:disable Rails/Output
6
- module Renalware
7
- module UKRDC
8
- module TreatmentTimeline
9
- module Generators
10
- class HDTimeline
11
- pattr_initialize :modality
12
- delegate :patient, to: :modality
13
-
14
- def call
15
- create_treatment_from_modality
16
- create_treatments_within_modality
17
- deduplicate
18
- end
19
-
20
- private
21
-
22
- def create_treatment_from_modality
23
- print "[#{treatment.txt_code}] "
24
- treatments << Treatment.create!(
25
- patient: patient,
26
- clinician: modality.created_by,
27
- started_on: modality.started_on,
28
- ended_on: modality.ended_on,
29
- modality_code: treatment
30
- )
31
- end
32
-
33
- class ProfileDecorator < DumbDelegator
34
- def initialize(profile, last_profile:)
35
- @last_profile = last_profile
36
- super(profile)
37
- end
38
-
39
- def hd_type
40
- document.dialysis.hd_type
41
- end
42
-
43
- def changed?
44
- return true if last_profile.blank?
45
-
46
- hd_type_changed? || hospital_unit_changed?
47
- end
48
-
49
- def unchanged?
50
- !changed?
51
- end
52
-
53
- def hd_type_changed?
54
- last_profile.document.dialysis.hd_type != hd_type
55
- end
56
-
57
- def hospital_unit_changed?
58
- last_profile.hospital_unit_id != hospital_unit_id
59
- end
60
-
61
- private
62
-
63
- attr_reader :last_profile
64
- end
65
-
66
- # 3 things trigger a new Treatment for an HD patient
67
- # - change of site
68
- # - change of hd_type to from hd and (hdf_pre || hdf_post)
69
- # - change of hd prescription
70
- # Looop through the hd_profiles and trigger an new treatment when these change
71
- def create_treatments_within_modality
72
- profiles = hd_profiles_for(patient, from: modality.started_on, to: modality.ended_on)
73
- last_profile = NullObject.instance
74
-
75
- profiles.each do |profile_|
76
- profile = ProfileDecorator.new(profile_, last_profile: last_profile)
77
- create_treatment_from(profile) if profile.changed?
78
- last_profile = profile_
79
- end
80
- end
81
-
82
- # - if modality started on same day as hd profile prescribed then use HD Profile hd_type
83
- # if present else hd
84
- # - if modality started before hd_profile setup and hd_profile is hdf, we'll have
85
- # 2 treatments: hd then hdf
86
- # - if hosp unit changes within the modality timeframe, trigger a new treatment
87
- # - if medications change? new treatment? Check with GS
88
- def deduplicate
89
- # p treatments.map(&:id)
90
- end
91
-
92
- # rubocop:disable Metrics/AbcSize
93
- def create_treatment_from(profile)
94
- code = treatment_for_hd_type(profile.hd_type)
95
- print "[#{code.txt_code}] "
96
- treatments << Treatment.create!(
97
- patient: patient,
98
- clinician: modality.created_by,
99
- started_on: modality.started_on,
100
- ended_on: modality.ended_on,
101
- modality_code: treatment_for_hd_type(profile.hd_type)
102
- )
103
- end
104
- # rubocop:enable Metrics/AbcSize
105
-
106
- def treatments
107
- @treatments ||= []
108
- end
109
-
110
- def treatment_for_hd_type(hd_type)
111
- ukrr_name = case hd_type.to_s.downcase
112
- when "hd" then "Haemodialysis"
113
- when "hdf_pre", "hdf_post" then "Haemodiafiltration"
114
- end
115
- UKRDC::ModalityCode.find_by!(description: ukrr_name)
116
- end
117
-
118
- def hd_profiles_for(patient, from:, to: Time.zone.now)
119
- conditions = {
120
- patient_id: patient.id,
121
- prescribed_on: from..DateTime::Infinity.new
122
- }
123
-
124
- scope = Renalware::HD::Profile
125
- .with_deactivated
126
- .order(prescribed_on: :asc, deactivated_at: :desc)
127
-
128
- scope
129
- .where(conditions.merge(deactivated_at: from..to))
130
- .or(scope.where(conditions.merge(deactivated_at: nil)))
131
- end
132
-
133
- def hd_patient
134
- Renalware::HD.cast_patient(patient)
135
- end
136
-
137
- def treatment
138
- ModalityCode.find_by!(description: "Haemodialysis")
139
- end
140
- end
141
- end
142
- end
143
- end
144
- end
145
- # rubocop:enable Rails/Output
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency "renalware/ukrdc"
4
-
5
- module Renalware
6
- module UKRDC
7
- module TreatmentTimelinex
8
- module Generators
9
- class LowClearanceTimeline
10
- pattr_initialize :modality
11
-
12
- def call; end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency "renalware/ukrdc"
4
-
5
- module Renalware
6
- module UKRDC
7
- module TreatmentTimeline
8
- module Generators
9
- class PDTimeline
10
- pattr_initialize :modality
11
- delegate :patient, to: :modality
12
-
13
- def call; end
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency "renalware/ukrdc"
4
-
5
- module Renalware
6
- module UKRDC
7
- module TreatmentTimeline
8
- module Generators
9
- class TransplantsDonorTimeline
10
- pattr_initialize :modality
11
-
12
- def call; end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_dependency "renalware/ukrdc"
4
-
5
- module Renalware
6
- module UKRDC
7
- module TreatmentTimeline
8
- module Generators
9
- class TransplantsRecipientTimeline
10
- pattr_initialize :modality
11
-
12
- def call; end
13
- end
14
- end
15
- end
16
- end
17
- end