This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard_tables_creation.sql
1295 lines (1271 loc) · 96.2 KB
/
standard_tables_creation.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
/**************************************************************************
* Copyright 2016 Observational Health Data Sciences and Informatics (OHDSI)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors: Anna Ostropolets, Dmitry Dimschitz, Christian Reich
* Date: April 2016
**************************************************************************/
--CREATING UNITED TABLES OUT 3 BATCHES THAT WE WERE GIVEN. AS DRUG_IDENTIFICATION_NUMBER IS UNIQUE WE USED IT INSTEAD OF DRUG CODE
create table drug_product as (
select drug_CODE as old_code,PRODUCT_CATEGORIZATION,CLASS,ltrim(DRUG_IDENTIFICATION_NUMBER,'0') as DRUG_CODE,BRAND_NAME,DESCRIPTOR,PEDIATRIC_FLAG,ACCESSION_NUMBER,NUMBER_OF_AIS,AI_GROUP_NO,
case when DRUG_IDENTIFICATION_NUMBER in (select DRUG_IDENTIFICATION_NUMBER from drug_product_ap) then 'A'
when DRUG_IDENTIFICATION_NUMBER in (select DRUG_IDENTIFICATION_NUMBER from drug_product_ia) then 'D'
else null end as INVALID_REASON
from (
select * from drug_product_ia
union
select * from drug_product_act
union
select * from drug_product_ap)
)
;
insert into drug_product (drug_code, BRAND_NAME)
select ltrim(DIN_STD,'0'),PROD_DESC from additional_list
WHERE ltrim(DIN_STD,'0') not in (
select drug_code from drug_product);
delete drug_product where drug_code in (
select concept_code from non_drug);
delete drug_product where rowid not in (
select min(rowid) from drug_product group by drug_code
)
;
CREATE TABLE ACTIVE_INGREDIENTS
(
DRUG_CODE VARCHAR2(200 Byte),
ACTIVE_INGREDIENT_CODE VARCHAR2(200 Byte),
INGREDIENT VARCHAR2(240 Byte),
STRENGTH VARCHAR2(20 Byte),
STRENGTH_UNIT VARCHAR2(40 Byte),
STRENGTH_TYPE VARCHAR2(40 Byte),
DOSAGE_VALUE VARCHAR2(20 Byte),
DOSAGE_UNIT VARCHAR2(40 Byte),
NOTES VARCHAR2(2000 Byte)
)
TABLESPACE USERS;
insert into active_ingredients
select b.drug_code, ACTIVE_INGREDIENT_CODE,INGREDIENT,STRENGTH,STRENGTH_UNIT,STRENGTH_TYPE,DOSAGE_VALUE,DOSAGE_UNIT,NOTES
from (
select * from active_ingredients_ap
union
select * from active_ingredients_ia
union
select * from active_ingredients_act) a
join drug_product b on old_code=a.drug_Code
;
delete active_ingredients where drug_code in (
select concept_code from non_drug);
create table ingr_add_list as ( --just created this
SELECT ingredient, ltrim(DIN_STD,'0') as drug_code, 'A'||rownum as AIC, regexp_replace (strength,'(/)+(AMP|TAB|BLISTER|SPRAY|CAP|VIAL|SUP|SRT|SRC|LOZ|PCK|KIT|DOSE)') as strength from (
select distinct
trim(regexp_substr(t.MLCL_DESC, '[^\&\;]+', 1, levels.column_value)) as ingredient, DIN_STD,trim(regexp_substr(t.STRNT_DESC, '[^\&]+', 1, levels.column_value)) as strength,rownum
from additional_list t,
table(cast(multiset(select level from dual connect by level <= length (regexp_replace(t.MLCL_DESC, '[^\&\;]+')) + 1) as sys.OdciNumberList)) levels where t.DIN_STD not in (select drug_code from active_ingredients)) );
delete ingr_add_list where drug_code in (select drug_code from active_ingredients);
create table ingr_add_list_2 as(select case when strength like '%/%' then regexp_substr (STRENGTH, '[[:digit:]]*(\.[[:digit:]]+)?') else null end as numerator_value ,
case when strength like '%/%' then regexp_substr (STRENGTH, '(MG|UNIT|X|GM|GM|ML|L|X|G|ACT|MCG|CM)',1,1) else null end as numerator_unit,
case when strength like '%/%' then regexp_substr (strength, '(MG|ML|ACT(s)*|GM|G|Kg|L|X|MCG|CM)$') else null end as denominator_unit,
case when strength like '%/%' then replace (regexp_substr (strength,'/[[:digit:]\.]*'), '/') else null end as denominator_value,
case when strength not like '%/%' then regexp_substr (STRENGTH, '[[:digit:]]*(\.[[:digit:]]+)?') else null end as amount_value,
case when strength not like '%/%' then regexp_replace (STRENGTH, '[[:digit:]]*(\.[[:digit:]]+)?') else null end as amount_unit,
drug_code, ingredient,AIC,strength
from ingr_add_list);
insert into active_ingredients (DRUG_CODE,ACTIVE_INGREDIENT_CODE,INGREDIENT,STRENGTH,STRENGTH_UNIT)
select DRUG_CODE,AIC,INGREDIENT,AMOUNT_VALUE,AMOUNT_UNIT from ingr_add_list_2 where amount_value is not null;
insert into active_ingredients (DRUG_CODE,ACTIVE_INGREDIENT_CODE,INGREDIENT,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
select DRUG_CODE,AIC,INGREDIENT,NUMERATOR_VALUE,NUMERATOR_UNIT,DENOMINATOR_VALUE,DENOMINATOR_UNIT from ingr_add_list_2 where amount_value is null;
delete active_ingredients where ingredient='x';
update active_ingredients set ingredient='SENNOSIDES B' where ingredient='B';
--UPDATING ACTIVE_INGREDIENTS TO REMOVE ORIGINAL TABLES INACCURACY
UPDATE ACTIVE_INGREDIENTS SET STRENGTH_UNIT = 'CH' WHERE DRUG_CODE = '876321' AND INGREDIENT = 'ACETIC ACID';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH_UNIT = '%', DOSAGE_VALUE = '' WHERE DRUG_CODE = '813613' AND INGREDIENT = 'LIDOCAINE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '2.5', STRENGTH_UNIT = '%' WHERE DRUG_CODE = '813613' AND INGREDIENT = 'PRILOCAINE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH_UNIT = 'DH' WHERE DRUG_CODE = '672823' AND INGREDIENT = 'ACONITE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH_UNIT = '%', DOSAGE_VALUE = '' WHERE DRUG_CODE = '2243569' AND INGREDIENT = 'CAMPHOR';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '5.71', STRENGTH_UNIT = '%'WHERE DRUG_CODE = '2243569' AND INGREDIENT = 'PHENOL';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1.24', STRENGTH_UNIT = '%' WHERE DRUG_CODE = '2243569' AND INGREDIENT = 'MENTHOL';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '400', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '649643' AND INGREDIENT = 'MAGNESIUM';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '400', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '649643' AND INGREDIENT = 'SIMETHICONE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '200', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '2084732';
UPDATE ACTIVE_INGREDIENTS SET DOSAGE_UNIT = 'G' WHERE DRUG_CODE = '2237089';
UPDATE ACTIVE_INGREDIENTS SET DOSAGE_VALUE = '0.5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '2239208';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '25', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '649643' AND ACTIVE_INGREDIENT_CODE = 'A32477';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '400', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '649643' AND ACTIVE_INGREDIENT_CODE = 'A6204';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '10.5' WHERE DRUG_CODE = '62812' AND INGREDIENT = 'CAPSICUM';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '5.95' WHERE DRUG_CODE = '190462' AND INGREDIENT = 'VERBASCUM THAPSUS';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '22' WHERE DRUG_CODE = '248207' AND INGREDIENT = 'SENNA';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '6410' WHERE DRUG_CODE = '464988' AND INGREDIENT = 'MODIFIED RAGWEED TYROSINE ADSORBATE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1000' WHERE DRUG_CODE = '894400' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '2.26' WHERE DRUG_CODE = '1900722' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1.25' WHERE DRUG_CODE = '2003856' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1.25' WHERE DRUG_CODE = '2003864' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '2.23' WHERE DRUG_CODE = '634050' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '40' WHERE DRUG_CODE = '695335' AND INGREDIENT = 'BICARBONATE (SODIUM BICARBONATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '120' WHERE DRUG_CODE = '695335' AND INGREDIENT = 'SULFATE (SODIUM SULFATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '20' WHERE DRUG_CODE = '695335' AND INGREDIENT = 'CHLORIDE (POTASSIUM CHLORIDE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '50' WHERE DRUG_CODE = '695335' AND INGREDIENT = 'CHLORIDE (SODIUM CHLORIDE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '2.26' WHERE DRUG_CODE = '662992' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1000' WHERE DRUG_CODE = '658707' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '850' WHERE DRUG_CODE = '1983954' AND INGREDIENT = 'POTASSIUM (POTASSIUM PHOSPHATE DIBASIC)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '950' WHERE DRUG_CODE = '2014149' AND INGREDIENT = 'POTASSIUM (POTASSIUM PHOSPHATE DIBASIC)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '950' WHERE DRUG_CODE = '1991094' AND INGREDIENT = 'POTASSIUM (POTASSIUM PHOSPHATE DIBASIC)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '2.5' WHERE DRUG_CODE = '2023326' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '242' WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'BARBERRY ROOT';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '243' WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'CITRULLUS COLOCYNTHIS';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '42' WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'ALOE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '40' WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'TORMENTILLA';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '41' WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'RHUBARB';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '310' WHERE DRUG_CODE = '2035901' AND INGREDIENT = 'POTASSIUM (POTASSIUM PHOSPHATE DIBASIC)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '240' WHERE DRUG_CODE = '2065983' AND INGREDIENT = 'EUPHORBIA CYPARISSIAS';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '4.5' WHERE DRUG_CODE = '2009137' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '160' WHERE DRUG_CODE = '2200724' AND INGREDIENT = 'POTASSIUM (POTASSIUM IODIDE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '650' WHERE DRUG_CODE = '2230209' AND INGREDIENT = 'POTASSIUM (POTASSIUM CHLORIDE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '160' WHERE DRUG_CODE = '2230429' AND INGREDIENT = 'IODINE (POTASSIUM IODIDE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '773' WHERE DRUG_CODE = '2231927' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '0.635' WHERE DRUG_CODE = '2231064' AND INGREDIENT = 'TITANIUM DIOXIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '0.85' WHERE DRUG_CODE = '2231065' AND INGREDIENT = 'TITANIUM DIOXIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '4.15' WHERE DRUG_CODE = '2231065' AND INGREDIENT = 'OCTINOXATE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1.05' WHERE DRUG_CODE = '2231066' AND INGREDIENT = 'TITANIUM DIOXIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1.55' WHERE DRUG_CODE = '2231068' AND INGREDIENT = 'TITANIUM DIOXIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '21.3125' WHERE DRUG_CODE = '2276569' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '31.0625' WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '52' WHERE DRUG_CODE = '2266121' AND INGREDIENT = 'DELTA-9-TETRAHYDROCANNABINOL (CANNABIS SATIVA EXTRACT)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '745' WHERE DRUG_CODE = '2242013' AND INGREDIENT = 'VITAMIN C (CALCIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '950' WHERE DRUG_CODE = '2240814' AND INGREDIENT = 'CALCIUM (CALCIUM PHOSPHATE MONOBASIC)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '3100' WHERE DRUG_CODE = '2241327' AND INGREDIENT = 'MODIFIED GRASS TYROSINE ADSORBATE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '1440' WHERE DRUG_CODE = '2241328' AND INGREDIENT = 'MODIFIED TREE TYROSINE ADSORBATE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '5.75' WHERE DRUG_CODE = '2406365' AND INGREDIENT = 'OCTINOXATE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '10.39' WHERE DRUG_CODE = '2373793' AND INGREDIENT = 'SODIUM CHLORIDE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '100', STRENGTH_UNIT = 'ML', DOSAGE_VALUE = '100', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '2239576' AND INGREDIENT = 'WATER';
UPDATE ACTIVE_INGREDIENTS SET DOSAGE_VALUE = '0.5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '2241047' AND INGREDIENT = 'WATER';
UPDATE ACTIVE_INGREDIENTS SET DOSAGE_VALUE = '14', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '2405024' AND INGREDIENT = 'TRASTUZUMAB';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '200', STRENGTH_UNIT = 'MG', DOSAGE_VALUE = '5', DOSAGE_UNIT = 'ML' WHERE DRUG_CODE = '569801' AND INGREDIENT = 'MAGNESIUM';
UPDATE ACTIVE_INGREDIENTS SET INGREDIENT = 'salicylic acid' WHERE DRUG_CODE = '2158671';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '263' WHERE DRUG_CODE = '776300' AND INGREDIENT = 'VITAMIN C (POTASSIUM ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '4.26' WHERE DRUG_CODE = '776300' AND INGREDIENT = 'VITAMIN C (ZINC ASCORBATE)';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '242' WHERE DRUG_CODE = '2073226' AND INGREDIENT = 'PAPAVERINE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '13.25' WHERE DRUG_CODE = '2023326' AND INGREDIENT = 'DEXTROSE';
UPDATE ACTIVE_INGREDIENTS SET STRENGTH = '0.1', STRENGTH_UNIT = '%' WHERE DRUG_CODE = '2023326' AND INGREDIENT = 'EPINEPHRINE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '776300' AND INGREDIENT = 'POTASSIUM (POTASSIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '776300' AND INGREDIENT = 'ZINC (ZINC ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2073226' AND INGREDIENT = 'PAPAVERINE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2073226' AND INGREDIENT = 'PAPAVERINE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2023326' AND INGREDIENT = 'DEXTROSE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '62812' AND INGREDIENT = 'CAPSICUM';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '190462' AND INGREDIENT = 'VERBASCUM THAPSUS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '248207' AND INGREDIENT = 'SENNA';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '464988' AND INGREDIENT = 'MODIFIED RAGWEED TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '464988' AND INGREDIENT = 'MODIFIED RAGWEED TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '464988' AND INGREDIENT = 'MODIFIED RAGWEED TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '894400' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '1900722' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2003856' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2003864' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2003864' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '634050' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '695335' AND INGREDIENT = 'POTASSIUM (POTASSIUM CHLORIDE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '695335' AND INGREDIENT = 'SODIUM (SODIUM SULFATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '695335' AND INGREDIENT = 'SODIUM (SODIUM BICARBONATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '695335' AND INGREDIENT = 'SODIUM (SODIUM CHLORIDE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '711470' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '662992' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '658707' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '1983954' AND INGREDIENT = 'PHOSPHORUS (POTASSIUM PHOSPHATE DIBASIC)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2014149' AND INGREDIENT = 'PHOSPHORUS (POTASSIUM PHOSPHATE DIBASIC)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '1991094' AND INGREDIENT = 'PHOSPHORUS (POTASSIUM PHOSPHATE DIBASIC)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2023326' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'BARBERRY ROOT';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'BARBERRY ROOT';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'BARBERRY ROOT';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'CITRULLUS COLOCYNTHIS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'CITRULLUS COLOCYNTHIS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2029731' AND INGREDIENT = 'CITRULLUS COLOCYNTHIS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'ALOE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'ALOE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'TORMENTILLA';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'RHUBARB';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2030675' AND INGREDIENT = 'RHUBARB';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2035901' AND INGREDIENT = 'PHOSPHORUS (POTASSIUM PHOSPHATE DIBASIC)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2065983' AND INGREDIENT = 'EUPHORBIA CYPARISSIAS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2065983' AND INGREDIENT = 'EUPHORBIA CYPARISSIAS';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2009137' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2009137' AND INGREDIENT = 'LIDOCAINE HYDROCHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2200724' AND INGREDIENT = 'IODINE (POTASSIUM IODIDE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2230209' AND INGREDIENT = 'CHLORINE (POTASSIUM CHLORIDE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2230429' AND INGREDIENT = 'POTASSIUM (POTASSIUM IODIDE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231927' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231064' AND INGREDIENT = 'TITANIUM DIOXIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231065' AND INGREDIENT = 'TITANIUM DIOXIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231066' AND INGREDIENT = 'OXYBENZONE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231066' AND INGREDIENT = 'TITANIUM DIOXIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2231068' AND INGREDIENT = 'TITANIUM DIOXIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276569' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276569' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276569' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276569' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2276577' AND INGREDIENT = 'METHACHOLINE CHLORIDE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2266121' AND INGREDIENT = 'CANNABIDIOL (CANNABIS SATIVA EXTRACT)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2242013' AND INGREDIENT = 'CALCIUM (CALCIUM ASCORBATE)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2240814' AND INGREDIENT = 'PHOSPHORUS (CALCIUM PHOSPHATE MONOBASIC)';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2241327' AND INGREDIENT = 'MODIFIED GRASS TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2241327' AND INGREDIENT = 'MODIFIED GRASS TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2241328' AND INGREDIENT = 'MODIFIED TREE TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2241328' AND INGREDIENT = 'MODIFIED TREE TYROSINE ADSORBATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2406365' AND INGREDIENT = 'AVOBENZONE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2406365' AND INGREDIENT = 'OCTOCRYLENE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2406365' AND INGREDIENT = 'OCTINOXATE';
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2373793' AND INGREDIENT = 'SODIUM CHLORIDE';
--DELETING DUPLICATES
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2439042' AND ACTIVE_INGREDIENT_CODE = 11564;
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2246512' AND ACTIVE_INGREDIENT_CODE = 6487;
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2210614' AND ACTIVE_INGREDIENT_CODE = 331;
DELETE FROM ACTIVE_INGREDIENTS WHERE DRUG_CODE = '2210622' AND ACTIVE_INGREDIENT_CODE = 331;
create table route as(
select b.drug_code, ROUTE_OF_ADMINISTRATION from (
select * from route_ap
union
select * from route_ia
union
select * from route_act
) a join drug_product b on old_code=a.drug_Code);
delete route where drug_code in (select concept_code from non_drug)
;
create table form as(
select b.drug_code, PHARMACEUTICAL_FORM from (
select * from form_ap
union
select * from form_ia
union
select * from form_act
) a join drug_product b on old_code=a.drug_Code);
delete form where drug_code in (select concept_code from non_drug);
insert into form (drug_code, PHARMACEUTICAL_FORM)
select ltrim(DIN_STD,'0'),FORM_NM from additional_list WHERE ltrim(DIN_STD,'0') not in (select drug_code from drug_product)
;
create table packaging as(
select b.DRUG_CODE,PACKAGE_SIZE_UNIT,PACKAGE_TYPE,PACKAGE_SIZE,PRODUCT_INFORMATION from (
select * from packaging_ap
union
select * from packaging_ia
union
select * from packaging_act
)a join drug_product b on old_code=a.drug_Code);
delete packaging where drug_code in (select concept_code from non_drug);
insert into packaging (drug_code, PRODUCT_INFORMATION)
select ltrim(DIN_STD,'0'), PACK_DESC from additional_list WHERE ltrim(DIN_STD,'0') not in (select drug_code from drug_product)
;
create table status as(
select b.drug_Code, STATUS,HISTORY_DATE,CURRENT_STATUS_FLAG from (
select * from status_ap
union
select * from status_ia
union
select * from status_act
)a join drug_product b on old_code=a.drug_Code);
delete status where drug_code in (select concept_code from non_drug)
;
create table companies as(
select b.drug_Code, MFR_CODE,COMPANY_CODE,COMPANY_NAME,COMPANY_TYPE,ADDRESS_MAILING_FLAG,ADDRESS_BILLING_FLAG,ADDRESS_NOTIFICATION_FLAG,ADDRESS_OTHER,SUITE_NUMBER,STREET_NAME,CITY_NAME,PROVINCE,COUNTRY,POSTAL_CODE,POST_OFFICE_BOX from (
select * from companies_ap
union
select * from companies_ia
union
select * from companies_act
)a join drug_product b on old_code=a.drug_Code);
delete companies where drug_code in (select concept_code from non_drug)
;
create table therapeutic_class as(
select b.drug_Code, TC_ATC_NUMBER,TC_ATC,TC_AHFS_NUMBER,TC_AHFS from(
select * from therapeutic_class_act
union
select * from therapeutic_class_ap
union
select * from therapeutic_class_ia
)a join drug_product b on old_code=a.drug_Code);
insert into therapeutic_class (DRUG_CODE,TC_ATC_NUMBER,TC_ATC)
select ltrim(DIN_STD,'0'),ATC4_CD,ATC4_DESC from additional_list WHERE ltrim(DIN_STD,'0') not in (select drug_code from drug_product);
--INGREDIENTS
create table ingr as (select drug_CODE as concept_code, active_ingredient_Code as AIC, ingredient as concept_name,
'Ingredient' as concept_class_id from active_ingredients);
--UPDATING INGREDIENTS IN ORDER TO DELETE ALL UNNECESSARY INFORMATION
update ingr
set concept_name=regexp_replace (concept_name,' \(.*\)')
WHEre regexp_LIKE (concept_name,'\(.*\)$')
and upper(concept_name) not like '%(%HUMAN)%'
and upper(concept_name) not like '%(%RABBIT)%'
and upper(concept_name) not like '%(%RECOMBINANT%)%'
and upper(concept_name) not like '%(%SYNTHETIC)%'
and upper(concept_name) not like '%(%ACTIVATED)%'
and upper(concept_name) not like '%(%OVINE)%'
and upper(concept_name) not like '%(%ANHYDROUS)%'
and upper(concept_name) not like '%VICTORIA%'
and upper(concept_name) not like '%YAMAGATA%'
and upper(concept_name) not like '%(PMSG)%'
and upper(concept_name) not like '%(%H3N2)%'
and upper(concept_name) not like '%(%H1N1)%'
and upper(concept_name) not like '%(NPH)'
and upper(concept_name) not like '%(8)%'
and upper(concept_name) not like '%(V.C.O%)%'
and upper(concept_name) not like '%(D.C.O%)%'
and upper(concept_name) not like '%(FIM)%'
and upper(concept_name) not like '%(PRP-T)%'
and upper(concept_name) not like '%(FSH)%'
and upper(concept_name) not like '%(BCG)%'
and upper(concept_name) not like '%(R-METHUG-CSF)%'
and upper(concept_name) not like '%(MCT)%'
and upper(concept_name) not like '%(JERYL LYNN STRAIN)%'
and upper(concept_name) not like '%(EQUINE)%'
and upper(concept_name) not like '%(DILUENT)%'
and upper(concept_name) not like '%(WISTAR RA27/3 STRAIN)%'
and upper(concept_name) not like '%(EDMONSTON B STRAIN)%'
and upper(concept_name) not like '%(HAEMAGGLUTININ-STRAIN B%)%'
and concept_name not like '%(Neisseria meningitidis group B NZ98/254 strain)%'
and concept_name not like '%(2)%'
and concept_name not like '%(%DOLOMITE%)%'
and concept_name not like '%(TUBERCULIN TINE TEST)%'
and concept_name not like '%(LEAVES)%'
and concept_name not like '%(ACETATE)'
and concept_name not like '%(KELP, POTASSIUM IODIDE)%'
and concept_name not like '%(TI 201)%'
and concept_name not like '%[CU(MIB)4]BF4'
and concept_name not like '%(ETHYLENEOXY)%'
and concept_name not like '%(CALCIFEROL)%'
and concept_name not like '%(MA HUANG)%'
and concept_name not like '%(%BASIC)'
and concept_name not like '%(EXT.)%'
and concept_name not like '%(CALF)%'
and concept_name not like '%(LIVER)%'
and concept_name not like '%(PAW%'
and concept_name not like '%(PORK)%';
update ingr
set concept_name=regexp_replace (concept_name,' \(.*\)')
WHEre concept_name like '%(%BASIC%)' and concept_name not like '%(DIBASIC)' and concept_name not like '%(TRIBASIC)';
update ingr
set concept_name=regexp_replace (concept_name,' \(.*\)') where concept_name like '%(%,%)%' and concept_code in (select concept_code from ingr_OMOP);
--CREATE TABLE WITH PRECISE NAME TAKEN FROM ORIGINAL TABLE TO USE LATER
create table ingr_OMOP as (select distinct drug_CODE as concept_code, active_ingredient_Code as AIC, ingredient as concept_name,
'Ingredient' as concept_class_id from active_ingredients);
update ingr_OMOP
set concept_name=regexp_SUBSTR (concept_name,'\(.*\)')
WHEre upper(concept_name) not like '%(%HUMAN)'
and upper(concept_name) not like '%(%RABBIT)'
and upper(concept_name) not like '%(%RECOMBINANT%)'
and upper(concept_name) not like '%(%SYNTHETIC)'
and upper(concept_name) not like '%(%ACTIVATED)'
and upper(concept_name) not like '%(%OVINE)'
and upper(concept_name) not like '%(%ANHYDROUS)'
and upper(concept_name) not like '%(%BASIC%)'
and upper(concept_name) not like '%VICTORIA%'
and upper(concept_name) not like '%YAMAGATA%'
and upper(concept_name) not like '%(PMSG)'
and upper(concept_name) not like '%(%H3N2)'
and upper(concept_name) not like '%(%H1N1)'
and upper(concept_name) not like '%(NPH)'
and upper(concept_name) not like '%(8)'
and upper(concept_name) not like '%(V.C.O%)%'
and upper(concept_name) not like '%(D.C.O%)%'
and upper(concept_name) not like '%(FIM)'
and upper(concept_name) not like '%(PRP-T)'
and upper(concept_name) not like '%(FSH)'
and upper(concept_name) not like '%(BCG)'
and upper(concept_name) not like '%(R-METHUG-CSF)'
and upper(concept_name) not like '%(MCT)'
and upper(concept_name) not like '%(JERYL LYNN STRAIN)'
and upper(concept_name) not like '%(EQUINE)'
and upper(concept_name) not like '%(DILUENT)'
and upper(concept_name) not like '%(WISTAR RA27/3 STRAIN)'
and upper(concept_name) not like '%(SACUBITRIL VALSARTAN SODIUM HYDRATE COMPLEX)'
and upper(concept_name) not like '%(EDMONSTON B STRAIN)'
and upper(concept_name) not like '%(HAEMAGGLUTININ-STRAIN B%)'
and concept_name not like '%(Neisseria meningitidis group B NZ98/254 strain)'
and concept_name not like '%(2)%'
and concept_name not like '%(%DOLOMITE%)%'
and concept_name not like '%(TUBERCULIN TINE TEST)%'
and concept_name not like '%(%BONE MEAL%)%'
and concept_name not like '%(FISH OIL)%'
and concept_name not like '%(LEMON GRASS)%'
and concept_name not like '%(LEAVES)%'
and concept_name not like '%(ACETATE)'
and concept_name not like '%(%YEAST%)%'
and concept_name not like '%(KELP%)%'
and concept_name not like '%(TI 201)%'
and concept_name not like '%(COD LIVER OIL)%'
and concept_name not like '%[CU(MIB)4]BF4'
and concept_name not like '%(ETHYLENEOXY)%'
and concept_name not like '%(PAPAYA)%'
and concept_name not like '%(CALCIFEROL)%'
and concept_name not like '%(MA HUANG)%'
and concept_name not like '%(HORSETAIL)%'
and concept_name not like '%(FLAXSEED)%'
and concept_name not like '%(EXT.)%'
and concept_name not like '%(ROTH)%'
and concept_name not like '%(CALF)%'
and concept_name not like '%(PINEAPPLE)%'
and concept_name not like '%(LIVER)%'
and concept_name not like '%(PAW%'
and concept_name not like '%(PORK)%';
update ingr_OMOP
set concept_name=regexp_SUBSTR (concept_name,'\(.*\)')
where concept_name like '%(%BASIC%)' and concept_name not like '%(DIBASIC)' and concept_name not like '%(TRIBASIC)';
delete ingr_OMOP where concept_name is null;
delete ingr_OMOP where upper(concept_name) like '%(MCT)'
or upper(concept_name) like '%(%HUMAN)'
or upper(concept_name) like '%(%RABBIT)'
or upper(concept_name) like '%(%RECOMBINANT%)'
or upper(concept_name) like '%(%SYNTHETIC)'
or upper(concept_name) like '%(%ACTIVATED)'
or upper(concept_name) like '%(%OVINE)'
or upper(concept_name) like '%(%ANHYDROUS)'
or upper(concept_name) like '%VICTORIA%'
or upper(concept_name) like '%YAMAGATA%'
or upper(concept_name) like '%(PMSG)'
or upper(concept_name) like '%(%H3N2)'
or upper(concept_name) like '%(%H1N1)'
or upper(concept_name) like '%(NPH)'
or upper(concept_name) like '%(8)'
or upper(concept_name) like '%(V.C.O%)%'
or upper(concept_name) like '%(D.C.O%)%'
or upper(concept_name) like '%(FIM)'
or upper(concept_name) like '%(PRP-T)'
or upper(concept_name) like '%(FSH)'
or upper(concept_name) like '%(BCG)'
or upper(concept_name) like '%(R-METHUG-CSF)'
or upper(concept_name) like '%(JERYL LYNN STRAIN)'
or upper(concept_name) like '%(EQUINE)'
or upper(concept_name) like '%(DILUENT)'
or upper(concept_name) like '%(WISTAR RA27/3 STRAIN)'
or upper(concept_name) like '%(SACUBITRIL VALSARTAN SODIUM HYDRATE COMPLEX)'
or upper(concept_name) like '%(EDMONSTON B STRAIN)'
or upper(concept_name) like '%(HAEMAGGLUTININ-STRAIN B%)'
or concept_name like '%(Neisseria meningitidis group B NZ98/254 strain)'
or concept_name like '%(2)%'
or concept_name like '%(%DOLOMITE%)%'
or concept_name like '%(TUBERCULIN TINE TEST)%'
or concept_name like '%(BONE%'
or concept_name like '%(%OIL)%'
or concept_name like '%(LEMON GRASS)%'
or concept_name like '%(LEAVES)%'
or concept_name like '%(ACETATE)'
or concept_name like '%(%YEAST%)%'
or concept_name like '%(KELP%)%'
or concept_name like '%(TI 201)%'
or concept_name like '%(COD LIVER OIL)%'
or concept_name like '%[CU(MIB)4]BF4'
or concept_name like '%(ETHYLENEOXY)%'
or concept_name like '%(PAPAYA)%'
or concept_name like '%(CALCIFEROL)%'
or concept_name like '%(MA HUANG)%'
or concept_name like '%(HORSETAIL)%'
or concept_name like '%(FLAXSEED)%'
or concept_name like '%(EXT.)%'
or concept_name like '%(ROTH)%'
or concept_name like '%(CALF)%'
or concept_name like '%(PINEAPPLE)%'
or concept_name like '%(LIVER)%'
or concept_name like '%(PAW%'
or concept_name like '%(PORK)%';
update ingr_OMOP
set concept_name=regexp_replace (concept_name,'\(');
update ingr_OMOP
set concept_name=regexp_replace (concept_name,'\)');
delete ingr_OMOP where concept_name like '%OIL%';
delete ingr_OMOP where concept_name like '%EGG%';
delete ingr_OMOP where concept_name like '%BONE%';
delete ingr_OMOP where concept_name like '%CRYSTALS%';
delete ingr_OMOP where concept_name like '%,%' and concept_name not like '%KELP%';
delete ingr_OMOP where concept_name like '%ACEROLA%';
delete ingr_OMOP where concept_name like '%ROSE HIPS%';
delete ingr_OMOP where concept_name like '%BUCKWHEAT%';
delete ingr_OMOP where concept_name like '%1-PIPERIDYLTHIOCARBONYL%';
delete ingr_OMOP where concept_name like '%ALOE%';
delete ingr_OMOP where concept_name='D.C.O.';
delete ingr_OMOP where concept_name like '%VITAMIN%';
delete ingr_OMOP where concept_name='BCG';
delete ingr_OMOP where concept_name like '%SENNA%';
delete ingr_OMOP where concept_name like '%OYSTER%';
delete ingr_OMOP where concept_name like '%WHEAT%';
delete ingr_OMOP where concept_name='DEXTROSE';
delete ingr_OMOP where concept_name='EPHEDRA';
delete ingr_OMOP where concept_name='CIG';
delete ingr_OMOP where concept_name='BLACK CURRANT';
delete ingr_OMOP where concept_name='ATTENUAT. STRAIN SA14-14-2 PRODUCED IN VERO CELLS';
delete ingr_OMOP where concept_name='FEVERFEW';
delete ingr_OMOP where concept_name='EXTRACT';
delete ingr_OMOP where concept_name='H1N1V-LIKE STRAIN X-179A';
delete ingr_OMOP where concept_name='H5N1';
delete ingr_OMOP where concept_name='HOMEO';
delete ingr_OMOP where concept_name='III';
delete ingr_OMOP where concept_name='INS';
delete ingr_OMOP where concept_name='LIVER EXTRACT';
delete ingr_OMOP where concept_name='PRP';
delete ingr_OMOP where concept_name='NUTMEG';
delete ingr_OMOP where concept_name='RHPDGF-BB';
delete ingr_OMOP where concept_name='SAGO PALM';
delete ingr_OMOP where concept_name='SEA PROTEINATE';
delete ingr_OMOP where concept_name='SOYBEAN';
delete ingr_OMOP where concept_name='VIRIDANS AND NON-HEMOLYTIC';
delete ingr_OMOP where concept_name='PURIFIED CHICK EMBRYO CELL CULTURE';
delete ingr_OMOP where concept_name='DURAPATITE';
delete ingr_OMOP where concept_name='OXYCARBONATE';
delete ingr_OMOP where concept_name='BENZOTHIAZOLE' ;
delete ingr_OMOP where concept_name='BENZOTHIAZOLE' ;
delete ingr_OMOP where concept_name like '%ASPERGILLUS%';
delete ingr_OMOP where concept_name like '%ANANAS%';
delete ingr_OMOP where concept_name like '%BARLEY%';
delete ingr_OMOP where concept_name like '%BORAGO%';
delete ingr_OMOP where concept_name='MORPHOLINOTHIO';
delete ingr_OMOP where concept_name='OKA/MERCK STRAIN';
delete ingr_OMOP where concept_name like '%RHIZOPUS%';
delete ingr_OMOP where concept_name like '%DRIED%';
delete ingr_OMOP where concept_name='S';
DELETE FROM INGR_OMOP WHERE CONCEPT_CODE = '782971' AND AIC = '10225' AND CONCEPT_NAME = 'POVIDONE-IODINE';
DELETE FROM INGR_OMOP WHERE CONCEPT_CODE = '593710' AND AIC = '105' AND CONCEPT_NAME = 'MAGNESIUM OXIDE';
DELETE FROM INGR_OMOP WHERE CONCEPT_CODE = '94498' AND AIC = '778' AND CONCEPT_NAME = 'MAGNESIUM CITRATE';
--CREATING TABLE WITH FINAL INGREDIENT NAMES, ALSO WILL BE USED IN DRUG_STRENGTH_STAGE.PICN STANDS FOR PRECISE INGREDIENT CONCEPT NAME
create table ingr_2 as
select distinct a.concept_name as PICN,c.CONCEPT_CODE,c.AIC,c.CONCEPT_NAME,STRENGTH,STRENGTH_UNIT,
STRENGTH_TYPE,DOSAGE_VALUE,DOSAGE_UNIT,NOTES from ingr c join active_ingredients b on c.AIC=b.active_ingredient_code and b.drug_Code=c.concept_code
left join ingr_OMOP a on a.AIC=c.AIC and a.concept_code=c.concept_code and regexp_like(INGREDIENT,a.concept_name)
;
update ingr_2
set concept_name=PICN where PICN is not null;
update ingr_2
set concept_name=regexp_replace (concept_name,' \(.*\)')
WHEre upper(concept_name) like '%(%,%)%' or upper(concept_name) like '%(DOLOMITE)%' or upper(concept_name) like '%(LIVER)%' or upper(concept_name) like '%(CALCIFEROL)%' or upper(concept_name) like '%(ACETATE)%';
update ingr_2 set dosage_unit='%' where strength_unit='%' and dosage_unit is null
;
--PARCING INGREDIENT 'ALUMINUM HYDROXIDE-MAGNESIUM CARBONATE-CO DRIED GEL' INTO TWO PARTS WITH RELATIVE DOSAGE
delete ingr_2 where aic='3980';
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (116882,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (116882,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (13838,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (13838,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (1988786 ,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (1988786 ,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2004046,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2004046,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2124998,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2124998,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2162318,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2162318,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2162326,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (2162326,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (407453,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (407453,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (457310,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (457310,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (649651,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (649651,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (540846,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (540846,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (478865,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (478865,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
insert into ingr_2 (concept_code, AIC, concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (608521,3980,'ALUMINUM HYDROXIDE',184,'MG',10,'ML');
insert into ingr_2 (concept_code,AIC,concept_name,STRENGTH,STRENGTH_UNIT,DOSAGE_VALUE,DOSAGE_UNIT)
values (608521,3980,'MAGNESIUM CARBONATE',116,'MG',10,'ML');
UPDATE ingr_2 SET STRENGTH = '10' WHERE STRENGTH = ' 10' AND STRENGTH_UNIT = '%' AND DOSAGE_VALUE IS NULL AND DOSAGE_UNIT = '%' AND concept_CODE = '2229776';
UPDATE ingr_2 SET concept_name='SENNOSIDES B' where concept_name='B';
delete ingr_2 where concept_name='x';
--DELETING ALL PSEUDO-UNITS
update ingr_2
set strength_unit=null
where STRENGTH_UNIT='NIL';
update ingr_2
set strength=null
where STRENGTH='0';
update ingr_2
set dosage_unit=null where dosage_unit in ('TAB', 'CAP','BLISTER','LOZ','PCK','PIECE', 'SUP', 'ECT','NS','EVT','TSP','GUM','SRC','WAF','SRT','SUT','SLT','SRD','DOSE','DROP','SPRAY','VIAL', 'CARTRIDGE','INSERT',
'CARTRIDGE','INSERT','GUM','PAD' ,'PATCH' ,'PCK' ,'PEN' ,'SUT' ,'SYR' ,'TBS' ,'W/W','W/V','V/V','V/W','CYLR','ECT','IMP','SUP','JAR','SYR','SRT','PAIL','VTAB',
'CH','CAN','D','DH','EVT','ECC','ECT','XMK','X','CAP','LOZ','BLISTER','PIECE','WAF','SRC','TSP','SLT','NS','PAD','AMP','BOTTLE','TEA','KIT','STRIP','NIL','GM')
;
--TABLE WITH INGREDIENTS FOR DRUG_CONCEPT_STAGE
create table ingr_all as(
select distinct concept_name, 'Ingredient' as concept_class_id from ingr_2)
;
--FORMS
create table forms as (
select distinct ROUTE_OF_ADMINISTRATION||' '||PHARMACEUTICAL_FORM as concept_name,
'Dose Form' as concept_class_id, drug_Code
from (
select a.DRUG_CODE,PHARMACEUTICAL_FORM,ROUTE_OF_ADMINISTRATION from form a
left join route b on a.drug_code=b.drug_code
where a.drug_code in (
select drug_Code from drug_product
)));
UPDATE FORMS SET CONCEPT_NAME = 'SOLUTION' WHERE CONCEPT_NAME = '0-UNASSIGNED SOLUTION' AND CONCEPT_CLASS_ID = 'Dose Form';
--CREATING TABLES CONTAINING PAIRS OF DRUGS WITH THE SAME DRUG_CODE BUT DIFFERENT FORM. THESE DRUGS AREN'T REAL KITS SO WE ARE MAKING THEM OF ONE FORM
create table temp1 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='DROPS' and b.PHARMACEUTICAL_FORM='SUSPENSION');
create table temp2 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='DROPS' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp3 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LOTION' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp4 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp5 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='METERED-DOSE AEROSOL' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp6 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='OINTMENT' and b.PHARMACEUTICAL_FORM='PAD');
create table temp8 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='SUSPENSION');
create table temp9 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='ENEMA' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp11 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp12 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SUSPENSION' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp13 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='METERED-DOSE AEROSOL' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp14 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='POWDER FOR SOLUTION');
create table temp15 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp16 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='POWDER FOR SOLUTION');
create table temp17 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp18 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='PACKAGE' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp19 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='AEROSOL' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp20 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='POWDER FOR SOLUTION' and b.PHARMACEUTICAL_FORM='PACKAGE');
create table temp21 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='MOUTHWASH/GARGLE');
create table temp22 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SOLUTION' and b.PHARMACEUTICAL_FORM='POWDER FOR SOLUTION');
create table temp23 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LOTION' and b.PHARMACEUTICAL_FORM='KIT');
create table temp24 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='POWDER FOR SUSPENSION,SUSTAINED-RELEASE' and b.PHARMACEUTICAL_FORM='KIT');
create table temp25 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SOLUTION' and b.PHARMACEUTICAL_FORM='MOUTHWASH/GARGLE');
create table temp26 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='POWDER FOR SUSPENSION');
create table temp27 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='METERED-DOSE AEROSOL' and b.PHARMACEUTICAL_FORM='SUSPENSION');
create table temp29 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='METERED-DOSE AEROSOL' and b.PHARMACEUTICAL_FORM='SPRAY');
create table temp10 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='MOUTHWASH/GARGLE' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp7 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='POWDER FOR SOLUTION' and b.PHARMACEUTICAL_FORM='AEROSOL');
create table temp30 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='POWDER' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp31 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='EMULSION');
create table temp32 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='JELLY');
create table temp33 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TABLET (ENTERIC-COATED)' and b.PHARMACEUTICAL_FORM='TABLET (EXTENDED-RELEASE)');
create table temp34 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TABLET' and b.PHARMACEUTICAL_FORM='TABLET (EXTENDED-RELEASE)');
create table temp35 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SHAMPOO' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp36 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='OINTMENT' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp37 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GEL' and b.PHARMACEUTICAL_FORM='TOOTHPASTE');
create table temp38 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp39 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='PAD' and b.PHARMACEUTICAL_FORM='PLASTER');
create table temp40 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GLOBULES' and b.PHARMACEUTICAL_FORM='TABLET');
create table temp41 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GRANULES' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp42 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GRANULES' and b.PHARMACEUTICAL_FORM='DROPS');
create table temp43 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='CAPSULE');
create table temp44 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='TABLET');
create table temp45 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SUSPENSION' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp46 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TOOTHPASTE' and b.PHARMACEUTICAL_FORM='PASTE');
create table temp47 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='LIQUID');
create table temp48 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='LOTION');
create table temp50 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='OINTMENT');
create table temp49 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GEL' and b.PHARMACEUTICAL_FORM='SHAMPOO');
create table temp51 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GLOBULES' and b.PHARMACEUTICAL_FORM='GRANULES');
create table temp52 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CAPSULE (IMMEDIATE RELEASE)' and b.PHARMACEUTICAL_FORM='CAPSULE (EXTENDED RELEASE)');
create table temp53 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SUSPENSION' and b.PHARMACEUTICAL_FORM='CREAM');
create table temp54 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TABLET (EXTENDED-RELEASE)' and b.PHARMACEUTICAL_FORM='TABLET (DELAYED-RELEASE)');
create table temp55 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='DROPS' and b.PHARMACEUTICAL_FORM='POWDER');
create table temp56 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='KIT' and b.PHARMACEUTICAL_FORM='POWDER FOR SUSPENSION, SUSTAINED-RELEASE');
create table temp57 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='ENEMA' and b.PHARMACEUTICAL_FORM='SUSPENSION');
create table temp58 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='WIPE' and b.PHARMACEUTICAL_FORM='CREAM');
create table temp59 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='METERED-DOSE AEROSOL' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp60 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TABLET (IMMEDIATE RELEASE)' and b.PHARMACEUTICAL_FORM='TABLET (EXTENDED-RELEASE)');
create table temp61 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='AEROSOL' and b.PHARMACEUTICAL_FORM='LOTION');
create table temp62 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='TOOTHPASTE');
create table temp63 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='SOLUTION');
create table temp64 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='SOAP BAR');
create table temp65 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LOTION' and b.PHARMACEUTICAL_FORM='SOAP BAR');
create table temp66 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GLOBULES' and b.PHARMACEUTICAL_FORM='DROPS');
create table temp67 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='LOTION');
create table temp68 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='PACKAGE' and b.PHARMACEUTICAL_FORM='TEA (HERBAL)');
create table temp69 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='GAS');
create table temp70 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='TINCTURE' and b.PHARMACEUTICAL_FORM='SPRAY');
create table temp71 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SHAMPOO' and b.PHARMACEUTICAL_FORM='LOTION');
create table temp72 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='DROPS');
create table temp73 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SOLUTION' and b.PHARMACEUTICAL_FORM='SPONGE');
create table temp74 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='SPONGE');
create table temp75 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='PELLET');
create table temp76 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code where b.PHARMACEUTICAL_FORM='STICK');
create table temp77 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='IMPLANT' and b.PHARMACEUTICAL_FORM='KIT');
create table temp78 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='CREAM' and b.PHARMACEUTICAL_FORM='KIT');
create table temp79 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='GEL' and b.PHARMACEUTICAL_FORM='KIT');
create table temp80 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LIQUID' and b.PHARMACEUTICAL_FORM='PAD');
create table temp81 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SPRAY' and b.PHARMACEUTICAL_FORM='EMULSION');
create table temp82 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='SOAP BAR' and b.PHARMACEUTICAL_FORM='GEL');
create table temp83 (drug_code varchar (255) ); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231806'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231807'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231816'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231817'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231820');
INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231822'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231823'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231826'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2231827'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2232001'); INSERT INTO TEMP83( DRUG_CODE)VALUES( '2232004');
create table temp84 (drug_code varchar (255) ); INSERT INTO TEMP84( DRUG_CODE)VALUES( '415820'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '419087'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '432172'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '724491');
INSERT INTO TEMP84( DRUG_CODE)VALUES( '505900'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '509159'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '510874'); INSERT INTO TEMP84( DRUG_CODE)VALUES( '724041');
create table temp85 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='AEROSOL' and b.PHARMACEUTICAL_FORM='SHAMPOO');
create table temp86 as (select c.drug_code from drug_product c join form b on c.drug_code=b.drug_code join form a on c.drug_code=a.drug_code where a.PHARMACEUTICAL_FORM='LOTION' and b.PHARMACEUTICAL_FORM='GEL');
CREATE TABLE FORM_1 AS (
select case when drug_code in (select drug_code from temp1) then 'SUSPENSION'
when drug_code in (select drug_code from temp2) then 'SOLUTION'
when drug_code in (select drug_code from temp3) then 'LOTION'
when drug_code in (select drug_code from temp4) then 'SPRAY'
when drug_code in (select drug_code from temp5) then 'METERED-DOSE AEROSOL'
when drug_code in (select drug_code from temp6) then 'OINTMENT'
when drug_code in (select drug_code from temp8) then 'SUSPENSION'
when drug_code in (select drug_code from temp9) then 'ENEMA'
when drug_code in (select drug_code from temp10) then 'SOLUTION'
when drug_code in (select drug_code from temp11) then 'SOLUTION'
when drug_code in (select drug_code from temp12) then 'SUSPENSION'
when drug_code in (select drug_code from temp13) then 'METERED-DOSE AEROSOL'
when drug_code in (select drug_code from temp14) then 'SOLUTION'
when drug_code in (select drug_code from temp15) then 'SOLUTION'
when drug_code in (select drug_code from temp16) then 'SOLUTION'
when drug_code in (select drug_code from temp17) then 'SOLUTION'
when drug_code in (select drug_code from temp18) then 'POWDER'
when drug_code in (select drug_code from temp19) then 'AEROSOL'
when drug_code in (select drug_code from temp20) then 'SOLUTION'
when drug_code in (select drug_code from temp21) then 'SOLUTION'
when drug_code in (select drug_code from temp22) then 'SOLUTION'
when drug_code in (select drug_code from temp23) then 'LOTION'
when drug_code in (select drug_code from temp24) then 'SUSPENSION'
when drug_code in (select drug_code from temp25) then 'SOLUTION'
when drug_code in (select drug_code from temp26) then 'SUSPENSION'
when drug_code in (select drug_code from temp27) then 'METERED-DOSE AEROSOL'
when drug_code in (select drug_code from temp29) then 'METERED-DOSE AEROSOL'
when drug_code in (select drug_code from temp30) then 'SOLUTION'
when drug_code in (select drug_code from temp31) then 'CREAM'
when drug_code in (select drug_code from temp32) then 'CREAM'
when drug_code in (select drug_code from temp33) then 'TABLET (EXTENDED-RELEASE)'
when drug_code in (select drug_code from temp34) then 'TABLET (EXTENDED-RELEASE)'
when drug_code in (select drug_code from temp7) then 'AEROSOL'
when drug_code in (select drug_code from temp35) then 'TOPICAL SOLUTION'
when drug_code in (select drug_code from temp36) then 'SOLUTION'
when drug_code in (select drug_code from temp37) then 'GEL'
when drug_code in (select drug_code from temp38) then 'SOLUTION'
when drug_code in (select drug_code from temp41) then 'SOLUTION'
when drug_code in (select drug_code from temp40) then 'TABLET'
when drug_code in (select drug_code from temp39) then 'PATCH'
when drug_code in (select drug_code from temp42) then 'SOLUTION'
when drug_code in (select drug_code from temp43) then 'CAPSULE'
when drug_code in (select drug_code from temp44) then 'TABLET'
when drug_code in (select drug_code from temp45) then 'SUSPENSION'
when drug_code in (select drug_code from temp46) then 'TOOTHPASTE'
when drug_code in (select drug_code from temp47) then 'CREAM'
when drug_code in (select drug_code from temp48) then 'CREAM'
when drug_code in (select drug_code from temp49) then 'SHAMPOO'
when drug_code in (select drug_code from temp51) then 'GRANULES'
when drug_code in (select drug_code from temp50) then 'CREAM'
when drug_code in (select drug_code from temp52) then 'CAPSULE'
when drug_code in (select drug_code from temp53) then 'CREAM'
when drug_code in (select drug_code from temp54) then 'TABLET'
when drug_code in (select drug_code from temp55) then 'SOLUTION'
when drug_code in (select drug_code from temp56) then 'SUSPENSION'
when drug_code in (select drug_code from temp57) then 'SUSPENSION'
when drug_code in (select drug_code from temp58) then 'CREAM'
when drug_code in (select drug_code from temp59) then 'METERED-DOSE AEROSOL'
when drug_code in (select drug_code from temp60) then 'TABLET'
when drug_code in (select drug_code from temp61) then 'LOTION'
when drug_code in (select drug_code from temp62) then 'TOOTHPASTE'
when drug_code in (select drug_code from temp63) then 'SPRAY'
when drug_code in (select drug_code from temp64) then 'LIQUID SOAP'
when drug_code in (select drug_code from temp65) then 'LOTION'
when drug_code in (select drug_code from temp66) then 'SOLUTION'
when drug_code in (select drug_code from temp67) then 'SPRAY'
when drug_code in (select drug_code from temp68) then 'TEA'
when drug_code in (select drug_code from temp69) then 'GAS'
when drug_code in (select drug_code from temp70) then 'SPRAY'
when drug_code in (select drug_code from temp71) then 'SHAMPOO'
when drug_code in (select drug_code from temp72) then 'SPRAY'
when drug_code in (select drug_code from temp73) then 'SOLUTION'
when drug_code in (select drug_code from temp74) then 'SOLUTION'
when drug_code in (select drug_code from temp75) then 'SOLUTION'
when drug_code in (select drug_code from temp76) then 'GEL'
when drug_code in (select drug_code from temp77) then 'IMPLANT'
when drug_code in (select drug_code from temp78) then 'CREAM'
when drug_code in (select drug_code from temp79) then 'GEL'
when drug_code in (select drug_code from temp80) then 'SOLUTION'
when drug_code in (select drug_code from temp81) then 'SPRAY'
when drug_code in (select drug_code from temp82) then 'SOAP'
when drug_code in (select drug_code from temp83) then 'TABLET'
when drug_code in (select drug_code from temp84) then 'SOLUTION'
when drug_code in (select drug_code from temp85) then 'SHAMPOO'
when drug_code in (select drug_code from temp86) then 'LOTION'
else PHARMACEUTICAL_FORM end as PHARMACEUTICAL_FORM, drug_code
from form)
;
create table ff2 as (
select new_form, drug_code from (
select distinct listagg (concept_name, '/') WITHIN GROUP (ORDER BY concept_name) OVER (PARTITION BY drug_code ) as form_comb, drug_Code from
(select distinct r.ROUTE_OF_ADMINISTRATION||' '||a.PHARMACEUTICAL_FORM as concept_name, a.drug_Code from form_1 a
join route r on r.drug_code=a.drug_Code
where a.drug_Code in (
select r.drug_Code from route group by r.drug_Code having count(1)>1)
and a.drug_code not in (select drug_code from new_pack)
)
) f
join new_form n on n.form_Comb=f.form_Comb
)
;
update form_1 a
set PHARMACEUTICAL_FORM=(select new_form from ff2 b where b.drug_code = a.drug_code) where exists (select new_form from ff2 b where b.drug_code = a.drug_code)
;
create table form_2 as (
select case when drug_code in (select drug_code from additional_list) or drug_code in (select drug_code from ff2) then PHARMACEUTICAL_FORM else ROUTE_OF_ADMINISTRATION||' '||PHARMACEUTICAL_FORM end as PHARMACEUTICAL_FORM,
drug_code
from (
select a.DRUG_CODE, ROUTE_OF_ADMINISTRATION, PHARMACEUTICAL_FORM from form_1 a
left join route b on a.drug_code=b.drug_code
)
);
UPDATE FORM_2 SET PHARMACEUTICAL_FORM = 'SOLUTION' WHERE PHARMACEUTICAL_FORM = '0-UNASSIGNED SOLUTION';
--TABLE WITH FORMS FOR DRUG_CONCEPT_STAGE
create table forms_v2 as (
select distinct PHARMACEUTICAL_FORM as concept_name, 'Dose Form' as concept_class_id from form_2 where PHARMACEUTICAL_FORM is not null
)
;
--TABLE WITH UNITS FOR DRUG_CONCEPT_STAGE
CREATE TABLE UNIT AS (
SELECT distinct upper(strength_unit) AS concept_name, upper(strength_unit) as concept_CODE, 'Unit' as concept_class_id
FROM ACTIVE_INGREDIENTS where strength_unit is not null);
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('SQ CM','SQ CM', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('L','L', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('HOUR','HOUR', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('CC','CC', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('CM','CM', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('GM','GM', 'Unit');
insert into unit (concept_name,concept_CODE, concept_class_id)
values ('ACT','ACT', 'Unit');
--TABLE WITH BRAND NAMES FOR DRUG_CONCEPT_STAGE
create table brand_v3 as (
select distinct concept_name, concept_class_id from brand_v2
)
;
--BRANDED DRUGS
create table Branded_Drug_p1 as (select distinct
a.brand_name as concept_name, case when a.drug_code in (select drug_code from new_pack) then 'Branded Pack'
when d.dosage_value is not null then 'Quant Branded Drug' else 'Branded Drug' end as concept_class_id, a.drug_code as concept_code
from drug_product a
join active_ingredients d on d.drug_code = a.drug_Code
left join form c on a.drug_code = c.drug_code
where a.drug_code in (select drug_code from brand_v2))
;
--ADDING FORM TO BRANDED DRUG NAME TO AVOID SAME BRAND NAME - BRANDED DRUG NAME PAIRS
UPDATE BRANDED_DRUG_P1 SET CONCEPT_NAME = 'TARO-CARBAMAZEPINE SUSPENSION' WHERE CONCEPT_NAME = 'TARO-CARBAMAZEPINE' AND CONCEPT_CLASS_ID = 'Quant Branded Drug' AND CONCEPT_CODE = '2367394';
UPDATE BRANDED_DRUG_P1 SET CONCEPT_NAME = 'TARO-CARBAMAZEPINE TABLET' WHERE CONCEPT_NAME = 'TARO-CARBAMAZEPINE' AND CONCEPT_CLASS_ID = 'Branded Drug' AND CONCEPT_CODE = '2407515';
UPDATE BRANDED_DRUG_P1 SET CONCEPT_NAME = 'CYSTADANE POWDER FOR SOLUTION' WHERE CONCEPT_NAME = 'CYSTADANE' AND CONCEPT_CLASS_ID = 'Quant Branded Drug' AND CONCEPT_CODE = '2238526';
--CREATE BRANDED DRUGS THAT ARE PRESENTED IN ORIGINAL TABLES IN PACKS
create table branded_drug_p2 as
(select distinct a.concept_name, case when DENOMINATOR_VALUE is not null then 'Quant Branded Drug' else 'Branded Drug' end
as concept_class_id, concept_code from new_pack a join brand_v2 b on a.concept_code=b.drug_code )
;
--CLINICAL DRUG
create table CLINICal_Drug as (
select distinct a.brand_name||' '||c.PHARMACEUTICAL_FORM as concept_name, a.drug_code as concept_code,
case when dosage_value is not null then 'Quant Clinical Drug' else 'Clinical Drug' end as concept_class_id
from drug_product a
join active_ingredients d on d.drug_code = a.drug_Code
left join form_2 c on a.drug_code = c.drug_code
where a.drug_code not in (
select concept_Code from branded_drug_p1
union
select concept_code from branded_drug_p2)
)
;
--DRUG MANUFACTURER
drop table manufacturer;
create table manufacturer as (
select distinct COMPANY_NAME as concept_name,'Manufacturer' as concept_class_id from companies
)
;
create table DRUG_concept_STAGE (
concept_name varchar(255),
vocabulary_id varchar(20),
concept_class_id varchar(25),
standard_concept varchar(1),
concept_code varchar(50),
possible_excipient varchar(1),
pack_size varchar (25),
domain_id varchar (25),
valid_start_date date,
valid_end_date date,
invalid_reason varchar(1)
)
;
--SEQUENCE FOR OMOP-GENERATED CODES STARTING WITH THE LAST CODE USED IN PREVIOUS VOCABULARY
create sequence conc_stage_seq
MINVALUE 97124
MAXVALUE 1000000
START WITH 97124
INCREMENT BY 1
CACHE 20;
;
--TABLE WITH OMOP-GENERATED CODES
create table list_temp as (
select a.*, conc_stage_seq.NEXTVAL as concept_code from ( select * from
(select concept_name,concept_class_id from ingr_all where concept_name is not null
union
select concept_name,concept_class_id from brand_v3 where concept_name is not null
union
select concept_name,concept_class_id from forms_v2 where concept_name is not null
union
select concept_name,concept_class_id from branded_drug_p2 where concept_name is not null
union
select concept_name,concept_class_id from manufacturer where concept_name is not null)) a)
;
--CONCEPT-STAGE CREATION
insert into DRUG_concept_STAGE (CONCEPT_NAME,VOCABULARY_ID,CONCEPT_CLASS_ID,STANDARD_CONCEPT,CONCEPT_CODE,POSSIBLE_EXCIPIENT,pack_size,domain_id,VALID_START_DATE,VALID_END_DATE,INVALID_REASON)
select distinct CONCEPT_NAME, 'DPD', CONCEPT_CLASS_ID, '', CONCEPT_CODE, '', '','Drug', TO_DATE('2015/12/12', 'yyyy/mm/dd') as valid_start_date,
TO_DATE('2099/12/31', 'yyyy/mm/dd') as valid_end_date, ''
from
(
select distinct CONCEPT_NAME,CONCEPT_CLASS_ID,cast (CONCEPT_CODE as varchar(255)) as concept_code from Branded_drug_p1
union
select distinct CONCEPT_NAME,CONCEPT_CLASS_ID,cast (CONCEPT_CODE as varchar(255)) as concept_code from CLINICAL_drug
union
select distinct CONCEPT_NAME,CONCEPT_CLASS_ID,CONCEPT_CODE from unit
union
select distinct CONCEPT_NAME, CONCEPT_CLASS_ID, 'OMOP'||CONCEPT_CODE from list_temp --ADD 'OMOP' to all OMOP-generated concepts
);
--FLAG INDICATING INERT INGREDIENTS
update drug_Concept_stage
set POSSIBLE_EXCIPIENT=1 where upper(concept_name)='WATER' or upper(concept_name)='NEON';
--UPDATING VALID DATES USING INFO IN ORIGINAL TABLES
create table dates as (
select distinct d.DRUG_CODE, valid_date from drug_product d join
(
select min(HISTORY_DATE) as valid_date , drug_code from status group by drug_code
) a on a.drug_code = d.old_code
)
;
update drug_concept_stage a
set VALID_START_DATE=(select valid_date from dates b where a.concept_code = b.drug_code);
update drug_concept_stage
set VALID_START_DATE= TO_DATE('1970/01/01', 'yyyy/mm/dd') where valid_start_date is null;
update drug_concept_stage
set concept_class_id = replace (concept_class_id , 'Quant ')
WHERe CONCEPT_CODE IN (
select A.CONCEPT_CODE from drug_concept_stage a
join drug_strength_stage s on a.concept_code = s.drug_concept_code and a.concept_class_id like '%Quant%' and (s.DENOMINATOR_VALUE is null or NUMERATOR_VALUE is null)
);
delete drug_concept_stage where concept_name='NIL';
create table DTB1 as (
select distinct a.concept_code, a.concept_name from dRUG_concept_stage a
where concept_class_id='Branded Drug' or concept_class_id='Quant Branded Drug' or concept_class_id='Branded Pack');
create table DTB2 as (
select distinct a.concept_code, a.concept_name, b.drug_code from dRUG_concept_stage a
join brand_v2 b on b.concept_name = a.concept_name