From 9833fd018ed08ee2b32bae4960c486a12ca1705e Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 11 Oct 2014 14:28:53 -0400 Subject: [PATCH 1/1] Add find_copy_details_by_item to NCIP::ILS::Evergreen. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS/Evergreen.pm | 55 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index 6a784b0..f13d75d 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -1029,7 +1029,8 @@ sub requestitem { $data->{UserOptionalFields} = $optionalfields; } $elements = $request->{$message}->{ItemElementType}; - if ($elements && $copy_details) { + if ($elements) { + $copy_details = $self->find_copy_details_by_item($item) unless ($copy_details); $elements = [$elements] unless (ref($elements) eq 'ARRAY'); my $optionalfields = $self->handle_item_elements($copy_details->{copy}, $elements); $data->{ItemOptionalFields} = $optionalfields; @@ -1860,6 +1861,58 @@ sub retrieve_copy_details_by_barcode { return $copy; } +=head2 find_copy_details_by_item + + $copy_details = $ils->find_copy_details_by_item($item); + +This routine returns a copy_details hashref (See: +retrieve_copy_details_by_barcode) for a given item. It attempts to +find the "first" copy for the given item. If item is a call number it +looks for the first, not deleted copy. If item is a bib, it looks for +the first not deleted copy on the first not deleted call number. If +item is a copy, it simply returns the details for the copy. + +=cut + +sub find_copy_details_by_item { + my $self = shift; + my $item = shift; + + my ($details); + + if (ref($item) eq 'Fieldmapper::biblio::record_entry') { + my $acns = $U->simplereq( + 'open-ils.pcrud', + 'open-ils.pcrud.search.acn.atomic', + $self->{session}->{authtoken}, + { + record => $item->id(), + deleted => 'f' + } + ); + ($item) = sort {$a->id() <=> $b->id()} @{$acns}; + } + + if (ref($item) eq 'Fieldmapper::asset::call_number') { + my $copies = $U->simplereq( + 'open-ils.pcrud', + 'open-ils.pcrud.search.acp.atomic', + $self->{session}->{authtoken}, + { + call_number => $item->id(), + deleted => 'f' + } + ); + ($item) = sort {$a->id() <=> $b->id()} @{$copies}; + } + + if (ref(item) eq 'Fieldmapper::asset::copy') { + $details = $self->retrieve_copy_details_by_barcode($item->barcode()); + } + + return $details; +} + =head2 retrieve_copy_status $status = $ils->retrieve_copy_status($id); -- 2.43.2