Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[bioontology-support] [EXTERNAL] Re: Access Code Notations via REST API

Zak Raicik ZRaicik at jhancock.com
Mon Jun 29 11:58:02 PDT 2020


No problem- thanks. I didn’t realize that was a display parameter I could toggle. This was helpful!

Zak Raicik, FSA
Director, Data Science
Manulife

From: Michael Dorf <mdorf at stanford.edu>
Date: Monday, June 29, 2020 at 2:45 PM
To: Zak Raicik <ZRaicik at jhancock.com>
Cc: "support at bioontology.org" <support at bioontology.org>
Subject: Re: [bioontology-support] [EXTERNAL] Re: Access Code Notations via REST API

Sorry, my email client has removed the original indentations:

counter = 1
page_url = REST_URL + "/ontologies/ICD10/classes?display=prefLabel,synonym,definition,notation,cui,semanticType,properties&no_links=true&no_context=true&page="
classes_page = get_gson(REST_URL + page_url + counter.to_string)

while classes_page['collection’] != null
    for single_class in class_page['collection’]
        icd10_code = single_class[’notation’]
        # do stuff with the icd10_code
    end for

    counter += 1
    classes_page = get_gson(REST_URL + page_url + counter.to_string)
end while



On Jun 29, 2020, at 11:39 AM, Michael Dorf <mdorf at stanford.edu<mailto:mdorf at stanford.edu>> wrote:

Hi Zak,

My Python is a bit rusty (we mostly use Ruby in our in-house stack), but I can comment on the execution.

ontologies = get_json(REST_URL+"/ontologies")
url = [x['links']['classes'] for x in ontologies if 'icd10' in x['acronym'].lower()][2]
It looks like you are calling the /ontologies REST endpoint, then iterating over the results to: a) find the ICD10 ontology; and b) extract the link to classes for ICD10 ontology. This code is redundant. Your link to the /classes endpoint of ICD10 ontology is already well known, you don’t need to look for it:
http://data.bioontology.org/ontologies/ICD10/classes?display=prefLabel,synonym,definition,notation,cui,semanticType,properties&no_links=true&no_context=true&page=1

To get the notation field, you must explicitly ask for it by using the “display” parameter. So the pseudocode for your operation should look like this (sorry, I can’t write it in straight Python):

counter = 1
page_url = REST_URL + "/ontologies/ICD10/classes?display=prefLabel,synonym,definition,notation,cui,semanticType,properties&no_links=true&no_context=true&page="
classes_page = get_gson(REST_URL + page_url + counter.to_string)

while classes_page['collection’] != null
for single_class in class_pages['collection’]
icd10_code = single_class[’notation’]
# do stuff with the icd10_code
counter += 1
classes_page = get_gson(REST_URL + page_url + counter.to_string)


Hope you can convert it to what you need.

Thanks!

Michael






On Jun 29, 2020, at 11:04 AM, Zak Raicik <ZRaicik at jhancock.com<mailto:ZRaicik at jhancock.com>> wrote:

Hey Michael-

Thanks for the response. My confusion is coming from the fact that I don’t see the field “notation” as a key in the returning JSON.

I attached my code below. Do you mind taking a quick look?

import urllib.request, urllib.error, urllib.parse
import json
import os
import pandas as pd

from tqdm.notebook import tqdm

REST_URL = http://data.bioontology.org<http://data.bioontology.org/>

def get_json(url):
    opener = urllib.request.build_opener()
    opener.addheaders = [('Authorization', 'apikey token=' + api_key)]
    return json.loads(opener.open(url).read())

ontologies = get_json(REST_URL+"/ontologies")
url = [x['links']['classes'] for x in ontologies if 'icd10' in x['acronym'].lower()][2]

codes = pd.DataFrame()
page = get_json(url)
NumberPages0 = page['pageCount']
EntriesPerPage = len([x for x in page['collection']])

for PageNumber in tqdm(range(NumberPages0)):
    NextPage = page['links']['nextPage']
   for entry in range(EntriesPerPage):
        Id = page['collection'][entry]['@id']
        code = Id.rsplit('/', 1)[-1]
        desc = page['collection'][entry]['prefLabel']
        data = {"Code": code, "Description": desc}
        codes = codes.append(data,ignore_index=True)
    if NextPage is not None:
        page = get_json(NextPage)
        EntriesPerPage = len([x for x in page['collection']])

Zak Raicik, FSA
Director, Data Science
Manulife

From: Michael Dorf <mdorf at stanford.edu<mailto:mdorf at stanford.edu>>
Date: Monday, June 29, 2020 at 1:38 PM
To: Zak Raicik <ZRaicik at jhancock.com<mailto:ZRaicik at jhancock.com>>
Cc: "support at bioontology.org<mailto:support at bioontology.org>" <support at bioontology.org<mailto:support at bioontology.org>>
Subject: [EXTERNAL] Re: [bioontology-support] Access Code Notations via REST API

CAUTION This email is from an external sender, be cautious with links and attachments.
Hi Zak,

Thank you for contacting us. You can retrieve this info programmatically in one of these two ways:

1. Using the /classes endpoint:

http://data.bioontology.org/ontologies/ICD10/classes?display=prefLabel,synonym,definition,notation,cui,semanticType,properties&no_links=true&no_context=true&page=1

OR

2. Using the /search endpoint:

http://data.bioontology.org/search?ontologies=ICD10&sort=prefLabel&display=prefLabel,synonym,definition,notation,cui,semanticType,properties&no_links=true&no_context=true&page=1

In the latter example, the results are being sorted by the prefLabel alphabetically. In your Python script, you can iterate over ALL ontology terms by processing the results one page at a time and incrementing the “page=1” parameter on each subsequent call.

The ICD10 code is stored in the field “notation”.

For the actual Python code, you can use some of the examples below as your starting point:

https://github.com/ncbo/ncbo_rest_sample_code/tree/master/python

Let us know if you have additional questions.

Michael




On Jun 29, 2020, at 6:11 AM, Zak Raicik <ZRaicik at jhancock.com<mailto:ZRaicik at jhancock.com>> wrote:

Hi –

Is there any way to use the REST API to get a comprehensive listing off all codes/notations within a given class?

For example, if I want to get a complete listing of all possible ICD10 codes from the API using python- is that possible?

Thanks,
Zak Raicik, FSA
Director, Data Science
Manulife

STATEMENT OF CONFIDENTIALITY The information contained in this email message and any attachments may be confidential and legally privileged and is intended for the use of the addressee(s) only. If you are not an intended recipient, please: (1) notify me immediately by replying to this message; (2) do not use, disseminate, distribute or reproduce any part of the message or any attachment; and (3) destroy all copies of this message and any attachments.
_______________________________________________
bioontology-support mailing list
bioontology-support at lists.stanford.edu<mailto:bioontology-support at lists.stanford.edu>
https://mailman.stanford.edu/mailman/listinfo/bioontology-support


STATEMENT OF CONFIDENTIALITY The information contained in this email message and any attachments may be confidential and legally privileged and is intended for the use of the addressee(s) only. If you are not an intended recipient, please: (1) notify me immediately by replying to this message; (2) do not use, disseminate, distribute or reproduce any part of the message or any attachment; and (3) destroy all copies of this message and any attachments.

_______________________________________________
bioontology-support mailing list
bioontology-support at lists.stanford.edu<mailto:bioontology-support at lists.stanford.edu>
https://mailman.stanford.edu/mailman/listinfo/bioontology-support



STATEMENT OF CONFIDENTIALITY The information contained in this email message and any attachments may be confidential and legally privileged and is intended for the use of the addressee(s) only. If you are not an intended recipient, please: (1) notify me immediately by replying to this message; (2) do not use, disseminate, distribute or reproduce any part of the message or any attachment; and (3) destroy all copies of this message and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/bioontology-support/attachments/20200629/946c9f94/attachment-0001.html>


More information about the bioontology-support mailing list