-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadAccountDB.pl
More file actions
executable file
·33 lines (28 loc) · 1011 Bytes
/
loadAccountDB.pl
File metadata and controls
executable file
·33 lines (28 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
#
# loadAccountDB.pl
#
use DBI;
$dbh = DBI->connect("dbi:mysql:dbname=account_number;host=ohfdb1;port=3306","***","***",{ RaiseError => 1, AutoCommit => 0 });
while(<STDIN>) {
($acct_number,$mrn,$last_name,$first_name,$m,$d,$y,$time) = split(/,/);
$m = "0" . $m if $m < 10;
$d = "0" . $d if $d < 10;
$y = "200" . $y if (length $y == 1);
$y = "20" . $y if (length $y == 2);
chomp($time);
$time = "000" . $time if (length $time == 1);
$time = "00" . $time if (length $time == 2);
$time = "0" . $time if (length $time == 3);
$visit = $y . $m . $d . $time;
die "Invalid DATE $visit\n" unless ($visit =~/\d{12}/);
print "$acct_number,$mrn,$last_name,$first_name,$visit\n";
eval {
$dbh->do("INSERT INTO account_number_xref VALUES ($acct_number,$mrn,\"$last_name\",\"$first_name\",$visit)");
};
if ($@) {
eval { $dbh->rollback(); };
die "Couldn't roll back transaction: $acct_number,$mrn,$last_name,$first_name,$m,$d,$y\n" if $@;
}
}
$dbh->commit();