From f663f78b7d28aa398975862d9f0f357848499bce Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 28 Nov 2022 17:30:17 -0500 Subject: [PATCH] LP1901930 Add some missing SIP fields Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/SIP2.pm | 15 +++++-- .../lib/OpenILS/Application/SIP2/Common.pm | 47 ++++++++++++++++++++++ .../lib/OpenILS/Application/SIP2/Patron.pm | 21 ++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index b2cf0be53c..85859a20bd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -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}); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm index c9c38c67de..6337593915 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm @@ -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; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm index 86da493874..f9f636a0bc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm @@ -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 -- 2.11.0