internationalization
[openemr.git] / contrib / util / load_doc_fees.plx
blob104cf794025d75cf2b4b11f47a69af5833a3290f
1 #!/usr/bin/perl
2 use strict;
4 use DBI;
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 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.
19 # Run it like this:
21 # ./load_doc_fees.plx < PFALL05A.TXT
23 # Fee schedules are at http://www.cms.hhs.gov/providers/pufdownload/.
24 # Medicare also produces periodic updates which are in the same format
25 # and can also be processed by this program.
26 #######################################################################
28 #######################################################################
29 # Parameters that you should customize #
30 #######################################################################
32 my $DBNAME = "openemr"; # database name
33 my $CARRIER = "05440"; # Tennessee
34 my $FEE_MULTIPLIER = 1.5; # fee multiplier
36 # You can hard-code the database user name and password (see below),
37 # or else put them into the environment with bash commands like these
38 # before running this script:
40 # export DBI_USER=username
41 # export DBI_PASS=password
43 my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME") or die $DBI::errstr;
45 # my $dbh = DBI->connect("dbi:mysql:dbname=$DBNAME", "username", "password")
46 # or die $DBI::errstr;
48 #######################################################################
49 # Startup #
50 #######################################################################
52 $| = 1; # Turn on autoflushing of stdout.
54 my $countnew = 0;
55 my $countup = 0;
57 #######################################################################
58 # Main Loop #
59 #######################################################################
61 while (my $line = <STDIN>) {
62 next unless ($line =~ /^"20/);
64 my @cols = split /,/, $line;
66 my $carrier = substr($cols[1], 1, -1);
67 my $code = substr($cols[3], 1, -1);
68 my $modifier = substr($cols[4], 1, -1);
69 my $fee = substr($cols[5], 1, -1);
71 next unless ($carrier eq $CARRIER);
72 next unless ($code =~ /^\d/); # CPT codes only
74 $modifier =~ s/ //g;
75 $fee *= $FEE_MULTIPLIER;
77 my $usth = $dbh->prepare("SELECT id FROM codes " .
78 "WHERE code_type = 1 AND code = '$code' AND modifier = '$modifier'")
79 or die $dbh->errstr;
80 $usth->execute() or die $usth->errstr;
81 my @urow = $usth->fetchrow_array();
83 my $query;
84 if (! @urow) {
85 $query = "INSERT INTO codes " .
86 "( code_text, code, code_type, modifier, fee ) VALUES " .
87 "( '', '$code', 1, '$modifier', $fee )";
88 ++$countnew;
90 else {
91 $query = "UPDATE codes SET fee = $fee " .
92 "WHERE code_type = 1 AND code = '$code' AND modifier = '$modifier'";
93 ++$countup;
96 $dbh->do($query) or die $query;
98 print $query . "\n";
101 #######################################################################
102 # Shutdown #
103 #######################################################################
105 print "\nInserted $countnew rows, updated $countup rows.\n";
107 $dbh->disconnect;