renalware-core 2.0.99 → 2.0.100

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 688cbe6a0810acd8980722dbde29b68a21116d2e695a01bb0f71da9bef6c03c2
4
- data.tar.gz: ca04c46a641c5214422e23f5b78e4872bccb5447691e5f02a1f76a049da16923
3
+ metadata.gz: 8aa7d57a0adfff2d76fadc4c11c9442fa83d82ca6dd5f01dcca5cfbf4226e0a9
4
+ data.tar.gz: 7a7c0329c9a32aac0da27b4165ab2bb1f1c9dd111729d4d86cbfaacab46040d8
5
5
  SHA512:
6
- metadata.gz: 7585d9b098511c978d0b3f5b5f3b7ab7bcc89dc648e01943d7391694f69672afc07bf00451e9a65ab4f2caa622d2e7809aa8ade755d32428a208891c4332f223
7
- data.tar.gz: 1c30a614fb4d0d85fc50a566ce141fd4aaf684ad6fed4080b32fd207e7bc2334e2f3c432d73899435826be964a67dc08078db6318846ab852ed1872751811f10
6
+ metadata.gz: 8f73fec51538a54fa18a57c9f3d2b009f8f64ce1253d7c9a43eb5cc1d19164fcba654b9ec43a976733359a833873299c1c7b199abe75e54d3baf9f3bb8478118
7
+ data.tar.gz: f9117254aad358aa7d265db64cfeeba583be6a8cac7c707e33440e8827659abe75529c4c8bcf17e92f4532d1eb10790fb3a498aaba4018f9ed39b9f82a8ef1cd
@@ -36,13 +36,11 @@ module Renalware
36
36
 
37
37
  def call
38
38
  logger.tagged(request_uuid) do
39
- # ActiveRecord::Base.transaction do
40
39
  summary.milliseconds_taken = Benchmark.ms do
41
40
  create_patient_xml_files
42
41
  encrypt_patient_xml_files
43
42
  copy_encrypted_xml_files_into_the_outgoing_folder
44
43
  end
45
- # end
46
44
  paths.create_symlink_to_latest_timestamped_folder_so_it_is_easier_to_eyeball
47
45
  build_summary
48
46
  print_summary
@@ -93,7 +91,7 @@ module Renalware
93
91
  summary.results = export_results
94
92
  end
95
93
 
96
- # rubocop:disable Metrics/AbcSize
94
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
97
95
  def ukrdc_patients_who_have_changed_since_last_send
98
96
  @ukrdc_patients_who_have_changed_since_last_send ||= begin
99
97
  logger.info("Finding #{patient_ids&.any? ? patient_ids : 'all ukrdc'} patients")
@@ -115,7 +113,7 @@ module Renalware
115
113
  query.all
116
114
  end
117
115
  end
118
- # rubocop:enable Metrics/AbcSize
116
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
119
117
 
120
118
  # rubocop:disable Metrics/AbcSize
121
119
  def print_summary
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "renalware/ukrdc"
4
+ require "attr_extras"
5
+
6
+ module Renalware
7
+ module UKRDC
8
+ module Housekeeping
9
+ # Responsible for cleaning up old archive folders that are created each time the
10
+ # ukrdc:export task has run. Each archive folder's name has a batch number in it which is the
11
+ # id of the UKRDC::BatchNumber model created at the start of each export. We can find the
12
+ # folders to remove by extracting the batch number from the folder name and deleting the
13
+ # folder if that batch is no longer 'recent'.
14
+ # Called from a housekeeping rake task.
15
+ class RemoveOldExportArchiveFolders
16
+ def self.call
17
+ new.call
18
+ end
19
+
20
+ def call
21
+ remove_old_archives
22
+ end
23
+
24
+ private
25
+
26
+ class ArchiveFolder
27
+ pattr_initialize :folder
28
+
29
+ # Returns the integer batch number from the folder name
30
+ # e.g. 13 from /var/ukrdc/archive/000013_20190827081107620
31
+ def batch_number
32
+ matches = folder.match(%r(\/(\d{6})_))
33
+ return unless matches
34
+
35
+ matches[1].to_i
36
+ end
37
+ end
38
+
39
+ def remove_old_archives
40
+ log "Remove old archives"
41
+ log "Keeping archived batches #{batch_numbers_to_keep.join(', ')}"
42
+
43
+ Dir.glob(glob_pattern).each do |folder|
44
+ archive_folder = ArchiveFolder.new(folder)
45
+ next unless archive_folder.batch_number
46
+
47
+ if remove_folder?(archive_folder)
48
+ log "Removing #{folder}"
49
+ FileUtils.rm_rf folder
50
+ end
51
+ end
52
+ end
53
+
54
+ # Pattern to use to find batch-numbered folders in the archive directory
55
+ def glob_pattern
56
+ archive_path.join("??????_*")
57
+ end
58
+
59
+ def archive_path
60
+ Pathname(Renalware.config.ukrdc_working_path).join("archive")
61
+ end
62
+
63
+ def number_of_archived_folders_to_keep
64
+ Renalware.config.ukrdc_number_of_archived_folders_to_keep.to_i
65
+ end
66
+
67
+ # Returns the ids of a few of the most recent BatchNumbers rows (ie the batch number) that
68
+ # we should not delete - these being the most recent ones we want to stick around in case we
69
+ # need to inspect what was sent.
70
+ def batch_numbers_to_keep
71
+ @batch_numbers_to_keep ||= begin
72
+ BatchNumber
73
+ .limit(number_of_archived_folders_to_keep)
74
+ .order(created_at: :desc)
75
+ .pluck(:id)
76
+ end
77
+ end
78
+
79
+ def remove_folder?(archive_folder)
80
+ !batch_numbers_to_keep.include?(archive_folder.batch_number)
81
+ end
82
+
83
+ def log(msg)
84
+ Rails.logger.info(" " + msg)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -16,7 +16,8 @@ ruby:
16
16
  = f.association :type,
17
17
  collection: Renalware::Accesses::Type.ordered,
18
18
  label_method: :long_name,
19
- wrapper: :horizontal_medium
19
+ wrapper: :horizontal_medium,
20
+ input_html: { class: "searchable_select" }
20
21
  = f.input :side, wrapper: :horizontal_small
21
22
  = f.association :pd_catheter_insertion_technique,
22
23
  collection: Renalware::Accesses::CatheterInsertionTechnique.ordered,
@@ -9,7 +9,7 @@
9
9
  dt Treatment:
10
10
  dd= exit_site_infection.treatment
11
11
  dt Notes:
12
- dd= exit_site_infection.notes
12
+ dd= simple_format(exit_site_infection.notes)
13
13
  dt= attr_name(exit_site_infection, :clinical_presentation)
14
14
  dd= exit_site_infection.clinical_presentation&.texts&.join(", ")
15
15
  - %i(recurrent cleared catheter_removed).each do |option|
@@ -41,7 +41,7 @@
41
41
  .row
42
42
  .large-12.columns
43
43
  = article_tag "Peritonitis Episode Notes" do
44
- p= peritonitis_episode.notes
44
+ = simple_format(peritonitis_episode.notes)
45
45
 
46
46
  .right
47
47
  = link_to "Edit",
data/db/seeds.rb CHANGED
@@ -20,6 +20,7 @@ def log(msg, type: :full)
20
20
  end
21
21
  end
22
22
 
23
+ PaperTrail.enabled = false
23
24
 
24
25
  # Seed the database with data common to all installations.
25
26
  # Site specific data should be seeded from the host application.
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SeedsHelper
4
- def without_papertrail_versioning_for(klass)
5
- raise ArgumentError unless klass.is_a? Class
6
- klass.paper_trail.disable
4
+ def without_papertrail_versioning_for(klasses)
5
+ Array(klasses).each { |klass| klass.paper_trail.disable }
7
6
  yield
8
- klass.paper_trail.enable
7
+ Array(klasses).each { |klass| klass.paper_trail.enable }
9
8
  end
10
9
  end
@@ -66,6 +66,9 @@ module Renalware
66
66
  ENV.fetch("UKRDC_WORKING_PATH", File.join("/var", "ukrdc"))
67
67
  end
68
68
  config_accessor(:ukrdc_site_code) { ENV.fetch("UKRDC_PREFIX", "RJZ") }
69
+ config_accessor(:ukrdc_number_of_archived_folders_to_keep) do
70
+ ENV.fetch("UKRDC_NUMBER_OF_ARCHIVED_FOLDERS_TO_KEEP", "3")
71
+ end
69
72
 
70
73
  # To use a date other that the default changes_since date when
71
74
  # compiling pathology to send to UKRDC, you can set an ENV var as follows:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Renalware
4
- VERSION = "2.0.99"
4
+ VERSION = "2.0.100"
5
5
  end
data/lib/tasks/ukrdc.rake CHANGED
@@ -47,4 +47,12 @@ namespace :ukrdc do
47
47
  Rails.logger = logger
48
48
  Renalware::UKRDC::TreatmentTimeline::GenerateTreatments.call
49
49
  end
50
+
51
+ task housekeeping: :environment do
52
+ logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
53
+ logger.level = Logger::INFO
54
+ Rails.logger = logger
55
+ logger.info "UKRDC housekeeping"
56
+ Renalware::UKRDC::Housekeeping::RemoveOldExportArchiveFolders.call
57
+ end
50
58
  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.99
4
+ version: 2.0.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airslie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-23 00:00:00.000000000 Z
11
+ date: 2019-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_type
@@ -1840,6 +1840,7 @@ files:
1840
1840
  - app/models/renalware/ukrdc/create_patient_xml_file.rb
1841
1841
  - app/models/renalware/ukrdc/export_summary.rb
1842
1842
  - app/models/renalware/ukrdc/filename.rb
1843
+ - app/models/renalware/ukrdc/housekeeping/remove_old_export_archive_folders.rb
1843
1844
  - app/models/renalware/ukrdc/modality_code.rb
1844
1845
  - app/models/renalware/ukrdc/pathology_observation_requests_query.rb
1845
1846
  - app/models/renalware/ukrdc/paths.rb