NIH | National Cancer Institute | NCI Wiki  

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Java

Prerequisite:  Java 1.6.x8

Code Block
languagejava
titleJava REST example
collapsetrue
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://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://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();






    }
}

Scala

We recommend using the free community edition of Intellij

Multiexcerpt include
MultiExcerptNameExitDisclaimer
nopaneltrue
PageWithExcerptwikicontent:Exit Disclaimer to Include
. Download and install the Scala plugin according to the directions. Then follow instructions for creating a Scala project and an object like the following. Change the URL to whatever CTS2 service is available

Code Block
languagejava
titleScala REST Example
collapsetrue
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://lexevscts2.nci.nih.gov/lexevscts2/valuesets").openConnection().asInstanceOf[HttpURLConnection]
  val inputStream = connection.getInputStream
  val src = Source.fromInputStream(inputStream)
  src.getLines().foreach(println)
}

...

Code Block
languagehtml/xml
titleHTML
collapsetrue
<!DOCTYPE html>
<html>
<head>
    <title>Code System</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="cts2/js/codeSystem.js"></script>
    <script src="cts2/js/jquery-1.10.2.js"></script>
</head>
<body>
<h1>Code Systems</h1>
<script>init()</script>
<ul class="nav nav-pills nav-stacked">
    <li class="active"><a href="#">Home</a></li>
</ul>
<script src="bootstrap/js/bootstrap.js"></script>
</body>
</html>
  • Open the new html HTML file in a browser and you should see  code systems displayed on a browser page.

...

Code Block
languagebash
titleShell Script using Unix curl command
r0223758:~ m029206$ curl http://http://lexevscts2.nci.nih.gov/lexevscts2/codesystemversions

...

The CTS2 Framework and its dependencies are easily pulled in to your Java project via maven using the following elements in the pom.xml file:

Code Block
      <repository>
            <id>edu.informatics<id>nci.maven.release<releases</id>
            <name>Informatics<name>NCI Maven Release Repository</name>
            <url>https://ncimvn.nci.nih.gov/nexus/content/repositories/LexEVSRelease</url>
      </repository>

      <dependency>
            <groupId>edu.mayo.cts2.framework</groupId>
            <artifactId>cts2-core</artifactId>
            <version>1.23.13.FINAL</version>
      </dependency>

...

DescriptionRESTModel Element Class
Code System Versions<base url>codesystemversions?format=jsonCodeSystemVersionCatalogEntryDirectory
Code System Read
<base url>/codesystem/NCI_Thesaurus/version/1017.07e06d
CodeSystemVersionCatalogEntryMsg
Code System Version Query<base url>/codesystemversions?matchvalue=nci_thesaurus&filtercomponent=resourceName&format=jsonCodeSystemVersionCatalogEntryDirectory
Value Sets<base url>resolvedvaluesets?format=jsonResolvedValueSetDirectory
Value Set Definition Read<base url>/cts2/valueset/CDISC%20ADaM%20Date%20Imputation%20Flag%20TerminologyCDISC ADaM Terminology/definition/c38261e55f51c37b?format=jsonValueSetDefinitionMsg
Value Set Query
<base url>/resolvedvaluesets?matchvalue=imputation&filtercomponent=resourceName&format=json
ResolvedValueSetDirectory
Value Set Entries<base url>/valueset/NICHD Newborn Screening valueset/CDISC Questionnaire Terminology/definition/4125c982aa5e7b3f/resolution/1?format=json
IteratableResolvedValueSet
Entities
<base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entities?format=json
EntityDirectory
Entity Read<base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entity/C3399?format=jsonEntityDescriptionMsg
Entity Query
          <base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entities?matchvalue=swelling&format=json
EntityDirectory
Association parents<base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entity/C3399?format=json

EntityDescriptionMsg
with an instance entity with method calls:

entity.getEntityDescription().getNamedEntity().getParent()

returning an instance of URIAndEntityName[]

Association children
<base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entity/C3399/children?format=json
EntityDirectory
Association subjectOf
<base url>/codesystem/npo/version/TestForMultiNamespace/entity/GO:NPO_1607/subjectof?format=json
AssociationDirectory
Association targetOf
<base url>/codesystem/NCI_Thesaurus/version/1017.10a06d/entity/C3399/targetof?format=json
AssociationDirectory
Maps
<base url>/mapversions?format=json
MapVersionDirectory
Map Version Query<base url>/mapversions?matchvalue=ncit&filtercomponent=resourceSynopsis&format=jsonMapVersionDirectory
Map Version Read
<base url>/map/NCItMA_to_ICD9CMNCIt_Mapping/version/NCItMA_to_ICD9CMNCIt_Mapping-1.0?format=json
MapVersionDirectoryMapVersionMsg
Map Entities
<base urel>url>/map/NCItMA_to_ICD9CMNCIt_Mapping/version/NCItMA_to_ICD9CMNCIt_Mapping-1.0/entries?format=json
 MapEntryDirectory MapVersionDirectory
Map Restriction To, From, or Both Role
<base url>/mapversions?codesystem=ICD9CMICD10CM&codesystemsmaprole=MAP_TO_ROLE&format=json
MapVersionDirectory
Complete Code Example
Code Block
languagejava
collapsetrue
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://lexevscts2.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();
	}

}

Other Development Platforms

...