LP1901930 Add some missing SIP fields
authorBill Erickson <berickxx@gmail.com>
Mon, 28 Nov 2022 22:30:17 +0000 (17:30 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 28 Nov 2022 22:30:17 +0000 (17:30 -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/Common.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm

index b2cf0be..85859a2 100644 (file)
@@ -255,7 +255,8 @@ sub handle_item_info {
             {CK => $details->{media_type}},
             {CM => $details->{hold_pickup_date}},
             {CT => $details->{destination_loc}},
-            {CY => $details->{hold_patron_barcode}}
+            {CY => $details->{hold_patron_barcode}},
+            $SC->stat_cat_sip_fields($details->{item})
         ]
     };
 }
@@ -286,7 +287,6 @@ sub handle_patron_info {
 
     $response->{code} = '64';
 
-    #return $response unless $details;
     unless ($details) {
         push(
             @{$response->{fixed_fields}}, 
@@ -314,13 +314,20 @@ sub handle_patron_info {
 
     push(
         @{$response->{fields}}, 
-        {BE => $patron->email},
+        {AQ => $patron->home_ou->name},
         {PA => $SC->sipymd($patron->expire_date)},
         {PB => $SC->sipymd($patron->dob, 1)},
         {PC => $patron->profile->name},
-        {XI => $patron->id}
+        {XI => $patron->id},
+        $SC->stat_cat_sip_fields($details->{item})
     );
 
+    $SC->maybe_add_field($response, BD => $details->{patron_address});
+    $SC->maybe_add_field($response, BE => $patron->email);
+    $SC->maybe_add_field($response, BF => $details->{patron_phone});
+    $SC->maybe_add_field($response, 
+        PI => $patron->net_access_level ? $patron->net_access_level->name : '');
+
     if ($list_items eq 'hold_items') {
         for my $hold (@{$details->{hold_items}}) {
             push(@{$response->{fields}}, {AS => $hold});
index c9c38c6..6337593 100644 (file)
@@ -133,5 +133,52 @@ sub format_user_name {
     );
 }
 
+# $source is either an actor.usr or an asset.copy.
+# Returns a list of extra fields.
+sub stat_cat_sip_fields {
+    my ($class, $source) = @_;
+    my @extras;
+
+    for my $entry_map (@{$source->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 (defined $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);
+            }
+        }
+
+        next unless length($value) > 0; # No value = no export
+
+        push(@extras, {$stat_cat->sip_field => $value});
+    }
+
+    return @extras;
+}
+
 
 1;
index 86da493..f9f636a 100644 (file)
@@ -31,6 +31,8 @@ sub get_patron_details {
                 billing_address
                 mailing_address
                 profile
+                home_ou
+                net_access_level
                 stat_cat_entries
             /],
             actscecm => [qw/stat_cat/]
@@ -42,6 +44,25 @@ sub get_patron_details {
     my $patron = $details->{patron} = $card->usr;
     $card->usr($card->usr->id);
     $patron->card($card);
+    $details->{patron_phone} = 
+        $patron->day_phone || $patron->evening_phone || $patron->other_phone;
+
+    if (my $addr = $patron->billing_address || $patron->mailing_address) {
+
+        my $addrstr = join(' ', map {$_ || ''} (
+            $addr->street1,
+            $addr->street2,
+            $addr->city . ',',
+            $addr->county,
+            $addr->state,
+            $addr->country,
+            $addr->post_code
+        ));
+
+        $addrstr =~ s/\s+/ /sg; # Compress spaces
+
+        $details->{patron_address} = $addrstr;
+    }
 
     if (defined $password) {
         # SIP still replies with the patron data if the password