his_emr_api_lab 2.3.2 → 2.3.4
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/app/jobs/lab/process_lab_result_job.rb +11 -1
- data/app/jobs/lab/void_order_job.rb +8 -0
- data/app/serializers/lab/lab_order_serializer.rb +1 -1
- data/app/services/lab/notification_service.rb +7 -1
- data/app/services/lab/orders_service.rb +31 -1
- data/app/services/lab/results_service.rb +18 -1
- data/lib/lab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf823a7706db9f2444ed694c9f58ea1c1851c9cf00de058bb6c980434e57b27a
|
|
4
|
+
data.tar.gz: 55ac7590a6cc36249ef8322b254844f3ada7ca891b45d00c3512ccfa2eee8ddc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b3efe1cf4d98acb7dd218866c331d384a7f4c0855fe2ad4475edc88e3c89799d74d479c4ca8159707eeb433a1cf985a8b98f847f2d3a6a66330af88b675343b
|
|
7
|
+
data.tar.gz: 51d757cdbaff73aa883332f8a0a17cc71cc117fd7812192b9c60b11506b16c8f4ba30c7a1850ee5bc49a56c531e93f912eca963519ee4251ad0edbb225ce716a
|
|
@@ -8,10 +8,20 @@ module Lab
|
|
|
8
8
|
def perform(results_obs_id, serializer, result_enter_by)
|
|
9
9
|
Rails.logger.info("Lab::ProcessLabResultJob: Processing result completion for #{serializer}")
|
|
10
10
|
# set location context for the job based on the order's encounter to ensure proper context for any operations performed in the job
|
|
11
|
-
results_obs = Lab::LabResult.unscoped.find(results_obs_id)
|
|
11
|
+
results_obs = Lab::LabResult.unscoped.includes(:test).find(results_obs_id)
|
|
12
12
|
encounter = Encounter.unscoped.find_by(encounter_id: results_obs.encounter_id)
|
|
13
13
|
Location.current = Location.find(encounter.location_id) if encounter&.location_id
|
|
14
14
|
Lab::ResultsService.process_result_completion(results_obs, serializer, result_enter_by)
|
|
15
|
+
|
|
16
|
+
# Publish notification that results have been processed
|
|
17
|
+
ActiveSupport::Notifications.instrument(
|
|
18
|
+
'lab.results_saved',
|
|
19
|
+
patient_id: results_obs.person_id,
|
|
20
|
+
order_id: results_obs.order_id,
|
|
21
|
+
result_id: results_obs.obs_id,
|
|
22
|
+
encounter_id: results_obs.encounter_id,
|
|
23
|
+
timestamp: Time.current
|
|
24
|
+
)
|
|
15
25
|
end
|
|
16
26
|
end
|
|
17
27
|
end
|
|
@@ -16,6 +16,14 @@ module Lab
|
|
|
16
16
|
|
|
17
17
|
worker = Lab::Lims::PushWorker.new(Lab::Lims::ApiFactory.create_api)
|
|
18
18
|
worker.push_order(order)
|
|
19
|
+
|
|
20
|
+
# Publish notification that order has been voided
|
|
21
|
+
ActiveSupport::Notifications.instrument(
|
|
22
|
+
'lab.order_voided',
|
|
23
|
+
patient_id: order.patient_id,
|
|
24
|
+
order_id: order.order_id,
|
|
25
|
+
timestamp: Time.current
|
|
26
|
+
)
|
|
19
27
|
end
|
|
20
28
|
end
|
|
21
29
|
end
|
|
@@ -18,7 +18,7 @@ module Lab
|
|
|
18
18
|
order_type_id: order.order_type_id,
|
|
19
19
|
order_id: order.order_id, # Deprecated: Link to :id
|
|
20
20
|
encounter_id: order.encounter_id,
|
|
21
|
-
visit_id: encounter&.visit_id,
|
|
21
|
+
**(Encounter.column_names.include?('visit_id') ? { visit_id: encounter&.visit_id } : {}),
|
|
22
22
|
order_date: order.start_date,
|
|
23
23
|
location_id: encounter&.location_id,
|
|
24
24
|
program_id: encounter&.program_id,
|
|
@@ -31,7 +31,13 @@ class Lab::NotificationService
|
|
|
31
31
|
return if alert_type != 'LIMS'
|
|
32
32
|
|
|
33
33
|
# Use unscoped to find user regardless of location context
|
|
34
|
-
lab =
|
|
34
|
+
lab = Lab::Lims::Utils.lab_user
|
|
35
|
+
|
|
36
|
+
unless lab
|
|
37
|
+
Rails.logger.warn('NotificationService: lab_daemon user not found, skipping notification creation')
|
|
38
|
+
return
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
ActiveRecord::Base.transaction do
|
|
36
42
|
alert = NotificationAlert.create!(text: alert_message.to_json, date_to_expire: Time.now + not_period.days,
|
|
37
43
|
creator: lab, changed_by: lab, date_created: Time.now)
|
|
@@ -50,6 +50,10 @@ module Lab
|
|
|
50
50
|
# reason_for_test_id: is a concept_id for a (standard) reason of why the test is being carried out
|
|
51
51
|
# requesting_clinician: Name of the clinician requesting the test (defaults to current user)
|
|
52
52
|
def order_test(order_params)
|
|
53
|
+
serialized_order = nil
|
|
54
|
+
order_id = nil
|
|
55
|
+
patient_id = nil
|
|
56
|
+
|
|
53
57
|
Order.transaction do
|
|
54
58
|
encounter = find_encounter(order_params)
|
|
55
59
|
if order_params[:accession_number].present? && check_tracking_number(order_params[:accession_number])
|
|
@@ -68,13 +72,29 @@ module Lab
|
|
|
68
72
|
# Reload order to include status trails and tests
|
|
69
73
|
order = Lab::LabOrder.prefetch_relationships.find(order.order_id)
|
|
70
74
|
|
|
71
|
-
Lab::LabOrderSerializer.serialize_order(
|
|
75
|
+
serialized_order = Lab::LabOrderSerializer.serialize_order(
|
|
72
76
|
order, requesting_clinician: add_requesting_clinician(order, order_params),
|
|
73
77
|
reason_for_test: add_reason_for_test(order, order_params),
|
|
74
78
|
target_lab: add_target_lab(order, order_params),
|
|
75
79
|
comment_to_fulfiller: add_comment_to_fulfiller(order, order_params)
|
|
76
80
|
)
|
|
81
|
+
|
|
82
|
+
# Store IDs for notification after transaction commits
|
|
83
|
+
order_id = order.order_id
|
|
84
|
+
patient_id = order.patient_id
|
|
77
85
|
end
|
|
86
|
+
|
|
87
|
+
# Publish notification AFTER transaction commits
|
|
88
|
+
# This ensures the order is visible in the database before rebuilding
|
|
89
|
+
ActiveSupport::Notifications.instrument(
|
|
90
|
+
'lab.order_created',
|
|
91
|
+
patient_id: patient_id,
|
|
92
|
+
order_id: order_id,
|
|
93
|
+
accession_number: serialized_order[:accession_number],
|
|
94
|
+
timestamp: Time.current
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
serialized_order
|
|
78
98
|
end
|
|
79
99
|
|
|
80
100
|
def attach_test_method(order, order_params)
|
|
@@ -153,6 +173,16 @@ module Lab
|
|
|
153
173
|
save_order_status_trail(order, order_params) if order_params['status']
|
|
154
174
|
end
|
|
155
175
|
create_rejection_notification(order_params) if order_params['status'] == 'test-rejected'
|
|
176
|
+
|
|
177
|
+
# Publish notification that order status has changed
|
|
178
|
+
ActiveSupport::Notifications.instrument(
|
|
179
|
+
'lab.order_status_changed',
|
|
180
|
+
patient_id: order.patient_id,
|
|
181
|
+
order_id: order.order_id,
|
|
182
|
+
new_status: order_params['status'],
|
|
183
|
+
tracking_number: order_params['tracking_number'],
|
|
184
|
+
timestamp: Time.current
|
|
185
|
+
)
|
|
156
186
|
end
|
|
157
187
|
|
|
158
188
|
def update_order_result(order_params)
|
|
@@ -46,21 +46,38 @@ module Lab
|
|
|
46
46
|
ProcessLabResultJob.perform_now(results_obs.id, serializer, result_enter_by)
|
|
47
47
|
|
|
48
48
|
Rails.logger.info("Lab::ResultsService: Result created for test #{test_id} #{serializer}")
|
|
49
|
+
|
|
50
|
+
# Publish notification that results have been created
|
|
51
|
+
ActiveSupport::Notifications.instrument(
|
|
52
|
+
'lab.results_created',
|
|
53
|
+
patient_id: results_obs.person_id,
|
|
54
|
+
order_id: results_obs.order_id,
|
|
55
|
+
result_id: results_obs.obs_id,
|
|
56
|
+
test_id: test_id,
|
|
57
|
+
timestamp: Time.current
|
|
58
|
+
)
|
|
59
|
+
|
|
49
60
|
serializer
|
|
50
61
|
end
|
|
51
62
|
|
|
52
63
|
def process_result_completion(results_obs, serializer, result_enter_by)
|
|
53
64
|
process_acknowledgement(results_obs, result_enter_by)
|
|
54
65
|
precess_notification_message(results_obs, serializer, result_enter_by)
|
|
66
|
+
rescue StandardError => e
|
|
67
|
+
Rails.logger.error("Lab::ResultsService: Error in post-result processing: #{e.message}")
|
|
68
|
+
Rails.logger.error(e.backtrace.join("\n"))
|
|
69
|
+
# Don't re-raise - result is already saved
|
|
55
70
|
end
|
|
56
71
|
|
|
57
72
|
private
|
|
58
73
|
|
|
59
74
|
def precess_notification_message(result, values, result_enter_by)
|
|
60
75
|
order = Order.find(result.order_id)
|
|
76
|
+
test_concept_id = result.test&.value_coded
|
|
77
|
+
|
|
61
78
|
data = { Type: result_enter_by,
|
|
62
79
|
Specimen: get_test_catalog_name(order.concept_id) || ConceptName.find_by(concept_id: order.concept_id)&.name,
|
|
63
|
-
'Test type': get_test_catalog_name(
|
|
80
|
+
'Test type': test_concept_id ? (get_test_catalog_name(test_concept_id) || ConceptName.find_by(concept_id: test_concept_id)&.name) : nil,
|
|
64
81
|
'Accession number': order&.accession_number,
|
|
65
82
|
order_date: Order.columns.include?('start_date') ? order.start_date : order.date_created,
|
|
66
83
|
'ARV-Number': find_arv_number(result.person_id),
|
data/lib/lab/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: his_emr_api_lab
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.
|
|
4
|
+
version: 2.3.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elizabeth Glaser Pediatric Foundation Malawi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: couchrest
|