fix: faxsms psr7 vendor fix (#7794)
[openemr.git] / contrib / util / load_doc_fees.plx
blobfb91a703d10e3f412bfe6f4795bf8901071ebd38
1 #!/usr/bin/perl
2 use strict;
4 use DBI;
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.
19 # Run it like this:
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 #######################################################################
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 my $codes_id;
87 if (! @urow) {
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'};
93 print $query . "\n";
94 ++$countnew;
96 else {
97 $codes_id = $urow[0];
98 $query = "DELETE FROM prices WHERE pr_id = $codes_id AND pr_selector = ''";
99 $dbh->do($query) or die $query;
100 print $query . "\n";
101 ++$countup;
104 $query = "INSERT INTO prices ( pr_id, pr_level, pr_price ) " .
105 "VALUES ( $codes_id, 'standard', $fee )";
106 $dbh->do($query) or die $query;
107 print $query . "\n";
110 #######################################################################
111 # Shutdown #
112 #######################################################################
114 print "\nInserted $countnew rows, updated $countup rows.\n";
116 $dbh->disconnect;