From 0288bbab6c20a35e90a0ee9f6e99d8c942e8dbc8 Mon Sep 17 00:00:00 2001 From: Travers Franckle Date: Wed, 19 Dec 2012 16:49:04 -0500 Subject: [PATCH] implement SMART Container Manifest - SMART /version and /capabilities consolidated into /manifest - fixes #27 --- indivo/accesscontrol/__init__.py | 2 +- indivo/tests/api/smart_tests.py | 4 +- indivo/urls/urls.py | 2 +- indivo/views/smart_container.py | 186 +++++++++++++++++-------------- settings.py.default | 3 + 5 files changed, 111 insertions(+), 86 deletions(-) diff --git a/indivo/accesscontrol/__init__.py b/indivo/accesscontrol/__init__.py index 0c7e8b47..e441e7f5 100644 --- a/indivo/accesscontrol/__init__.py +++ b/indivo/accesscontrol/__init__.py @@ -47,7 +47,7 @@ def basic_access(principal, **unused_args): pha, app_manifest, smart_ontology, - smart_capabilities,] + smart_manifest,] AccessRule('Basic Access', basic_access, views) # Account-related views diff --git a/indivo/tests/api/smart_tests.py b/indivo/tests/api/smart_tests.py index b8658c52..c930c3ca 100644 --- a/indivo/tests/api/smart_tests.py +++ b/indivo/tests/api/smart_tests.py @@ -11,7 +11,7 @@ def test_get_smart_ontology(self): response = self.client.get('/ontology') self.assertEqual(response.status_code, 200) - def test_get_smart_capabilities(self): - response = self.client.get('/capabilities/') + def test_get_smart_manifest(self): + response = self.client.get('/manifest') self.assertEqual(response.status_code, 200) diff --git a/indivo/urls/urls.py b/indivo/urls/urls.py index 4afa1fc1..968f3952 100644 --- a/indivo/urls/urls.py +++ b/indivo/urls/urls.py @@ -35,7 +35,7 @@ # SMART container calls (r'^ontology$', MethodDispatcher({'GET': smart_ontology})), - (r'^capabilities/$', MethodDispatcher({'GET': smart_capabilities})), + (r'^manifest$', MethodDispatcher({'GET': smart_manifest})), # static (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': 'static'}), diff --git a/indivo/views/smart_container.py b/indivo/views/smart_container.py index 4070c1f8..0e19e155 100644 --- a/indivo/views/smart_container.py +++ b/indivo/views/smart_container.py @@ -9,6 +9,8 @@ from base import * import urllib2 +from django.conf import settings + def smart_ontology(request): """Fetch the SMART ontology as RDF/XML.""" @@ -19,85 +21,105 @@ def smart_ontology(request): ontology = urllib2.urlopen(url).read() return HttpResponse(ontology, mimetype="application/rdf+xml") -def smart_capabilities(request): - """SMART Capabilities""" - capabilites = '''{ - "http://smartplatforms.org/terms#Alert": { - "methods": [ - "POST" - ] - }, - "http://smartplatforms.org/terms#Allergy": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#AppManifest": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Capabilities": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Demographics": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Encounter": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Fulfillment": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Immunization": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#LabResult": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Medication": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Ontology": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#Problem": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#User": { - "methods": [ - "GET" - ] - }, - "http://smartplatforms.org/terms#UserPreferences": { - "methods": [ - "DELETE", - "GET", - "PUT" - ] - }, - "http://smartplatforms.org/terms#VitalSignSet": { - "methods": [ - "GET" - ] - } -}''' - return HttpResponse(capabilites, mimetype='application/json') \ No newline at end of file +def smart_manifest(request): + """SMART Container Manifest""" + + manifest = ''' + {{ + "smart_version": "0.5.0", + "api_base": "{api_base}", + "name": "SMART v0.5 Sandbox", + "description": "{site_description}", + "admin": "{admin}", + + "launch_urls": {{ + "authorize_token": "{ui_base}/oauth/authorize", + "exchange_token": "{api_base}/oauth/access_token", + "request_token": "{api_base}/oauth/request_token" + }}, + + "capabilities": {{ + "http://smartplatforms.org/terms#Allergy": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#AppManifest": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#ClinicalNote": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#ContainerManifest": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Demographics": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Encounter": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Fulfillment": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Immunization": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#LabResult": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Medication": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Ontology": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Problem": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#Procedure": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#SocialHistory": {{ + "methods": [ + "GET" + ] + }}, + "http://smartplatforms.org/terms#VitalSignSet": {{ + "methods": [ + "GET" + ] + }} + }} + }}''' + + processed_manifest = manifest.format(api_base=settings.SITE_URL_PREFIX, + ui_base=settings.UI_SERVER_URL, + site_description=settings.SITE_DESCRIPTION, + admin=settings.EMAIL_SUPPORT_ADDRESS) + + return HttpResponse(processed_manifest, mimetype='application/json') diff --git a/settings.py.default b/settings.py.default index a2aa4d5a..c00a00ea 100644 --- a/settings.py.default +++ b/settings.py.default @@ -40,6 +40,9 @@ SAMPLE_DATA_DIR = APP_HOME + '/sample_data' # URL prefix (where indivo_server will be accessible from the web) SITE_URL_PREFIX = "http://localhost:8000" +# Description to show in SMART manifest call +SITE_DESCRIPTION = "Indivo Server" + # URL prefix for the UI server # (usually port 80 on the same machine) UI_SERVER_URL = 'http://localhost'