Dear Monks,
I have written this script to parse a flat HL7 file. It seems like it works but I have noticed that it doesn't separate all the accounts. Since the segments are in HL7 format with tags like MSH, PID, PV1, FT1. The script is suppose to go to tag "FT1" , then go to six position and check to see if the account matches and if it doesn't. It is suppose to move the line to another file. The script below only searches for the accounts below but not the tag as of yet. I'm not familiar with using a temporary buffer or store values in memory yet. Does someone knows how to parse an HL7 file base on the tags? I was thinking in modifying the script by searching the "FT1" tag then compare it with existing accounts. if it matches leave the line and if it doesn't move the line to another file until the end of file. Do you have any ideas on how to get it done. Thanks.
#!/usr/bin/perl -w
use strict;
my $infile = 'c:\\hl7file2.txt';
my ( $yr, $mo, $dy ) = (localtime)[5,4,3];
my $outfile = sprintf( "%04d%02d%02d.txt",$yr+1900,$mo+1,$dy );
my $counter;
open IN, "<$infile" or die "Couldn't open $infile, $!";
open OUT,">$outfile" or die "Couldn't open $outfile, $!";
# $counter++;
# print $counter;
my @finds = qw( 00000 00001 00002 00003 00004 76370 76375 76950 77403
+77404 77406
77407 77408 77409 77411 77412 77413 77414 77416 77418
+ 77370 77336
77417 );
# my $finds_re = join '|', map { quotemeta }@finds;
my $finds_re = '\b' . join( '|', map { quotemeta } @finds ) . '\b';
$finds_re = qr/$finds_re/;
# print $finds_re;
while(<IN>) {
next if m/$finds_re/;
print OUT;
}
close IN;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.