his_emr_api_lab 0.0.8 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b410e215fad55950c150d2ec7a82bda3f434cca4cc287e0d4fca2a9116e9182
4
- data.tar.gz: 6b3a0c75c303c2139c1f6f963875667c4606bce42d23f6a22c277412e24db960
3
+ metadata.gz: '00645812f301ba486329bfe76c91406af972fb152d9b08be82ca09bedb1715a2'
4
+ data.tar.gz: 9c1f1136ed92e903059e40adb0c66aa6f4ed7057fce3d71e70b973655df08679
5
5
  SHA512:
6
- metadata.gz: 4f6068aecbc02d5c3df75ac422c4d4f9baeac86c6559a1e75078ef68088b4e6702239a366fb5e5879a2925592e3440a2880668bcc50f4730c9d2051f522ac94a
7
- data.tar.gz: 5e3b4d61f507f2de7847951dcdd738a50dd29ba4ae5f981ce8284f3ba11c35d6d1c337787c1b78154b96eb318fc5343d404a3827fd02c89ffc3da60eb2d617c3
6
+ metadata.gz: 5894ad876b761667077801c771b39d4f8dd7347a0cebe10886c513d6d2c9401dec7296c6dbf66788f5e2ceff05b15368de96c1c49a4223a560c1f44e5154ea95
7
+ data.tar.gz: c85f640154e2612b0b3943cc2332f7de7ee65db3a8401a241c55e53d9061cadb5ea24e69a4ca9d4a647f6468a6d5fa6160e2a8126d0e68865f551cab85e1e2c3
@@ -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
@@ -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)
@@ -139,9 +139,17 @@ module Lab
139
139
  def find_patient_by_nhid(nhid)
140
140
  national_id_type = PatientIdentifierType.where(name: ['National id', 'Old Identification Number'])
141
141
  identifiers = PatientIdentifier.where(type: national_id_type, identifier: nhid)
142
+ .joins('INNER JOIN person ON person.person_id = patient_identifier.patient_id AND person.voided = 0')
142
143
  if identifiers.count.zero?
143
- identifiers = PatientIdentifier.unscoped.where(voided: 1, type: national_id_type, identifier: nhid)
144
+ identifiers = PatientIdentifier.unscoped
145
+ .where(voided: 1, type: national_id_type, identifier: nhid)
146
+ .joins('INNER JOIN person ON person.person_id = patient_identifier.patient_id AND person.voided = 0')
144
147
  end
148
+
149
+ # Joining to person above to ensure that the person is not voided,
150
+ # it was noted at one site that there were some people that were voided
151
+ # upon merging but the patient and patient_identifier was not voided
152
+
145
153
  return nil if identifiers.count.zero?
146
154
 
147
155
  patients = Patient.where(patient_id: identifiers.select(:patient_id))
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.8'
4
+ VERSION = '0.0.13'
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.8
4
+ version: 0.0.13
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-05-01 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