CLEiM
Cross Lingual Education in Medicine
 All Classes Namespaces Files Functions Variables
CallPMSoap.java
Go to the documentation of this file.
00001 package com.uem.gsi.cleim.scl;
00002 import java.rmi.RemoteException;
00003 import java.util.ArrayList;
00004 import java.util.List;
00005 
00006 import org.apache.axis2.AxisFault;
00007 import org.apache.commons.httpclient.util.URIUtil;
00008 
00009 import com.uem.gsi.cleim.util.Constants;
00010 
00011 import gov.nih.nlm.ncbi.www.soap.eutils.*;
00012 
00013 public class CallPMSoap {
00014         private String term;
00015         private String lan="";
00016         private String logic="+";
00017   private int limit=20;
00018         private int pmPage=0;
00019         private int count=0;
00020         private int totalpages=0;
00021         private String idList="";
00022         private List<String> lIDList;
00023         private List<String> lTitle;
00024         private List<String> lPubDate;
00025         private List<String> lAuthors;
00026   private List<String> lAbstractUrl;
00027   
00028         public CallPMSoap() {
00029                 lIDList = new ArrayList<String>();
00030                 lTitle = new ArrayList<String>();
00031         lPubDate = new ArrayList<String>();
00032         lAuthors = new ArrayList<String>();
00033         lAbstractUrl = new ArrayList<String>();
00034   }
00035         
00036         private void queryPMID(){
00037                 try {
00038                         EUtilsServiceStub stub = new EUtilsServiceStub();
00039                         EUtilsServiceStub.ESearchRequest eSearchRequest=new EUtilsServiceStub.ESearchRequest();
00040                         eSearchRequest.setTool(Constants.ENTREZ_TOOL);
00041                         eSearchRequest.setEmail(Constants.ENTREZ_EMAIL);
00042                         eSearchRequest.setDb("pubmed");
00043                         String termUrlenc=URIUtil.encodeQuery(this.term).replaceAll("%20", this.logic);
00044                         eSearchRequest.setTerm(termUrlenc+this.lan);
00045                         eSearchRequest.setSort("PublicationDate");
00046                         eSearchRequest.setDatetype("edat");
00047                         eSearchRequest.setUsehistory("y");
00048                         eSearchRequest.setRetMax(""+this.limit);
00049                         eSearchRequest.setRetStart(""+this.pmPage*this.limit);
00050                         EUtilsServiceStub.ESearchResult res = stub.run_eSearch(eSearchRequest);
00051                         this.count=new Integer(res.getCount());
00052                         totalpages=new Integer(count/limit);
00053                         if (res.getIdList().getId()!=null){
00054                                 int i = 0;
00055                                 int resLength=res.getIdList().getId().length;
00056                                 for (i = 0; i < resLength-1; i++){
00057                                         String id=res.getIdList().getId()[i];
00058                                         lIDList.add(id);
00059                                         idList+=id+",";
00060                                 }
00061                                 String id=res.getIdList().getId()[resLength-1];
00062                                 lIDList.add(id);
00063                                 idList+=id;
00064                         }
00065                 } catch (AxisFault e) {
00066                         e.printStackTrace();
00067                 } catch (RemoteException e) {
00068                         e.printStackTrace();
00069                 } catch (Exception e){
00070                         e.printStackTrace();
00071                 }
00072         }
00073         
00074         public void queryPMInit(){
00075                 queryPMID();
00076                 if (!idList.equals("")){
00077                         try {
00078                                 EUtilsServiceStub stub = new EUtilsServiceStub();
00079                                 EUtilsServiceStub.ESummaryRequest eSummaryRequest = new  EUtilsServiceStub.ESummaryRequest();
00080                                 eSummaryRequest.setTool(Constants.ENTREZ_TOOL);
00081                                 eSummaryRequest.setEmail(Constants.ENTREZ_EMAIL);
00082                                 eSummaryRequest.setDb("pubmed");
00083                                 eSummaryRequest.setId(this.idList);
00084                                 //eSummaryRequest.setRetmax("10");
00085                                 //eSummaryRequest.setRetstart(0);
00086                                 EUtilsServiceStub.ESummaryResult res = stub.run_eSummary(eSummaryRequest);
00087                                 int resLength=res.getDocSum().length;
00088                                 for (int i = 0; i < resLength; i++){
00089                                         String title="",pubdate="",abstracturl="",authors="";
00090                                         for (int k = 0; k < res.getDocSum()[i].getItem().length; k++){
00091                                                 if (res.getDocSum()[i].getItem()[k].getItem()==null){
00092                                                         String name=res.getDocSum()[i].getItem()[k].getName();
00093                                                         String value=res.getDocSum()[i].getItem()[k].getItemContent();
00094                                                         if (name.equals("Title")) title=value;
00095                                                         else if (name.equals("PubDate")) pubdate=value;
00096                                                         else if (name.equals("HasAbstract") && value.equals("1")) 
00097                                                                 abstracturl=Constants.ENTREZ_BASE+"efetch.fcgi?db=pubmed&id="+
00098                                                        this.lIDList.get(i)+"&rettype=abstract&retmode=text";
00099                                                 }else{
00100                                                         if (res.getDocSum()[i].getItem()[k].getName().equals("AuthorList")){
00101                                                                 int subLength=res.getDocSum()[i].getItem()[k].getItem().length;
00102                                                                 for (int w = 0; w < subLength; w++){
00103                                                                         String value=res.getDocSum()[i].getItem()[k].getItem()[w].getItemContent();
00104                                                                         authors+=value+". ";
00105                                                                 }
00106                                                         }
00107                                                 }
00108                                                 
00109                                         }
00110                                         lTitle.add(title);
00111                                         lPubDate.add(pubdate);
00112                                         lAbstractUrl.add(abstracturl);
00113                                         lAuthors.add(authors);
00114                                 }
00115                         } catch (AxisFault e) {
00116                                 e.printStackTrace();
00117                         } catch (RemoteException e) {
00118                                 e.printStackTrace();
00119                         }
00120                 }
00121         }
00122         public void setTerm(String pterm){
00123                 this.term=pterm;
00124         }
00125         public void setLanSpa(){
00126                 this.lan="+(spa[LANG])";
00127         }
00128         public void setLan(String pLan){
00129                 this.lan=pLan;
00130         }
00131         public void setLogic(String plogic){
00132                 this.logic=plogic;
00133         }
00134         public void setLimit(int plimit){
00135                 this.limit=plimit;
00136         }
00137         public void setPage(int pPage){
00138                 this.pmPage=pPage;
00139         }
00140         public int getCount(){
00141         return this.count;
00142   }
00143         public int getTotalPages(){
00144         return this.totalpages;
00145   }
00146         public List<String> getTitles(){
00147         return this.lTitle;
00148   }
00149   public List<String> getPubDates(){
00150         return this.lPubDate;
00151   }
00152   public List<String> getAuthors(){
00153         return this.lAuthors;
00154   }
00155   public List<String> getAbstractUrl(){
00156         return this.lAbstractUrl;
00157   }
00158   
00159         public static void main (String[] args){
00160                 CallPMSoap oPM=new CallPMSoap();
00161                 oPM.setTerm("Cáncer de próstata");
00162                 try {
00163                 oPM.setPage(0);
00164                 //oPM.setLanSpa();
00165                 oPM.queryPMInit();
00166             List<String> l0=oPM.getTitles();
00167             List<String> l1=oPM.getPubDates();
00168             List<String> l2=oPM.getAuthors();
00169             List<String> l3=oPM.getAbstractUrl();
00170             System.out.println("Resultados: "+oPM.getCount());
00171             for (int i=0;i<l1.size();i++){
00172                 System.out.println("<tr>");
00173                 System.out.println("<td>"+l0.get(i)+"<br><a href='"+l3.get(i)+
00174                                 "' target=_blank>Go to Abstract</a></td>"+
00175                                 "<td>"+l1.get(i)+"</td>"+
00176                                 "<td>"+l2.get(i)+"</td>");
00177                 System.out.println("</tr>");
00178             }
00179           } catch (Exception e) {
00180                 System.out.println(e.toString());
00181           }
00182      
00183         }
00184         
00185 }