예제 #1
0
파일: views.py 프로젝트: DongHuaLu/mdcom
def member_org_invite_incoming(request):
	context = get_context(request)
	if ('Office_Manager' in request.session['MHL_Users']):
		manager = request.session['MHL_Users']['Office_Manager']
		# get_managed_practice can only get the root managed practices
		managed_organizations = get_managed_practice(manager.user)
		org_ids = [org.id for org in managed_organizations]
		pendings = Pending_Org_Association.objects.filter(to_practicelocation__id__in=org_ids).\
			select_related('from_practicelocation', 'to_practicelocation')
		org_pendings = [
		{
			'pending_id': pending.id,
			'sender_name': " ".join([pending.sender.first_name, pending.sender.last_name]),
			'from_practicelocation_logo': ImageHelper.get_image_by_type(
				pending.from_practicelocation.practice_photo, "Middle", 
					'Practice', 'img_size_practice'),
			'from_practicelocatin_type': pending.from_practicelocation.organization_type.name,
			'from_practicelocation_name': pending.from_practicelocation.practice_name,
			'to_practicelocation_name': pending.to_practicelocation.practice_name,
			'to_practicelocatin_type': pending.to_practicelocation.organization_type.name,
		} for pending in pendings]

		org_pendings_ret = [
			render_to_string('MHLOrganization/MemberOrg/invitation_notification.html', p)
				for p in org_pendings]
		return HttpResponse(json.dumps(org_pendings_ret), mimetype='application/json')
예제 #2
0
def practiceManageLogic(request):
    user_type = int(request.user_type)
    role_user = request.role_user
    if (request.method != 'POST'):
        # Get the user's current practices, and list them.
        practices = role_user.practices.filter(\
          organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
        if USER_TYPE_OFFICE_MANAGER == user_type:
            practices = get_managed_practice(role_user)

        practices = [[p.id, p.practice_name] for p in practices]
        current_practice = role_user.current_practice
        if ('pk' in dir(current_practice)):
            current_practice = current_practice.pk
            data = {
                'practices': practices,
                'current_practice': current_practice,
            }
        return HttpJSONSuccessResponse(data=data)

    # office staff can't change current practice
    if USER_TYPE_OFFICE_STAFF == user_type:
        return err403(request)

    form = SetPracticeForm(request.POST, user_type=user_type)
    if (not form.is_valid()):
        return err_GE031(form)

    new_practice = form.cleaned_data['current_practice']
    if (new_practice == None):
        # Clearing the current practice.
        role_user.current_practice = None
        role_user.save()
        data = {
            'providers': [],
            'staff': [],
        }
        return HttpJSONSuccessResponse(data=data)
    if (new_practice in role_user.practices.values_list('id', flat=True)):
        # great, do the change.
        role_user.current_practice_id = new_practice
        role_user.save()
        data = {
            'providers': getPracticeProviders(new_practice)['users'],
            'staff': getPracticeStaff(new_practice)['users'],
        }
        return HttpJSONSuccessResponse(data=data)

    err_obj = {
        'errno': 'AM001',
        'descr': _('Invalid practice selection.'),
    }
    return HttpResponseBadRequest(content=json.dumps(err_obj),
                                  mimetype='application/json')
예제 #3
0
def practiceManageLogic(request):
	user_type = int(request.user_type)
	role_user = request.role_user
	if (request.method != 'POST'):
		# Get the user's current practices, and list them.
		practices = role_user.practices.filter(\
				organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
		if USER_TYPE_OFFICE_MANAGER == user_type:
			practices = get_managed_practice(role_user)

		practices = [[p.id, p.practice_name] for p in practices]
		current_practice = role_user.current_practice
		if ('pk' in dir(current_practice)):
			current_practice = current_practice.pk
			data = {
					'practices':practices,
					'current_practice':current_practice,
				}
		return HttpJSONSuccessResponse(data=data)

	# office staff can't change current practice
	if USER_TYPE_OFFICE_STAFF == user_type:
		return err403(request)

	form = SetPracticeForm(request.POST, user_type=user_type)
	if (not form.is_valid()):
		return err_GE031(form)
	
	new_practice = form.cleaned_data['current_practice']
	if (new_practice == None):
		# Clearing the current practice.
		role_user.current_practice = None
		role_user.save()
		data = {
				'providers': [],
				'staff': [],
			}
		return HttpJSONSuccessResponse(data=data)
	if (new_practice in role_user.practices.values_list('id', flat=True)):
		# great, do the change.
		role_user.current_practice_id = new_practice
		role_user.save()
		data = {
				'providers': getPracticeProviders(new_practice)['users'],
				'staff': getPracticeStaff(new_practice)['users'],
			}
		return HttpJSONSuccessResponse(data=data)
	
	err_obj = {
		'errno': 'AM001',
		'descr': _('Invalid practice selection.'),
	}
	return HttpResponseBadRequest(content=json.dumps(err_obj), mimetype='application/json')
예제 #4
0
def getInvitationPendings(request_host, mhluser, role_user, user_type):
    user_type = int(user_type)
    invitations = []
    pend_practice = Pending_Association.objects.filter(
        to_user=mhluser).order_by('created_time')
    for p in pend_practice:
        from_user = p.from_user
        practice = p.practice_location
        logo_path = ImageHelper.get_image_by_type(practice.practice_photo,
                                                  size='Large',
                                                  type='',
                                                  resize_type='img_size_logo')
        if not logo_path == '':
            logo_path = '%s%s' % (request_host, logo_path)
        org_name = practice.practice_name
        member_invitations_content_context = {
            "invitation_sender": get_fullname(from_user),
            "role": 'provider',
            'org_type': practice.organization_type.name,
            "org_logo": logo_path,
            "org_name": org_name,
            'org_addr1': practice.practice_address1,
            'org_addr2': practice.practice_address2,
            'org_zip': practice.practice_zip,
            'org_id': practice.id,
            'org_city': practice.practice_city,
            'org_state': practice.practice_state,
        }
        member_invitations_content = render_to_string(
            'MHLOrganization/member_invitation_for_app.html',
            member_invitations_content_context)
        p = {
            "pending_id": p.pk,
            "type": "1",
            "content": member_invitations_content
        }
        invitations.append(p)

    if user_type == USER_TYPE_OFFICE_MANAGER:
        managed_organizations = get_managed_practice(role_user)
        org_ids = [org.id for org in managed_organizations]
        pendings = Pending_Org_Association.objects.filter(
            to_practicelocation__id__in=org_ids).select_related(
                'from_practicelocation', 'to_practicelocation')

        for p in pendings:
            logo_path = ImageHelper.get_image_by_type(
                p.from_practicelocation.practice_photo, "Middle", 'Practice',
                'img_size_logo')
            if not logo_path == '':
                logo_path = '%s%s' % (request_host, logo_path)
            from_practicelocation_name = p.from_practicelocation.practice_name
            to_practicelocation_name = p.to_practicelocation.practice_name
            member_org_invitations_content_context = {
                'pending_id':
                p.id,
                'sender_name':
                get_fullname(p.sender),
                'from_practicelocation_logo':
                logo_path,
                'from_practicelocatin_type':
                p.from_practicelocation.organization_type.name,
                'from_practicelocation_name':
                from_practicelocation_name,
                'to_practicelocation_name':
                to_practicelocation_name,
                'to_practicelocatin_type':
                p.to_practicelocation.organization_type.name,
            }
            member_org_invitations_content = render_to_string(
                'MHLOrganization/member_org_invitation_for_app.html',
                member_org_invitations_content_context)
            p = {
                "pending_id": p.pk,
                "type": "2",
                "content": member_org_invitations_content
            }
            invitations.append(p)
    call_group_penddings = []
    for p in get_call_group_penddings(mhluser.id):
        p_content = render_to_string('App/call_group_invitation_for_app.html',
                                     p)
        call_group_penddings.append({
            "pending_id": p['id'],
            "type": "3",
            "content": p_content
        })

    return {'invitations': invitations,\
      'call_group_penddings': call_group_penddings}
예제 #5
0
def processor(request, activeApp=None):
	"""Creates a dictionary complete with standard MyHealth template definitions."""
	context = {}

	mobile_device_check(request, context)

	context['debug'] = settings.DEBUG
	context['DEBUG'] = settings.DEBUG

	context['SERVER_ADDRESS'] = settings.SERVER_ADDRESS
	context['SERVER_PROTOCOL'] = settings.SERVER_PROTOCOL
	context['SERVERVERSION'] = "v%s" % '.'.join(__version__.split('.')[0:3])

	if (not 'MHL_UserIDs' in request.session or not 'MHL_Users' in request.session):
		return context

	# Get user types
	context['sender_types'] = request.session['MHL_UserIDs']

	if request and request.user.is_authenticated():
		# initialize to defaults
		context['current_site'] = ""
		context['current_practice'] = None
		context['current_time_zone'] = ""

		context['schedule_time_setting'] = 1

		if ('Provider' in request.session['MHL_Users']):
			provider = request.session['MHL_Users']['Provider']
			user = provider
			context['user_is_provider'] = True
			context['current_site'] = provider.current_site
			context['practice'] = provider.practices.filter(\
				organization_type__pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
			current_practice = provider.current_practice
			if current_practice and current_practice.organization_type\
				and RESERVED_ORGANIZATION_TYPE_ID_PRACTICE == current_practice.organization_type.id:
				context['current_practice'] = current_practice
			context['unread_msg_count'] = provider.vm_msgs.filter(read_flag=False).count()
			sites = user.sites.all()
			if (user.current_site):
				current_site = {'current': user.current_site.id}
				context['site_form'] = CurrentSiteForm(sites, initial=current_site)
			else:
				context['site_form'] = CurrentSiteForm(sites)
		#inna - add some info for office manager	
		if ('OfficeStaff' in request.session['MHL_Users']):
			#add by xlin in 20120328 to fix bug 580 that current site not show
			context['current_site'] = request.session['MHL_Users']['OfficeStaff'].current_site

			if ('OfficeStaff' in request.session['MHL_Users']):
				staff = request.session['MHL_Users']['OfficeStaff']
				user = staff
				context['current_practice'] = request.\
					session['MHL_Users']['OfficeStaff'].current_practice
				context['current_practice_can_have_any_staff'] = \
						context['current_practice'] and\
						context['current_practice'].can_have_any_staff()
				context['current_practice_can_have_any_provider'] = \
						context['current_practice'] and\
						context['current_practice'].can_have_any_provider()

			if  ('Office_Manager' in request.session['MHL_UserIDs']):
				context['user_is_office_manager'] = True
				office_staff = request.session['MHL_Users']['OfficeStaff']
				user = office_staff
				context['managed_practices'] = get_managed_practice(office_staff)
			else:
				context['user_is_office_staff'] = True
			sites = user.sites.all()
			if (user.current_site):
				current_site = {
								'current': user.current_site.id,
						}
				context['site_form'] = CurrentSiteForm(sites, initial=current_site)
			else:
				context['site_form'] = CurrentSiteForm(sites)

		context['mhl_user_displayName'] = get_fullname(request.session['MHL_Users']['MHLUser'])
		current_time_zone_key = getCurrentTimeZoneForUser(
				request.session['MHL_Users']['MHLUser'],
				current_practice=context['current_practice'])
		context['current_time_zone'] = getDisplayedTimeZone(current_time_zone_key)

		#add by xlin 121017 for todo1045
		if request.session['MHL_Users']['MHLUser'].time_setting:
			context['schedule_time_setting'] = 0
		else:
			context['schedule_time_setting'] = 1

		# TODO, if dcAdmin need custom_logo, remove the limitation.
		if "dcAdmin" not in request.path_info:
			context['prefer_logo'] = get_prefer_logo(request.session['MHL_Users']['MHLUser'].id)

		current_practice = context['current_practice']
		context['can_have_answering_service'] = False
		context["current_organization_type"] = ""
		if current_practice:
			context['can_have_answering_service'] = current_practice.\
				get_setting_attr('can_have_answering_service')
			context["current_organization_type"] = get_org_type_name(current_practice)

	return context
예제 #6
0
파일: templates.py 프로젝트: cnzhuran/mdcom
def processor(request, activeApp=None):
    """Creates a dictionary complete with standard MyHealth template definitions."""
    context = {}

    mobile_device_check(request, context)

    context['debug'] = settings.DEBUG
    context['DEBUG'] = settings.DEBUG

    context['SERVER_ADDRESS'] = settings.SERVER_ADDRESS
    context['SERVER_PROTOCOL'] = settings.SERVER_PROTOCOL
    context['SERVERVERSION'] = "v%s" % '.'.join(__version__.split('.')[0:3])

    if (not 'MHL_UserIDs' in request.session
            or not 'MHL_Users' in request.session):
        return context

    # Get user types
    context['sender_types'] = request.session['MHL_UserIDs']

    if request and request.user.is_authenticated():
        # initialize to defaults
        context['current_site'] = ""
        context['current_practice'] = None
        context['current_time_zone'] = ""

        context['schedule_time_setting'] = 1

        if ('Provider' in request.session['MHL_Users']):
            provider = request.session['MHL_Users']['Provider']
            user = provider
            context['user_is_provider'] = True
            context['current_site'] = provider.current_site
            context['practice'] = provider.practices.filter(\
             organization_type__pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
            current_practice = provider.current_practice
            if current_practice and current_practice.organization_type\
             and RESERVED_ORGANIZATION_TYPE_ID_PRACTICE == current_practice.organization_type.id:
                context['current_practice'] = current_practice
            context['unread_msg_count'] = provider.vm_msgs.filter(
                read_flag=False).count()
            sites = user.sites.all()
            if (user.current_site):
                current_site = {'current': user.current_site.id}
                context['site_form'] = CurrentSiteForm(sites,
                                                       initial=current_site)
            else:
                context['site_form'] = CurrentSiteForm(sites)
        #inna - add some info for office manager
        if ('OfficeStaff' in request.session['MHL_Users']):
            #add by xlin in 20120328 to fix bug 580 that current site not show
            context['current_site'] = request.session['MHL_Users'][
                'OfficeStaff'].current_site

            if ('OfficeStaff' in request.session['MHL_Users']):
                staff = request.session['MHL_Users']['OfficeStaff']
                user = staff
                context['current_practice'] = request.\
                 session['MHL_Users']['OfficeStaff'].current_practice
                context['current_practice_can_have_any_staff'] = \
                  context['current_practice'] and\
                  context['current_practice'].can_have_any_staff()
                context['current_practice_can_have_any_provider'] = \
                  context['current_practice'] and\
                  context['current_practice'].can_have_any_provider()

            if ('Office_Manager' in request.session['MHL_UserIDs']):
                context['user_is_office_manager'] = True
                office_staff = request.session['MHL_Users']['OfficeStaff']
                user = office_staff
                context['managed_practices'] = get_managed_practice(
                    office_staff)
            else:
                context['user_is_office_staff'] = True
            sites = user.sites.all()
            if (user.current_site):
                current_site = {
                    'current': user.current_site.id,
                }
                context['site_form'] = CurrentSiteForm(sites,
                                                       initial=current_site)
            else:
                context['site_form'] = CurrentSiteForm(sites)

        context['mhl_user_displayName'] = get_fullname(
            request.session['MHL_Users']['MHLUser'])
        current_time_zone_key = getCurrentTimeZoneForUser(
            request.session['MHL_Users']['MHLUser'],
            current_practice=context['current_practice'])
        context['current_time_zone'] = getDisplayedTimeZone(
            current_time_zone_key)

        #add by xlin 121017 for todo1045
        if request.session['MHL_Users']['MHLUser'].time_setting:
            context['schedule_time_setting'] = 0
        else:
            context['schedule_time_setting'] = 1

        # TODO, if dcAdmin need custom_logo, remove the limitation.
        if "dcAdmin" not in request.path_info:
            context['prefer_logo'] = get_prefer_logo(
                request.session['MHL_Users']['MHLUser'].id)

        current_practice = context['current_practice']
        context['can_have_answering_service'] = False
        context["current_organization_type"] = ""
        if current_practice:
            context['can_have_answering_service'] = current_practice.\
             get_setting_attr('can_have_answering_service')
            context["current_organization_type"] = get_org_type_name(
                current_practice)

    return context
예제 #7
0
파일: utils.py 프로젝트: DongHuaLu/mdcom
def getInvitationPendings(request_host, mhluser, role_user, user_type):
	user_type = int(user_type)
	invitations = []
	pend_practice = Pending_Association.objects.filter(to_user=mhluser).order_by('created_time')
	for p in pend_practice:
		from_user = p.from_user
		practice = p.practice_location
		logo_path = ImageHelper.get_image_by_type(practice.practice_photo, 
			size='Large', type='', resize_type='img_size_logo')
		if not logo_path == '':
			logo_path = '%s%s' % (request_host, logo_path)
		org_name = practice.practice_name
		member_invitations_content_context = {
			"invitation_sender": get_fullname(from_user),
			"role": 'provider',
			'org_type': practice.organization_type.name,
			"org_logo": logo_path,
			"org_name": org_name,
			'org_addr1': practice.practice_address1,
			'org_addr2': practice.practice_address2,
			'org_zip': practice.practice_zip,
			'org_id': practice.id,
			'org_city': practice.practice_city,
			'org_state': practice.practice_state,
		}
		member_invitations_content = render_to_string(
			'MHLOrganization/member_invitation_for_app.html', 
				member_invitations_content_context)
		p = {
				"pending_id": p.pk,
				"type": "1",
				"content": member_invitations_content
			}
		invitations.append(p)

	if user_type == USER_TYPE_OFFICE_MANAGER:
		managed_organizations = get_managed_practice(role_user)
		org_ids = [org.id for org in managed_organizations]
		pendings = Pending_Org_Association.objects.filter(
			to_practicelocation__id__in=org_ids).select_related('from_practicelocation', 
				'to_practicelocation')

		for p in pendings:
			logo_path = ImageHelper.get_image_by_type(
				p.from_practicelocation.practice_photo, "Middle", 'Practice', 'img_size_logo')
			if not logo_path == '':
				logo_path = '%s%s' % (request_host, logo_path)
			from_practicelocation_name = p.from_practicelocation.practice_name
			to_practicelocation_name = p.to_practicelocation.practice_name
			member_org_invitations_content_context = {
				'pending_id': p.id,
				'sender_name': get_fullname(p.sender),
				'from_practicelocation_logo': logo_path,
				'from_practicelocatin_type': p.from_practicelocation.organization_type.name,
				'from_practicelocation_name': from_practicelocation_name,
				'to_practicelocation_name': to_practicelocation_name,
				'to_practicelocatin_type': p.to_practicelocation.organization_type.name,
			}
			member_org_invitations_content = render_to_string(
				'MHLOrganization/member_org_invitation_for_app.html', 
					member_org_invitations_content_context)
			p = {
				"pending_id": p.pk,
				"type": "2",
				"content": member_org_invitations_content
			}
			invitations.append(p)
	call_group_penddings = []
	for p in get_call_group_penddings(mhluser.id):
		p_content = render_to_string(
				'App/call_group_invitation_for_app.html', p)
		call_group_penddings.append({
			"pending_id": p['id'],
			"type": "3",
			"content": p_content
		})

	return {'invitations': invitations,\
			'call_group_penddings': call_group_penddings}
예제 #8
0
def get_orgs_I_can_manage(mhluser_id, parent_id=None, org_id_excluded=None,\
			org_type_id=None, clear_no_type_org=None, org_name=None, root_id=None):
	#todo this function need to be refactored
	""" Get organization relation I can managed.
	:param mhluser_id: is an instance of MHLUser's id
	:param parent_id: is org's id
	:param org_id_excluded: exclude this organization and its descent organizations.
	:param clear_no_type_org:  if True, clear the organization who don't have sub types
	:param org_type_id: is org's type id
	:param org_name: now it's org's name
	:param format: the format of the result
	:returns: list of organization relation
	"""
	is_public = None
	if (Administrator.objects.filter(user__id=mhluser_id).exists()):
		q_f = Q()
		if org_id_excluded:
			org_ids_excluded = append_all_descent_organizations_ids([org_id_excluded])
			q_f = q_f & ~Q(organization__id__in=org_ids_excluded)
		org_relations = OrganizationRelationship.active_objects.filter(q_f)\
			.select_related('organization','parent')
	else:
		is_public = True
		office_staffs = OfficeStaff.objects.filter(user__id=mhluser_id)
		if len(office_staffs) == 1:
			office_staff = office_staffs[0]
		else:
			return []
		# get_managed_practice can only get the root managed practices
		managed_organizations = get_managed_practice(office_staff)
		org_ids = [org.id for org in managed_organizations]
		org_ids = append_all_descent_organizations_ids(org_ids, org_id_excluded=org_id_excluded)
		if org_ids:
			org_relations = OrganizationRelationship.active_objects.filter(\
				organization__id__in=org_ids).select_related('organization','parent')
		else:
			return []

	q_f = Q()
	if parent_id:
		q_f = q_f & Q(parent__id=parent_id)

	if org_type_id:
		q_f = q_f & Q(organization__organization_type__id=org_type_id)

	if clear_no_type_org:
		org_type_ids = OrganizationTypeSubs.objects.all().distinct()\
			.values_list("from_organizationtype__id", flat=True)

		type_ids_child_allow = None
		if org_id_excluded:
			try:
				org = PracticeLocation.objects.get(id=org_id_excluded)
				org_types = get_parent_types_by_typeid(org.organization_type.id, is_public=is_public)
				type_ids_child_allow = [org_type.id for org_type in org_types]
			except PracticeLocation.DoesNotExist:
				pass
		if type_ids_child_allow is not None:
			org_type_ids = list(set(org_type_ids) & set(type_ids_child_allow))

		if org_type_ids:
			q_f = q_f & Q(organization__organization_type__id__in=org_type_ids)

	if org_name:
		q_f = q_f & Q(organization__practice_name__icontains=org_name)

	org_relations = org_relations.filter(q_f)

	if root_id and root_id != RESERVED_ORGANIZATION_ID_SYSTEM:
		root_ids = get_all_child_org_ids([long(root_id)])
		org_relations = org_relations.filter(organization__pk__in=root_ids)
	
	org_relations = org_relations.order_by('organization__practice_name')
	return org_relations[:settings.MAX_ORG_TREE_NODES]
예제 #9
0
def practice_mgmt(request):
	user_type = int(request.user_type)
	role_user = request.role_user
	if (request.method != 'POST'):
		# Get the user's current practices, and list them.
		practices = role_user.practices.filter(organization_type__id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE)
		if USER_TYPE_OFFICE_MANAGER == user_type:
			practices = get_managed_practice(role_user)

		practices = [[p.id, p.practice_name] for p in practices]
		current_practice = role_user.current_practice
		if ('pk' in dir(current_practice)):
			current_practice = current_practice.pk
		response = {
					'data': {
							'practices':practices,
							'current_practice':current_practice,
						},
					'warnings': {},
				}
		return HttpResponse(content=json.dumps(response), mimetype='application/json')

	# office staff can't change current practice
	if USER_TYPE_OFFICE_STAFF == user_type:
		return err403(request)

	form = SetPracticeForm(request.POST, user_type=user_type)
	if (not form.is_valid()):
		return err_GE031(form)
	
	new_practice = form.cleaned_data['current_practice']
	response = {
			'data': {
				},
			'warnings':{}
		}
	res_data = response['data']
	old_cur_prac = role_user.current_practice
	if (new_practice == None):
		# Clearing the current practice.
		role_user.current_practice = None
		role_user.save()
		res_data = {
			'providers': [],
			'staff': [],
		}
	elif (new_practice in role_user.practices.values_list('id', flat=True)):
		# great, do the change.
		role_user.current_practice_id = new_practice
		role_user.save()
		res_data = {
			'providers': practice_providers(request, 
					return_python=True)['data']['users'],
			'staff': practice_staff(request, 
					return_python=True)['data']['users'],
		}

	if (old_cur_prac is None and new_practice is not None) \
		or (old_cur_prac is not None and not old_cur_prac.id == new_practice):
		# send notification to related users
		thread.start_new_thread(notify_user_tab_changed, (request.user.id,))
	return HttpResponse(content=json.dumps(response), mimetype='application/json')

	err_obj = {
		'errno': 'AM001',
		'descr': _('Invalid practice selection.'),
	}
	return HttpResponseBadRequest(content=json.dumps(err_obj), mimetype='application/json')