Example #1
0
def acceptToJoinPractice(mhluser, pending_id, provider=None):
    """
	Accept to join Practice.

	:param mhluser: is an instance of MHLUser.
	:parm pending_id: invitation pending's id.
	:parm provider: is an instance of Provider.
	"""
    try:
        association = Pending_Association.objects.get(pk=pending_id)
        practice = association.practice_location

        if not provider:
            provider = get_object_or_404(Provider, user=mhluser)

        provider.practices.add(practice)
        current_practice = provider.current_practice
        #update current practice if needed
        new_current_practice = get_practice_org(practice)
        if (current_practice == None and new_current_practice):
            provider.current_practice = new_current_practice
            provider.save()

        #remove association record
        log_association = Log_Association()
        log_association.association_id = association.id
        log_association.from_user_id = association.from_user_id
        log_association.to_user_id = association.to_user_id
        log_association.practice_location_id = association.practice_location.id
        log_association.action_user_id = mhluser.id
        log_association.action = 'ACC'
        log_association.created_time = datetime.datetime.now()

        log_association.save()

        association.delete()

        # Add the provider to the call group.
        if (not CallGroupMember.objects.filter(call_group=practice.call_group,
                                               member=provider).exists()):
            CallGroupMember(call_group=practice.call_group,
                            member=provider,
                            alt_provider=1).save()

        # send notification to related users
        thread.start_new_thread(notify_user_tab_changed, (mhluser.id, ))

        return {
          "success": True,
          "message": _('You have successfully joined %s organization.')\
             %(practice.practice_name)
         }
    except Pending_Association.DoesNotExist:
        return {
            "success":
            False,
            "message":
            _("You already have been added to the organization"
              " or your invitation has been canceled from other client.")
        }
Example #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)
Example #3
0
def acceptToJoinPractice(mhluser, pending_id, provider=None):
	"""
	Accept to join Practice.

	:param mhluser: is an instance of MHLUser.
	:parm pending_id: invitation pending's id.
	:parm provider: is an instance of Provider.
	"""
	try:
		association = Pending_Association.objects.get(pk=pending_id)
		practice = association.practice_location
	
		if not provider:
			provider = get_object_or_404(Provider, user=mhluser)
	
		provider.practices.add(practice)
		current_practice = provider.current_practice
		#update current practice if needed
		new_current_practice = get_practice_org(practice)
		if (current_practice == None and new_current_practice):
			provider.current_practice = new_current_practice
			provider.save()

		#remove association record
		log_association = Log_Association()
		log_association.association_id = association.id
		log_association.from_user_id = association.from_user_id
		log_association.to_user_id = association.to_user_id
		log_association.practice_location_id = association.practice_location.id
		log_association.action_user_id = mhluser.id
		log_association.action = 'ACC'
		log_association.created_time = datetime.datetime.now()
	
		log_association.save()
	
		association.delete()
	
		# Add the provider to the call group.
		if (not CallGroupMember.objects.filter(
						call_group=practice.call_group, member=provider).exists()):
			CallGroupMember(
					call_group=practice.call_group,
					member=provider,
					alt_provider=1).save()

		# send notification to related users
		thread.start_new_thread(notify_user_tab_changed, (mhluser.id,))

		return {
				"success": True,
				"message": _('You have successfully joined %s organization.')\
							%(practice.practice_name)
			}
	except Pending_Association.DoesNotExist:
		return {
				"success": False,
				"message": _("You already have been added to the organization"
					" or your invitation has been canceled from other client.")
			}
Example #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
Example #5
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)
Example #6
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)
Example #7
0
def addPracticeToProvider(request):
    provider = request.session['MHL_Users']['Provider']
    current_practice = provider.current_practice

    if (request.method == 'POST'):
        form = AddPracticeToProviderForm(request.POST)
    else:
        form = AddPracticeToProviderForm(request.GET)

    if (not form.is_valid()):
        err_obj = {
            'errors': form.errors,
        }
        return HttpResponseBadRequest(json.dumps(err_obj),
                                      mimetype='application/json')

    pract_id = form.cleaned_data['pract_id']
    assoc_id = form.cleaned_data['assoc_id']

    #add practice association row
    practice = PracticeLocation.objects.get(pk=pract_id)
    provider.practices.add(practice)

    #update current practice if needed
    new_current_practice = get_practice_org(practice)
    if (current_practice == None and new_current_practice):
        provider.current_practice = new_current_practice
        provider.save()

    #remove association record
    association = Pending_Association.objects.filter(pk=assoc_id)
    if association and len(association) > 0:
        association = association[0]

        log_association = Log_Association()

        log_association.association_id = association.id
        log_association.from_user_id = association.from_user_id
        log_association.to_user_id = association.to_user_id
        log_association.practice_location_id = association.practice_location.id
        log_association.action_user_id = request.user.id
        log_association.action = 'ACC'
        log_association.created_time = datetime.datetime.now()
        log_association.save()

        association.delete()

        # Add the provider to the call group, ONLY if practice set up before V2 of answering service
        if (practice.uses_original_answering_serice()
                and not CallGroupMember.objects.filter(
                    call_group=practice.call_group, member=provider).exists()):
            CallGroupMember(call_group=practice.call_group,
                            member=provider,
                            alt_provider=1).save()
        # send notification to related users
        thread.start_new_thread(notify_user_tab_changed, (provider.user.id, ))

        ret_data = {
            "success": True,
        }
        return HttpResponse(json.dumps(ret_data), mimetype='application/json')
    else:
        ret_data = {
            "success":
            False,
            "message":
            _("You already have been added to the organization or "
              "your invitation has been canceled from other client.")
        }
        return HttpResponse(json.dumps(ret_data), mimetype='application/json')
Example #8
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)
Example #9
0
def addPracticeToProvider(request):
	provider = request.session['MHL_Users']['Provider']
	current_practice = provider.current_practice

	if (request.method == 'POST'):
		form = AddPracticeToProviderForm(request.POST)
	else:
		form = AddPracticeToProviderForm(request.GET)

	if (not form.is_valid()):
		err_obj = {
			'errors': form.errors,
		}
		return HttpResponseBadRequest(json.dumps(err_obj), mimetype='application/json')

	pract_id = form.cleaned_data['pract_id']
	assoc_id = form.cleaned_data['assoc_id']

	#add practice association row
	practice = PracticeLocation.objects.get(pk=pract_id)
	provider.practices.add(practice)

	#update current practice if needed
	new_current_practice = get_practice_org(practice)
	if (current_practice == None and new_current_practice):
		provider.current_practice = new_current_practice
		provider.save()

	#remove association record
	association = Pending_Association.objects.filter(pk=assoc_id)
	if association and len(association) > 0:
		association = association[0]

		log_association = Log_Association()

		log_association.association_id = association.id
		log_association.from_user_id = association.from_user_id
		log_association.to_user_id = association.to_user_id
		log_association.practice_location_id = association.practice_location.id
		log_association.action_user_id = request.user.id
		log_association.action = 'ACC'
		log_association.created_time = datetime.datetime.now()
		log_association.save()

		association.delete()

		# Add the provider to the call group, ONLY if practice set up before V2 of answering service
		if (practice.uses_original_answering_serice() and not CallGroupMember.objects.filter(
						call_group=practice.call_group, member=provider).exists()):
			CallGroupMember(
					call_group=practice.call_group,
					member=provider,
					alt_provider=1).save()
		# send notification to related users
		thread.start_new_thread(notify_user_tab_changed, (provider.user.id,))

		ret_data = {
			"success": True,
		}
		return HttpResponse(json.dumps(ret_data), mimetype='application/json')
	else:
		ret_data = {
			"success": False,
			"message": _("You already have been added to the organization or "
						"your invitation has been canceled from other client.")
		}
		return HttpResponse(json.dumps(ret_data), mimetype='application/json')
Example #10
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)