renalware-core 2.0.88 → 2.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +9 -0
- data/app/models/renalware/hospitals/unit.rb +11 -0
- data/app/models/renalware/ukrdc/create_encrypted_patient_xml_files.rb +15 -5
- data/app/models/renalware/ukrdc/create_patient_xml_file.rb +5 -2
- data/app/models/renalware/ukrdc/patients_query.rb +8 -4
- data/app/models/renalware/ukrdc/treatment_timeline/generate_timeline.rb +5 -5
- data/app/models/renalware/ukrdc/treatment_timeline/remap_model_table_names_to_their_prepared_equivalents.rb +16 -7
- data/app/presenters/renalware/ukrdc/patient_presenter.rb +5 -1
- data/app/views/renalware/api/ukrdc/patients/_treatments.xml.builder +21 -19
- data/lib/renalware/version.rb +1 -1
- data/lib/tasks/ukrdc.rake +13 -16
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dea8d3ef3c91160dead8c1db92b9a131b218f2ab1001c2acd0ad6698f6b83e33
|
4
|
+
data.tar.gz: 4a19dba06dfd48d8973e103dd3cb950162bf3fe038af55acbd5cee991e240b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de2b1c0d56675e5e23607cca2729c9864516ff919e838a278dcc84a15598b72ed2ab26b0be8894894a8cb10d5c1229213af78a6001bbfcc723ec881e5f43e52b
|
7
|
+
data.tar.gz: a8c732dfd1caba2154487c21c8f557ba52e09f161b71886262516938b2331399c33806d9fe292b961ad08d60d373baf55e632c1754d7cddfdcebe76922d5259f
|
data/Rakefile
CHANGED
@@ -43,3 +43,12 @@ namespace :assets do
|
|
43
43
|
Rake::Task["app:assets:clobber"].invoke
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
# Default rake task to run all tests:
|
48
|
+
# bundle exec rake
|
49
|
+
task :engine_default_task do
|
50
|
+
sh "bin/rspec"
|
51
|
+
sh "bin/cucumber"
|
52
|
+
sh "bin/cucumber TEST_DEPTH=web --profile rake_web"
|
53
|
+
end
|
54
|
+
task(:default).clear.enhance(["engine_default_task"])
|
@@ -7,6 +7,12 @@ module Renalware
|
|
7
7
|
class Unit < ApplicationRecord
|
8
8
|
extend Enumerize
|
9
9
|
|
10
|
+
UNIT_TYPE_RR8_MAP = {
|
11
|
+
hospital: "HOSP",
|
12
|
+
satellite: "SATL",
|
13
|
+
home: "HOME"
|
14
|
+
}.freeze
|
15
|
+
|
10
16
|
belongs_to :hospital_centre, class_name: "Hospitals::Centre"
|
11
17
|
has_many :wards,
|
12
18
|
class_name: "Hospitals::Ward",
|
@@ -32,6 +38,11 @@ module Renalware
|
|
32
38
|
def to_s
|
33
39
|
"#{name} (#{unit_code})"
|
34
40
|
end
|
41
|
+
|
42
|
+
# Map unit_type to its equivalent Renal Registry RR8 code.
|
43
|
+
def unit_type_rr8
|
44
|
+
UNIT_TYPE_RR8_MAP[unit_type.to_sym]
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
@@ -19,10 +19,11 @@ module Renalware
|
|
19
19
|
:request_uuid,
|
20
20
|
:timestamp,
|
21
21
|
:batch_number,
|
22
|
-
:summary
|
22
|
+
:summary,
|
23
|
+
:force_send
|
23
24
|
)
|
24
25
|
|
25
|
-
def initialize(changed_since: nil, patient_ids: nil, logger: nil)
|
26
|
+
def initialize(changed_since: nil, patient_ids: nil, logger: nil, force_send: false)
|
26
27
|
@changed_since = Time.zone.parse(changed_since) if changed_since.present?
|
27
28
|
@patient_ids = Array(patient_ids)
|
28
29
|
@logger = logger || Rails.logger
|
@@ -30,6 +31,7 @@ module Renalware
|
|
30
31
|
@timestamp = Time.zone.now.strftime("%Y%m%d%H%M%S%L")
|
31
32
|
@batch_number ||= BatchNumber.next.number
|
32
33
|
@summary = ExportSummary.new
|
34
|
+
@force_send = force_send
|
33
35
|
end
|
34
36
|
|
35
37
|
def call
|
@@ -74,7 +76,8 @@ module Renalware
|
|
74
76
|
changes_since: changed_since,
|
75
77
|
request_uuid: request_uuid,
|
76
78
|
batch_number: batch_number,
|
77
|
-
logger: logger
|
79
|
+
logger: logger,
|
80
|
+
force_send: force_send
|
78
81
|
).call
|
79
82
|
end
|
80
83
|
end
|
@@ -89,11 +92,18 @@ module Renalware
|
|
89
92
|
def ukrdc_patients_who_have_changed_since_last_send
|
90
93
|
@ukrdc_patients_who_have_changed_since_last_send ||= begin
|
91
94
|
logger.info("Finding #{patient_ids&.any? ? patient_ids : 'all ukrdc'} patients")
|
92
|
-
query = Renalware::UKRDC::PatientsQuery.new.call(
|
95
|
+
query = Renalware::UKRDC::PatientsQuery.new.call(
|
96
|
+
changed_since: changed_since,
|
97
|
+
changed_since_last_send: !force_send
|
98
|
+
)
|
93
99
|
query = query.where(id: Array(patient_ids)) if patient_ids.present?
|
94
100
|
|
95
101
|
if changed_since.present?
|
96
|
-
|
102
|
+
if force_send
|
103
|
+
logger.info("sending #{query.count} patients, taking changes since #{changed_since}")
|
104
|
+
else
|
105
|
+
logger.info("#{query.count} patients have changed since #{changed_since}")
|
106
|
+
end
|
97
107
|
else
|
98
108
|
logger.info("#{query.count} patients have changed since the last send")
|
99
109
|
end
|
@@ -14,10 +14,13 @@ module Renalware
|
|
14
14
|
:logger,
|
15
15
|
:batch_number,
|
16
16
|
:renderer, # so we can pass a test renderer to bypass real rendering
|
17
|
-
:log
|
17
|
+
:log,
|
18
|
+
:force_send
|
18
19
|
]
|
19
20
|
|
20
21
|
# rubocop:disable Metrics/AbcSize
|
22
|
+
# If force_send is true then send all files even if they have not changed since the last
|
23
|
+
# send. This is primarily for debugging and testing phases with UKRDC
|
21
24
|
def call
|
22
25
|
update_patient_to_indicated_we_checked_them_for_any_relevant_changes
|
23
26
|
UKRDC::TransmissionLog.with_logging(patient, request_uuid) do |log|
|
@@ -25,7 +28,7 @@ module Renalware
|
|
25
28
|
logger.info " Patient #{patient.ukrdc_external_id}"
|
26
29
|
xml_payload = build_payload(log)
|
27
30
|
if xml_payload.present?
|
28
|
-
if xml_payload_same_as_last_sent_payload?(xml_payload)
|
31
|
+
if !force_send && xml_payload_same_as_last_sent_payload?(xml_payload)
|
29
32
|
logger.info " skipping as no change in XML file"
|
30
33
|
log.unsent_no_change_since_last_send!
|
31
34
|
else
|
@@ -18,11 +18,15 @@ module Renalware
|
|
18
18
|
# this for now I think. If it is a problem we can use the checked_for_ukrdc_changes_at column
|
19
19
|
# on patients.
|
20
20
|
class PatientsQuery
|
21
|
-
def call(changed_since: nil)
|
21
|
+
def call(changed_since: nil, changed_since_last_send: true)
|
22
22
|
if changed_since.present?
|
23
|
-
|
24
|
-
|
23
|
+
# patients who changed since a specific date (inclusive)
|
24
|
+
sendable_patients.where("updated_at >= ?", changed_since)
|
25
|
+
elsif changed_since_last_send
|
26
|
+
# patients who have never been sent, or have changed since the last time they were sent
|
25
27
|
sendable_patients.where("(sent_to_ukrdc_at is null) or (updated_at > sent_to_ukrdc_at)")
|
28
|
+
else
|
29
|
+
sendable_patients
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -31,7 +35,7 @@ module Renalware
|
|
31
35
|
def sendable_patients
|
32
36
|
Renalware::Patient.where(send_to_rpv: true).or(
|
33
37
|
Renalware::Patient.where(send_to_renalreg: true)
|
34
|
-
)
|
38
|
+
).order(family_name: :asc, given_name: :asc)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -15,11 +15,11 @@ module Renalware
|
|
15
15
|
|
16
16
|
def call
|
17
17
|
PrepareTables.call
|
18
|
-
RemapModelTableNamesToTheirPreparedEquivalents.call
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
RemapModelTableNamesToTheirPreparedEquivalents.new.call do
|
19
|
+
modalities.each do |modality|
|
20
|
+
print "#{modality.description.name} "
|
21
|
+
GeneratorFactory.call(modality).call
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
module Renalware
|
5
5
|
module UKRDC
|
6
6
|
module TreatmentTimeline
|
7
|
-
#
|
7
|
+
# When generating the treatment timeline, sites may want to pre-prepare a massaged version
|
8
8
|
# of say hd_profiles, in order to correct any anomalies. This service object
|
9
9
|
# will remap the table_name of the supplied (or default models) to the
|
10
10
|
# 'ukrdc_prepared_*' version if it exists. Otrherwise it will not change the table name.
|
@@ -19,16 +19,25 @@ module Renalware
|
|
19
19
|
].freeze
|
20
20
|
class ExecutionNotAllowedError < StandardError; end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def call(models)
|
22
|
+
# Saves the original table names for the array of models classes
|
23
|
+
# remaps to its ukrdc_prepared_* varaient if it exists, yields to allow
|
24
|
+
# the claling process to do its thing, then importantly winds back to
|
25
|
+
# the original table names.
|
26
|
+
def call(models = MODELS)
|
27
27
|
fail_unless_running_in_rake_or_rspec
|
28
|
-
Array(models)
|
28
|
+
models = Array(models)
|
29
|
+
original_table_names = models.map(&:table_name)
|
30
|
+
|
31
|
+
models.each do |model_class|
|
29
32
|
prepared_table_name = prepared_table_name_for(model_class.table_name)
|
30
33
|
model_class.table_name = prepared_table_name if table_exists?(prepared_table_name)
|
31
34
|
end
|
35
|
+
|
36
|
+
yield if block_given?
|
37
|
+
|
38
|
+
models.each_with_index do |model_class, index|
|
39
|
+
model_class.table_name = original_table_names[index]
|
40
|
+
end
|
32
41
|
end
|
33
42
|
|
34
43
|
private
|
@@ -39,7 +39,10 @@ module Renalware
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def modalities
|
42
|
-
__getobj__
|
42
|
+
__getobj__
|
43
|
+
.modalities
|
44
|
+
.includes(:description)
|
45
|
+
.order(started_on: :asc, created_at: :asc)
|
43
46
|
end
|
44
47
|
|
45
48
|
def dead?
|
@@ -52,6 +55,7 @@ module Renalware
|
|
52
55
|
current_modality.description.is_a?(Renalware::HD::ModalityDescription)
|
53
56
|
end
|
54
57
|
|
58
|
+
# Note we of course only send letters for RPV patients and exlcude them for all others.
|
55
59
|
def letters
|
56
60
|
return ::Renalware::Letters::Letter.none if send_to_rpv == false
|
57
61
|
|
@@ -8,6 +8,7 @@ xml = builder
|
|
8
8
|
# like CAPD and HDF are not yet implemented, just the top level modality.
|
9
9
|
patient.modalities.each do |modality|
|
10
10
|
ukrdc_modality_code_id = modality.description.ukrdc_modality_code_id
|
11
|
+
|
11
12
|
next if ukrdc_modality_code_id.blank?
|
12
13
|
|
13
14
|
ukrdc_modality_code = Renalware::UKRDC::ModalityCode.find(ukrdc_modality_code_id)
|
@@ -28,24 +29,25 @@ patient.modalities.each do |modality|
|
|
28
29
|
xml.Code ukrdc_modality_code.txt_code
|
29
30
|
end
|
30
31
|
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
# This is a bit of hack to get the HD Profile location for the current modality
|
33
|
+
if [1, 2, 3, 4, 5, 9].include?(ukrdc_modality_code.txt_code.to_i) # HD
|
34
|
+
profile = Renalware::HD::Profile
|
35
|
+
.where(patient_id: patient.id)
|
36
|
+
.where(<<-SQL).order(created_at: :desc).first
|
37
|
+
created_at::date <= '#{modality.started_on}'
|
38
|
+
and (
|
39
|
+
deactivated_at is NULL or
|
40
|
+
(
|
41
|
+
deactivated_at > '#{modality.started_on}'
|
42
|
+
)
|
43
|
+
)
|
44
|
+
SQL
|
45
|
+
|
46
|
+
if profile&.hospital_unit&.unit_type_rr8.present?
|
47
|
+
xml.Attributes do
|
48
|
+
xml.QBL05 profile.hospital_unit.unit_type_rr8 # eg HOME
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/renalware/version.rb
CHANGED
data/lib/tasks/ukrdc.rake
CHANGED
@@ -5,40 +5,37 @@ require "fileutils"
|
|
5
5
|
# Note you can print out the help for this task and others with `rake -D`
|
6
6
|
namespace :ukrdc do
|
7
7
|
desc <<-DESC
|
8
|
-
Creates a folder of UKRDC XML files with any changes to PV patients since their last export
|
8
|
+
Creates a folder of UKRDC XML files with any changes to PV + RR patients since their last export
|
9
9
|
Notes:
|
10
10
|
1. Running the rake task updates the sent_to_ukrdc_at for each patient exported.
|
11
|
-
If you don't want to do this you may need to edit this task to
|
11
|
+
If you don't want to do this you may need to edit this task to wrap the code in a
|
12
12
|
transaction you can optionally roll back.
|
13
13
|
2: If testing this inside the renalware-core gem, you will need to append app: e.g.
|
14
14
|
app:ukrdc:export ...
|
15
15
|
|
16
16
|
Example usage
|
17
|
-
1. To get all patients with
|
18
|
-
were sent, or have not been sent to the UKRDC yet:
|
17
|
+
1. To get all RR and RPV patients with who have changed
|
18
|
+
since the last time they were sent, or have not been sent to the UKRDC yet:
|
19
19
|
|
20
20
|
bundle exec rake ukrdc:export
|
21
21
|
|
22
|
-
2. To get all
|
22
|
+
2. To get all RR and RPV patients who have changed since a certain date:
|
23
23
|
|
24
|
-
bundle exec rake ukrdc:export
|
25
|
-
or in zsh shell
|
26
|
-
bundle exec rake ukrdc:export\["2018-02-23"\]
|
24
|
+
bundle exec rake ukrdc:export changed_since="2018-02-23"
|
27
25
|
|
28
|
-
3. To get only certain RPV patients (by their id eg ids 1 and 2)
|
29
|
-
a certain
|
26
|
+
3. To get only certain RR and RPV patients (by their id eg ids 1 and 2) with changes since
|
27
|
+
a certain date:
|
30
28
|
|
31
|
-
bundle exec rake ukrdc:export
|
32
|
-
or in the zsh shell
|
33
|
-
bundle exec rake ukrdc:export\["2018-02-23","1 2"\]
|
29
|
+
bundle exec rake ukrdc:export changed_since=2018-02-23 patient_ids=1,2
|
34
30
|
DESC
|
35
|
-
task :export
|
31
|
+
task :export => :environment do |_task, args|
|
36
32
|
logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
37
33
|
logger.level = Logger::INFO
|
38
34
|
Rails.logger = logger
|
39
35
|
Renalware::UKRDC::CreateEncryptedPatientXMLFiles.new(
|
40
|
-
changed_since:
|
41
|
-
patient_ids:
|
36
|
+
changed_since: ENV["changed_since"],
|
37
|
+
patient_ids: ENV.fetch("patient_ids", "").split(",").map(&:to_i),
|
38
|
+
force_send: ENV["force_send"] == "true"
|
42
39
|
).call
|
43
40
|
end
|
44
41
|
|
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.
|
4
|
+
version: 2.0.89
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airslie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_type
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 9.
|
75
|
+
version: '9.6'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 9.
|
82
|
+
version: '9.6'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: client_side_validations
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -938,16 +938,16 @@ dependencies:
|
|
938
938
|
name: yard
|
939
939
|
requirement: !ruby/object:Gem::Requirement
|
940
940
|
requirements:
|
941
|
-
- - "
|
941
|
+
- - ">="
|
942
942
|
- !ruby/object:Gem::Version
|
943
|
-
version: 0.9.
|
943
|
+
version: 0.9.20
|
944
944
|
type: :runtime
|
945
945
|
prerelease: false
|
946
946
|
version_requirements: !ruby/object:Gem::Requirement
|
947
947
|
requirements:
|
948
|
-
- - "
|
948
|
+
- - ">="
|
949
949
|
- !ruby/object:Gem::Version
|
950
|
-
version: 0.9.
|
950
|
+
version: 0.9.20
|
951
951
|
description: Renalware uses demographic, clinical, pathology, and nephrology datasets
|
952
952
|
to improve patient care, undertake clinical and administrative audits and share
|
953
953
|
data with external systems.
|