mahis_emr_api_lab 1.2.2 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dce8f674cad939a3e92204eadfa4e97d299c41acbfbf0182efc0374544fcb846
4
- data.tar.gz: f84dc3cbea226eed9d5f82d2a6e54169744d7e0a76f1a0e8e0c81d4e543db004
3
+ metadata.gz: 1564986977bbbb02dab3359307faa412965cecb2a0aaa3d0cc97b9e2ef068f92
4
+ data.tar.gz: 42fcee721977f3cbc1fd29f8f184b23e532cde82bf9846494c90bf1285f0d773
5
5
  SHA512:
6
- metadata.gz: 0b7dea9b4174a922fb47d3e01ca88639a5f35d847d764265d19f597820af1c1358ca0879ec7d570281fca20359a8288cf68e415dba6aecc3b574e9710ea179ca
7
- data.tar.gz: 3135f070f3b81e16d4f1c135dc07a347f6b74be84a04c1a1bacdfecc4b1353ecb48644e576c0364ebed3afb9c36f0ee5ec42a1c128f9f0f49c3eebb4ec7146c4
6
+ metadata.gz: 91179c762c1d91c33d6ca6c6c751ff73102b8a4e8ac9f191e3eb2aa00e0ccfa9a1e16f69accb3f19ec9d1a54f25b0066f17de4d47560c0c976d47859ad9240b9
7
+ data.tar.gz: f91bb3ab835a5ec653fdaa9666475b2d26f1e0acc2d43d8d753456c748137051d6ef364bf5709bc9569f774ecd0758022f798f1a5786b59c638d878c473b2fac
@@ -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
@@ -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
@@ -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
@@ -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}")
@@ -60,9 +61,9 @@ module Lab
60
61
  Rails.logger.info("Updating order ##{order_dto[:accession_number]} in LIMS")
61
62
  lims_api.update_order(mapping.lims_id, order_dto)
62
63
  if order_dto['test_results'].nil? || order_dto['test_results'].empty?
63
- mapping.update(pushed_at: Time.now)
64
+ mapping.update(pushed_at: Time.now)
64
65
  else
65
- mapping.update(pushed_at: Time.now, result_push_status: true)
66
+ mapping.update(pushed_at: Time.now, result_push_status: true)
66
67
  end
67
68
  elsif order_dto[:_id] && Lab::LimsOrderMapping.where(lims_id: order_dto[:_id]).exists?
68
69
  # HACK: v1.1.7 had a bug where duplicates of recently created orders where being created by
@@ -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
 
@@ -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.2'
4
+ VERSION = '1.2.4'
5
5
  end
@@ -0,0 +1,6 @@
1
+ require 'lab/engine'
2
+ require 'lab/version'
3
+
4
+ module Lab
5
+ # Your code goes here...
6
+ 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.2
4
+ version: 1.2.4
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-21 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -294,6 +294,7 @@ files:
294
294
  - lib/lab/engine.rb
295
295
  - lib/lab/version.rb
296
296
  - lib/logger_multiplexor.rb
297
+ - lib/mahis_emr_api_lab.rb
297
298
  - lib/tasks/lab_tasks.rake
298
299
  - lib/tasks/loaders/data/reasons-for-test.csv
299
300
  - lib/tasks/loaders/data/test-measures.csv
@@ -308,7 +309,7 @@ licenses:
308
309
  - MIT
309
310
  metadata:
310
311
  source_code_uri: https://github.com/EGPAFMalawiHIS/his_emr_api_lab
311
- post_install_message:
312
+ post_install_message:
312
313
  rdoc_options: []
313
314
  require_paths:
314
315
  - lib
@@ -323,8 +324,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
324
  - !ruby/object:Gem::Version
324
325
  version: '0'
325
326
  requirements: []
326
- rubygems_version: 3.4.5
327
- signing_key:
327
+ rubygems_version: 3.4.17
328
+ signing_key:
328
329
  specification_version: 4
329
330
  summary: Lab extension for the HIS-EMR-API
330
331
  test_files: []