his_emr_api_lab 1.1.13 → 1.1.14

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: f7b7bee82670948e0315bde7a3d0f9cab91476bcb27646ec7c234e0c96d11bc9
4
- data.tar.gz: 127d70d6a044a8ddc5dcc25ed2460d1fcb463d8f27f3817b54fca7d5ada6d88a
3
+ metadata.gz: f655e84314f6a25a8ecce1668132e93bbd1a175efd35cb832792b94cc9d33e42
4
+ data.tar.gz: 298f226847e19dd868e7caf487b00b49dc306bed4ca2c2a0f2c07765278598e5
5
5
  SHA512:
6
- metadata.gz: 421db4bdc5cb32b994d9329c87ebe8c79eae681765abe980bd87c6fab83c70de74961d78845d2602af31aea018b480ddcad9f97de4dfa01a8cd975c8c9a49db8
7
- data.tar.gz: 4d1c1df19df7b297e66d44055bcbe88b410f25e744a56f0bb46a99f8fd06af9e25ad332499cbd34e8ea10f7879c14455f8b16d376e24c7a50bf7518156ce3646
6
+ metadata.gz: 132e7e46b9c9c6468651b1ebde2ce182852cc17992a54928b49b3605191c53f81ab324e21657d1b421ac317d48c51cd2a73c24d11f94cd5ca4f0d47714c04d9b
7
+ data.tar.gz: c49d8d971697158bf1646027935ed1e95cb825a161fef18a9d658affb7e1493b24b0f70748d8c61d4a9e69d81e00d5d3f3395eec7ea4c4189401b992a27d97f5
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab
4
+ ##
5
+ # Push an order to LIMS.
6
+ class PushOrderJob < ApplicationJob
7
+ def perform(order_id)
8
+ push_worker = Lab::Lims::PushWorker.new(Lab::Lims::ApiFactory.create_api)
9
+ push_worker.push_order_by_id(order_id)
10
+ end
11
+ end
12
+ end
@@ -20,8 +20,7 @@ module Lab
20
20
  break false
21
21
  end
22
22
 
23
- lims_api = Lab::Lims::Api::RestApi.new(Lab::Lims::Config.rest_api)
24
- worker = Lab::Lims::PullWorker.new(lims_api)
23
+ worker = Lab::Lims::PullWorker.new(Lab::Lims::ApiFactory.create_api)
25
24
  worker.pull_orders(patient_id: patient_id)
26
25
 
27
26
  true
@@ -10,8 +10,7 @@ module Lab
10
10
  User.current = Lab::Lims::Utils.lab_user
11
11
  Location.current = Location.find_by_name('ART clinic')
12
12
 
13
- lims_api = Lab::Lims::Api::RestApi.new
14
- worker = Lab::Lims::Worker.new(lims_api)
13
+ worker = Lab::Lims::PushWorker.new(Lab::Lims::ApiFactory.create_api)
15
14
  worker.push_order(Lab::LabOrder.unscoped.find(order_id))
16
15
  end
17
16
  end
@@ -42,14 +42,21 @@ module Lab
42
42
  end
43
43
 
44
44
  scope :drawn, -> { where.not(concept_id: ConceptName.where(name: 'Unknown').select(:concept_id)) }
45
-
46
45
  scope :not_drawn, -> { where(concept_id: ConceptName.where(name: 'Unknown').select(:concept_id)) }
47
46
 
47
+ after_save :queue_lims_push
48
+
48
49
  def self.prefetch_relationships
49
50
  includes(:reason_for_test,
50
51
  :requesting_clinician,
51
52
  :target_lab,
52
53
  tests: [:result])
53
54
  end
55
+
56
+ private
57
+
58
+ def queue_lims_push
59
+ Lab::PushOrderJob.perform_later(order_id)
60
+ end
54
61
  end
55
62
  end
@@ -6,7 +6,7 @@ module Lab
6
6
  tests ||= order.voided == 1 ? voided_tests(order) : order.tests
7
7
  requesting_clinician ||= order.requesting_clinician
8
8
  reason_for_test ||= order.reason_for_test
9
- target_lab = target_lab || order.target_lab || Location.current_health_center.name
9
+ target_lab = target_lab&.value_text || order.target_lab&.value_text || Location.current_health_center&.name
10
10
 
11
11
  ActiveSupport::HashWithIndifferentAccess.new(
12
12
  {
@@ -21,7 +21,7 @@ module Lab
21
21
  name: concept_name(order.concept_id)
22
22
  },
23
23
  requesting_clinician: requesting_clinician&.value_text,
24
- target_lab: target_lab&.value_text,
24
+ target_lab: target_lab,
25
25
  reason_for_test: {
26
26
  concept_id: reason_for_test&.value_coded,
27
27
  name: concept_name(reason_for_test&.value_coded)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab
4
+ module Lims
5
+ module Api
6
+ ##
7
+ # A LIMS Api wrappper that does nothing really.
8
+ #
9
+ # Primarily meant as a dummy for testing environments.
10
+ class BlackholeApi
11
+ def create_order(order_dto); end
12
+
13
+ def update_order(order_dto); end
14
+
15
+ def void_order(order_dto); end
16
+
17
+ def consume_orders(&_block); end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab
4
+ module Lims
5
+ ##
6
+ # Creates LIMS Apis based on current configuration
7
+ module ApiFactory
8
+ def self.create_api
9
+ return Lab::Lims::Api::BlackholeApi.new if Rails.env.casecmp?('test')
10
+
11
+ case Lab::Lims::Config.preferred_api
12
+ when /rest/i then Lab::Lims::Api::RestApi.new(Lab::Lims::Config.rest_api)
13
+ when /couchdb/ then Lab::Lims::Api::CouchDbApi.new(config: Lab::Lims::Config.couchdb_api)
14
+ else raise "Invalid lims_api configuration: #{Lab::Lims::Config.preferred_api}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -46,9 +46,20 @@ require_relative 'utils'
46
46
 
47
47
  module Lab
48
48
  module Lims
49
+ ##
50
+ # Tools for performing a bulk import of data from LIMS' databases to local OpenMRS database.
51
+ #
52
+ # Migration sources supported:
53
+ # - MySQL
54
+ # - CouchDB
55
+ #
56
+ # The sources above can be changed by setting the environment various MIGRATION_SOURCE to
57
+ # either mysql or couchdb.
49
58
  module Migrator
50
59
  MAX_THREADS = ENV.fetch('MIGRATION_WORKERS', 6).to_i
51
60
 
61
+ ##
62
+ # A Lab::Lims::Api object that supports crawling of a LIMS CouchDB instance.
52
63
  class CouchDbMigratorApi < Lab::Lims::Api::CouchDbApi
53
64
  def initialize(*args, processes: 1, on_merge_processes: nil, **kwargs)
54
65
  super(*args, **kwargs)
@@ -91,6 +102,12 @@ module Lab
91
102
  end
92
103
  end
93
104
 
105
+ ##
106
+ # Extends the PullWorker to provide pause/resume capabilities.
107
+ #
108
+ # Migrations can be take a long time to complete, in cases where something
109
+ # went wrong you wouldn't to start all over. This worker thus saves
110
+ # progress and allows for the process to continue from whether it stopped.
94
111
  class MigrationWorker < PullWorker
95
112
  LOG_FILE_PATH = Utils::LIMS_LOG_PATH.join('migration-last-id.dat')
96
113
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Lab
4
4
  module Lims
5
+ ##
6
+ # Pulls orders from a Lims API object and saves them to the local database.
5
7
  class PullWorker
6
8
  attr_reader :lims_api
7
9
 
@@ -100,9 +102,7 @@ module Lab
100
102
  .distinct(:patient_id)
101
103
  .all
102
104
 
103
- if patients.size > 1
104
- raise DuplicateNHID, "Duplicate National Health ID: #{nhid}"
105
- end
105
+ raise DuplicateNHID, "Duplicate National Health ID: #{nhid}" if patients.size > 1
106
106
 
107
107
  patients.first
108
108
  end
@@ -166,9 +166,7 @@ module Lab
166
166
  def create_order(patient, order_dto)
167
167
  logger.debug("Creating order ##{order_dto['_id']}")
168
168
  order = OrdersService.order_test(order_dto.to_order_service_params(patient_id: patient.patient_id))
169
- unless order_dto['test_results'].empty?
170
- update_results(order, order_dto['test_results'])
171
- end
169
+ update_results(order, order_dto['test_results']) unless order_dto['test_results'].empty?
172
170
 
173
171
  order
174
172
  end
@@ -177,9 +175,7 @@ module Lab
177
175
  logger.debug("Updating order ##{order_dto['_id']}")
178
176
  order = OrdersService.update_order(order_id, order_dto.to_order_service_params(patient_id: patient.patient_id)
179
177
  .merge(force_update: 'true'))
180
- unless order_dto['test_results'].empty?
181
- update_results(order, order_dto['test_results'])
182
- end
178
+ update_results(order, order_dto['test_results']) unless order_dto['test_results'].empty?
183
179
 
184
180
  order
185
181
  end
@@ -283,9 +279,7 @@ module Lab
283
279
  mapping = Lab::LimsOrderMapping.find_by(lims_id: lims_id)
284
280
  return nil unless mapping
285
281
 
286
- if Lab::LabOrder.where(order_id: mapping.order_id).exists?
287
- return mapping
288
- end
282
+ return mapping if Lab::LabOrder.where(order_id: mapping.order_id).exists?
289
283
 
290
284
  mapping.destroy
291
285
  nil
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Lab
4
4
  module Lims
5
+ ##
6
+ # Pushes all local orders to a LIMS Api object.
5
7
  class PushWorker
6
8
  attr_reader :lims_api
7
9
 
@@ -33,7 +35,9 @@ module Lab
33
35
  end
34
36
 
35
37
  def push_order_by_id(order_id)
36
- order = Lab::LabOrder.unscoped.find(order_id)
38
+ order = Lab::LabOrder.joins(order_type: { name: 'Lab' })
39
+ .unscoped
40
+ .find(order_id)
37
41
  push_order(order)
38
42
  end
39
43
 
@@ -79,11 +79,7 @@ module Lab
79
79
  end
80
80
 
81
81
  def self.lims_api
82
- case Lims::Config.preferred_api
83
- when /couchdb/i then Api::CouchDbApi.new(config: Lab::Lims::Config.couchdb)
84
- when /rest/i then Api::RestApi.new(Lab::Lims::Config.rest_api)
85
- else raise "Invalid LIMS API in application.yml, expected 'rest' or 'couchdb'"
86
- end
82
+ Lab::Lims::ApiFactory.create_api
87
83
  end
88
84
  end
89
85
  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.13'
4
+ VERSION = '1.1.14'
5
5
  end
@@ -68,6 +68,7 @@
68
68
  "Hepatitis B Test","Hepatitis B"
69
69
  "Hepatitis C Test","Hepatitis C"
70
70
  "Rheumatoid Factor Test","Rheumatoid Factor"
71
+ "CrAg","CrAg"
71
72
  "Cryptococcus Antigen Test","CrAg"
72
73
  "Anti Streptolysis O","ASO"
73
74
  "C-reactive protein","CRP"
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.13
4
+ version: 1.1.14
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-09-06 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -248,6 +248,7 @@ files:
248
248
  - app/controllers/lab/test_types_controller.rb
249
249
  - app/controllers/lab/tests_controller.rb
250
250
  - app/jobs/lab/application_job.rb
251
+ - app/jobs/lab/push_order_job.rb
251
252
  - app/jobs/lab/update_patient_orders_job.rb
252
253
  - app/jobs/lab/void_order_job.rb
253
254
  - app/mailers/lab/application_mailer.rb
@@ -265,10 +266,12 @@ files:
265
266
  - app/services/lab/accession_number_service.rb
266
267
  - app/services/lab/concepts_service.rb
267
268
  - app/services/lab/labelling_service/order_label.rb
269
+ - app/services/lab/lims/api/blackhole_api.rb
268
270
  - app/services/lab/lims/api/couchdb_api.rb
269
271
  - app/services/lab/lims/api/mysql_api.rb
270
272
  - app/services/lab/lims/api/rest_api.rb
271
273
  - app/services/lab/lims/api/ws_api.rb
274
+ - app/services/lab/lims/api_factory.rb
272
275
  - app/services/lab/lims/config.rb
273
276
  - app/services/lab/lims/exceptions.rb
274
277
  - app/services/lab/lims/migrator.rb