-
Notifications
You must be signed in to change notification settings - Fork 54
/
etl-helpers.js
executable file
·961 lines (940 loc) · 32.1 KB
/
etl-helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
/*jshint -W003, -W097, -W117, -W026 */
'use strict';
var _ = require('underscore');
var moment = require('moment');
module.exports = (function () {
return {
getReportParams: function getReportParams(
reportName,
whereClause,
queryParams
) {
let whereParams = [];
// format dates to avoid timezone errors
queryParams.startDate = (
queryParams.startDate || new Date().toISOString().substring(0, 10)
).split('T')[0];
queryParams.endDate = (
queryParams.endDate || new Date().toISOString().substring(0, 10)
).split('T')[0];
queryParams.referenceDate = (
queryParams.referenceDate || new Date().toISOString().substring(0, 10)
).split('T')[0];
// format cohort filters
queryParams.startAge = queryParams.startAge || 0;
queryParams.endAge = queryParams.endAge || 150;
queryParams.gender = (queryParams.gender || 'M,F').split(',');
queryParams.genders = (queryParams.genders || 'M,F').split(',');
// resolve requested indicators parameter name
queryParams.requestIndicators = queryParams.indicators;
// format location TODO: Remove location ids on reports and params in order to avoid resolutions
var locations = [];
if (queryParams.locations) {
_.each(queryParams.locations.split(','), function (loc) {
locations.push(Number(loc));
});
queryParams.locations = locations;
}
// format locationUuids
var locationUuids = [];
if (queryParams.locationUuids) {
_.each(queryParams.locationUuids.split(','), function (loc) {
if (loc == '' || loc == 'undefined' || loc == undefined) {
console.log(loc);
} else {
locationUuids.push(String(loc));
}
});
if (locationUuids.length > 0) {
queryParams.locationUuids = locationUuids;
} else {
delete queryParams['locationUuids'];
}
}
// format programUuids
var programUuids = [];
if (queryParams.programUuids) {
_.each(queryParams.programUuids.split(','), function (program) {
programUuids.push(String(program));
});
queryParams.programUuids = programUuids || ['*'];
}
var stateUuids = [];
if (queryParams.stateUuids) {
_.each(queryParams.stateUuids.split(','), function (state) {
stateUuids.push(String(state));
});
queryParams.stateUuids = stateUuids || ['*'];
}
var providerUuids = [];
if (queryParams.providerUuids) {
_.each(queryParams.providerUuids.split(','), function (provider) {
if (
provider == '' ||
provider == 'undefined' ||
provider == undefined
) {
console.log(provider);
} else {
providerUuids.push(String(provider));
}
});
if (providerUuids.length > 0) {
queryParams.providerUuids = providerUuids;
} else {
delete queryParams['providerUuids'];
}
}
// format conceptUuid
var conceptUuids = [];
if (queryParams.conceptUuids) {
_.each(queryParams.conceptUuids.split(','), function (state) {
conceptUuids.push(String(state));
});
queryParams.conceptUuids = conceptUuids;
}
//
for (let filter of whereClause) {
whereParams.push({
name: filter,
value: queryParams[filter]
});
}
var reportParams = {
reportName: reportName,
whereParams: whereParams,
countBy: queryParams.countBy || 'num_persons',
groupBy: queryParams.groupBy || 'groupByLocation',
offset: queryParams.startIndex,
limit: queryParams.limit,
requestIndicators: queryParams.indicators,
requestParams: queryParams
};
return reportParams;
},
getSortOrder: function getSortOrder(param) {
if (!param) return null;
var parts;
var order = [];
_.each(param.split(','), function (order_by) {
parts = order_by.split('|');
order.push({
column: parts[0],
asc: parts[1].toLowerCase() === 'asc'
});
});
return order;
},
getFilters: function getFilters(filters) {
var s = '';
var vals = [],
column;
_.each(filters, function (item) {
column = item.column;
for (var f in item.filters) {
if (
item.filters[f] === undefined ||
item.filters[f] === null ||
item.filters[f] === ''
)
continue;
console.log(item.filters[f]);
s += column;
if (f === 'start') s += ' >= ?';
else if (f === 'end') s += ' <= ?';
else s += ' like ?';
vals.push(item.filters[f]);
s += ' AND ';
}
});
s = s.substring(0, s.length - 5);
if (s !== '') s = '(' + s + ')';
console.log(s);
console.log(vals);
return {
s: s,
vals: vals
};
},
getConceptName: function getConceptName(code) {
if (code === null || code === undefined) return '';
var concepts = {
221: 'RHEUMATIC HEART DISEASE',
9842: 'DUCTAL CELL CARCINOMA',
664: 'NEGATIVE',
703: 'POSITIVE',
1115: 'NORMAL',
1116: 'ABNORMAL',
1118: 'NOT DONE',
1136: 'PULMONARY EFFUSION',
1137: 'MILIARY CHANGES',
1138: 'INDETERMINATE',
1304: 'POOR SAMPLE QUALITY',
1530: 'CARDIAC ARRHYTHMIA',
1531: 'ATRIAL FIBRILLATION',
1532: 'LEFT VENTRICULAR HYPERTROPHY',
1533: 'RIGHT VENTRICULAR HYPERTROPHY',
1538: 'DILATED CARDIOMYOPATHY',
1539: 'PERICARDIAL EFFUSION',
1540: 'MURAL THROMBI',
1541: 'PULMONARY HYPERTENSION',
1542: 'VENTRICULAR SEPTAL DEFECT',
5158: 'EVIDENCE OF CARDIAC ENLARGEMENT',
5622: 'OTHER NON-CODED',
6049: 'INFILTRATE',
6050: 'DIFFUSE NON-MILIARY CHANGES',
6052: 'CAVITARY LESION',
1098: 'MONTHLY',
1099: 'WEEKLY',
1639: 'MORNING',
1640: 'NOON',
1641: 'AFTERNOON',
1730: 'EVENING',
1888: 'TWICE A DAY',
1889: 'THREE TIMES A DAY',
1890: 'FOUR TIMES A DAY',
1891: 'ONCE A DAY',
1899: 'NUMBER OF MILLIGRAM',
2176: 'EVERY NIGHT',
2178: 'STAT',
7682: 'ONCE EVERY TWO WEEKS',
7772: 'AS NEEDED',
8909: 'ONCE A WEEK',
8927: 'ONCE',
9933: 'ONCE EVERY THREE WEEKS',
10091: 'FIVE TIMES DAILY',
10092: 'TWICE A WEEK',
10093: 'THREE TIMES A WEEK',
10094: 'FOUR TIMES A WEEK',
1256: 'START',
1257: 'CONTINUE',
1259: 'CHANGE',
1260: 'STOP',
2261: 'METFORMIN',
2257: 'GLIBENCLAMIDE',
2254: '70% NPH INSULIN WITH 30% REGULAR INSULIN',
2256: 'INSULIN LISPRO',
2255: 'INSULIN NPH',
2258: 'GLICLAZIDE',
2259: 'CHLORPROPAMIDE',
2260: 'GLIMEPIRIDE',
279: 'INSULIN, LENTE',
282: 'INSULIN, REGULAR',
2270: 'PIOGLITAZONE',
2271: 'ROSIGLITAZONE',
2279: 'GLIBENCLAMIDE AND METFORMIN',
1107: 'NONE',
7281: 'NEW DM PATIENT',
7282: 'KNOWN DM PATIENT',
7285: 'NEW HTN PATIENT',
7286: 'KNOWN HTN PATIENT',
1878: 'STROKE',
8076: 'T.I.A',
1456: 'HEART FAILURE',
8077: 'ISCHEMIC H.D ',
821: 'PERIPHERAL NEUROPATHY',
8084: 'DIABETIC RETINOPATHY',
8085: 'GASTROPATHY',
8086: 'AUTONOMIC NEUROPATHY',
70: 'CATARACTS',
1885: 'KIDNEY FAILURE',
6730: 'VISUAL IMPAIREMENT',
// ONCOLOGY CONCEPTS
8480: 'LENALIDOMIDE',
6555: 'MULTIPLE MYELOMA',
6902: 'BONE MARROW ASPIRATION',
10206: 'DURIE-SALMON SYSTEM',
9851: 'STAGE 0',
9852: 'STAGE I',
9853: 'STAGE IA',
9854: 'STAGE IB',
9855: 'STAGE IC',
9856: 'STAGE II',
9857: 'STAGE IIA',
9858: 'STAGE IIB',
9859: 'STAGE IIC',
9860: 'STAGE III',
9861: 'STAGE IIIA',
9862: 'STAGE IIIB',
9863: 'STAGE IIIC',
9864: 'STAGE IV',
9865: 'STAGE IVA',
9867: 'STAGE IVC',
9866: 'STAGE IVB',
6575: 'CHEMOTHERAPY',
10078: 'INTRATHECAL, DRUG ROUTE',
8479: 'THALIDOMIDE',
6566: 'COMPLETE STAGING',
6536: 'GYNECOLOGIC CANCER TYPE',
7213: 'MELPHALAN',
6485: 'SARCOMA',
6537: 'CERVICAL CANCER',
9918: 'CHEMO MEDS',
8478: 'IMATINIB',
7217: 'PALLIATIVE TAMOXIFEN',
7203: 'CYCLOPHOSPHAMIDE',
7215: 'METHOTREXATE',
7223: 'FLUOROURACIL',
7198: 'HYDROXYDAUNORUBICIN (ADRIAMYCIN)',
491: 'PREDNISONE',
7199: 'BLEOMYCIN',
7218: 'VINBLASTINE',
7205: 'DACARBAZINE',
7212: '5FU / LEUCOVORIN',
8513: 'ANASTRAZOLE',
7202: 'CISPLATIN',
7209: 'ETOPOSIDE',
7197: 'ACTINOMYCIN D',
7219: 'VINCRISTINE',
8506: 'PACLITAXEL',
7210: 'GEMCITABINE (GEMZAR)',
8499: 'IFOSFAMIDE',
8492: 'CARBOPLATINUM',
8522: 'INTERFERON ALFA',
8510: 'CAPECITABINE',
8511: 'EPIRUBICIN',
9919: 'MESNA',
8518: 'LEUPROLIDE',
8516: 'BICALUTAMIDE',
8481: 'SORAFENIB',
7207: 'DEXAMETHASONE',
7204: 'CYTARABINE',
7201: 'CHLORAMBUCIL',
8519: 'ZOLADEX/GOSERELIN',
8507: 'TAXOTERE',
10139: 'OXALIPLATIN',
10140: 'ZOLEDRONIC ACID',
8515: 'LETROZOLE',
8514: 'EXEMESTANE',
8486: 'BORTEZOMIB',
1895: 'MEDICATION ADDED',
10198: 'OTHER MEDS GIVEN',
88: 'BABY ASA',
8598: 'VIT. B12 INJECTION',
8597: 'VIT D SUPPLEMETATION',
1195: 'ANTIBIOTICS',
8410: 'ANTICOAGULATION',
7458: 'IV FLUIDS',
9710: 'SICKLE CELL DRUGS',
7211: 'HYDROXYUREA',
257: 'FOLATE/FOLIC ACID',
784: 'PEN-V',
97: 'PALLUDRINE',
8723: 'ONCOLOGY TREATMENT PLAN',
7465: 'SURGERY',
8427: 'RADIATION THERAPY',
9626: 'HORMONE REPLACEMENT THERAPY',
10038: 'BIOLOGIC THERAPY',
10232: 'TARGETED THERAPY',
10039: 'OTHER ONCOLOGY TREATMENT PLAN',
10586: 'IN REMISSION',
8725: 'REASONS FOR SURGERY',
8428: 'CURATIVE CARE',
8724: 'PALLIATIVE CARE',
8727: 'DIAGNOSTIC',
2206: 'CHEMOTHERAPY INTENT',
9219: 'NEO ADJUVANT INTENT',
9218: 'ADJUVANT INTENT',
9220: 'SYMPTOM CONTROL',
9869: 'CHEMOTHERAPY PLAN',
6576: 'CHEMOTHERAPY REGIMEN MODIFICATION',
1190: 'CHEMOTHERAPY START DATE',
6643: 'CURRENT CHEMOTHERAPY CYCLE',
7463: 'DRUG ROUTE',
10079: 'INTRA OMMAYA',
7597: 'SUBCUTANEOUS INJECTION',
7581: 'INTRAMUSCULAR INJECTION',
7609: 'INTRARTERIAL INJECTION',
7447: 'ORAL ADMINISTRATION',
6042: 'DIAGNOSIS',
9728: 'DIAGNOSIS DATE',
9868: 'OVERALL CANCER STAGE GROUP',
7176: 'CANCER TYPE',
9847: 'NON-CANCER',
9841: 'BREAST CANCER TYPE',
6582: 'CANCER STAGE',
6504: 'DIAGNOSIS METHOD',
507: "KAPOSI'S SARCOMA",
6486: 'SOFT TISSUE SARCOMA',
6487: 'OSTEOGENIC SARCOMA',
6488: "EWING'S SARCOMA",
6489: 'RHABDOMYOSARCOMA',
6490: 'OTHER SARCOMA',
1065: 'YES',
9849: 'NEW CANCER PATIENT',
9850: 'CANCER RECURRENCE',
6484: 'SOLID CANCER',
7175: 'HEMATOLOGIC CANCER',
6529: 'THYROID CANCER',
6522: 'GASTRIC CANCER',
9636: 'ENDOMETRIAL CANCER',
9637: 'BONE OR SOFT TISSUE CANCER',
9638: 'ADRENOCORTICAL CARCINOMA',
9639: 'BRAIN CANCER',
9640: 'ACUTE LEUKEMIA',
6544: 'BREAST CANCER',
6545: 'INFLAMMATORY BREAST CANCER',
9846: 'OTHER SOLID CANCER TYPE',
6514: 'GENITOURINARY CANCER',
6520: 'GASTROINTESTINAL CANCER',
6528: 'HEAD AND NECK CANCER',
6551: 'LYMPHOMA CANCER TYPE',
6540: 'SKIN CANCER TYPE',
216: 'LEUKEMIA',
10129: 'NON SMALL CELL LUNG CANCER',
10130: 'SMALL CELL LUNG CANCER',
8424: 'RETINOBLASTOMA',
8425: 'NEUROBLASTOMA',
9845: 'LUNG CANCER',
6515: 'BLADDER CANCER',
6516: 'RENAL CELL CANCER',
6517: "WILM'S TUMOR",
6518: 'PROSTATE CANCER',
6519: 'TESTES CANCER',
6521: 'ESOPHAGEAL CANCER',
6523: 'PANCREATIC CANCER',
6524: 'CHOLANGIOCARCINOMA',
6525: 'COLON CANCER',
6526: 'RECTAL CANCER',
6527: 'ANAL CANCER',
6568: 'HEPATOCELLULAR CANCER',
6530: 'NASOPHARYNGEAL SQUAMOUS CELL CANCER',
6531: 'OROPHARYNGEAL SQUAMOUS CELL CANCER',
6532: 'HYPOPHARYNGEAL SQUAMOUS CELL CANCER',
6533: 'LARYNGEAL SQUAMOUS CELL CANCER',
6534: 'HEAD AND NECK SQUAMOUS CELL CANCER, SITE NOT SPECIFIED',
6535: 'POSTERIOR NASAL SPACE TUMOR',
6538: 'UTERINE CANCER',
6539: 'OVARIAN CANCER',
6553: "NON-HODGKIN'S LYMPHOMA",
6552: "HODGKIN'S LYMPHOMA",
8423: "BURKITT'S LYMPHOMA",
6541: 'SKIN SQUAMOUS CELL CANCER',
6542: 'BASAL CELL CANCER',
6543: 'MELANOMA',
7420: 'HIGH GRADE SQUAMOUS INTRAEPITHELIAL LESION',
7422: 'ADENOCARCINOMA',
7421: 'SQUAMOUS CELL CARCINOMA, NOT OTHERWISE SPECIFIED',
10131: 'LARGE CELL CARCINOMA',
10209: 'MIXED SQUAMOUS',
6547: 'CHRONIC MYELOGENOUS LEUKEMIA',
6548: 'CHRONIC LYMPHOCYTIC LEUKEMIA',
6549: 'ACUTE MYELOGENOUS LEUKEMIA',
6550: 'ACUTE LYMPHOCYTIC LEUKEMIA',
7469: 'ACETOWHITE LESION',
5245: 'PALLOR',
7470: 'PUNCTUATED CAPILLARIES',
9591: 'OYSTER WHITE LESION',
9592: 'BRIGHT WHITE LESION',
7293: 'ULCER',
6497: 'DYSFUNCTIONAL UTERINE BLEEDING',
7472: 'ATYPICAL BLOOD VESSELS',
9593: 'FRIABLE TISSUE',
6971: 'POSSIBLE',
11772: 'YELLOW STAINING LESION',
7417: 'ATYPICAL SQUAMOUS CELLS OF UNDETERMINED SIGNIFICANCE',
7418: 'ATYPICAL GLANDULAR CELLS OF UNDETERMINED SIGNIFICANCE',
7419: 'LOW GRADE SQUAMOUS INTRAEPITHELIAL LESION',
7420: 'HIGH GRADE SQUAMOUS INTRAEPITHELIAL LESION',
7421: 'SQUAMOUS CELL CARCINOMA, NOT OTHERWISE SPECIFIED',
10055: 'INVASIVE CANCER'
};
return concepts[code];
},
getARVNames: function getARVNames(str) {
if (
str === null ||
str === undefined ||
str === 'unknown' ||
str === '-1'
) {
return '';
}
var arvs = {
625: { mapped_to_ids: '625', name: 'STAVUDINE' },
628: { mapped_to_ids: '628', name: 'LAMIVUDINE' },
630: { mapped_to_ids: '628;797', name: 'ZIDOVUDINE AND LAMIVUDINE' },
631: { mapped_to_ids: '631', name: 'NEVIRAPINE' },
633: { mapped_to_ids: '633', name: 'EFAVIRENZ' },
635: { mapped_to_ids: '635', name: 'NELFINAVIR' },
749: { mapped_to_ids: '749', name: 'INDINAVIR' },
791: { mapped_to_ids: '791', name: 'EMTRICITABINE' },
792: {
mapped_to_ids: '625;628;631',
name: 'STAVUDINE LAMIVUDINE AND NEVIRAPINE'
},
794: { mapped_to_ids: '794', name: 'LOPINAVIR AND RITONAVIR' },
795: { mapped_to_ids: '795', name: 'RITONAVIR' },
796: { mapped_to_ids: '796', name: 'DIDANOSINE' },
797: { mapped_to_ids: '797', name: 'ZIDOVUDINE' },
802: { mapped_to_ids: '802', name: 'TENOFOVIR' },
814: { mapped_to_ids: '814', name: 'ABACAVIR' },
817: {
mapped_to_ids: '628;797;814',
name: 'ABACAVIR LAMIVUDINE AND ZIDOVUDINE'
},
1065: { mapped_to_ids: '1065', name: 'YES' },
1066: { mapped_to_ids: '1066', name: 'NO' },
1107: { mapped_to_ids: '1107', name: 'NONE' },
1400: { mapped_to_ids: '628;802', name: 'LAMIVUDINE AND TENOFOVIR' },
5424: { mapped_to_ids: '5424', name: 'OTHER ANTIRETROVIRAL DRUG' },
5811: { mapped_to_ids: '5811', name: 'UNKNOWN ANTIRETROVIRAL DRUG' },
6156: { mapped_to_ids: '6156', name: 'RALTEGRAVIR' },
6157: { mapped_to_ids: '6157', name: 'DARUNAVIR' },
6158: { mapped_to_ids: '6158', name: 'ETRAVIRINE' },
6159: { mapped_to_ids: '6159', name: 'ATAZANAVIR' },
6160: { mapped_to_ids: '795;6159', name: 'ATAZANAVIR AND RITONAVIR' },
6180: { mapped_to_ids: '791;802', name: 'EMTRICITABINE AND TENOFOVIR' },
6467: {
mapped_to_ids: '628;631;633',
name: 'NEVIRAPINE LAMIVUDINE AND ZIDOVUDINE'
},
6679: { mapped_to_ids: '628;814', name: 'ABACAVIR AND LAMIVUDINE' },
6964: {
mapped_to_ids: '628;633;802',
name: 'TENOFOVIR AND LAMIVUDINE AND EFAVIRENZ'
},
6965: { mapped_to_ids: '625;628', name: 'LAMIVUDINE AND STAVUDINE' },
9435: { mapped_to_ids: '9435', name: 'EVIPLERA' },
9759: { mapped_to_ids: '9759', name: 'DOLUTEGRAVIR' },
9026: { mapped_to_ids: '9026', name: 'LOPINAVIR' },
10090: { mapped_to_ids: '10090', name: 'RILPIVIRINE' },
12053: { mapped_to_ids: '12053', name: 'CABOTEGRAVIR AND RILPIVIRINE' },
12469: {
mapped_to_ids: '12469',
name: ' TENOFOVIR ALAFENAMIDE AND LAMIVUDINE AND DOLUTEGRAVIR'
}
};
var arvCodes = str.split(' ## ');
var arvNames = [];
var sortedArvCodes = arvCodes.sort().join(';');
var matchingName = _.find(arvs, function (arv) {
if (arv['mapped_to_ids'] === sortedArvCodes) {
return arv;
}
});
_.each(arvCodes, function (code) {
if (arvs[code]) {
arvNames.push(arvs[code].name);
} else {
arvNames.push(code);
}
});
return matchingName ? matchingName.name : arvNames.join(', ');
},
getContraceptiveMethod: function getContraceptiveMethod(str) {
if (str === null || str === undefined)
return { concept: 1107, name: 'NONE', period: null };
var contraceptives = [
{ concept: 190, name: 'CONDOMS', period: 'Short term' },
{ concept: 780, name: 'ORAL CONTRACEPTION', period: 'Short term' },
{
concept: 907,
name: 'MEDROXYPROGESTERONE ACETATE',
period: 'Short term'
},
{ concept: 5278, name: 'DIAPHRAGM', period: 'Short term' },
{
concept: 5279,
name: 'INJECTABLE CONTRACEPTIVE',
period: 'Long term'
},
{ concept: 5622, name: 'OTHER NON-CODED', period: null },
{ concept: 5275, name: 'INTRAUTERINE DEVICE', period: 'Long term' },
{ concept: 5276, name: 'FEMALE STERILIZATION', period: 'Long term' },
{ concept: 5277, name: 'NATURAL FAMILY PLANNING', period: null },
{ concept: 1107, name: 'NONE', period: null },
{ concept: 6220, name: 'CONTRACEPTIVE IMPLANT', period: 'Long term' },
{
concept: 6218,
name: 'COMBINED HORMONE ORAL CONTRACEPTIVE PILL',
period: 'Short term'
},
{ concept: 6219, name: 'PERIODIC ABSTINENCE', period: null },
{ concept: 6217, name: 'PROGESTIN PILLS', period: 'Short term' },
{ concept: 6700, name: 'TUBAL LIGATION', period: 'Long term' },
{ concept: 6701, name: 'VASECTOMY', period: 'Long term' },
{
concept: 5841,
name: 'HERBAL TRADITIONAL MEDICATIONS',
period: 'Short term'
},
{ concept: 6717, name: 'FEMALE CONDOMS', period: 'Short term' },
{ concept: 6718, name: 'MALE CONDOMS', period: 'Short term' },
{
concept: 6725,
name: 'EMERGENCY CONTRACEPTIVE PILLS',
period: 'Short term'
},
{ concept: 8134, name: 'CONTRACEPTIVE SPONGE', period: 'Short term' },
{
concept: 5274,
name: 'FAMILY PLANNING VIA ORAL CONTRACEPTIVE PILLS',
period: 'Short term'
},
{ concept: 1624, name: 'DO NOT KNOW', period: null },
{ concept: 6707, name: 'UNDECIDED', period: null },
{
concept: 8300,
name: 'LACTATIONAL AMENORRHEA METHOD',
period: 'Short term'
},
{
concept: 9510,
name: '3-YEAR CONTRACEPTIVE IMPLANT',
period: 'Long term'
},
{
concept: 9511,
name: '5-YEAR CONTRACEPTIVE IMPLANT',
period: 'Long term'
},
{ concept: 1067, name: 'UNKNOWN', period: null },
{
concept: 9734,
name: 'COPPER INTRAUTERINE DEVICE',
period: 'Long term'
},
{
concept: 9735,
name: 'HORMONAL INTRAUTERINE DEVICE',
period: 'Long term'
},
{
concept: 10956,
name: 'CONTRACEPTION METHOD UNDECIDED',
period: null
},
{
concept: 10817,
name: 'NORPLANT(IMPLANTABLE CONTRACEPTIVE)',
period: 'Long term'
}
];
var contraceptiveMethod = {} | null;
_.each(contraceptives, function (contraceptive) {
if (contraceptive.concept === str) {
contraceptiveMethod = contraceptive;
}
});
if (contraceptiveMethod === 0 || typeof contraceptiveMethod != 'object')
return { concept: str, name: 'UNKNOWN', period: null };
return contraceptiveMethod;
},
getTestsOrderedNames: function getTestsOrderedNames(str) {
if (str === null || str === undefined) return '';
var tests = {
678: 'WBC',
21: 'Hb',
790: 'Cr',
654: 'ALT',
653: 'AST',
5497: 'CD4',
730: 'CD4%',
856: 'Viral Load',
1040: 'Rapid HIV',
1030: 'HIV DNA PCR',
2323: 'TB PCR',
2311: 'Sputum Culture',
307: 'Sputum AFB',
8064: 'Sputum Gene Xpert',
8070: 'MTB Finding',
8071: 'RIF Resistant Finding',
299: 'VDRL',
729: 'Platelets',
851: 'MCV',
12: 'Chest Xray',
1019: 'Complete Blood Count',
657: 'CD4 PANEL',
6126: 'HbA1c',
887: 'RBS',
6252: 'FBS',
1537: 'EKG',
857: 'UREA'
};
var testsCodes = str.toString().split(' ## ');
var testsNames = [];
_.each(testsCodes, function (code) {
testsNames.push(tests[code]);
});
return testsNames.join(',');
},
getCDMNames: function getCDMNames(tests, str) {
if (str === null || str === undefined) return '';
/*var tests = {
99:"LASIX",
250:"NIFEDIPINE",
920:"TAGRETOL",
1107: "NONE",
1242:"ENALAPRIL",
1243:"HCTZ",
2254:"INSULIN 70/30",
2255:"INSULIN NPH",
2256:"INSULIN HUMALOGUE",
2257:"GLIBENCLAMIDE",
2258:"GLICLAZIDE",
2259: "CHLORPROPAMIDE",
2260:"GLIMEPIRIDE",
2261:"METFORMIN",
2264:"LISINOPRIL/HCTZ",
2265:"LOSARTAN",
2266:"METROPOLOL",
2267:"ATENOLOL",
2268:"CAVEDILOL",
2276:"ATORVASTATIN",
2270: "PIOGLITAZONE",
2271: "ROSIGLITAZONE",
2278:"SILDENAFIL",
2279: "GLIBENCLAMIDE AND METFORMIN",
7303:"JUNIOR ASA",
8015:"INSULIN GLARGINE",
8020:"PREGABALIN",
9205:"FELODIPINE",
10049:"TELMISARTAN",
10050:"CANDESARTAN",
221: "RHEUMATIC HEART DISEASE",
664: "NEGATIVE",
703: "POSITIVE",
1115: "NORMAL",
1116: "ABNORMAL",
1118: "NOT DONE",
1136: "PULMONARY EFFUSION",
1137: "MILIARY CHANGES",
1138: "INDETERMINATE",
1304: "POOR SAMPLE QUALITY",
1530: "CARDIAC ARRHYTHMIA",
1531: "ATRIAL FIBRILLATION",
1532: "LEFT VENTRICULAR HYPERTROPHY",
1533: "RIGHT VENTRICULAR HYPERTROPHY",
1538: "DILATED CARDIOMYOPATHY",
1539: "PERICARDIAL EFFUSION",
1540: "MURAL THROMBI",
1541: "PULMONARY HYPERTENSION",
1542: "VENTRICULAR SEPTAL DEFECT",
5158: "EVIDENCE OF CARDIAC ENLARGEMENT",
5622: "OTHER NON-CODED",
6049: "INFILTRATE",
6050: "DIFFUSE NON-MILIARY CHANGES",
6052: "CAVITARY LESION",
1098: "MONTHLY",
1099: "WEEKLY",
1639: "MORNING",
1640: "NOON",
1641: "AFTERNOON",
1730: "EVENING",
1888: "TWICE A DAY",
1889: "THREE TIMES A DAY",
1890: "FOUR TIMES A DAY",
1891: "ONCE A DAY",
1899: "NUMBER OF MILLIGRAM",
2176: "EVERY NIGHT",
2178: "STAT",
5622: "OTHER NON-CODED",
7682: "ONCE EVERY TWO WEEKS",
7772: "AS NEEDED",
8909: "ONCE A WEEK",
8927: "ONCE",
9933: "ONCE EVERY THREE WEEKS",
10091: "FIVE TIMES DAILY",
10092: "TWICE A WEEK",
10093: "THREE TIMES A WEEK",
10094: "FOUR TIMES A WEEK",
1256: "START",
1257: "CONTINUE",
1259: "CHANGE",
1260: "STOP",
2261: "METFORMIN",
2257: "GLIBENCLAMIDE",
2254: "70% NPH INSULIN WITH 30% REGULAR INSULIN",
2256: "INSULIN LISPRO",
2255: "INSULIN NPH",
2258: "GLICLAZIDE",
2259: "CHLORPROPAMIDE",
2260: "GLIMEPIRIDE",
279: "INSULIN, LENTE",
282: "INSULIN, REGULAR",
2270: "PIOGLITAZONE",
2271: "ROSIGLITAZONE",
2279: "GLIBENCLAMIDE AND METFORMIN",
1107: "NONE",
7281:"NEW DM PATIENT",
7282:"KNOWN DM PATIENT",
7285:"NEW HTN PATIENT",
7286:"KNOWN HTN PATIENT",
1878:"STROKE",
8076:"T.I.A",
1456:"HEART FAILURE",
8077:"ISCHEMIC H.D ",
821:"PERIPHERAL NEUROPATHY",
8084:"DIABETIC RETINOPATHY",
8085:"GASTROPATHY",
8086:"AUTONOMIC NEUROPATHY",
70:"CATARACTS",
1878:"STROKE",
1456:"HEART FAILURE",
1885:"KIDNEY FAILURE",
6730:"VISUAL IMPAIREMENT",
6636:"NEUROPATHY",
8087:"DIABETIC FOOT ULCER",
136:"CHEST PAIN",
175:"DIABETES MELLITUS",
5949:"FATIGUE",
620:"HEADACHE"
};*/
var testsCodes = str.toString().split(' ## ');
var testsNames = [];
_.each(testsCodes, function (code) {
code = code.trim();
testsNames.push(tests[code]);
});
return testsNames.join(',');
},
transformMedicalRefillToClinical: function transformMedicalRefillToClinical(
hivSummaries
) {
let transfromedArray = [];
_.each(hivSummaries, (hivSummary) => {
if (hivSummary.encounter_type == 186) {
// console.log('summarytest',hivSummary);
hivSummary.is_clinical_encounter = 1;
// console.log('summarytest',hivSummary);
}
transfromedArray.push(hivSummary);
});
return transfromedArray;
},
getConceptNames: function getCDMNames(concepts, str) {
if (str === null || str === undefined) return '';
var testsCodes = str.toString().split(' ## ');
var testsNames = [];
_.each(testsCodes, function (code) {
code = code.trim();
testsNames.push(concepts[code]);
});
return testsNames.join(',');
},
resolvedLabOrderErrors: function resolvedLabOrderErrors(
vlerror,
cd4eror,
pcrerror
) {
var message = '';
if (vlerror === 1) message = 'Error processing Viral Load';
if (cd4eror === 1) {
if (message !== '') message = message + ', ' + 'Error processing cd4';
else message = 'Error processing cd4';
}
if (pcrerror === 1) {
if (message !== '')
message = message + ', ' + 'Error processing hiv dna pcr';
else message = 'Error processing hiv dna pcr';
}
return message;
},
buildWhereClauseForDataEntryIndicators: function buildWhereClauseForDataEntryIndicators(
queryParams,
where
) {
if (queryParams.locations) {
var locations = [];
_.each(queryParams.locations.split(','), function (loc) {
locations.push(Number(loc));
});
where[0] = where[0] + ' and t2.location_id in ?';
where.push(locations);
}
if (queryParams.provideruuid) {
where[0] = where[0] + ' and t4.uuid = ?';
where.push(queryParams.provideruuid);
}
if (queryParams.creatoruuid) {
where[0] = where[0] + ' and t5.uuid = ?';
where.push(queryParams.creatoruuid);
}
if (queryParams.encounterTypeIds) {
var encounterTypes = [];
_.each(queryParams.encounterTypeIds.split(','), function (encType) {
encounterTypes.push(Number(encType));
});
where[0] = where[0] + ' and t2.encounter_type in ?';
where.push(encounterTypes);
}
if (queryParams.formIds) {
var formIds = [];
_.each(queryParams.formIds.split(','), function (formid) {
formIds.push(Number(formid));
});
where[0] = where[0] + ' and t2.form_id in ?';
where.push(formIds);
}
},
decodeBase64Image: function decodeBase64Image(dataString) {
var matches = dataString.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/),
response = {};
if (matches.length !== 3) {
return new Error('Invalid input string');
}
response.type = matches[1];
response.data = new Buffer(matches[2], 'base64');
return response;
},
buildWhereParamsDataEntryIndicators: function buildWhereParamsDataEntryIndicators(
queryParams,
where
) {
if (queryParams.locations) {
var locations = [];
_.each(queryParams.locations.split(','), function (loc) {
locations.push(Number(loc));
});
where.locations = locations;
}
if (queryParams.provideruuid) {
where.providerUuid = queryParams.provideruuid;
}
if (queryParams.creatoruuid) {
var creatorUuids = [];
_.each(queryParams.creatoruuid.split(','), function (creator) {
creatorUuids.push(creator);
});
where.creator = creatorUuids;
}
if (queryParams.encounterTypeIds) {
var encounterTypes = [];
_.each(queryParams.encounterTypeIds.split(','), function (encType) {
encounterTypes.push(Number(encType));
});
where.encounterTypes = encounterTypes;
}
if (queryParams.visitTypeIds) {
var visitTypes = [];
_.each(queryParams.visitTypeIds.split(','), function (visitType) {
visitTypes.push(Number(visitType));
});
where.visitTypes = visitTypes;
}
if (queryParams.formIds) {
var formIds = [];
_.each(queryParams.formIds.split(','), function (formid) {
formIds.push(Number(formid));
});
where.formIds = formIds;
}
},
filterDate: function filterDate(date) {
if (!_.isNull(date)) {
return moment(date).format('DD-MM-YYYY');
}
return date;
},
titleCase: function titleCase(name) {
if (name) {
name = name.toLowerCase().split(' ');
for (var i = 0; i < name.length; i++) {
name[i] = name[i].charAt(0).toUpperCase() + name[i].slice(1);
}
return name.join(' ');
}
}
};
})();