コード例 #1
0
ファイル: smarthacks.py プロジェクト: jmandel2/smart_server
def allow_options(request, **kwargs):
    r =  utils.x_domain(HttpResponse())
    r['Access-Control-Allow-Methods'] = "POST, GET, PUT, DELETE"
    r['Access-Control-Allow-Headers'] = "authorization,x-requested-with,content-type"
    r['Access-Control-Max-Age'] = 60
    print r._headers
    return r
コード例 #2
0
ファイル: account.py プロジェクト: Michael777aa/smart_server
def user_get(request, user_id, **kwargs):
    print "user_get", user_id, kwargs
    try:
        a = Account.objects.get(email=user_id)
        m = a.to_rdf()
    except: return HttpResponseNotFound()
    
    return utils.x_domain(HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #3
0
ファイル: smarthacks.py プロジェクト: nagyistoce/smart_server
def get_record_tokens_helper(record, app):
    t = HELPER_APP_SERVER.generate_and_preauthorize_access_token(
        app, record=record)
    r = {
        'oauth_token': t.token,
        'oauth_token_secret': t.secret,
        'smart_record_id': record.id
    }
    return utils.x_domain(HttpResponse(urllib.urlencode(r), "application/x-www-form-urlencoded"))
コード例 #4
0
def user_get(request, user_id, **kwargs):
    print "user_get", user_id, kwargs
    try:
        a = Account.objects.get(email=user_id)
        m = a.to_rdf()
    except:
        return HttpResponseNotFound()

    return utils.x_domain(
        HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #5
0
ファイル: smarthacks.py プロジェクト: claimat/smart_server
def get_record_tokens_helper(record, app):
    t = HELPER_APP_SERVER.generate_and_preauthorize_access_token(app,
                                                                 record=record)
    r = {
        'oauth_token': t.token,
        'oauth_token_secret': t.secret,
        'smart_record_id': record.id
    }
    return utils.x_domain(
        HttpResponse(urllib.urlencode(r), "application/x-www-form-urlencoded"))
コード例 #6
0
ファイル: smarthacks.py プロジェクト: gijs/smart_server
def container_capabilities(request, **kwargs):
    #m = bound_graph()
    #site = URIRef(settings.SITE_URL_PREFIX)
    #print "avail", dir(m)
    
    #m.add((site, rdf['type'], sp['Container']))
    #m.add((site, sp['capability'], sporg['capability/SNOMED/lookup']))
    #m.add((site, sp['capability'], sporg['capability/SPL/lookup']))
    #m.add((site, sp['capability'], sporg['capability/Pillbox/lookup']))
    
    #return utils.x_domain(HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
    
    capabilities = get_capabilities()
    return utils.x_domain(HttpResponse(json.dumps(capabilities, sort_keys=True, indent=4), "application/json"))
コード例 #7
0
ファイル: smarthacks.py プロジェクト: claimat/smart_server
def container_capabilities(request, **kwargs):
    m = bound_graph()
    site = URIRef(settings.SITE_URL_PREFIX)
    print "avail", dir(m)
    m.add((site, rdf['type'], sp['Container']))

    m.add((site, sp['capability'], sporg['capability/SNOMED/lookup']))

    m.add((site, sp['capability'], sporg['capability/SPL/lookup']))

    m.add((site, sp['capability'], sporg['capability/Pillbox/lookup']))

    return utils.x_domain(
        HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #8
0
def get_container_manifest(request, **kwargs):
    response = {
        'smart_version': settings.VERSION,
        'api_base': settings.SITE_URL_PREFIX,
        'name': settings.NAME,
        'description': settings.DESCRIPTION,
        'admin': settings.EMAIL_SUPPORT_ADDRESS,
        'launch_urls': {
            'request_token': settings.SITE_URL_PREFIX+"/oauth/request_token",
            'authorize_token': settings.SMART_UI_SERVER_LOCATION+"/oauth/authorize",
            'exchange_token': settings.SITE_URL_PREFIX+"/oauth/access_token",
        },
        'capabilities': get_capabilities()
    }
    return utils.x_domain(HttpResponse(json.dumps(response, sort_keys=True, indent=4), "application/json"))
コード例 #9
0
ファイル: smarthacks.py プロジェクト: bewest/smart_server
def container_capabilities(request, **kwargs):
    m = bound_graph()
    site = URIRef(settings.SITE_URL_PREFIX)
    print "avail", dir(m)
    m.add((site, rdf['type'], sp['Container']))

    m.add((site, sp['capability'], sporg['capability/SNOMED/lookup']))

    m.add((site, sp['capability'], sporg['capability/SPL/lookup']))

    m.add((site,
             sp['capability'],
             sporg['capability/Pillbox/lookup']))
    
    return utils.x_domain(HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #10
0
ファイル: account.py プロジェクト: Michael777aa/smart_server
def user_search(request, **kwargs):
    aa = Account.objects.all()

    m = bound_graph()
    
    f  = request.GET.get("givenName", None)
    l  = request.GET.get("familyName", None)
    d  = request.GET.get("department", None)
    r  = request.GET.get("role", None)
    
    if (f != None): aa = aa.filter(given_name__icontains=f)
    if (l != None): aa = aa.filter(family_name__icontains=l)
    if (d != None): aa = aa.filter(department__icontains=d)
    if (r != None): aa = aa.filter(role__icontains=r)
    
    for a in aa:
        print "Adding ", a.email, a.given_name, a.family_name
        a.to_rdf(m)
    
    return utils.x_domain(HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #11
0
ファイル: smarthacks.py プロジェクト: claimat/smart_server
def do_webhook(request, webhook_name):
    hook = None
    headers = {}

    # Find the preferred app for this webhook...
    try:
        hook = AppWebHook.objects.filter(name=webhook_name)[0]
    except:
        raise Exception("No hook exists with name:  '%s'" % webhook_name)

    data = request.raw_post_data
    if (request.method == 'GET'): data = request.META['QUERY_STRING']

    print "requesting web hook", hook.url, request.method, data

    hook_req = utils.url_request_build(hook.url, request.method, headers, data)

    # If the web hook needs patient context, we've got to generate + pass along tokens
    if (hook.requires_patient_context):
        app = hook.app
        record = request.principal.share.record
        account = request.principal.share.authorized_by
        # Create a new token for the webhook to access the in-context patient record
        token = HELPER_APP_SERVER.generate_and_preauthorize_access_token(
            app, record=record, account=account)

        # And supply the token details as part of the Authorization header, 2-legged signed
        # Using the helper app's consumer token + secret
        # (the 2nd parameter =None --> 2-legged OAuth request)
        oauth_request = OAuthRequest(app,
                                     None,
                                     hook_req,
                                     oauth_parameters=token.passalong_params)
        oauth_request.sign()
        for (hname, hval) in oauth_request.to_header().iteritems():
            hook_req.headers[hname] = hval

    response = utils.url_request(hook.url, request.method, headers, data)
    print "GOT,", response
    return utils.x_domain(
        HttpResponse(response, mimetype='application/rdf+xml'))
コード例 #12
0
def user_search(request, **kwargs):
    aa = Account.objects.all()

    m = bound_graph()

    f = request.GET.get("givenName", None)
    l = request.GET.get("familyName", None)
    d = request.GET.get("department", None)
    r = request.GET.get("role", None)

    if (f != None): aa = aa.filter(given_name__icontains=f)
    if (l != None): aa = aa.filter(family_name__icontains=l)
    if (d != None): aa = aa.filter(department__icontains=d)
    if (r != None): aa = aa.filter(role__icontains=r)

    for a in aa:
        print "Adding ", a.email, a.given_name, a.family_name
        a.to_rdf(m)

    return utils.x_domain(
        HttpResponse(utils.serialize_rdf(m), "application/rdf+xml"))
コード例 #13
0
ファイル: smarthacks.py プロジェクト: gijs/smart_server
def do_webhook(request, webhook_name):
    hook = None
    headers = {}
    
    # Find the preferred app for this webhook...
    try:
        hook = AppWebHook.objects.filter(name=webhook_name)[0]
    except:
        raise Exception("No hook exists with name:  '%s'"%webhook_name)
    
    data = request.raw_post_data
    if (request.method == 'GET'): data = request.META['QUERY_STRING']    
    
    print "requesting web hook", hook.url, request.method, data

    hook_req = utils.url_request_build(hook.url, request.method, headers, data)
    
    # If the web hook needs patient context, we've got to generate + pass along tokens
    if (hook.requires_patient_context):        
        app = hook.app
        record = request.principal.share.record
        account = request.principal.share.authorized_by
        # Create a new token for the webhook to access the in-context patient record
        token = HELPER_APP_SERVER.generate_and_preauthorize_access_token(app, record=record, account=account)
        
        # And supply the token details as part of the Authorization header, 2-legged signed
        # Using the helper app's consumer token + secret
        # (the 2nd parameter =None --> 2-legged OAuth request)
        oauth_request = OAuthRequest(app, None, hook_req, oauth_parameters=token.passalong_params)
        oauth_request.sign()        
        for (hname, hval) in oauth_request.to_header().iteritems():
            hook_req.headers[hname] = hval 
    
    response = utils.url_request(hook.url, request.method, headers, data)
    print "GOT,", response
    return utils.x_domain(HttpResponse(response, mimetype='application/rdf+xml'))
コード例 #14
0
ファイル: smarthacks.py プロジェクト: claimat/smart_server
def allow_options(request, **kwargs):
    r = utils.x_domain(HttpResponse())
    r['Access-Control-Allow-Methods'] = "POST, GET, PUT, DELETE"
    r['Access-Control-Allow-Headers'] = "authorization,x-requested-with,content-type"
    r['Access-Control-Max-Age'] = 60
    return r