From ec07fad3df5c3297c87a34b7bbfcd5657481d963 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 22 Sep 2014 14:32:34 -0400 Subject: [PATCH] Add $code option to NCIP::ILS->find_bibliographic_id. I wonder now, if I should not have overriden the method in the Evergreen driver, but I thought this would be generically useful. We will probably want a method that can return all of the IDs at some point, but for now, any subclasses that need that, can implement it, themselves. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/NCIP/ILS.pm b/lib/NCIP/ILS.pm index bbc88a6..4f040d3 100644 --- a/lib/NCIP/ILS.pm +++ b/lib/NCIP/ILS.pm @@ -396,17 +396,22 @@ sub find_item_barcode { =head2 find_bibliographic_id $biblio_id = $ils->find_bibliographic_id($request); + $biblio_id = $ild->find_bibliographic_id($request, $code); Finds a BibliograpicId in the request message and returns either NCIP::Item::BibliographicItemId or NCIP::Item::BibliographicRecordId depending upon which is found in the request. If no BibliographicId is found, then it returns undef. +If the optional $code argument is supplied, then it will look for an +entry having that value in the identifier's code field. + =cut sub find_bibliographic_id { my $self = shift; my $request = shift; + my $idcode = shift; # Our return variable, so set this if we find an id. my $id; @@ -425,7 +430,23 @@ sub find_bibliographic_id { if ($idxml) { # BibliographicId is repeatable in some messages, but we only # use the first one. - $idxml = $idxml->[0] if (ref($idxml) eq 'ARRAY'); + if (ref($idxml) eq 'ARRAY') { + if ($idcode) { + foreach my $entry (@$idxml) { + if ($entry->{BibliographicRecordId}->{BibliographicRecordIdentifierCode} + && $entry->{BibliographicRecordId}->{BibliographicRecordIdentifierCode} eq $idcode) { + $idxml = $entry; + last; + } elsif ($entry->{BibliographicItemId}->{BibliographicItemIdentifierCode} + && $entry->{BibliographicItemId}->{BibliographicItemIdentifierCode} eq $idcode) { + $idxml = $enty; + last; + } + } + } else { + $idxml = $idxml->[0]; + } + } if ($idxml->{BibliographicRecordId}) { my ($identifier, $agencyid, $code); $identifier = $idxml->{BibliographicRecordId}->{BibliographicRecordIdentifier}; -- 2.43.2