renalware-core 2.0.78 → 2.0.79
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/README.md +1 -1
- data/app/assets/javascripts/renalware/application.js.erb +1 -0
- data/app/assets/javascripts/renalware/layout.js +3 -0
- data/app/assets/stylesheets/renalware/modules/_patients.scss +2 -1
- data/app/controllers/renalware/admin/feeds/files_controller.rb +7 -1
- data/app/controllers/renalware/patients/practices_controller.rb +1 -1
- data/app/controllers/renalware/patients/primary_care_physician_controller.rb +32 -13
- data/app/controllers/renalware/virology/dashboards_controller.rb +1 -4
- data/app/controllers/renalware/virology/profiles_controller.rb +10 -5
- data/app/documents/renalware/hd/session_document.rb +4 -0
- data/app/documents/renalware/patient_document.rb +15 -1
- data/app/documents/renalware/renal/profile_document.rb +22 -0
- data/app/documents/renalware/virology/profile_document.rb +1 -0
- data/app/models/renalware/clinics/remembered_clinic_visit_preferences.rb +1 -1
- data/app/models/renalware/feeds/files/practice_memberships/import_job.rb +2 -8
- data/app/models/renalware/feeds/files/primary_care_physicians/import_csv.rb +2 -2
- data/app/models/renalware/hd/session/closed.rb +2 -0
- data/app/models/renalware/patients/last_successful_practice_sync_date_query.rb +28 -0
- data/app/models/renalware/patients/practice.rb +0 -2
- data/app/models/renalware/patients/practice_search_query.rb +4 -2
- data/app/models/renalware/patients/sync_gps_via_file_download_job.rb +52 -0
- data/app/models/renalware/patients/sync_ods_job.rb +53 -0
- data/app/models/renalware/patients/sync_practices_via_api.rb +157 -0
- data/app/models/renalware/system/api_log.rb +29 -0
- data/app/presenters/renalware/admissions/consult_summary_part.rb +36 -0
- data/app/presenters/renalware/ukrdc/patient_presenter.rb +66 -6
- data/app/presenters/renalware/virology/dashboard_presenter.rb +32 -0
- data/app/validators/renalware/patients/respiratory_rate_validator.rb +17 -0
- data/app/views/renalware/admissions/consults/_summary_part.html.slim +17 -0
- data/app/views/renalware/admissions/consults/_table.html.slim +58 -19
- data/app/views/renalware/api/ukrdc/patients/_diagnoses.xml.builder +43 -3
- data/app/views/renalware/api/ukrdc/patients/_medications.xml.builder +23 -3
- data/app/views/renalware/api/ukrdc/patients/_social_histories.xml.builder +2 -2
- data/app/views/renalware/hd/protocols/_virology.html.slim +2 -0
- data/app/views/renalware/hd/sessions/_form.html.slim +4 -0
- data/app/views/renalware/pathology/historical_observation_results/index.html.slim +2 -2
- data/app/views/renalware/virology/dashboards/_latest_hep_b_antibody_statuses.html.slim +5 -0
- data/app/views/renalware/virology/dashboards/show.html.slim +6 -3
- data/app/views/renalware/virology/profiles/_summary.html.slim +2 -2
- data/app/views/renalware/virology/profiles/edit.html.slim +1 -0
- data/config/locales/renalware/hd/session.en.yml +4 -0
- data/config/locales/renalware/virology/virology.en.yml +1 -0
- data/db/functions/import_practice_memberships_csv_v03.sql +65 -0
- data/db/migrate/20190531172829_add_last_change_date_to_patient_practices.rb +26 -0
- data/db/migrate/20190602114659_create_system_api_logs.rb +15 -0
- data/db/migrate/20190603084428_add_pages_to_system_api_logs.rb +5 -0
- data/db/migrate/20190603135247_add_columns_to_patient_primary_care_physicians.rb +8 -0
- data/db/migrate/20190603143834_update_import_practice_memberships_csv.rb +13 -0
- data/db/migrate/20190603165812_drop_import_practices_csv_function.rb +13 -0
- data/db/seeds/default/feeds/import_file_types.rb +0 -8
- data/db/seeds/default/renal/prd_descriptions.csv +266 -266
- data/lib/document/enum.rb +4 -0
- data/lib/renalware/configuration.rb +1 -0
- data/lib/renalware/version.rb +1 -1
- data/lib/tasks/feeds/files.rake +0 -16
- data/lib/tasks/hd.rake +2 -0
- data/lib/tasks/ods.rake +10 -0
- data/spec/factories/feeds/file.rb +0 -4
- data/spec/factories/feeds/file_types.rb +2 -7
- data/spec/factories/hd/hd_session_document.rb +2 -0
- data/spec/factories/system/api_logs.rb +19 -0
- data/spec/support/pathology_spec_helper.rb +12 -8
- data/vendor/assets/javascripts/renalware/double_scroll.js +128 -0
- metadata +23 -9
- data/app/models/renalware/feeds/files/practices/convert_xml_to_csv.rb +0 -153
- data/app/models/renalware/feeds/files/practices/country_map.rb +0 -36
- data/app/models/renalware/feeds/files/practices/csv_file.rb +0 -25
- data/app/models/renalware/feeds/files/practices/csv_organisation.rb +0 -37
- data/app/models/renalware/feeds/files/practices/import_csv.rb +0 -32
- data/app/models/renalware/feeds/files/practices/import_job.rb +0 -61
- data/app/models/renalware/feeds/files/practices/xml_parser.rb +0 -102
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e498f337dc6db41cfb6478cd0241f19693a22f284ff95941a1756c32beb057d5
|
|
4
|
+
data.tar.gz: 45bf39706420b19adc516e7e2fc2effd4c095392a675d01af1e1a64892ba0420
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ba0afc1c09b0f94252f359d6ca2412906e668c437913a11115ba3174325ed27e441ea29e9e895e07a9e9ca1b6a259ed622be7d31dbe3fc3dc9dd0d4a5906293
|
|
7
|
+
data.tar.gz: a14cb7fa2f36d3d40b3939715e485804b713b148dcd54dd68420eba7f1007a6cfbf31dde473952805ce79cae497276ae004e0734ee120f42b4affbe1c016a3d3
|
data/README.md
CHANGED
|
@@ -123,7 +123,7 @@ On a Mac:
|
|
|
123
123
|
- Download chromedriver from eg [here](https://chromedriver.storage.googleapis.com/index.html?path=2.38/)
|
|
124
124
|
- Unzip and place in location in your PATH eh `/usr/local/bin`
|
|
125
125
|
- If you have chromedriver errors it maybe your installed version of Chrome is not
|
|
126
|
-
compatible your chromedriver version. In this case check your versions with
|
|
126
|
+
compatible your chromedriver version. In this case check your versions with:
|
|
127
127
|
|
|
128
128
|
```
|
|
129
129
|
chromedriver -v
|
|
@@ -39,7 +39,13 @@ module Renalware
|
|
|
39
39
|
private
|
|
40
40
|
|
|
41
41
|
def files
|
|
42
|
-
@files ||=
|
|
42
|
+
@files ||= begin
|
|
43
|
+
Renalware::Feeds::File
|
|
44
|
+
.ordered
|
|
45
|
+
.includes(:file_type, :created_by)
|
|
46
|
+
.page(page)
|
|
47
|
+
.per(per_page)
|
|
48
|
+
end
|
|
43
49
|
end
|
|
44
50
|
|
|
45
51
|
def file_upload_params
|
|
@@ -35,10 +35,8 @@ module Renalware
|
|
|
35
35
|
# So to allow the Practice and GP to be assigned to such a patient we have to skip validation
|
|
36
36
|
# callbacks by using update_columns.
|
|
37
37
|
def update_patient
|
|
38
|
-
return false unless selected_pyhsician
|
|
39
|
-
|
|
40
38
|
patient.update_columns(
|
|
41
|
-
primary_care_physician_id:
|
|
39
|
+
primary_care_physician_id: selected_physician_id,
|
|
42
40
|
practice_id: patient_params[:practice_id],
|
|
43
41
|
updated_by_id: current_user.id
|
|
44
42
|
)
|
|
@@ -56,9 +54,12 @@ module Renalware
|
|
|
56
54
|
}
|
|
57
55
|
end
|
|
58
56
|
|
|
59
|
-
def
|
|
60
|
-
@
|
|
61
|
-
PrimaryCarePhysician
|
|
57
|
+
def selected_physician_id
|
|
58
|
+
@selected_physician_id ||= begin
|
|
59
|
+
PrimaryCarePhysician
|
|
60
|
+
.select(:id)
|
|
61
|
+
.find_by(id: patient_params[:primary_care_physician_id])
|
|
62
|
+
&.id
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
65
|
|
|
@@ -67,20 +68,38 @@ module Renalware
|
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
# Every time a practice is selected from the autocomplete list in the Find GP modal
|
|
70
|
-
# we re-render the edit form and inject the practice_id as a hidden field therein
|
|
71
|
-
#
|
|
71
|
+
# we re-render the edit form and inject the practice_id as a hidden field therein so it
|
|
72
|
+
# is available in a form submission in the #update action.
|
|
72
73
|
# The practice_id in this method is supplied here as a query param by the JS that refreshes
|
|
73
74
|
# the form when a practice is selected - it will be the same as that posted in the form when
|
|
74
|
-
# saved, but at this stage its
|
|
75
|
+
# saved, but at this stage its ephemeral and just here to let us build the GP list to
|
|
75
76
|
# render in the form.
|
|
76
77
|
def available_primary_care_physicians
|
|
77
|
-
|
|
78
|
-
return [] unless
|
|
78
|
+
practice_id = params[:practice_id]
|
|
79
|
+
return [] unless practice_id
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
[
|
|
81
|
+
find_practice_memberships_for(practice_id).map do |membership|
|
|
82
|
+
[
|
|
83
|
+
format_gp_name(membership),
|
|
84
|
+
membership.primary_care_physician&.id
|
|
85
|
+
]
|
|
82
86
|
end
|
|
83
87
|
end
|
|
88
|
+
|
|
89
|
+
def find_practice_memberships_for(practice_id)
|
|
90
|
+
PracticeMembership
|
|
91
|
+
.eager_load(:primary_care_physician)
|
|
92
|
+
.where(practice_id: practice_id)
|
|
93
|
+
.order(
|
|
94
|
+
"#{PracticeMembership.table_name}.left_on desc,"\
|
|
95
|
+
"#{PrimaryCarePhysician.table_name}.name asc"
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def format_gp_name(membership)
|
|
100
|
+
left_on = " (Left #{I18n.l(membership.left_on)})" if membership.left_on.present?
|
|
101
|
+
"#{membership.primary_care_physician}#{left_on}"
|
|
102
|
+
end
|
|
84
103
|
end
|
|
85
104
|
end
|
|
86
105
|
end
|
|
@@ -7,10 +7,7 @@ module Renalware
|
|
|
7
7
|
class DashboardsController < BaseController
|
|
8
8
|
def show
|
|
9
9
|
authorize [:renalware, :virology, :dashboard], :show?
|
|
10
|
-
render locals: {
|
|
11
|
-
patient: patient,
|
|
12
|
-
vaccinations: Vaccination.for_patient(patient)
|
|
13
|
-
}
|
|
10
|
+
render locals: { dashboard: DashboardPresenter.new(patient) }
|
|
14
11
|
end
|
|
15
12
|
end
|
|
16
13
|
end
|
|
@@ -32,15 +32,20 @@ module Renalware
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def update_profile(profile)
|
|
35
|
-
document_params = profile_params[:document]
|
|
36
35
|
document = profile.document
|
|
37
|
-
document.hiv =
|
|
38
|
-
document.hepatitis_b =
|
|
39
|
-
document.
|
|
40
|
-
document.
|
|
36
|
+
document.hiv = year_date_diagnosis_for(:hiv)
|
|
37
|
+
document.hepatitis_b = year_date_diagnosis_for(:hepatitis_b)
|
|
38
|
+
document.hepatitis_b_core_antibody = year_date_diagnosis_for(:hepatitis_b_core_antibody)
|
|
39
|
+
document.hepatitis_c = year_date_diagnosis_for(:hepatitis_c)
|
|
40
|
+
document.htlv = year_date_diagnosis_for(:htlv)
|
|
41
41
|
profile.save_by(current_user)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
def year_date_diagnosis_for(condition)
|
|
45
|
+
document_params = profile_params[:document]
|
|
46
|
+
YearDatedDiagnosis.new(document_params[condition])
|
|
47
|
+
end
|
|
48
|
+
|
|
44
49
|
def profile_params
|
|
45
50
|
params.require(:virology_profile).permit(document: {})
|
|
46
51
|
end
|
|
@@ -34,11 +34,14 @@ module Renalware
|
|
|
34
34
|
attribute :temperature, Float
|
|
35
35
|
attribute :temperature_measured, Document::Enum, enums: %i(yes no), default: :yes
|
|
36
36
|
attribute :bm_stix, Float
|
|
37
|
+
attribute :respiratory_rate, Integer
|
|
38
|
+
attribute :respiratory_rate_measured, Document::Enum, enums: %i(yes no), default: :yes
|
|
37
39
|
|
|
38
40
|
%i(
|
|
39
41
|
weight
|
|
40
42
|
temperature
|
|
41
43
|
bm_stix
|
|
44
|
+
respiratory_rate
|
|
42
45
|
pulse
|
|
43
46
|
).each { |att| validates(att, numericality: { allow_blank: true }) }
|
|
44
47
|
|
|
@@ -46,6 +49,7 @@ module Renalware
|
|
|
46
49
|
validates :temperature, "renalware/patients/temperature" => true
|
|
47
50
|
validates :bm_stix, "renalware/patients/bm_stix" => true
|
|
48
51
|
validates :pulse, "renalware/patients/pulse" => true
|
|
52
|
+
validates :respiratory_rate, "renalware/patients/respiratory_rate" => true
|
|
49
53
|
end
|
|
50
54
|
attribute :observations_before, Observations
|
|
51
55
|
attribute :observations_after, Observations
|
|
@@ -28,8 +28,22 @@ module Renalware
|
|
|
28
28
|
attribute :psychosocial, Psychosocial
|
|
29
29
|
|
|
30
30
|
class History < Document::Embedded
|
|
31
|
+
SMOKING_SNOMED_MAP = {
|
|
32
|
+
"yes" => { code: 77176002, description: "Current" },
|
|
33
|
+
"no" => { code: 8392000, description: "Non" },
|
|
34
|
+
"ex" => { code: 8517006, description: "Ex" }
|
|
35
|
+
}.freeze
|
|
36
|
+
|
|
31
37
|
attribute :alcohol, Document::Enum, enums: %i(never rarely social heavy)
|
|
32
|
-
attribute :smoking, Document::Enum, enums: %i(no ex yes)
|
|
38
|
+
attribute :smoking, Document::Enum, enums: %i(no ex yes)
|
|
39
|
+
|
|
40
|
+
def smoking_snomed
|
|
41
|
+
SMOKING_SNOMED_MAP[@smoking]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def smoking_rr
|
|
45
|
+
@smoking&.upcase
|
|
46
|
+
end
|
|
33
47
|
end
|
|
34
48
|
attribute :history, History
|
|
35
49
|
end
|
|
@@ -7,6 +7,24 @@ module Renalware
|
|
|
7
7
|
module Renal
|
|
8
8
|
class ProfileDocument < Document::Embedded
|
|
9
9
|
class Comorbidities < Document::Embedded
|
|
10
|
+
SMOMED_MAP = {
|
|
11
|
+
diabetes: 73211009,
|
|
12
|
+
ischaemic_heart_dis: 414545008,
|
|
13
|
+
cabg_or_angioplasty: 232717009,
|
|
14
|
+
heart_failure: 84114007,
|
|
15
|
+
atrial_fibrill: 49436004,
|
|
16
|
+
malignancy: 86049000,
|
|
17
|
+
cerebrovascular_dis: 62914000,
|
|
18
|
+
chronic_obstr_pulm_dis: 13645005,
|
|
19
|
+
liver_disease: 235856003,
|
|
20
|
+
periph_vascular_dis: 400047006,
|
|
21
|
+
amputation_for_pvd: 81723002,
|
|
22
|
+
claudication: 275520000,
|
|
23
|
+
ischaemic_neuropathic_ulcers: 13954005,
|
|
24
|
+
non_coronary_intervention: 418285008,
|
|
25
|
+
dementia: 52448006
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
10
28
|
attribute :diabetes, YearDatedConfirmation
|
|
11
29
|
attribute :ischaemic_heart_dis, YearDatedConfirmation
|
|
12
30
|
attribute :cabg_or_angioplasty, YearDatedConfirmation
|
|
@@ -23,6 +41,10 @@ module Renalware
|
|
|
23
41
|
attribute :non_coronary_intervention, YearDatedConfirmation
|
|
24
42
|
attribute :dementia, YearDatedConfirmation
|
|
25
43
|
attribute :smoking, SmokingStatus
|
|
44
|
+
|
|
45
|
+
def self.snomed_code_for(att)
|
|
46
|
+
SMOMED_MAP[att]
|
|
47
|
+
end
|
|
26
48
|
end
|
|
27
49
|
attribute :comorbidities, Comorbidities
|
|
28
50
|
end
|
|
@@ -8,6 +8,7 @@ module Renalware
|
|
|
8
8
|
class ProfileDocument < Document::Embedded
|
|
9
9
|
attribute :hiv, YearDatedDiagnosis
|
|
10
10
|
attribute :hepatitis_b, YearDatedDiagnosis
|
|
11
|
+
attribute :hepatitis_b_core_antibody, YearDatedDiagnosis
|
|
11
12
|
attribute :hepatitis_c, YearDatedDiagnosis
|
|
12
13
|
attribute :htlv, YearDatedDiagnosis
|
|
13
14
|
end
|
|
@@ -13,13 +13,11 @@ module Renalware
|
|
|
13
13
|
|
|
14
14
|
def perform(file)
|
|
15
15
|
logging_to_stringio(strio = StringIO.new)
|
|
16
|
-
log "Before upload there are #{practice_membership_count}
|
|
17
|
-
"#{inactive_practice_membership_count} inactive practice memberships"
|
|
16
|
+
log "Before upload there are #{practice_membership_count} practice memberships"
|
|
18
17
|
file.update!(status: :processing, attempts: file.attempts + 1)
|
|
19
18
|
status = :success
|
|
20
19
|
elapsed_ms = Benchmark.ms { process_archive(file.location) }
|
|
21
|
-
log "After upload there are #{practice_membership_count}
|
|
22
|
-
"#{inactive_practice_membership_count} inactive practice memberships"
|
|
20
|
+
log "After upload there are #{practice_membership_count} practice memberships"
|
|
23
21
|
rescue StandardError => e
|
|
24
22
|
Rails.logger.error(formatted_exception(e))
|
|
25
23
|
status = :failure
|
|
@@ -40,10 +38,6 @@ module Renalware
|
|
|
40
38
|
def practice_membership_count
|
|
41
39
|
Patients::PracticeMembership.count
|
|
42
40
|
end
|
|
43
|
-
|
|
44
|
-
def inactive_practice_membership_count
|
|
45
|
-
Patients::PracticeMembership.deleted.count
|
|
46
|
-
end
|
|
47
41
|
end
|
|
48
42
|
end
|
|
49
43
|
end
|
|
@@ -11,13 +11,13 @@ module Renalware
|
|
|
11
11
|
pattr_initialize :csv_path
|
|
12
12
|
|
|
13
13
|
def call
|
|
14
|
-
|
|
14
|
+
import_gp_csv_using_sql_function
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
private
|
|
18
18
|
|
|
19
19
|
# See migration for SQL function definition
|
|
20
|
-
def
|
|
20
|
+
def import_gp_csv_using_sql_function
|
|
21
21
|
conn = ActiveRecord::Base.connection
|
|
22
22
|
conn.execute(
|
|
23
23
|
"SELECT renalware.import_gps_csv(#{conn.quote(csv_path.realpath.to_s)}::text)"
|
|
@@ -45,6 +45,8 @@ module Renalware
|
|
|
45
45
|
validates :blood_pressure, presence: true
|
|
46
46
|
validates :weight_measured, presence: true
|
|
47
47
|
validates :temperature_measured, presence: true
|
|
48
|
+
validates :respiratory_rate_measured, presence: true
|
|
49
|
+
validates :respiratory_rate, presence: { if: -> { respiratory_rate_measured&.yes? } }
|
|
48
50
|
validates :weight, presence: { if: -> { weight_measured&.yes? } }
|
|
49
51
|
validates :temperature, presence: { if: -> { temperature_measured&.yes? } }
|
|
50
52
|
validates :blood_pressure, "renalware/patients/blood_pressure_presence" => true
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "attr_extras"
|
|
4
|
+
|
|
5
|
+
module Renalware
|
|
6
|
+
module Patients
|
|
7
|
+
class LastSuccessfulPracticeSyncDateQuery
|
|
8
|
+
pattr_initialize :identifier
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
max_created_at&.to_date&.to_s
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def max_created_at
|
|
17
|
+
System::APILog
|
|
18
|
+
.where(
|
|
19
|
+
identifier: identifier,
|
|
20
|
+
dry_run: false,
|
|
21
|
+
status: Renalware::System::APILog::STATUS_DONE
|
|
22
|
+
)
|
|
23
|
+
.group(:identifier)
|
|
24
|
+
.maximum(:created_at)[identifier]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -5,8 +5,6 @@ require_dependency "renalware/patients"
|
|
|
5
5
|
module Renalware
|
|
6
6
|
module Patients
|
|
7
7
|
class Practice < ApplicationRecord
|
|
8
|
-
acts_as_paranoid
|
|
9
|
-
|
|
10
8
|
has_one :address, as: :addressable
|
|
11
9
|
has_many :practice_memberships, dependent: :restrict_with_exception
|
|
12
10
|
has_many :primary_care_physicians, through: :practice_memberships
|
|
@@ -13,12 +13,14 @@ module Renalware
|
|
|
13
13
|
return [] if search_term.blank?
|
|
14
14
|
|
|
15
15
|
term = "%#{search_term}%"
|
|
16
|
-
Practice.select(:id, :name)
|
|
16
|
+
Practice.select(:id, :name, :code)
|
|
17
17
|
.left_outer_joins(:address)
|
|
18
18
|
.includes(:address)
|
|
19
19
|
.where("patient_practices.name ILIKE ? "\
|
|
20
|
+
"OR patient_practices.code = ? " \
|
|
20
21
|
"OR addresses.street_1 ILIKE ? " \
|
|
21
|
-
"OR addresses.postcode ILIKE ?", term, term, term)
|
|
22
|
+
"OR addresses.postcode ILIKE ?", term, search_term, term, term)
|
|
23
|
+
.where(active: true)
|
|
22
24
|
.limit(50)
|
|
23
25
|
end
|
|
24
26
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_dependency "renalware/patients"
|
|
4
|
+
|
|
5
|
+
module Renalware
|
|
6
|
+
module Patients
|
|
7
|
+
class SyncGpsViaFileDownloadJob < ApplicationJob
|
|
8
|
+
ODS_DOWNLOADABLES = {
|
|
9
|
+
primary_care_physicians: {
|
|
10
|
+
url: "https://files.digital.nhs.uk/assets/ods/current/egpcur.zip",
|
|
11
|
+
filename: "egpcur.zip"
|
|
12
|
+
},
|
|
13
|
+
practice_memberships: {
|
|
14
|
+
url: "https://files.digital.nhs.uk/assets/ods/current/epracmem.zip",
|
|
15
|
+
filename: "epracmem.zip"
|
|
16
|
+
}
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
# Do not retry this job
|
|
20
|
+
discard_on(StandardError) do |_job, exception|
|
|
21
|
+
Renalware::Engine.exception_notifier.notify(exception)
|
|
22
|
+
Rails.logger.error exception
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Now we have brought practices up to date, update GPs and their membership in practices.
|
|
26
|
+
# Download the relevant zip file, save it as a Feeds::File (the zip file will be copied to
|
|
27
|
+
# the uploads dir) and kick off a sync job to import the data, which it does by unzipping
|
|
28
|
+
# the file, extracting the csv and using a PG function to upsert the contents.
|
|
29
|
+
# Note we cannot reliably use an aysnc job here as the order of execution of the 3 updates -
|
|
30
|
+
# practices, gps, practice memberships - is strict.
|
|
31
|
+
def perform
|
|
32
|
+
ODS_DOWNLOADABLES.each do |type, options|
|
|
33
|
+
# Download the ODS file to a temporary location
|
|
34
|
+
tmp_file = Rails.root.join("tmp").join(options[:filename])
|
|
35
|
+
`wget -O #{tmp_file} #{options[:url]}`
|
|
36
|
+
file = create_feed_file(type, tmp_file)
|
|
37
|
+
Renalware::Feeds::Files::ImportJobFactory.job_class_for(file.file_type).perform_now(file)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def create_feed_file(type, tmp_file)
|
|
44
|
+
Renalware::Feeds::Files::CreateFeedFile.call(
|
|
45
|
+
uploaded_file: tmp_file,
|
|
46
|
+
file_type: Renalware::Feeds::FileType.find_by(name: type),
|
|
47
|
+
user: Renalware::SystemUser.find
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|