예제 #1
0
def rejectToJoinPractice(mhluser, pending_id):
    """
	Reject to join Practice.

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

        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 = 'REJ'
        log_association.created_time = datetime.datetime.now()

        log_association.save()
        association.delete()

        mail_managers(
            practice,
            _('DoctorCom: Request To Join Practice Rejected'),
            """Dear Manager,

We're sorry, but {{provider_fullname}} turned down your request to join {{practice_name}}.

Best,
DoctorCom Staff
""",
            practice_name=practice.practice_name,
            provider_fullname=get_fullname(mhluser),
        )
        return {
          "success": True,
          "message": _('You have declined %s\'s invitation.')\
            %(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.")
        }
예제 #2
0
def rejectAssociation(request):
	if (request.method == 'POST'):
		form = AssocIdAssociationForm(request.POST)
	else:
		form = AssocIdAssociationForm(request.GET)
	if (not form.is_valid()):
		return HttpResponse(json.dumps(_('A server error has occurred.')))

	assoc_id = form.cleaned_data['assoc_id']
	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 = 'REJ'
		log_association.created_time = datetime.datetime.now()
		log_association.save()
		association.delete()

		practice = association.practice_location
		mail_managers(practice,
						_('DoctorCom: Request To Join Practice Rejected'),
						"""Dear Manager,

We're sorry, but {{provider_name}} {{provider_name_last}} turned down your request 
to join {{practice_name}}.

Best,
DoctorCom Staff
""",
					practice_name=practice.practice_name,
					provider_name=request.user.first_name,
					provider_name_last=request.user.last_name
					)
		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')
예제 #3
0
def rejectAssociation(request):
    if (request.method == 'POST'):
        form = AssocIdAssociationForm(request.POST)
    else:
        form = AssocIdAssociationForm(request.GET)
    if (not form.is_valid()):
        return HttpResponse(json.dumps(_('A server error has occurred.')))

    assoc_id = form.cleaned_data['assoc_id']
    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 = 'REJ'
        log_association.created_time = datetime.datetime.now()
        log_association.save()
        association.delete()

        practice = association.practice_location
        mail_managers(practice,
                      _('DoctorCom: Request To Join Practice Rejected'),
                      """Dear Manager,

We're sorry, but {{provider_name}} {{provider_name_last}} turned down your request 
to join {{practice_name}}.

Best,
DoctorCom Staff
""",
                      practice_name=practice.practice_name,
                      provider_name=request.user.first_name,
                      provider_name_last=request.user.last_name)
        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')
예제 #4
0
def resendAssociation(request):
	if (request.method == 'POST'):
		form = AssocIdAssociationForm(request.POST)
	else:
		form = AssocIdAssociationForm(request.GET)

	if (not form.is_valid()):
		return HttpResponse(json.dumps(_('A server error has occurred.')))

	assoc_id = form.cleaned_data['assoc_id']
	association = Pending_Association.objects.get(pk=assoc_id)
	practice = association.practice_location

	created_time = datetime.datetime.now()
	association.resent_time = created_time

	association.save()

	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 = 'RES'
	log_association.created_time = created_time

	log_association.save()

	mail_managers(practice,
				_('DoctorCom: Request To Join Practice'),
						"""Dear Manager,

{{provider_name}} {{provider_name_last}} wants to join {{practice_name}}.

Please log into DoctorCom to view and accept the request. You can also accept 
the request by clicking https://{{server_address}}/Practice/Staff/

Best,
DoctorCom Staff
""",

				practice_name=practice.practice_name,
				provider_name=request.user.first_name,
				provider_name_last=request.user.last_name,
				server_address=settings.SERVER_ADDRESS
				)
	return HttpResponse(json.dumps('ok'))
예제 #5
0
파일: utils.py 프로젝트: DongHuaLu/mdcom
def rejectToJoinPractice(mhluser, pending_id):
	"""
	Reject to join Practice.

	:param mhluser: is an instance of MHLUser.
	:parm pending_id: invitation pending's id.
	"""
	try:
		association = Pending_Association.objects.get(to_user=mhluser, pk=pending_id)
		practice = association.practice_location
	
		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 = 'REJ'
		log_association.created_time = datetime.datetime.now()
	
		log_association.save()
		association.delete()
	
		mail_managers(practice,
						_('DoctorCom: Request To Join Practice Rejected'),
						"""Dear Manager,

We're sorry, but {{provider_fullname}} turned down your request to join {{practice_name}}.

Best,
DoctorCom Staff
""",
	
					practice_name=practice.practice_name,
					provider_fullname=get_fullname(mhluser),
					)
		return {
				"success": True,
				"message": _('You have declined %s\'s invitation.')\
						%(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.")
			}
예제 #6
0
def resendAssociation(request):
    if (request.method == 'POST'):
        form = AssocIdAssociationForm(request.POST)
    else:
        form = AssocIdAssociationForm(request.GET)

    if (not form.is_valid()):
        return HttpResponse(json.dumps(_('A server error has occurred.')))

    assoc_id = form.cleaned_data['assoc_id']
    association = Pending_Association.objects.get(pk=assoc_id)
    practice = association.practice_location

    created_time = datetime.datetime.now()
    association.resent_time = created_time

    association.save()

    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 = 'RES'
    log_association.created_time = created_time

    log_association.save()

    mail_managers(practice,
                  _('DoctorCom: Request To Join Practice'),
                  """Dear Manager,

{{provider_name}} {{provider_name_last}} wants to join {{practice_name}}.

Please log into DoctorCom to view and accept the request. You can also accept 
the request by clicking https://{{server_address}}/Practice/Staff/

Best,
DoctorCom Staff
""",
                  practice_name=practice.practice_name,
                  provider_name=request.user.first_name,
                  provider_name_last=request.user.last_name,
                  server_address=settings.SERVER_ADDRESS)
    return HttpResponse(json.dumps('ok'))
예제 #7
0
def removeAssociation(request):
	if (request.method == 'POST'):
		form = AssocIdAssociationForm(request.POST)
	else:
		form = AssocIdAssociationForm(request.GET)

	if (not form.is_valid()):
		return HttpResponse(json.dumps(_('A server error has occurred.')))

	assoc_id = form.cleaned_data['assoc_id']
	association = Pending_Association.objects.get(pk=assoc_id)
	practice = association.practice_location

	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 = 'CAN'
	log_association.created_time = datetime.datetime.now()

	log_association.save()

	association.delete()

	mail_managers(practice,
					_('DoctorCom: Request To Join Practice Canceled'),
					"""Dear Manager,

We're sorry, but the request from {{provider_name}} {{provider_name_last}} to 
join {{practice_name}} has been cancelled.

Best,
DoctorCom Staff
""",

				practice_name=practice.practice_name,
				provider_name=request.user.first_name,
				provider_name_last=request.user.last_name
				)
	return HttpResponse(json.dumps('ok'))
예제 #8
0
	def test_mail_managers(self):
		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()
		subject = 'abc'
		body = 'test'
		sender = None
		
		result = mail_managers(practice, subject, body, sender)
		self.assertIsNone(result)
		
		sender = '*****@*****.**'
		result = mail_managers(practice, subject, body, sender)
		self.assertIsNone(result)
예제 #9
0
    def test_mail_managers(self):
        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()
        subject = 'abc'
        body = 'test'
        sender = None

        result = mail_managers(practice, subject, body, sender)
        self.assertIsNone(result)

        sender = '*****@*****.**'
        result = mail_managers(practice, subject, body, sender)
        self.assertIsNone(result)
예제 #10
0
def removeAssociation(request):
    if (request.method == 'POST'):
        form = AssocIdAssociationForm(request.POST)
    else:
        form = AssocIdAssociationForm(request.GET)

    if (not form.is_valid()):
        return HttpResponse(json.dumps(_('A server error has occurred.')))

    assoc_id = form.cleaned_data['assoc_id']
    association = Pending_Association.objects.get(pk=assoc_id)
    practice = association.practice_location

    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 = 'CAN'
    log_association.created_time = datetime.datetime.now()

    log_association.save()

    association.delete()

    mail_managers(practice,
                  _('DoctorCom: Request To Join Practice Canceled'),
                  """Dear Manager,

We're sorry, but the request from {{provider_name}} {{provider_name_last}} to 
join {{practice_name}} has been cancelled.

Best,
DoctorCom Staff
""",
                  practice_name=practice.practice_name,
                  provider_name=request.user.first_name,
                  provider_name_last=request.user.last_name)
    return HttpResponse(json.dumps('ok'))
예제 #11
0
def removeProviderPractice(request):
	if (request.method == 'POST'):
		form = AssociationProviderIdForm(request.POST)
	else:
		form = AssociationProviderIdForm(request.GET)

	if (not form.is_valid()):
		return HttpResponse(json.dumps({'err': _('The data is error. Please '
						'refresh page again.')}), mimetype='application/json')

	prov_id = form.cleaned_data['prov_id']

	#get managers' practice, and practices call group
	office_staff = request.session['MHL_Users']['OfficeStaff']
	practice = office_staff.current_practice
	call_group = practice.call_group

	current_date = datetime.datetime.now()
	two_weeks_date = current_date + datetime.timedelta(days=15)

	#get provider to be removed
	provider = Provider.objects.get(user=prov_id)
	user = provider.user

	#if schedule exists in next two weeks massage managers, so they can cover gaps
	events_set = EventEntry.objects.filter(callGroup=call_group, oncallPerson=user, 
			eventStatus=1, endDate__gt=current_date)
	#raise Exception('return set is', events_set, practice, user)

	if (events_set.count() > 0):

		subject = 'DoctorCom: Gaps in On Call Schedule'
		body = _("""Dear Manager,

%(first_name)s %(last_name)s has removed %(user)s from %(practice_name)s. %(user)s was 
removed from the on-call schedule, creating gaps in coverage. Please update your 
on-call schedule to fill these gaps.

Best,
DoctorCom Staff""") \
		% {
			'first_name': request.user.first_name,
			'last_name': request.user.last_name,
			'user': provider.user,
			'practice_name': practice.practice_name
		}
			#work around message_managers fails to message:

			#message_managers(request, practice, subject,
			#				body, 
			#	practice_name=practice.practice_name,
			#	manager_name=request.user.first_name,
			#	manager_name_last=request.user.last_name,
			#	provider_name=provider.user
			#	)

		#get a list of all office managers for this practice
		OfficeManagers = get_all_practice_managers(practice.id)
		#this will be message for office managers, next key makes sms not being sent out with
		#message-becasue office managers do not have to carry cell phones, dahsboard only
		request.session['answering_service'] = 'yes'

		#create message object
		msg = Message(sender=None, sender_site=None, subject=subject)
		msg.save()

		msg_body = msg.save_body(body)

		#create list of recepients - all office manager of the practice in question
		for OfficeStaff in OfficeManagers:
			MessageRecipient(message=msg, user=OfficeStaff.user).save()

		msg.send(request, msg_body)

		#send email as well to all managers
		mail_managers(practice, subject, body)

	today = datetime.date.today()
	#remove from schedule - mark as deleted
	EventEntry.objects.filter(callGroup=call_group, oncallPerson=user, 
		startDate__gte=today).update(eventStatus=0, lastupdate=current_date)
	EventEntry.objects.filter(callGroup=call_group, oncallPerson=user, 
		endDate__gte=today, startDate__lt=today).update(endDate=today, lastupdate=current_date)

	CallGroupMember.objects.filter(call_group=call_group, member=user).delete()

	#remove from provider
	if (provider.current_practice == practice):
		provider.current_practice = None
		provider.save()

	provider.practices.remove(practice)

	return HttpResponse(json.dumps('ok'), mimetype='application/json')
예제 #12
0
def removePractice(request):
    if (request.method == 'POST'):
        form = PractIdAssociationForm(request.POST)
    else:
        form = PractIdAssociationForm(request.GET)

    if (not form.is_valid()):
        return HttpResponse(json.dumps(['err',
                                        'A server error has occurred.']),
                            mimetype='application/json')

    pract_id = form.cleaned_data['pract_id']
    current_date = datetime.datetime.now()
    two_weeks_date = current_date + datetime.timedelta(days=15)

    user = request.user
    provider = request.session['MHL_Users']['Provider']
    practice = PracticeLocation.objects.get(pk=pract_id)

    #remove from call group for this practice
    #if schedule exists in next two weeks massage managers, so they can cover gaps
    if practice.call_group:
        call_group = practice.call_group
        events_set = EventEntry.objects.filter(callGroup=call_group,
                                               oncallPerson=user,
                                               eventStatus=1,
                                               endDate__range=(current_date,
                                                               two_weeks_date))
    else:
        call_group = practice.call_groups.all()
        events_set = EventEntry.objects.filter(callGroup__in=call_group,
                                               oncallPerson=user,
                                               eventStatus=1,
                                               endDate__range=(current_date,
                                                               two_weeks_date))
    if (events_set.count() > 0):

        subject = _('DoctorCom: Gaps in On Call Schedule')
        body = """Dear Manager,

%(user)s has left %(practice_name)s. %(user)s was removed from the on-call schedule, 
creating gaps in coverage. Please update your on-call schedule to fill these gaps.

Best,
DoctorCom Staff""" % {
            'user': provider.user,
            'practice_name': practice.practice_name
        }

        #get a list of all office managers for this practice
        OfficeManagers = get_all_practice_managers(practice.id)
        #this will be message for office managers, next key makes sms not being sent out
        #with message-becasue office managers do not have to carry cell phones, dahsboard only
        request.session['answering_service'] = _('yes')

        #create message object
        msg = Message(sender=None, sender_site=None, subject=subject)
        msg.save()

        msg_body = msg.save_body(body)

        #create list of recepients - all office manager of the practice in question
        for OfficeStaff in OfficeManagers:
            MessageRecipient(message=msg, user=OfficeStaff.user).save()

        msg.send(request, msg_body)

        #send email as well to all managers
        mail_managers(practice, subject, body)

    #remove from schedule - mark as deleted
    if practice.call_group:
        CallGroupMember.objects.filter(call_group=call_group,
                                       member=user).delete()
        EventEntry.objects.filter(callGroup=call_group,
                                  oncallPerson=user,
                                  endDate__gte=current_date).update(
                                      eventStatus=0, lastupdate=current_date)
    else:
        CallGroupMember.objects.filter(call_group__in=call_group,
                                       member=user).delete()
        EventEntry.objects.filter(callGroup__in=call_group,
                                  oncallPerson=user,
                                  endDate__gte=current_date).update(
                                      eventStatus=0, lastupdate=current_date)

    #remove from provider
    if (provider.current_practice == practice):
        provider.current_practice = None
        provider.save()

    provider.practices.remove(practice)

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

    return HttpResponse(json.dumps(['err', 'No errors.']),
                        mimetype='application/json')
예제 #13
0
def addAssociationForPractice(request):
    user = request.user

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

    if (not form.is_valid()):
        return HttpResponse(json.dumps(_('A server error has occurred.')))

    pract_id = form.cleaned_data['pract_id']
    #get practice
    practice = PracticeLocation.objects.get(pk=pract_id)
    #check if manager sent association request to this provider already
    ret_set = Pending_Association.objects.filter(to_user=user,
                                                 practice_location=pract_id)
    if (ret_set.count() > 0):
        return HttpResponse(json.dumps(['duplicate'
                                        ]))  # , mimetype='application/json')

    #get practices Managers
    OfficeManagers = get_all_practice_managers(pract_id)
    if (len(OfficeManagers) == 0):
        raise Exception(' '.join([
            _('Practice with id'),
            str(pract_id),
            _('doesn\'t seem to have any managers!')
        ]))

    association = Pending_Association()
    created_time = datetime.datetime.now()

    association.from_user_id = user.id
    association.to_user_id = OfficeManagers[0].user.id
    association.practice_location_id = practice.id
    association.created_time = created_time
    association.resent_time = created_time
    association.save()

    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 = 'CRE'
    log_association.created_time = created_time

    log_association.save()

    #now let's mail all managers invitaion request
    mail_managers(practice,
                  _('DoctorCom: Request To Join Practice'),
                  """Dear Manager,

{{provider_name}} {{provider_name_last}} wants to join {{practice_name}}.

Please log into DoctorCom to view and accept the request. You can also accept 
the request by clicking https://{{server_address}}/Practice/Staff/

Best,
DoctorCom Staff
""",
                  practice_name=practice.practice_name,
                  provider_name=request.user.first_name,
                  provider_name_last=request.user.last_name,
                  server_address=settings.SERVER_ADDRESS)

    return HttpResponse(json.dumps('ok'))  # , mimetype='application/json')
예제 #14
0
def removePractice(request):
	if (request.method == 'POST'):
		form = PractIdAssociationForm(request.POST)
	else:
		form = PractIdAssociationForm(request.GET)

	if (not form.is_valid()):
		return HttpResponse(json.dumps(['err', 'A server error has occurred.']), 
						mimetype='application/json')

	pract_id = form.cleaned_data['pract_id']
	current_date = datetime.datetime.now()
	two_weeks_date = current_date + datetime.timedelta(days=15)

	user = request.user
	provider = request.session['MHL_Users']['Provider']
	practice = PracticeLocation.objects.get(pk=pract_id)

	#remove from call group for this practice
	#if schedule exists in next two weeks massage managers, so they can cover gaps
	if practice.call_group:
		call_group = practice.call_group
		events_set = EventEntry.objects.filter(callGroup=call_group, 
			oncallPerson=user, eventStatus=1, endDate__range=(current_date, two_weeks_date))
	else:
		call_group = practice.call_groups.all()
		events_set = EventEntry.objects.filter(callGroup__in=call_group, 
			oncallPerson=user, eventStatus=1, endDate__range=(current_date, two_weeks_date))
	if (events_set.count() > 0):	

		subject = _('DoctorCom: Gaps in On Call Schedule')
		body = """Dear Manager,

%(user)s has left %(practice_name)s. %(user)s was removed from the on-call schedule, 
creating gaps in coverage. Please update your on-call schedule to fill these gaps.

Best,
DoctorCom Staff""" % {'user': provider.user, 'practice_name': practice.practice_name}

		#get a list of all office managers for this practice
		OfficeManagers = get_all_practice_managers(practice.id)
		#this will be message for office managers, next key makes sms not being sent out 
		#with message-becasue office managers do not have to carry cell phones, dahsboard only
		request.session['answering_service'] = _('yes')

		#create message object		
		msg = Message(sender=None, sender_site=None, subject=subject)
		msg.save()

		msg_body = msg.save_body(body)

		#create list of recepients - all office manager of the practice in question
		for OfficeStaff in OfficeManagers:
			MessageRecipient(message=msg, user=OfficeStaff.user).save()

		msg.send(request, msg_body)

		#send email as well to all managers
		mail_managers(practice, subject, body)

	#remove from schedule - mark as deleted	
	if practice.call_group:
		CallGroupMember.objects.filter(call_group=call_group, member=user).delete()
		EventEntry.objects.filter(callGroup=call_group, oncallPerson=user, 
			endDate__gte=current_date).update(eventStatus=0, lastupdate=current_date)
	else:
		CallGroupMember.objects.filter(call_group__in=call_group, member=user).delete()
		EventEntry.objects.filter(callGroup__in=call_group, oncallPerson=user, 
			endDate__gte=current_date).update(eventStatus=0, lastupdate=current_date)

	#remove from provider
	if (provider.current_practice == practice):
		provider.current_practice = None
		provider.save()

	provider.practices.remove(practice)

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

	return HttpResponse(json.dumps(['err', 'No errors.']), mimetype='application/json')
예제 #15
0
def addAssociationForPractice(request):
	user = request.user

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

	if (not form.is_valid()):
		return HttpResponse(json.dumps(_('A server error has occurred.')))

	pract_id = form.cleaned_data['pract_id']
	#get practice
	practice = PracticeLocation.objects.get(pk=pract_id)
	#check if manager sent association request to this provider already
	ret_set = Pending_Association.objects.filter(to_user=user, practice_location=pract_id)
	if (ret_set.count() > 0):
		return HttpResponse(json.dumps(['duplicate']))  # , mimetype='application/json')

	#get practices Managers
	OfficeManagers = get_all_practice_managers(pract_id)
	if (len(OfficeManagers) == 0):
		raise Exception(' '.join([_('Practice with id'), str(pract_id),
				_('doesn\'t seem to have any managers!')]))

	association = Pending_Association()
	created_time = datetime.datetime.now()

	association.from_user_id = user.id
	association.to_user_id = OfficeManagers[0].user.id
	association.practice_location_id = practice.id
	association.created_time = created_time
	association.resent_time = created_time
	association.save()

	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 = 'CRE'
	log_association.created_time = created_time

	log_association.save()

	#now let's mail all managers invitaion request
	mail_managers(practice,
					_('DoctorCom: Request To Join Practice'),
					"""Dear Manager,

{{provider_name}} {{provider_name_last}} wants to join {{practice_name}}.

Please log into DoctorCom to view and accept the request. You can also accept 
the request by clicking https://{{server_address}}/Practice/Staff/

Best,
DoctorCom Staff
""",

				practice_name=practice.practice_name,
				provider_name=request.user.first_name,
				provider_name_last=request.user.last_name,
				server_address=settings.SERVER_ADDRESS
				)

	return HttpResponse(json.dumps('ok'))  # , mimetype='application/json')