in reply to Parse an ADT file

I'm still a lowly Novice here, so be gentle oh great ones :)

While I'm not sure I can get you exactly what you're after, I can provide you some of the general logic I use to parse HL7 files. I know there's better ways to do it, but this is the project I learned Perl with, and so it's very rudimentary.

I work primarily with HL7 lab results, but the logic is pretty general for any HL7 record.

First off, I call the procedure with a file as a parameter, and assign it to the variable $b... Then call the following subroutine logic:

sub parse_lab_test { @segs = split('\r', $b); # \r is the record terminator foreach $seg (@segs) { $segtype = substr($seg, 0, 3); if ($segtype eq "MSH") { msh_fields($seg); } elsif ($segtype eq "PID") { pid_fields($seg); } elsif ($segtype eq "PV1") { pv1_fields($seg); ... etc ... } else { &segment_error; } } }
Then, for example, if you're working on the MSH segment, you'd have the following subroutine:

sub msh_fields { ($mshseg) = @_; @vals = split('\|', $mshseg); $docsource = $vals[3]; $trandate = $vals[6]; $doctype2 = $vals[7]; $rectype = $vals[8]; $unique_hl7_id = $vals[9]; if ($rectype ne 'ORU^R01'){ # Discrete Results only next MAIN; # Label that ends the script } }
Then, you just define all the HL7 segments you're interested in. In your case, you'd have $segtype = 'FT1', then call ft1_fields.

Anyways, that's how I do it... It's not the smallest or most elegant way to do it, but it's pretty easy to maintain :)

Trek