예제 #1
0
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
예제 #2
0
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
예제 #3
0
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})
예제 #4
0
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
예제 #5
0
def get_smart_client(resource_tokens=None):
    ret = SmartClient(SMART_SERVER_OAUTH['consumer_key'], SMART_SERVER_PARAMS,
                      SMART_SERVER_OAUTH, resource_tokens)
    return ret
예제 #6
0
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)
예제 #7
0
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