Here is my code in it's entirety.
#!/usr/bin/perl -w
BEGIN{
$ENV{SYBASE} = "/opt/sybase";
}
BEGIN{
$ENV{LD_LIBRARY_PATH} = "/usr/local/samba/lib";
print "env is $ENV{LD_LIBRARY_PATH}\n" if $DEBUG;
}
BEGIN{
$ENV{LIBPATH} = "/usr/local/samba/lib";
print "env is $ENV{LIBPATH}\n" if $DEBUG;
}
#Modules
use IO::Socket::INET;
use Sybase::CTlib;
use Date::Calc ":all";
use Carp;
use Crypt::CBC;
#Declare Variables
my $DEBUG=0; #Set to one for comments
my $OrderId;
my $HashOrderId;
my $msg;
my $key = "integration";
my $iv = pack("H16", "0123456789ABCDEF");
my $web_address = "http://webpinspdfdev/powerchartaccess/ViewPDF?o=";
+#Will need to be changed for production
my $ciphertext;
my $cipher;
my $DIR;
my $idxcount = 0;
my $out_file = "/opt/impact55/Hash_PDF/out_file_$idxcount.dat";
#Source Code
$BASEPATH = "/opt/impact55/Hash_PDF";
$APP = $ARGV[0];
problem ("You must supply one APP as an argument!")
unless ($#ARGV == 0);
if($APP eq "PFT"){$DIR = "PFT"} #Set file directory
my @transactions = glob("$BASEPATH/$DIR/PDF_${APP}_*.tmp"); #put all f
+iles in array
print "transactions: @transactions\n" if $DEBUG;
if($APP eq "PFT"){
#for each file in array
foreach my $in_file (@transactions){
print "in_file: $in_file\n" if $DEBUG;
open(FH,$in_file);
@lines = <FH>;
close(FH);
$idxcount++;
#set encryption
$cipher = Crypt::CBC->new( -key => $key,
-cipher => 'Crypt::Blowfish',
-header => 'none',
-iv => $iv);
#Cycle through transaction
foreach my $line (@lines) {
#Pull individual segments
my($MSH,$PID,$ORC,$OBR,$OrderId) =
$line =~ m{(MSH\|.*)\r #MSH segment
(PID\|.*)\r #PID Segment
(ORC\|.*)\r #ORC Segment
(OBR\|.*)\r #OBR Segment
OrderId\:(\w+\_\d+)\r}smx; #Order Id to
+ be hashed
$OrderId = $OrderId;
print "MSH: $MSH\n" if $DEBUG;
print "PID: $PID\n" if $DEBUG;
print "ORC: $ORC\n" if $DEBUG;
print "OBR: $OBR\n" if $DEBUG;
#Encypt Order Id
$ciphertext = $cipher->encrypt_hex($OrderId);
print "Crypted Order Id: $ciphertext\n" if $DEBUG;
#Build OBX segment
my $OBX = "OBX|1|RP|100.214||";
$OBX .= $web_address;
$OBX .= $ciphertext;
$OBX .= "||||||||||";
print "OBX: $OBX\n" if $DEBUG;
#Build Message
$msg = sprintf "\013";
$msg .= sprintf "$MSH\015";
$msg .= sprintf "$PID\r";
$msg .= sprintf "$ORC\015";
$msg .= sprintf "$OBR\015";
$msg .= sprintf "$OBX\034\015";
print "MSG: $msg\n" if $DEBUG;
#Output
if($DEBUG){
open(my $FHOUT,">$out_file");
print $FHOUT $msg;
close($FHOUT);
}
else{
#Create the connection
my $socket = IO::Socket::INET->new(
Proto => 'tcp',
PeerHost => 'axtcnr:6540',
) or die("Can't connect to axtcnr:6540
+: $!\n");
#Send transaction
if($msg =~ m{(\013.*\034\015)}smx){
print $socket $1;
}
#Shutdown sending only receive
$socket->shutdown(1);
#Read response
$socket->recv($rv,1024);
print "Received from Server : $rv\n";
}
}
}
}
|