his_emr_api_lab 0.0.7 → 0.0.12

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: 2de242e5fc5982f097e27abb3b4c85ac45b3eb8296ba53bf285ebe8a3422d486
4
- data.tar.gz: '064059e7286ba44485e1707c2be889126776e15125732859bc41c682d4784002'
3
+ metadata.gz: 38f48eba209b710d53ac07d89c95e335f9578a2b2b2137550b8b48f0032355f9
4
+ data.tar.gz: e6930b341721036f4aaeb8ab64551eb1ed4d35e6b80314d181488265e1cda0ba
5
5
  SHA512:
6
- metadata.gz: c2bff8f28b0319d9cb19120704738a5cad5820cc8036abb083666d40d3b5f07d1c9d460b9c5b93bc5c7fe5cf393ac091196d0042bbf50730ad812dc1cad0979e
7
- data.tar.gz: 8c1b11e868f38fcd9c61d275b2bd74783dd698eaaea2ee88d2819b76c944c36972856090a239f7087b3c96a65de7104fd65347ce7128f3c76d799768dbd80253
6
+ metadata.gz: 2f9873af33a53537e59143efd1bf6b36fe5af1201be7cd463c42d14417babfb31640f3a46e12bd5dc73d709fa6075ea619a1faf868143f1f3f9a641341342c85
7
+ data.tar.gz: dbc656255bdb6c160a71771c06532d533ec90f38a6d7e37f5d1880564dcacf874097fe2c5ce424da60602117674135fec6859dda4380f3c4ef20cf4fd3235777
@@ -27,7 +27,7 @@ module Lab
27
27
  '',
28
28
  drawer,
29
29
  '',
30
- specimen,
30
+ tests,
31
31
  reason_for_test,
32
32
  order.accession_number,
33
33
  order.accession_number)
@@ -36,7 +36,7 @@ module Lab
36
36
  def reason_for_test
37
37
  return 'Unknown' unless order.reason_for_test
38
38
 
39
- ConceptName.find_by_concept_id(order.reason_for_test.value_coded)&.name || 'Unknown'
39
+ short_concept_name(order.reason_for_test.value_coded) || 'Unknown'
40
40
  end
41
41
 
42
42
  def patient
@@ -60,11 +60,14 @@ module Lab
60
60
  def drawer
61
61
  return 'N/A' if order.concept_id == unknown_concept.concept_id
62
62
 
63
- name = PersonName.find_by_person_id(order.creator)
64
- return "#{name.given_name} #{name.family_name}" if name
63
+ drawer_id = order.discontinued_by || order.creator
64
+ draw_date = (order.discontinued_date || order.start_date).strftime('%d/%^b/%Y %H:%M:%S')
65
65
 
66
- user = User.find(order.creator)
67
- user&.username || 'N/A'
66
+ name = PersonName.find_by_person_id(drawer_id)
67
+ return "#{name.given_name} #{name.family_name} #{draw_date}" if name
68
+
69
+ user = User.find_by_user_id(drawer_id)
70
+ user ? "#{user.username} #{draw_date}" : 'N/A'
68
71
  end
69
72
 
70
73
  def specimen
@@ -73,6 +76,24 @@ module Lab
73
76
  ConceptName.find_by_concept_id(order.concept_id)&.name || 'Unknown'
74
77
  end
75
78
 
79
+ def tests
80
+ tests = order.tests.map do |test|
81
+ name = short_concept_name(test.value_coded) || 'Unknown'
82
+
83
+ next 'VL' if name.match?(/Viral load/i)
84
+
85
+ name.size > 7 ? name[0..6] : name
86
+ end
87
+
88
+ tests.join(', ')
89
+ end
90
+
91
+ def short_concept_name(concept_id)
92
+ ConceptName.where(concept_id: concept_id)
93
+ .min_by { |concept| concept.name.size }
94
+ &.name
95
+ end
96
+
76
97
  def unknown_concept
77
98
  ConceptName.find_by_name('Unknown')
78
99
  end
@@ -0,0 +1,34 @@
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
@@ -44,7 +44,7 @@ module Lab
44
44
  module Lims
45
45
  module Migrator
46
46
  class MigratorApi < Api
47
- MAX_THREADS = 6
47
+ MAX_THREADS = (ENV.fetch('MIGRATION_WORKERS') { 6 }).to_i
48
48
 
49
49
  attr_reader :rejections
50
50
 
@@ -69,6 +69,10 @@ 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
75
+
72
76
  Utils.parse_date(self['date_created'])
73
77
  end
74
78
 
@@ -66,6 +66,8 @@ module Lab
66
66
  Date.strptime(str_date, '%d-%m-%Y').strftime('%Y-%m-%d')
67
67
  elsif str_date.match?(/(\d{4}\d{2}\d{2})\d+/)
68
68
  Date.strptime(str_date, '%Y%m%d').strftime('%Y-%m-%d')
69
+ elsif str_date.match?(%r{\d{2}/\d{2}/\d{4}})
70
+ str_date.to_date.to_s
69
71
  else
70
72
  Rails.logger.warn("Invalid date: #{str_date}")
71
73
  parse_date(fallback_date)
@@ -28,7 +28,9 @@ module Lab
28
28
  fout.write("Worker ##{Process.pid} started at #{Time.now}")
29
29
  worker = new(Api.new)
30
30
  worker.pull_orders
31
- worker.push_orders
31
+ # TODO: Verify that names being pushed to LIMS are of the correct format (ie matching
32
+ # LIMS naming conventions). Enable pushing when that is done
33
+ # worker.push_orders
32
34
  end
33
35
  end
34
36
 
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.7'
4
+ VERSION = '0.0.12'
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.7
4
+ version: 0.0.12
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-04-27 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchrest
@@ -252,6 +252,7 @@ files:
252
252
  - app/services/lab/lims/api.rb
253
253
  - app/services/lab/lims/config.rb
254
254
  - app/services/lab/lims/exceptions.rb
255
+ - app/services/lab/lims/failed_imports.rb
255
256
  - app/services/lab/lims/migrator.rb
256
257
  - app/services/lab/lims/order_dto.rb
257
258
  - app/services/lab/lims/order_serializer.rb