Class: Pubmed

Inherits:
Service show all
Includes:
MetadataHelper
Defined in:
app/service_adaptors/pubmed.rb

Overview

Looks up pmid from NLM api, and enhances referent with citation data.

If you use SFX, you prob don't need/want this, as SFX does this already.

Constant Summary

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

#group, #name, #priority, #request, #service_id, #status, #task, #url

Instance Method Summary collapse

Methods included from MetadataHelper

#get_doi, #get_epage, #get_gpo_item_nums, #get_identifier, #get_isbn, #get_issn, #get_lccn, #get_month, #get_oclcnum, #get_pmid, #get_search_creator, #get_search_terms, #get_search_title, #get_spage, #get_sudoc, #get_top_level_creator, #get_year, #normalize_lccn, #normalize_title, #raw_search_title, title_is_serial?

Methods included from MarcHelper

#add_856_links, #edition_statement, #get_title, #get_years, #gmd_values, #service_type_for_856, #should_skip_856_link?, #strip_gmd

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config) ⇒ Pubmed

Returns a new instance of Pubmed



11
12
13
14
15
# File 'app/service_adaptors/pubmed.rb', line 11

def initialize(config)
  @display_name = "PubMed"
  @url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi'
  super(config)
end

Instance Method Details

#enhance_referent(body, request) ⇒ Object

Pull everything useful out of the Pubmed record



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/service_adaptors/pubmed.rb', line 45

def enhance_referent(body, request)   
  doc = Nokogiri::XML(body)
  return unless cite = doc.at("PubmedArticleSet/PubmedArticle/MedlineCitation") # Nothing of interest here
  
  return unless article = cite.at("Article") # No more useful metadata   
  if abstract = article.at("Abstract/AbstractText")
    request.add_service_response(        
    :service=>self,
    :display_text => "Abstract from #{@display_name}",
    :content => abstract.inner_text,
    :service_type_value => 'abstract') unless abstract.inner_text.blank?      
  end
  
  if journal = article.at("Journal")
    if issn = journal.at('ISSN')
      if issn.attributes['issntype']=="Print"                  
        request.referent.enhance_referent('issn', issn.inner_html)
      else 
        request.referent.enhance_referent('eissn', issn.inner_html)        
      end
    end
    if jrnlissue = journal.at('JournalIssue')
      if volume = jrnlissue.at('Volume')
        request.referent.enhance_referent('volume', volume.inner_text)
      end
      if issue = jrnlissue.at('Issue')
        request.referent.enhance_referent('issue', issue.inner_text)
      end   
      if date = jrnlissue.at('PubDate')    
        
        request.referent.enhance_referent('date', openurl_date(date))
        
      end              
    end
    
    if jtitle = journal.at('Title')
      request.referent.enhance_referent('jtitle', jtitle.inner_text)          
    end
    if stitle = journal.at('ISOAbbreviation')
      request.referent.enhance_referent('stitle', stitle.inner_text)
    end       
    
    if atitle = article.at('ArticleTitle')
      request.referent.enhance_referent('atitle', atitle.inner_text)
    end   
    
    if pages = article.at('Pagination/MedlinePgn')
      page_str = pages.inner_text
      request.referent.enhance_referent('pages', page_str)
      if spage = page_str.split("-")[0]
        request.referent.enhance_referent('spage', spage.strip)
      end
    end                
    
    if author = article.at('AuthorList/Author')
      if last_name = author.at('LastName')
        request.referent.enhance_referent('aulast', last_name.inner_text)
      end
      if first_name = author.at('ForeName')
        request.referent.enhance_referent('aufirst', first_name.inner_text)
      end          
      if initials = author.at('Initials')
        request.referent.enhance_referent('auinit', initials.inner_text)
      end          
    end              
  end      

end

#fetch_record(pmid) ⇒ Object

Do the request. Takes the PMID as inputs



33
34
35
36
37
38
39
40
41
42
# File 'app/service_adaptors/pubmed.rb', line 33

def fetch_record(pmid)  
  pmid_url = self.url + "?db=pubmed&retmode=xml&rettype=full&id="+pmid
  begin
    response = Net::HTTP.get_response(URI.parse(pmid_url))
  rescue
    return false
  end
  return false if response.body.match("<ERROR>Empty id list - nothing todo</ERROR>")
  return response.body
end

#handle(request) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'app/service_adaptors/pubmed.rb', line 17

def handle(request)
  return request.dispatched(self, true) unless pmid = get_pmid(request.referent)
      
  return request.dispatched(self, false) unless response = self.fetch_record(pmid)
  
  self.enhance_referent(response, request)
  
  return request.dispatched(self, true)    
end

#openurl_date(date_xml) ⇒ Object

input a PubMed <PubDate> element, return a string usable as rft.date yyyymmdd



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/service_adaptors/pubmed.rb', line 116

def openurl_date(date_xml)
  date = ""
  
  if y = date_xml.at("Year")
    date << ("%04d" % y.inner_text.strip[0,4].to_i )
    if m = date_xml.at("Month")
      # Month name to number
      date << ( "%02d" % DateTime.parse(m.inner_text.strip).month )
      if d = date_xml.at("Day")
        date << ("%02d" % d.inner_text.strip[0,2].to_i)
      end
    end
  end
          
  return date             
end

#service_types_generatedObject



27
28
29
# File 'app/service_adaptors/pubmed.rb', line 27

def service_types_generated
  @service_types ||= [ServiceTypeValue["referent_enhance"]]
end