initial support for multiple browser windows
[openemr.git] / contrib / util / load_doc_fees.plx
blobaeb11934acfa2935d6b73178338156a561ce054b
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 < PFALL06A.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 #######################################################################
50 # Startup #
51 #######################################################################
53 $| = 1; # Turn on autoflushing of stdout.
55 my $countnew = 0;
56 my $countup = 0;
58 #######################################################################
59 # Main Loop #
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
75 $modifier =~ s/ //g;
76 $fee *= $FEE_MULTIPLIER;
78 my $usth = $dbh->prepare("SELECT id FROM codes " .
79 "WHERE code_type = 1 AND code = '$code' AND modifier = '$modifier'")
80 or die $dbh->errstr;
81 $usth->execute() or die $usth->errstr;
82 my @urow = $usth->fetchrow_array();
84 my $query;
85 if (! @urow) {
86 $query = "INSERT INTO codes " .
87 "( code_text, code, code_type, modifier, fee ) VALUES " .
88 "( '', '$code', 1, '$modifier', $fee )";
89 ++$countnew;
91 else {
92 $query = "UPDATE codes SET fee = $fee " .
93 "WHERE code_type = 1 AND code = '$code' AND modifier = '$modifier'";
94 ++$countup;
97 $dbh->do($query) or die $query;
99 print $query . "\n";
102 #######################################################################
103 # Shutdown #
104 #######################################################################
106 print "\nInserted $countnew rows, updated $countup rows.\n";
108 $dbh->disconnect;