]> git.donarmstrong.com Git - reference.git/commitdiff
fix multiple catalog records per id
authorDon Armstrong <don@donarmstrong.com>
Tue, 24 Jan 2017 16:20:15 +0000 (08:20 -0800)
committerDon Armstrong <don@donarmstrong.com>
Tue, 24 Jan 2017 16:20:15 +0000 (08:20 -0800)
debian/changelog
lib/Reference/Retrieve/PubMed.pm

index 091d371ad9dd93919153a02db99a999213b29d2a..04f7482fa6732d6b52a8e63d6d989245eff5e472 100644 (file)
@@ -1,3 +1,9 @@
+libreference-perl (0.2-3) unstable; urgency=medium
+
+  * Fix multiple catalog records per id
+
+ -- Don Armstrong <don@debian.org>  Tue, 24 Jan 2017 10:09:53 -0600
+
 libreference-perl (0.2-2) unstable; urgency=medium
 
   * New update for odd journal names
index 9c477756bac22d47c7304ffa7889d461674b6bc8..6cc771be078e9db14c95cfdf087d1b117626e771 100644 (file)
@@ -337,7 +337,7 @@ sub _fix_medline_journal($$$;){
          $ISSN = $ISSN->{content};
      }
      my $url = qq(http://www.ncbi.nlm.nih.gov/nlmcatalog/?term=${ISSN}[ISSN]&format=text&report=xml);
-     print STDERR "url: $url" if $DEBUG;
+     print STDERR "url: $url\n" if $DEBUG;
      my $request = HTTP::Request->new('GET', $url);
      my $response = $ua->request($request);
      $response = $response->content;
@@ -345,10 +345,17 @@ sub _fix_medline_journal($$$;){
      $response =~ s/\&lt;/</gso;
      $response =~ s/^<\/?pre>//;
 
-     print STDERR "response: $response" if $DEBUG;
+     print STDERR "response: $response\n" if $DEBUG;
      my $xa = new XML::Simple;
      my $ref_struct = $xa->XMLin($response,ForceArray=>['NCBICatalogRecord'],KeyAttr=>[]);
-     my $ref = $ref_struct->{NCBICatalogRecord}[0];
+     my $ref;
+     for (0..@{$ref_struct->{NCBICatalogRecord}}) {
+         if (exists $ref_struct->{NCBICatalogRecord}[$_]{JrXml}) {
+             $ref = $ref_struct->{NCBICatalogRecord}[$_];
+             last;
+         }
+     }
+     $ref = $ref_struct->{NCBICatalogRecord}[0] if not defined $ref;
      print STDERR Dumper($ref) if $DEBUG;
 
      my %journal;
@@ -362,9 +369,11 @@ sub _fix_medline_journal($$$;){
               $journal{lc($2)} = $3;
          }
   }
+     print STDERR Dumper($ref) if $DEBUG;
      if (ref $ref->{JrXml}{Serial}{ISSN} ne 'ARRAY') {
          $ref->{JrXml}{Serial}{ISSN} = [$ref->{JrXml}{Serial}{ISSN}];
      }
+     print STDERR Dumper($ref->{JrXml}) if $DEBUG;
      my $print_issn = $ref->{JrXml}{Serial}{ISSN}[0]{IssnType} eq 'Print' ? 0 : 1;
      my @journal_entry =
          (title       => $ref->{JrXml}{Serial}{Title},