LP1655158 Patron Search by Date of Birth
authorblake <blake@mobiusconsortium.org>
Thu, 10 Aug 2017 15:20:19 +0000 (15:20 +0000)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 24 Aug 2017 14:01:47 +0000 (10:01 -0400)
Altered to extract day/month from Postgres in two digits instead of one.

Signed-off-by: blake <blake@mobiusconsortium.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm
docs/RELEASE_NOTES_NEXT/lp1655158_search_by_dob_NOTES.adoc [new file with mode: 0755]

index 9631f88..3a769bf 100644 (file)
@@ -698,11 +698,24 @@ sub patron_search {
        @usrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
     }
 
-    $dob = join ' AND ', map { ("CAST (DATE_PART('" . ( s/year//g ? 'year' : ( s/month//g ? 'month' : 'day' ) ) . "', dob) AS text) ~ ?") } grep { ''.$$search{$_}{group} eq '4' } keys %$search;
+    while (($key, $value) = each (%$search)) {
+        if($$search{$key}{group} eq '4') {
+            my $tval = $key;
+            $tval =~ s/dob_//g;
+            my $right = "RIGHT('0'|| ";
+            my $end = ", 2)";
+            $log->info("BOOYA - tval = $tval");
+            $end = $right = '' if lc $tval eq 'year';
+            $dob .= $right."CAST(DATE_PART('$tval', dob) AS text)$end ~ ? AND ";
+        }
+    }
+    # Trim the last " AND "
+    $dob = substr($dob,0,-4);
+
     @dobv = map { _clean_regex_chars($$search{$_}{value}) } grep { ''.$$search{$_}{group} eq '4' } keys %$search;
 
     $usr .= ' AND ' if ( $usr && $dob );
-    $usr .= $dob if $dob;
+    $usr .= $dob if $dob; # $dob not in-line above in case $usr doesn't have any search vals (only searched for dob)
     push(@usrv, @dobv) if @dobv;
 
     my $addr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
diff --git a/docs/RELEASE_NOTES_NEXT/lp1655158_search_by_dob_NOTES.adoc b/docs/RELEASE_NOTES_NEXT/lp1655158_search_by_dob_NOTES.adoc
new file mode 100755 (executable)
index 0000000..a0ddb5c
--- /dev/null
@@ -0,0 +1,4 @@
+Patron Search by Birth Date
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+* Now you can include the patron birth year and/or birth month and/or
+  birth day when searching for patrons using the web based staff client.
\ No newline at end of file