renalware-core 2.0.0.pre.rc1 → 2.0.0.pre.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/renalware/modules/_dashboard.scss +5 -4
- data/app/controllers/renalware/admin/users_controller.rb +6 -2
- data/app/controllers/renalware/admissions/consults_controller.rb +1 -1
- data/app/controllers/renalware/letters/contacts_controller.rb +4 -1
- data/app/controllers/renalware/pathology/current_observation_results_controller.rb +5 -11
- data/app/controllers/renalware/research/study_participants_controller.rb +1 -1
- data/app/helpers/renalware/dashboards_helper.rb +10 -0
- data/app/helpers/renalware/layout_helper.rb +3 -1
- data/app/models/concerns/renalware/letters/letter_pathology.rb +20 -0
- data/app/models/concerns/renalware/patient_pathology_scopes.rb +15 -7
- data/app/models/renalware/admissions/consult.rb +4 -3
- data/app/models/renalware/admissions/consult_site.rb +9 -0
- data/app/models/renalware/hd/mdm_patients_query.rb +2 -1
- data/app/models/renalware/letters/draft_letter.rb +2 -1
- data/app/models/renalware/letters/letter.rb +1 -0
- data/app/models/renalware/letters/part/recent_pathology_results.rb +2 -16
- data/app/models/renalware/letters/revise_letter.rb +2 -0
- data/app/models/renalware/pathology/{current_key_observation_set.rb → current_key_observation_set.rb.dead} +0 -0
- data/app/models/renalware/pathology/current_observation_set.rb +35 -0
- data/app/models/renalware/pathology/message_listener.rb +5 -3
- data/app/models/renalware/pathology/message_param_parser.rb +35 -10
- data/app/models/renalware/pathology/observation.rb +1 -1
- data/app/models/renalware/pathology/observation_request.rb +4 -1
- data/app/models/renalware/pathology/observations_jsonb_serializer.rb +73 -0
- data/app/models/renalware/pathology/patient.rb +4 -0
- data/app/models/renalware/pathology/update_current_observations.rb.dead +25 -0
- data/app/models/renalware/patient.rb +1 -1
- data/app/models/renalware/patients/mdm_patients_query.rb +4 -8
- data/app/models/renalware/pd/mdm_patients_query.rb +4 -8
- data/app/models/renalware/renal/low_clearance/mdm_patients_query.rb +5 -4
- data/app/models/renalware/transplants/mdm_patients_query.rb +4 -1
- data/app/presenters/renalware/admissions/consult_presenter.rb +6 -2
- data/app/presenters/renalware/dashboard/dashboard_presenter.rb +0 -4
- data/app/presenters/renalware/hd/patient_presenter.rb +6 -0
- data/app/presenters/renalware/mdm_patient_presenter.rb +6 -10
- data/app/presenters/renalware/pathology/{current_observation_results/html_table_view.rb → current_observation_results.dead/html_table_view.rb.dead} +0 -0
- data/app/presenters/renalware/pathology/{current_observation_results/presenter.rb → current_observation_results.dead/presenter.rb.dead} +0 -0
- data/app/presenters/renalware/pathology/observation_set_presenter.rb +57 -0
- data/app/presenters/renalware/pathology/observations_diff.rb +97 -77
- data/app/presenters/renalware/pathology/patient_presenter.rb +0 -4
- data/app/presenters/renalware/renal/clinical_summary_presenter.rb +1 -1
- data/app/views/renalware/admin/users/_filters.html.slim +19 -0
- data/app/views/renalware/admin/users/index.html.slim +9 -12
- data/app/views/renalware/admissions/consults/_filters.html.slim +2 -2
- data/app/views/renalware/admissions/consults/_form.html.slim +13 -53
- data/app/views/renalware/admissions/consults/_table.html.slim +3 -3
- data/app/views/renalware/dashboard/dashboards/show.html.slim +1 -1
- data/app/views/renalware/hd/mdm_patients/_patient.html.slim +2 -2
- data/app/views/renalware/letters/letters/_pathology.html.slim +2 -2
- data/app/views/renalware/letters/parts/_recent_pathology_results.html.slim +3 -3
- data/app/views/renalware/mdm_patients/_patient.html.slim +7 -7
- data/app/views/renalware/pathology/current_observation_results/index.html.slim +12 -1
- data/app/views/renalware/pathology/observations/_diff.html.slim +26 -20
- data/config/initializers/core_extensions.rb +2 -0
- data/config/locales/renalware/admissions/consults.en.yml +9 -0
- data/config/locales/renalware/dashboard/dashboard.yml +1 -1
- data/config/locales/renalware/patient.yml +0 -1
- data/db/migrate/20171204112150_create_consult_sites.rb +14 -0
- data/db/migrate/20171211161400_create_pathology_current_table.rb +19 -0
- data/db/migrate/20171213111513_create_fn_to_refresh_current_obs.rb +50 -0
- data/db/migrate/20171214141335_create_trigger_to_update_current_observation_sets.rb +111 -0
- data/db/migrate/20171214190849_enforce_request_id_on_observations.rb +5 -0
- data/db/migrate/20171215122454_add_pathology_observation_set_to_letters.rb +10 -0
- data/lib/core_extensions/hash.rb +11 -0
- data/lib/renalware/version.rb +1 -1
- data/spec/factories/admissions/consult_sites.rb +6 -0
- data/spec/factories/admissions/consults.rb +1 -1
- metadata +21 -5
@@ -0,0 +1,111 @@
|
|
1
|
+
class CreateTriggerToUpdateCurrentObservationSets < ActiveRecord::Migration[5.1]
|
2
|
+
def up
|
3
|
+
sql = <<-SQL
|
4
|
+
CREATE OR REPLACE FUNCTION update_current_observation_set_from_trigger() RETURNS TRIGGER AS $body$
|
5
|
+
-- TC 14/12/2017
|
6
|
+
-- This function is called by a trigger when a row is inserted or updated in
|
7
|
+
-- pathology_observations. Its purpose is to keep current_observation_sets up to date
|
8
|
+
-- with the latest observations for any patient.
|
9
|
+
-- The current_observation_sets table maintains a jsonb hash into which we insert or replace
|
10
|
+
-- the observation, keyed by OBX code.
|
11
|
+
-- e.g. .. {"HGB": { "result": 123.1, "observed_at": '2017-12-12-01:01:01'}, ..
|
12
|
+
DECLARE
|
13
|
+
a_patient_id bigint;
|
14
|
+
a_code text;
|
15
|
+
current_observed_at timestamp;
|
16
|
+
current_result text;
|
17
|
+
new_observed_at timestamp;
|
18
|
+
BEGIN
|
19
|
+
RAISE NOTICE 'TRIGGER called on %',TG_TABLE_NAME ;
|
20
|
+
|
21
|
+
/*
|
22
|
+
If inserting or updating, we _could_ assume the last observation to be inserted is
|
23
|
+
the most 'recent' one (with the latest observed_at date).
|
24
|
+
However the order of incoming messages is not guaranteed, so we have two options:
|
25
|
+
1. Refresh the entire current_observation_set for the patient
|
26
|
+
2. Check the current observed_at date in the jsonb and only update if we have a more
|
27
|
+
recent one
|
28
|
+
We have gone for 2.
|
29
|
+
*/
|
30
|
+
|
31
|
+
IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE') THEN
|
32
|
+
|
33
|
+
-- Note we could re-generate the entire current pathology for the patient using
|
34
|
+
-- select refresh_current_observation_set(a_patient_id);
|
35
|
+
-- which is safer but uses more resources, so avoiding this for now.
|
36
|
+
|
37
|
+
-- Find and store patient_id into local variable
|
38
|
+
select request.patient_id into a_patient_id
|
39
|
+
from pathology_observation_requests request
|
40
|
+
where request.id = NEW.request_id;
|
41
|
+
|
42
|
+
-- Find and store the obx code into local variable
|
43
|
+
select description.code into a_code
|
44
|
+
from pathology_observation_descriptions description
|
45
|
+
where description.id = NEW.description_id;
|
46
|
+
|
47
|
+
-- Important! Create the observation_set if it doesn exist yet
|
48
|
+
-- ignore the error id the row already exists
|
49
|
+
insert into pathology_current_observation_sets (patient_id)
|
50
|
+
values (a_patient_id)
|
51
|
+
ON CONFLICT DO NOTHING;
|
52
|
+
|
53
|
+
-- We are going to compare the current and new observed_at dates
|
54
|
+
-- so need to cast them to a timestamp
|
55
|
+
select cast(New.observed_at as timestamp) into new_observed_at;
|
56
|
+
|
57
|
+
-- Get the most recent date and value for this observation
|
58
|
+
-- and store to variables.
|
59
|
+
select
|
60
|
+
cast(values -> a_code ->> 'observed_at' as timestamp),
|
61
|
+
values -> a_code ->> 'result'
|
62
|
+
into current_observed_at, current_result from
|
63
|
+
pathology_current_observation_sets
|
64
|
+
where patient_id = a_patient_id;
|
65
|
+
|
66
|
+
-- Output some info to helps us debug. This can be removed later.
|
67
|
+
RAISE NOTICE ' Request id % Patient id % Code %', NEW.request_id, a_patient_id, a_code;
|
68
|
+
RAISE NOTICE ' Last %: % at %', a_code, current_result, current_observed_at;
|
69
|
+
RAISE NOTICE ' New %: % at %', a_code, NEW.result, new_observed_at;
|
70
|
+
|
71
|
+
IF current_observed_at IS NULL OR new_observed_at >= current_observed_at THEN
|
72
|
+
-- The new pathology_observation row contain a more recent result that the old one.
|
73
|
+
-- (note there may not be an old one if the patient has neve had this obs before).
|
74
|
+
|
75
|
+
RAISE NOTICE ' Updating pathology_current_observation_sets..';
|
76
|
+
|
77
|
+
-- Update the values jsonb column with the new hash for this code, e.g.
|
78
|
+
-- .. {"HGB": { "result": 123.1, "observed_at": '2017-12-12-01:01:01'}, ..
|
79
|
+
-- Note the `set values` below actually reads in the jsonb, updates it,
|
80
|
+
-- and wites the whole thing back.
|
81
|
+
update pathology_current_observation_sets
|
82
|
+
set values = jsonb_set(
|
83
|
+
values,
|
84
|
+
('{'||a_code||'}')::text[], -- defined in the fn path::text[]
|
85
|
+
jsonb_build_object('result', NEW.result, 'observed_at', new_observed_at),
|
86
|
+
true)
|
87
|
+
where patient_id = a_patient_id;
|
88
|
+
END IF;
|
89
|
+
END IF;
|
90
|
+
RETURN NULL ;
|
91
|
+
END $body$ LANGUAGE plpgsql VOLATILE COST 100;
|
92
|
+
-- End function
|
93
|
+
|
94
|
+
-- Create the trigger which will call out function every time a row in pathology_observations
|
95
|
+
-- is inserted or updated
|
96
|
+
DROP TRIGGER IF EXISTS update_current_observation_set_trigger ON pathology_observations;
|
97
|
+
CREATE TRIGGER update_current_observation_set_trigger
|
98
|
+
AFTER INSERT OR UPDATE
|
99
|
+
ON pathology_observations
|
100
|
+
FOR EACH ROW EXECUTE PROCEDURE update_current_observation_set_from_trigger();
|
101
|
+
SQL
|
102
|
+
ActiveRecord::Base.connection.execute(sql)
|
103
|
+
end
|
104
|
+
|
105
|
+
def down
|
106
|
+
ActiveRecord::Base.connection.execute("
|
107
|
+
DROP TRIGGER IF EXISTS update_current_observation_set_trigger ON pathology_observations;
|
108
|
+
DROP FUNCTION IF EXISTS update_current_observation_set_from_trigger();
|
109
|
+
")
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Recursively covert a nested hash into nested OpenStructs
|
2
|
+
# See https://coderwall.com/p/74rajw/convert-a-complex-nested-hash-to-an-object
|
3
|
+
module CoreExtensions
|
4
|
+
module Hash
|
5
|
+
module OpenStructConversion
|
6
|
+
def to_o
|
7
|
+
JSON.parse to_json, object_class: OpenStruct
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/renalware/version.rb
CHANGED
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.0.pre.
|
4
|
+
version: 2.0.0.pre.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airslie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -1152,6 +1152,7 @@ files:
|
|
1152
1152
|
- app/helpers/renalware/clinic_helper.rb
|
1153
1153
|
- app/helpers/renalware/clinical_helper.rb
|
1154
1154
|
- app/helpers/renalware/clipboard_helper.rb
|
1155
|
+
- app/helpers/renalware/dashboards_helper.rb
|
1155
1156
|
- app/helpers/renalware/definition_list_helper.rb
|
1156
1157
|
- app/helpers/renalware/devise_helper.rb
|
1157
1158
|
- app/helpers/renalware/dropdown_button_helper.rb
|
@@ -1207,6 +1208,7 @@ files:
|
|
1207
1208
|
- app/models/concerns/renalware/deviseable.rb
|
1208
1209
|
- app/models/concerns/renalware/explicit_state_model.rb
|
1209
1210
|
- app/models/concerns/renalware/hd/session_scopes.rb
|
1211
|
+
- app/models/concerns/renalware/letters/letter_pathology.rb
|
1210
1212
|
- app/models/concerns/renalware/modality_scopes.rb
|
1211
1213
|
- app/models/concerns/renalware/ordered_scope.rb
|
1212
1214
|
- app/models/concerns/renalware/ordered_set_scope.rb
|
@@ -1233,6 +1235,7 @@ files:
|
|
1233
1235
|
- app/models/renalware/admissions.rb
|
1234
1236
|
- app/models/renalware/admissions/consult.rb
|
1235
1237
|
- app/models/renalware/admissions/consult_query.rb
|
1238
|
+
- app/models/renalware/admissions/consult_site.rb
|
1236
1239
|
- app/models/renalware/admissions/request.rb
|
1237
1240
|
- app/models/renalware/admissions/request_reason.rb
|
1238
1241
|
- app/models/renalware/clinical.rb
|
@@ -1414,8 +1417,9 @@ files:
|
|
1414
1417
|
- app/models/renalware/pathology/clinic.rb
|
1415
1418
|
- app/models/renalware/pathology/consultant.rb
|
1416
1419
|
- app/models/renalware/pathology/create_observations.rb
|
1417
|
-
- app/models/renalware/pathology/current_key_observation_set.rb
|
1420
|
+
- app/models/renalware/pathology/current_key_observation_set.rb.dead
|
1418
1421
|
- app/models/renalware/pathology/current_observation.rb
|
1422
|
+
- app/models/renalware/pathology/current_observation_set.rb
|
1419
1423
|
- app/models/renalware/pathology/current_observations_for_descriptions_query.rb
|
1420
1424
|
- app/models/renalware/pathology/determine_observation_date_series.rb
|
1421
1425
|
- app/models/renalware/pathology/lab.rb
|
@@ -1430,6 +1434,7 @@ files:
|
|
1430
1434
|
- app/models/renalware/pathology/observation_for_patient_request_description_query.rb
|
1431
1435
|
- app/models/renalware/pathology/observation_request.rb
|
1432
1436
|
- app/models/renalware/pathology/observations_for_descriptions_query.rb
|
1437
|
+
- app/models/renalware/pathology/observations_jsonb_serializer.rb
|
1433
1438
|
- app/models/renalware/pathology/observations_within_date_range_query.rb
|
1434
1439
|
- app/models/renalware/pathology/ordered_patient_query.rb
|
1435
1440
|
- app/models/renalware/pathology/patient.rb
|
@@ -1473,6 +1478,7 @@ files:
|
|
1473
1478
|
- app/models/renalware/pathology/requests/request_query.rb
|
1474
1479
|
- app/models/renalware/pathology/requests/requests_factory.rb
|
1475
1480
|
- app/models/renalware/pathology/results.rb
|
1481
|
+
- app/models/renalware/pathology/update_current_observations.rb.dead
|
1476
1482
|
- app/models/renalware/pathology/view_current_observation_results.rb
|
1477
1483
|
- app/models/renalware/pathology/view_observation_results.rb
|
1478
1484
|
- app/models/renalware/patient.rb
|
@@ -1704,11 +1710,12 @@ files:
|
|
1704
1710
|
- app/presenters/renalware/medications/treatable_presenter.rb
|
1705
1711
|
- app/presenters/renalware/messaging/internal/message_presenter.rb
|
1706
1712
|
- app/presenters/renalware/messaging/internal/receipt_presenter.rb
|
1707
|
-
- app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
|
1708
|
-
- app/presenters/renalware/pathology/current_observation_results/presenter.rb
|
1713
|
+
- app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
|
1714
|
+
- app/presenters/renalware/pathology/current_observation_results.dead/presenter.rb.dead
|
1709
1715
|
- app/presenters/renalware/pathology/historical_observation_results/html_table_view.rb
|
1710
1716
|
- app/presenters/renalware/pathology/historical_observation_results/presenter.rb
|
1711
1717
|
- app/presenters/renalware/pathology/observation_presenter.rb
|
1718
|
+
- app/presenters/renalware/pathology/observation_set_presenter.rb
|
1712
1719
|
- app/presenters/renalware/pathology/observations_diff.rb
|
1713
1720
|
- app/presenters/renalware/pathology/observations_for_codes_presenter.rb
|
1714
1721
|
- app/presenters/renalware/pathology/patient_presenter.rb
|
@@ -1792,6 +1799,7 @@ files:
|
|
1792
1799
|
- app/views/renalware/addresses/_form.html.slim
|
1793
1800
|
- app/views/renalware/admin/user_mailer/approval.text.erb
|
1794
1801
|
- app/views/renalware/admin/user_mailer/unexpiry.text.erb
|
1802
|
+
- app/views/renalware/admin/users/_filters.html.slim
|
1795
1803
|
- app/views/renalware/admin/users/edit.html.slim
|
1796
1804
|
- app/views/renalware/admin/users/index.html.slim
|
1797
1805
|
- app/views/renalware/admissions/consults/_filters.html.slim
|
@@ -2912,9 +2920,15 @@ files:
|
|
2912
2920
|
- db/migrate/20171123143534_add_pk_to_drug_types_drugs.rb
|
2913
2921
|
- db/migrate/20171123154116_create_renal_versions.rb
|
2914
2922
|
- db/migrate/20171128163543_add_more_missing_indexes.rb
|
2923
|
+
- db/migrate/20171204112150_create_consult_sites.rb
|
2915
2924
|
- db/migrate/20171206121652_add_loinc_code_to_observation_descriptions.rb
|
2916
2925
|
- db/migrate/20171208211206_create_user_feedback.rb
|
2917
2926
|
- db/migrate/20171211130716_remove_unused_patients_cols.rb
|
2927
|
+
- db/migrate/20171211161400_create_pathology_current_table.rb
|
2928
|
+
- db/migrate/20171213111513_create_fn_to_refresh_current_obs.rb
|
2929
|
+
- db/migrate/20171214141335_create_trigger_to_update_current_observation_sets.rb
|
2930
|
+
- db/migrate/20171214190849_enforce_request_id_on_observations.rb
|
2931
|
+
- db/migrate/20171215122454_add_pathology_observation_set_to_letters.rb
|
2918
2932
|
- db/seeds.rb
|
2919
2933
|
- db/seeds/default/accesses/access_pd_catheter_insertion_techniques.csv
|
2920
2934
|
- db/seeds/default/accesses/access_pd_catheter_insertion_techniques.rb
|
@@ -3023,6 +3037,7 @@ files:
|
|
3023
3037
|
- lib/core_extensions/active_support/duration.rb
|
3024
3038
|
- lib/core_extensions/date.rb
|
3025
3039
|
- lib/core_extensions/dumb_delegator.rb
|
3040
|
+
- lib/core_extensions/hash.rb
|
3026
3041
|
- lib/core_extensions/i18n/always_cascade.rb
|
3027
3042
|
- lib/core_extensions/i18n/handle_blank_value.rb
|
3028
3043
|
- lib/core_extensions/scenic.rb
|
@@ -3069,6 +3084,7 @@ files:
|
|
3069
3084
|
- spec/factories/accesses/profiles.rb
|
3070
3085
|
- spec/factories/accesses/sites.rb
|
3071
3086
|
- spec/factories/accesses/types.rb
|
3087
|
+
- spec/factories/admissions/consult_sites.rb
|
3072
3088
|
- spec/factories/admissions/consults.rb
|
3073
3089
|
- spec/factories/admissions/request_reasons.rb
|
3074
3090
|
- spec/factories/admissions/requests.rb
|