LP1901930 Add some missing SIP fields
authorBill Erickson <berickxx@gmail.com>
Tue, 29 Nov 2022 16:14:20 +0000 (11:14 -0500)
committerBill Erickson <berickxx@gmail.com>
Tue, 29 Nov 2022 16:14:20 +0000 (11:14 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Checkin.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Item.pm

index 3a985e8..657908d 100644 (file)
@@ -254,9 +254,11 @@ sub handle_item_info {
             {CF => $details->{hold_queue_length}},
             {CK => $details->{media_type}},
             {CM => $details->{hold_pickup_date}},
+            {CR => $details->{collection_code}},
+            {CS => $details->{call_number}},
             {CT => $details->{destination_loc}},
             {CY => $details->{hold_patron_barcode}},
-            $SC->stat_cat_sip_fields($details->{item})
+            $SC->asset_stat_cat_sip_fields($details->{item})
         ]
     };
 }
@@ -434,7 +436,7 @@ sub patron_response_common_data {
             {BL => $SC->sipbool(1)},          # valid patron
             {BV => $details->{balance_owed}}, # fee amount
             {CQ => $SC->sipbool($details->{valid_patron_password})},
-            $SC->stat_cat_sip_fields($patron),
+            $SC->actor_stat_cat_sip_fields($patron),
         ]
     };
 
@@ -724,11 +726,7 @@ sub handle_checkin {
         return_date => $return_date
     );
 
-    my $screen_msg = $checkin_details->{screen_msg};
     my $magnetic = $item_details->{magnetic_media};
-    my $hold_bc = $checkin_details->{hold_patron_barcode};
-    my $hold_name = $checkin_details->{hold_patron_name};
-    my $dest_loc = $checkin_details->{destination_loc};
 
     return {
         code => '10',
@@ -746,15 +744,18 @@ sub handle_checkin {
             {AO => $config->{institution}},
             {AP => $checkin_details->{current_loc}},
             {AQ => $checkin_details->{permanent_loc}},
+            {BF => $checkin_details->{hold_patron_phone}},
             {BG => $item_details->{owning_loc}},
             {BT => $item_details->{fee_type}},
             {CI => 0}, # security inhibit
             {CK => $item_details->{media_type}},
+            {CR => $item_details->{collection_code}},
+            {CS => $item_details->{call_number}},
             {CV => $checkin_details->{alert_type}},
-            $screen_msg ? {AF => $screen_msg}   : (),
-            $dest_loc   ? {CT => $dest_loc}     : (),
-            $hold_bc    ? {CY => $hold_bc}      : (),
-            $hold_name  ? {DA => $hold_name}    : ()
+            {AF => $checkin_details->{screen_msg}},
+            {CT => $checkin_details->{destination_loc}},
+            {CY => $checkin_details->{hold_patron_barcode}},
+            {DA => $checkin_details->{hold_patron_name}},
         ]
     };
 }
index 1df5f80..c0e05e8 100644 (file)
@@ -138,6 +138,9 @@ sub handle_hold {
         $details->{hold_patron_barcode} = $card->barcode;
     }
 
+    $details->{hold_patron_phone} = 
+        $holder->day_phone || $holder->evening_phone || $holder->other_phone;
+
     if (ref $hold->pickup_lib) {
         $pickup_lib_id = $hold->pickup_lib->id;
         $pickup_lib_sn = $hold->pickup_lib->shortname;
index b90e1f2..b51bc4e 100644 (file)
@@ -133,48 +133,71 @@ sub format_user_name {
     );
 }
 
-# $source is either an actor.usr or an asset.copy.
+sub format_stat_cat_sip_field {
+    my ($field, $value, $format) = @_;
+
+    if ($format) {
+
+        if ($format =~ /^\|(.*)\|$/) { # Is format a regex?
+
+            if ($value =~ /($1)/) { 
+                # Regex has matched.
+
+                if (defined $2) { 
+                    # We have an embedded capture group.  Use it.
+                    $value = $2; 
+                } else { 
+                    # No embedded capture group
+                    $value = $1; # Use our outer one
+                }
+            } else { 
+                # No match
+                # Empty string. Will be checked for below.
+                $value = ''; 
+            }
+        } else { # Not a regex
+
+            #  Try sprintf match (looking for a %s, if any)
+            $value = sprintf($format, $value);
+        }
+    }
+
+    return length($value) > 0 ? ({$field => $value}) : ();
+}
+
 # Returns a list of extra fields.
-sub stat_cat_sip_fields {
-    my ($class, $source) = @_;
+sub actor_stat_cat_sip_fields {
+    my ($class, $patron) = @_;
     my @extras;
 
-    for my $entry_map (@{$source->stat_cat_entries}) {
+    for my $entry_map (@{$patron->stat_cat_entries}) {
         my $stat_cat = $entry_map->stat_cat;
         next unless $stat_cat->sip_field;
 
         my $value = $entry_map->stat_cat_entry;
         my $format = $stat_cat->sip_format;
 
-        if ($format) {
-
-            if ($format =~ /^\|(.*)\|$/) { # Is format a regex?
+        push(@extras, 
+            format_stat_cat_sip_field($stat_cat->sip_field, $value, $format));
+    }
 
-                if ($value =~ /($1)/) { 
-                    # Regex has matched.
+    return @extras;
+}
 
-                    if (defined $2) { 
-                        # We have an embedded capture group.  Use it.
-                        $value = $2; 
-                    } else { 
-                        # No embedded capture group
-                        $value = $1; # Use our outer one
-                    }
-                } else { 
-                    # No match
-                    # Empty string. Will be checked for below.
-                    $value = ''; 
-                }
-            } else { # Not a regex
+# Returns a list of extra fields.
+sub asset_stat_cat_sip_fields {
+    my ($class, $item) = @_;
+    my @extras;
 
-                #  Try sprintf match (looking for a %s, if any)
-                $value = sprintf($format, $value);
-            }
-        }
+    for my $entry_map (@{$item->stat_cat_entry_copy_maps}) {
+        my $stat_cat = $entry_map->stat_cat;
+        next unless $stat_cat->sip_field;
 
-        next unless length($value) > 0; # No value = no export
+        my $value = $entry_map->stat_cat_entry->value;
+        my $format = $stat_cat->sip_format;
 
-        push(@extras, {$stat_cat->sip_field => $value});
+        push(@extras, 
+            format_stat_cat_sip_field($stat_cat->sip_field, $value, $format));
     }
 
     return @extras;
index f697382..65210cd 100644 (file)
@@ -37,6 +37,7 @@ sub get_item_details {
 
     my $details = {
         item => $item,
+        call_number => $item->call_number->label,
         security_marker => '02', # matches SIP/Item.pm
         owning_loc => $item->call_number->owning_lib->shortname,
         current_loc => $item->circ_lib->shortname,
@@ -44,6 +45,12 @@ sub get_item_details {
         destination_loc => $item->circ_lib->shortname # maybe replaced below
     };
 
+    # use the non-translated version of the copy location as the
+    # collection code, since it may be used for additional routing
+    # purposes by the SIP client.  Config option?
+    $details->{collection_code} = $e->retrieve_asset_copy_location(
+               [$item->location, {no_i18n => 1}])->name;
+
     $details->{circ} = $e->search_action_circulation([{
         target_copy => $item->id,
         checkin_time => undef,