mahis_emr_api_lab 1.2.3 → 1.2.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: 9ea6fe4728c370e41a0e916119b766d0c9958623cd39c8c96ad5fd1d825af7ef
4
- data.tar.gz: 64b3cd907fc28f430c1bd203b4226214bafdb4ab6f4a7d3913de6086efcdafb8
3
+ metadata.gz: 0b93353e9b867677abd45317e32291dcbd53d68e328cb2ac7cc2e294d719b71f
4
+ data.tar.gz: 22fcdf2407609885b81df63de7be75ff20156f6b0b6d8de6a6eb8974d54915ae
5
5
  SHA512:
6
- metadata.gz: b404b558028886e53503bcaf55f34befda732e2fb6abd401611f8f453d63c9ec37c0dc02b74ecca14dee1359d072f0ffb738962d2a3ecdecb5122fbd1de5d461
7
- data.tar.gz: 0e9dfb9a29a79f6dc96dc0956ec2a7872b607874a77fea69bb19cc34e169210ecd4d5a358790b9beb530dd6fd563d52acef2f7a30a70977d9f525fe0019f80b6
6
+ metadata.gz: e95ee315519fcf1d77d9b337b449921c05489cf7842bf2f74e730f61fd298233aba7b87c0a819b6bcac9f39c58c87703c5ed76a9b7b1f31b60573d3fcceb8b14
7
+ data.tar.gz: 3326b887701a0fdf285bb37f2a2daa56500f4b81875080cb711bc25b046370e94c6e198c837e7521415b69ccc0cbfe01cb0c18096e09196f2b79468eaf15fbba
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Lab
4
4
  class LabelsController < ApplicationController
5
- skip_before_action :authenticate
5
+ _callbacks = _process_action_callbacks.map(&:filter)
6
+ skip_before_action :authenticate if _callbacks.include?(:authenticate)
6
7
 
7
8
  def print_order_label
8
9
  order_id = params.require(:order_id)
@@ -3,7 +3,8 @@
3
3
  # This controller handles creation and authentication of LIMS User
4
4
  module Lab
5
5
  class UsersController < ::ApplicationController
6
- skip_before_action :authenticate
6
+ _callbacks = _process_action_callbacks.map(&:filter)
7
+ skip_before_action :authenticate if _callbacks.include?(:authenticate)
7
8
  # create a LIMS User that will be responsible for sending lab results
8
9
  def create
9
10
  user_params = params.permit(:username, :password)
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Lab
4
4
  class LabResult < Observation
5
+ def children
6
+ Observation.where(obs_group_id: obs_id, voided: 0)
7
+ end
8
+
5
9
  alias measures children
6
10
 
7
11
  default_scope do
@@ -33,7 +33,7 @@ module Lab
33
33
  bum.binge_changes(since: from, limit: limit, include_docs: true) do |change|
34
34
  next unless change['doc']['type']&.casecmp?('Order')
35
35
 
36
- yield OrderDTO.new(change['doc']), self
36
+ yield OrderDto.new(change['doc']), self
37
37
  end
38
38
  end
39
39
 
@@ -162,7 +162,7 @@ module Lab
162
162
  drawn_by_first_name, drawn_by_last_name = specimen['drawn_by_name']&.split
163
163
  patient_first_name, patient_last_name = patient['name'].split
164
164
 
165
- OrderDTO.new(
165
+ OrderDto.new(
166
166
  _id: specimen['doc_id'].blank? ? SecureRandom.uuid : specimen['doc_id'],
167
167
  _rev: '0',
168
168
  tracking_number: specimen['tracking_number'],
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rest-client'
3
4
 
4
5
  class Lab::Lims::Api::RestApi
@@ -8,6 +9,8 @@ class Lab::Lims::Api::RestApi
8
9
 
9
10
  class InvalidParameters < LimsApiError; end
10
11
 
12
+ START_DATE = Time.parse('2024-09-03').freeze
13
+
11
14
  def initialize(config)
12
15
  @config = config
13
16
  end
@@ -195,7 +198,7 @@ class Lab::Lims::Api::RestApi
195
198
  end
196
199
 
197
200
  ##
198
- # Converts an OrderDTO to parameters for POST /create_order
201
+ # Converts an OrderDto to parameters for POST /create_order
199
202
  def make_create_params(order_dto)
200
203
  {
201
204
  tracking_number: order_dto.fetch(:tracking_number),
@@ -224,7 +227,7 @@ class Lab::Lims::Api::RestApi
224
227
  end
225
228
 
226
229
  ##
227
- # Converts an OrderDTO to parameters for POST /update_order
230
+ # Converts an OrderDto to parameters for POST /update_order
228
231
  def make_update_params(order_dto)
229
232
  date_updated, status = sample_drawn_status(order_dto)
230
233
 
@@ -240,7 +243,7 @@ class Lab::Lims::Api::RestApi
240
243
  def current_district
241
244
  health_centre = Location.current_health_center
242
245
  raise 'Current health centre not set' unless health_centre
243
-
246
+
244
247
  district = health_centre.district || Lab::Lims::Config.application['district']
245
248
 
246
249
  unless district
@@ -252,7 +255,7 @@ class Lab::Lims::Api::RestApi
252
255
  end
253
256
 
254
257
  ##
255
- # Extracts sample drawn status from an OrderDTO
258
+ # Extracts sample drawn status from an OrderDto
256
259
  def sample_drawn_status(order_dto)
257
260
  order_dto[:sample_statuses].each do |trail_entry|
258
261
  date, status = trail_entry.each_pair.find { |_date, status| status['status'].casecmp?('Drawn') }
@@ -265,13 +268,13 @@ class Lab::Lims::Api::RestApi
265
268
  end
266
269
 
267
270
  ##
268
- # Extracts a sample drawn date from a LIMS OrderDTO.
271
+ # Extracts a sample drawn date from a LIMS OrderDto.
269
272
  def sample_drawn_date(order_dto)
270
273
  sample_drawn_status(order_dto).first
271
274
  end
272
275
 
273
276
  ##
274
- # Extracts the requesting clinician from a LIMS OrderDTO
277
+ # Extracts the requesting clinician from a LIMS OrderDto
275
278
  def requesting_clinician(order_dto)
276
279
  orderer = order_dto[:who_order_test]
277
280
 
@@ -406,7 +409,7 @@ class Lab::Lims::Api::RestApi
406
409
  Rails.logger.debug('Looking for orders without a specimen')
407
410
  unknown_specimen = ConceptName.where(name: Lab::Metadata::UNKNOWN_SPECIMEN)
408
411
  .select(:concept_id)
409
- orders = Lab::LabOrder.where(concept_id: unknown_specimen)
412
+ orders = Lab::LabOrder.where(concept_id: unknown_specimen, date_created: START_DATE..(Date.today + 1.day))
410
413
  .where.not(accession_number: Lab::LimsOrderMapping.select(:lims_id))
411
414
  orders = orders.where(patient_id: patient_id) if patient_id
412
415
 
@@ -418,16 +421,17 @@ class Lab::Lims::Api::RestApi
418
421
  # Lab::OrdersSearchService.find_orders_without_results(patient_id: patient_id)
419
422
  # .where.not(accession_number: Lab::LimsOrderMapping.select(:lims_id).where("pulled_at IS NULL"))
420
423
  Lab::OrdersSearchService.find_orders_without_results(patient_id: patient_id)
421
- .where(order_id: Lab::LimsOrderMapping.select(:order_id))
424
+ .where(order_id: Lab::LimsOrderMapping.select(:order_id), date_created: START_DATE..(Date.today + 1.day))
422
425
  end
423
426
 
424
427
  def orders_without_reason(patient_id = nil)
425
428
  Rails.logger.debug('Looking for orders without a reason for test')
426
429
  orders = Lab::LabOrder.joins(:reason_for_test)
427
430
  .merge(Observation.where(value_coded: nil, value_text: nil))
431
+ .where(date_created: START_DATE..(Date.today + 1.day))
428
432
  .limit(1000)
429
433
  .where.not(accession_number: Lab::LimsOrderMapping.select(:lims_id))
430
- orders = orders.where(patient_id: patient_id) if patient_id
434
+ orders = orders.where(patient_id: patient_id, date_created: START_DATE..(Date.today + 1.day)) if patient_id
431
435
 
432
436
  orders
433
437
  end
@@ -2,10 +2,12 @@
2
2
 
3
3
  module Lab
4
4
  module Lims
5
- class LimsException < StandardError; end
6
- class DuplicateNHID < LimsException; end
7
- class MissingAccessionNumber < LimsException; end
8
- class UnknownSpecimenType < LimsException; end
9
- class UnknownTestType < LimsException; end
5
+ module Exceptions
6
+ class LimsException < StandardError; end
7
+ class DuplicateNHID < LimsException; end
8
+ class MissingAccessionNumber < LimsException; end
9
+ class UnknownSpecimenType < LimsException; end
10
+ class UnknownTestType < LimsException; end
11
+ end
10
12
  end
11
13
  end
@@ -29,7 +29,7 @@ require 'lab/lab_test'
29
29
  require 'lab/lims_order_mapping'
30
30
  require 'lab/lims_failed_import'
31
31
 
32
- require_relative './api/couchdb_api'
32
+ require_relative './api/couch_db_api'
33
33
  require_relative './config'
34
34
  require_relative './pull_worker'
35
35
  require_relative './utils'
@@ -82,7 +82,7 @@ module Lab
82
82
  next unless row['doc']['type']&.casecmp?('Order')
83
83
 
84
84
  User.current = Utils.lab_user
85
- yield OrderDTO.new(row['doc']), OpenStruct.new(last_seq: (from || 0) + limit, current_seq: from)
85
+ yield OrderDto.new(row['doc']), OpenStruct.new(last_seq: (from || 0) + limit, current_seq: from)
86
86
  end
87
87
 
88
88
  from += orders.size
@@ -6,7 +6,7 @@ module Lab
6
6
  module Lims
7
7
  ##
8
8
  # LIMS' Data Transfer Object for orders
9
- class OrderDTO < ActiveSupport::HashWithIndifferentAccess
9
+ class OrderDto < ActiveSupport::HashWithIndifferentAccess
10
10
  include Utils
11
11
 
12
12
  ##
@@ -7,14 +7,14 @@ require_relative './utils'
7
7
  module Lab
8
8
  module Lims
9
9
  ##
10
- # Serializes a LabOrder into a LIMS OrderDTO.
10
+ # Serializes a LabOrder into a LIMS OrderDto.
11
11
  module OrderSerializer
12
12
  class << self
13
13
  include Utils
14
14
 
15
15
  def serialize_order(order)
16
16
  serialized_order = Lims::Utils.structify(Lab::LabOrderSerializer.serialize_order(order))
17
- Lims::OrderDTO.new(
17
+ Lims::OrderDto.new(
18
18
  _id: Lab::LimsOrderMapping.find_by(order: order)&.lims_id || serialized_order.accession_number,
19
19
  tracking_number: serialized_order.accession_number,
20
20
  sending_facility: current_facility_name,
@@ -214,7 +214,7 @@ module Lab
214
214
  end
215
215
 
216
216
  next if test.result || test_results['results'].blank?
217
-
217
+
218
218
  result_date = Time.now
219
219
  measures = test_results['results'].map do |indicator, value|
220
220
  measure = find_measure(order, indicator, value)
@@ -10,6 +10,7 @@ module Lab
10
10
  include Utils # for logger
11
11
 
12
12
  SECONDS_TO_WAIT_FOR_ORDERS = 30
13
+ START_DATE = Time.parse('2024-09-03').freeze
13
14
 
14
15
  def initialize(lims_api)
15
16
  @lims_api = lims_api
@@ -23,7 +24,7 @@ module Lab
23
24
  logger.debug("Found #{orders.size} orders...")
24
25
  orders.each do |order|
25
26
  push_order(order)
26
- rescue GatewayError => e
27
+ rescue StandardError => e
27
28
  logger.error("Failed to push order ##{order.accession_number}: #{e.class} - #{e.message}")
28
29
  rescue StandardError => e
29
30
  logger.error("Failed to push order ##{order.id}: #{order&.accession_number} : #{e.class} - #{e.message}")
@@ -94,6 +95,7 @@ module Lab
94
95
  Rails.logger.debug('Looking for new orders that need to be created in LIMS...')
95
96
  Lab::LabOrder.where.not(order_id: Lab::LimsOrderMapping.all.select(:order_id))
96
97
  .where("accession_number IS NOT NULL AND accession_number !=''")
98
+ .where(date_created: START_DATE..(Date.today + 1.day))
97
99
  .order(date_created: :desc)
98
100
  end
99
101
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'logger_multiplexor'
4
4
 
5
- require_relative './api/couchdb_api'
5
+ require_relative './api/couch_db_api'
6
6
 
7
7
  module Lab
8
8
  module Lims
@@ -148,8 +148,7 @@ module Lab
148
148
  'arv_number': find_arv_number(order.patient_id),
149
149
  'patient_id': result.person_id,
150
150
  'ordered_by': order&.provider&.person&.name,
151
- 'rejection_reason': order_params['comments']
152
- }.as_json
151
+ 'rejection_reason': order_params['comments'] }.as_json
153
152
  NotificationService.new.create_notification('LIMS', data)
154
153
  end
155
154
 
@@ -197,7 +196,6 @@ module Lab
197
196
  return Encounter.find(encounter_id) if order_params[:encounter] || order_params[:encounter_id]
198
197
  raise StandardError, 'encounter_id|uuid or patient_id|uuid required' unless order_params[:patient]
199
198
 
200
-
201
199
  encounter = Encounter.new
202
200
  encounter.patient = Patient.find(patient_id)
203
201
  encounter.encounter_type = EncounterType.find_by_name!(Lab::Metadata::ENCOUNTER_TYPE_NAME)
@@ -263,7 +261,6 @@ module Lab
263
261
  #
264
262
  # Examples of reasons include: Routine, Targeted, Confirmatory, Repeat, or Stat.
265
263
  def add_reason_for_test(order, params)
266
-
267
264
  reason = params[:reason_for_test_id] || params[:reason_for_test]
268
265
 
269
266
  reason = Concept.find(reason)
@@ -289,6 +286,8 @@ module Lab
289
286
  end
290
287
 
291
288
  def create_order_observation(order, concept_name, date, **values)
289
+ creator = User.find_by(username: 'lab_daemon')
290
+ User.current ||= creator
292
291
  Observation.create!(
293
292
  order: order,
294
293
  encounter_id: order.encounter_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 = '1.2.3'
4
+ VERSION = '1.2.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mahis_emr_api_lab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elizabeth Glaser Pediatric Foundation Malawi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2025-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -254,7 +254,7 @@ files:
254
254
  - app/services/lab/lims/acknowledgement_serializer.rb
255
255
  - app/services/lab/lims/acknowledgement_worker.rb
256
256
  - app/services/lab/lims/api/blackhole_api.rb
257
- - app/services/lab/lims/api/couchdb_api.rb
257
+ - app/services/lab/lims/api/couch_db_api.rb
258
258
  - app/services/lab/lims/api/mysql_api.rb
259
259
  - app/services/lab/lims/api/rest_api.rb
260
260
  - app/services/lab/lims/api/ws_api.rb
@@ -309,7 +309,7 @@ licenses:
309
309
  - MIT
310
310
  metadata:
311
311
  source_code_uri: https://github.com/EGPAFMalawiHIS/his_emr_api_lab
312
- post_install_message:
312
+ post_install_message:
313
313
  rdoc_options: []
314
314
  require_paths:
315
315
  - lib
@@ -324,8 +324,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
324
  - !ruby/object:Gem::Version
325
325
  version: '0'
326
326
  requirements: []
327
- rubygems_version: 3.4.17
328
- signing_key:
327
+ rubygems_version: 3.4.1
328
+ signing_key:
329
329
  specification_version: 4
330
330
  summary: Lab extension for the HIS-EMR-API
331
331
  test_files: []