def test_crosswalk_fhir_id(self): """ Get the Crosswalk FHIR_Id """ u = User.objects.create_user( username="******", first_name="Billybob", last_name="Button", email="*****@*****.**", password="******", ) UserProfile.objects.create(user=u, user_type="DEV", create_applications=True) x = Crosswalk() x.user = u x.fhir_id = "Patient/23456" x.save() result = crosswalk_patient_id(u) self.assertEqual(x.fhir_id, result) # Test the dt_reference for Patient result = dt_patient_reference(u) expect = {"reference": x.fhir_id} self.assertEqual(result, expect)
def test_crosswalk_fhir_id(self): """ Get the Crosswalk FHIR_Id """ u = User.objects.create_user( username="******", first_name="Billybob", last_name="Button", email='*****@*****.**', password="******", ) UserProfile.objects.create(user=u, user_type="DEV", create_applications=True) x = Crosswalk() x.user = u x.fhir_id = "Patient/23456" x.save() result = crosswalk_patient_id(u) self.assertEqual(x.fhir_id, result) # Test the dt_reference for Patient result = dt_patient_reference(u) expect = {'reference': x.fhir_id} self.assertEqual(result, expect)
def setUp(self): # Setup the RequestFactory # I could probably update this to use a Mock() self.factory = RequestFactory() self.user = User.objects.create_user(username="******", email="fred4@...", password="******") xwalk = Crosswalk() xwalk.user = self.user xwalk.fhir_id = "Patient/12345" xwalk.save()
def setUp(self): # Setup the RequestFactory # I could probably update this to use a Mock() self.factory = RequestFactory() self.user = User.objects.create_user(username='******', email='fred4@...', password='******') xwalk = Crosswalk() xwalk.user = self.user xwalk.fhir_id = "Patient/12345" xwalk.save()
def update_crosswalk(user, server, id): """ Look up Crosswalk for user and add patient_id """ try: xwalk = Crosswalk.objects.get(user=user) except Crosswalk.DoesNotExist: xwalk = Crosswalk() xwalk.user = user if xwalk.fhir_id: return xwalk else: xwalk.fhir_id = id xwalk.fhir_source = server xwalk.save() return xwalk
def test_user_logged_in_crosswalk_fhir_id(self): """ check_crosswalk - User Logged in. Entry in xwalk with FHIR_ID """ request = self.factory.get('/create_test_account/bb_upload/') request.user = self.user request._messages = FakeMessages() # setattr(request, 'session', 'session') # request.messages = self.messages # setattr(request, '_messages', messages) xwalk = Crosswalk() xwalk.user = self.user xwalk.fhir_id = "12345678" xwalk.save() expected = 'Account is already linked to a FHIR resource.' result = check_crosswalk(request) result = result # print("Crosswalk found " # "with FHIR ID Result:%s" % request._messages.pop) self.assertEqual(request._messages.pop, expected)
def convert_bb(request): """ Read bb_text from CrossWalk Convert to JSON (bb_to_json) Analyze JSON Get Claims Search for Claims Check for Unique Patient Get Unique Patient Store ID in Crosswalk """ try: xwalk = Crosswalk.objects.get(user=request.user) except Crosswalk.DoesNotExist: xwalk = Crosswalk() xwalk.user = request.user # We may want to add the default FHIR Server to the crosswalk entry # before we save. # xwalk.fhir_source = xwalk.save() # Do we have Blue Button text to work with? bb_text = check_for_bb_text(xwalk.user) if not bb_text: return HttpResponseRedirect(reverse('home')) # Convert from text to JSON bb_result = bb_to_json(request, bb_text.bb_content) bb_json = bb_result['mmg_bbjson'] # print("JSON:", bb_result['mmg_bbjson']) # Extract Claims from bb_json bb_claims = getbbclm(request, bb_result['mmg_bbjson']) # print("\nClaims:", bb_claims) fhir_claims = eval_claims(request, bb_claims) # Take bb_claims and get a unique list of patients # Hopefully we only have ONE bb_patient_ids = unique_keys(fhir_claims, key="patient") # print("Patient IDs:", bb_patient_ids) if len(bb_patient_ids) is 0: # We have a problem... # Too many or Too Few Patient IDs returned from Claims messages.error(request, "Unable to find a Patient Match") elif len(bb_patient_ids) > 1: messages.error(request, "Unable to match to a unique Patient ID") else: messages.info(request, "We found a match %s" % bb_patient_ids[0]) if not xwalk.fhir_id: # We need the Id from Patient ID # It should be in format Patient/{ID} fhir_id = bb_patient_ids[0].split('/') if len(fhir_id) > 1: fhir_id_num = fhir_id[-1] xwalk.fhir_id = fhir_id_num mc_prof = {} if bb_json['result'] == "OK": mc_prof['bb_json'] = bb_json['mmg_bbjson'] mc_prof['email'] = get_bbemail(request, bb_json) mc_prof['profile'] = get_bbprof(request, bb_json) # Extract claims from Blue Button JSON mc_prof['claims'] = getbbclm(request, bb_json) return render(request, 'eimm/bluebutton_analytics.html', {'content': bb_json, 'profile': mc_prof, 'profilep': pretty_json(mc_prof['profile']), 'claimsp': pretty_json(mc_prof['claims']) }) return HttpResponseRedirect(reverse('home'))
def convert_bb(request): """ Read bb_text from CrossWalk Convert to JSON (bb_to_json) Analyze JSON Get Claims Search for Claims Check for Unique Patient Get Unique Patient Store ID in Crosswalk """ try: xwalk = Crosswalk.objects.get(user=request.user) except Crosswalk.DoesNotExist: xwalk = Crosswalk() xwalk.user = request.user # We may want to add the default FHIR Server to the crosswalk entry # before we save. # xwalk.fhir_source = xwalk.save() # Do we have Blue Button text to work with? bb_text = check_for_bb_text(xwalk.user) if not bb_text: return HttpResponseRedirect(reverse('home')) # Convert from text to JSON bb_result = bb_to_json(request, bb_text.bb_content) bb_json = bb_result['mmg_bbjson'] # print("JSON:", bb_result['mmg_bbjson']) # Extract Claims from bb_json bb_claims = getbbclm(request, bb_result['mmg_bbjson']) # print("\nClaims:", bb_claims) fhir_claims = eval_claims(request, bb_claims) # Take bb_claims and get a unique list of patients # Hopefully we only have ONE bb_patient_ids = unique_keys(fhir_claims, key="patient") # print("Patient IDs:", bb_patient_ids) if len(bb_patient_ids) is 0: # We have a problem... # Too many or Too Few Patient IDs returned from Claims messages.error(request, "Unable to find a Patient Match") elif len(bb_patient_ids) > 1: messages.error(request, "Unable to match to a unique Patient ID") else: messages.info(request, "We found a match %s" % bb_patient_ids[0]) if not xwalk.fhir_id: # We need the Id from Patient ID # It should be in format Patient/{ID} fhir_id = bb_patient_ids[0].split('/') if len(fhir_id) > 1: fhir_id_num = fhir_id[-1] xwalk.fhir_id = fhir_id_num mc_prof = {} if bb_json['result'] == "OK": mc_prof['bb_json'] = bb_json['mmg_bbjson'] mc_prof['email'] = get_bbemail(request, bb_json) mc_prof['profile'] = get_bbprof(request, bb_json) # Extract claims from Blue Button JSON mc_prof['claims'] = getbbclm(request, bb_json) return render( request, 'eimm/bluebutton_analytics.html', { 'content': bb_json, 'profile': mc_prof, 'profilep': pretty_json(mc_prof['profile']), 'claimsp': pretty_json(mc_prof['claims']) }) return HttpResponseRedirect(reverse('home'))