Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; /** * Created with IntelliJ IDEA. * User: m029206 * Date: 9/20/12 * Time: 11:48 AM. */ public class ValueSetClient { public void getValueSets(){ String uri = "http://informatics.mayo.edu/cts2/rest/http://lexevscts2.nci.nih.gov/lexevscts2/valuesets"; URL url; try { url = new URL(uri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } connection.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void getValueSet(){ String uri = "http:///informatics.mayo.edu/cts2/resthttp://lexevscts2.nci.nih.gov/lexevscts2/valuesets?matchvalue=Sequence&format=json"; URL url; HttpURLConnection connection = null; try { url = new URL(uri); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; System.out.println("\nOutput from CTS2 Service .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if(connection != null){ connection.disconnect(); } } } public static void main(String[] args){ ValueSetClient client = new ValueSetClient(); client.getValueSets(); client.getValueSet(); } } |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
package mayo.edu.cts2.client.rest.scala import java.net.{HttpURLConnection, URL} import io.Source /** * Created with IntelliJ IDEA. * Author: Scott Bauer bauer.scott@mayo.edu * Date: 10/2/12 * Time: 3:17 PM */ object CTS2RestClient extends App{ val connection = new URL("http://http://informaticslexevscts2.nci.mayonih.edugov/cts2/restlexevscts2/valuesets").openConnection().asInstanceOf[HttpURLConnection] val inputStream = connection.getInputStream val src = Source.fromInputStream(inputStream) src.getLines().foreach(println) } |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
__author__ = 'sbauer' import urllib2 try: file = urllib2.urlopen('http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/resolvedvaluesets') except urllib2.URLError, e: if e.code == 404: print("check url") # continue to handle other errors here else: print(file.read()) |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
__author__ = 'sbauer' from restful_lib import Connection conn = Connection("http://http://informaticslexevscts2.nci.mayonih.edugov/cts2/restlexevscts2") reply = conn.request_get("/valuesets") if reply['headers']['status'] == '200': print reply['body'] conn = Connection("http://http://informaticslexevscts2.nci.mayonih.edugov/cts2/restlexevscts2") reply = conn.request_get("/valuesets?format=json",headers={'Accept':'application/json;q=1.0'}) if reply['headers']['status'] == '200': print reply['body'] print eval(reply['body']) conn = Connection("http://http://informaticslexevscts2.nci.mayonih.edugov/cts2/restlexevscts2") print conn.request_get("/valuesets?matchvalue='Sequence'")['body'] |
...
Warning |
---|
This script example features JSON parsing. The JSON structure in CTS2 1.0 was non-standard and will not be compatible with the standardized JSON in CTS2 1.1. CTS2 XML is standard. CTS2 associated with LexEVS 6.2 will contain the standard version of JSON for CTS 1.1. |
- Download JQuery 1.10.x
and Bootstrap 3.0.xMultiexcerpt include nopanel true MultiExcerptName ExitDisclaimer PageWithExcerpt wikicontent:Exit Disclaimer to Include Multiexcerpt include nopanel true MultiExcerptName ExitDisclaimer PageWithExcerpt wikicontent:Exit Disclaimer to Include - Create a CTSRest directory for your files
- Add directories bootstrap and cts2 to this root
- Add subdirectories js and css to both directories you've just created
- Add bootstrap.js to the bootstrap/js directory
- Add bootstrap.min.css to the bootstrap/css directory
- Add jquery-1.10.2.js to the cts2/js library
- Create a codeSystem.js text file and add the following text (adjust the serviceUrl to point to a convenient CTS2 service)
...
Code Block | ||||
---|---|---|---|---|
| ||||
r0223758:~ m029206$ curl http://informatics.mayo.edu/cts2/rest/http://lexevscts2.nci.nih.gov/lexevscts2/codesystemversions |
Java Serialization using the CTS2 Framework
...
Code Block | ||||
---|---|---|---|---|
| ||||
package cts2.mayo.example; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; import edu.mayo.cts2.framework.core.json.JsonConverter; import edu.mayo.cts2.framework.model.codesystemversion.CodeSystemVersionCatalogEntryDirectory; import edu.mayo.cts2.framework.model.codesystemversion.CodeSystemVersionCatalogEntrySummary; import edu.mayo.cts2.framework.model.core.EntitySynopsis; import edu.mayo.cts2.framework.model.core.URIAndEntityName; import edu.mayo.cts2.framework.model.entity.EntityDescriptionMsg; import edu.mayo.cts2.framework.model.entity.EntityDirectory; import edu.mayo.cts2.framework.model.entity.EntityDirectoryEntry; import edu.mayo.cts2.framework.model.mapversion.MapVersionDirectory; import edu.mayo.cts2.framework.model.mapversion.MapVersionDirectoryEntry; import edu.mayo.cts2.framework.model.valuesetdefinition.IteratableResolvedValueSet; import edu.mayo.cts2.framework.model.valuesetdefinition.ResolvedValueSetDirectory; import edu.mayo.cts2.framework.model.valuesetdefinition.ResolvedValueSetDirectoryEntry; public class RESTFromCTS2Framework { String baseUri = "http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/"; String format = "?format=json"; public void getValueSets(){ URL url; try { url = new URL(baseUri + "resolvedvaluesets" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); ResolvedValueSetDirectory valuesetdir = converter.fromJson( builder.toString(), ResolvedValueSetDirectory.class); List<ResolvedValueSetDirectoryEntry> sum = valuesetdir .getEntryAsReference(); for (ResolvedValueSetDirectoryEntry s : sum) { System.out.println(s.getResolvedHeader().getResolutionOf() .getValueSet().getContent()); } } catch (Exception e) { e.printStackTrace(); } } public void getValueSetEntries(){ URL url; try { url = new URL(baseUri + "valueset/NICHD%20Newborn%20Screening%20Terminology/definition/4125c982/resolution/1" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); IteratableResolvedValueSet valuesetdir = converter.fromJson( builder.toString(), IteratableResolvedValueSet.class); List<EntitySynopsis> sum = valuesetdir.getEntryAsReference(); for (EntitySynopsis s : sum) { System.out.println(s.getName()); } } catch (Exception e) { e.printStackTrace(); } } public void getCodeSystems(){ URL url; try { url = new URL(baseUri + "codesystemversions" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); CodeSystemVersionCatalogEntryDirectory valuesetdir = converter.fromJson( builder.toString(), CodeSystemVersionCatalogEntryDirectory.class); List<CodeSystemVersionCatalogEntrySummary> sum = valuesetdir .getEntryAsReference(); for (CodeSystemVersionCatalogEntrySummary s : sum) { System.out.println(s.getFormalName()); } } catch (Exception e) { e.printStackTrace(); } } public void getEntities(){ URL url; try { url = new URL(baseUri + "codesystem/NCI_Thesaurus/version/10.10a/entities" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); EntityDirectory valuesetdir = converter.fromJson( builder.toString(), EntityDirectory.class); List<EntityDirectoryEntry> sum = valuesetdir .getEntryAsReference(); for (EntityDirectoryEntry s : sum) { System.out.println(s.getName()); } } catch (Exception e) { e.printStackTrace(); } } public void entityReadParent(){ URL url; try { url = new URL(baseUri + "codesystem/NCI_Thesaurus/version/10.10a/entity/C3399" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); EntityDescriptionMsg entity = converter.fromJson( builder.toString(), EntityDescriptionMsg.class); URIAndEntityName[] sum = entity.getEntityDescription().getNamedEntity().getParent(); for (URIAndEntityName s : sum) { System.out.println(s.getName()); } } catch (Exception e) { e.printStackTrace(); } } public void getMaps(){ URL url; try { url = new URL(baseUri + "mapversions" + format); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestProperty("Accept", "text/json"); if (connection.getResponseCode() != 200) { throw new RuntimeException("Failed : The HTTP error code is : " + connection.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader( (connection.getInputStream()))); String output; StringBuilder builder = new StringBuilder(); while ((output = br.readLine()) != null) { builder.append(output); } JsonConverter converter = new JsonConverter(); MapVersionDirectory maps = converter.fromJson( builder.toString(), MapVersionDirectory.class); List<MapVersionDirectoryEntry> sum = maps.getEntryAsReference(); for (MapVersionDirectoryEntry s : sum) { System.out.println(s.getFormalName()); } } catch (Exception e) { e.printStackTrace(); } } /** * @param args */ public static void main(String[] args) { new RESTFromCTS2Framework().getCodeSystems(); new RESTFromCTS2Framework().getValueSets(); new RESTFromCTS2Framework().getEntities(); new RESTFromCTS2Framework().entityReadParent(); new RESTFromCTS2Framework().getMaps(); new RESTFromCTS2Framework().getValueSetEntries(); } } |
...
Read a version of the entity based on the context of it's namespace.
Code Block |
---|
http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607 |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<EntityDescriptionMsg xmlns="http://schema.omg.org/spec/CTS2/1.0/Entity" xmlns:core="http://schema.omg.org/spec/CTS2/1.0/Core"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.omg.org/spec/CTS2/1.0/Entity http://www.omg.org/spec/cts2/201206/entity/Entity.xsd"> <core:heading> <core:resourceRoot> codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607 </core:resourceRoot> <core:resourceURI> http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607 </core:resourceURI> <core:accessDate>2013-12-17T13:18:11.095-06:00</core:accessDate> </core:heading> <EntityDescription> <namedEntity about="http://id.nlm.nih.gov/cui/C1138831/NPO_1607" entryState="ACTIVE"> <entityID> <core:namespace>GO</core:namespace> <core:name>NPO_1607</core:name> </entityID> <describingCodeSystemVersion> <core:version href="http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace">npo-TestForMultiNamespace</core:version> <core:codeSystem uri="http://purl.bioontology.org/ontology/npo">npo</core:codeSystem> </describingCodeSystemVersion> <designation designationRole="PREFERRED"> <core:value>regulation of molecular function</core:value> </designation> <property> <core:predicate uri="http://purl.bioontology.org/ontology/npo/code"> <core:namespace>npo</core:namespace> <core:name>code</core:name> </core:predicate> <core:value> <core:literal> <core:value>NPO_1653</core:value> </core:literal> </core:value> </property> <property> <core:predicate uri="http://purl.bioontology.org/ontology/npo/dBXrefID"> <core:namespace>npo</core:namespace> <core:name>dBXrefID</core:name> </core:predicate> <core:value> <core:literal> <core:value>GO:0065009</core:value> </core:literal> </core:value> </property> <property> <core:predicate uri="http://purl.bioontology.org/ontology/npo/definition"> <core:namespace>npo</core:namespace> <core:name>definition</core:name> </core:predicate> <core:value> <core:literal> <core:value> <ncicp:ComplexDefinition><ncicp:def-definition>Any process that modulates the frequency, rate or extent of a molecular function, an elemental biological activity occurring at the molecular level, such as catalysis or binding.</ncicp:def-definition></ncicp:ComplexDefinition> </core:value> </core:literal> </core:value> </property> <property> <core:predicate uri="http://purl.bioontology.org/ontology/npo/preferred_name"> <core:namespace>npo</core:namespace> <core:name>preferred_name</core:name> </core:predicate> <core:value> <core:literal> <core:value>regulation of molecular function</core:value> </core:literal> </core:value> </property> <property> <core:predicate uri="http://purl.bioontology.org/ontology/npo/primitive"> <core:namespace>npo</core:namespace> <core:name>primitive</core:name> </core:predicate> <core:value> <core:literal> <core:value>false</core:value> </core:literal> </core:value> </property> <subjectOf> http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607/subjectof </subjectOf> <targetOf> http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607/targetof </targetOf> <children> http://bmidev4:5555/cts2lexevscts2.nci.nih.gov/lexevscts2/codesystem/npo/version/TestForMultiNamespace/entity/NPO_1607/children </children> <entityType uri="http://www.w3.org/2002/07/owl#Class"> <core:namespace>owl</core:namespace> <core:name>Class</core:name> </entityType> </namedEntity> </EntityDescription> </EntityDescriptionMsg> |
...