From b3f486ca21974e16c8601a7581a0ec142c33fe5d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 3 Oct 2012 09:32:34 -0400 Subject: [PATCH] Collect full list if LI identifiers Also use regex match instead of search/replace, as it's not necessary (and probably slower). Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Utils/EDIReader.pm | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm index c8b58b0727..bd3c8e1ffe 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/EDIReader.pm @@ -3,35 +3,38 @@ use strict; use warnings; my $NEW_MSG_RE = '^UNH'; my $NEW_LIN_RE = '^LIN'; -my $MISC_CHARGE_TYPE_RE = '^ALC\+C\++([^\+]+).*'; +my $MISC_CHARGE_TYPE_RE = '^ALC\+C\++([^\+]+)'; my $MISC_CHARGE_AMT_RE = '^MOA\+(8|131):(\d+)'; my %edi_fields = ( - message_type => '^UNH\+\d+\+(\S{6}):.*', - buyer_san => '^NAD\+BY\+([^:]+).*', - vendor_san => '^NAD\+SU\+([^:]+).*', + message_type => '^UNH\+\d+\+(\S{6})', + buyer_san => '^NAD\+BY\+([^:]+)', + vendor_san => '^NAD\+SU\+([^:]+)', purchase_order => '^RFF\+ON:(\S+)', - invoiceident2 => '^BGM\+380\+(.*)\+.*', + invoice_ident => '^BGM\+380\+([^\+]+)', total_billed => '^MOA\+86:(\d+)' ); my %edi_li_fields = ( id => '^RFF\+LI:\S+\/(\S+)', - index => '^LIN\+([^\+]+).*', - ident => '^LIN\+\S+\++([^:]+).*', - ident2 => '^PIA\+0*5\+([^:]+).*', + index => '^LIN\+([^\+]+)', amount_billed => '^MOA\+203:(\d+)', - unit_price => '^PRI\+AAB:(\d+).*', - expected_date => '^DTM\+44:([^:]+).*' + unit_price => '^PRI\+AAB:(\d+)', + expected_date => '^DTM\+44:([^:]+)' +); + +my %edi_li_ident_fields = ( + ident => '^LIN\+\S+\++([^:]+):?(\S+)?', + ident2 => '^PIA\+0*5\+([^:]+):?(\S+)?', ); my %edi_li_quant_fields = ( - quantity => '^QTY\+\d+:(\d+).*', - code => '^QTY\+(\d+):.*', + quantity => '^QTY\+\d+:(\d+)', + code => '^QTY\+(\d+):', ); my %edi_charge_fields = ( - charge_type => '^ALC\+C\++([^\+]+).*', + charge_type => '^ALC\+C\++([^\+]+)', charge_amount => '^MOA\+(8|131):(\d+)' ); @@ -74,7 +77,7 @@ sub read { next unless $msg; for my $field (keys %edi_fields) { - ($msg->{$field} = $_) =~ s/$edi_fields{$field}/$1/g + ($msg->{$field}) = $_ =~ /$edi_fields{$field}/ if /$edi_fields{$field}/; } @@ -90,19 +93,21 @@ sub read { if (my $li = $msg->{_current_li}) { for my $field (keys %edi_li_fields) { - ($li->{$field} = $_) =~ s/$edi_li_fields{$field}/$1/g + ($li->{$field}) = $_ =~ /$edi_li_fields{$field}/g if /$edi_li_fields{$field}/; } - - # if no ident value is present, promote ident2 - $li->{ident} = delete $li->{ident2} - if $li->{ident2} and not $li->{ident}; + for my $field (keys %edi_li_ident_fields) { + if (/$edi_li_ident_fields{$field}/) { + my ($ident, $type) = $_ =~ /$edi_li_ident_fields{$field}/; + push(@{$li->{identifiers}}, {code => $type, value => $ident}); + } + } if (/$edi_li_quant_fields{quantity}/) { my $quant = {}; - ($quant->{quantity} = $_) =~ s/$edi_li_quant_fields{quantity}/$1/g; - ($quant->{code} = $_) =~ s/$edi_li_quant_fields{code}/$1/g; + ($quant->{quantity}) = $_ =~ /$edi_li_quant_fields{quantity}/; + ($quant->{code}) = $_ =~ /$edi_li_quant_fields{code}/; push(@{$li->{quantities}}, $quant); } @@ -119,7 +124,7 @@ sub read { if (my $charge = $msg->{_current_charge}) { for my $field (keys %edi_charge_fields) { - ($charge->{$field} = $_) =~ s/$edi_charge_fields{$field}/$1/g + ($charge->{$field}) = $_ =~ /$edi_charge_fields{$field}/ if /$edi_charge_fields{$field}/; } } -- 2.11.0