I can't find the issue
Thanks in advance Steve
#!/usr/bin/perl use 5.010; use strict; use autodie; use warnings; require Text::CSV; # Filenames #Uncomment for production #my $currentlist_file = '/apg/pdsdata/1700/dwprod1700/data/export/g +eneral/pre_lacecurrent2.csv'; # file1 #my $pre_historical_file = '/apg/pdsdata/1700/dwprod1700/data/export/g +eneral/pre_lace_historical.csv'; # file2 #Use datafile exported from EPIC daily. Data file includes active enco +unter's comorbidity & A_point #3/10/2015 - Version 3 - Add functionality to include comorbidity from + Current Encounter #my $epiccurrent_file = '/apg/pdsdata/1700/dwprod1700/data/export/gene +ral/pre_lace_epiccurrent.csv'; # file3 #my $lscore_file = '/apg/LACE/LaceScore.csv'; # out +put file #Comment out when moving to production # Filenames #Uncomment for production my $currentlist_file = 'pre_lacecurrent2.csv'; # file1 my $pre_historical_file = 'pre_lace_historical.csv'; # file2 my $epiccurrent_file = 'pre_lace_epiccurrent.csv'; # file3 my $lscore_file = 'LaceScore.csv'; # output file my $lacetoEpic = 'LacetoEpic.txt'; # 2nd output fil +e # Open files open my $currentlist_fh, '<:utf8', $currentlist_file; open my $pre_historical_fh, '<:utf8', $pre_historical_file; #Version 3 change open my $epiccurrent_fh, '<:utf8', $epiccurrent_file; open my $lacetoEpic_fh, '>:utf8', $lacetoEpic; # If lacecurrent is not equal to today then do not run #die if ( -M $currentlist_file > 1); #die if ( -M $epiccurrent_file > 1); #die if ( -M $pre_historical_file > 2); my %fh; my %lscore = ( #Production # "J" => "/apg/LACE/LACE_SOUTH.txt", # "L" => "/apg/LACE/LACE_PLAZA.txt", # "B" => "/apg/LACE/LACE_NORTH.txt", # "S" => "/apg/LACE/LACE_EAST.txt", # "C" => "/apg/LACE/LACE_CUSHING.txt", #Test "J" => "LACE_SOUTH.txt", "L" => "LACE_PLAZA.txt", "B" => "LACE_NORTH.txt", "S" => "LACE_EAST.txt", "C" => "LACE_CUSHING.txt", ); #Production #my $lscore_fallback_file = '/apg/LACE/LACE_OTHER.txt'; #my $lacetoEpic = '/apg/LACE/lacescore.txt'; # 2nd output file #my $lacetoEpic = 'lacescore.txt'; # 2nd output file #Test my $lscore_fallback_file = 'LACE_OTHER.txt'; my @currentlist_columns = qw( FacID PatID MasterID PatLName PatFName Type CPIID Bdate LPoint APoint ); #Version 3 change my @epiccurrent_columns = qw( PatID PatLName PatFName eAPoint eCPoint ); my @pre_historical_columns = qw( MasterID CPoint EPoint ); my $currentlist_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); # Version 3 Change my $epiccurrent_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); my $pre_historical_csv = Text::CSV->new( { binary => 1, # binary mode allow_whitespace => 0, # don't allow whitespace sep_char => ',', # separation character } ); my $lscore_csv = Text::CSV->new( { binary => 1, # binary mode sep_char => "\t", # separation character eol => "\n", # end of line quote_space => 0, # quote space sparated words } ); # Set column names $currentlist_csv->column_names(\@currentlist_columns); $pre_historical_csv->column_names(\@pre_historical_columns); # Version 3 Change $epiccurrent_csv->column_names(\@epiccurrent_columns); # Skip the first lines from the CSV files $currentlist_csv->getline($currentlist_fh); $pre_historical_csv->getline($pre_historical_fh); # Version 3 Change $epiccurrent_csv->getline($epiccurrent_fh); # Version 3 Change # Slurp the entire pre_lace_epiccurrent.csv file into an array my $epiccurrent_array = $epiccurrent_csv->getline_hr_all($epiccurrent_ +fh); # Slurp the entire pre_historical.csv file into an array my $pre_historical_array = $pre_historical_csv->getline_hr_all($pre_hi +storical_fh); # For each row in currentlist.csv while (my $currentlist_row = $currentlist_csv->getline_hr($currentlist +_fh)) { my $lscore_fh; if (exists($lscore{$currentlist_row->{FacID}})) { $lscore_fh = $fh{$currentlist_row->{FacID}} //= do { open my $f, '>:utf8', $lscore{$currentlist_row->{FacID}}; $f; }; } else { $lscore_fh = $fh{__LSCORE__} //= do { open my $f, '>:utf8', $lscore_fallback_file; $f; }; } ################# # Boolean value for testing whether PATID.currentlist exists in EpicC +urrent my $found = 0; # Find the first row in pre_historical.csv where PATID.currentlist + == PATID.epiccurrent foreach my $epiccurrent_row (@{$epiccurrent_array}) { if ($currentlist_row->{PatID} eq $epiccurrent_row->{PatID}) { #my $apoint = $epiccurrent_row->{eAPoint}; my $cpoint = $epiccurrent_row->{eCPoint}; # Check CPoint if (defined($cpoint) and $cpoint =~ /^\h*[0-9]+\h* +\z/) { $cpoint = $cpoint > 6 ? 6 : $cpoint + 0; } else { $cpoint = 0; } ################# # Boolean value for testing whether MasterID.currentlist exists in + pre_historical my $found = 0; # Find the first row in pre_historical.csv where MasterID.currentl +ist == MasterID.pre_historical foreach my $pre_historical_row (@{$pre_historical_array}) { if ($currentlist_row->{MasterID} eq $pre_historical_row->{Mast +erID}) { my $cpoint = $cpoint + $pre_historical_row->{CPoint}; my $epoint = $pre_historical_row->{EPoint}; # Check CPoint if (defined($cpoint) and $cpoint =~ /^\h*[0-9]+\h*\z/) { $cpoint = $cpoint > 6 ? 6 : $cpoint + 0; } else { $cpoint = 0; } # Check EPoint if (defined($epoint) and $epoint =~ /^\h*[0-9]+\h*\z/) { $epoint = $epoint > 4 ? 4 : $epoint + 0; } else { $epoint = 0; } my $tscore = $currentlist_row->{LPoint} + $epiccurrent_row +->{eAPoint} + $cpoint + $epoint; $lscore_csv->print( $lscore_fh, [$currentlist_row->{FacID}, $currentl +ist_row->{PatID}, $currentlist_row->{MasterID}, $currentlist_row->{PatLName}, $current +list_row->{Type}, $currentlist_row->{LPoint}, $epiccurrent_row->{eAPoint}, $cpoint, + $epoint, $tscore, ] ); $lscore_csv->print( $lacetoEpic_fh, [$currentlist_row->{CPIID}, $currentlis +t_row->{PatID}, $currentlist_row->{FacID}, $currentlist_row->{PatFName},$currentli +st_row->{PatLName}, $currentlist_row->{Type},$currentlist_r +ow->{Bdate}, $currentlist_row->{LPoint}, $epiccurren +t_row->{eAPoint}, $cpoint,$epoint, $tscore, ] ); $found = 1; last; # stop when MasterID.currentlist.csv == MasterID. +pre_historical.csv # and go to the next row of currentlist.csv } } } # MasterID.currentlist has not been found in pre_historical if (not $found) { my $tscore = $currentlist_row->{LPoint} + $epiccurrent_row->{e +APoint}; $lscore_csv->print( $lscore_fh, [$currentlist_row->{FacID}, $currentlist +_row->{PatID}, $currentlist_row->{MasterID}, $currentlist +_row->{PatLName}, $currentlist_row->{Type}, $currentlist +_row->{LPoint}, $epiccurrent_row->{eAPoint}, 0, 0, $tscore, ] ); $lscore_csv->print( $lacetoEpic_fh, [$currentlist_row->{CPIID}, $currentlis +t_row->{PatID}, $currentlist_row->{FacID}, $currentlist_row->{PatFName},$currentli +st_row->{PatLName}, $currentlist_row->{Type},$currentlist_r +ow->{Bdate}, $currentlist_row->{LPoint}, $epiccurren +t_row->{eAPoint}, 0,0,$tscore ] ); } }
In reply to Missing right curly or square bracket by steve1040
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |