From bcde797909fea6c21f491a55d2c32aa523409a35 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 31 Aug 2014 10:09:36 -0400 Subject: [PATCH] Add find_item_barcode to NCIP::ILS. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS.pm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/NCIP/ILS.pm b/lib/NCIP/ILS.pm index a32442f..73f26a0 100644 --- a/lib/NCIP/ILS.pm +++ b/lib/NCIP/ILS.pm @@ -323,7 +323,6 @@ sub find_user_barcode { my $barcode; my $field; my $message = $self->parse_request_type($request); - return unless($message); # Check for UserId first because it is more common and still valid # in LookupUser. @@ -363,4 +362,45 @@ sub find_user_barcode { return (wantarray) ? ($barcode, $field) : $barcode; } +=head2 find_item_barcode + +Cfind_item_barcode($request);> + +If you have a request type that includes an item barcode identifier +value, this routine will find it. + +It will return the barcode in scalar context, or the barcode and the +tag of the field where the barcode was found in list context. + +If multiple barcode fields are provided, it returns the first one that +it finds. This is not necessarily the first one given in the request +message. Maybe we should add a plural form of this method to find all +of the item barcodes provided? + +=cut + +sub find_item_barcode { + my $self = shift; + my $request = shift; + + my $barcode; + my $field; + my $message = $self->parse_request_type($request); + + my $idinput = $request->{$message}->{ItemId}; + if ($idinput) { + $field = 'ItemIdentifierValue'; + $idinput = [$idinput] unless (ref($idinput) eq 'ARRAY'); + foreach my $input (@$idinput) { + if ($input->{ItemIdentifierType}) { + next unless ($input->{ItemIdentifierType} =~ /barcode/i); + } + $barcode = $input->{ItemIdentifierValue}; + last if ($barcode); + } + } + + return (wantarray) ? ($barcode, $field) : $barcode; +} + 1; -- 2.43.2