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 ICD9 codes into the "codes" table of
19 # ./load_icd_desc.plx < V22ICD9_FILE1.TXT
21 # To get this input file, download and extract v22_icd9.zip from
22 # http://www.cms.hhs.gov/providers/pufdownload/. After that, you might
23 # want to also load the "friendlier" descriptions from icd9_long.txt at
24 # http://www.aafp.org/.
25 #######################################################################
27 #######################################################################
28 # Parameters that you may customize #
29 #######################################################################
31 my $DBNAME = "openemr"; # database name
33 # You can hard-code the database user name and password (see below),
34 # or else put them into the environment with bash commands like these
35 # before running this script:
37 # export DBI_USER=username
38 # export DBI_PASS=password
40 my $dbh = DBI
->connect("dbi:mysql:dbname=$DBNAME") or die $DBI::errstr
;
42 # my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME", "username", "password")
43 # or die $DBI::errstr;
47 # $dbh->do("delete from codes where code_type = 2") or die "oops";
49 #######################################################################
51 #######################################################################
53 $| = 1; # Turn on autoflushing of stdout.
58 #######################################################################
60 #######################################################################
62 while (my $line = <STDIN
>) {
65 next unless ($line =~ /^([0-9A-Z]\d\d\S*)\s+(\S.*)$/);
69 $code =~ s/\.//; # remove periods from the icd9 codes
70 $desc =~ s/\s*$//g; # remove all trailing whitespace
71 $desc =~ s/'/''/g; # just in case there are any quotes
73 my $usth = $dbh->prepare("SELECT id FROM codes " .
74 "WHERE code_type = 2 AND code = '$code'")
76 $usth->execute() or die $usth->errstr;
77 my @urow = $usth->fetchrow_array();
81 $query = "INSERT INTO codes " .
82 "( code_type, code, modifier, code_text ) VALUES " .
83 "( 2, '$code', '', '$desc' )";
87 $query = "UPDATE codes SET code_text = '$desc' " .
88 "WHERE code_type = 2 AND code = '$code'";
92 # Comment this out if you do not want to update the database here.
93 # You can save stdout to a file if you want to inspect it and then
94 # run it through the mysql utility.
96 $dbh->do($query) or die $query;
101 #######################################################################
103 #######################################################################
105 print "\nInserted $countnew rows, updated $countup codes.\n";