his_emr_api_lab 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/lab/lims/failed_imports.rb +0 -1
- data/app/services/lab/lims/order_dto.rb +2 -2
- data/app/services/lab/lims/order_serializer.rb +22 -7
- data/app/services/lab/lims/worker.rb +12 -3
- data/db/migrate/20210610095024_fix_numeric_results_value_type.rb +20 -0
- data/lib/lab/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cecc609c02db9bc3bfef3b86458006055944bf3bc7729446490c5375c9ceabd4
|
4
|
+
data.tar.gz: 9992f6d05a17f52c725dc014876a29faadc1b96ba2711f26851e73c917e44e61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d37c96cfad06c9d7c8a62dab06ab9c4a2ecbb7ffed973287d09abfe5f7f3fb9d721ae5f473edc1aab7ba100cf4f525af329f8797e319cfb534f7141e96d12c3
|
7
|
+
data.tar.gz: 2e88ceb111fa7a74be37c78d8b7df7a6b179f28c38ee9824d829097e8568c058ea9996afd2105fff44d61e51aa37184d495f77fd6ed6ee84e3ffd86419cc8e9f
|
@@ -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['
|
86
|
+
return unknown_concept.concept_id unless self['priority']
|
87
87
|
|
88
|
-
ConceptName.find_by_name!(self['
|
88
|
+
ConceptName.find_by_name!(self['priority']).concept_id
|
89
89
|
end
|
90
90
|
|
91
91
|
def lab_program
|
@@ -18,7 +18,7 @@ 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.
|
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),
|
@@ -27,7 +27,7 @@ module Lab
|
|
27
27
|
test_statuses: format_test_status_trail(order),
|
28
28
|
who_order_test: format_orderer(order),
|
29
29
|
districy: current_district, # yes districy [sic]...
|
30
|
-
priority: serialized_order.reason_for_test.name,
|
30
|
+
priority: format_sample_priority(serialized_order.reason_for_test.name),
|
31
31
|
date_created: serialized_order.order_date,
|
32
32
|
test_results: format_test_results(serialized_order),
|
33
33
|
type: 'Order'
|
@@ -69,7 +69,7 @@ module Lab
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def format_sample_type(name)
|
72
|
-
name.casecmp?('Unknown') ? 'not_specified' : name
|
72
|
+
name.casecmp?('Unknown') ? 'not_specified' : name.titleize
|
73
73
|
end
|
74
74
|
|
75
75
|
def format_sample_status(name)
|
@@ -98,8 +98,7 @@ module Lab
|
|
98
98
|
|
99
99
|
def format_test_status_trail(order)
|
100
100
|
order.tests.each_with_object({}) do |test, trail|
|
101
|
-
test_name = ConceptName.find_by_concept_id!(test.value_coded).name
|
102
|
-
test_name = 'Viral load' if test_name.casecmp?('HIV Viral Load')
|
101
|
+
test_name = format_test_name(ConceptName.find_by_concept_id!(test.value_coded).name)
|
103
102
|
|
104
103
|
current_test_trail = trail[test_name] = {}
|
105
104
|
|
@@ -125,9 +124,11 @@ module Lab
|
|
125
124
|
order.tests&.each_with_object({}) do |test, results|
|
126
125
|
next unless test.result
|
127
126
|
|
128
|
-
results[test.name] = {
|
127
|
+
results[format_test_name(test.name)] = {
|
129
128
|
results: test.result.each_with_object({}) do |measure, measures|
|
130
|
-
measures[measure.indicator.name] = {
|
129
|
+
measures[format_test_name(measure.indicator.name)] = {
|
130
|
+
result_value: "#{measure.value_modifier}#{measure.value}"
|
131
|
+
}
|
131
132
|
end,
|
132
133
|
result_date: test.result.first&.date,
|
133
134
|
result_entered_by: {}
|
@@ -135,6 +136,20 @@ module Lab
|
|
135
136
|
end
|
136
137
|
end
|
137
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
|
+
|
138
153
|
def current_health_center
|
139
154
|
health_center = Location.current_health_center
|
140
155
|
raise 'Current health center not set' unless health_center
|
@@ -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 =
|
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
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
|
+
version: 1.0.5
|
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-
|
11
|
+
date: 2021-06-23 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
|