def generate_pid(): '''Returns a unique patient ID number in the range [100000000-999999999]''' # Keep generating random PIDs until a unique one is found while True: # Generate a new PID pid = str(random.randint(100000000, 999999999)) isUnique = True print "Generated PID:", pid # Initialize a background app SMART client smart_client = SmartClient(PROXY_OAUTH['consumer_key'], PROXY_PARAMS, PROXY_OAUTH, None) # Check if the PID already exists try: target = '/apps/' + BACKGROUND_OAUTH[ 'consumer_key'] + '/tokens/records/' + pid smart_client.get(target) isUnique = False except: pass # Kill the loop when the PID is determined to be unique if isUnique: break # Return the fresh PID print "PID is unique" return pid
def generate_pid (): '''Returns a unique patient ID number in the range [100000-999999]''' # Keep generating random PIDs until a unique one is found while True: # Generate a new PID pid = str(random.randint(100000000, 999999999)) isUnique = True print "Generated PID:", pid # Initialize a background app SMART client smart_client = SmartClient(PROXY_OAUTH['consumer_key'], PROXY_PARAMS, PROXY_OAUTH, None) # Check if the PID already exists try: target = '/apps/' + BACKGROUND_OAUTH['consumer_key'] + '/tokens/records/' + pid smart_client.get(target) isUnique = False except: pass # Kill the loop when the PID is determined to be unique if isUnique: break # Return the fresh PID print "PID is unique" return pid
def get_smart_client(): """Initializes and returns a new SMART Client Expects an OAUTH header as a REST parameter """ smart_oauth_header = web.input().oauth_header smart_oauth_header = urllib.unquote(smart_oauth_header) oa_params = oauth.parse_header(smart_oauth_header) SMART_SERVER_PARAMS["api_base"] = oa_params["smart_container_api_base"] SMART_SERVER_OAUTH["consumer_key"] = oa_params["smart_app_id"] oa_params = oauth.parse_header(smart_oauth_header) resource_tokens = { "oauth_token": oa_params["smart_oauth_token"], "oauth_token_secret": oa_params["smart_oauth_token_secret"], } ret = SmartClient(SMART_SERVER_OAUTH["consumer_key"], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) ret.record_id = oa_params["smart_record_id"] ret.user_id = oa_params["smart_user_id"] ret.smart_app_id = oa_params["smart_app_id"] return ret
def get_smart_client(): '''Initializes and returns a new SMART Client Expects an OAUTH header as a REST parameter ''' smart_oauth_header = web.input().oauth_header smart_oauth_header = urllib.unquote(smart_oauth_header) oa_params = oauth.parse_header(smart_oauth_header) SMART_SERVER_PARAMS['api_base'] = oa_params['smart_container_api_base'] SMART_SERVER_OAUTH['consumer_key'] = oa_params['smart_app_id'] oa_params = oauth.parse_header(smart_oauth_header) resource_tokens = { 'oauth_token': oa_params['smart_oauth_token'], 'oauth_token_secret': oa_params['smart_oauth_token_secret'] } ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) ret.record_id = oa_params['smart_record_id'] ret.user_id = oa_params['smart_user_id'] ret.smart_app_id = oa_params['smart_app_id'] return ret
def get_smart_client(): '''Initializes and returns a new SMART Client Expects an OAUTH header as a REST parameter ''' smart_oauth_header = web.input().oauth_header smart_oauth_header = urllib.unquote(smart_oauth_header) oa_params = oauth.parse_header(smart_oauth_header) SMART_SERVER_PARAMS['api_base'] = oa_params['smart_container_api_base'] SMART_SERVER_OAUTH['consumer_key'] = oa_params['smart_app_id'] oa_params = oauth.parse_header(smart_oauth_header) resource_tokens={'oauth_token': oa_params['smart_oauth_token'], 'oauth_token_secret':oa_params['smart_oauth_token_secret']} ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) ret.record_id=oa_params['smart_record_id'] ret.user_id=oa_params['smart_user_id'] ret.smart_app_id=oa_params['smart_app_id'] return ret
def get_access_url (patientID, pin): '''Generates a secure SMART Proxy access URL to the patient record''' # Intialize a machine app SMART client smart_client = SmartClient(PROXY_OAUTH['consumer_key'], PROXY_PARAMS, PROXY_OAUTH, None) # Request and return the deep web URL return smart_client.get("/records/" + patientID + "/generate_direct_url", {'pin':pin})
def get_access_url(patientID, pin): '''Generates a secure SMART Proxy access URL to the patient record''' # Intialize a machine app SMART client smart_client = SmartClient(PROXY_OAUTH['consumer_key'], PROXY_PARAMS, PROXY_OAUTH, None) # Request and return the deep web URL return smart_client.get("/records/" + patientID + "/generate_direct_url", {'pin': pin})
def get_smart_client(authorization_header, resource_tokens=None): oa_params = oauth.parse_header(authorization_header) resource_tokens={'oauth_token': oa_params['smart_oauth_token'], 'oauth_token_secret':oa_params['smart_oauth_token_secret']} ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) ret.record_id=oa_params['smart_record_id'] return ret
def get_smart_client(authorization_header, resource_tokens=None): oa_params = oauth.parse_header(authorization_header) resource_tokens = { 'oauth_token': oa_params['smart_oauth_token'], 'oauth_token_secret': oa_params['smart_oauth_token_secret'] } ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) ret.record_id = oa_params['smart_record_id'] return ret
def _get_smart_client(smart_oauth_header): if smart_oauth_header == '': return "No smart_oauth_header" """Convenience function to initialize a new SmartClient""" try: smart_oauth_header = urllib.unquote(smart_oauth_header) except: return "Couldn't find a parameter to match the name 'oauth_header'" oa_params = oauth.parse_header(smart_oauth_header) # This is how we know... # 1. what container we're talking to try: SMART_SERVER_PARAMS['api_base'] = oa_params['smart_container_api_base'] #SMART_SERVER_PARAMS['api_base'] = 'http://sandbox-api.smartplatforms.org' except: return "Couldn't find 'smart_contianer_api_base' in %s" % smart_oauth_header # 2. what our app ID is try: SMART_SERVER_OAUTH['consumer_key'] = oa_params['smart_app_id'] except: return "Couldn't find 'smart_app_id' in %s" % smart_oauth_header # (For demo purposes, we're assuming a hard-coded consumer secret, but # in real life we'd look this up in some config or DB now...) resource_tokens = { 'oauth_token': oa_params['smart_oauth_token'], 'oauth_token_secret': oa_params['smart_oauth_token_secret'] } ret = SmartClient( SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens ) ret.record_id = oa_params['smart_record_id'] return ret
def get_smart_client(resource_tokens=None): ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS, SMART_SERVER_OAUTH, resource_tokens) return ret
def get_smart_client(resource_tokens=None): ret = SmartClient(settings.SMART_APP_ID, settings.SMART_SERVER_PARAMS, settings.SMART_SERVER_OAUTH, resource_tokens) ret.stylesheet = "%s%s"%(settings.XSLT_STYLESHEET_LOC, "ccr_to_med_rdf.xslt") return ret
def get_app_manifests(): smart_client = SmartClient(PROXY_OAUTH['consumer_key'], PROXY_PARAMS, PROXY_OAUTH, None) res = smart_client.get("/apps/manifests/") apps = json.loads(res.body) apps = sorted(apps, key=lambda app: app['name']) return json.dumps(apps, indent=4)
def get_smart_client(resource_tokens=None): ret = SmartClient(settings.SS_OAUTH['consumer_key'], {'api_base': settings.SMART_API_SERVER_BASE}, settings.SS_OAUTH, resource_tokens) return ret