his_emr_api_lab 1.0.4 → 1.1.2

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.
@@ -10,6 +10,7 @@ module Lab
10
10
  TEST_RESULT_CONCEPT_NAME = 'Lab test result'
11
11
  TEST_RESULT_INDICATOR_CONCEPT_NAME = 'Lab test result indicator'
12
12
  TEST_TYPE_CONCEPT_NAME = 'Test type'
13
+ UNKNOWN_SPECIMEN = 'Unknown'
13
14
 
14
15
  # Encounter
15
16
  ENCOUNTER_TYPE_NAME = 'Lab'
@@ -5,6 +5,14 @@ module Lab
5
5
  module OrdersSearchService
6
6
  class << self
7
7
  def find_orders(filters)
8
+ # A bit of hack-ish solution to have a patient's orders updated upon
9
+ # scanning of a patient. Done in this way to deal with LIMS' lack of
10
+ # a notification system for lab order updates. We are limited to polling
11
+ # for updates on a per order basis.
12
+ if filters[:patient_id]
13
+ Lab::UpdatePatientOrdersJob.perform_later(filters[:patient_id])
14
+ end
15
+
8
16
  extra_filters = pop_filters(filters, :date, :end_date, :status)
9
17
 
10
18
  orders = Lab::LabOrder.prefetch_relationships
@@ -17,6 +25,16 @@ module Lab
17
25
  orders.map { |order| Lab::LabOrderSerializer.serialize_order(order) }
18
26
  end
19
27
 
28
+ def find_orders_without_results(patient_id: nil)
29
+ results_query = Lab::LabResult.all
30
+ results_query = results_query.where(person_id: patient_id) if patient_id
31
+
32
+ query = Lab::LabOrder.where.not(order_id: results_query.select(:order_id))
33
+ query = query.where(patient_id: patient_id) if patient_id
34
+
35
+ query
36
+ end
37
+
20
38
  def filter_orders_by_date(orders, date: nil, end_date: nil)
21
39
  date = date&.to_date
22
40
  end_date = end_date&.to_date
@@ -53,6 +71,8 @@ module Lab
53
71
  popped_params[filter.to_sym] = params.delete(filter)
54
72
  end
55
73
  end
74
+
75
+ def fetch_results(order); end
56
76
  end
57
77
  end
58
78
  end
@@ -71,15 +71,24 @@ module Lab
71
71
  end
72
72
 
73
73
  order = Lab::LabOrder.find(order_id)
74
- unless order.concept_id == unknown_concept_id || params[:force_update]&.to_s&.casecmp?('true')
75
- raise ::UnprocessableEntityError
74
+ if order.concept_id != unknown_concept_id && !params[:force_update]&.casecmp?('true')
75
+ raise ::UnprocessableEntityError, "Can't change order specimen once set"
76
+ end
77
+
78
+ if specimen_id.to_i != order.concept_id
79
+ Rails.logger.debug("Updating order ##{order.order_id}")
80
+ order.update!(concept_id: specimen_id,
81
+ discontinued: true,
82
+ discontinued_by: User.current.user_id,
83
+ discontinued_date: params[:date]&.to_date || Time.now,
84
+ discontinued_reason_non_coded: 'Sample drawn/updated')
85
+ end
86
+
87
+ if params.key?(:reason_for_test_id)
88
+ Rails.logger.debug("Updating reason for test on order ##{order.order_id}")
89
+ update_reason_for_test(order, params[:reason_for_test_id])
76
90
  end
77
91
 
78
- order.update!(concept_id: specimen_id,
79
- discontinued: true,
80
- discontinued_by: User.current.user_id,
81
- discontinued_date: params[:date]&.to_date || Date.today,
82
- discontinued_reason_non_coded: 'Sample drawn/updated')
83
92
  Lab::LabOrderSerializer.serialize_order(order)
84
93
  end
85
94
 
@@ -92,8 +101,10 @@ module Lab
92
101
  order.target_lab&.void(reason)
93
102
 
94
103
  order.tests.each { |test| test.void(reason) }
104
+ voided = order.void(reason)
105
+ Lab::VoidOrderJob.perform_later(order_id)
95
106
 
96
- order.void(reason)
107
+ voided
97
108
  end
98
109
 
99
110
  private
@@ -157,7 +168,7 @@ module Lab
157
168
  order,
158
169
  Lab::Metadata::REASON_FOR_TEST_CONCEPT_NAME,
159
170
  params[:date],
160
- value_coded: params['reason_for_test_id']
171
+ value_coded: params[:reason_for_test_id]
161
172
  )
162
173
  end
163
174
 
@@ -190,6 +201,21 @@ module Lab
190
201
  def unknown_concept_id
191
202
  ConceptName.find_by_name!('Unknown').concept_id
192
203
  end
204
+
205
+ 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
209
+
210
+ return if order.reason_for_test&.value_coded == concept_id
211
+
212
+ unless order.reason_for_test&.value_coded.nil?
213
+ raise InvalidParameterError, "Can't change reason for test once set"
214
+ end
215
+
216
+ order.reason_for_test.delete
217
+ add_reason_for_test(order, date: order.start_date, reason_for_test_id: concept_id)
218
+ end
193
219
  end
194
220
  end
195
221
  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.0.4'
4
+ VERSION = '1.1.2'
5
5
  end
@@ -3,4 +3,5 @@
3
3
  "Repeat / Missing"
4
4
  "Targeted"
5
5
  "Confirmatory"
6
+ "Stat"
6
7
  "Other"
@@ -86,8 +86,6 @@ Blood,HbA1c,"2019-11-19 14:05:31"
86
86
  Blood,Microalbumin,"2019-11-19 14:05:31"
87
87
  Blood,Microprotein,"2019-11-19 14:05:31"
88
88
  Blood,"Von Willebrand Factor","2019-11-19 14:05:31"
89
- Blood,"HIV_viral_load","2021-04-13 00:00:00"
90
- Blood,"Viral laod","2021-04-11 00:00:00"
91
89
  Blood,"Viral Load","2019-11-19 14:05:31"
92
90
  Blood,"Urine Lam","2019-11-19 14:05:31"
93
91
  Blood,"Protein and Sugar","2021-04-16"
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.0.4
4
+ version: 1.1.2
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-06-16 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 5.2.4.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: socket.io-client-simple
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.2.1
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.2.1
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: bcrypt
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +248,8 @@ files:
234
248
  - app/controllers/lab/test_types_controller.rb
235
249
  - app/controllers/lab/tests_controller.rb
236
250
  - app/jobs/lab/application_job.rb
251
+ - app/jobs/lab/update_patient_orders_job.rb
252
+ - app/jobs/lab/void_order_job.rb
237
253
  - app/mailers/lab/application_mailer.rb
238
254
  - app/models/lab/application_record.rb
239
255
  - app/models/lab/lab_accession_number_counter.rb
@@ -251,12 +267,15 @@ files:
251
267
  - app/services/lab/labelling_service/order_label.rb
252
268
  - app/services/lab/lims/api/couchdb_api.rb
253
269
  - app/services/lab/lims/api/mysql_api.rb
270
+ - app/services/lab/lims/api/rest_api.rb
271
+ - app/services/lab/lims/api/ws_api.rb
254
272
  - app/services/lab/lims/config.rb
255
273
  - app/services/lab/lims/exceptions.rb
256
- - app/services/lab/lims/failed_imports.rb
257
274
  - app/services/lab/lims/migrator.rb
258
275
  - app/services/lab/lims/order_dto.rb
259
276
  - app/services/lab/lims/order_serializer.rb
277
+ - app/services/lab/lims/pull_worker.rb
278
+ - app/services/lab/lims/push_worker.rb
260
279
  - app/services/lab/lims/utils.rb
261
280
  - app/services/lab/lims/worker.rb
262
281
  - app/services/lab/metadata.rb
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './api'
4
- require_relative './order_dto'
5
-
6
- module Lab
7
- module Lims
8
- ##
9
- # Manage LIMS orders that failed to import
10
- module FailedImports
11
- class << self
12
- ##
13
- # Retrieve all imports that failed
14
- def failed_imports(start_id = 0, limit = 20)
15
- Lab::LimsFailedImport.where('id >= ?', start_id).limit(limit)
16
- end
17
-
18
- ##
19
- # Forcefully imports a failed import into a patient
20
- def force_import(failed_import_id, _patient_id)
21
- failed_import = Lab::LimsFailedImport.find(failed_import_id)
22
- order_dto = Lab::Lims::OrderDTO.new(lims_api.find_order(failed_import.lims_id))
23
- byebug
24
- end
25
-
26
- private
27
-
28
- def lims_api
29
- @lims_api ||= Lab::Lims::Api.new
30
- end
31
- end
32
- end
33
- end
34
- end