his_emr_api_lab 2.3.3 → 2.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3873475c6cfd03e575f78f41fbf683f18c7dc7c9805727b7fe95c68bda0c9ad0
4
- data.tar.gz: 1ac84309c0eb67cc136b7e51c2254d45b64514c7a2cc605f7366cc73d33fcc59
3
+ metadata.gz: dc965d603f0266ab7897325bdf7342208fb136527c39b2b6d267269b79c2670c
4
+ data.tar.gz: 67b239f498c628d805d336df0b1ce1aa906969638046453640b57278dbdc3d1a
5
5
  SHA512:
6
- metadata.gz: d4a4106f2ace136bede102affbf76ba7d6d9d740711f401b53727349ff47f3bc781ad5b3f709e56b17c75dcb1f194a7e6fa4e2abaa3895ac6685f262afa62c53
7
- data.tar.gz: 04ac7da59794e253c10bab14a5002633c1b9f30e48e0a70338153af8020443bd75914400ef274edc469a5852862bfe03623f5be4664c564af29ada6782a9b1e0
6
+ metadata.gz: 1944e524aab65fa92c218339dd61e1edfd741b38c0525b8c89092d493dd77bfc1f450f5bbe51dca6b9896db402f32f7d38a2e0c90ba59eac04e257a82bbb5375
7
+ data.tar.gz: 33b215daa16a744b72ff9999ec71fcfbc211c21fad7cad8f73d540ec8eb9cf16183bdd1a4f90ee6a901847a89f0cba0f4d4326bb28383515105f2662805f232a
@@ -8,7 +8,7 @@ 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)
@@ -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,
@@ -117,8 +117,13 @@ module Lab
117
117
  # From the members above, filter out only those concepts that are result indicators
118
118
  measures = ConceptSet.find_members_by_name(Lab::Metadata::TEST_RESULT_INDICATOR_CONCEPT_NAME)
119
119
  .select(:concept_id)
120
+ # Get specimen types to exclude from results
121
+ specimen_types = ConceptSet.find_members_by_name(Lab::Metadata::SPECIMEN_TYPE_CONCEPT_NAME)
122
+ .select(:concept_id)
120
123
 
124
+ # Find concepts that are linked to the test type AND are measures (but NOT specimens)
121
125
  sets = ConceptSet.where(concept_set: test, concept_id: measures)
126
+ .where.not(concept_id: specimen_types)
122
127
 
123
128
  return ActiveRecord::Base.connection.select_all <<~SQL
124
129
  SELECT ca.concept_id, ca.value_reference as name, ca2.value_reference as nlims_code, c.uuid
@@ -82,6 +82,9 @@ module Lab
82
82
  unescaped_name = CGI.unescapeHTML(name)
83
83
  attribute_type_id = ConceptAttributeType.test_catalogue_name.concept_attribute_type_id
84
84
 
85
+ attribute = ConceptAttribute.where('attribute_type_id = ? AND value_reference = ?', attribute_type_id, unescaped_name).first
86
+ return attribute.concept if attribute
87
+
85
88
  ConceptName.joins('INNER JOIN concept_attribute ON concept_attribute.concept_id = concept_name.concept_id')
86
89
  .where('concept_attribute.attribute_type_id = ? AND concept_attribute.value_reference = ? AND concept_name.name = ?',
87
90
  attribute_type_id, unescaped_name, unescaped_name)
@@ -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 = User.unscoped.find_by(username: 'lab_daemon')
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)
@@ -63,15 +63,21 @@ module Lab
63
63
  def process_result_completion(results_obs, serializer, result_enter_by)
64
64
  process_acknowledgement(results_obs, result_enter_by)
65
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
66
70
  end
67
71
 
68
72
  private
69
73
 
70
74
  def precess_notification_message(result, values, result_enter_by)
71
75
  order = Order.find(result.order_id)
76
+ test_concept_id = result.test&.value_coded
77
+
72
78
  data = { Type: result_enter_by,
73
79
  Specimen: get_test_catalog_name(order.concept_id) || ConceptName.find_by(concept_id: order.concept_id)&.name,
74
- 'Test type': get_test_catalog_name(result.test.value_coded) || ConceptName.find_by(concept_id: result.test.value_coded)&.name,
80
+ 'Test type': test_concept_id ? (get_test_catalog_name(test_concept_id) || ConceptName.find_by(concept_id: test_concept_id)&.name) : nil,
75
81
  'Accession number': order&.accession_number,
76
82
  order_date: Order.columns.include?('start_date') ? order.start_date : order.date_created,
77
83
  'ARV-Number': find_arv_number(result.person_id),
data/lib/lab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lab
4
- VERSION = '2.3.3'
4
+ VERSION = '2.3.5'
5
5
  end
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.3
4
+ version: 2.3.5
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-04-07 00:00:00.000000000 Z
11
+ date: 2026-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest