X-Git-Url: https://git.donarmstrong.com/?p=reference.git;a=blobdiff_plain;f=lib%2FReference%2FRetrieve%2FPubMed.pm;h=78cf93533641c6b190f04c039e6f1ca77b303ba9;hp=d1de4e9c20a68ec1d7c275f3e348edcc8674bb09;hb=HEAD;hpb=6f76a72abf717b3e1fa3ea4027169734b1ebbad7 diff --git a/lib/Reference/Retrieve/PubMed.pm b/lib/Reference/Retrieve/PubMed.pm index d1de4e9..78cf935 100644 --- a/lib/Reference/Retrieve/PubMed.pm +++ b/lib/Reference/Retrieve/PubMed.pm @@ -201,8 +201,8 @@ sub _create_reference_from_xml($$){ title => [_fix_medline_title($ref->{MedlineCitation}->{Article}->{ArticleTitle})], abstract => [_fix_medline_abstract($ref->{MedlineCitation}->{Article}->{Abstract}->{AbstractText})], journal => [_fix_medline_journal($ref->{MedlineCitation}->{Article}->{Journal}, - $ref->{MedlineCitation}->{Article}->{MedlineJournalInfo}, - $ua, + $ref->{MedlineCitation}->{MedlineJournalInfo}, + $ua, #@_, # configuration )], _fix_ids($ref), @@ -332,12 +332,17 @@ sub _fix_medline_journal($$$;){ # # - my $ISSN = $journal->{ISSN}; + my $ISSN = length($journal->{ISSN})? $journal->{ISSN} : $medline_journal->{ISSNLinking}; if (ref $ISSN) { $ISSN = $ISSN->{content}; + } + if (not length($ISSN)) { + use Data::Printer; + p $journal; + die "No ISSN"; } 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 +350,17 @@ sub _fix_medline_journal($$$;){ $response =~ s/\<///; - 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 +374,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}, @@ -423,7 +437,7 @@ sub _fix_medline_pages($){ if (not defined $start) { ($start) = $pagination =~ /(\d+)/ } - if ($start > $stop and defined $stop) { + if ($start > $stop and defined $stop and length($stop)) { # this must be a reduced page listing; fix it up $stop+=$start - $start % 10 ** (int(log($stop)/log(10))+1); }