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
@@ -32,7 +32,7 @@ xml.DialysisSession(
32
32
  xml.Attributes do
33
33
  xml.QHD19 session.had_intradialytic_hypotension?
34
34
  xml.QHD20 session.access_rr02_code
35
- xml.QHD21 session.access_side_rr40_code
35
+ xml.QHD21 session.access_rr41_code
36
36
  xml.QHD22 "N" # Access in two sites simultaneously
37
37
  xml.QHD30 session.blood_flow
38
38
  xml.QHD31 session.duration_in_minutes # Time Dialysed in Minutes
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ xml = builder
4
+
5
+ xml.Treatment do
6
+ xml.EncounterNumber treatment.modality_id
7
+ xml.EncounterType "N"
8
+ xml.FromTime treatment.started_on&.iso8601
9
+ xml.ToTime(treatment.ended_on&.iso8601) if treatment.ended_on.present?
10
+
11
+ xml.AdmitReason do
12
+ xml.CodingStandard "CF_RR7_TREATMENT"
13
+ xml.Code treatment.modality_code.txt_code
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ xml = builder
4
+
5
+ xml.Treatment do
6
+ xml.EncounterNumber [treatment.modality_id, treatment.hd_profile_id].compact.join("-")
7
+ xml.EncounterType "N"
8
+ xml.FromTime treatment.started_on&.iso8601
9
+ xml.ToTime(treatment.ended_on&.iso8601) if treatment.ended_on.present?
10
+
11
+ if treatment.hospital_unit.present?
12
+ xml.HealthCareFacility do
13
+ xml.CodingStandard "ODS"
14
+ xml.Code treatment.hospital_unit.unit_code
15
+ end
16
+ end
17
+
18
+ xml.AdmitReason do
19
+ xml.CodingStandard "CF_RR7_TREATMENT"
20
+ xml.Code treatment.modality_code.txt_code
21
+ end
22
+
23
+ # HD
24
+ rr8 = treatment.hospital_unit&.unit_type_rr8
25
+ if rr8.present?
26
+ xml.Attributes do
27
+ xml.QBL05 rr8 # eg HOME
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ xml = builder
2
+
3
+ xml.Treatment do
4
+ xml.EncounterNumber [treatment.modality_id,treatment.pd_regime_id].compact.join("-")
5
+ xml.EncounterType "N"
6
+ xml.FromTime treatment.started_on&.iso8601
7
+ xml.ToTime(treatment.ended_on&.iso8601) if treatment.ended_on.present?
8
+
9
+ xml.AdmitReason do
10
+ xml.CodingStandard "CF_RR7_TREATMENT"
11
+ xml.Code treatment.modality_code.txt_code
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ class AlterUKRDCTreatments < ActiveRecord::Migration[5.2]
2
+ def change
3
+ within_renalware_schema do
4
+ add_reference :ukrdc_treatments, :hd_profile, index: true, foreign_key: true
5
+ add_reference :ukrdc_treatments, :pd_regime, index: true, foreign_key: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class CreateHDProfileForModalites < ActiveRecord::Migration[5.2]
2
+ def change
3
+ within_renalware_schema do
4
+ create_view :hd_profile_for_modalities
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class CreatePDRegimeForModalities < ActiveRecord::Migration[5.2]
2
+ def change
3
+ within_renalware_schema do
4
+ create_view :pd_regime_for_modalities
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ -- This view is HD-specific, but really serevers to make UKRDC export easier.
2
+ -- It attempts to solve the gnarly problem of finding the hd profile associated with the start
3
+ -- of an HD modality. For example if a patient goes on to HD, an HD modality row is created.
4
+ -- However it could be a couple of weeks before they have an HD profile setup. This view
5
+ -- attempts to find that association.
6
+ -- We need to know the association so when we export the modality as a UKRDC
7
+ -- Treatment, we can pull in the site, hd_type etc from the hd profile.
8
+ -- Sometimes we will not be able to resolve a profile for the patient however.
9
+ WITH hd_modalities AS (
10
+ SELECT
11
+ m.patient_id,
12
+ m.id AS modality_id,
13
+ m.started_on,
14
+ m.ended_on
15
+ FROM
16
+ modality_modalities m
17
+ INNER JOIN modality_descriptions md ON md.id = m.description_id
18
+ WHERE
19
+ md.name = 'HD'
20
+ ),
21
+ distinct_hd_profiles AS (
22
+ -- selects the last profile created for a patient on any one day as there can be
23
+ -- many iterations of a profile as it is refined/edited by the clinician.
24
+ -- We can assume the final iteration on that day is the final one.
25
+ -- If it was changed the next day then no bother
26
+ SELECT DISTINCT ON (patient_id, created_at::date)
27
+ id AS hd_profile_id,
28
+ patient_id,
29
+ COALESCE(prescribed_on, created_at)::date AS effective_prescribed_on,
30
+ prescribed_on,
31
+ created_at::date AS created_on,
32
+ created_at,
33
+ deactivated_at,
34
+ active
35
+ FROM
36
+ hd_profiles
37
+ ORDER BY
38
+ -- Note the last order by (created_at) is required otherwsie we are only ordering by
39
+ -- date - and since there might be several on the same day, the order is undefined.
40
+ -- Note we cannot use created_at as the 2nd sort as its type has to match the distinct on..
41
+ -- so we have to cast it to a date here. Feel free to run just this select statmment to
42
+ -- understand the limitations
43
+ patient_id, created_at::date, created_at desc
44
+ )
45
+ -- Note in this last select we select the earlist hd profile we find that matches
46
+ -- as sometimes there can be > 1 hd profile returned from distinct_hd_profiles
47
+ SELECT
48
+ m.*,
49
+ (
50
+ SELECT
51
+ hd_profile_id
52
+ FROM
53
+ distinct_hd_profiles hp
54
+ WHERE
55
+ hp.patient_id = m.patient_id
56
+ AND(hp.deactivated_at IS NULL OR deactivated_at > m.started_on)
57
+ -- No longer limiting the look ahead to 2 weeks - there is now no future limit
58
+ -- AND hp.created_on <= (started_on + interval '2 weeks')
59
+ ORDER BY
60
+ created_at ASC
61
+ LIMIT 1) AS hd_profile_id
62
+ FROM
63
+ hd_modalities m;
@@ -0,0 +1,60 @@
1
+ -- This view is PD-specific, but really serevers to make UKRDC export easier.
2
+ -- It attempts to solve the gnarly problem of finding the pd regime associated with the start
3
+ -- of a PD modality. For example if a patient goes on to PD, a PD regime row is created.
4
+ -- However it could be a couple of weeks before they have a the PD regime setup. This view
5
+ -- attempts to find that association.
6
+ -- We need to know this association so when we export the modality as a UKRDC
7
+ -- Treatment, we can pull in the pd type (CAPD etc) from the regime.
8
+ -- Sometimes we will not be able to resolve a regime for the patient however.
9
+
10
+ WITH pd_modalities AS (
11
+ SELECT
12
+ m.patient_id,
13
+ m.id AS modality_id,
14
+ m.started_on,
15
+ m.ended_on
16
+ FROM
17
+ modality_modalities m
18
+ INNER JOIN modality_descriptions md ON md.id = m.description_id
19
+ WHERE
20
+ md.name = 'PD'
21
+ ),
22
+ distinct_pd_regimes AS (
23
+ -- selects the last regime created for a patient on any one day as there can be
24
+ -- many iterations of a regime as it is refined/edited by the clinician.
25
+ -- We can assume the final iteration on that day is the final one.
26
+ -- If it was changed the next day then no bother
27
+ SELECT DISTINCT ON (patient_id, start_date)
28
+ id AS pd_regime_id,
29
+ patient_id,
30
+ start_date,
31
+ end_date,
32
+ created_at
33
+ FROM
34
+ pd_regimes
35
+ ORDER BY
36
+ -- Note the last order by (created_at) is required otherwsie we are only ordering by
37
+ -- date - and since there might be several on the same day, the order is undefined.
38
+ -- Feel free to run just this select statmment to understand the limitations
39
+ patient_id, start_date asc, created_at desc
40
+ )
41
+ -- Note in this last select we select the earlist pd regime we find that matches
42
+ -- as sometimes there can be > 1 regime returned from distinct_pd_regimes
43
+ SELECT
44
+ m.*,
45
+ (
46
+ SELECT
47
+ pd_regime_id
48
+ FROM
49
+ distinct_pd_regimes pdr
50
+ WHERE
51
+ pdr.patient_id = m.patient_id
52
+ AND (pdr.end_date IS NULL OR pdr.end_date > m.started_on)
53
+ -- No longer limiting our look-ahead search for a regime to a specific time limit -
54
+ -- instead we just keep looking til we find the first regime
55
+ -- AND pdr.start_date <= (m.started_on + interval '2 weeks')::date
56
+ ORDER BY
57
+ created_at ASC
58
+ LIMIT 1) AS pd_regime_id
59
+ FROM
60
+ pd_modalities m order by m.patient_id;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renalware
4
- VERSION = "2.0.89"
4
+ VERSION = "2.0.90"
5
5
  end
@@ -28,10 +28,11 @@ namespace :ukrdc do
28
28
 
29
29
  bundle exec rake ukrdc:export changed_since=2018-02-23 patient_ids=1,2
30
30
  DESC
31
- task :export => :environment do |_task, args|
31
+ task export: :environment do |_task, _args|
32
32
  logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
33
33
  logger.level = Logger::INFO
34
34
  Rails.logger = logger
35
+ # Renalware::UKRDC::TreatmentTimeline::GenerateTreatments.call
35
36
  Renalware::UKRDC::CreateEncryptedPatientXMLFiles.new(
36
37
  changed_since: ENV["changed_since"],
37
38
  patient_ids: ENV.fetch("patient_ids", "").split(",").map(&:to_i),
@@ -16,5 +16,29 @@ FactoryBot.define do
16
16
  }
17
17
  }
18
18
  }
19
+
20
+ trait :hd do
21
+ # noop
22
+ end
23
+
24
+ trait :hdf_pre do
25
+ document {
26
+ {
27
+ dialysis: {
28
+ hd_type: :hdf_pre
29
+ }
30
+ }
31
+ }
32
+ end
33
+
34
+ trait :hdf_post do
35
+ document {
36
+ {
37
+ dialysis: {
38
+ hd_type: :hdf_post
39
+ }
40
+ }
41
+ }
42
+ end
19
43
  end
20
44
  end
@@ -13,6 +13,10 @@ FactoryBot.define do
13
13
  amino_acid_volume { 40 }
14
14
  icodextrin_volume { 50 }
15
15
  add_hd { false }
16
+
17
+ factory :capd_assisted_regime do
18
+ treatment { "CAPD Dry Day Assisted" }
19
+ end
16
20
  end
17
21
 
18
22
  factory :apd_regime, class: "Renalware::PD::APDRegime" do
@@ -33,5 +37,9 @@ FactoryBot.define do
33
37
  no_cycles_per_apd { 7 }
34
38
  overnight_volume { 5100 }
35
39
  apd_machine_pac { "123-4567-890" }
40
+
41
+ factory :apd_assisted_regime do
42
+ treatment { "APD Dry Day Assisted" }
43
+ end
36
44
  end
37
45
  end
@@ -13,5 +13,35 @@ FactoryBot.define do
13
13
  txt_code { 3 }
14
14
  qbl_code { 3 }
15
15
  end
16
+
17
+ trait :pd do
18
+ description { "Peritoneal dialysis – type unknown" }
19
+ txt_code { 19 }
20
+ qbl_code { 19 }
21
+ end
22
+
23
+ trait :apd do
24
+ description { "APD" }
25
+ txt_code { 12 }
26
+ qbl_code { 12 }
27
+ end
28
+
29
+ trait :apd_assisted do
30
+ description { "Assisted APD" }
31
+ txt_code { 121 }
32
+ qbl_code { 121 }
33
+ end
34
+
35
+ trait :capd do
36
+ description { "CAPD" }
37
+ txt_code { 11 }
38
+ qbl_code { 11 }
39
+ end
40
+
41
+ trait :capd_assisted do
42
+ description { "Assisted CAPD" }
43
+ txt_code { 111 }
44
+ qbl_code { 111 }
45
+ end
16
46
  end
17
47
  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.89
4
+ version: 2.0.90
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airslie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-04 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_type
@@ -1497,6 +1497,8 @@ files:
1497
1497
  - app/models/renalware/hd/preference_set.rb
1498
1498
  - app/models/renalware/hd/prescription_administration.rb
1499
1499
  - app/models/renalware/hd/profile.rb
1500
+ - app/models/renalware/hd/profile_for_modality.rb
1501
+ - app/models/renalware/hd/profiles_in_date_range_query.rb
1500
1502
  - app/models/renalware/hd/provider.rb
1501
1503
  - app/models/renalware/hd/provider_unit.rb
1502
1504
  - app/models/renalware/hd/revise_hd_profile.rb
@@ -1753,7 +1755,9 @@ files:
1753
1755
  - app/models/renalware/pd/pet_adequacy_result.rb
1754
1756
  - app/models/renalware/pd/regime.rb
1755
1757
  - app/models/renalware/pd/regime_bag.rb
1758
+ - app/models/renalware/pd/regime_for_modality.rb
1756
1759
  - app/models/renalware/pd/regime_termination.rb
1760
+ - app/models/renalware/pd/regimes_in_date_range_query.rb
1757
1761
  - app/models/renalware/pd/revise_regime.rb
1758
1762
  - app/models/renalware/pd/save_peritonitis_episode.rb
1759
1763
  - app/models/renalware/pd/system.rb
@@ -1845,13 +1849,13 @@ files:
1845
1849
  - app/models/renalware/ukrdc/treatment_timeline/generate_timeline.rb
1846
1850
  - app/models/renalware/ukrdc/treatment_timeline/generate_treatments.rb
1847
1851
  - app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
1848
- - app/models/renalware/ukrdc/treatment_timeline/generators/deaths_timeline.rb
1849
- - app/models/renalware/ukrdc/treatment_timeline/generators/generic_timeline.rb
1850
- - app/models/renalware/ukrdc/treatment_timeline/generators/hd_timeline.rb
1851
- - app/models/renalware/ukrdc/treatment_timeline/generators/low_clearance_timelinex.rb
1852
- - app/models/renalware/ukrdc/treatment_timeline/generators/pd_timeline.rb
1853
- - app/models/renalware/ukrdc/treatment_timeline/generators/transplants_donor_timeline.rb
1854
- - app/models/renalware/ukrdc/treatment_timeline/generators/transplants_recipient_timeline.rb
1852
+ - app/models/renalware/ukrdc/treatment_timeline/generic/generator.rb
1853
+ - app/models/renalware/ukrdc/treatment_timeline/hd/generator.rb
1854
+ - app/models/renalware/ukrdc/treatment_timeline/hd/modality_code_map.rb
1855
+ - app/models/renalware/ukrdc/treatment_timeline/hd/profile_decorator.rb
1856
+ - app/models/renalware/ukrdc/treatment_timeline/pd/generator.rb
1857
+ - app/models/renalware/ukrdc/treatment_timeline/pd/modality_code_map.rb
1858
+ - app/models/renalware/ukrdc/treatment_timeline/pd/regime_decorator.rb
1855
1859
  - app/models/renalware/ukrdc/treatment_timeline/prepare_tables.rb
1856
1860
  - app/models/renalware/ukrdc/treatment_timeline/remap_model_table_names_to_their_prepared_equivalents.rb
1857
1861
  - app/models/renalware/ukrdc/xml_renderer.rb
@@ -2161,6 +2165,9 @@ files:
2161
2165
  - app/views/renalware/api/ukrdc/patients/procedures/_dialysis_session.xml.builder
2162
2166
  - app/views/renalware/api/ukrdc/patients/procedures/_transplant_operation.xml.builder
2163
2167
  - app/views/renalware/api/ukrdc/patients/show.xml.builder
2168
+ - app/views/renalware/api/ukrdc/patients/treatments/_generic.xml.builder
2169
+ - app/views/renalware/api/ukrdc/patients/treatments/_hd.xml.builder
2170
+ - app/views/renalware/api/ukrdc/patients/treatments/_pd.xml.builder
2164
2171
  - app/views/renalware/api/v1/medications/prescriptions/index.json.jbuilder
2165
2172
  - app/views/renalware/api/v1/patients/patients/index.json.jbuilder
2166
2173
  - app/views/renalware/api/v1/patients/patients/show.json.jbuilder
@@ -3520,6 +3527,9 @@ files:
3520
3527
  - db/migrate/20190611152859_add_fields_to_transplant_recipient_workup.rb
3521
3528
  - db/migrate/20190612124015_create_transplant_rejection_episodes.rb
3522
3529
  - db/migrate/20190617121528_create_transplant_rejection_treatments.rb
3530
+ - db/migrate/20190705083727_alter_ukrdc_treatments.rb
3531
+ - db/migrate/20190705105921_create_hd_profile_for_modalites.rb
3532
+ - db/migrate/20190709101610_create_pd_regime_for_modalities.rb
3523
3533
  - db/seeds.rb
3524
3534
  - db/seeds/default/accesses/access_pd_catheter_insertion_techniques.csv
3525
3535
  - db/seeds/default/accesses/access_pd_catheter_insertion_techniques.rb
@@ -3607,6 +3617,7 @@ files:
3607
3617
  - db/triggers/update_current_observation_set_trigger_v01.sql
3608
3618
  - db/triggers/update_research_study_participants_trigger_v01.sql
3609
3619
  - db/views/hd_grouped_transmission_logs_v01.sql
3620
+ - db/views/hd_profile_for_modalities_v01.sql
3610
3621
  - db/views/hd_schedule_definition_filters_v01.sql
3611
3622
  - db/views/medication_current_prescriptions_v01.sql
3612
3623
  - db/views/pathology_current_key_observation_sets_v01.sql
@@ -3620,6 +3631,7 @@ files:
3620
3631
  - db/views/patient_summaries_v04.sql
3621
3632
  - db/views/patient_summaries_v05.sql
3622
3633
  - db/views/patient_summaries_v06.sql
3634
+ - db/views/pd_regime_for_modalities_v01.sql
3623
3635
  - db/views/reporting_anaemia_audit_v01.sql
3624
3636
  - db/views/reporting_bone_audit_v01.sql
3625
3637
  - db/views/reporting_daily_letters_v01.sql
@@ -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 DeathsTimeline
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 GenericTimeline
10
- pattr_initialize :modality
11
-
12
- def call; end
13
- end
14
- end
15
- end
16
- end
17
- end