mahis_emr_api_lab 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +71 -0
  4. data/Rakefile +32 -0
  5. data/app/controllers/lab/application_controller.rb +6 -0
  6. data/app/controllers/lab/labels_controller.rb +17 -0
  7. data/app/controllers/lab/orders_controller.rb +78 -0
  8. data/app/controllers/lab/reasons_for_test_controller.rb +9 -0
  9. data/app/controllers/lab/results_controller.rb +20 -0
  10. data/app/controllers/lab/specimen_types_controller.rb +15 -0
  11. data/app/controllers/lab/test_result_indicators_controller.rb +9 -0
  12. data/app/controllers/lab/test_types_controller.rb +15 -0
  13. data/app/controllers/lab/tests_controller.rb +25 -0
  14. data/app/controllers/lab/users_controller.rb +32 -0
  15. data/app/jobs/lab/application_job.rb +4 -0
  16. data/app/jobs/lab/push_order_job.rb +12 -0
  17. data/app/jobs/lab/update_patient_orders_job.rb +32 -0
  18. data/app/jobs/lab/void_order_job.rb +17 -0
  19. data/app/mailers/lab/application_mailer.rb +6 -0
  20. data/app/models/lab/application_record.rb +5 -0
  21. data/app/models/lab/lab_accession_number_counter.rb +13 -0
  22. data/app/models/lab/lab_acknowledgement.rb +6 -0
  23. data/app/models/lab/lab_encounter.rb +7 -0
  24. data/app/models/lab/lab_order.rb +58 -0
  25. data/app/models/lab/lab_result.rb +31 -0
  26. data/app/models/lab/lab_test.rb +19 -0
  27. data/app/models/lab/lims_failed_import.rb +4 -0
  28. data/app/models/lab/lims_order_mapping.rb +10 -0
  29. data/app/models/lab/order_extension.rb +14 -0
  30. data/app/serializers/lab/lab_order_serializer.rb +56 -0
  31. data/app/serializers/lab/result_serializer.rb +36 -0
  32. data/app/serializers/lab/test_serializer.rb +52 -0
  33. data/app/services/lab/accession_number_service.rb +77 -0
  34. data/app/services/lab/acknowledgement_service.rb +47 -0
  35. data/app/services/lab/concepts_service.rb +82 -0
  36. data/app/services/lab/json_web_token_service.rb +20 -0
  37. data/app/services/lab/labelling_service/order_label.rb +106 -0
  38. data/app/services/lab/lims/acknowledgement_serializer.rb +29 -0
  39. data/app/services/lab/lims/acknowledgement_worker.rb +37 -0
  40. data/app/services/lab/lims/api/blackhole_api.rb +21 -0
  41. data/app/services/lab/lims/api/couchdb_api.rb +53 -0
  42. data/app/services/lab/lims/api/mysql_api.rb +316 -0
  43. data/app/services/lab/lims/api/rest_api.rb +434 -0
  44. data/app/services/lab/lims/api/ws_api.rb +121 -0
  45. data/app/services/lab/lims/api_factory.rb +19 -0
  46. data/app/services/lab/lims/config.rb +105 -0
  47. data/app/services/lab/lims/exceptions.rb +11 -0
  48. data/app/services/lab/lims/migrator.rb +216 -0
  49. data/app/services/lab/lims/order_dto.rb +105 -0
  50. data/app/services/lab/lims/order_serializer.rb +251 -0
  51. data/app/services/lab/lims/pull_worker.rb +314 -0
  52. data/app/services/lab/lims/push_worker.rb +152 -0
  53. data/app/services/lab/lims/utils.rb +91 -0
  54. data/app/services/lab/lims/worker.rb +94 -0
  55. data/app/services/lab/metadata.rb +26 -0
  56. data/app/services/lab/notification_service.rb +72 -0
  57. data/app/services/lab/orders_search_service.rb +72 -0
  58. data/app/services/lab/orders_service.rb +330 -0
  59. data/app/services/lab/results_service.rb +166 -0
  60. data/app/services/lab/tests_service.rb +105 -0
  61. data/app/services/lab/user_service.rb +62 -0
  62. data/config/routes.rb +28 -0
  63. data/db/migrate/20210126092910_create_lab_lab_accession_number_counters.rb +12 -0
  64. data/db/migrate/20210310115457_create_lab_lims_order_mappings.rb +15 -0
  65. data/db/migrate/20210323080140_change_lims_id_to_string_in_lims_order_mapping.rb +15 -0
  66. data/db/migrate/20210326195504_add_order_revision_to_lims_order_mapping.rb +5 -0
  67. data/db/migrate/20210407071728_create_lab_lims_failed_imports.rb +19 -0
  68. data/db/migrate/20210610095024_fix_numeric_results_value_type.rb +20 -0
  69. data/db/migrate/20210807111531_add_default_to_lims_order_mapping.rb +7 -0
  70. data/lib/auto12epl.rb +201 -0
  71. data/lib/couch_bum/couch_bum.rb +92 -0
  72. data/lib/generators/lab/install/USAGE +9 -0
  73. data/lib/generators/lab/install/install_generator.rb +19 -0
  74. data/lib/generators/lab/install/templates/rswag-ui-lab.rb +5 -0
  75. data/lib/generators/lab/install/templates/start_worker.rb +32 -0
  76. data/lib/generators/lab/install/templates/swagger.yaml +714 -0
  77. data/lib/lab/engine.rb +13 -0
  78. data/lib/lab/version.rb +5 -0
  79. data/lib/logger_multiplexor.rb +38 -0
  80. data/lib/mahis_emr_api_lab.rb +6 -0
  81. data/lib/tasks/lab_tasks.rake +25 -0
  82. data/lib/tasks/loaders/data/reasons-for-test.csv +7 -0
  83. data/lib/tasks/loaders/data/test-measures.csv +225 -0
  84. data/lib/tasks/loaders/data/tests.csv +161 -0
  85. data/lib/tasks/loaders/loader_mixin.rb +53 -0
  86. data/lib/tasks/loaders/metadata_loader.rb +26 -0
  87. data/lib/tasks/loaders/reasons_for_test_loader.rb +23 -0
  88. data/lib/tasks/loaders/specimens_loader.rb +65 -0
  89. data/lib/tasks/loaders/test_result_indicators_loader.rb +54 -0
  90. metadata +331 -0
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab
4
+ VERSION = '1.2.0'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # Log to multiple streams.
5
+ #
6
+ # The 'logger' module does not provide a logger that can log
7
+ # to multiple streams at once hence this hack. This class
8
+ # bundles multiple loggers so that they can be treated as
9
+ # one.
10
+ #
11
+ # Example:
12
+ # >>> logger = LoggerMultiplexor.new(STDOUT, 'development.log')
13
+ # >>> logger.info('Hello') # Logs 'Hello' to both streams
14
+ class LoggerMultiplexor
15
+ def initialize(*loggers)
16
+ @loggers = loggers.map do |stream|
17
+ if stream.is_a?(Logger) || stream.is_a?(LoggerMultiplexor)
18
+ stream
19
+ else
20
+ Logger.new(stream)
21
+ end
22
+ end
23
+ end
24
+
25
+ def method_missing(method_name, *args)
26
+ if respond_to_missing?(method_name)
27
+ @loggers.each { |logger| logger.send(method_name, *args) }
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def respond_to_missing?(method_name)
34
+ @loggers.all? do |logger|
35
+ logger.respond_to?(method_name)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ require 'lab/engine'
2
+ require 'lab/version'
3
+
4
+ module Lab
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,25 @@
1
+ desc 'Generate openapi/swagger documentation template in engine'
2
+ task :swag, ['app:rswag:specs:swaggerize'] do
3
+ source = 'spec/dummy/swagger/v1/swagger.yaml'
4
+ destination = 'lib/generators/lab/install/templates/swagger.yaml'
5
+
6
+ FileUtils.copy(source, destination)
7
+ end
8
+
9
+ namespace :lab do
10
+ desc 'Install Lab engine into container application'
11
+ task :install do
12
+ sh 'rails generate lab:install'
13
+ sh 'rake lab:install:migrations'
14
+ end
15
+
16
+ desc 'Uninstall Lab engine from container application'
17
+ task :uninstall do
18
+ sh 'rails destroy lab:install'
19
+ end
20
+
21
+ desc 'Load Lab metadata into database'
22
+ task :load_metadata do
23
+ sh "rails r #{__dir__}/loaders/metadata_loader.rb"
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ "reason_name"
2
+ "Routine"
3
+ "Repeat / Missing"
4
+ "Targeted"
5
+ "Confirmatory"
6
+ "Stat"
7
+ "Other"
@@ -0,0 +1,225 @@
1
+ "test_name","measure_name"
2
+ "TB Microscopic Exam","tb"
3
+ "GeneXpert","MTB"
4
+ "GeneXpert","RIF Resistance"
5
+ "Gram Stain","Gram"
6
+ "Gram Stain","Clue cells"
7
+ "Gram Stain","Other organism seen"
8
+ "Culture & Sensitivity","Culture"
9
+ "Cell Count","WBC"
10
+ "Cell Count","RBC"
11
+ "India Ink","India ink"
12
+ "Differential","Polymorphs"
13
+ "Differential","Lymphocytes"
14
+ "Differential","Diff remarks"
15
+ "ZN Stain","ZN"
16
+ "Wet prep","wet prep"
17
+ "Wet prep","Other organism seen"
18
+ "TB Tests","Macro exam"
19
+ "TB Tests","Smear microscopy result"
20
+ "TB Tests","Gene Xpert MTB"
21
+ "TB Tests","Gene Xpert RIF Resistance"
22
+ "TB Tests","HIV Status"
23
+ "TB Tests","Reason For Testing"
24
+ "TB Tests","Indication for GeneXpert Test"
25
+ "Urine Macroscopy","Colour"
26
+ "Urine Macroscopy","Appearance"
27
+ "Urine Microscopy","WBC"
28
+ "Urine Microscopy","RBC"
29
+ "Urine Microscopy","Epithelial cells"
30
+ "Urine Microscopy","Casts"
31
+ "Urine Microscopy","Crystals"
32
+ "Urine Microscopy","Parasites"
33
+ "Urine Microscopy","Yeast cells"
34
+ "Urine Chemistries","pH"
35
+ "Urine Chemistries","Blood"
36
+ "Urine Chemistries","Urobilinogen"
37
+ "Urine Chemistries","Bilirubin"
38
+ "Urine Chemistries","Protein"
39
+ "Urine Chemistries","Nitrate"
40
+ "Urine Chemistries","Ketones"
41
+ "Urine Chemistries","Glucose"
42
+ "Urine Chemistries","Specific gravity"
43
+ "Urine Chemistries","Leucocytes"
44
+ "Stool Analysis","Macroscopy"
45
+ "Stool Analysis","Consistency"
46
+ "Stool Analysis","Microscopy"
47
+ "Malaria Screening","Blood film"
48
+ "Malaria Screening","Malaria Species"
49
+ "Malaria Screening","MRDT"
50
+ "Blood Parasites Screen","Blood film"
51
+ "Semen Analysis","Progressive motility"
52
+ "Semen Analysis","Non-progressive motility"
53
+ "Semen Analysis","Immotility"
54
+ "Semen Analysis","Appearance"
55
+ "Semen Analysis","Liquifaction time"
56
+ "Semen Analysis","volume"
57
+ "Semen Analysis","pH"
58
+ "Semen Analysis","Sperm count"
59
+ "Semen Analysis","Sperm morphology"
60
+ "HVS analysis","Macroscopy"
61
+ "HVS analysis","WBC"
62
+ "HVS analysis","Epithelial cells"
63
+ "HVS analysis","Parasites/Bacteria"
64
+ "HVS analysis","Spermatozoa"
65
+ "Syphilis Test","RPR"
66
+ "Syphilis Test","VDRL"
67
+ "Syphilis Test","TPHA"
68
+ "Hepatitis B Test","Hepatitis B"
69
+ "Hepatitis C Test","Hepatitis C"
70
+ "Rheumatoid Factor Test","Rheumatoid Factor"
71
+ "CrAg","CrAg"
72
+ "Cryptococcus Antigen Test","CrAg"
73
+ "Anti Streptolysis O","ASO"
74
+ "C-reactive protein","CRP"
75
+ "Measles","Measles IgM ELISA-Behring enzygnost"
76
+ "Rubella","Rubella IgM ELISA-Behring enzynost"
77
+ "CD4","CD4 Count"
78
+ "CD4","CD4 %"
79
+ "CD4","Lymphocyte Count"
80
+ "CD4","CD8 Count"
81
+ "CD4","CD3 Count"
82
+ "ABO Blood Grouping","Grouping"
83
+ "Cross-match","Pack No."
84
+ "Cross-match","Pack ABO Group"
85
+ "Cross-match","Product Type"
86
+ "Cross-match","Expiry Date"
87
+ "Cross-match","Volume"
88
+ "Cross-match","Cross-match Method"
89
+ "Transfusion Outcome","Outcome"
90
+ "Liver Function Tests","ALT/GPT"
91
+ "Liver Function Tests","AST/GOT"
92
+ "Liver Function Tests","Alkaline Phosphate(ALP)"
93
+ "Liver Function Tests","GGT/r-GT"
94
+ "Liver Function Tests","Bilirubin Direct(BID)"
95
+ "Liver Function Tests","Bilirubin Total(BIT))"
96
+ "Liver Function Tests","Albumin(ALB)"
97
+ "Liver Function Tests","Total Protein(PRO)"
98
+ "Renal Function Test","Urea"
99
+ "Renal Function Test","Creatinine"
100
+ "Lipogram","Triglycerides(TG)"
101
+ "Lipogram","Cholestero l(CHOL)"
102
+ "Lipogram","HDL Direct (HDL-C)"
103
+ "Lipogram","LDL Direct (LDL-C)"
104
+ "FBC","WBC"
105
+ "FBC","RBC"
106
+ "FBC","HGB"
107
+ "FBC","HCT"
108
+ "FBC","MCV"
109
+ "FBC","MCH"
110
+ "FBC","MCHC"
111
+ "FBC","PLT"
112
+ "FBC","RDW-SD"
113
+ "FBC","RDW-CV"
114
+ "FBC","PDW"
115
+ "FBC","MPV"
116
+ "FBC","PCT"
117
+ "FBC","NEUT%"
118
+ "FBC","LYMPH%"
119
+ "FBC","MONO%"
120
+ "FBC","EO%"
121
+ "FBC","BASO%"
122
+ "FBC","NEUT#"
123
+ "FBC","LYMPH#"
124
+ "FBC","MONO#"
125
+ "FBC","EO#"
126
+ "FBC","BASO#"
127
+ "FBC","Mid#"
128
+ "FBC","Gran#"
129
+ "FBC","Mid%"
130
+ "FBC","Gran%"
131
+ "FBC","EOS%"
132
+ "FBC","P-LCC"
133
+ "FBC","P-LCR"
134
+ "Electrolytes","K"
135
+ "Electrolytes","Na"
136
+ "Electrolytes","Cl"
137
+ "Enzymes","a-AMYLASE-H"
138
+ "Enzymes","ALT-H"
139
+ "Enzymes","AST-H"
140
+ "Enzymes","ALP-H"
141
+ "Enzymes","TP-H"
142
+ "Enzymes","TC-H"
143
+ "Enzymes","UREA-H"
144
+ "Enzymes","GLU-O-H"
145
+ "Enzymes","TBIL-DSA-H"
146
+ "Enzymes","DBIL-DSA-H"
147
+ "Enzymes","UA-H"
148
+ "Enzymes","TG-H"
149
+ "Enzymes","ALB-H"
150
+ "Glucose","Glucose"
151
+ "Prothrombin Time","PT"
152
+ "APTT","APTT"
153
+ "INR","INR"
154
+ "ESR","ESR"
155
+ "Sickling Test","Sickling Screen"
156
+ "Pregnancy Test","Pregnancy Test"
157
+ "Manual Differential & Cell Morphology","Nucleated Red Cells"
158
+ "Manual Differential & Cell Morphology","Neutrophils"
159
+ "Manual Differential & Cell Morphology","Lymphocytes"
160
+ "Manual Differential & Cell Morphology","Monocytes"
161
+ "Manual Differential & Cell Morphology","Eosinophils"
162
+ "Manual Differential & Cell Morphology","Basophils"
163
+ "Manual Differential & Cell Morphology","Promyelocytes"
164
+ "Manual Differential & Cell Morphology","Myelocytes"
165
+ "Manual Differential & Cell Morphology","Metamyelocytes"
166
+ "Manual Differential & Cell Morphology","Band/Staff Forms"
167
+ "Manual Differential & Cell Morphology","Blasts"
168
+ "Manual Differential & Cell Morphology","Other"
169
+ "Manual Differential & Cell Morphology","RBC Comments"
170
+ "Manual Differential & Cell Morphology","WBC Comments"
171
+ "Manual Differential & Cell Morphology","Platelet Comments"
172
+ "Manual Differential & Cell Morphology","Interpretative Comments"
173
+ "Manual Differential & Cell Morphology","Attempted/ Differential Diagnosis"
174
+ "Manual Differential & Cell Morphology","Further Tests"
175
+ "Pancreatic Function Test","Amylase"
176
+ "Pancreatic Function Test","Lipase"
177
+ "Direct Coombs Test","Direct Coombs Test"
178
+ "Calcium","Ca"
179
+ "Phosphorus","P"
180
+ "Magnesium","Mg"
181
+ "Creatinine Kinase","CK"
182
+ "Uric Acid","UA"
183
+ "ESBL Test","ESBL"
184
+ "ESBL Test","Cefotaxime"
185
+ "ESBL Test","Cefotaxime + Clavulanate"
186
+ "ESBL Test","Ceftazidime"
187
+ "ESBL Test","Ceftazidime + Clavulanate"
188
+ "ESBL Test","Cefepime"
189
+ "ESBL Test","Cefepime + clavulanate"
190
+ "APTT Ratio","APTT Ratio"
191
+ "Fibronogen","Fibronogen"
192
+ "50:50 Normal Plasma","50:50 Normal Plasma"
193
+ "50:50 Mix FVIII Deficient","50:50 Mix FVIII Deficient"
194
+ "50:50 Mix F-IX Deficient","50:50 Mix F-IX Deficient"
195
+ "Factor VIII Assay","Factor VIII Assay"
196
+ "Factor IX Assay","Factor IX Assay"
197
+ "TT","TT"
198
+ "Coagulation Assay","PT"
199
+ "Coagulation Assay","INR"
200
+ "Coagulation Assay","APTT"
201
+ "Coagulation Assay","APTT Ratio"
202
+ "Coagulation Assay","TT"
203
+ "Coagulation Assay","Fibronogen"
204
+ "Coagulation Assay","50:50 Mix Normal Plasma"
205
+ "Coagulation Assay","50:50 Mix FVIII Deficient"
206
+ "Coagulation Assay","50:50 Mix F-IX Deficient"
207
+ "Coagulation Assay","Factor IX Assay"
208
+ "Coagulation Assay","Factor VIII Assay"
209
+ "Cardiac Function Tests","Creatine Kinase MB(CKMB)"
210
+ "Cardiac Function Tests","Creatine Kinase(CKN)"
211
+ "Cardiac Function Tests","Lactatedehydrogenase(LDH)"
212
+ "Minerals","Calcium (CA)"
213
+ "Minerals","Phosphorus (PHOS)"
214
+ "Minerals","Magnesium (MGXB)"
215
+ "BioMarkers","C-reactive Protein (CRP)"
216
+ "BioMarkers","Rheumatoid Factor (RF)"
217
+ "BioMarkers","Antistreptolysin O (ASO)"
218
+ "Iron Studies","Iron"
219
+ "Iron Studies","UIBC"
220
+ "HbA1c","HbA1c"
221
+ "Microalbumin","MAL"
222
+ "Microprotein","MPR"
223
+ "Von Willebrand Factor","Von Willebrand (Antigen)"
224
+ "Von Willebrand Factor","Von Willebrand (Activity)"
225
+ "Viral Load","Viral Load"
@@ -0,0 +1,161 @@
1
+ specimen_name,test_name,created_at
2
+ Sputum,"TB Microscopic Exam","2019-11-19 14:05:31"
3
+ Sputum,GeneXpert,"2019-11-19 14:05:31"
4
+ Sputum,"Gram Stain","2019-11-19 14:05:31"
5
+ Sputum,"Culture & Sensitivity","2019-11-19 14:05:31"
6
+ Sputum,Differential,"2019-11-19 14:05:31"
7
+ Sputum,"TB Tests","2019-11-19 14:05:31"
8
+ CSF,"Gram Stain","2019-11-19 14:05:31"
9
+ CSF,"Culture & Sensitivity","2019-11-19 14:05:31"
10
+ CSF,"Cell Count","2019-11-19 14:05:31"
11
+ CSF,"India Ink","2019-11-19 14:05:31"
12
+ CSF,Differential,"2019-11-19 14:05:31"
13
+ CSF,"ZN Stain","2019-11-19 14:05:31"
14
+ CSF,"TB Tests","2019-11-19 14:05:31"
15
+ CSF,"ESBL Test","2019-11-19 14:05:31"
16
+ CSF,CrAg,"2019-11-19 14:05:31"
17
+ Blood,"Gram Stain","2019-11-19 14:05:31"
18
+ Blood,"Culture & Sensitivity","2019-11-19 14:05:31"
19
+ Blood,"Malaria Screening","2019-11-19 14:05:31"
20
+ Blood,"Blood Parasites Screen","2019-11-19 14:05:31"
21
+ Blood,"Syphilis Test","2019-11-19 14:05:31"
22
+ Blood,"Hepatitis B Test","2019-11-19 14:05:31"
23
+ Blood,"Hepatitis C Test","2019-11-19 14:05:31"
24
+ Blood,"Rheumatoid Factor Test","2019-11-19 14:05:31"
25
+ Blood,"Cryptococcus Antigen Test","2019-11-19 14:05:31"
26
+ Blood,"Anti Streptolysis O","2019-11-19 14:05:31"
27
+ Blood,"C-reactive protein","2019-11-19 14:05:31"
28
+ Blood,Measles,"2019-11-19 14:05:31"
29
+ Blood,Rubella,"2019-11-19 14:05:31"
30
+ Blood,CD4,"2019-11-19 14:05:31"
31
+ Blood,"ABO Blood Grouping","2019-11-19 14:05:31"
32
+ Blood,Cross-match,"2019-11-19 14:05:31"
33
+ Blood,"Transfusion Outcome","2019-11-19 14:05:31"
34
+ Blood,"Liver Function Tests","2019-11-19 14:05:31"
35
+ Blood,"Renal Function Test","2019-11-19 14:05:31"
36
+ Blood,Lipogram,"2019-11-19 14:05:31"
37
+ Blood,FBC,"2019-11-19 14:05:31"
38
+ Blood,"FBS","2021-04-11 00:00:00"
39
+ Blood,Electrolytes,"2019-11-19 14:05:31"
40
+ Blood,Enzymes,"2019-11-19 14:05:31"
41
+ Blood,Glucose,"2019-11-19 14:05:31"
42
+ Blood,"Prothrombin Time","2019-11-19 14:05:31"
43
+ Blood,APTT,"2019-11-19 14:05:31"
44
+ Blood,INR,"2019-11-19 14:05:31"
45
+ Blood,ESR,"2019-11-19 14:05:31"
46
+ Blood,"D/Coombs","2021-04-11 00:00:00"
47
+ Blood,"creat","2021-04-11 00:00:00"
48
+ Blood,"Widal","2021-04-11 00:00:00"
49
+ Blood,"AAFB (3rd)","2021-04-11 00:00:00"
50
+ Blood,"Urine micro","2021-04-11 00:00:00"
51
+ Blood,"AAFB (1st)","2021-04-11 00:00:00"
52
+ Blood,ASOT,"2021-04-11 00:00:00"
53
+ Blood,"Blood C/S","2021-04-11 00:00:00"
54
+ Blood,"Cryptococcal Ag","2021-04-11 00:00:00"
55
+ Blood,"I/Ink","2021-04-11 00:00:00"
56
+ Blood,"Prot& Sugar","2021-04-11 00:00:00"
57
+ Blood,C_S,"2021-04-11 00:00:00"
58
+ Blood,hep,"2021-04-11 00:00:00"
59
+ Blood,"Cryptococcal Antigen","2021-04-11 00:00:00"
60
+ Blood,Resistance,"2021-04-11 00:00:00"
61
+ Blood,Sickle,"2021-04-11 00:00:00"
62
+ Blood,"Sickling Test","2019-11-19 14:05:31"
63
+ Blood,"Manual Differential & Cell Morphology","2019-11-19 14:05:31"
64
+ Blood,"Pancreatic Function Test","2019-11-19 14:05:31"
65
+ Blood,"Direct Coombs Test","2019-11-19 14:05:31"
66
+ Blood,Calcium,"2019-11-19 14:05:31"
67
+ Blood,Phosphorus,"2019-11-19 14:05:31"
68
+ Blood,Magnesium,"2019-11-19 14:05:31"
69
+ Blood,"Creatinine Kinase","2019-11-19 14:05:31"
70
+ Blood,"Uric Acid","2019-11-19 14:05:31"
71
+ Blood,"ESBL Test","2019-11-19 14:05:31"
72
+ Blood,"APTT Ratio","2019-11-19 14:05:31"
73
+ Blood,Fibronogen,"2019-11-19 14:05:31"
74
+ Blood,"50:50 Normal Plasma","2019-11-19 14:05:31"
75
+ Blood,"50:50 Mix FVIII Deficient","2019-11-19 14:05:31"
76
+ Blood,"50:50 Mix F-IX Deficient","2019-11-19 14:05:31"
77
+ Blood,"Factor VIII Assay","2019-11-19 14:05:31"
78
+ Blood,"Factor IX Assay","2019-11-19 14:05:31"
79
+ Blood,TT,"2019-11-19 14:05:31"
80
+ Blood,"Coagulation Assay","2019-11-19 14:05:31"
81
+ Blood,"Cardiac Function Tests","2019-11-19 14:05:31"
82
+ Blood,Minerals,"2019-11-19 14:05:31"
83
+ Blood,BioMarkers,"2019-11-19 14:05:31"
84
+ Blood,"Iron Studies","2019-11-19 14:05:31"
85
+ Blood,HbA1c,"2019-11-19 14:05:31"
86
+ Blood,Microalbumin,"2019-11-19 14:05:31"
87
+ Blood,Microprotein,"2019-11-19 14:05:31"
88
+ Blood,"Von Willebrand Factor","2019-11-19 14:05:31"
89
+ Blood,"Viral Load","2019-11-19 14:05:31"
90
+ Blood,"Urine Lam","2019-11-19 14:05:31"
91
+ Blood,"Protein and Sugar","2021-04-16"
92
+ Blood,"White cell count","2021-04-16"
93
+ Blood,Urea,"2019-11-19 14:05:31"
94
+ Blood,Creatinine,"2019-11-19 14:05:31"
95
+ Blood,ALT,"2019-11-19 14:05:31"
96
+ Blood,AST,"2019-11-19 14:05:31"
97
+ "Pleural Fluid","Gram Stain","2019-11-19 14:05:31"
98
+ "Pleural Fluid","Culture & Sensitivity","2019-11-19 14:05:31"
99
+ "Pleural Fluid","Cell Count","2019-11-19 14:05:31"
100
+ "Pleural Fluid",Differential,"2019-11-19 14:05:31"
101
+ "Pleural Fluid","ZN Stain","2019-11-19 14:05:31"
102
+ "Pleural Fluid","TB Tests","2019-11-19 14:05:31"
103
+ "Pleural Fluid","ESBL Test","2019-11-19 14:05:31"
104
+ "Ascitic Fluid","Gram Stain","2019-11-19 14:05:31"
105
+ "Ascitic Fluid","Culture & Sensitivity","2019-11-19 14:05:31"
106
+ "Ascitic Fluid","Cell Count","2019-11-19 14:05:31"
107
+ "Ascitic Fluid",Differential,"2019-11-19 14:05:31"
108
+ "Ascitic Fluid","ZN Stain","2019-11-19 14:05:31"
109
+ "Ascitic Fluid","TB Tests","2019-11-19 14:05:31"
110
+ "Ascitic Fluid","ESBL Test","2019-11-19 14:05:31"
111
+ "Pericardial Fluid","Gram Stain","2019-11-19 14:05:31"
112
+ "Pericardial Fluid","Culture & Sensitivity","2019-11-19 14:05:31"
113
+ "Pericardial Fluid","Cell Count","2019-11-19 14:05:31"
114
+ "Pericardial Fluid",Differential,"2019-11-19 14:05:31"
115
+ "Pericardial Fluid","ZN Stain","2019-11-19 14:05:31"
116
+ "Pericardial Fluid","TB Tests","2019-11-19 14:05:31"
117
+ "Pericardial Fluid","ESBL Test","2019-11-19 14:05:31"
118
+ "Peritoneal Fluid","Gram Stain","2019-11-19 14:05:31"
119
+ "Peritoneal Fluid","Culture & Sensitivity","2019-11-19 14:05:31"
120
+ "Peritoneal Fluid","Cell Count","2019-11-19 14:05:31"
121
+ "Peritoneal Fluid",Differential,"2019-11-19 14:05:31"
122
+ "Peritoneal Fluid","ZN Stain","2019-11-19 14:05:31"
123
+ "Peritoneal Fluid","TB Tests","2019-11-19 14:05:31"
124
+ "Peritoneal Fluid","ESBL Test","2019-11-19 14:05:31"
125
+ HVS,"Gram Stain","2019-11-19 14:05:31"
126
+ HVS,"Culture & Sensitivity","2019-11-19 14:05:31"
127
+ HVS,"Wet prep","2019-11-19 14:05:31"
128
+ HVS,"HVS analysis","2019-11-19 14:05:31"
129
+ HVS,"ESBL Test","2019-11-19 14:05:31"
130
+ Swabs,"Gram Stain","2019-11-19 14:05:31"
131
+ Swabs,"Culture & Sensitivity","2019-11-19 14:05:31"
132
+ Swabs,"Wet prep","2019-11-19 14:05:31"
133
+ Swabs,"ESBL Test","2019-11-19 14:05:31"
134
+ Pus,"Gram Stain","2019-11-19 14:05:31"
135
+ Pus,"Culture & Sensitivity","2019-11-19 14:05:31"
136
+ Pus,"TB Tests","2019-11-19 14:05:31"
137
+ Pus,"ESBL Test","2019-11-19 14:05:31"
138
+ Stool,"Gram Stain","2019-11-19 14:05:31"
139
+ Stool,"Culture & Sensitivity","2019-11-19 14:05:31"
140
+ Stool,"Stool Analysis","2019-11-19 14:05:31"
141
+ Urine,"Gram Stain","2019-11-19 14:05:31"
142
+ Urine,"Culture & Sensitivity","2019-11-19 14:05:31"
143
+ Urine,"Urine Macroscopy","2019-11-19 14:05:31"
144
+ Urine,"Urine Microscopy","2019-11-19 14:05:31"
145
+ Urine,"Urine Chemistries","2019-11-19 14:05:31"
146
+ Urine,"Pregnancy Test","2019-11-19 14:05:31"
147
+ Urine,"ESBL Test","2019-11-19 14:05:31"
148
+ Urine,"Urine Lam","2019-11-19 14:05:31"
149
+ Urine,"Urine Dipstick","2019-11-19 14:05:31"
150
+ Other,"Gram Stain","2019-11-19 14:05:31"
151
+ Other,"Culture & Sensitivity","2019-11-19 14:05:31"
152
+ Other,"Cell Count","2019-11-19 14:05:31"
153
+ Other,"ZN Stain","2019-11-19 14:05:31"
154
+ Swab,"Culture & Sensitivity","2019-11-19 14:05:31"
155
+ Swab,"Semen Analysis","2019-11-19 14:05:31"
156
+ Plasma,"Gram Stain","2019-11-19 14:05:31"
157
+ Plasma,"Culture & Sensitivity","2019-11-19 14:05:31"
158
+ Plasma,"Cell Count","2019-11-19 14:05:31"
159
+ Plasma,"ZN Stain","2019-11-19 14:05:31"
160
+ "DBS (Free drop to DBS card)","Viral Load","2019-11-19 14:05:31"
161
+ "DBS (Using capillary tube)","Viral Load","2019-11-19 14:05:31"
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lab
4
+ module Loaders
5
+ module LoaderMixin
6
+ def self.included(_mod)
7
+ User.current = User.find_by_username('admin') || User.first
8
+ Location.current = Location.find_by_name('Registration') || Location.first
9
+ end
10
+
11
+ CONCEPT_DATATYPE_CODED = 2
12
+ CONCEPT_CLASS_TEST = 1
13
+
14
+ def find_or_create_concept(name, is_set: false)
15
+ # Filter out concept_names with voided concepts
16
+ concept = ConceptName.joins(:concept).find_by_name(name)
17
+ return concept if concept
18
+
19
+ ConceptName.create!(
20
+ concept: Concept.create!(
21
+ short_name: name,
22
+ datatype_id: CONCEPT_DATATYPE_CODED,
23
+ class_id: CONCEPT_CLASS_TEST,
24
+ is_set: is_set,
25
+ uuid: SecureRandom.uuid,
26
+ creator: User.current.user_id,
27
+ date_created: Time.now
28
+ ),
29
+ name: name,
30
+ locale: 'en',
31
+ concept_name_type: 'FULLY_SPECIED',
32
+ uuid: SecureRandom.uuid,
33
+ creator: User.current.user_id,
34
+ date_created: Time.now
35
+ )
36
+ end
37
+
38
+ def add_concept_to_set(set_concept_id:, concept_id:)
39
+ set = ConceptSet.find_by(concept_set: set_concept_id, concept_id: concept_id)
40
+ return set if set
41
+
42
+ ConceptSet.create!(concept_set: set_concept_id,
43
+ concept_id: concept_id,
44
+ creator: User.current.user_id,
45
+ date_created: Time.now)
46
+ end
47
+
48
+ def data_path(filename)
49
+ "#{__dir__}/data/#{filename}"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'reasons_for_test_loader'
4
+ require_relative 'specimens_loader'
5
+ require_relative 'test_result_indicators_loader'
6
+
7
+ module Lab
8
+ module Loaders
9
+ module MetadataLoader
10
+ def self.load
11
+ unless Program.where(name: 'Laboratory program').exists?
12
+ Program.create(name: 'Laboratory program',
13
+ description: 'Manage Lab information',
14
+ creator: 1,
15
+ uuid: SecureRandom.uuid)
16
+ end
17
+
18
+ SpecimensLoader.load
19
+ TestResultIndicatorsLoader.load
20
+ ReasonsForTestLoader.load
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Lab::Loaders::MetadataLoader.load
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './loader_mixin'
4
+
5
+ module Lab
6
+ module Loaders
7
+ module ReasonsForTestLoader
8
+ class << self
9
+ include LoaderMixin
10
+
11
+ def load
12
+ CSV.open(data_path('reasons-for-test.csv'), headers: :first_row) do |csv|
13
+ csv.each do |row|
14
+ puts "Adding reason for test: #{row['reason_name']}"
15
+ add_concept_to_set(set_concept_id: find_or_create_concept(Lab::Metadata::REASON_FOR_TEST_CONCEPT_NAME).concept_id,
16
+ concept_id: find_or_create_concept(row['reason_name']).concept_id)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require_relative './loader_mixin'
5
+
6
+ module Lab
7
+ module Loaders
8
+ ##
9
+ # Load specimens and their tests into the database
10
+ module SpecimensLoader
11
+ class << self
12
+ include LoaderMixin
13
+
14
+ def load
15
+ puts "------- Loading tests and specimens ---------"
16
+ CSV.open(data_path('tests.csv'), headers: :first_row) do |csv|
17
+ csv.each_with_object({}) do |row, test_types|
18
+ specimen_name = row['specimen_name']
19
+ test_name = row['test_name']
20
+
21
+ ActiveRecord::Base.transaction do
22
+ test_type = test_types[test_name] || create_test_type(test_name)
23
+ create_specimen_type(specimen_name, test_type)
24
+
25
+ test_types[test_name] ||= test_type
26
+ end
27
+
28
+ puts "Created test #{test_name} <--< #{specimen_name}"
29
+ rescue StandardError => e
30
+ puts "Error: #{test_name}: #{e}"
31
+ end
32
+ end
33
+ end
34
+
35
+ def test_type_concept_id
36
+ find_or_create_concept(Lab::Metadata::TEST_TYPE_CONCEPT_NAME).concept_id
37
+ end
38
+
39
+ def specimen_type_concept_id
40
+ find_or_create_concept(Lab::Metadata::SPECIMEN_TYPE_CONCEPT_NAME).concept_id
41
+ end
42
+
43
+
44
+ def create_test_type(name)
45
+ concept_id = find_or_create_concept(name, is_set: true).concept_id
46
+
47
+ add_concept_to_set(set_concept_id: test_type_concept_id, concept_id: concept_id)
48
+ rescue StandardError => e
49
+ raise "Failed to create test type `#{name}`: #{e}"
50
+ end
51
+
52
+ def create_specimen_type(name, test_type)
53
+ concept_id = find_or_create_concept(name).concept_id
54
+
55
+ [
56
+ add_concept_to_set(set_concept_id: specimen_type_concept_id, concept_id: concept_id),
57
+ add_concept_to_set(set_concept_id: test_type.concept_id, concept_id: concept_id)
58
+ ]
59
+ rescue StandardError => e
60
+ raise "Failed to create specimen type `#{name}`: #{e}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end