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 CPT codes and their modifiers and fees into the "codes"
15 # table of OpenEMR. If the row already exists then only the fee is
16 # modified, otherwise a new row is created with no description.
17 # See also load_cpt_desc.plx which loads the descriptions.
21 # ./load_doc_fees.plx < PFALL08A.TXT
23 # Fee schedules as of this writing are at:
24 # http://www.cms.hhs.gov/PhysicianFeeSched/PFSNPAF/list.asp
25 # Medicare also produces periodic updates which are in the same format
26 # and can also be processed by this program.
27 #######################################################################
29 #######################################################################
30 # Parameters that you should customize #
31 #######################################################################
33 my $DBNAME = "openemr"; # database name
34 my $CARRIER = "05440"; # Tennessee
35 my $FEE_MULTIPLIER = 1.5; # fee multiplier
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 #######################################################################
53 $| = 1; # Turn on autoflushing of stdout.
58 #######################################################################
60 #######################################################################
62 while (my $line = <STDIN
>) {
63 next unless ($line =~ /^"20/);
65 my @cols = split /,/, $line;
67 my $carrier = substr($cols[1], 1, -1);
68 my $code = substr($cols[3], 1, -1);
69 my $modifier = substr($cols[4], 1, -1);
70 my $fee = substr($cols[5], 1, -1);
72 next unless ($carrier eq $CARRIER);
73 next unless ($code =~ /^\d/); # CPT codes only
76 $fee *= $FEE_MULTIPLIER;
78 my $usth = $dbh->prepare("SELECT id FROM codes " .
79 "WHERE code_type = 1 AND code = '$code' AND modifier = '$modifier'")
81 $usth->execute() or die $usth->errstr;
82 my @urow = $usth->fetchrow_array();
88 $query = "INSERT INTO codes " .
89 "( code_text, code, code_type, modifier, fee ) VALUES " .
90 "( '', '$code', 1, '$modifier', 0 )";
91 $dbh->do($query) or die $query;
92 $codes_id = $dbh->{'mysql_insertid'};
98 $query = "DELETE FROM prices WHERE pr_id = $codes_id AND pr_selector = ''";
99 $dbh->do($query) or die $query;
104 $query = "INSERT INTO prices ( pr_id, pr_level, pr_price ) " .
105 "VALUES ( $codes_id, 'standard', $fee )";
106 $dbh->do($query) or die $query;
110 #######################################################################
112 #######################################################################
114 print "\nInserted $countnew rows, updated $countup rows.\n";