Esempio n. 1
0
    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')
Esempio n. 2
0
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)
Esempio n. 3
0
	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')
Esempio n. 4
0
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
Esempio n. 5
0
	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')
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
    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')
Esempio n. 9
0
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)
Esempio n. 10
0
	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'])
Esempio n. 11
0
	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')
Esempio n. 12
0
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)
Esempio n. 13
0
    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')
Esempio n. 14
0
    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'])
Esempio n. 15
0
    def done(self, request, form_list):
        inviteForm = form_list[0]
        providerForm = form_list[1]
        providerInfo = form_list[2]
        extraSetupForm = form_list[3]

        invite = Invitation.objects.get(code=inviteForm.cleaned_data['code'])
        provider = providerForm.save(commit=False)
        provider.set_password(providerForm.cleaned_data['password1'])
        if (invite.typeVerified):
            provider.status_verified = True
            provider.status_verifier = MHLUser.objects.get(id=invite.sender_id)
        provider.save()

        provider.user = MHLUser.objects.get(id=provider.id)
        type = providerForm.cleaned_data['userType']
        if type == '1':
            Physician(
                user=provider,
                specialty=extraSetupForm.cleaned_data['specialty'],
                accepting_new_patients=extraSetupForm.
                cleaned_data['accepting_new_patients'],
                staff_type=extraSetupForm.cleaned_data['staff_type']).save()
        if type == '10':
            Physician(
                user=provider,
                specialty=extraSetupForm.cleaned_data['specialty'],
                accepting_new_patients=extraSetupForm.
                cleaned_data['accepting_new_patients'],
                staff_type=extraSetupForm.cleaned_data['staff_type']).save()
            provider.clinical_clerk = True
        if type == '2':
            NP_PA(user=provider).save()

        lst = extraSetupForm.cleaned_data['sites']
        lst2 = extraSetupForm.cleaned_data['licensed_states']
        sitesList = lst.split(',')
        sitesList2 = lst2.split(',')

        slst = []
        slst2 = []
        for s in sitesList:
            if s:
                slst.append(int(s))

        for s in sitesList2:
            if s:
                slst2.append(int(s))
        if slst:
            provider.sites = Site.objects.filter(id__in=slst)

        if extraSetupForm.cleaned_data['current_site']:
            currentSites = Site.objects.filter(
                id=int(extraSetupForm.cleaned_data['current_site']))
            if currentSites:
                cs = currentSites[0]
                provider.current_site = cs

        if slst2:
            provider.licensure_states = States.objects.filter(id__in=slst2)

        geocode_response = geocode2(providerInfo.cleaned_data['address1'], \
              providerInfo.cleaned_data['city'], \
              providerInfo.cleaned_data['state'], \
              providerInfo.cleaned_data['zip'])
        lat = geocode_response['lat']
        longit = geocode_response['lng']

        # use mhluser's address1, address2, city, state, zip to store "address" information,
        provider.address1 = providerInfo.cleaned_data['address1']
        provider.address2 = providerInfo.cleaned_data['address2']
        provider.city = providerInfo.cleaned_data['city']
        provider.state = providerInfo.cleaned_data['state']
        provider.zip = providerInfo.cleaned_data['zip']
        provider.lat = lat
        provider.longit = longit

        #add by xlin in 20120504 to add current practice
        if invite.assignPractice:
            prac = invite.assignPractice
            provider.current_practice = get_practice_org(prac)

        provider.tos_accepted = True
        if invite.recipient == request.POST['email']:
            provider.email_confirmed = True

        # Generating the user's voicemail box configuration
        config = VMBox_Config(pin='')
        config.owner = provider
        config.save()

        # LocalNumberForm, area_code, pin, mdcom_phone, mdcom_phone_sid
        numberForm = form_list[4]
        mdcom_phone = numberForm.mdcom_phone
        mdcom_phone_sid = numberForm.mdcom_phone_sid
        pin = numberForm.cleaned_data['pin']

        provider.mdcom_phone = mdcom_phone
        provider.mdcom_phone_sid = mdcom_phone_sid

        #add doctorcom number
        if settings.CALL_ENABLE:
            user_type = ContentType.objects.get_for_model(provider)
            config = VMBox_Config.objects.get(owner_type=user_type,
                                              owner_id=provider.id)
            #config.change_pin(request, new_pin=pin)
            config.set_pin(pin)
            config.save()
            twilio_ConfigureProviderLocalNumber(provider, provider.mdcom_phone)
            request.session['userId'] = provider.id
            request.session['pin'] = pin

        provider.save()

        if invite.assignPractice:
            provider.practices.add(prac)
            #add by xlin in 20120504 add new provider in call group
            group = PracticeLocation.objects.get(pk=invite.assignPractice.id)
            #ONLY if practice set up before V2 of answering service
            if (prac.uses_original_answering_serice()):
                cm = CallGroupMember(call_group=group.call_group,
                                     member=provider,
                                     alt_provider=1)
                cm.save()

        # TESTING_KMS_INTEGRATION
        create_default_keys(provider.user,
                            providerForm.cleaned_data['password1'])

        # Remove the invitation.
        invite.delete(createdUser=provider.user, send_notice=False)
        return HttpResponseRedirect(self.redirect_url)