def post(self,request, patient_id, *args, **kwargs): # This is a patient profile POST # # use request.user to lookup a crosswalk # get the FHIR Patient ID # Call the FHIR Patient Profile # Return the result print("in Patients.post with", patient_id) if settings.DEBUG: print("in Patients.post with", patient_id) xwalk_id = lookup_xwalk(request, ) if settings.DEBUG: print("crosswalk:", xwalk_id) template_name = 'v1api/patient.html' form = self.form_class(request.POST) if form.is_valid(): # <process form cleaned data> return HttpResponseRedirect('/success/') return render(request, self.template_name, {'form': form})
def get(self, request, eob_id, *args, **kwargs): # This is an ExplanationOfBenefit profile GET # # use request.user to lookup a crosswalk # get the FHIR Patient ID # Call the FHIR Patient Profile # Return the result # EOB will need to look up request.user and apply a filter on the EOB # The filter in search Parameters will be the GUID # We need to load the GUID when we are loading EOBs and # Patient Records. # http://ec2-52-4-198-86.compute-1.amazonaws.com:8081/baseDstu2/ # ExplanationOfBenefit/?patient=Patient/131052&_format=json if settings.DEBUG: print("in EOB.get with", eob_id) xwalk_id = lookup_xwalk(request, ) if settings.DEBUG: print("crosswalk:", xwalk_id) if xwalk_id == None: return HttpResponseRedirect(reverse_lazy('api:v1:home')) if settings.DEBUG: print("now we need to evaluate the parameters and arguments" " to work with ", xwalk_id, "and ", request.user) print("GET Parameters:", request.GET, ":") if patient_id == xwalk_id: key = eob_id else: key = xwalk_id.strip() in_fmt = "json" Txn = {'name': "ExplanationOfBenefit", 'display': 'ExplanationOfBenefit', 'mask': True, 'server': settings.FHIR_SERVER, 'locn': "/baseDstu2/ExplanationOfBenefit/", 'template': 'v1api/eob.html', 'in_fmt': in_fmt, } skip_parm = ['_id'] pass_params = build_params(request.GET, skip_parm) if settings.DEBUG: print("Pass_params=", pass_params) pass_to = Txn['server'] + Txn['locn'] + key + "/" print("Here is the URL to send, %s now get parameters" % pass_to) if pass_params != "": pass_to = pass_to + pass_params try: r = requests.get(pass_to) except requests.ConnectionError: if settings.DEBUG: print("Problem connecting to FHIR Server") messages.error(request, "FHIR Server is unreachable." ) return HttpResponseRedirect(reverse_lazy('api:v1:home')) text_out = "" if '_format=xml' in pass_to: text_out= minidom.parseString(r.text).toprettyxml() else: text_out = r.json() return HttpResponse('This is the EOB Pass Thru %s using %s ' 'and with response of %s' % (xwalk_id, pass_to, text_out))
def get(self, request, patient_id, *args, **kwargs): # This is a patient profile GET # # use request.user to lookup a crosswalk # get the FHIR Patient ID # Call the FHIR Patient Profile # Return the result print("in the get!") if settings.DEBUG: print("in Patients.get with", patient_id) xwalk_id = lookup_xwalk(request, ) if settings.DEBUG: print("crosswalk:", xwalk_id) if xwalk_id == None: return HttpResponseRedirect(reverse_lazy('api:v1:home')) if settings.DEBUG: print("now we need to evaluate the parameters and arguments" " to work with ", xwalk_id, "and ", request.user) print("GET Parameters:", request.GET, ":") if patient_id == xwalk_id: key = patient_id else: key = xwalk_id.strip() in_fmt = "json" Txn = {'name': "Patient", 'display': 'Patient', 'mask': True, 'server': settings.FHIR_SERVER, 'locn': "/baseDstu2/Patient/", 'template': 'v1api/patient.html', 'in_fmt': in_fmt, } skip_parm = ['_id', 'access_token', 'client_id', 'response_type', 'state'] # access_token can be passed in as a part of OAuth protected request. # as can: state=random_state_string&response_type=code&client_id=ABCDEF # Remove it before passing url through to FHIR Server pass_params = build_params(request.GET, skip_parm) pass_to = Txn['server'] + Txn['locn'] + key + "/" print("Here is the URL to send, %s now get parameters" % pass_to) if pass_params != "": pass_to = pass_to + pass_params try: r = requests.get(pass_to) except requests.ConnectionError: if settings.DEBUG: print("Problem connecting to FHIR Server") messages.error(request, "FHIR Server is unreachable." ) return HttpResponseRedirect(reverse_lazy('api:v1:home')) text_out = "" if '_format=xml' in pass_to: text_out= minidom.parseString(r.text).toprettyxml() else: text_out = r.json() if settings.DEBUG: print("What we got back was:", text_out) return HttpResponse('This is the Patient Pass Thru %s using %s ' 'and with response of %s ' % (xwalk_id, pass_to, text_out ))
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')
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')
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')
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')