6 #######################################################################
7 # Copyright (C) 2005 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 descriptions of CPT codes into the "codes" table of
15 # OpenEMR. The codes must already be in the table
16 # (see load_doc_fees.plx).
20 # ./load_cpt_desc.plx < MEDU.txt
22 # See https://catalog.ama-assn.org/Catalog/ for purchasing and
23 # downloading CPT codes and descriptions. What you want is the
24 # "CPT ASCII Data Files Complete Set".
25 #######################################################################
27 #######################################################################
28 # Parameters that you may customize #
29 #######################################################################
31 my $DBNAME = "openemr"; # database name
33 # To load the short descriptions (SHORTU.txt, not currently used by
34 # OpenEMR but probably should), change this to "code_text_short":
36 my $TEXT_COL = "code_text";
38 # You can hard-code the database user name and password (see below),
39 # or else put them into the environment with bash commands like these
40 # before running this script:
42 # export DBI_USER=username
43 # export DBI_PASS=password
45 my $dbh = DBI
->connect("dbi:mysql:dbname=$DBNAME") or die $DBI::errstr
;
47 # my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME", "username", "password")
48 # or die $DBI::errstr;
50 #######################################################################
52 #######################################################################
54 $| = 1; # Turn on autoflushing of stdout.
59 #######################################################################
61 #######################################################################
63 while (my $line = <STDIN
>) {
64 next unless ($line =~ /^\d/);
66 my $code = substr($line, 0, 5);
67 my $desc = substr($line, 6);
68 $desc =~ s/\s*$//g; # remove all trailing whitespace
69 $desc =~ s/'/''/g; # just in case there are any quotes
71 my $usth = $dbh->prepare("SELECT id FROM codes " .
72 "WHERE code_type = 1 AND code = '$code'")
74 $usth->execute() or die $usth->errstr;
75 my @urow = $usth->fetchrow_array();
79 $query = "INSERT INTO codes " .
80 "( $TEXT_COL, code, code_type, modifier ) VALUES " .
81 "( '$desc', '$code', 1, '' )";
85 $query = "UPDATE codes SET $TEXT_COL = '$desc' " .
86 "WHERE code_type = 1 AND code = '$code'";
90 # Comment this out if you do not want to update the database here.
91 # You can save stdout to a file if you want to inspect it and then
92 # run it through the mysql utility.
94 $dbh->do($query) or die $query;
99 #######################################################################
101 #######################################################################
103 print "\nInserted $countnew rows, updated $countup codes.\n";