his_emr_api_lab 1.1.5 → 1.1.9

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: 960dc05ef6fbcddc4538762d7c7f3369e77d2f24b879e14a110ffa4ab2141d22
4
- data.tar.gz: 666ea51bb7ff2938b6d4fd733a619a49cf600aed37c330c8be3f9680bdc4e94e
3
+ metadata.gz: a13cacbcc7be1a44baac082c8ade406f20538dabe21c26b3b2ef249cd9ee22cd
4
+ data.tar.gz: 9b0a9cfb4676982b299600078fa0421133af14a0b8d15dd49ac9ca1933fad7e0
5
5
  SHA512:
6
- metadata.gz: 3ba9d9cb6d59d656b8d72190d6ecb1bcf6c193fdeb22121608ec39fb2fbb77e1b11e2b53d45d8937f6969cb1212e1adb045bb4a53e76f1eefa825731c2abcb98
7
- data.tar.gz: 6e27abac8e38b86238adecf6eec31e3cad2503b5d46e534b498b47cad563cf15ebacf74fdc66c552338ebc584e3f08c331480cb57be14df5951c297ce642a44a
6
+ metadata.gz: 93092265b1d1cde16121ff005c901387e357040e32b05b3dff508564cde3832f8451e6805c7ca47c772abf90a47757a6cfd9a95084962b148cbdf7819f3a3493
7
+ data.tar.gz: d2d1dded33ca89b66ad8d99c477fa373f6cc8c33958cc17192fb1a7691abaf4802ebc800c63006ff46d64e527a630ce263c0edddc1db368d67b2848406fd997c
@@ -44,6 +44,9 @@ class Lab::Lims::Api::RestApi
44
44
 
45
45
  def consume_orders(*_args, patient_id: nil, **_kwargs)
46
46
  orders_pending_updates(patient_id).each do |order|
47
+ mapping = Lab::LimsOrderMapping.find_by(order_id: order.order_id)
48
+ next if mapping.nil? || check_and_fix_duplicate!(mapping, order)
49
+
47
50
  order_dto = Lab::Lims::OrderSerializer.serialize_order(order)
48
51
 
49
52
  if order_dto['priority'].nil? || order_dto['sample_type'].casecmp?('not_specified')
@@ -405,4 +408,24 @@ class Lab::Lims::Api::RestApi
405
408
 
406
409
  orders
407
410
  end
411
+
412
+ # Checks for duplicates previously created due to this proving orders that have
413
+ # not been pushed to LIMS as orders awaiting updates.
414
+ def check_and_fix_duplicate!(mapping, order)
415
+ duplicate_orders = Lab::LabOrder.where(accession_number: mapping.lims_id)
416
+ .where.not(order_id: mapping.order_id)
417
+ return false if duplicate_orders.size.zero?
418
+
419
+ unless order.discontinued
420
+ order.void('Duplicate created due to bug in HIS-EMR-API-Lab v1.1.7')
421
+ mapping.destroy
422
+ return true
423
+ end
424
+
425
+ duplicate_orders.each do |duplicate_order|
426
+ duplicate_order.void("Has duplicate that contains updates ##{order.order_id}: Duplicate was created by bug in HIS-EMR-API-Lab v1.1.7")
427
+ end
428
+
429
+ true
430
+ end
408
431
  end
@@ -12,7 +12,7 @@ module Lab
12
12
 
13
13
  class << self
14
14
  def preferred_api
15
- emr_api_application('lims_api', 'couchdb')
15
+ emr_api_application('lims_api')
16
16
  end
17
17
 
18
18
  ##
@@ -32,7 +32,7 @@ module Lab
32
32
  def specimen_type_id
33
33
  lims_specimen_name = self['sample_type']&.strip&.downcase
34
34
 
35
- if %w[specimen_not_collected not_assigned not_specified].include?(lims_specimen_name)
35
+ if lims_specimen_name.nil? || %w[specimen_not_collected not_assigned not_specified].include?(lims_specimen_name)
36
36
  return ConceptName.select(:concept_id).find_by_name!('Unknown').concept_id
37
37
  end
38
38
 
@@ -58,6 +58,9 @@ module Lab
58
58
  Rails.logger.info("Updating order ##{order_dto['accession_number']} in LIMS")
59
59
  lims_api.update_order(mapping.lims_id, order_dto)
60
60
  mapping.update(pushed_at: Time.now)
61
+ elsif order_dto[:_id] && Lab::LimsOrderMapping.where(lims_id: order_dto[:_id]).exists?
62
+ Rails.logger.warn("Duplicate accession number found: #{order_dto[:_id]}, skipping order...")
63
+ nil
61
64
  else
62
65
  Rails.logger.info("Creating order ##{order_dto['accession_number']} in LIMS")
63
66
  update = lims_api.create_order(order_dto)
@@ -45,7 +45,7 @@ module Lab
45
45
 
46
46
  def self.start_worker(worker_name)
47
47
  Rails.logger = LoggerMultiplexor.new(log_path("#{worker_name}.log"), $stdout)
48
- ActiveRecord::Base.logger = Rails.logger
48
+ # ActiveRecord::Base.logger = Rails.logger
49
49
  Rails.logger.level = :debug
50
50
 
51
51
  File.open(log_path("#{worker_name}.lock"), File::RDWR | File::CREAT, 0o644) do |fout|
@@ -0,0 +1,7 @@
1
+ class AddDefaultToLimsOrderMapping < ActiveRecord::Migration[5.2]
2
+ def up
3
+ change_column :lab_lims_order_mappings, :revision, :string, limit: 256, default: nil, null: true
4
+ end
5
+
6
+ def down; end
7
+ end
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.1.5'
4
+ VERSION = '1.1.9'
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: 1.1.5
4
+ version: 1.1.9
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: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -290,6 +290,7 @@ files:
290
290
  - db/migrate/20210326195504_add_order_revision_to_lims_order_mapping.rb
291
291
  - db/migrate/20210407071728_create_lab_lims_failed_imports.rb
292
292
  - db/migrate/20210610095024_fix_numeric_results_value_type.rb
293
+ - db/migrate/20210807111531_add_default_to_lims_order_mapping.rb
293
294
  - lib/auto12epl.rb
294
295
  - lib/couch_bum/couch_bum.rb
295
296
  - lib/generators/lab/install/USAGE
@@ -330,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
331
  - !ruby/object:Gem::Version
331
332
  version: '0'
332
333
  requirements: []
333
- rubygems_version: 3.0.8
334
+ rubygems_version: 3.1.4
334
335
  signing_key:
335
336
  specification_version: 4
336
337
  summary: Lab extension for the HIS-EMR-API