![]() |
Page History
...
Install Python on your system. Create a text file with the .py extension and run with the "python myrestclient.py" command
Code Block | ||||
---|---|---|---|---|
| ||||
__author__ = 'sbauer' import urllib2 try: file = urllib2.urlopen('http://bmidev4:5555/cts2/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://informatics.mayo.edu/cts2/rest") reply = conn.request_get("/valuesets") if reply['headers']['status'] == '200': print reply['body'] conn = Connection("http://informatics.mayo.edu/cts2/rest") 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://informatics.mayo.edu/cts2/rest") print conn.request_get("/valuesets?matchvalue='Sequence'")['body'] |
JavaScript (JQuery and Bootstrap.js)
- Download JQuery 1.10.x and Bootstrap 3.0.x
- 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var CodeSystemListConfig = { serviceUrl: "http://<base url>/codesystemversions?format=json" }; function init() { $(document).ready( function() { var url = CodeSystemListConfig.serviceUrl; $.getJSON(url + "&callback=?", function (data) { for (var i in data.codeSystemVersionCatalogEntryDirectory.entryList) { var entry = data.codeSystemVersionCatalogEntryDirectory.entryList[i]; var key = entry.formalName; var designation = entry.documentURI; var uri = entry.href; $("ul").append("<li><a href=\"" + uri +"\">" + key + "</a></li>"); } }); }); } |
- when complete add codesystem.js to the cts2/js directory
- Create a new html file containing the following html and add it to the root CTSRest folder
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<!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 file in a browser and you should see code systems displayed on a browser page.
Unix Command Line
returns XML that can be piped to a file
...