Beispiel #1
0
def fhir_search_home(request):
    """ Check if search parameters are in the GET

     if not pass through to authenticated_home

     """

    if request.user.is_authenticated():

        if request.method == 'GET':
            if '_getpages' in request.GET:
                # print("We got something to get")

                return rebuild_fhir_search(request)

    return authenticated_home(request)
def fhir_search_home(request):
    """ Check if search parameters are in the GET

     if not pass through to authenticated_home

     """

    if request.user.is_authenticated():

        if request.method == "GET":
            if "_getpages" in request.GET:
                # print("We got something to get")

                return rebuild_fhir_search(request)

    return authenticated_home(request)
Beispiel #3
0
def rebuild_fhir_search(request):
    """ Rebuild the Search String

    We will start to use a session variable

    We received:
    http://localhost:8000/cmsblue/fhir/v1
    ?_getpages=61c6e2d1-2b7c-49c3-a083-3d5b3874d4ff&_getpagesoffset=10
    &_count=10&_format=json&_pretty=true&_bundletype=searchset

    Session Variables will be storing:
    - FHIR Target URL/Resource
    - _getpages value
    - expires datetime

    Construct FHIR_Target_URL + search parameters

    """

    # now = str(datetime.now())
    ikey = ''
    if '_getpages' in request.GET:
        ikey = request.GET['_getpages']
        sn_vr = read_session(request, ikey, skey=SESSION_KEY)
        # logger.debug("Session info:%s" % sn_vr)

        if sn_vr == {}:
            # Nothing returned from Session Variables
            # Key could be expired or not matched
            return authenticated_home(request)

        url_call = sn_vr['fhir_to']
        url_call += '/?' + request.META['QUERY_STRING']

        rewrite_url_list = sn_vr['rwrt_list']
        resource_type = sn_vr['res_type']
        interaction_type = sn_vr['intn_type']
        key = sn_vr['key']
        vid = sn_vr['vid']

        cx = get_crosswalk(request.user)

        # logger.debug("Calling:%s" % url_call)
        r = request_call(request, url_call, cx,
                         reverse_lazy('authenticated_home'))

        host_path = get_host_url(request, '?')

        # get 'xml' 'json' or ''
        fmt = get_search_param_format(request.META['QUERY_STRING'])

        text_out = post_process_request(request, fmt, host_path, r,
                                        rewrite_url_list)
        od = build_output_dict(request, OrderedDict(), resource_type, key, vid,
                               interaction_type, fmt, text_out)

        if fmt == 'xml':
            # logger.debug('We got xml back in od')
            return HttpResponse(r.text, content_type='application/%s' % fmt)
            # return HttpResponse( tostring(dict_to_xml('content', od)),
            #                      content_type='application/%s' % fmt)
        elif fmt == 'json':
            # logger.debug('We got json back in od')
            return HttpResponse(pretty_json(od),
                                content_type='application/%s' % fmt)

        # logger.debug('We got a different format:%s' % fmt)
        return render(
            request,
            'bluebutton/default.html',
            {
                'content': pretty_json(od),
                'output': od
            },
        )

    return authenticated_home(request)
Beispiel #4
0
def fhir_conformance(request, *args, **kwargs):
    """ Pull and filter fhir Conformance statement

    BaseDstu2 = "Conformance"
    BaseStu3 = "CapabilityStatement"

    metadata call

    """
    if not request.user.is_authenticated():
        return authenticated_home(request)

    try:
        cx = Crosswalk.objects.get(user=request.user)
    except Crosswalk.DoesNotExist:
        cx = None
        # logger.debug('Crosswalk for %s does not exist' % request.user)

    if cx:
        call_to = cx.fhir_source.fhir_url
    else:
        call_to = FhirServerUrl()

    resource_type = conformance_or_capability(call_to)

    if call_to.endswith('/'):
        call_to += 'metadata'
    else:
        call_to += '/metadata'

    pass_params = strip_oauth(request.GET)
    # pass_params should be an OrderedDict after strip_auth
    # logger.debug("result from strip_oauth:%s" % pass_params)

    # Let's store the inbound requested format
    # We need to simplify the format call to the backend
    # so that we get data we can manipulate
    requested_format = request_format(pass_params)

    # now we simplify the format/_format request for the back-end
    pass_params = strip_format_for_back_end(pass_params)
    back_end_format = pass_params['_format']

    encoded_params = urlencode(pass_params)
    #
    # Add ? to front of parameters if needed
    pass_params = prepend_q(encoded_params)

    # logger.debug("Calling:%s" % call_to + pass_params)

    ####################################################
    ####################################################

    r = request_call(request, call_to + pass_params, cx,
                     reverse_lazy('authenticated_home'))

    ####################################################
    ####################################################

    text_out = ''
    host_path = get_host_url(request, '?')

    # get 'xml' 'json' or ''
    # fmt = get_search_param_format(request.META['QUERY_STRING'])
    # force to json

    # logger.debug("Format:%s" % back_end_format)

    rewrite_url_list = settings.FHIR_SERVER_CONF['REWRITE_FROM']
    # print("Starting Rewrite_list:%s" % rewrite_url_list)

    text_out = post_process_request(request, back_end_format, host_path,
                                    r.text, rewrite_url_list)

    query_string = build_querystring(request.GET.copy())
    # logger.debug("Query:%s" % query_string)

    if 'xml' in requested_format:
        # logger.debug('We got xml back in od')

        # logger.debug("is xml filtered?%s" % requested_format)
        xml_dom = xml_to_dom(text_out)
        text_out = dom_conformance_filter(xml_dom)
        # logger.debug("Text from XML function:\n%s\n=========" % text_out)
        if 'html' not in requested_format:
            return HttpResponse(text_out,
                                content_type='application'
                                '/%s' % requested_format)
        else:
            # logger.debug("Sending text_out for display: %s" % text_out[0:100])
            return render(
                request, 'bluebutton/default_xml.html', {
                    'output': text_out,
                    'content': {
                        'parameters': query_string,
                        'resource_type': resource_type,
                        'request_method': "GET",
                        'interaction_type': "metadata",
                        'source': cx.fhir_source.name
                    }
                })

            # return HttpResponse( tostring(dict_to_xml('content', od)),
        #                      content_type='application/%s' % fmt)
    elif back_end_format == 'json':
        # logger.debug('We got json back in od')
        od = conformance_filter(text_out, back_end_format)
        text_out = pretty_json(od)
        if 'html' not in requested_format:
            return HttpResponse(text_out,
                                content_type='application/'
                                '%s' % requested_format)
    else:
        # let's make sure we have json to deliver:
        od = conformance_filter(text_out, back_end_format)
        text_out = pretty_json(od)

    # logger.debug('We got a different format:%s' % back_end_format)

    return render(
        request, 'bluebutton/default.html', {
            'output': text_out,
            'content': {
                'parameters': query_string,
                'resource_type': resource_type,
                'request_method': "GET",
                'interaction_type': "metadata",
                'source': cx.fhir_source.name
            }
        })
def rebuild_fhir_search(request):
    """ Rebuild the Search String

    We will start to use a session variable

    We received:
    http://localhost:8000/cmsblue/fhir/v1
    ?_getpages=61c6e2d1-2b7c-49c3-a083-3d5b3874d4ff&_getpagesoffset=10
    &_count=10&_format=json&_pretty=true&_bundletype=searchset

    Session Variables will be storing:
    - FHIR Target URL/Resource
    - _getpages value
    - expires datetime

    Construct FHIR_Target_URL + search parameters

    """

    # now = str(datetime.now())
    ikey = ""
    if "_getpages" in request.GET:
        ikey = request.GET["_getpages"]
        sn_vr = read_session(request, ikey, skey=SESSION_KEY)
        # logger.debug("Session info:%s" % sn_vr)

        if sn_vr == {}:
            # Nothing returned from Session Variables
            # Key could be expired or not matched
            return authenticated_home(request)

        url_call = sn_vr["fhir_to"]
        url_call += "/?" + request.META["QUERY_STRING"]

        rewrite_url_list = sn_vr["rwrt_list"]
        resource_type = sn_vr["res_type"]
        interaction_type = sn_vr["intn_type"]
        key = sn_vr["key"]
        vid = sn_vr["vid"]

        logger.debug("Calling:%s" % url_call)
        r = request_call(request, url_call, reverse_lazy("authenticated_home"))

        host_path = get_host_url(request, "?")

        # get 'xml' 'json' or ''
        fmt = get_search_param_format(request.META["QUERY_STRING"])

        text_out = post_process_request(request, fmt, host_path, r, rewrite_url_list)
        od = build_output_dict(request, OrderedDict(), resource_type, key, vid, interaction_type, fmt, text_out)

        if fmt == "xml":
            # logger.debug('We got xml back in od')
            return HttpResponse(r.text, content_type="application/%s" % fmt)
            # return HttpResponse( tostring(dict_to_xml('content', od)),
            #                      content_type='application/%s' % fmt)
        elif fmt == "json":
            # logger.debug('We got json back in od')
            return HttpResponse(pretty_json(od), content_type="application/%s" % fmt)

        # logger.debug('We got a different format:%s' % fmt)
        return render(request, "bluebutton/default.html", {"content": pretty_json(od), "output": od})

    return authenticated_home(request)
def fhir_conformance(request, *args, **kwargs):
    """ Pull and filter fhir Conformance statement

    metadata call

    """
    if not request.user.is_authenticated():
        return authenticated_home(request)

    resource_type = "Conformance"
    call_to = FhirServerUrl()
    if call_to.endswith("/"):
        call_to += "metadata"
    else:
        call_to += "/metadata"

    pass_params = urlencode(strip_oauth(request.GET))

    # Add ? to front of parameters if needed
    pass_params = prepend_q(pass_params)

    logger.debug("Calling:%s" % call_to + pass_params)

    r = request_call(request, call_to + pass_params, reverse_lazy("authenticated_home"))

    text_out = ""
    host_path = get_host_url(request, "?")

    # get 'xml' 'json' or ''
    fmt = get_search_param_format(request.META["QUERY_STRING"])

    rewrite_url_list = settings.FHIR_SERVER_CONF["REWRITE_FROM"]
    # print("Starting Rewrite_list:%s" % rewrite_url_list)

    text_out = post_process_request(request, fmt, host_path, r.text, rewrite_url_list)

    od = conformance_filter(text_out, fmt)

    if fmt == "xml":
        # logger.debug('We got xml back in od')
        return HttpResponse(text_out, content_type="application/%s" % fmt)
        # return HttpResponse( tostring(dict_to_xml('content', od)),
        #                      content_type='application/%s' % fmt)
    elif fmt == "json":
        # logger.debug('We got json back in od')
        return HttpResponse(pretty_json(od), content_type="application/%s" % fmt)

    # logger.debug('We got a different format:%s' % fmt)

    return render(
        request,
        "bluebutton/default.html",
        {
            "output": pretty_json(od),
            "content": {
                "parameters": request.GET.urlencode(),
                "resource_type": resource_type,
                "request_method": "GET",
                "interaction_type": "metadata",
            },
        },
    )