Merge branch 'topic/stock_detail_page'
[sgn.git] / cgi-bin / chado / fetch_pubmed.pl
blob0d77a01d4fa2abb16eb8dd5783746440515b7818
2 use strict;
5 use CXGN::Page;
6 use CXGN::Page::FormattingHelpers qw / info_section_html page_title_html html_optional_show/;
7 use CXGN::Chado::Publication;
9 use CXGN::Login;
10 use CXGN::People;
11 use CXGN::Contact;
12 use CXGN::Tools::Pubmed;
13 use CXGN::Tools::Text qw / sanitize_string /;
14 use CXGN::DB::Connection;
16 use base qw / CXGN::DB::ModifiableI /;
18 my $page=CXGN::Page->new("Fetch PubMed","Naama");
19 my $dbh = CXGN::DB::Connection->new();
21 my $logged_in_person_id=CXGN::Login->new($dbh)->verify_session();
22 my $logged_in_user=CXGN::People::Person->new($dbh, $logged_in_person_id);
23 my $logged_in_person_id=$logged_in_user->get_sp_person_id();
24 my $logged_in_username=$logged_in_user->get_first_name()." ".$logged_in_user->get_last_name();
25 my $logged_in_user_type=$logged_in_user->get_user_type();
27 #only curators can access this page
28 if($logged_in_user_type eq 'curator') {
29 $page->header();
30 my %args=$page->get_all_encoded_arguments();
31 my $ids = $args{"pubmed_ids"};
32 my $curator_id= $args{curator_id};
33 my $action = $args{action};
35 my @fail=();
36 if($ids) {
37 my @pubmeds = split (/\r\n/, $ids);
38 if(@fail) {
39 my $fail_str="";
40 foreach(@fail) { $fail_str .= "<li>$_</li>\n"; }
41 print <<END_HTML;
43 <table width=80% align=center>
44 <tr><td>
45 <p>Could not feth pubmed ids for the following reasons</p>
46 <ul>
47 $fail_str
48 </ul>
49 <p>Please use your browser\'s back button to try again.</p>
50 </td></tr>
51 <tr><td><br /></td></tr>
52 </table>
53 END_HTML
55 else {
56 print qq | <br/><b> Fetched the following publications from PubMed</b> | ;
57 my $pubmed_string;
58 my $count=0;
59 foreach my $pubmed (@pubmeds) {
60 my $pub = CXGN::Chado::Publication->new($dbh);
61 $pub->set_accession($pubmed);
62 CXGN::Tools::Pubmed->new($pub); #call eutils and populates the publication object with all necessary fields
63 if ($pub->get_title()) {
64 $count++;
65 my $pub_ref=$pub->print_pub_ref();
66 $pubmed_string .= $pubmed . "|";
67 print <<END_HTML;
68 <table width=80% align=center>
69 <tr><td><p><b>$count.</b> $pub_ref (PMID:$pubmed)</p></td></tr>
70 <tr><td><br /></td></tr>
71 </table>
72 END_HTML
75 print <<END_HTML;
76 <form method="post" action="">
77 <input type="submit" name="action" value="Confirm store">
78 <input type = "hidden" name="curator_id" value=$curator_id>
79 <input type = "hidden" name="publications" value=$pubmed_string>
80 </form><br>
81 <a href="javascript:history.back(1)">Go back without storing the publications</a>
82 END_HTML
86 }elsif ($action eq 'Confirm store') {
88 my $ids = $args{publications};
89 my $curator_id = $args{curator_id} ;
91 my @pubmeds = split (/\|/, $ids);
92 my $count=0;
93 print qq | <br/><b> stored the following publications from PubMed</b><br /> | ;
94 print qq| (assigned to curator $curator_id) | ;
95 #chop $ids;
96 foreach my $pubmed (@pubmeds) {
97 #$pubmed =~ s/ +//g;
98 my $pub = CXGN::Chado::Publication->new($dbh);
99 $count++;
100 $pub->set_accession($pubmed);
101 $pub->add_dbxref("PMID:$pubmed");
102 CXGN::Tools::Pubmed->new($pub); #call eutils and populates the publication object with all necessary fields
103 my $pub_ref=$pub->print_pub_ref();
104 my $e_id = $pub->get_eid;
105 if ($e_id) {
106 $pub->add_dbxref("DOI:$e_id");
108 $pub->store();
110 unless ($pub->is_curated() ) {
111 $pub->set_sp_person_id($logged_in_person_id);
112 $pub->set_curator_id($curator_id); #
113 $pub->set_status('pending');
114 $pub->store_pub_curator();
115 $pub->d("Assigned publication $pubmed to curator $curator_id");
117 print <<END_HTML;
118 <table width=80% align=center>
119 <tr><td><p><b>$count.</b> $pub_ref (PMID:$pubmed)</p></td></tr>
120 <tr><td><br /></td></tr>
121 </table>
122 END_HTML
124 print qq | <a href="/chado/fetch_pubmed.pl">Go back to fetch publications page </a ><br />|;
125 print qq| <a href= "/search/pub_search.pl?w9b3_status=pending">See publications pending curation</a><br />|;
126 } else {
127 my @curators= CXGN::People::Person::get_curators($dbh);
128 my %names = map {$_ => CXGN::People::Person->new($dbh, $_)->get_first_name() } @curators;
129 my $curator_options=qq|<option value="">--Assign publications to curator--</option>|;
130 for my $curator_id (keys %names) {
131 my $curator= $names{$curator_id};
132 $curator_options .=qq|<option value="$curator_id">$curator</option>|;
135 print <<END_HTML;
136 <br/>
137 <form method="post" action="fetch_pubmed.pl">
138 <table cellpadding="2" cellspacing="2">
139 <th colspan="2">Curators may use this form to bulk fetch publications from PubMed.<br />&nbsp;</th>
140 <tr><td><textarea id="" cols="20" rows="10" name="pubmed_ids" value ="Insert a list of PubMed IDs"></textarea></td>
141 <td>
142 <select id="curator_id" name="curator_id"> $curator_options </select>
143 </td></tr>
144 <tr><td><input type="submit" name="fetch_pubmeds" value="Store"><input type="reset" value="Reset form" /></td></tr>
145 </table>
146 <br />
148 END_HTML
151 $page->footer();
153 else { $page->client_redirect('/solpeople/login.pl'); }
157 sub confirm_store {
159 my $self=shift;
160 $self->print_confirm_form();
164 sub print_confirm_form {
165 my $self=shift;
166 my %args= $self->get_args();
168 my $query= sanitize_string($args{query});