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 HCPCS codes into the "codes" table of
15 # OpenEMR. Both the long and short descriptions are loaded from the
18 # For 2005, run it like this:
20 # ./load_hcpcs_desc.plx < 05anweb.txt
22 # To get this input file, download and extract anhcpc05.zip from
23 # http://www.cms.hhs.gov/providers/pufdownload/.
24 #######################################################################
26 #######################################################################
27 # Parameters that you may customize #
28 #######################################################################
30 my $DBNAME = "openemr"; # database name
32 # To load the short descriptions (SHORTU.txt, not currently used by
33 # OpenEMR but probably should), change this to "code_text_short":
35 my $TEXT_COL = "code_text";
37 # You can hard-code the database user name and password (see below),
38 # or else put them into the environment with bash commands like these
39 # before running this script:
41 # export DBI_USER=username
42 # export DBI_PASS=password
44 my $dbh = DBI
->connect("dbi:mysql:dbname=$DBNAME") or die $DBI::errstr
;
46 # my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME", "username", "password")
47 # or die $DBI::errstr;
49 #######################################################################
51 #######################################################################
59 $| = 1; # Turn on autoflushing of stdout.
61 #######################################################################
63 #######################################################################
66 return unless $currcode;
69 $currlong =~ s/'/''/g;
70 $currshort =~ s/'/''/g;
72 my $usth = $dbh->prepare("SELECT id FROM codes " .
73 "WHERE code_type = 3 AND code = '$currcode'")
75 $usth->execute() or die $usth->errstr;
76 my @urow = $usth->fetchrow_array();
80 $query = "INSERT INTO codes " .
81 "( code_type, code, modifier, code_text_short, code_text ) VALUES " .
82 "( 3, '$currcode', '', '$currshort', '$currshort' )";
86 $query = "UPDATE codes SET code_text_short = '$currshort', code_text = '$currshort' " .
87 "WHERE code_type = 3 AND code = '$currcode'";
91 # Comment this out if you do not want to update the database here.
92 # You can save stdout to a file if you want to inspect it and then
93 # run it through the mysql utility.
95 $dbh->do($query) or die $query;
100 #######################################################################
102 #######################################################################
104 while (my $line = <STDIN
>) {
105 my $rectype = substr($line, 10, 1);
106 next unless ($rectype eq '3' or $rectype eq '4');
108 if ($rectype eq '3') {
110 $currcode = substr($line, 0, 5);
112 $currshort = substr($line, 91, 28);
113 $currshort =~ s/\s*$//g; # remove all trailing whitespace
116 $currlong .= substr($line, 11, 80);
117 $currlong =~ s/\s*$//g;
122 #######################################################################
124 #######################################################################
126 print "\nInserted $countnew rows, updated $countup codes.\n";