def test_practice_providers(self): request = generateHttpRequest() #provider has no current practice result = practice_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) organization_type = create_org_type() practice = ct_practice('name', organization_type) request.provider.current_practice = practice #provider has current practice but find 0 result = practice_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #provider has current practice and find 1 request.provider.practices.add(practice) request.provider.clinical_clerk = True request.provider.save() phy = Physician(user=request.provider) phy.save() result = practice_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def testSetSubProviderResultList(self): provider = create_user(get_random_username(), "provider", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider.save() nppa = NP_PA(user=provider) nppa.save() provider1 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider1.save() phy = Physician(user=provider1) phy.specialty = 'AC' phy.save() self.assertEqual(0, len(setSubProviderResultList([], phy)), 'test failed for setSubProviderResultList') self.assertEqual(1, len(setSubProviderResultList([nppa], phy)), 'test failed for setSubProviderResultList') self.assertEqual(2, len(setSubProviderResultList([nppa, phy])), 'test failed for setSubProviderResultList')
def test_community_providers(self): request = generateHttpRequest() #find 0 provider result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #find 1 provider phy = Physician(user=request.provider) phy.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1) organization_type = create_org_type() practice = ct_practice('name', organization_type) assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def test_community_providers(self): request = generateHttpRequest() #find 0 provider result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #find 1 provider phy = Physician(user=request.provider) phy.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1) organization_type = create_org_type() practice = ct_practice('name', organization_type) assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def member_provider_create(request): context = get_context_for_organization(request) current_practice = request.org if request.method == 'POST': provider_form = CreateProviderForm(data=request.POST, current_practice=current_practice) if provider_form.is_valid(): provider = provider_form.save(commit=False) provider.lat = provider_form.cleaned_data['lat'] provider.longit = provider_form.cleaned_data['longit'] provider.address1 = provider_form.cleaned_data['address1'] provider.address2 = provider_form.cleaned_data['address2'] provider.city = provider_form.cleaned_data['city'] provider.state = provider_form.cleaned_data['state'] provider.zip = provider_form.cleaned_data['zip'] provider.current_practice = get_practice_org(current_practice) provider.is_active = 0 provider.office_lat = 0.0 provider.office_longit = 0.0 provider.save() provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() user_type = int(provider_form.cleaned_data['user_type']) if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() # TESTING_KMS_INTEGRATION create_default_keys(provider.user) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() sendAccountActiveCode(request, user_type, current_practice, request.session["MHL_Users"]["MHLUser"]) else: context['user_form'] = provider_form return render_to_response('MHLOrganization/Member/member_provider_create.html', context) provider_form = CreateProviderForm(current_practice=current_practice) context['user_form'] = provider_form return render_to_response('MHLOrganization/Member/member_provider_create.html', context)
def test_get_all_providers_and_staffs(self): request = generateHttpRequest() #get method request.method = 'GET' result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #find 0 any type user result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 0) #has 1 nppa user = create_user('np1', 'abc', '', 'demo') provider = Provider(user=user, username='******', first_name='abc', last_name='', office_lat=0.0, office_longit=0.0) provider.save() nppa = NP_PA(user=provider) nppa.save() request.POST['name'] = unicode('abc') result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 1) self.assertEqual(msg['users'][0]['first_name'], 'abc') phy = Physician(user=provider) phy.save() result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc') #staff organization_type = create_org_type() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', mdcom_phone='8005550085', organization_type=organization_type) practice.save() staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() staff.practices.add(practice) request.POST['name'] = unicode(request.user.first_name) result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc')
def testProfile(self): phys = Physician(user = self.user) phys.save() data = { 'username':get_random_username(), 'first_name':'c', 'last_name':'tian', 'mobile_phone':9001111111, 'gender':'M', 'old_email':'*****@*****.**', 'email':'*****@*****.**', 'lat':0.0, 'longit':0.0, 'address1':'address1', 'address2':'address2', 'city':'Chicago', 'state':'IL', 'zip':60601, 'user_type':1, 'office_lat':41.885805, 'office_longit':-87.6229106, } response = self.client.post(reverse\ ('MHLogin.api.v1.views_account.profile'), data,**self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2) site = Site( name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite' ) site.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() self.user.current_site = site self.user.current_practice = practice self.user.save() response = self.client.get(reverse\ ('MHLogin.api.v1.views_account.profile'), data,**self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2)
def test_user_search(self): request = generateHttpRequest() #get method request.method = 'GET' result = user_search(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') request.method = 'POST' #invalid form data request.POST['name'] = 'abc' request.POST['limit'] = 'limit' result = user_search(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid form data request.POST['limit'] = 10 #find 0 provider result = user_search(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['count'], 0) #find 1 provider mhluser = MHLUser.objects.get(id=request.user.id) mhluser.first_name = 'abc' mhluser.save() result = user_search(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['count'], 1) #1 physician find phy = Physician(user=request.provider) phy.save() result = user_search(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['count'], 1) #1 medical student find request.provider.clinical_clerk = True request.provider.save() result = user_search(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['count'], 1)
def testProfile(self): phys = Physician(user=self.user) phys.save() data = { 'username': get_random_username(), 'first_name': 'c', 'last_name': 'tian', 'mobile_phone': 9001111111, 'gender': 'M', 'old_email': '*****@*****.**', 'email': '*****@*****.**', 'lat': 0.0, 'longit': 0.0, 'address1': 'address1', 'address2': 'address2', 'city': 'Chicago', 'state': 'IL', 'zip': 60601, 'user_type': 1, 'office_lat': 41.885805, 'office_longit': -87.6229106, } response = self.client.post(reverse\ ('MHLogin.api.v1.views_account.profile'), data,**self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2) site = Site(name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite') site.save() practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() self.user.current_site = site self.user.current_practice = practice self.user.save() response = self.client.get(reverse\ ('MHLogin.api.v1.views_account.profile'), data,**self.extra) self.assertEqual(response.status_code, 200, response.status_code) msg = json.loads(response.content) self.assertEqual(len(msg), 2)
def createNewProvider(provider_form, current_user): if isinstance(provider_form, CreateProviderForm): current_practice = current_user.current_practice provider = provider_form.save(commit=False) provider.lat = provider_form.cleaned_data['lat'] provider.longit = provider_form.cleaned_data['longit'] provider.address1 = provider_form.cleaned_data['address1'] provider.address2 = provider_form.cleaned_data['address2'] provider.city = provider_form.cleaned_data['city'] provider.state = provider_form.cleaned_data['state'] provider.zip = provider_form.cleaned_data['zip'] provider.current_practice = get_practice_org(current_practice) provider.is_active = 0 provider.office_lat = 0.0 if not provider.office_lat else provider.office_lat provider.office_longit = 0.0 if not provider.office_longit else provider.office_longit provider.save() if current_practice: provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() user_type = int(provider_form.cleaned_data['user_type']) if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() # TESTING_KMS_INTEGRATION create_default_keys(provider.user) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() sendAccountActiveCode(provider_form, user_type, current_user) else: raise TypeError
def test_site_students(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() #provider not staff assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'DM020') #get back provider and has no current site assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #provider has current site site = Site(name='test site', address1='test address', lat=0.0, longit=0.1) site.save() request.provider.current_site = site request.provider.save() result = site_students(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['data']['users']), 0) #Physician has current site request.provider.sites.add(site) request.provider.clinical_clerk = True request.provider.save() phy = Physician(user=request.provider) phy.save() result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def test_user_info(self): request = generateHttpRequest() #not find any provider match result = user_info(request, -123) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'PF001') #provider call this method result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #physician call this method phy = Physician(user=request.provider) phy.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #staff call this method assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) staff = OfficeStaff(user=request.user) staff.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #staff with current practice organization_type = create_org_type() practice = ct_practice('name', organization_type) staff.current_practice = practice staff.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #manager call this method manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200)
def test_site_students(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() #provider not staff assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'DM020') #get back provider and has no current site assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #provider has current site site = Site(name='test site', address1='test address', lat=0.0, longit=0.1) site.save() request.provider.current_site = site request.provider.save() result = site_students(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['data']['users']), 0) #Physician has current site request.provider.sites.add(site) request.provider.clinical_clerk = True request.provider.save() phy = Physician(user=request.provider) phy.save() result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def test_user_info(self): request = generateHttpRequest() #not find any provider match result = user_info(request, -123) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'PF001') #provider call this method result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #physician call this method phy = Physician(user=request.provider) phy.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #staff call this method assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) staff = OfficeStaff(user=request.user) staff.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #staff with current practice organization_type = create_org_type() practice = ct_practice('name', organization_type) staff.current_practice = practice staff.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200) #manager call this method manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() result = user_info(request, request.user.id) self.assertEqual(result.status_code, 200)
def generate_users(request): if (not settings.DEBUG): return HttpResponseRedirect(reverse('MHLogin.Administration.views.home')) context = get_context(request) if (request.method == 'GET'): context["form"] = GenerateUsersForm() return render_to_response('qa_tools/genereate_users.html', context) else: form = GenerateUsersForm(request.POST) if form.is_valid(): current_practice = form.cleaned_data["practices"] user_type = int(form.cleaned_data["user_types"]) number = int(form.cleaned_data["number"]) user_name_start = form.cleaned_data["user_name_start"] generate_user = None for i in range(number): username = "******" % (user_name_start, i) first_name = "%s_f_%d" % (user_name_start, i) last_name = "%s_f_%d" % (user_name_start, i) email = "*****@*****.**" % (username) password = "******" if USER_TYPE_DOCTOR == user_type \ or USER_TYPE_NPPA == user_type \ or USER_TYPE_MEDICAL_STUDENT == user_type: provider = Provider( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, lat=current_practice.practice_lat, longit=current_practice.practice_longit, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, current_practice=current_practice, is_active=1, office_lat=current_practice.practice_lat, office_longit=current_practice.practice_longit, mdcom_phone="8004664411" ) provider.save() provider.set_password(password) provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() create_default_keys(provider.user, password) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() generate_user = provider elif USER_TYPE_OFFICE_MANAGER == user_type \ or USER_TYPE_NURSE == user_type \ or USER_TYPE_DIETICIAN == user_type: mhluser = MHLUser( username = username, first_name = first_name, last_name = last_name, email = email, email_confirmed = True, is_active = 1, address1 = current_practice.practice_address1, address2 = current_practice.practice_address2, city = current_practice.practice_city, state = current_practice.practice_state, zip = current_practice.practice_zip, lat = current_practice.practice_lat, longit = current_practice.practice_longit ) mhluser.save() mhluser.set_password(password) staff = OfficeStaff( user=mhluser, current_practice=current_practice ) staff.user = mhluser staff.current_practice = current_practice staff.save() staff.practices.add(current_practice) staff.save() if USER_TYPE_OFFICE_MANAGER == user_type: manager = Office_Manager(user=staff, practice=current_practice) manager.save() if USER_TYPE_NURSE == user_type: nurse = Nurse(user=staff) nurse.save() elif USER_TYPE_DIETICIAN == user_type: dietician = Dietician(user=staff) dietician.save() generate_user = mhluser log_str = 'Generate user %d: for %s' % (i, str(generate_user)) logger.debug(log_str) print log_str return render_to_response('qa_tools/genereate_users_success.html', context) else: context["form"] = form return render_to_response('qa_tools/genereate_users.html', context)
def newProvider(request): context = get_context(request) office_staff = request.session['MHL_Users']['OfficeStaff'] current_practice = office_staff.current_practice request.session['SELECTED_ORG_ID'] = current_practice.id showDialog = 0 username = "" if request.method == 'POST': provider_form = CreateProviderForm(data=request.POST, current_practice=current_practice) if provider_form.is_valid(): # todo, using function createNewProvider in /mdcom/MHLogin/MHLUsers/utils_users.py username = provider_form.cleaned_data['username'] provider = provider_form.save(commit=False) provider.lat = provider_form.cleaned_data['lat'] provider.longit = provider_form.cleaned_data['longit'] provider.address1 = provider_form.cleaned_data['address1'] provider.address2 = provider_form.cleaned_data['address2'] provider.city = provider_form.cleaned_data['city'] provider.state = provider_form.cleaned_data['state'] provider.zip = provider_form.cleaned_data['zip'] provider.current_practice = get_practice_org(current_practice) provider.is_active = 0 provider.save() provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() user_type = provider_form.cleaned_data['user_type'] if '1' == user_type: #Physician ph = Physician(user=provider) ph.save() elif '2' == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif '10' == user_type: ph = Physician(user=provider) ph.save() # TESTING_KMS_INTEGRATION create_default_keys(provider.user) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() sendAccountActiveCode(request, user_type) showDialog = 1 else: context['showDialog'] = showDialog context['user_form'] = provider_form return render_to_response('Staff/newProvider.html', context) context['username'] = username context['showDialog'] = showDialog context['user_form'] = CreateProviderForm(current_practice=current_practice) return render_to_response('Staff/newProvider.html', context)
def testGetProviderList(self, mockgeo): practice1 = PracticeLocation( practice_name='USA practice', practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice1.save() practice2 = PracticeLocation(practice_name='China practice', practice_address1='jiangsu', practice_address2='beijing', practice_city='suzhou', practice_state='JS', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice2.save() site1 = Site(name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite') site1.save() site2 = Site(name='doctorcom', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite') site2.save() provider1 = create_user("prov1", "provider_first", "provider_last", "demo", "555 Bryant St.", "Palo Alto", "CA", "94306", uklass=Provider) provider1.address2 = 'suzhou china' provider1.user.save() provider1.sites.add(site1) provider1.sites.add(site2) provider1.current_site = site1 provider1.practices.add(practice1) provider1.practices.add(practice2) provider1.current_practice = practice1 provider1.save() provider2 = create_user("prov2", "provider_first1", "provider_last1", "demo", "suzhou china", "suzhou", "AB", "94307", uklass=Provider) provider2.sites.add(site2) provider2.current_site = site2 provider2.practices.add(practice2) provider2.current_practice = practice2 provider2.save() condition_dicts = [ { 'name': u'provider', 'result': 2, 'result_failed': 'name failed' }, { 'name': u'last1 first1', 'result': 1, 'result_failed': 'name failed' }, { 'name': u'abc', 'result': 0, 'result_failed': 'name failed' }, { 'address': u'Bryant', 'result': 1, 'result_failed': 'address failed' }, { 'address': u'suzhou china', 'result': 2, 'result_failed': 'address failed' }, { 'address': u'abc', 'result': 0, 'result_failed': 'address failed' }, { 'city': u'Palo', 'result': 1, 'result_failed': 'city failed' }, { 'city': u'suzhou', 'result': 1, 'result_failed': 'city failed' }, { 'city': u'abc', 'result': 0, 'result_failed': 'city failed' }, { 'state': u'CA', 'result': 1, 'result_failed': 'state failed' }, { 'state': u'AB', 'result': 1, 'result_failed': 'state failed' }, { 'state': u'abc', 'result': 0, 'result_failed': 'state failed' }, { 'zip': provider1.zip, 'result': 1, 'result_failed': 'zip failed1' }, { 'zip': provider2.zip, 'result': 1, 'result_failed': 'zip failed2' }, { 'zip': provider2.zip, 'distance': 5000, 'result': 1, 'result_failed': 'zip failed3' }, { 'zip': u'43523', 'result': 0, 'result_failed': 'zip failed' }, { 'current_hospital': u'doctorcom', 'result': 1, 'result_failed': 'current_hospital failed' }, { 'current_hospital': u'mysite', 'result': 1, 'result_failed': 'current_hospital failed' }, { 'current_hospital': u'22222', 'result': 0, 'result_failed': 'current_hospital failed' }, { 'hospital': u'mysite', 'result': 1, 'result_failed': 'hospital failed' }, { 'hospital': u'doctorcom', 'result': 2, 'result_failed': 'hospital failed' }, { 'hospital': u'abc', 'result': 0, 'result_failed': 'hospital failed' }, { 'current_practice': u'USA practice', 'result': 1, 'result_failed': 'current_practice failed' }, { 'current_practice': u'China practice', 'result': 1, 'result_failed': 'current_practice failed' }, { 'current_practice': u'abc', 'result': 0, 'result_failed': 'current_practice failed' }, { 'practice': u'USA practice', 'result': 1, 'result_failed': 'practice failed' }, { 'practice': u'China practice', 'result': 2, 'result_failed': 'practice failed' }, { 'practice': u'abc', 'result': 0, 'result_failed': 'practice failed' }, { 'limit': 0, 'result': 2, 'result_total': 2, 'result_failed': 'limit failed' }, { 'limit': 1, 'result': 1, 'result_total': 2, 'result_failed': 'limit failed' }, { 'limit': 2, 'result': 2, 'result_total': 2, 'result_failed': 'limit failed' }, { 'name': u'provider', 'address': u'suzhou china', 'city': u'suzhou', 'state': u'AB', 'current_hospital': u'doctorcom', 'hospital': u'doctorcom', 'current_practice': u'China practice', 'limit': 1, 'result': 1, 'result_total': 1, 'result_failed': 'all failed' }, { 'name': u'abc', 'address': u'suzhou china', 'city': u'suzhou', 'state': u'AB', 'zip': provider2.zip, 'current_hospital': u'doctorcom', 'hospital': u'doctorcom', 'current_practice': u'China practice', 'limit': 1, 'result': 0, 'result_total': 0, 'result_failed': 'all failed' }, ] with mock.patch('MHLogin.api.v1.utils_users.geocode2', new_callable=lambda: UtilsUsersTest.mock_geocode): for d in condition_dicts: result = getProviderList(d) if 'result_total' not in d: d['result_total'] = d['result'] self.assertEqual(d['result_total'], result['total_count'], d['result_failed']) self.assertEqual(d['result'], len(result['results']), d['result_failed']) phy2 = Physician(user=provider1) phy2.specialty = 'AC' phy2.save() nppa = NP_PA(user=provider2) nppa.save() condition_dicts = [ { 'specialty': u'AC', 'result': 1, 'result_failed': 'specialty failed' }, { 'specialty': u'NP/PA/Midwife', 'result': 1, 'result_failed': 'specialty failed' }, { 'specialty': u'abc', 'result': 2, 'result_failed': 'specialty failed' }, ] for d in condition_dicts: result = getProviderList(d) if 'result_total' not in d: d['result_total'] = d['result'] self.assertEqual(d['result_total'], result['total_count'], d['result_failed']) self.assertEqual(d['result'], len(result['results']), d['result_failed'])
def testSetProviderResultList(self): provider = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider.save() nppa = NP_PA(user=provider) nppa.save() provider1 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider1.save() phy = Physician(user=provider1) phy.specialty = 'AC' phy.save() practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() provider2 = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider2.practices.add(practice) provider2.current_practice = practice provider2.save() nppa2 = NP_PA(user=provider2) nppa2.save() provider3 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider3.practices.add(practice) provider3.current_practice = practice provider3.save() phy2 = Physician(user=provider3) phy2.specialty = 'AC' phy2.save() site = Site(name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite') site.save() provider4 = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider4.sites.add(site) provider4.current_site = site provider4.save() nppa3 = NP_PA(user=provider4) nppa3.save() provider5 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider5.sites.add(site) provider5.current_site = site provider5.save() phy3 = Physician(user=provider5) phy3.specialty = 'AC' phy3.save() self.assertEqual(0, len(setProviderResultList([])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa.user], phy.user)), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa2.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy2.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa3.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy3.user])), 'test failed for setProviderResultList') self.assertEqual( 6, len( setProviderResultList([ nppa.user, phy.user, nppa2.user, phy2.user, nppa3.user, phy3.user ])), 'test failed for setProviderResultList')
def testGetUserInfo(self): mhlu = create_user(get_random_username(), "mhluser", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "") mhlu.mdcom_phone = '9002000001' mhlu.save() mhlu_id = mhlu.id return_data1 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/generic_128.png', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': mhlu_id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'mhluser', 'office_state': u'CA', 'office_zip': u'', 'staff_type': '' } self.assertEqual(Http404, getUserInfo(mhlu_id + 1, None), 'test failed for getUserInfo') self.assertEqual(return_data1, getUserInfo(mhlu_id), 'test failed for getUserInfo mhluser') # create provider for test provider = create_user(get_random_username(), "provider", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider.mdcom_phone = '9002000002' provider.save() return_data2 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/avatar2.png', 'specialty': 'NP/PA/Midwife', 'mdcom_phone': u'9002000002', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': provider.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'provider', 'office_state': u'CA', 'office_zip': u'', 'staff_type': '' } self.assertEqual(return_data2, getUserInfo(provider.user.id), 'test failed for getUserInfo provider') # create physician provider1 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider1.mdcom_phone = '9002000002' provider1.save() phy = Physician(user=provider1) phy.specialty = 'AC' phy.save() return_data3 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/avatar2.png', 'specialty': u'Acupuncture', 'mdcom_phone': u'9002000002', 'office_city': u'Palo Alto', 'accepting_patients': True, 'id': phy.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'physician', 'office_state': u'CA', 'office_zip': u'', 'staff_type': '' } self.assertEqual(return_data3, getUserInfo(phy.user.user.id), 'test failed for getUserInfo physician') # create office staff staff = create_office_staff(get_random_username(), "staff", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) return_data4 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/staff_icon.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': staff.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'staff', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Staff' } self.assertEqual(return_data4, getUserInfo(staff.user.id), 'test failed for getUserInfo staff') # create nurse staff2 = create_office_staff(get_random_username(), "nurse", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) nurse = Nurse(user=staff2) nurse.save() return_data5 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/nurse.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': nurse.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'nurse', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Staff' } self.assertEqual(return_data5, getUserInfo(nurse.user.user.id), 'test failed for getUserInfo nurse') # create office staff staff3 = create_office_staff(get_random_username(), "maneger", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) mgr = Office_Manager(user=staff3) practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() mgr.manager_role = 1 mgr.practice = practice mgr.save() return_data5 = { 'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/staff_icon.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': mgr.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'maneger', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Manager' } self.assertEqual(return_data5, getUserInfo(mgr.user.user.id), 'test failed for getUserInfo maneger')
def newProvider(request): context = get_context(request) office_staff = request.session['MHL_Users']['OfficeStaff'] current_practice = office_staff.current_practice request.session['SELECTED_ORG_ID'] = current_practice.id showDialog = 0 username = "" if request.method == 'POST': provider_form = CreateProviderForm(data=request.POST, current_practice=current_practice) if provider_form.is_valid(): # todo, using function createNewProvider in /mdcom/MHLogin/MHLUsers/utils_users.py username = provider_form.cleaned_data['username'] provider = provider_form.save(commit=False) provider.lat = provider_form.cleaned_data['lat'] provider.longit = provider_form.cleaned_data['longit'] provider.address1 = provider_form.cleaned_data['address1'] provider.address2 = provider_form.cleaned_data['address2'] provider.city = provider_form.cleaned_data['city'] provider.state = provider_form.cleaned_data['state'] provider.zip = provider_form.cleaned_data['zip'] provider.current_practice = get_practice_org(current_practice) provider.is_active = 0 provider.save() provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() user_type = provider_form.cleaned_data['user_type'] if '1' == user_type: #Physician ph = Physician(user=provider) ph.save() elif '2' == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif '10' == user_type: ph = Physician(user=provider) ph.save() # TESTING_KMS_INTEGRATION create_default_keys(provider.user) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() sendAccountActiveCode(request, user_type) showDialog = 1 else: context['showDialog'] = showDialog context['user_form'] = provider_form return render_to_response('Staff/newProvider.html', context) context['username'] = username context['showDialog'] = showDialog context['user_form'] = CreateProviderForm( current_practice=current_practice) return render_to_response('Staff/newProvider.html', context)
def testSetProviderResultList(self): provider = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider.save() nppa = NP_PA(user=provider) nppa.save() provider1 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider1.save() phy = Physician(user=provider1) phy.specialty = 'AC' phy.save() practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() provider2 = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider2.practices.add(practice) provider2.current_practice = practice provider2.save() nppa2 = NP_PA(user=provider2) nppa2.save() provider3 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider3.practices.add(practice) provider3.current_practice = practice provider3.save() phy2 = Physician(user=provider3) phy2.specialty = 'AC' phy2.save() site = Site( name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite' ) site.save() provider4 = create_user(get_random_username(), "nppa", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider4.sites.add(site) provider4.current_site = site provider4.save() nppa3 = NP_PA(user=provider4) nppa3.save() provider5 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider5.sites.add(site) provider5.current_site = site provider5.save() phy3 = Physician(user=provider5) phy3.specialty = 'AC' phy3.save() self.assertEqual(0, len(setProviderResultList([])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa.user], phy.user)), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa2.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy2.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([nppa3.user])), 'test failed for setProviderResultList') self.assertEqual(1, len(setProviderResultList([phy3.user])), 'test failed for setProviderResultList') self.assertEqual(6, len(setProviderResultList([nppa.user, phy.user, nppa2.user, phy2.user, nppa3.user, phy3.user])), 'test failed for setProviderResultList')
def testGetProviderList(self, mockgeo): practice1 = PracticeLocation( practice_name='USA practice', practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice1.save() practice2 = PracticeLocation( practice_name='China practice', practice_address1='jiangsu', practice_address2='beijing', practice_city='suzhou', practice_state='JS', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice2.save() site1 = Site( name='mysite', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite' ) site1.save() site2 = Site( name='doctorcom', address1='555 Pleasant Pioneer Grove', address2='Trailer Q615', city='Mountain View', state='CA', zip='94040-4104', lat=37.36876, longit=-122.081864, short_name='MSite' ) site2.save() provider1 = create_user("prov1", "provider_first", "provider_last", "demo", "555 Bryant St.", "Palo Alto", "CA", "94306", uklass=Provider) provider1.address2 = 'suzhou china' provider1.user.save() provider1.sites.add(site1) provider1.sites.add(site2) provider1.current_site = site1 provider1.practices.add(practice1) provider1.practices.add(practice2) provider1.current_practice = practice1 provider1.save() provider2 = create_user("prov2", "provider_first1", "provider_last1", "demo", "suzhou china", "suzhou", "AB", "94307", uklass=Provider) provider2.sites.add(site2) provider2.current_site = site2 provider2.practices.add(practice2) provider2.current_practice = practice2 provider2.save() condition_dicts = [ {'name':u'provider', 'result':2, 'result_failed':'name failed'}, {'name':u'last1 first1', 'result':1, 'result_failed':'name failed'}, {'name':u'abc', 'result':0, 'result_failed':'name failed'}, {'address':u'Bryant', 'result':1, 'result_failed':'address failed'}, {'address':u'suzhou china', 'result':2, 'result_failed':'address failed'}, {'address':u'abc', 'result':0, 'result_failed':'address failed'}, {'city':u'Palo', 'result':1, 'result_failed':'city failed'}, {'city':u'suzhou', 'result':1, 'result_failed':'city failed'}, {'city':u'abc', 'result':0, 'result_failed':'city failed'}, {'state':u'CA', 'result':1, 'result_failed':'state failed'}, {'state':u'AB', 'result':1, 'result_failed':'state failed'}, {'state':u'abc', 'result':0, 'result_failed':'state failed'}, {'zip':provider1.zip, 'result':1, 'result_failed':'zip failed1'}, {'zip':provider2.zip, 'result':1, 'result_failed':'zip failed2'}, {'zip':provider2.zip, 'distance':5000, 'result':1, 'result_failed':'zip failed3'}, {'zip':u'43523', 'result':0, 'result_failed':'zip failed'}, {'current_hospital':u'doctorcom', 'result':1, 'result_failed':'current_hospital failed'}, {'current_hospital':u'mysite', 'result':1, 'result_failed':'current_hospital failed'}, {'current_hospital':u'22222', 'result':0, 'result_failed':'current_hospital failed'}, {'hospital':u'mysite', 'result':1, 'result_failed':'hospital failed'}, {'hospital':u'doctorcom', 'result':2, 'result_failed':'hospital failed'}, {'hospital':u'abc', 'result':0, 'result_failed':'hospital failed'}, {'current_practice':u'USA practice', 'result':1, 'result_failed':'current_practice failed'}, {'current_practice':u'China practice', 'result':1, 'result_failed':'current_practice failed'}, {'current_practice':u'abc', 'result':0, 'result_failed':'current_practice failed'}, {'practice':u'USA practice', 'result':1, 'result_failed':'practice failed'}, {'practice':u'China practice', 'result':2, 'result_failed':'practice failed'}, {'practice':u'abc', 'result':0, 'result_failed':'practice failed'}, {'limit':0, 'result':2, 'result_total':2, 'result_failed':'limit failed'}, {'limit':1, 'result':1, 'result_total':2, 'result_failed':'limit failed'}, {'limit':2, 'result':2, 'result_total':2, 'result_failed':'limit failed'}, { 'name':u'provider', 'address':u'suzhou china', 'city':u'suzhou', 'state':u'AB', 'current_hospital':u'doctorcom', 'hospital':u'doctorcom', 'current_practice':u'China practice', 'limit':1, 'result':1, 'result_total':1, 'result_failed':'all failed' }, { 'name':u'abc', 'address':u'suzhou china', 'city':u'suzhou', 'state':u'AB', 'zip':provider2.zip, 'current_hospital':u'doctorcom', 'hospital':u'doctorcom', 'current_practice':u'China practice', 'limit':1, 'result':0, 'result_total':0, 'result_failed':'all failed' }, ] with mock.patch('MHLogin.api.v1.utils_users.geocode2', new_callable=lambda: UtilsUsersTest.mock_geocode): for d in condition_dicts: result = getProviderList(d) if 'result_total' not in d: d['result_total'] = d['result'] self.assertEqual(d['result_total'], result['total_count'], d['result_failed']) self.assertEqual(d['result'], len(result['results']), d['result_failed']) phy2 = Physician(user=provider1) phy2.specialty = 'AC' phy2.save() nppa = NP_PA(user=provider2) nppa.save() condition_dicts = [ {'specialty':u'AC', 'result':1, 'result_failed':'specialty failed'}, {'specialty':u'NP/PA/Midwife', 'result':1, 'result_failed':'specialty failed'}, {'specialty':u'abc', 'result':2, 'result_failed':'specialty failed'}, ] for d in condition_dicts: result = getProviderList(d) if 'result_total' not in d: d['result_total'] = d['result'] self.assertEqual(d['result_total'], result['total_count'], d['result_failed']) self.assertEqual(d['result'], len(result['results']), d['result_failed'])
def testGetUserInfo(self): mhlu = create_user(get_random_username(), "mhluser", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "") mhlu.mdcom_phone = '9002000001' mhlu.save() mhlu_id = mhlu.id return_data1 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/generic_128.png', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': mhlu_id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'mhluser', 'office_state': u'CA', 'office_zip': u'', 'staff_type': ''} self.assertEqual(Http404, getUserInfo(mhlu_id + 1, None), 'test failed for getUserInfo') self.assertEqual(return_data1, getUserInfo(mhlu_id), 'test failed for getUserInfo mhluser') # create provider for test provider = create_user(get_random_username(), "provider", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider.mdcom_phone = '9002000002' provider.save() return_data2 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/avatar2.png', 'specialty': 'NP/PA/Midwife', 'mdcom_phone': u'9002000002', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': provider.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'provider', 'office_state': u'CA', 'office_zip': u'', 'staff_type': ''} self.assertEqual(return_data2, getUserInfo(provider.user.id), 'test failed for getUserInfo provider') # create physician provider1 = create_user(get_random_username(), "physician", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) provider1.mdcom_phone = '9002000002' provider1.save() phy = Physician(user=provider1) phy.specialty = 'AC' phy.save() return_data3 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/avatar2.png', 'specialty': u'Acupuncture', 'mdcom_phone': u'9002000002', 'office_city': u'Palo Alto', 'accepting_patients': True, 'id': phy.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'physician', 'office_state': u'CA', 'office_zip': u'', 'staff_type': ''} self.assertEqual(return_data3, getUserInfo(phy.user.user.id), 'test failed for getUserInfo physician') # create office staff staff = create_office_staff(get_random_username(), "staff", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) return_data4 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/staff_icon.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': staff.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'staff', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Staff'} self.assertEqual(return_data4, getUserInfo(staff.user.id), 'test failed for getUserInfo staff') # create nurse staff2 = create_office_staff(get_random_username(), "nurse", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) nurse = Nurse(user=staff2) nurse.save() return_data5 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/nurse.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': nurse.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'nurse', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Staff'} self.assertEqual(return_data5, getUserInfo(nurse.user.user.id), 'test failed for getUserInfo nurse') # create office staff staff3 = create_office_staff(get_random_username(), "maneger", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=OfficeStaff) mgr = Office_Manager(user=staff3) practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() mgr.manager_role = 1 mgr.practice = practice mgr.save() return_data5 = {'last_name': u'thj', 'office_address1': u'555 Bryant St.', 'office_address2': u'', 'photo': '/media/images/photos/staff_icon.jpg', 'specialty': '', 'mdcom_phone': '', 'office_city': u'Palo Alto', 'accepting_patients': False, 'id': mgr.user.user.id, 'custom_logos': get_custom_logos(mhlu_id), 'first_name': u'maneger', 'office_state': u'CA', 'office_zip': u'', 'staff_type': 'Office Manager'} self.assertEqual(return_data5, getUserInfo(mgr.user.user.id), 'test failed for getUserInfo maneger')
def generate_users(request): if (not settings.DEBUG): return HttpResponseRedirect( reverse('MHLogin.Administration.views.home')) context = get_context(request) if (request.method == 'GET'): context["form"] = GenerateUsersForm() return render_to_response('qa_tools/genereate_users.html', context) else: form = GenerateUsersForm(request.POST) if form.is_valid(): current_practice = form.cleaned_data["practices"] user_type = int(form.cleaned_data["user_types"]) number = int(form.cleaned_data["number"]) user_name_start = form.cleaned_data["user_name_start"] generate_user = None for i in range(number): username = "******" % (user_name_start, i) first_name = "%s_f_%d" % (user_name_start, i) last_name = "%s_f_%d" % (user_name_start, i) email = "*****@*****.**" % (username) password = "******" if USER_TYPE_DOCTOR == user_type \ or USER_TYPE_NPPA == user_type \ or USER_TYPE_MEDICAL_STUDENT == user_type: provider = Provider( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, lat=current_practice.practice_lat, longit=current_practice.practice_longit, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, current_practice=current_practice, is_active=1, office_lat=current_practice.practice_lat, office_longit=current_practice.practice_longit, mdcom_phone="8004664411") provider.save() provider.set_password(password) provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() create_default_keys(provider.user, password) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() generate_user = provider elif USER_TYPE_OFFICE_MANAGER == user_type \ or USER_TYPE_NURSE == user_type \ or USER_TYPE_DIETICIAN == user_type: mhluser = MHLUser( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, is_active=1, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, lat=current_practice.practice_lat, longit=current_practice.practice_longit) mhluser.save() mhluser.set_password(password) staff = OfficeStaff(user=mhluser, current_practice=current_practice) staff.user = mhluser staff.current_practice = current_practice staff.save() staff.practices.add(current_practice) staff.save() if USER_TYPE_OFFICE_MANAGER == user_type: manager = Office_Manager(user=staff, practice=current_practice) manager.save() if USER_TYPE_NURSE == user_type: nurse = Nurse(user=staff) nurse.save() elif USER_TYPE_DIETICIAN == user_type: dietician = Dietician(user=staff) dietician.save() generate_user = mhluser log_str = 'Generate user %d: for %s' % (i, str(generate_user)) logger.debug(log_str) print log_str return render_to_response('qa_tools/genereate_users_success.html', context) else: context["form"] = form return render_to_response('qa_tools/genereate_users.html', context)