his_emr_api_lab 0.0.15 → 1.0.4

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: 2a7b072fd83de5ea6c03054521d68b82ac2c01237097a8ea9748113b5446a285
4
- data.tar.gz: 5a67e4211a1d0b61d6f8a51357ee2a9fb898bd1c7973d2fc224039451f0a00d1
3
+ metadata.gz: 6142a8351eea3dc6cc2dde34b014948bd95c5d4398355ddc29d2aa0ddff8c095
4
+ data.tar.gz: ca4493c370000ab13cae02629c8cc3ea840f9bf03a70dee35a3f8bc3574e12e3
5
5
  SHA512:
6
- metadata.gz: ea314a6c8598617ae9f8ef0cb272d3258ecc50d60f2226103625edd2a11ae7a49bbb08915816ffe3650c3bd78339db7373ee96b63e0a7072c3a703c2e62ecca7
7
- data.tar.gz: ba1049dbb93d3d842cb31eae9a88e939e0e687e0a2d866432c07713bc670d75c92760dbdd2a22c89f733f00ccc2382b757cd0a4f32563a590fedfe253c6af5a2
6
+ metadata.gz: b18abf5a9f7e00c213ff41bea37c924f7c5abafbfefd5f63727c76093d26e057391ddb047e4a2583fbfdb9d98bd05895387cc6b26aacfe54df4a290cb804f9b9
7
+ data.tar.gz: e7e23b2a1eb5d387855e7acc7e1bd60dcdfca08938245693a07833a6fc43314e1127a9108eaaf8e1536fa3e16acaaa74ecf104d107b3fb71a98ad9b0c4b8a875
@@ -45,10 +45,11 @@ module Lab
45
45
  paths = [
46
46
  "#{ENV['HOME']}/apps/nlims_controller/config/#{filename}",
47
47
  "/var/www/nlims_controller/config/#{filename}",
48
- Rails.root.parent.join("nlims_controller/config/#{filename}"),
49
- Rails.root.join('config/lims-couch.yml')
48
+ Rails.root.parent.join("nlims_controller/config/#{filename}")
50
49
  ]
51
50
 
51
+ paths = [Rails.root.join('config/lims-couchdb.yml'), *paths] if filename == 'couchdb.yml'
52
+
52
53
  paths.each do |path|
53
54
  Rails.logger.debug("Looking for LIMS couchdb config at: #{path}")
54
55
  return path if File.exist?(path)
@@ -83,9 +83,9 @@ module Lab
83
83
 
84
84
  # Translates a LIMS sample priority to a concept_id
85
85
  def reason_for_test
86
- return unknown_concept.concept_id unless self['sample_priority']
86
+ return unknown_concept.concept_id unless self['priority']
87
87
 
88
- ConceptName.find_by_name!(self['sample_priority']).concept_id
88
+ ConceptName.find_by_name!(self['priority']).concept_id
89
89
  end
90
90
 
91
91
  def lab_program
@@ -18,14 +18,16 @@ module Lab
18
18
  tracking_number: serialized_order.accession_number,
19
19
  sending_facility: current_facility_name,
20
20
  receiving_facility: serialized_order.target_lab,
21
- tests: serialized_order.tests.collect(&:name),
21
+ tests: serialized_order.tests.map { |test| format_test_name(test.name) },
22
22
  patient: format_patient(serialized_order.patient_id),
23
23
  order_location: format_order_location(serialized_order.encounter_id),
24
24
  sample_type: format_sample_type(serialized_order.specimen.name),
25
25
  sample_status: format_sample_status(serialized_order.specimen.name),
26
26
  sample_statuses: format_sample_status_trail(order),
27
+ test_statuses: format_test_status_trail(order),
28
+ who_order_test: format_orderer(order),
27
29
  districy: current_district, # yes districy [sic]...
28
- priority: serialized_order.reason_for_test.name,
30
+ priority: format_sample_priority(serialized_order.reason_for_test.name),
29
31
  date_created: serialized_order.order_date,
30
32
  test_results: format_test_results(serialized_order),
31
33
  type: 'Order'
@@ -67,7 +69,7 @@ module Lab
67
69
  end
68
70
 
69
71
  def format_sample_type(name)
70
- name.casecmp?('Unknown') ? 'not_specified' : name
72
+ name.casecmp?('Unknown') ? 'not_specified' : name.titleize
71
73
  end
72
74
 
73
75
  def format_sample_status(name)
@@ -75,9 +77,7 @@ module Lab
75
77
  end
76
78
 
77
79
  def format_sample_status_trail(order)
78
- if order.concept_id == ConceptName.find_by_name!('Unknown').concept_id
79
- return []
80
- end
80
+ return [] if order.concept_id == ConceptName.find_by_name!('Unknown').concept_id
81
81
 
82
82
  user = User.find(order.discontinued_by || order.creator)
83
83
  drawn_by = PersonName.find_by_person_id(user.user_id)
@@ -96,13 +96,39 @@ module Lab
96
96
  ]
97
97
  end
98
98
 
99
+ def format_test_status_trail(order)
100
+ order.tests.each_with_object({}) do |test, trail|
101
+ test_name = format_test_name(ConceptName.find_by_concept_id!(test.value_coded).name)
102
+
103
+ current_test_trail = trail[test_name] = {}
104
+
105
+ current_test_trail[test.obs_datetime.strftime('%Y%m%d%H%M%S')] = {
106
+ status: 'Drawn',
107
+ updated_by: find_user(test.creator)
108
+ }
109
+
110
+ next unless test.result
111
+
112
+ current_test_trail[test.obs_datetime.strftime('%Y%m%d%H%M%S')] = {
113
+ status: 'Verified',
114
+ updated_by: find_user(test.result.creator)
115
+ }
116
+ end
117
+ end
118
+
119
+ def format_orderer(order)
120
+ find_user(order.creator)
121
+ end
122
+
99
123
  def format_test_results(order)
100
124
  order.tests&.each_with_object({}) do |test, results|
101
125
  next unless test.result
102
126
 
103
- results[test.name] = {
127
+ results[format_test_name(test.name)] = {
104
128
  results: test.result.each_with_object({}) do |measure, measures|
105
- measures[measure.indicator.name] = { result_value: "#{measure.value_modifier}#{measure.value}" }
129
+ measures[format_test_name(measure.indicator.name)] = {
130
+ result_value: "#{measure.value_modifier}#{measure.value}"
131
+ }
106
132
  end,
107
133
  result_date: test.result.first&.date,
108
134
  result_entered_by: {}
@@ -110,6 +136,20 @@ module Lab
110
136
  end
111
137
  end
112
138
 
139
+ def format_test_name(test_name)
140
+ return 'Viral Load' if test_name.casecmp?('HIV Viral load')
141
+
142
+ return 'TB' if test_name.casecmp?('TB Program')
143
+
144
+ test_name.titleize
145
+ end
146
+
147
+ def format_sample_priority(priority)
148
+ return 'Routine' if priority&.casecmp?('Medical examination, routine')
149
+
150
+ priority&.titleize
151
+ end
152
+
113
153
  def current_health_center
114
154
  health_center = Location.current_health_center
115
155
  raise 'Current health center not set' unless health_center
@@ -134,6 +174,20 @@ module Lab
134
174
  def current_facility_name
135
175
  current_health_center.name
136
176
  end
177
+
178
+ def find_user(user_id)
179
+ user = User.find(user_id)
180
+ person_name = PersonName.find_by(person_id: user.person_id)
181
+ phone_number = PersonAttribute.find_by(type: PersonAttributeType.where(name: 'Cell phone number'),
182
+ person_id: user.person_id)
183
+
184
+ {
185
+ first_name: person_name&.given_name,
186
+ last_name: person_name&.family_name,
187
+ phone_number: phone_number&.value,
188
+ id: user.username
189
+ }
190
+ end
137
191
  end
138
192
  end
139
193
  end
@@ -26,11 +26,11 @@ module Lab
26
26
  User.current = Utils.lab_user
27
27
 
28
28
  fout.write("Worker ##{Process.pid} started at #{Time.now}")
29
- worker = new(CouchDbApi.new)
29
+ worker = new(Api::CouchDbApi.new)
30
30
  worker.pull_orders
31
31
  # TODO: Verify that names being pushed to LIMS are of the correct format (ie matching
32
32
  # LIMS naming conventions). Enable pushing when that is done
33
- # worker.push_orders
33
+ worker.push_orders
34
34
  end
35
35
  end
36
36
 
@@ -209,7 +209,7 @@ module Lab
209
209
  raise MissingAccessionNumber if order_dto[:tracking_number].blank?
210
210
 
211
211
  logger.info("Importing LIMS order ##{order_dto[:tracking_number]}")
212
- mapping = LimsOrderMapping.find_by(lims_id: order_dto[:_id])
212
+ mapping = find_order_mapping_by_lims_id(order_dto[:_id])
213
213
 
214
214
  ActiveRecord::Base.transaction do
215
215
  if mapping
@@ -221,7 +221,6 @@ module Lab
221
221
  order_id: order['id'],
222
222
  pulled_at: Time.now,
223
223
  revision: order_dto['_rev'])
224
- byebug unless mapping.errors.empty?
225
224
  end
226
225
 
227
226
  order
@@ -313,7 +312,7 @@ module Lab
313
312
  end
314
313
 
315
314
  def guess_result_datatype(result)
316
- return 'numeric' if result.strip.match?(/^[+-]?(\d+(\.\d+)|\.\d+)?$/)
315
+ return 'numeric' if result.strip.match?(/^[+-]?((\d+(\.\d+)?)|\.\d+)$/)
317
316
 
318
317
  'text'
319
318
  end
@@ -339,6 +338,16 @@ module Lab
339
338
  def last_seq_path
340
339
  LIMS_LOG_PATH.join('last_seq.dat')
341
340
  end
341
+
342
+ def find_order_mapping_by_lims_id(lims_id)
343
+ mapping = Lab::LimsOrderMapping.find_by(lims_id: lims_id)
344
+ return nil unless mapping
345
+
346
+ return mapping if Lab::LabOrder.where(order_id: mapping.order_id).exists?
347
+
348
+ mapping.destroy
349
+ nil
350
+ end
342
351
  end
343
352
  end
344
353
  end
@@ -0,0 +1,20 @@
1
+ class FixNumericResultsValueType < ActiveRecord::Migration[5.2]
2
+ def up
3
+ results = Lab::LabResult.all.includes(:children)
4
+
5
+ ActiveRecord::Base.connection.transaction do
6
+ results.each do |result|
7
+ result.children.each do |measure|
8
+ next unless measure.value_text&.match?(/^[+-]?((\d+(\.\d+)?)|\.\d+)$/)
9
+
10
+ puts "Updating result value type for result measure ##{measure.obs_id}"
11
+ measure.value_numeric = measure.value_text
12
+ measure.value_text = nil
13
+ measure.save!
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def down; end
20
+ 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 = '0.0.15'
4
+ VERSION = '1.0.4'
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: 0.0.15
4
+ version: 1.0.4
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-05-21 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -270,6 +270,7 @@ files:
270
270
  - db/migrate/20210323080140_change_lims_id_to_string_in_lims_order_mapping.rb
271
271
  - db/migrate/20210326195504_add_order_revision_to_lims_order_mapping.rb
272
272
  - db/migrate/20210407071728_create_lab_lims_failed_imports.rb
273
+ - db/migrate/20210610095024_fix_numeric_results_value_type.rb
273
274
  - lib/auto12epl.rb
274
275
  - lib/couch_bum/couch_bum.rb
275
276
  - lib/generators/lab/install/USAGE