Results 1 to 5 of 5
  1.    #1  
    Hi all. I am trying to create a PubMed app and am using the EntrezAJAX: An AJAX endpoint for NCBI's Entrez service

    It's easy to return a result in Json format like:

    Code:
    "result": [
    
    {"DOI": "10.1002/jhm.701", "Title": "Pregabalin-induced trismus in a leukemia patient.", "Source": "J Hosp Med", "PmcRefCount": 0, "Issue": "2", "ISSN": "1553-5592", "Volume": "6", "FullJournalName": "Journal of hospital medicine : an official publication of the Society of Hospital Medicine", "RecordStatus": "PubMed - in process", "ESSN": "1553-5606", "ELocationID": "doi: 10.1002/jhm.701", "Pages": "103-4", "PubStatus": "ppublish", "AuthorList": ["Kwong YL", "Leung AY", "Cheung RT"], "PubTypeList": ["Journal Article"], "PubDate": "2011 Feb", "NlmUniqueID": "101271025", "LastAuthor": "Cheung RT", "ArticleIds": {"medline": [], "pubmed": ["21290583"], "doi": "10.1002/jhm.701"}, "Item": [], "History": {"entrez": "2011/02/04 06:00", "medline": ["2011/02/04 06:00"], "pubmed": ["2011/02/04 06:00"]}, "LangList": ["English"], "HasAbstract": 0, "SO": "2011 Feb;6(2):103-4", "EPubDate": "", "References": [], "Id": "21290583"}, 
    
    {"DOI": "10.1002/cncr.25773", "Title": "Intensity-modulated radiation therapy reduces radiation-induced trismus in patients with nasopharyngeal carcinoma: A prospective study with >5 years of follow-up.", "Source": "Cancer", "PmcRefCount": 0, "Issue": "", "ISSN": "0008-543X", "Volume": "", "FullJournalName": "Cancer", "RecordStatus": "PubMed - as supplied by publisher", "ESSN": "1097-0142", "ELocationID": "doi: 10.1002/cncr.25773", "Pages": "", "PubStatus": "aheadofprint", "AuthorList": ["Chen YY", "Zhao C", "Wang J", "Ma HL", "Lai SZ", "Liu Y", "Han F", "Lu LX", "Bao Y", "Chen M"], "PubTypeList": ["Journal Article"], "PubDate": "2011 Jan 24", "NlmUniqueID": "0374236", "LastAuthor": "Chen M", "ArticleIds": {"medline": [], "pubmed": ["21264821"], "doi": "10.1002/cncr.25773"}, "Item": [], "History": {"entrez": "2011/01/26 06:00", "medline": ["2011/01/26 06:00"], "pubmed": ["2011/01/26 06:00"]}, "LangList": ["English"], "HasAbstract": 1, "SO": "2011 Jan 24;", "EPubDate": "2011 Jan 24", "References": [], "Id": "21264821"}, 
    
    etc...
    ]
    Now I can successfully make the Ajax request and

    Code:
    	gotResponse: function(transport) {
    		json= transport.responseText;
    everything seems to hold all the Json data as above

    I would like to get it into a webOS list but this code fails to update my list and the Ares logviewer isn't very helpful:

    Code:
    	gotResponse: function(transport) {
    		json = transport.responseText;
    		k = 0;
    	newData = [];
    	for(j=0; j<json.query.count; j++) {
    	newData[k] = {
    	title: json.query.result[j].Title,
    	pubmedID: json.query.result[j].Id
    	};
    k++;
    }
    this.listModel.items = newData;
    this.controller.modelChanged(this.listModel, this);
    Appreciate help, thanks
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  2. #2  
    You have to convert the responseText to a JSON array first.

    Code:
    json = transport.responseText;
    json = Mojo.parseJSON(json);
    k = 0;
  3. #3  
    First question: what object are you using for your XHR? a native XMLHttpRequest, an explicit Ajax.Request from prototype, or Ares's newfangled "webservice" object?

    Second question: Is your list an Ares list or a Mojo list? (or, can you manually add items to the list?)

    Actual help: Try adding a "Mojo.Log.info" line to your loop.

    Random advice not related to your question: instead of using k and introducing a possibility for a numeric mis-match, why not just use newData.push() to add items to the newData array?

    Code:
    gotResponse: function(transport) {
    	json = transport.responseText;
    	k = 0;
    	newData = [];
    	for(j=0; j<json.query.count; j++) {
    		newData[k] = {
    			title: json.query.result[j].Title,
    			pubmedID: json.query.result[j].Id
    		};
    		k++;
    	}
    	this.listModel.items = newData;
    	this.controller.modelChanged(this.listModel, this);
    }
    Doug Meerschaert
    NoInsultSoftware.com

    Apps: Scratch, GasMath, CheckMath
  4.    #4  
    OK thanks. Forgot about the conversion of the JSON text to object

    I am using an Ajax request as outlined from this example page (I use my own API key requested from entrezajax - the one in the code below is that given in the example):

    Code:
    http://entrezajax.appspot.com/examples/esearch+esummary.html
    The http request to entrezajax will return a JSON formatted text. Eg if I am looking for "lymphoma" :

    Code:
    http://entrezajax.appspot.com/esearch+esummary?apikey=191d24f81e61c107bca103f7d6a9ca10&db=pubmed&term=lymphoma

    My code which I am using in Ares is an Ajax request:

    Code:
          path = "http://entrezajax.appspot.com/esearch+esummary";
                   var myAJax = new Ajax.Request(path, {
                   method: 'get',
                   parameters: {
                   apikey : '191d24f81e61c107bca103f7d6a9ca10', //key given in example
                   db     : 'pubmed',
                   term   : searchterm,
                   retmax : 20,          // max number of results from Esearch
                   max    : 10,          // max number of results passed to Esummary
                   start  : 0
                   },
                   evalJSON: 'force',
                   onSuccess: this.gotResponse.bind(this),
                   onFailure: this.noResponse.bind(this)
              });
    Here's the gotResponse bit:

    Code:
    		gotResponse: function(transport) {
    		everything = transport.responseText;
    		var json = everything.evalJSON();
    If I understand things correctly, json should now hold the text data as a json object. I wish to push selected items to a new array and use this in a webOS list.

    So for example a search for lymphoma which gives this result:

    Code:
    {
        "result": [
            {
                "DOI": "10.1016/j.critrevonc.2010.12.003",
                "Title": "Lymphoblastic lymphoma.",
                "Source": "Crit Rev Oncol Hematol",
                "PmcRefCount": 0,
                "Issue": "",
                "ISSN": "1040-8428",
                "Volume": "",
                "FullJournalName": "Critical reviews in oncology/hematology",
                "RecordStatus": "PubMed - as supplied by publisher",
                "ESSN": "1879-0461",
                "ELocationID": "",
                "Pages": "",
                "PubStatus": "aheadofprint",
                "AuthorList": [
                    "Cortelazzo S",
                    "Ponzoni M",
                    "Ferreri AJ",
                    "Hoelzer D"
                ],
                "EPubDate": "2011 Jan 25",
                "PubDate": "2011 Jan 25",
                "NlmUniqueID": "8916049",
                "LastAuthor": "Hoelzer D",
                "ArticleIds": {
                    "pii": "S1040-8428(10)00283-0",
                    "medline": [
                        
                    ],
                    "pubmed": [
                        "21273093"
                    ],
                    "doi": "10.1016/j.critrevonc.2010.12.003"
                },
                "Item": [
                    
                ],
                "History": {
                    "received": "2010/04/20 00:00",
                    "medline": [
                        "2011/01/29 06:00"
                    ],
                    "revised": "2010/11/09 00:00",
                    "pubmed": [
                        "2011/01/29 06:00"
                    ],
                    "accepted": "2010/12/23 00:00",
                    "entrez": "2011/01/29 06:00"
                },
                "LangList": [
                    "English"
                ],
                "HasAbstract": 1,
                "SO": "2011 Jan 25;",
                "PubTypeList": [
                    "Journal Article"
                ],
                "References": [
                    
                ],
                "Id": "21273093"
            },
    has a lot of stuff I don't need.
    I would like to push only the "Title" ("Lymphoblastic lymphoma" in this first item) and "id" ("21273093" in this first item) into a new array to use in a list and this is what I tried to do in the earlier code.


    Code:
    		k = 0;
    		newData = [];
    		for(j=0; j<json.result.count; j++) {
    		newData[k] = {
    		title: json.result[j].Title,
    		pubmedID: json.result[j].Id
    		};
    		k++;
    		}
    		this.listModel.items = newData;
    		this.controller.modelChanged(this.listModel, this);
    but the list remains blank. I am using the Ares Log viewer turned on but there is no hint of what is going on wrong
    console.log(newData.length); turns out 0 so the data is not being pushed into the new array.
    Last edited by palmdoc2005; 02/05/2011 at 06:55 PM.
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News
  5.    #5  
    My bad, it should be


    Code:
    		k = 0;
    		newData = [];
    		for(j=0; j<json.result.length; j++) {
    		newData[k] = {
    		title: json.result[j].Title,
    		};
    		k++;
    		}
    		this.listModel.items = newData;
    		this.controller.modelChanged(this.listModel, this);
    which works.

    Don't know why
    pubmedID: json.result[j].Id

    can't get the Id
    Check out my My Medical webOS Apps
    Featured free apps: DrugView | Eponyms | eMed | Dosecalcfree | Beeb News

Posting Permissions