From 3602ecf56e6f3ba7b12bb15a4b47f9e82276523f Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Wed, 2 Oct 2013 16:11:57 -0400 Subject: [PATCH] Update pickup lib at ItemShipped time The ItemRequested NCIP message does not include information on where the user wishes to pick up their hold. Because of this, all holds are created with an initial hold pickup location from the ini file. Pickup library information is included in the ItemShipped message. When we receive the ItemShipped message, we retrieve the hold and update its pickup library based on a mapping file which maps the address data in the NCIP message to a local org unit id. Signed-off-by: Jeff Godin --- iNCIPit-example.ini | 1 + iNCIPit.cgi | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++-- pickup-libs-example | 1 + 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 pickup-libs-example diff --git a/iNCIPit-example.ini b/iNCIPit-example.ini index aec4145..3f01958 100644 --- a/iNCIPit-example.ini +++ b/iNCIPit-example.ini @@ -29,6 +29,7 @@ init_pickup_lib = 2 [path] oils_header = /openils/bin/support-scripts/oils_header.pl opensrf_core = /openils/conf/opensrf_core.xml +pickup_lib_map = pickup-libs userpriv_map = userpriv [status] diff --git a/iNCIPit.cgi b/iNCIPit.cgi index 49b7ec8..c6f0398 100644 --- a/iNCIPit.cgi +++ b/iNCIPit.cgi @@ -131,7 +131,7 @@ sub load_config { } # load and parse userpriv_map file, returning a hashref -sub load_userpriv_map { +sub load_map_file { my $filename = shift; my $map = {}; if (open(my $fh, "<", $filename)) { @@ -155,6 +155,16 @@ sub lookup_userpriv { } } +sub lookup_pickup_lib { + my $input = shift; + my $map = shift; + if (defined($map->{$input})) { # if we found this pickup lib + return $map->{$input}; # return value from mapping hash + } else { + return undef; # the original value does us no good -- return undef + } +} + sub logit { my ( $msg, $func, $more_info ) = @_; open RESP_DATA, ">>resp_data.txt"; @@ -667,12 +677,29 @@ sub item_shipped { my $taidScheme = HTML::Entities::encode($taidSchemeX); my $taidValue = $doc->find('/NCIPMessage/ItemShipped/InitiationHeader/ToAgencyId/UniqueAgencyId/Value'); + my $address = $doc->findvalue('/NCIPMessage/ItemShipped/ShippingInformation/PhysicalAddress/UnstructuredAddress/UnstructuredAddressData'); + my $visid = $doc->findvalue('/NCIPMessage/ItemShipped/ItemOptionalFields/ItemDescription/VisibleItemId/VisibleItemIdentifier') . $faidValue; my $barcode = $doc->findvalue('/NCIPMessage/ItemShipped/UniqueItemId/ItemIdentifierValue') . $faidValue; my $title = $doc->findvalue('/NCIPMessage/ItemShipped/ItemOptionalFields/BibliographicDescription/Title'); my $callnumber = $doc->findvalue('/NCIPMessage/ItemShipped/ItemOptionalFields/ItemDescription/CallNumber'); my $copy = copy_from_barcode($barcode); + + my $pickup_lib; + + if ($address) { + my $pickup_lib_map = load_map_file( $conf->{path}->{pickup_lib_map} ); + + if ($pickup_lib_map) { + $pickup_lib = lookup_pickup_lib($address, $pickup_lib_map); + } + } + + if ($pickup_lib) { + update_hold_pickup($barcode, $pickup_lib); + } + fail( $copy->{textcode} . " $barcode" ) unless ( blessed $copy); my $r = update_copy_shipped( $copy, $conf->{status}->{transit}, $visid ); # put copy into INN-Reach Transit status & modify barcode = Visid != tempIIIiNumber @@ -900,7 +927,7 @@ sub lookupUser { $good_until = $patron->expire_date || "unknown"; $userpriv = $patron->profile->name; - my $userpriv_map = load_userpriv_map( $conf->{path}->{userpriv_map} ); + my $userpriv_map = load_map_file( $conf->{path}->{userpriv_map} ); if ($userpriv_map) { $userpriv = lookup_userpriv($userpriv, $userpriv_map); @@ -1272,6 +1299,27 @@ sub locid_from_barcode { return $response->{ids}[0]; } +sub bre_id_from_barcode { + check_session_time(); + my ($barcode) = @_; + my $response = + OpenSRF::AppSession->create('open-ils.search') + ->request( 'open-ils.search.bib_id.by_barcode', $barcode ) + ->gather(1); + return $response; +} + +sub holds_for_bre { + check_session_time(); + my ($bre_id) = @_; + my $response = + OpenSRF::AppSession->create('open-ils.circ') + ->request( 'open-ils.circ.holds.retrieve_all_from_title', $session{authtoken}, $bre_id ) + ->gather(1); + return $response; + +} + # Convert a MARC::Record to XML for Evergreen # # Copied from Dyrcona's issa framework which copied @@ -1561,6 +1609,38 @@ sub place_simple_hold { } } +sub update_hold_pickup { + check_session_time(); + + my ( $copy_barcode, $pickup_lib ) = @_; + + # start with barcode of item, find bib ID + my $rec = bre_id_from_barcode($copy_barcode); + + # call for holds on that bib + my $holds = holds_for_bre($rec); + + # There should only be a single copy hold + my $hold_id = @{$holds->{copy_holds}}[0]; + + # update the copy hold with the new pickup lib information + my $hold_details = + OpenSRF::AppSession->create('open-ils.circ') + ->request( 'open-ils.circ.hold.details.retrieve', $session{authtoken}, $hold_id ) + ->gather(1); + + my $hold = $hold_details->{hold}; + + $hold->pickup_lib($pickup_lib); + + my $result = + OpenSRF::AppSession->create('open-ils.circ') + ->request( 'open-ils.circ.hold.update', $session{authtoken}, $hold ) + ->gather(1); + + return $result; +} + # Flesh user information # Arguments # actor.usr.id diff --git a/pickup-libs-example b/pickup-libs-example new file mode 100644 index 0000000..40f04ce --- /dev/null +++ b/pickup-libs-example @@ -0,0 +1 @@ +zz999 Example System Example Branch 1:4 -- 2.3.6