his_emr_api_lab 2.5.0 → 2.5.1

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: 0ea18a06a50c6c0dfaded6e6911e0f9603cf2f9b8d1c4e81a476da3d8b8aba29
4
- data.tar.gz: b0991a42ac153666de1d4ce358226134e9804cfd93ba5a749c8030f364d5c2aa
3
+ metadata.gz: c1d2b63e22a684d77087a2aad3c2d1c227188b0b2e1b838969b168310db5a614
4
+ data.tar.gz: 43ff9bbf4c1f1d2dffe73e2331385401fe77f80562a3238a7ffd63309b1212fd
5
5
  SHA512:
6
- metadata.gz: c39da38186a7c15671704fb88981c4b8d76be7acddad44426b77c0b30ea88245ca4887d2cb79a787c04b4d7cf127498497be651c36ba25fe41b45490eeebff86
7
- data.tar.gz: 8c9469a31a9c6f5b82e7985b628f288178e7aaf9d6f4e4f24de70182267e23fad71659c2afc3e5308b33ed41ad89c48e2ec5dd3fde1eda4b1277712754264c7a
6
+ metadata.gz: fc9732083f82839c088453895f5fbdecee50be704584a4bcaf8a98e2bc475b6279c8b5a403432bc6abb54d5bdbf3f1346b996483f02b369df87e17d39b3e9ec2
7
+ data.tar.gz: 25269446cc1c3e1d00866f3304d06a90a8ce5c12c41c0a53892cf26c934395ea5fa9db825ceaf174af8ad8d688d47e301205f9cd4d756e5cbb32ad8c03253a86
@@ -100,64 +100,41 @@ module Lab
100
100
  Observation.unscoped.find_by(order_id: order.order_id, concept_id: concept, voided: 0)
101
101
  end
102
102
 
103
+ # The trail methods load the whole association (a handful of rows per
104
+ # order/test) and the "latest" methods take the last loaded row. Calling
105
+ # `.last` on an unloaded association instead issues
106
+ # `ORDER BY obs_datetime DESC, obs_id DESC LIMIT 1`, and with LIMIT 1 MySQL
107
+ # may walk an obs_datetime index (obs_datetime_idx / idx_obs_adherence_lookup)
108
+ # backwards across the whole obs table rather than use obs_order. Loading
109
+ # also caches the rows on the record, so the trail and the latest status
110
+ # share a single query.
103
111
  def self.latest_order_status(order)
104
- # Query obs table for latest order status
105
- latest_obs = order.status_trail_observations.last
106
- return nil unless latest_obs
107
-
108
- updated_by = parse_comments_json(latest_obs.comments)
109
-
110
- {
111
- status_id: 0, # status_id not used with text values
112
- status: latest_obs.value_text,
113
- timestamp: latest_obs.obs_datetime,
114
- updated_by: updated_by
115
- }
112
+ serialize_status_obs(order.status_trail_observations.to_a.last)
116
113
  end
117
114
 
118
115
  def self.serialize_order_status_trail(order)
119
- # Query obs table for order status trail
120
- order.status_trail_observations.map do |obs|
121
- updated_by = parse_comments_json(obs.comments)
122
-
123
- {
124
- status_id: 0, # status_id not used with text values
125
- status: obs.value_text,
126
- timestamp: obs.obs_datetime,
127
- updated_by: updated_by
128
- }
129
- end
116
+ order.status_trail_observations.to_a.map { |obs| serialize_status_obs(obs) }
130
117
  end
131
118
 
132
119
  def self.latest_test_status(test)
133
- # Query obs table for latest test status
134
- latest_obs = test.status_trail_observations.last
135
- return nil unless latest_obs
120
+ serialize_status_obs(test.status_trail_observations.to_a.last)
121
+ end
136
122
 
137
- updated_by = parse_comments_json(latest_obs.comments)
123
+ def self.serialize_test_status_trail(test)
124
+ test.status_trail_observations.to_a.map { |obs| serialize_status_obs(obs) }
125
+ end
126
+
127
+ def self.serialize_status_obs(obs)
128
+ return nil unless obs
138
129
 
139
130
  {
140
131
  status_id: 0, # status_id not used with text values
141
- status: latest_obs.value_text,
142
- timestamp: latest_obs.obs_datetime,
143
- updated_by: updated_by
132
+ status: obs.value_text,
133
+ timestamp: obs.obs_datetime,
134
+ updated_by: parse_comments_json(obs.comments)
144
135
  }
145
136
  end
146
137
 
147
- def self.serialize_test_status_trail(test)
148
- # Query obs table for test status trail
149
- test.status_trail_observations.map do |obs|
150
- updated_by = parse_comments_json(obs.comments)
151
-
152
- {
153
- status_id: 0, # status_id not used with text values
154
- status: obs.value_text,
155
- timestamp: obs.obs_datetime,
156
- updated_by: updated_by
157
- }
158
- end
159
- end
160
-
161
138
  # Helper to parse updated_by from obs comments field
162
139
  def self.parse_comments_json(comments)
163
140
  return {} if comments.blank?
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.5.0'.freeze
4
+ VERSION = '2.5.1'.freeze
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.5.0
4
+ version: 2.5.1
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-03 00:00:00.000000000 Z
11
+ date: 2026-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest