forked from OHDSI/Vocabulary-v5.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_stage.sql
3038 lines (2686 loc) · 65.8 KB
/
load_stage.sql
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
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
DROP TABLE IF EXISTS drugs;
CREATE TABLE drugs AS
SELECT DISTINCT fo_prd_id,
a.prd_name,
a.mast_prd_name,
a.dosage,
a.unit,
a.dosage2,
a.unit2,
a.mol_eid,
a.mol_name,
b.mol_name as mol_name_2,
atccode,
atc_name,
nfc_code,
manufacturer
FROM fo_product_1_vs_2 a
FULL OUTER JOIN drug_mapping_1_vs_2 b ON a.prd_eid = b.prd_eid;
--next manipulation requires correct numbers--
UPDATE drugs
SET PRD_NAME = replace(PRD_NAME, ',', '.')
WHERE PRD_NAME IS NOT NULL;
DROP TABLE IF EXISTS drugs_3;
CREATE TABLE drugs_3 AS
SELECT a.fo_prd_id,
a.prd_name,
a.mast_prd_name,
dosage_as_text as dosage,
b.unit,
dosage2_as_text as dosage2,
unit_id2 as unit2,
a.mol_eid,
a.mol_name,
b.manufacturer,
b.nfc_code,
a.atccode,
atc_name
FROM sources.aus_fo_product_3 a
LEFT JOIN sources.aus_drug_mapping_3 b ON a.prd_eid = b.prd_eid;
CREATE INDEX idx_fo_prd_id ON drugs_3 (fo_prd_id);
ANALYZE drugs_3;
UPDATE DRUGS
SET MANUFACTURER = (
SELECT MANUFACTURER
FROM DRUGS_3
WHERE DRUGS_3.FO_PRD_ID = DRUGS.FO_PRD_ID
);
UPDATE DRUGS
SET ATCCODE = (
SELECT ATCCODE
FROM DRUGS_3
WHERE DRUGS_3.FO_PRD_ID = DRUGS.FO_PRD_ID
AND DRUGS_3.ATCCODE NOT IN (
'IMIQUIMOD',
'-1',
'??'
)
);
INSERT INTO DRUGS (
fo_prd_id,
prd_name,
mast_prd_name,
dosage,
unit,
dosage2,
unit2,
mol_eid,
mol_name,
atccode,
atc_name,
nfc_code,
manufacturer
)
SELECT fo_prd_id,
prd_name,
mast_prd_name,
dosage,
unit,
dosage2,
unit2,
mol_eid,
mol_name,
atccode,
atc_name,
nfc_code,
manufacturer
FROM drugs_3
WHERE fo_prd_id NOT IN (
SELECT fo_prd_id
FROM drugs
);
INSERT INTO drugs (
fo_prd_id,
prd_name,
mast_prd_name,
dosage,
unit,
dosage2,
unit2,
mol_eid,
mol_name,
atccode,
atc_name,
manufacturer
)
SELECT fo_prd_id,
prd_name,
mast_prd_name,
dosage,
unit,
dosage2,
unit2,
mol_eid,
mol_name,
atccode,
atc_name,
manufacturer_name
FROM au_lpd
WHERE fo_prd_id NOT IN (
SELECT fo_prd_id
FROM drugs
);
UPDATE drugs
SET MOL_NAME = REPLACE(mol_name, '"', '');
UPDATE drugs
SET mol_name = NULL
WHERE mol_name LIKE '%INIT%';
DROP TABLE IF EXISTS drugs_update_1;
CREATE TABLE drugs_update_1 AS
SELECT DISTINCT a.fo_prd_id,
a.prd_name,
a.mast_prd_name,
a.dosage,
a.unit,
a.dosage2,
a.unit2,
b.mol_eid,
b.mol_name,
a.mol_name_2,
a.atccode,
a.atc_name,
a.nfc_code,
a.manufacturer
FROM drugs a
JOIN drugs b ON a.fo_prd_id != b.fo_prd_id
AND a.prd_name = b.prd_name
AND b.mol_name IS NOT NULL
AND a.mol_name IS NULL;
/*
drop table drugs_update_2;
create table drugs_update_2 as
select distinct a.FO_PRD_ID,a.PRD_NAME,a.MAST_PRD_NAME,a.DOSAGE,a.UNIT,a.DOSAGE2,a.UNIT2,b.MOL_EID,b.MOL_NAME,A.MOL_NAME_2,b.ATCCODE,b.ATC_NAME,b.NFC_CODE,a.MANUFACTURER
from drugs a join
drugs b on a.fo_prd_id!=b.fo_prd_id and
regexp_replace(a.prd_name, '(TABS|CAPS|VIAL|ACCUHALER|SOLUTION|JELLY|UNSPECIFIED|SUBLINGUAL|GEL|SYRUP|TOPICAL|CREAM|PATCH|TRANSD|DROPS|SUPP|AMP|\d).*','','g')=regexp_replace(b.prd_name, '(TABS|CAPS|VIAL|ACCUHALER|SOLUTION|JELLY|UNSPECIFIED|SUBLINGUAL|GEL|SYRUP|TOPICAL|CREAM|PATCH|TRANSD|DROPS|SUPP|AMP|\d).*','','g')
and b.mol_name is not null and a.mol_name is null and a.fo_prd_id not in (select fo_prd_id from drugs_update_1)
;
*/
DELETE
FROM drugs
WHERE fo_prd_id IN (
SELECT fo_prd_id
FROM drugs_update_1
);
INSERT INTO drugs
SELECT *
FROM drugs_update_1;
UPDATE drugs
SET PRD_NAME = replace(PRD_NAME, ',', '.')
WHERE PRD_NAME IS NOT NULL;
UPDATE drugs
SET PRD_NAME = REPLACE(PRD_NAME, '"', '');
DROP TABLE IF EXISTS non_drug;
CREATE TABLE non_drug AS
SELECT DISTINCT *
FROM drugs
WHERE ATCCODE IN (
'V01AA07',
'V03AK',
'V04B',
'V04CL',
'V04CX',
'V20',
'D02A',
'D02AD',
'D09A',
'D02AX',
'D02BA',
'D02AC'
)
OR ATCCODE LIKE 'V06%'
OR ATCCODE LIKE 'V07%';
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE PRD_NAME ~ '^TENA |S(\S)?26|STOCKING|ACCU-CHEK|ACCUTREND|STRIPS|WIPES|REMOVER|LOZENGE|KCAL|NUTRISION|BREATH-ALERT|CHAMBER|\sSTRP|REMOVAL|GAUZE|SUPPLY|PROTECTORS|SOUP|DRESS|CLEANSER|BANDAGE|BEVERAGE|RESOURCE|WEIGHT|ENDURA OPTIMIZER|UNDERWEAR|\sSTRP|\sROLL|\sKCAL|\sGAUZE|LENS\sPLUS|LEUKOPLAST|[^IN]TEST[^O]'
AND fo_prd_id NOT IN (
SELECT fo_prd_id
FROM non_drug
);
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE PRD_NAME ~ 'CHEK|BIOTENE|CALOGEN|CETAPHIL|ENSURE|FREESTYLE|HAMILTON|LUBRI|MEDISENSE|CARESENS'
AND fo_prd_id NOT IN (
SELECT fo_prd_id
FROM non_drug
);
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE (
MAST_PRD_NAME LIKE '%SUN%'
OR MAST_PRD_NAME LIKE '%ACCU-CHEK%'
OR MAST_PRD_NAME LIKE '%ACCUTREND%'
)
AND MAST_PRD_NAME NOT LIKE '%SELSUN%'
AND fo_prd_id NOT IN (
SELECT fo_prd_id
FROM non_drug
);
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE mol_name ~ 'IUD|LEUCOCYTES|AMIDOTRIZOATE|BANDAGE';
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE nfc_code ~ 'VZT|VGB|VGA|VZY|VEA|VEK|VZV'
AND fo_prd_id NOT IN (
SELECT fo_prd_id
FROM non_drug
);
INSERT INTO non_drug
SELECT *
FROM drugs
WHERE fo_prd_id::INT IN (
58557,
605075,
19298,
19308,
25214,
19317,
586445,
18816,
33606,
2043629,
26893,
2042567,
2042566,
2043068,
2043069,
2040332,
2047035,
2040625,
588960,
2040344,
586387,
2044122,
588399,
588398,
2041031,
606459,
2050029,
2041619,
2048638,
2048639,
2048642,
2042520,
2042519,
2040093,
33512,
2046954,
2046955,
2041294,
2041373,
2042857,
591584,
586298,
602040,
602041,
2049426,
588380,
586462,
586463,
88178,
586441,
88159,
88162,
88175,
88176,
2047881,
2044399,
2044254,
2047085,
88083,
2043833,
34825,
34959,
587498,
588222,
588432,
588424,
2046588,
58557,
2044042,
2045706,
2045707,
2047191,
2047298,
2045998,
590969,
591417,
32989,
2045897,
605545,
2041685,
2046849,
2045269,
33112,
2041739,
603439,
603440,
2043567,
2039962,
2044712,
34497,
2045725,
2050730,
2046632,
2042292,
2045041,
2041396,
2043896,
2040362,
2044727,
2041375,
2045040,
2046267,
2045462,
2043020,
22186,
592070,
592243,
4454,
4455,
2042477,
34639,
2046505,
2048158,
3003,
33861,
2040442,
2040443,
2043132,
588198,
588199,
588213,
588214,
2045537,
2047003,
2048682,
2043029,
2042110,
2049484,
6066,
587833,
590535,
2050503,
587949,
588204,
588205,
587822,
588207,
2046494,
586306,
2045668,
2043843,
2042620,
591627,
605549,
605550,
604390,
29291,
2044402,
2042870,
586959,
586960,
2045457,
2047083,
2045458,
2042724,
33648,
605548,
22807,
38919,
587834,
587835,
587668,
586460,
586459,
587836,
2046938,
2048554,
2048555,
2046645,
2044964,
2046937,
586368,
28263,
8530,
588350,
596295,
2043217,
2047595,
2041520,
2042851,
2041971,
27633,
588092,
587563,
2043458,
588334,
588333,
588295,
2047098,
598487,
2048439,
27415,
2043415,
586377,
588215,
2045741,
591367,
11670,
2049800,
2046104,
2925,
38896,
32110,
588306,
588282,
2046493,
2048763,
2047433,
592031,
2044126,
2042908,
2047034,
2050601,
37372,
33939,
586570,
587894,
588200,
2048608,
2041798,
588211,
2047523,
2045932,
16247,
34561,
2048156,
2047403,
2045943,
606044,
2044652,
5591,
5593,
28013,
28012,
36452,
33759,
589922,
605083,
2050328,
605082,
2050837,
34352,
2042067,
2040345,
2042767,
2049047,
2049049,
2047087,
2044051,
2044052,
2050217,
2050218,
589143,
589144,
2041193,
592231,
588373,
2050051,
2049662,
2046869,
2045261,
2043307,
34531,
2042894,
605664,
586308,
6429,
2044683,
2046806,
2049377,
2047681,
34335,
34339,
34336,
2040363,
2046825,
588549,
588548,
2042119
)
AND fo_prd_id NOT IN (
SELECT fo_prd_id
FROM non_drug
);
ALTER TABLE non_drug RENAME COLUMN fo_prd_id TO concept_code;
UPDATE drugs
SET unit = 'MCG'
WHERE unit = 'µg';
UPDATE drugs
SET unit2 = 'MCG'
WHERE unit2 = 'µg';
UPDATE drugs
SET MOL_NAME = 'DIPHTHERIA VACCINE/PERTUSSIS VACCINE/POLIOMYELITIS VACCINE - INACTIVATED/TETANUS VACCINE'
WHERE fo_prd_id IN (
'590079',
'595524',
'590082',
'587459',
'587464'
);
UPDATE drugs
SET MOL_NAME = 'CITRIC ACID/MACROGOL/MAGNESIUM OXIDE/PICOSULFATE/POTASSIUM CHLORIDE/SODIUM CHLORIDE/SODIUM SULFATE'
WHERE fo_prd_id = '586468';
UPDATE drugs
SET MOL_NAME = 'MENINGOCOCCAL VACCINE'
WHERE fo_prd_id = '586227';
UPDATE drugs
SET MOL_NAME = 'AVENA SATIVA/CAFFEINE/CAMELLIA SINENSIS/CARNITINE/CHROMIUM/GARCINIA QUAESITA/GYMNEMA SYLVESTRE/THIOCTIC ACID'
WHERE fo_prd_id = '59136';
UPDATE drugs
SET MOL_NAME = 'CALCIUM/COPPER/ELEUTHEROCOCCUS SENTICOSUS/GINKGO BILOBA/IODINE/MANGANESE/NICOTINIC ACID/PANTOTHENATE/PYRIDOXINE/RIBOFLAVIN/SELENIUM/THIAMINE/ZINC'
WHERE fo_prd_id = '24024';
UPDATE drugs
SET MOL_NAME = 'ALLIUM SATIVUM/ASCORBATE/BETACAROTENE/BIOFLAVONOIDS/CYSTEINE/MANGANESE/NICOTINAMIDE/PANTOTHENATE/PYRIDOXINE/RETINOL/RIBOFLAVIN/SELENIUM/THIOCTIC ACID/TOCOPHEROL/ZINC'
WHERE fo_prd_id = '33708';
UPDATE DRUGS
SET FO_PRD_ID = TRIM(FO_PRD_ID),
PRD_NAME = TRIM(PRD_NAME),
MAST_PRD_NAME = TRIM(MAST_PRD_NAME),
DOSAGE = TRIM(DOSAGE),
UNIT = TRIM(UNIT),
DOSAGE2 = TRIM(DOSAGE2),
MOL_NAME = TRIM(MOL_NAME),
ATCCODE = TRIM(ATCCODE),
ATC_NAME = TRIM(ATC_NAME),
NFC_CODE = TRIM(NFC_CODE),
MANUFACTURER = TRIM(MANUFACTURER);
UPDATE drugs
SET prd_name = 'SALICYLIC ACID & SULFUR AQUEOUS CREAM APF'
WHERE mast_prd_name = 'SALICYLIC ACID & SULFUR AQUEOUS CREAM APF';
--ingredients
DROP TABLE IF EXISTS ingredients;
CREATE TABLE ingredients AS
SELECT DISTINCT unnest(regexp_matches(MOL_NAME, '[^/]+', 'g')) AS ingredient,
FO_PRD_ID
FROM DRUGS
WHERE MOL_NAME IS NOT NULL;
INSERT INTO ingredients
SELECT DISTINCT upper(concept_name),
fo_prd_id
FROM i_map_postprocess
WHERE fo_prd_id NOT IN (
SELECT fo_prd_id
FROM ingredients
);
UPDATE ingredients
SET INGREDIENT = 'NICOTINAMIDE'
WHERE INGREDIENT = 'NICOTINIC ACID';
DELETE
FROM ingredients
WHERE fo_prd_id IN (
SELECT fo_prd_id
FROM no_ds_done
WHERE ingredient_name IS NOT NULL
);
INSERT INTO ingredients
SELECT DISTINCT ingredient_name,
fo_prd_id
FROM no_ds_done
WHERE ingredient_name IS NOT NULL;
DELETE
FROM ingredients
WHERE trim(replace(ingredient, '#', '')) IN (
SELECT trim(replace(concept_name, '#', ''))
FROM RELATIONSHIP_MANUAL_INGREDIENT_DONE
WHERE DUMMY IS NOT NULL
);
/*
create table ingr_2 as (select prd_name, regexp_replace(trim(regexp_replace(regexp_replace(regexp_replace(prd_name,'(CAPSULE|DEVICE|VOLUME|NEBUHALER|SPRAY|CREAM|LOZENGE|MENT|TABLET|NASAL|ROTAHALER|ELEXIR|DROP|INHALER|DAILY|AQ. SUS|EXTRA|OINT|SHAMPOO|BABY|GEL|POWDER|FACE|WASH|SYRUP|AMPOULE|OILY|LIQUI|POWDE|CLEAR SKIN ACNE CONTROL|KIT|ALLERGEN EXTRACTS|BAR|SOAP|CAPSU|SOLUTION|EYE|ORAL|LIQUID|SUPPOS.|AQUEOUS|BP|BPC|APF|LOTION|OINTMENT|SPINHALER)?'),'\s-.*'),'[0-9].*')),'\(.*')
as ingredient,fo_prd_id
from drugs where mol_name is null and fo_prd_id not in (select fo_prd_id from non_drug));
delete ingr_2 where ingredient like '%MULTI%' or ingredient like '%DERM%' or ingredient like '%NEILMED%' or ingredient like '%PAIN%' or ingredient like '%PANADOL%' or ingredient like '%/%' or ingredient like '%RELIEF%' or ingredient like '%PREGNANCY%' or ingredient like '%STRESS%'
;
--ingredeients3-manual table from ingr_2
*/
CREATE TABLE dose_form_test AS
SELECT fo_prd_id AS fo_prd_id,
prd_name AS prd_name,
nfc_code AS nfc_code,
(regexp_matches(prd_name, 'CFC-free inhaler|Capsule|IV dressings|Rectube|adhesive plaster|alcoholic lotion|ampoule|applicator|bandage|bath emulsion|bath oil', 'i')) [1] AS dose_form
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'bath solution|buccal tablet|caplet|capsule|chesty cough linctus|chewable tablet|chewing gum|collodion BP|colourless cream|cream|crystal', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'dental lacquer|diabetic linctus|disks plus disk inhaler|disks refill|dispersible tablet|douche plus fitting|dropper|dry powder spray|dusting powder', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'ear drop|ear spray|effervescent granule|effervescent tablet|emollient cream|eye drop|eye irrigation solution|eye/ear ointment|film|foam|gastro-resistant capsule', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'gastro-resistant tablet|gauze|gauze swab|gel kit|gel plus dressing|gel-forming eye drop|granule|granule.* for suspension|implant|infant suppositorie', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'infusion .*powder for reconstitution|infusion plus diluent|inhalation|inhalation capsule|inhalator|inhaler|inhaler plus spacer|inhaler refill|inhaler solution', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'injection|injection powder|injection .*powder for reconstitution|injection cartridge|injection plus diluent|injection refills|injection solution|injection vial', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'insufflator|intra articular/ intradermal injection|intra articular/intramuscular injection|intra-muscular injection|intramuscular injection .*pdr for recon.*|intranasal solution', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'intrathecal injection|intravenous infusion|intravenous infusion concentrate|intravenous infusion plus buffer|intravenous solution|irrigation solution|junior capsule|junior lozenge', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'linctus|lip protector|lipocream|liquid|lotio-gel|lozenge|maintenance set|matrigel capsule|melt tablet|modified release granule|modified release tablet|mouthwash and gargle', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'multi-dose vial|nail lacquer|nasal gel|nasal ointment|nebuliser solution|nose drop|nose gel|ocular insert|oil|oily cream|oily injection|ointment|ointment & suppositorie|ophthalmic solution', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'oral drop|oral emulsion|oral liquid|oral paint|oral powder|oral syringe|oro-dispersible film|paediatric capsule|paediatric drop|paediatric mixture|paediatric solution', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'paediatric sugar free suspension|paediatric suspension|paediatric syrup|paint|paper|patche|pellet|periodontal gel|pessary plus cream|plaster|poultice|powder|powder for reconstitution', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'prefilled pen|rectal foam|rectal solution|retention enema|sachet|scalp and skin cleanser solution|scalp application|scalp lotion|scalp solution|semi-solid|single dose injection vial', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'single dose unit eye drop|single dose unit eye gel|skin cleanser solution|soluble tablet|spincap|spray|spray application|spray solution|sterile solution|sterile suspension', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'sterile swab|stocking|subcutaneous injection|sublingual tablet|sugar free chewable tablet|sugar free dispersible tablet|sugar free granule|sugar free linctus|sugar free lozenge', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'sugar free mixture|sugar free paediatric linctus|sugar free paediatric syrup|sugar free suspension|supposit|surgical scrub|swab|tablet|tablet pack|tablet .* pessaries|tablet.* plus granule', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, '\stampon|throat spray|toothpaste|topical gel|topical liquid|tube|unit dose blister|unit dose vial|vaginal capsule|vaginal cleansing kit|vaginal cream|vaginal ring|vial|vitrellae', 'i')) [1]
FROM drugs
UNION
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'volatile liquid|vortex metered dose inhaler|wax|PENFILL.*INJECTION', 'i')) [1]
FROM drugs;
INSERT INTO dose_form_test
SELECT fo_prd_id,
prd_name,
nfc_code,
(regexp_matches(prd_name, 'SUPP\s|SUPPO|CAPSULE|SYRUP|SYRINGE|ORALDISTAB|AMPOULE|AUTOHA|INHALE|HALER|CHEW.*GUM|CHEW.*TAB|DISP.*TAB|TABSULE|AUTOINJ|\sPENFILL|PRE-FILLED|SUSPEN|REPETAB|LOTION|VAG.*GEL|GEL.*ORAL|ORAL.*GEL|EYE.*GEL', 'i')) [1]
FROM drugs
UNION ALL
SELECT fo_prd_id,
prd_name,
nfc_code,
substring(prd_name, 'EYE.*OINT|ANAL.*\sOINT|EAR/*\sOINT|\sOINT|\sORAL.*SOL|\sSOL.*ORAL|\sMICROENEMA|\sENEMA|\sNASAL.*DROP|\sDROP|EYE.*DRO|\sEAR.*DRO|\sMOUTHWASH|\sMOUTHWASH.*SOL|\sELIXI|PATCH|\sTABL|\sSHAMPOO|CAPSEAL|\sINJ')
FROM drugs
UNION ALL
SELECT fo_prd_id,
prd_name,
nfc_code,
substring(PRD_NAME, 'NEB.*SOL|PESSARY|INFUSION|WAFER|LINIMENT|MIXTURE|CAPSU|TAB-\d+|\s.*ABLE.*TAB|SOLUTION|PASTE|\sPEN\s|GEL|\sSOLUT\s|\sPOWDE|\sCAP\s|\sPASTILE|\sLOZE\s|EMULSION|MOUTHRINSE|NASAL SPRAY|EYE/EAR DROP|SOFTGELCAP')
FROM drugs;
DELETE
FROM dose_form_test
WHERE dose_form IS NULL;
DELETE
FROM dose_form_test
WHERE fo_prd_id IN (
SELECT concept_code
FROM non_drug
);
INSERT INTO dose_form_test
SELECT fo_prd_id,
prd_name,
nfc_code,
substring(prd_name, '(\sSYR|EYE.*DR|SUSP|AERO|\sCRM|BALM|INH|CREA|ELIXIR|NASAL SPR|PRE.?FILL SYR|SUSP|CAP|AMP|TAB|SHAMPOO|LOZ|OINT|PENFILL)(S)?(\s|$)')
FROM drugs
WHERE fo_prd_id NOT IN (
SELECT fo_prd_id
FROM dose_form_test
)
AND substring(prd_name, '(\sSYR|EYE.*DRP|SUSP|AERO|\sCRM|BALM|INH|CREA|ELIXIR|NASAL SPR|PRE.?FILL SYR|SUSP|CAP|AMP|TAB|SHAMPOO|LOZ|OINT|PENFILL)(S)?(\s|$)') IS NOT NULL
AND fo_prd_id NOT IN (
SELECT concept_code
FROM non_drug
);
INSERT INTO dose_form_test
SELECT fo_prd_id,
prd_name,
nfc_code,
substring(prd_name, '\sSYR|EYE.*DR|SUSP|AERO|\sCRM|BALM|INH|CREA|ELIXIR|NASAL SPR|SOLN')
FROM drugs
WHERE fo_prd_id NOT IN (
SELECT fo_prd_id
FROM dose_form_test
)
AND substring(prd_name, '\sSYR|EYE.*DRP|SUSP|AERO|\sCRM|BALM|INH|CREA|ELIXIR|NASAL SPR|SOLN') IS NOT NULL
AND fo_prd_id NOT IN (
SELECT concept_code
FROM non_drug
);
DELETE
FROM dose_form_test
WHERE fo_prd_id IN (
SELECT fo_prd_id
FROM pack_drug_product_2
);
INSERT INTO dose_form_test (
prd_name,
dose_form
)
SELECT DISTINCT prd_name,
coalesce(substring(substring(upper(prd_name), '_.*'), 'CAP|TAB|CREAM|PATCH|POWDER|SACHET|SUSP|INJ'), substring(upper(prd_name), 'CAP|TABLET|CREAM|SYRUP|INJ|VAGINAL SUPPOSITORY'))
FROM pack_drug_product_2
WHERE coalesce(substring(substring(upper(prd_name), '_.*'), 'CAP|TAB|CREAM|PATCH|POWDER|SACHET|SUSP|INJ'), substring(upper(prd_name), 'CAP|TABLET|CREAM|SYRUP|INJ|VAGINAL SUPPOSITORY')) IS NOT NULL;
UPDATE dose_form_test
SET dose_form = TRIM(upper(dose_form));
DELETE
FROM dose_form_test
WHERE dose_form IS NULL;
UPDATE dose_form_test
SET dose_form = 'TABLET'
WHERE dose_form LIKE 'TAB-%'
OR dose_form = 'TABSULE'
OR dose_form LIKE 'TABLET%'
OR DOSE_FORM LIKE '%REPETAB%'
OR DOSE_FORM LIKE '%TABL'
OR DOSE_FORM ~ 'PAINT|TAB(S)?';
UPDATE dose_form_test
SET dose_form = 'EFFERVESCENT TABLET'
WHERE dose_form LIKE '%EFFERVESCENT%TABLET%';
UPDATE dose_form_test
SET dose_form = 'CHEWABLE TABLET'
WHERE dose_form LIKE '%CHEW%TAB%'
OR DOSE_FORM LIKE '%ABLE%TAB%';
UPDATE dose_form_test
SET dose_form = 'CHEWING GUM'
WHERE dose_form LIKE '%CHEW%GUM%';
UPDATE dose_form_test
SET dose_form = 'DISPERSIBLE TABLET'
WHERE dose_form LIKE '%DISP%TAB%'
OR DOSE_FORM LIKE '%ORALDISTAB%';
UPDATE dose_form_test
SET dose_form = 'SUPPOSITORY'
WHERE dose_form LIKE '%SUPP%';
UPDATE dose_form_test
SET dose_form = 'NASAL DROP'
WHERE dose_form LIKE '%NASAL RELIEF SALINE NASAL DROP%'
OR dose_form = 'NOSE DROP';
UPDATE dose_form_test
SET dose_form = 'ORAL GEL'
WHERE dose_form LIKE '%ORAL %GEL%';
UPDATE dose_form_test
SET dose_form = 'CAPSULE'
WHERE dose_form LIKE '%CAPS%'
OR dose_form = 'CAP'
OR DOSE_FORM = 'SOFTGELCAP';
UPDATE dose_form_test
SET dose_form = 'INJECTION'
WHERE dose_form = 'INJ';
UPDATE dose_form_test
SET dose_form = 'EYE DROP'
WHERE dose_form LIKE '%EYE%DR'
OR dose_form IN (
'EYE DRP',
'EYE DRPS',
'EYE /DRP'
)
OR dose_form ~ 'EYE.*DR';
UPDATE dose_form_test
SET dose_form = 'EYE OINTMENT'
WHERE dose_form LIKE '%EYE%OINT';
UPDATE dose_form_test
SET dose_form = 'VAGINAL GEL'
WHERE dose_form LIKE '%VAG%GEL%';
UPDATE dose_form_test
SET dose_form = 'LOTION'
WHERE dose_form LIKE '%LOT%';
UPDATE dose_form_test
SET dose_form = 'ELIXIR'
WHERE dose_form LIKE '%ELIXI%';
UPDATE dose_form_test
SET dose_form = 'SOLUTION'
WHERE dose_form = 'SOLUTION'
OR dose_form = 'SOLUT'
OR dose_form = 'SOLN';
UPDATE dose_form_test
SET dose_form = 'ORAL SOLUTION'
WHERE dose_form LIKE '%SOLUTION%ORAL%'
OR dose_form = 'ORAL SOL';
UPDATE dose_form_test
SET dose_form = 'ORAL GEL'
WHERE dose_form = 'GEL ORAL'
OR dose_form = 'GEL-ORAL';
UPDATE dose_form_test
SET dose_form = 'INHALATION'
WHERE dose_form = 'INHALATOR'
OR dose_form = 'INHALE'
OR dose_form = 'HALER'
OR dose_form = 'INH'
OR dose_form = 'AERO';
UPDATE dose_form_test
SET dose_form = 'ENEMA'
WHERE dose_form LIKE '%ENEMA%';
UPDATE dose_form_test
SET dose_form = 'INHALATION SOLUTION'