예제 #1
0
def next_search(request, *args, **kwargs):
    """
    Handle search requests
    :param request:
    :return:
    """

    server = FhirServerUrl()
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    if settings.DEBUG:
        print("Server:", server)
        print("Kwargs:", kwargs)

    context = {
        'display': "Search",
        'name': "Search",
        'server': server,
        'in_fmt': in_fmt,
        'get_fmt': get_fmt,
        'template': 'v1api/search.html',
    }

    request_string = "?"
    for item in request.GET:
        request_string += item + "=" + request.GET[item] + "&"

    if request_string[:0] == "&":
        request_string = request_string[:-1]

    if not "patient=Patient/" in request_string:
        try:
            xwalk = Crosswalk.objects.get(user=request.user)
            patient_id = xwalk.fhir_url_id
            request_string += "&patient=Patient/" + patient_id
        except Crosswalk.DoesNotExist:
            return kickout_404("ID for this user not found:%s" % request.user)

    if settings.DEBUG:
        print("Gets:", request_string)

    try:
        r = requests.get(server + request_string)

        context = process_page(request, r, context)

        return publish_page(request, context)

    except requests.ConnectionError:
        print("Whoops - Problem connecting to FHIR Server")
        messages.error(
            request, "FHIR Server is unreachable. "
            "Are you on the CMS Network?")

    return render_to_response(context['template'],
                              RequestContext(
                                  request,
                                  context,
                              ))
예제 #2
0
def next_search(request, *args, **kwargs):
    """
    Handle search requests
    :param request:
    :return:
    """

    server = FhirServerUrl()
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    if settings.DEBUG:
        print("Server:", server)
        print("Kwargs:",kwargs)

    context = {'display':"Search",
               'name': "Search",
               'server': server,
               'in_fmt': in_fmt,
               'get_fmt': get_fmt,
               'template': 'v1api/search.html',
               }

    request_string = "?"
    for item in request.GET:
        request_string += item +"=" + request.GET[item] +"&"

    if request_string[:0] =="&":
        request_string = request_string[:-1]

    if not "patient=Patient/" in request_string:
        try:
            xwalk = Crosswalk.objects.get(user=request.user)
            patient_id = xwalk.fhir_url_id
            request_string += "&patient=Patient/"+patient_id
        except Crosswalk.DoesNotExist:
            return kickout_404("ID for this user not found:%s" % request.user)

    if settings.DEBUG:
        print("Gets:", request_string)

    try:
        r = requests.get(server+request_string)

        context = process_page(request, r, context)

        return publish_page(request, context)


    except requests.ConnectionError:
        print("Whoops - Problem connecting to FHIR Server")
        messages.error(request,
                       "FHIR Server is unreachable. "
                       "Are you on the CMS Network?")

    return render_to_response(context['template'],
                              RequestContext(request, context, ))
예제 #3
0
def ExplanationOfBenefit(request,
                         eob_id=None,
                         Access_Mode=None,
                         *args,
                         **kwargs):
    """
    Function-based interface to ExplanationOfBenefit
    :param request:
    :return:

    Use Cases:
    1. No eob_id: Do Search and apply patient=Patient/User.Crosswalk.fhir_url_id
    2. eob_id: Do Search and get eob with patient filter

    http://bluebuttonhapi-test.hhsdevcloud.us/baseDstu2/ExplanationOfBenefit
        ?_id=1286291&patient=Patient/1286160

    3. eob_id and Access_mode = OPEN



    """

    if settings.DEBUG:
        print("In apps.v1api.views.eob.ExplanationOfBenefit Function")

        print("request:", request.GET)

    process_mode = request.META['REQUEST_METHOD']

    patient_id = lookup_xwalk(request)
    # try:
    #     xwalk = Crosswalk.objects.get(user=request.user)
    # except Crosswalk.DoesNotExist:
    #     messages.error(request, "Unable to find Patient ID")
    #     return HttpResponseRedirect(reverse('api:v1:home'))
    #
    if patient_id == None:
        return HttpResponseRedirect(reverse('api:v1:home'))

    in_fmt = "json"
    get_fmt = get_format(request.GET)

    if settings.DEBUG:
        print("Request.GET :", request.GET)
        print("KWargs      :", kwargs)
        print("FHIR URL ID :", patient_id)

    # We should have the xwalk.FHIR_url_id
    # So we will construct the EOB Identifier to include

    # We will deal internally in JSON Format if caller does not choose
    # a format
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    pass_to = FhirServerUrl()
    pass_to += "/ExplanationOfBenefit/"

    key = patient_id.strip()
    patient_filter = "patient=Patient/" + key

    # pass_to += patient_filter

    skip_parm = ['_id', '_format']

    got_parms = build_params(request.GET, skip_parm)[1:]

    if got_parms:
        print("Got parms:", got_parms)
        pass_to += "?" + got_parms

    if Access_Mode == "OPEN":
        pass
    else:
        if "?" in pass_to:
            pass_to += "&" + patient_filter
        else:
            pass_to += "?" + patient_filter

    if eob_id:
        if "?" in pass_to:
            pass_to += "&"
        else:
            pass_to += "?"
        pass_to += "_id=" + eob_id

    print("Calling:", pass_to)

    # Set Context
    context = {
        'display': "EOB",
        'name': "ExplanationOfBenefit",
        'mask': True,
        'key': key,
        'eob': eob_id,
        'get_fmt': get_fmt,
        'in_fmt': in_fmt,
        'pass_to': pass_to,
        'template': 'v1api/eob.html',
    }

    if settings.DEBUG:
        print("Calling requests with pass_to:", pass_to)

    # We need to replace FHIR Server with External Server reference
    rewrite_from = settings.FHIR_SERVER_CONF['REWRITE_FROM']
    rewrite_to = settings.FHIR_SERVER_CONF['REWRITE_TO']

    try:
        r = requests.get(pass_to)

        context = process_page(request, r, context)

        return publish_page(request, context)

    except requests.ConnectionError:
        pass

    return cms_not_connected(request, 'api:v1:home')
예제 #4
0
def PatientExplanationOfBenefit(request, patient_id=None, *args, **kwargs):
    """
    Function-based interface to ExplanationOfBenefit
    :param request:
    :return:
    """

    if patient_id == None:
        patient_id = lookup_xwalk(request)

        if patient_id == None:
            err_msg = [
                'Crosswalk lookup failed: Sorry, We were unable to find',
                'your record',
            ]
            exit_message = concat_string("",
                                         msg=err_msg,
                                         delimiter=" ",
                                         last=".")
            messages.error(request, exit_message)
            return kickout_404(exit_message)

    if patient_id == "":
        err_msg = [
            'Sorry, No Patient Id provided',
        ]
        exit_message = concat_string("", msg=err_msg, delimiter=" ", last=".")
        messages.error(request, exit_message)
        return HttpResponseRedirect(reverse('api:v1:home'))

    if settings.DEBUG:
        print("In apps.v1api.views.eob.PatientExplanationOfBenefit Function")
        print("request:", request.GET)

    process_mode = request.META['REQUEST_METHOD']

    in_fmt = "json"
    get_fmt = get_format(request.GET)

    if settings.DEBUG:
        print("Request.GET :", request.GET)
        print("KWargs      :", kwargs)
        print("Patient     :", patient_id)

    # We should have the patient_id from xwalk.FHIR_url_id
    # So we will construct the EOB Identifier to include

    # We will deal internally in JSON Format if caller does not choose
    # a format
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    pass_to = FhirServerUrl()
    pass_to += "/ExplanationOfBenefit/"

    key = patient_id
    patient_filter = "?patient=Patient/" + key

    pass_to += patient_filter

    skip_parm = ['_id', '_format']

    pass_to = pass_to + "&" + build_params(request.GET, skip_parm)[1:]

    # Set Context
    context = {
        'display': "EOB",
        'name': "ExplanationOfBenefit",
        'mask': True,
        'key': key,
        'get_fmt': get_fmt,
        'in_fmt': in_fmt,
        'pass_to': pass_to,
        'template': 'v1api/eob.html',
    }

    if settings.DEBUG:
        print("Calling requests with pass_to:", pass_to)

    try:
        r = requests.get(pass_to)

        context = process_page(request, r, context)

        return publish_page(request, context)

    except requests.ConnectionError:
        pass

    return cms_not_connected(request, 'api:v1:home')
예제 #5
0
def ExplanationOfBenefit(request, eob_id=None, Access_Mode=None, *args, **kwargs):
    """
    Function-based interface to ExplanationOfBenefit
    :param request:
    :return:

    Use Cases:
    1. No eob_id: Do Search and apply patient=Patient/User.Crosswalk.fhir_url_id
    2. eob_id: Do Search and get eob with patient filter

    http://bluebuttonhapi-test.hhsdevcloud.us/baseDstu2/ExplanationOfBenefit
        ?_id=1286291&patient=Patient/1286160

    3. eob_id and Access_mode = OPEN



    """

    if settings.DEBUG:
        print("In apps.v1api.views.eob.ExplanationOfBenefit Function")

        print("request:", request.GET)

    process_mode = request.META['REQUEST_METHOD']

    patient_id = lookup_xwalk(request)
    # try:
    #     xwalk = Crosswalk.objects.get(user=request.user)
    # except Crosswalk.DoesNotExist:
    #     messages.error(request, "Unable to find Patient ID")
    #     return HttpResponseRedirect(reverse('api:v1:home'))
    #
    if patient_id == None:
        return HttpResponseRedirect(reverse('api:v1:home'))

    in_fmt = "json"
    get_fmt = get_format(request.GET)

    if settings.DEBUG:
        print("Request.GET :", request.GET)
        print("KWargs      :", kwargs)
        print("FHIR URL ID :", patient_id)

    # We should have the xwalk.FHIR_url_id
    # So we will construct the EOB Identifier to include

    # We will deal internally in JSON Format if caller does not choose
    # a format
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    pass_to = FhirServerUrl()
    pass_to += "/ExplanationOfBenefit/"

    key = patient_id.strip()
    patient_filter= "patient=Patient/" + key

    # pass_to += patient_filter

    skip_parm = ['_id', '_format']

    got_parms = build_params(request.GET, skip_parm)[1:]

    if got_parms:
        print("Got parms:", got_parms)
        pass_to += "?" + got_parms

    if Access_Mode == "OPEN":
        pass
    else:
        if "?" in pass_to:
            pass_to += "&" + patient_filter
        else:
            pass_to += "?" + patient_filter

    if eob_id:
        if "?" in pass_to:
            pass_to += "&"
        else:
            pass_to += "?"
        pass_to += "_id=" + eob_id

    print("Calling:", pass_to)

    # Set Context
    context = {'display':"EOB",
               'name': "ExplanationOfBenefit",
               'mask': True,
               'key': key,
               'eob': eob_id,
               'get_fmt': get_fmt,
               'in_fmt': in_fmt,
               'pass_to': pass_to,
               'template': 'v1api/eob.html',
               }

    if settings.DEBUG:
        print("Calling requests with pass_to:", pass_to)

    # We need to replace FHIR Server with External Server reference
    rewrite_from = settings.FHIR_SERVER_CONF['REWRITE_FROM']
    rewrite_to = settings.FHIR_SERVER_CONF['REWRITE_TO']

    try:
        r = requests.get(pass_to)

        context = process_page(request, r, context)

        return publish_page(request, context)

    except requests.ConnectionError:
        pass

    return cms_not_connected(request, 'api:v1:home')
예제 #6
0
def PatientExplanationOfBenefit(request, patient_id=None, *args, **kwargs):
    """
    Function-based interface to ExplanationOfBenefit
    :param request:
    :return:
    """

    if patient_id == None:
        patient_id = lookup_xwalk(request)

        if patient_id == None:
            err_msg = ['Crosswalk lookup failed: Sorry, We were unable to find',
                       'your record', ]
            exit_message = concat_string("",
                                         msg=err_msg,
                                         delimiter=" ",
                                         last=".")
            messages.error(request, exit_message)
            return kickout_404(exit_message)

    if patient_id == "":
        err_msg = ['Sorry, No Patient Id provided', ]
        exit_message = concat_string("",
                                     msg=err_msg,
                                     delimiter=" ",
                                     last=".")
        messages.error(request, exit_message)
        return HttpResponseRedirect(reverse('api:v1:home'))

    if settings.DEBUG:
        print("In apps.v1api.views.eob.PatientExplanationOfBenefit Function")
        print("request:", request.GET)

    process_mode = request.META['REQUEST_METHOD']

    in_fmt = "json"
    get_fmt = get_format(request.GET)


    if settings.DEBUG:
        print("Request.GET :", request.GET)
        print("KWargs      :", kwargs)
        print("Patient     :", patient_id)

    # We should have the patient_id from xwalk.FHIR_url_id
    # So we will construct the EOB Identifier to include

    # We will deal internally in JSON Format if caller does not choose
    # a format
    in_fmt = "json"
    get_fmt = get_format(request.GET)

    pass_to = FhirServerUrl()
    pass_to += "/ExplanationOfBenefit/"

    key = patient_id
    patient_filter= "?patient=Patient/" + key

    pass_to += patient_filter

    skip_parm = ['_id', '_format']

    pass_to = pass_to + "&" + build_params(request.GET, skip_parm)[1:]

    # Set Context
    context = {'display':"EOB",
               'name': "ExplanationOfBenefit",
               'mask': True,
               'key': key,
               'get_fmt': get_fmt,
               'in_fmt': in_fmt,
               'pass_to': pass_to,
               'template': 'v1api/eob.html',
               }

    if settings.DEBUG:
        print("Calling requests with pass_to:", pass_to)

    try:
        r = requests.get(pass_to)

        context = process_page(request, r, context)

        return publish_page(request, context)

    except requests.ConnectionError:
        pass

    return cms_not_connected(request, 'api:v1:home')