his_emr_api_lab 1.1.2 → 1.1.3

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: e2202cc31522b4ae92847b3102841cfcf0c65a9e389fde480e3e787f1ef49ec7
4
- data.tar.gz: a82291c66cdd6fb651e0917dc68e5b28b6dcedeb124973ab57f9f60187b4c920
3
+ metadata.gz: eb21c8db8180a800fc69ebdfcfe9e2e804a96c698e73f28ae3c2c865a8853c16
4
+ data.tar.gz: 2e2697ddeb327c79698ca229f9d625b6e6105e5621348df1c7d2d06d5c7b7cbb
5
5
  SHA512:
6
- metadata.gz: 7da2c231dba9fa4b013890becd128b0a8694fe797b510e9baa37638d1437133cc11e27e2479938eda921ccfe6c23583544092cb477372b5db298922913035c72
7
- data.tar.gz: cb8fbf9e9c71d187e0085b42f0fe5299976dc4309d672c815c231cdb096548d9b53b9b0f222f453b66a41a8d18b759f2d8d295c46c899206d7c7ffcee500bb6c
6
+ metadata.gz: 4440f3a2b7493335594206621cb2381207b59dfab73d841431d77ef8ba7f28f1bc033617378c7789f50e52dacdb0318b8e2ab1d93f3929b6a66601dbbfa1537c
7
+ data.tar.gz: aacb8d43a4b71dc017a46d3f19791defc5f9f7b0562a96c8514d3d821f7d79124ce59719bcbf91f2042c7da61f61907bbab2b7e04b33b18443c0ea204b902f18
@@ -38,6 +38,9 @@ module Lab
38
38
  end
39
39
 
40
40
  def create_order(order)
41
+ order = order.dup
42
+ order.delete('_id')
43
+
41
44
  bum.couch_rest :post, '/', order
42
45
  end
43
46
 
@@ -11,15 +11,19 @@ module Lab
11
11
  class ConfigNotFound < RuntimeError; end
12
12
 
13
13
  class << self
14
+ def preferred_api
15
+ emr_api_application('lims_api', 'couchdb')
16
+ end
17
+
14
18
  ##
15
19
  # Returns LIMS' couchdb configuration file for the current environment (Rails.env)
16
20
  def couchdb
17
21
  config_path = begin
18
- find_config_path('couchdb.yml')
19
- rescue ConfigNotFound => e
20
- Rails.logger.error("Failed to find default LIMS couchdb config: #{e.message}")
21
- find_config_path('couchdb-lims.yml') # This can be placed in HIS-EMR-API/config
22
- end
22
+ find_config_path('couchdb.yml')
23
+ rescue ConfigNotFound => e
24
+ Rails.logger.error("Failed to find default LIMS couchdb config: #{e.message}")
25
+ find_config_path('couchdb-lims.yml') # This can be placed in HIS-EMR-API/config
26
+ end
23
27
 
24
28
  Rails.logger.debug("Using LIMS couchdb config: #{config_path}")
25
29
 
@@ -64,9 +68,7 @@ module Lab
64
68
  @emr_api_application ||= YAML.load_file(Rails.root.join('config', 'application.yml'))
65
69
 
66
70
  @emr_api_application.fetch(param) do
67
- unless fallback
68
- raise ConfigNotFound, "Missing config param: #{param}"
69
- end
71
+ raise ConfigNotFound, "Missing config param: #{param}" unless fallback
70
72
 
71
73
  fallback
72
74
  end
@@ -83,9 +85,7 @@ module Lab
83
85
  Rails.root.parent.join("nlims_controller/config/#{filename}")
84
86
  ]
85
87
 
86
- if filename == 'couchdb.yml'
87
- paths = [Rails.root.join('config/lims-couchdb.yml'), *paths]
88
- end
88
+ paths = [Rails.root.join('config/lims-couchdb.yml'), *paths] if filename == 'couchdb.yml'
89
89
 
90
90
  paths.each do |path|
91
91
  Rails.logger.debug("Looking for LIMS couchdb config at: #{path}")
@@ -69,9 +69,7 @@ module Lab
69
69
  end
70
70
 
71
71
  def start_date
72
- if self['date_created'].blank?
73
- raise LimsException, 'Order missing created date'
74
- end
72
+ raise LimsException, 'Order missing created date' if self['date_created'].blank?
75
73
 
76
74
  Utils.parse_date(self['date_created'])
77
75
  end
@@ -85,7 +83,7 @@ module Lab
85
83
 
86
84
  # Translates a LIMS sample priority to a concept_id
87
85
  def reason_for_test
88
- return unknown_concept.concept_id unless self['priority']
86
+ return nil unless self['priority']
89
87
 
90
88
  name = case self['priority']
91
89
  when %r{Reapet / Missing}i then 'Repeat / Missing'
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'logger_multiplexor'
4
4
 
5
+ require_relative './api/couchdb_api'
6
+
5
7
  module Lab
6
8
  module Lims
7
9
  ##
@@ -19,8 +21,7 @@ module Lab
19
21
 
20
22
  def self.start_push_worker
21
23
  start_worker('push_worker') do
22
- api = Lims::Api::RestApi.new(Lab::Lims::Config.rest_api)
23
- worker = PushWorker.new(api)
24
+ worker = PushWorker.new(lims_api)
24
25
 
25
26
  worker.push_orders # (wait: true)
26
27
  end
@@ -28,8 +29,7 @@ module Lab
28
29
 
29
30
  def self.start_pull_worker
30
31
  start_worker('pull_worker') do
31
- api = Lims::Api::RestApi.new(Lab::Lims::Config.rest_api)
32
- worker = PullWorker.new(api)
32
+ worker = PullWorker.new(lims_api)
33
33
 
34
34
  worker.pull_orders
35
35
  end
@@ -37,8 +37,7 @@ module Lab
37
37
 
38
38
  def self.start_realtime_pull_worker
39
39
  start_worker('realtime_pull_worker') do
40
- api = Lims::Api::WsApi.new(Lab::Lims::Config.updates_socket)
41
- worker = PullWorker.new(api)
40
+ worker = PullWorker.new(Lims::Api::WsApi.new(Lab::Lims::Config.updates_socket))
42
41
 
43
42
  worker.pull_orders
44
43
  end
@@ -71,6 +70,14 @@ module Lab
71
70
  Rails.logger.warn("Check for realtime updates failed: #{e.message}")
72
71
  false
73
72
  end
73
+
74
+ def self.lims_api
75
+ case Lims::Config.preferred_api
76
+ when /couchdb/i then Api::CouchDbApi.new(config: Lab::Lims::Config.couchdb)
77
+ when /rest/i then Api::RestApi.new(Lab::Lims::Config.rest_api)
78
+ else raise "Invalid LIMS API in application.yml, expected 'rest' or 'couchdb'"
79
+ end
80
+ end
74
81
  end
75
82
  end
76
83
  end
@@ -66,9 +66,7 @@ module Lab
66
66
 
67
67
  def update_order(order_id, params)
68
68
  specimen_id = params.dig(:specimen, :concept_id)
69
- unless specimen_id
70
- raise ::InvalidParameterError, 'Specimen concept_id is required'
71
- end
69
+ raise ::InvalidParameterError, 'Specimen concept_id is required' unless specimen_id
72
70
 
73
71
  order = Lab::LabOrder.find(order_id)
74
72
  if order.concept_id != unknown_concept_id && !params[:force_update]&.casecmp?('true')
@@ -84,7 +82,7 @@ module Lab
84
82
  discontinued_reason_non_coded: 'Sample drawn/updated')
85
83
  end
86
84
 
87
- if params.key?(:reason_for_test_id)
85
+ if params[:reason_for_test_id]
88
86
  Rails.logger.debug("Updating reason for test on order ##{order.order_id}")
89
87
  update_reason_for_test(order, params[:reason_for_test_id])
90
88
  end
@@ -116,13 +114,9 @@ module Lab
116
114
  # a 'Lab' encounter is created using the provided program_id and
117
115
  # patient_id.
118
116
  def find_encounter(order_params)
119
- if order_params[:encounter_id]
120
- return Encounter.find(order_params[:encounter_id])
121
- end
117
+ return Encounter.find(order_params[:encounter_id]) if order_params[:encounter_id]
122
118
 
123
- unless order_params[:patient_id]
124
- raise InvalidParameterError, 'encounter_id or patient_id required'
125
- end
119
+ raise InvalidParameterError, 'encounter_id or patient_id required' unless order_params[:patient_id]
126
120
 
127
121
  program_id = order_params[:program_id] || Program.find_by_name!(Lab::Metadata::LAB_PROGRAM_NAME).program_id
128
122
 
@@ -203,17 +197,13 @@ module Lab
203
197
  end
204
198
 
205
199
  def update_reason_for_test(order, concept_id)
206
- if concept_id.blank?
207
- raise InvalidParameterError, "Reason for test can't be blank"
208
- end
200
+ raise InvalidParameterError, "Reason for test can't be blank" if concept_id.blank?
209
201
 
210
202
  return if order.reason_for_test&.value_coded == concept_id
211
203
 
212
- unless order.reason_for_test&.value_coded.nil?
213
- raise InvalidParameterError, "Can't change reason for test once set"
214
- end
204
+ raise InvalidParameterError, "Can't change reason for test once set" if order.reason_for_test&.value_coded
215
205
 
216
- order.reason_for_test.delete
206
+ order.reason_for_test&.delete
217
207
  add_reason_for_test(order, date: order.start_date, reason_for_test_id: concept_id)
218
208
  end
219
209
  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.2'
4
+ VERSION = '1.1.3'
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.2
4
+ version: 1.1.3
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-15 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest