his_emr_api_lab 1.1.20 → 1.1.21
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 +4 -4
- data/app/controllers/lab/results_controller.rb +1 -1
- data/app/services/lab/lims/api/rest_api.rb +3 -0
- data/app/services/lab/lims/order_serializer.rb +28 -0
- data/app/services/lab/lims/pull_worker.rb +4 -4
- data/app/services/lab/results_service.rb +27 -2
- data/lib/lab/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e14a15d54b4c2e4f38b5a8a93a91c6e2c9c159abcc26b89defa3a535822ef2a6
|
4
|
+
data.tar.gz: b3669866f7747eeead4e5d7b3595431474d7b78177527db1bd80f96bfa035280
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82efc08842fafa54aaf212a5852977e3cba393c3ac398d76310125dc26b5e6b4cc34a80686fa567039f09a9a9d2a1d0252ca48c3b14e8f0f3a0d7e506232dca0
|
7
|
+
data.tar.gz: fe78bc7e8defe9e562da0b8a05b08a7dbc69deda63780e92393d92e42af624602fc745861557319d85681d15f1170113cb9d9bc3bc973bd7277fe28e8fd5edc7
|
@@ -11,7 +11,7 @@ module Lab
|
|
11
11
|
:value_modifier,
|
12
12
|
{ indicator: [:concept_id] }] }])
|
13
13
|
|
14
|
-
result = Lab::ResultsService.create_results(params[:test_id], result_params)
|
14
|
+
result = Lab::ResultsService.create_results(params[:test_id], result_params, 'user entered')
|
15
15
|
|
16
16
|
render json: result, status: :created
|
17
17
|
end
|
@@ -188,6 +188,9 @@ class Lab::Lims::Api::RestApi
|
|
188
188
|
last_name: order_dto.fetch(:patient).fetch(:last_name),
|
189
189
|
phone_number: order_dto.fetch(:patient).fetch(:phone_number),
|
190
190
|
gender: order_dto.fetch(:patient).fetch(:gender),
|
191
|
+
arv_number: order_dto.fetch(:patient).fetch(:arv_number),
|
192
|
+
art_regimen: order_dto.fetch(:patient).fetch(:art_regimen),
|
193
|
+
art_start_date: order_dto.fetch(:patient).fetch(:art_start_date),
|
191
194
|
national_patient_id: order_dto.fetch(:patient).fetch(:id),
|
192
195
|
requesting_clinician: requesting_clinician(order_dto),
|
193
196
|
sample_type: order_dto.fetch(:sample_type),
|
@@ -64,12 +64,40 @@ module Lab
|
|
64
64
|
first_name: name&.given_name,
|
65
65
|
last_name: name&.family_name,
|
66
66
|
id: national_id&.identifier,
|
67
|
+
arv_number: find_arv_number(patient_id),
|
68
|
+
art_regimen: find_current_regimen(patient_id),
|
69
|
+
art_start_date: find_art_start_date(patient_id),
|
67
70
|
phone_number: phone_number&.value || 'Unknown',
|
68
71
|
gender: person.gender,
|
69
72
|
email: nil
|
70
73
|
}
|
71
74
|
end
|
72
75
|
|
76
|
+
def find_current_regimen(patient_id)
|
77
|
+
regimen_data = ActiveRecord::Base.connection.select_one <<~SQL
|
78
|
+
SELECT patient_current_regimen(#{patient_id}, current_date()) regimen
|
79
|
+
SQL
|
80
|
+
return nil if regimen_data.blank?
|
81
|
+
|
82
|
+
regimen_data['regimen']
|
83
|
+
end
|
84
|
+
|
85
|
+
def find_arv_number(patient_id)
|
86
|
+
PatientIdentifier.joins(:type)
|
87
|
+
.merge(PatientIdentifierType.where(name: 'ARV Number'))
|
88
|
+
.where(patient_id: patient_id)
|
89
|
+
.first&.identifier
|
90
|
+
end
|
91
|
+
|
92
|
+
def find_art_start_date(patient_id)
|
93
|
+
start_date = ActiveRecord::Base.connection.select_one <<~SQL
|
94
|
+
SELECT date_antiretrovirals_started(#{patient_id}, current_date()) AS earliest_date
|
95
|
+
SQL
|
96
|
+
return nil if start_date.blank?
|
97
|
+
|
98
|
+
start_date['earliest_date']
|
99
|
+
end
|
100
|
+
|
73
101
|
def format_sample_type(name)
|
74
102
|
return 'not_specified' if name.casecmp?('Unknown')
|
75
103
|
|
@@ -204,10 +204,10 @@ module Lab
|
|
204
204
|
|
205
205
|
creator = format_result_entered_by(test_results['result_entered_by'])
|
206
206
|
|
207
|
-
ResultsService.create_results(test.id, provider_id: User.current.person_id,
|
208
|
-
|
209
|
-
|
210
|
-
|
207
|
+
ResultsService.create_results(test.id, { provider_id: User.current.person_id,
|
208
|
+
date: Utils.parse_date(test_results['date_result_entered'], order[:order_date].to_s),
|
209
|
+
comments: "LIMS import: Entered by: #{creator}",
|
210
|
+
measures: measures } )
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -15,7 +15,10 @@ module Lab
|
|
15
15
|
# - measures: An array of measures. A measure is an object of the following structure
|
16
16
|
# - indicator: An object that has a concept_id field (concept_id of the indicator)
|
17
17
|
# - value_type: An enum that's limited to 'numeric', 'boolean', 'text', and 'coded'
|
18
|
-
|
18
|
+
# result_enter_by: A string that specifies who created the result
|
19
|
+
def create_results(test_id, params, result_enter_by = 'LIMS')
|
20
|
+
serializer = {}
|
21
|
+
results_obs = {}
|
19
22
|
ActiveRecord::Base.transaction do
|
20
23
|
test = Lab::LabTest.find(test_id)
|
21
24
|
encounter = find_encounter(test, encounter_id: params[:encounter_id],
|
@@ -24,13 +27,34 @@ module Lab
|
|
24
27
|
|
25
28
|
results_obs = create_results_obs(encounter, test, params[:date], params[:comments])
|
26
29
|
params[:measures].map { |measure| add_measure_to_results(results_obs, measure, params[:date]) }
|
30
|
+
OrderExtension.create!(creator: User.current, value: result_enter_by, order_id: results_obs.order_id,
|
31
|
+
date_created: Time.now)
|
27
32
|
|
28
|
-
Lab::ResultSerializer.serialize(results_obs)
|
33
|
+
serializer = Lab::ResultSerializer.serialize(results_obs)
|
29
34
|
end
|
35
|
+
NotificationService.new.create_notification(result_enter_by, prepare_notification_message(results_obs, serializer, result_enter_by))
|
36
|
+
Rails.logger.info("Lab::ResultsService: Result created for test #{test_id} #{serializer}")
|
37
|
+
serializer
|
30
38
|
end
|
31
39
|
|
32
40
|
private
|
33
41
|
|
42
|
+
def prepare_notification_message(result, values, result_enter_by)
|
43
|
+
{ Type: result_enter_by,
|
44
|
+
'Test type': ConceptName.find_by(concept_id: result.test.value_coded)&.name,
|
45
|
+
'Accession number': Order.find(result.order_id)&.accession_number,
|
46
|
+
'ARV-Number': find_arv_number(result.person_id),
|
47
|
+
PatientID: result.person_id,
|
48
|
+
Result: values }.as_json
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_arv_number(patient_id)
|
52
|
+
PatientIdentifier.joins(:type)
|
53
|
+
.merge(PatientIdentifierType.where(name: 'ARV Number'))
|
54
|
+
.where(patient_id: patient_id)
|
55
|
+
.first&.identifier
|
56
|
+
end
|
57
|
+
|
34
58
|
def find_encounter(test, encounter_id: nil, date: nil, provider_id: nil)
|
35
59
|
return Encounter.find(encounter_id) if encounter_id
|
36
60
|
|
@@ -64,6 +88,7 @@ module Lab
|
|
64
88
|
obs_group_id: test.obs_id)
|
65
89
|
return unless result
|
66
90
|
|
91
|
+
OrderExtension.find_by(order_id: result.order_id)&.void("Updated/overwritten by #{User.current.username}")
|
67
92
|
result.measures.map { |child_obs| child_obs.void("Updated/overwritten by #{User.current.username}") }
|
68
93
|
result.void("Updated/overwritten by #{User.current.username}")
|
69
94
|
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.1.
|
4
|
+
version: 1.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elizabeth Glaser Pediatric Foundation Malawi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: couchrest
|
@@ -319,7 +319,7 @@ licenses:
|
|
319
319
|
- MIT
|
320
320
|
metadata:
|
321
321
|
source_code_uri: https://github.com/EGPAFMalawiHIS/his_emr_api_lab
|
322
|
-
post_install_message:
|
322
|
+
post_install_message:
|
323
323
|
rdoc_options: []
|
324
324
|
require_paths:
|
325
325
|
- lib
|
@@ -334,8 +334,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
334
|
- !ruby/object:Gem::Version
|
335
335
|
version: '0'
|
336
336
|
requirements: []
|
337
|
-
|
338
|
-
|
337
|
+
rubyforge_project:
|
338
|
+
rubygems_version: 2.7.6
|
339
|
+
signing_key:
|
339
340
|
specification_version: 4
|
340
341
|
summary: Lab extension for the HIS-EMR-API
|
341
342
|
test_files: []
|