Missing $_REQUEST variable in messages check
[openemr.git] / contrib / util / load_fda_drugs.plx
blob7fa5fdd6dec2a126855d33d432b226e75eaf912b
1 #!/usr/bin/perl
2 use strict;
4 use DBI;
6 #######################################################################
7 # Copyright (C) 2005, 2008 Rod Roark <rod@sunsetsystems.com>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This loads the FDA Orange Book data for drugs into the "drugs"
15 # table of OpenEMR. If a row already exists with the same drug name
16 # it is ignored, otherwise a new row is created with the drug
17 # trade name provided from the Orange Book data.
19 # Run it like this:
21 # ./load_fda_drugs.plx < Products.txt
23 # The Orange Book Data files as of this writing are at:
24 # http://www.fda.gov/cder/orange/obreadme.htm
25 # Get the EOBZIP.ZIP file and extract the Products.txt file from there
26 #######################################################################
28 #######################################################################
29 # Parameters that you should customize #
30 #######################################################################
32 my $DBNAME = "openemr"; # database name
34 # You can hard-code the database user name and password (see below),
35 # or else put them into the environment with bash commands like these
36 # before running this script:
38 # export DBI_USER=username
39 # export DBI_PASS=password
41 my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME") or die $DBI::errstr;
43 # my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME", "username", "password")
44 # or die $DBI::errstr;
46 #######################################################################
47 # Startup #
48 #######################################################################
50 $| = 1; # Turn on autoflushing of stdout.
52 my $countnew = 0;
53 my $countup = 0;
55 #######################################################################
56 # Main Loop #
57 #######################################################################
59 while (my $line = <STDIN>) {
61 my ($ingredients, $dosage_route, $tradename, $applicant,
62 $strength, $ndaNum, $prodNum, $teCode, $approvalDate,
63 $refDrug, $type, $fullName) = split /~/, $line;
65 # check for existing record
66 my $usth = $dbh->prepare("SELECT drug_id FROM drugs " .
67 "WHERE name=".$dbh->quote($tradename) )
68 or die $dbh->errstr;
69 $usth->execute() or die $usth->errstr;
70 my @urow = $usth->fetchrow_array();
72 my $query;
73 my $drug_id;
75 if (! @urow) {
76 # add a new drug
77 $query = "INSERT INTO drugs" .
78 "( name ) VALUES " .
79 "( ".$dbh->quote($tradename)." )";
80 $dbh->do($query) or die $query;
81 $drug_id = $dbh->{'mysql_insertid'};
82 print $query . "\n";
83 ++$countnew;
85 else {
86 $drug_id = $urow[0];
87 print "Skipped $tradename, already exists\n";
88 ++$countup;
92 #######################################################################
93 # Shutdown #
94 #######################################################################
96 print "\nInserted $countnew rows, skipped $countup rows.\n";
98 $dbh->disconnect;