Exemplo n.º 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.")
        }
Exemplo n.º 2
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.")
			}
Exemplo n.º 3
0
def resendAssociation(request):

	#send email and update resent date
	user = request.user
	office_staff = request.session['MHL_Users']['OfficeStaff']
	practice = office_staff.current_practice

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

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

	assoc_id = form.cleaned_data['assoc_id']
	association = Pending_Association.objects.get(pk=assoc_id)
	created_time = datetime.datetime.now()
	association.resent_time = created_time

	association.save()

	#lets log our action
	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 = user.id
	log_association.action = 'RES'
	log_association.created_time = created_time

	log_association.save()

	provider = Provider.objects.get(user=association.to_user)
	mail_add_association(request, _('DoctorCom: Invitation To Join Practice'),  # subject,
							"""Dear {{provider_name}},

{{manager_name}} {{manager_name_last}} has sent you an invitation to join {{practice_name}}. 
Please login to DoctorCom to view and accept the pending invitaion. 

You can also accept the invitation by clicking  https://{{server_address}}/Profile/Practices/

Best, 
DoctorCom Staff""",
				provider.user.email,
				practice_name=practice.practice_name,
				manager_name=request.user.first_name,
				manager_name_last=request.user.last_name,
				provider_name=provider.user,
				server_address=settings.SERVER_ADDRESS
				)
	return HttpResponse(json.dumps('OK'), mimetype='application/json')
Exemplo n.º 4
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.")
        }
Exemplo n.º 5
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')
Exemplo n.º 6
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.")
			}
Exemplo n.º 7
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')
Exemplo n.º 8
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'))
Exemplo n.º 9
0
def addProviderToPractice(request):
	if (request.method == 'POST'):
		form = AssociationAssocIdForm(request.POST)
	else:
		form = AssociationAssocIdForm(request.GET)

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

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

	#add practice association row
	practice = PracticeLocation.objects.get(pk=association.practice_location.id)
	provider = Provider.objects.get(user=association.from_user)
	provider.practices.add(practice)

	#do not update provider's current practice even if it is NULL, only providers can do it

	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()

	#remove association record
	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,))

	return HttpResponse(json.dumps('ok'), mimetype='application/json')
Exemplo n.º 10
0
def removeAssociation(request):
	#send email and update resent date
	user = request.user
	office_staff = request.session['MHL_Users']['OfficeStaff']
	practice = office_staff.current_practice
	if (request.method == 'POST'):
		form = AssociationAssocIdForm(request.POST)
	else:
		form = AssociationAssocIdForm(request.GET)

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

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

	provider = Provider.objects.get(user=association.to_user)

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

	log_association.save()

	association.delete()

	mail_add_association(request, _('DoctorCom: Invitation To Join Practice Withdrawn'),
							"""Dear {{provider_name}},

We're sorry, but your DoctorCom Invitation to join {{practice_name}} has been withdrawn.

Best,
DoctorCom Staff""",
				provider.user.email,
				practice_name=practice.practice_name,
				provider_name=provider.user,
				server_address=settings.SERVER_ADDRESS
				)
	return HttpResponse(json.dumps('OK'), mimetype='application/json')
Exemplo n.º 11
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'))
Exemplo n.º 12
0
def rejectAssociation(request):
	office_staff = request.session['MHL_Users']['OfficeStaff']
	practice = office_staff.current_practice

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

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

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

	provider = Provider.objects.get(user=association.from_user)

	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()

	mail_add_association(request, _('DoctorCom: Request To Join Practice Rejected'),
							"""Dear {{provider_name}},

We're sorry, but your DoctorCom Invitation to join {{practice_name}} practice has been rejected. 

Best,
DoctorCom Staff""",
				provider.user.email,
				practice_name=practice.practice_name,
				provider_name=provider.user)

	return HttpResponse(json.dumps('OK'), mimetype='application/json')
Exemplo n.º 13
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'))
Exemplo n.º 14
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'))
Exemplo n.º 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')
Exemplo n.º 16
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')
Exemplo n.º 17
0
def addAssociation(request):
	user = request.user
	office_staff = request.session['MHL_Users']['OfficeStaff']
	practice = office_staff.current_practice

	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 wrong. Please '
					'refresh the page again.')}), mimetype='application/json')

	prov_id = form.cleaned_data['prov_id']

	#check if invitation from provider Exists
	ret_set = Pending_Association.objects.filter(from_user=prov_id, practice_location=practice.id)
	if (ret_set.count() > 0):
		return HttpResponse(json.dumps(['duplicate']))  # , mimetype='application/json')

	association = Pending_Association()
	created_time = datetime.datetime.now()
	resend_time = created_time
	association.from_user_id = user.id
	association.to_user_id = prov_id
	association.practice_location_id = practice.id
	association.created_time = created_time
	association.resent_time = resend_time

	association.save()

	#lets log our action
	log_association = Log_Association()

	log_association.association_id = association.id
	log_association.from_user_id = user.id
	log_association.to_user_id = prov_id
	log_association.practice_location_id = practice.id
	log_association.action_user_id = user.id
	log_association.action = 'CRE'
	log_association.created_time = created_time
	association.resent_time = resend_time
	log_association.save()

	#now let's mail provider invitaion request
	if request.POST['userType'] == '1':
		#provider = Provider.objects.get(user=prov_id)
		provider = Provider.objects.get(user__id=prov_id)
	else:
		#provider = OfficeStaff.objects.get(user=prov_id)
		provider = OfficeStaff.objects.get(user__id=prov_id)

	mail_add_association(request, _('DoctorCom: Invitation To Join Practice'),  # subject,
							"""Dear {{provider_name}},

{{manager_name}} {{manager_name_last}} has sent you an invitation to join {{practice_name}}. 
Please login to DoctorCom to view and accept the pending invitaion. 

You can also accept the invitation by clicking  https://{{server_address}}/Profile/Practices/

Best, 
DoctorCom Staff""",
				provider.user.email,
				practice_name=practice.practice_name,
				manager_name=request.user.first_name,
				manager_name_last=request.user.last_name,
				provider_name=provider.user,
				server_address=settings.SERVER_ADDRESS
				)

	return HttpResponse(json.dumps(['ok']))  # , mimetype='application/json')
Exemplo n.º 18
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')
Exemplo n.º 19
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')