Module: PubmedRemote

Defined in:
lib/pubmed_remote.rb

Class Method Summary collapse

Class Method Details

.get_abstract_cd(cd) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pubmed_remote.rb', line 55

def self.get_abstract_cd(cd)
  result=Result.new
  if(cd.pmid.nil?)
    result.error(I18n::t(:No_PMID_to_obtain_information_from_Pubmed))
  else
    pmid_integrator=reference_integrator_xml(cd.pmid)
    if(pmid_integrator)
      if pmid_integrator.abstract.nil?
        result.info(I18n::t(:Pubmed_information_retrieved_but_no_abstract))
      else
        cd.update(abstract:pmid_integrator.abstract)
        result.success(:Abstract_retrieved_from_Pubmed)
      end
    else
      result.error(I18n::t(:Invalid_response_from_Pubmed))
    end
  end
  result
end

.process_single_pmid(pmid) ⇒ Object

Process a single pmid



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pubmed_remote.rb', line 84

def self.process_single_pmid(pmid)
  pmc_summary=Pmc_Summary[pmid]

  if !pmc_summary
    efetch=PMC::Efetch.new([pmid])
    efetch.process
    xml=efetch.pmid_xml.first.xpath("//PubmedArticle").to_s
    Pmc_Summary.insert(:id=>pmid, :xml=>xml)
    xml
  else
    pmc_summary.xml
  end
end

.reference_integrator_xml(pmid) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/pubmed_remote.rb', line 75

def self.reference_integrator_xml(pmid)
  co=self.process_single_pmid(pmid)
  if(co)
    BibliographicalImporter::PmcEfetchXml::Reader.parse(co)[0]
  else
    false
  end
end

.retrieve_pmid(cd_ds) ⇒ Object

Update Canonical documents with pmid

Parameters:

  • cd_cd

    a Sequel Dataset

Returns:

  • Result



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pubmed_remote.rb', line 35

def self.retrieve_pmid(cd_ds)
  dois_list=cd_ds.map(:doi)
  dtpp=PMC::DoiToPmidProcessor.new(dois_list)
  dtpp.process
  retrieved_dois=dtpp.doi_as_pmid.find_all {|v| !v[1].nil?}
  nil_dois=dtpp.doi_as_pmid.find_all {|v| v[1].nil?}
  bad_dois=dtpp.doi_bad
  $db.transaction(:rollback=>:reraise) do
    retrieved_dois.each do |doi_pmid|
      CanonicalDocument.where(:doi=>doi_pmid[0]).update(:pmid=>doi_pmid[1])
    end
  end
  result=Result.new
  result.success(I18n::t("pubmedremote.retrieve_pmid_result", nil_dois:nil_dois.count, dois_pmid:retrieved_dois.count))
  if(bad_dois.length>0)
    result.error(I18n::t("pubmedremote.retrieve_pmid_result_bad_dois", bad_dois:bad_dois.join(", ")))
  end
result
end