def get_pending_accoc_list(org_id, is_apply, mhluser=None, practice=None): providers = Provider.objects.all().values_list('user', flat=True) pend_assocs = Pending_Association.objects.filter(\ practice_location__pk=org_id).order_by('-resent_time') if is_apply: pend_assocs = pend_assocs.filter(~Q(to_user__in=providers)) else: pend_assocs = pend_assocs.filter(Q(to_user__in=providers)) return_set = [{ 'flag':0, 'pract_id':u.practice_location.id, 'req_name': get_fullname(u.from_user) if is_apply else get_fullname(u.to_user), 'pract_name':u.practice_location.practice_name, 'assoc_id':u.pk, 'invitation_time': str(convert_dt_to_utz( u.created_time, mhluser, practice)), 'resent_time':str(convert_dt_to_utz(u.resent_time , mhluser, practice)) if u.resent_time else None, 'delta_time': get_delta_time_string(u.resent_time, mhluser,\ practice) if u.resent_time else get_delta_time_string(u.created_time, mhluser, practice), 'flag':1 if is_apply else 0, } for u in pend_assocs] return return_set
def _set_staff_list(staff, current_user, strip_staff_mobile=True, strip_staff_pager=True): """ Returns staff response data. :param users: is a list of Provider/OfficeStaff/OfficeManager. :param current_user: current_user is an instance of Provider/OfficeStaff. pass strip_staff_mobile=True if you want all office staff users(exclude managers and above they) to come back without a mobile phone number defined. This is useful if you don't want the u to seem call-able. pass strip_staff_pager=True if you want all office staff users(exclude managers and above they) to come back without a pager number defined. This is useful if you don't want the u to seem call-able. :returns: user list. """ # current_user_mobile = getCurrentUserMobile(current_user) current_user_mobile = current_user.user.mobile_phone object_ids = get_my_favorite_ids(current_user.user, object_type_flag=OBJECT_TYPE_FLAG_MHLUSER) user_list = [] for s in staff: if (s.__class__.__name__ == 'Office_Manager'): user_info = { 'id': s.user.user.id, 'first_name': s.user.user.first_name, 'last_name': s.user.user.last_name, 'staff_type': _('Office Manager'), 'has_mobile': bool(s.user.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_pager': bool(s.user.pager) and settings.CALL_ENABLE, 'thumbnail': ImageHelper.get_image_by_type(s.user.user.photo, "Small", "Staff"), 'user_photo_m': ImageHelper.get_image_by_type(s.user.user.photo, "Middle", "Staff"), 'practice_photo': ImageHelper.get_image_by_type(s.user.current_practice.practice_photo, "Large", "Practice") \ if s.user.current_practice else "", 'prefer_logo': get_prefer_logo(s.user.user.id, current_practice=s.user.current_practice), 'is_favorite': s.user.user.id in object_ids, 'fullname':get_fullname(s.user.user) } else: user_info = { 'id': s.user.id, 'first_name': s.user.first_name, 'last_name': s.user.last_name, 'staff_type': _('Office Staff'), 'has_mobile': not strip_staff_mobile and bool(s.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_pager': not strip_staff_pager and bool(s.pager) and settings.CALL_ENABLE, 'thumbnail': ImageHelper.get_image_by_type(s.user.photo, "Small", "Staff"), 'user_photo_m': ImageHelper.get_image_by_type(s.user.photo, "Middle", "Staff"), 'practice_photo': ImageHelper.get_image_by_type(s.current_practice.practice_photo, "Large", "Practice") \ if s.current_practice else "", 'prefer_logo': get_prefer_logo(s.user.id, current_practice=s.current_practice), 'is_favorite': s.user.id in object_ids, 'fullname':get_fullname(s.user) } # TODO: Clean me up once we refactor the user classes. try: nurse = Nurse.objects.get(user=s) user_info['thumbnail'] = ImageHelper.get_image_by_type(s.user.photo, "Small", "Nurse") user_info['user_photo_m'] = ImageHelper.get_image_by_type(s.user.photo, "Middle", "Nurse"), except Nurse.DoesNotExist: pass user_list.append(user_info) return sorted_uses(user_list)
def member_org_rejected_invite(request, pending_id): mhluser_id = request.user.id first_name = request.user.first_name last_name = request.user.last_name fullname=get_fullname(request.user) ret_data = rejected_member_org_invite(mhluser_id, last_name, pending_id) return HttpResponse(json.dumps(ret_data), mimetype='application/json')
def refuseInvitation(request, pending_id): if (request.method != 'POST'): return err_GE002() form = HandleInviteForm(request.POST) if (not form.is_valid()): return err_GE031(form) invite_type = form.cleaned_data['invite_type'] mhluser_id = request.user.id first_name = request.user.first_name last_name = request.user.last_name fullname=get_fullname(request.user) ret_data = {} if invite_type == 1: ret_data = rejectToJoinPractice(request.user, pending_id) elif invite_type == 3: ret_data = join_call_group(pending_id, "Reject", request.role_user) else: ret_data = rejected_member_org_invite(mhluser_id, fullname, pending_id) response = { 'data': ret_data, 'warnings': {}, } return HttpResponse(content=json.dumps(response), mimetype='application/json')
def _set_providers_list(providers, current_user, has_specialty=True): """ Returns org members response data. :param providers: is a list of Physician/NP_PA. :param current_user: current_user is an instance of Provider/OfficeStaff. :returns: user list. """ object_ids = get_my_favorite_ids(current_user.user, object_type_flag=OBJECT_TYPE_FLAG_MHLUSER) # current_user_mobile = getCurrentUserMobile(current_user) current_user_mobile = current_user.user.mobile_phone user_list = [] for p in providers: user_info = { 'id': p.user.user.id, 'first_name': p.user.first_name, 'last_name': p.user.last_name, 'specialty': '', 'has_mobile': bool(p.user.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_pager': bool(p.user.pager) and settings.CALL_ENABLE, 'thumbnail': ImageHelper.get_image_by_type(p.user.user.photo, "Small", "Provider"), 'user_photo_m': ImageHelper.get_image_by_type(p.user.user.photo, "Middle", "Provider"), 'practice_photo': ImageHelper.get_image_by_type(p.user.current_practice.practice_photo, "Large", "Practice") \ if p.user.current_practice else "", 'prefer_logo': get_prefer_logo(p.user.user.id, current_practice=p.user.current_practice), 'is_favorite': p.user.user.id in object_ids, 'fullname': get_fullname(p.user) } if ('specialty' in dir(p) and p.specialty and has_specialty): user_info['specialty'] = p.get_specialty_display() if NP_PA.active_objects.filter(user=p.user): user_info['specialty'] = 'NP/PA/Midwife' user_list.append(user_info) return sorted_uses(user_list)
def appendSettingInfoToResponse(request, resp): if hasattr(resp, "content") and resp.content: try: response = json.loads(resp.content) response = setSystemInfoToResponse(response) settings_json = response["settings"] mhluser = request.user user_type = int(request.user_type) role_user = request.role_user if mhluser: settings_json['current_time_zone'] = getCurrentTimeZoneForUser(mhluser, role_user) settings_json['time_setting'] = mhluser.time_setting if mhluser.time_setting else 0 default_picture_type = "Provider" if USER_TYPE_DOCTOR != user_type: default_picture_type = "Staff" if Nurse.objects.filter(user=role_user).exists(): default_picture_type = "Nurse" settings_json['user_photo_m'] = ImageHelper.get_image_by_type( mhluser.photo, "Middle", default_picture_type) settings_json['real_name'] = get_fullname(mhluser) settings_json['prefer_logo'] = get_prefer_logo(mhluser.id) return resp.__class__(content=json.dumps(response), mimetype='application/json') except ValueError: pass return resp
def appendSettingInfoToResponse(request, resp): if hasattr(resp, "content") and resp.content: try: response = json.loads(resp.content) response = setSystemInfoToResponse(response) settings_json = response["settings"] mhluser = request.user user_type = int(request.user_type) role_user = request.role_user if mhluser: settings_json['current_time_zone'] = getCurrentTimeZoneForUser( mhluser, role_user) settings_json[ 'time_setting'] = mhluser.time_setting if mhluser.time_setting else 0 default_picture_type = "Provider" if USER_TYPE_DOCTOR != user_type: default_picture_type = "Staff" if Nurse.objects.filter(user=role_user).exists(): default_picture_type = "Nurse" settings_json['user_photo_m'] = ImageHelper.get_image_by_type( mhluser.photo, "Middle", default_picture_type) settings_json['real_name'] = get_fullname(mhluser) settings_json['prefer_logo'] = get_prefer_logo(mhluser.id) return resp.__class__(content=json.dumps(response), mimetype='application/json') except ValueError: pass return resp
def currentProviders(request): context = get_context_for_organization(request) practice = request.org firstName = request.REQUEST.get("firstName", "") lastName = request.REQUEST.get("lastName", "") filter = Q() if lastName == '': filter = Q(first_name__icontains=firstName) | \ Q(last_name__icontains=firstName) | Q(email__icontains=firstName) else: filter = Q(first_name__icontains=firstName) & Q(last_name__icontains=lastName) | \ Q(first_name__icontains=lastName) & Q(last_name__icontains=firstName) #return_set = Provider.active_objects.filter(Q(practices=practice)).filter(filter) return_set = Provider.objects.filter(Q(practices=practice)).filter(filter) context['total_count'] = len(return_set) context['index'] = index = int(request.REQUEST.get('index', 0)) context['count'] = count = int(request.REQUEST.get('count', 10)) return_set = [ { 'id':u.user.pk, 'name':get_fullname(u.user), 'status':u.user.is_active, #add by xlin for issue437 to show last login 'last_login':str(u.user.last_login.strftime('%m/%d/%Y')), 'practice':str(practice), } for u in return_set[index*count:(index+1)*count] ] context['datas'] = return_set return render_to_response('MHLOrganization/Member/member_provider_list.html', context)
def _set_org_members_list(users, current_user): """ Returns org members response data. :param users: is a list of Provider/OfficeStaff. :param current_user: current_user is an instance of Provider/OfficeStaff. :returns: user list. """ object_ids = get_my_favorite_ids(current_user.user, object_type_flag=OBJECT_TYPE_FLAG_MHLUSER) # current_user_mobile = getCurrentUserMobile(current_user) current_user_mobile = current_user.user.mobile_phone # current_user_pager = current_user.pager user_list = [] for u in users: prefer_logo = get_prefer_logo(u.user.id, current_practice=u.current_practice) user_info = { 'id': u.user.id, 'first_name': u.user.first_name, 'last_name': u.user.last_name, 'specialty': '', 'has_mobile': bool(u.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_pager': bool(u.pager) and settings.CALL_ENABLE, 'practice_photo': ImageHelper.get_image_by_type(u.current_practice.practice_photo, "Large", "Practice") \ if u.current_practice else "", 'practice_photo_m': ImageHelper.get_image_by_type(u.current_practice.practice_photo, "Middle", "Practice") \ if u.current_practice else "", 'prefer_logo': prefer_logo, 'is_favorite': u.user.id in object_ids, 'fullname':get_fullname(u.user) } if(u.__class__.__name__ == 'OfficeStaff'): user_info["user_type"] = _('Office Staff') user_info["thumbnail"] = ImageHelper.get_image_by_type(u.user.photo, "Small", "Staff") user_info["user_photo_m"] = ImageHelper.get_image_by_type(u.user.photo, "Middle", "Staff") if Office_Manager.objects.filter(user=u).exists(): user_info["user_type"] = _('Office Manager') else: # TODO: Clean me up once we refactor the u classes. try: nurse = Nurse.objects.get(user=u) user_info['thumbnail'] = ImageHelper.get_image_by_type(u.user.photo, "Small", "Nurse") user_info['user_photo_m'] = ImageHelper.get_image_by_type(u.user.photo, "Middle", "Nurse") except Nurse.DoesNotExist: pass elif(u.__class__.__name__ == 'Provider'): user_info["user_type"] = _('Provider') user_info["thumbnail"] = ImageHelper.get_image_by_type(u.user.photo, "Small", "Provider") user_info["user_photo_m"] = ImageHelper.get_image_by_type(u.user.photo, "Middle", "Provider") # TODO: Clean me up once we refactor the u classes. try: p = Physician.objects.get(user=u) user_info['specialty'] = p.get_specialty_display() except Physician.DoesNotExist: pass user_list.append(user_info) return sorted_uses(user_list)
def profile_view_provider(request, provider): context = get_context(request) context['profile'] = provider context['sites'] = context['profile'].sites context['practices'] = provider.practices.filter(\ organization_type__pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) # Other Organization context['other_orgs'] = get_other_organizations(provider.id) user = request.session['MHL_Users']['Provider'] states_of_licensure = user.licensure_states.all() states_of_licensure = [i.state for i in states_of_licensure] context['states_of_licensure'] = ', '.join(states_of_licensure) context['skill'] = user.skill context['fullname'] = get_fullname(provider) if user.user.refer_forward == 1: context['refer_forward'] = _( 'Both office manager and I get a copy of referrals') else: context['refer_forward'] = _( 'Send Referrals to my office manager only') if ('Physician' in request.session['MHL_Users']): phys = request.session['MHL_Users']['Physician'] clinical_clerk = phys.user.clinical_clerk context['physician'] = not clinical_clerk context['user'] = phys.user context['photo'] = ImageHelper.get_image_by_type(phys.user.photo, size='Middle', type='Provider') context['specialty'] = '' context['accepting_new_patients'] = '' if (not clinical_clerk): context['specialty'] = str(phys.get_specialty_display()) if (phys.accepting_new_patients): context['accepting_new_patients'] = _('Yes') else: context['accepting_new_patients'] = _('No') context['staff_type'] = str(phys.get_staff_type_display()) if ('NP_PA' in request.session['MHL_Users']): np_pas = get_object_or_404(NP_PA, user=request.user) context['photo'] = ImageHelper.get_image_by_type(np_pas.user.photo, size='Middle', type='Provider') context['user'] = np_pas.user context['time_setting'] = provider.user.get_time_setting_display() context['time_zone'] = provider.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] return render_to_response('Profile/profile_view.html', context)
def profile_view_provider(request, provider): context = get_context(request) context['profile'] = provider context['sites'] = context['profile'].sites context['practices'] = provider.practices.filter(\ organization_type__pk=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) # Other Organization context['other_orgs'] = get_other_organizations(provider.id) user = request.session['MHL_Users']['Provider'] states_of_licensure = user.licensure_states.all() states_of_licensure = [i.state for i in states_of_licensure] context['states_of_licensure'] = ', '.join(states_of_licensure) context['skill'] = user.skill context['fullname'] = get_fullname(provider) if user.user.refer_forward == 1: context['refer_forward'] = _('Both office manager and I get a copy of referrals') else: context['refer_forward'] = _('Send Referrals to my office manager only') if ('Physician' in request.session['MHL_Users']): phys = request.session['MHL_Users']['Physician'] clinical_clerk = phys.user.clinical_clerk context['physician'] = not clinical_clerk context['user'] = phys.user context['photo'] = ImageHelper.get_image_by_type(phys.user.photo, size='Middle', type='Provider') context['specialty'] = '' context['accepting_new_patients'] = '' if (not clinical_clerk): context['specialty'] = str(phys.get_specialty_display()) if (phys.accepting_new_patients): context['accepting_new_patients'] = _('Yes') else: context['accepting_new_patients'] = _('No') context['staff_type'] = str(phys.get_staff_type_display()) if ('NP_PA' in request.session['MHL_Users']): np_pas = get_object_or_404(NP_PA, user=request.user) context['photo'] = ImageHelper.get_image_by_type(np_pas.user.photo, size='Middle', type='Provider') context['user'] = np_pas.user context['time_setting']=provider.user.get_time_setting_display() context['time_zone']=provider.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] return render_to_response('Profile/profile_view.html', context)
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.") }
def send_mail_to_org_manager(org, subject, body_template_file, body_context): mgrs = get_all_practice_managers(org) for mgr in mgrs: body_context.update({ 'manager_fullname': get_fullname(mgr.user) }) body = render_to_string(body_template_file, body_context) send_mail( subject, body, settings.SERVER_EMAIL, [mgr.user.email], fail_silently=False )
def rejected_member_org_invite(mhluser_id, fullname, pending_id): pending = Pending_Org_Association.objects.filter(id=pending_id) if pending and len(pending) > 0: pending = pending[0] pending_log = Log_Org_Association( association_id = pending.id, from_practicelocation_id = pending.from_practicelocation_id, to_practicelocation_id=pending.to_practicelocation_id, sender_id=pending.sender_id, action_user_id = mhluser_id, action = 'REJ', create_time = time.time() ) pending_log.save() pending.delete() from_org = pending.from_practicelocation to_org = pending.to_practicelocation from_org_type = from_org.organization_type.name if from_org.organization_type else "" subject = _('DoctorCom: Request To Join %s Rejected') % (from_org_type) body_template_file = "MHLOrganization/MemberOrg/invite_email_reject.html" body_context = { 'manager_fullname':fullname, 'sender_fullname':get_fullname(pending.sender), 'to_org_name': to_org.practice_name, 'from_org_name': from_org.practice_name, } body = render_to_string(body_template_file, body_context) send_mail( subject, body, settings.SERVER_EMAIL, [pending.sender.email], fail_silently=False ) to_practicelocation_name = pending.to_practicelocation.practice_name return { "success": True, "message": _('You have declined %s\'s invitation.')\ %(to_practicelocation_name) } else: return { "success": False, "message": _('Your organization already has been added to the ' 'organization or you declined the invitation from other client.') }
def send_invite_mail_to_org_manager(pending): sender = pending.sender from_org = pending.from_practicelocation to_org = pending.to_practicelocation from_org_type = from_org.organization_type.name if from_org.organization_type else "" subject = _('DoctorCom: Invitation To Join %s') % str(from_org_type) body_template_file = "MHLOrganization/MemberOrg/invite_email_send.html" body_context = { 'sender_fullname':get_fullname(sender), "to_org_type": to_org.organization_type.name if to_org.organization_type else "", "to_org_name": to_org.practice_name, "from_org_type": from_org_type, "from_org_name": from_org.practice_name } send_mail_to_org_manager(to_org, subject, body_template_file, body_context)
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.") }
def profile_view_broker(request, broker): context = get_context(request) context['profile'] = broker states_of_licensure = broker.licensure_states.all() states_of_licensure = [i.state for i in states_of_licensure] context['states_of_licensure'] = ', '.join(states_of_licensure) context['photo'] = ImageHelper.get_image_by_type(broker.user.photo, 'Middle', 'Broker') context['time_setting']=broker.user.get_time_setting_display() context['time_zone']=broker.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] context['fullname'] = get_fullname(broker) return render_to_response('Profile/profile_view_broker.html', context)
def user_search(request): """ Query MHLUser by name (first and/or last) returning Providers and Staff """ if (request.method != 'POST'): return err_GE002() form = UserSearchForm(request.POST) if (not form.is_valid()): return err_GE031(form) curr_mobile = request.role_user.user.mobile_phone object_ids = get_my_favorite_ids(request.user, OBJECT_TYPE_FLAG_MHLUSER) limit = form.cleaned_data['limit'] if 'limit' in form.cleaned_data else None qry = generate_name_query(form.cleaned_data['name']) user_qry = search_mhluser(qry, limit=limit) response = {'data': {'count': 0, 'results': []}, 'warnings': {}} provs = Provider.objects.filter(user__in=user_qry) staffs = OfficeStaff.objects.filter(user__in=user_qry) phys = Physician.objects.filter(user__in=provs) provs = {prov.user_id: prov for prov in provs} staffs = {staf.user_id: staf for staf in staffs} phys = {phy.user_id: phy for phy in phys} for user in user_qry: prov = provs[user.id] if user.id in provs else None staf = staffs[user.id] if user.id in staffs else None if not (staf or prov): continue # only include staff/providers phy = phys[prov.id] if prov and prov.id in phys else None pract = (prov and prov.current_practice) or (staf and staf.current_practice) pphoto = pract and pract.practice_photo response['data']['results'].append({ 'id': user.id, 'first_name': user.first_name, 'last_name': user.last_name, 'has_mobile': True if user.mobile_phone and curr_mobile else False, 'has_pager': True if (prov and prov.pager) or (staf and staf.pager) else False, 'thumbnail': get_image_by_type(user.photo, "Small", "Provider"), 'user_photo_m': get_image_by_type(user.photo, "Middle", "Provider"), 'practice_photo': get_image_by_type(pphoto, "Large", "Practice"), 'prefer_logo': get_prefer_logo(user.id, pract) if pract else '', 'is_favorite': user.id in object_ids, 'specialty': phy.get_specialty_display() if phy else '', 'fullname':get_fullname(user) }) response['data']['count'] += 1 return HttpResponse(content=json.dumps(response), mimetype='application/json')
def profile_view_broker(request, broker): context = get_context(request) context['profile'] = broker states_of_licensure = broker.licensure_states.all() states_of_licensure = [i.state for i in states_of_licensure] context['states_of_licensure'] = ', '.join(states_of_licensure) context['photo'] = ImageHelper.get_image_by_type(broker.user.photo, 'Middle', 'Broker') context['time_setting'] = broker.user.get_time_setting_display() context['time_zone'] = broker.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] context['fullname'] = get_fullname(broker) return render_to_response('Profile/profile_view_broker.html', context)
def get_more_providers(sender_id, specialty, base_geo=None): """ Get more providers with this specialty :param sender_id: MHLUser's id, :type sender_id: int :param specialty: search condition - specialty :type specialty: str :returns: list of user information like following: [{ 'id': '', 'title': "" (ike "Dr."), 'name': '', 'distance': '', 'photo': '' }] :raise ValueError """ if sender_id is None or specialty is None: raise ValueError org_ids = get_user_network_org_ids(sender_id) phys = Physician.objects.filter(user__practices__id__in=org_ids, specialty=specialty).distinct() base_flag = 0 if base_geo is not None and "longit" in base_geo and "lat" in base_geo: longit = base_geo["longit"] lat = base_geo["lat"] if "base_flag" in base_geo: base_flag = int(base_geo["base_flag"]) if longit is None or lat is None: base_flag = 0 providers = [{ 'id': phy.user.id, 'title': "" if phy.user.clinical_clerk else "Dr.", 'name': get_fullname(phy.user), 'distance': get_distance(phy.user.lat, phy.user.longit, \ lat, longit) if base_flag > 0 else '', 'base_flag': base_flag if phy.user.lat and phy.user.longit else 0, 'specialty': phy.get_specialty_display(), 'photo': ImageHelper.get_image_by_type(phy.user.photo, "Middle", "Provider") } for phy in phys] providers = sorted(providers, key=lambda k: k['distance']) return providers
def search_by_name_old(request): if (request.method == 'POST'): form = nameSearchFormOld(request.POST) else: form = nameSearchFormOld(request.GET) if (form.is_valid()): name = form.cleaned_data['q'] limit = form.cleaned_data['limit'] user_qry = search_by_name(name, limit) return_obj = [[u.pk, get_fullname(u)] for u in user_qry] return_obj = ['ok', return_obj] return HttpResponse(json.dumps(return_obj), mimetype='application/json') else: # if (not form.is_valid()) return HttpResponse(json.dumps( ['err', _('A server error has occurred.')]), mimetype='application/json')
def search_by_name_old(request): if (request.method == 'POST'): form = nameSearchFormOld(request.POST) else: form = nameSearchFormOld(request.GET) if (form.is_valid()): name = form.cleaned_data['q'] limit = form.cleaned_data['limit'] user_qry = search_by_name(name, limit) return_obj = [ [ u.pk, get_fullname(u) ] for u in user_qry] return_obj = ['ok', return_obj] return HttpResponse(json.dumps(return_obj), mimetype='application/json') else: # if (not form.is_valid()) return HttpResponse(json.dumps(['err', _('A server error has occurred.')]), mimetype='application/json')
def profile_view_staff(request, staff): context = get_context(request) context['profile'] = staff context['sites'] = staff.sites #add by xlin 20120718 nurse = Nurse.objects.filter(user=staff) context['fullname'] = get_fullname(staff) if nurse: context['photo'] = ImageHelper.get_image_by_type( staff.user.photo, size='Middle', type='Nurse') else: context['photo'] = ImageHelper.get_image_by_type( staff.user.photo, size='Middle', type='Staff') context['time_setting']=staff.user.get_time_setting_display() context['time_zone']=staff.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] return render_to_response('Profile/profile_view_staff.html', context)
def profile_view_staff(request, staff): context = get_context(request) context['profile'] = staff context['sites'] = staff.sites #add by xlin 20120718 nurse = Nurse.objects.filter(user=staff) context['fullname'] = get_fullname(staff) if nurse: context['photo'] = ImageHelper.get_image_by_type(staff.user.photo, size='Middle', type='Nurse') else: context['photo'] = ImageHelper.get_image_by_type(staff.user.photo, size='Middle', type='Staff') context['time_setting'] = staff.user.get_time_setting_display() context['time_zone'] = staff.user.get_time_zone_display() context['language'] = LANGUAGE[settings.FORCED_LANGUAGE_CODE] return render_to_response('Profile/profile_view_staff.html', context)
def get_my_favorite(owner, object_type_flag=None, html=False, can_send_refer=True, show_picture=False): """ Get my favorite list. :param owner: is an instance of MHLUser :param object_type_flag: the flag of favorite object, refer to OBJECT_TYPE_FLAG_OPTS. :param html: return style: if html is True, then return favorite list as html style. :param can_send_refer: whether can send refer :param show_picture: whether show picture in list :returns: list of favorite or html string """ if not owner or not isinstance(owner, MHLUser): raise ValueError current_user_mobile = owner.mobile_phone q_t = Q(owner=owner) if object_type_flag: object_type_flag = int(object_type_flag) type = OBJECT_TYPE_FLAGS[object_type_flag] q_t = q_t & Q(object_type__model=type) favorites = Favorite.objects.filter(q_t).select_related("object_type") providers = Provider.objects.all().select_related("user", "current_practice") provider_dict = _user_list_to_dict(providers) # physician_user_ids = Physician.objects.all().values_list('user_id', flat=True) # nppa_user_ids = NP_PA.objects.all().values_list('user_id', flat=True) staffs = OfficeStaff.objects.all().select_related("user", "current_practice") staff_dict = _user_list_to_dict(staffs) manager_ids = Office_Manager.active_objects.all().values_list( 'user_id', 'practice') manager_user_ids = [] manager_practice_ids = [] for ids in manager_ids: manager_user_ids.append(ids[0]) manager_practice_ids.append(ids[1]) nurse_user_ids = Nurse.objects.all().values_list('user_id', flat=True) # dietician_user_ids = Dietician.objects.all().values_list('user_id', flat=True) ret_favorites = [] for fav in favorites: try: obj = fav.object if not obj: continue obj_id = fav.object_id object_type_flag = OBJECT_TYPES[fav.object_type.model] object_name = '' object_name_web_display = '' object_type_display = '' photo = '' photo_m = '' prefer_logo = '' call_available = False msg_available = False pager_available = False refer_available = False refer_displayable = False current_practice = None if OBJECT_TYPE_FLAG_MHLUSER == object_type_flag: object_name_web_display = object_name = get_fullname(obj) object_type_display = _("User") call_available = bool(obj.mobile_phone) and bool( current_user_mobile) and settings.CALL_ENABLE msg_available = True if obj_id in provider_dict: object_type_display = _("Provider") if show_picture: photo = ImageHelper.get_image_by_type( obj.photo, "Small", "Provider") photo_m = ImageHelper.get_image_by_type( obj.photo, "Middle", "Provider") data = provider_dict[obj_id] refer_available = data["has_practice"] refer_displayable = can_send_refer pager_available = bool( data["pager"]) and settings.CALL_ENABLE current_practice = data["current_practice"] elif obj_id in staff_dict: object_type_display = _('Office Staff') if show_picture: photo = ImageHelper.get_image_by_type( obj.photo, "Small", "Staff") photo_m = ImageHelper.get_image_by_type( obj.photo, "Middle", "Staff") data = staff_dict[obj_id] if data['id'] in manager_user_ids: object_type_display = _('Office Manager') elif data['id'] in nurse_user_ids: if show_picture: photo = ImageHelper.get_image_by_type( obj.photo, "Small", "Nurse") photo_m = ImageHelper.get_image_by_type( obj.photo, "Middle", "Nurse") pager_available = bool( data["pager"]) and settings.CALL_ENABLE current_practice = data["current_practice"] if show_picture: prefer_logo = get_prefer_logo( obj_id, current_practice=current_practice) elif OBJECT_TYPE_FLAG_ORG == object_type_flag: object_name_web_display = object_name = obj.practice_name object_type_display = _("Organization") if obj.organization_type and obj.organization_type.name: object_type_display = obj.organization_type.name if show_picture: photo = ImageHelper.get_image_by_type( obj.practice_photo, "Large", 'Practice', 'img_size_practice') photo_m = ImageHelper.get_image_by_type( obj.practice_photo, "Middle", 'Practice', 'img_size_practice') call_available = (bool(obj.backline_phone) or bool(obj.practice_phone))\ and bool(current_user_mobile)\ and settings.CALL_ENABLE msg_available = obj_id in manager_practice_ids ret_favorites.append({ "object_name": object_name, "object_name_web_display": object_name_web_display, "object_type_flag": object_type_flag, "object_type_display": object_type_display, "object_id": fav.object_id, "photo": photo, "photo_m": photo_m, "prefer_logo": prefer_logo, "call_available": call_available, "msg_available": msg_available, "pager_available": pager_available, "refer_available": refer_available, "refer_displayable": refer_displayable }) except KeyError: pass ret_favorites = sorted(ret_favorites, key=lambda item: item['object_name'].lower()) if html: favorite_dict = {"favorites": ret_favorites} return render_to_string('my_favorite.html', favorite_dict) return ret_favorites
def get_my_favorite(owner, object_type_flag=None, html=False, can_send_refer=True, show_picture=False): """ Get my favorite list. :param owner: is an instance of MHLUser :param object_type_flag: the flag of favorite object, refer to OBJECT_TYPE_FLAG_OPTS. :param html: return style: if html is True, then return favorite list as html style. :param can_send_refer: whether can send refer :param show_picture: whether show picture in list :returns: list of favorite or html string """ if not owner or not isinstance(owner, MHLUser): raise ValueError current_user_mobile = owner.mobile_phone q_t = Q(owner=owner) if object_type_flag: object_type_flag = int(object_type_flag) type = OBJECT_TYPE_FLAGS[object_type_flag] q_t = q_t & Q(object_type__model=type) favorites = Favorite.objects.filter(q_t).select_related("object_type") providers = Provider.objects.all().select_related("user", "current_practice") provider_dict = _user_list_to_dict(providers) # physician_user_ids = Physician.objects.all().values_list('user_id', flat=True) # nppa_user_ids = NP_PA.objects.all().values_list('user_id', flat=True) staffs = OfficeStaff.objects.all().select_related("user", "current_practice") staff_dict = _user_list_to_dict(staffs) manager_ids = Office_Manager.active_objects.all().values_list('user_id', 'practice') manager_user_ids = [] manager_practice_ids = [] for ids in manager_ids: manager_user_ids.append(ids[0]) manager_practice_ids.append(ids[1]) nurse_user_ids = Nurse.objects.all().values_list('user_id', flat=True) # dietician_user_ids = Dietician.objects.all().values_list('user_id', flat=True) ret_favorites = [] for fav in favorites: try: obj = fav.object if not obj: continue obj_id = fav.object_id object_type_flag = OBJECT_TYPES[fav.object_type.model] object_name = '' object_name_web_display = '' object_type_display = '' photo = '' photo_m = '' prefer_logo = '' call_available = False msg_available = False pager_available = False refer_available = False refer_displayable = False current_practice = None if OBJECT_TYPE_FLAG_MHLUSER == object_type_flag: object_name_web_display = object_name = get_fullname(obj) object_type_display = _("User") call_available = bool(obj.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE msg_available = True if obj_id in provider_dict: object_type_display = _("Provider") if show_picture: photo = ImageHelper.get_image_by_type(obj.photo, "Small", "Provider") photo_m = ImageHelper.get_image_by_type(obj.photo, "Middle", "Provider") data = provider_dict[obj_id] refer_available = data["has_practice"] refer_displayable = can_send_refer pager_available = bool(data["pager"]) and settings.CALL_ENABLE current_practice = data["current_practice"] elif obj_id in staff_dict: object_type_display = _('Office Staff') if show_picture: photo = ImageHelper.get_image_by_type(obj.photo, "Small", "Staff") photo_m = ImageHelper.get_image_by_type(obj.photo, "Middle", "Staff") data = staff_dict[obj_id] if data['id'] in manager_user_ids: object_type_display = _('Office Manager') elif data['id'] in nurse_user_ids: if show_picture: photo = ImageHelper.get_image_by_type(obj.photo, "Small", "Nurse") photo_m = ImageHelper.get_image_by_type(obj.photo, "Middle", "Nurse") pager_available = bool(data["pager"]) and settings.CALL_ENABLE current_practice = data["current_practice"] if show_picture: prefer_logo = get_prefer_logo(obj_id, current_practice = current_practice) elif OBJECT_TYPE_FLAG_ORG == object_type_flag: object_name_web_display = object_name = obj.practice_name object_type_display = _("Organization") if obj.organization_type and obj.organization_type.name: object_type_display = obj.organization_type.name if show_picture: photo = ImageHelper.get_image_by_type(obj.practice_photo, "Large", 'Practice', 'img_size_practice') photo_m = ImageHelper.get_image_by_type(obj.practice_photo, "Middle", 'Practice', 'img_size_practice') call_available = (bool(obj.backline_phone) or bool(obj.practice_phone))\ and bool(current_user_mobile)\ and settings.CALL_ENABLE msg_available = obj_id in manager_practice_ids ret_favorites.append({ "object_name": object_name, "object_name_web_display": object_name_web_display, "object_type_flag": object_type_flag, "object_type_display": object_type_display, "object_id": fav.object_id, "photo": photo, "photo_m": photo_m, "prefer_logo": prefer_logo, "call_available": call_available, "msg_available": msg_available, "pager_available": pager_available, "refer_available": refer_available, "refer_displayable": refer_displayable }) except KeyError: pass ret_favorites = sorted(ret_favorites, key=lambda item: item['object_name'].lower()) if html: favorite_dict = {"favorites": ret_favorites} return render_to_string('my_favorite.html', favorite_dict) return ret_favorites
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}
def get_providers_by_conds(request): if (request.method == 'POST'): type = request.POST['type'] search_terms = unicode.split(request.POST['name']) q_1 = Q() q_2 = Q() if search_terms: if len(search_terms) == 1: first_name = search_terms[0] last_name2 = '' else: first_name = search_terms[0] last_name = search_terms[1:] last_name2 = ' '.join(last_name) if last_name2: q_2 = Q(user__first_name__icontains=first_name) \ & Q(user__last_name__icontains=last_name2) \ | Q(user__first_name__icontains=last_name2) \ & Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ & Q(user__user__last_name__icontains=last_name2) \ | Q(user__user__first_name__icontains=last_name2) \ & Q(user__user__last_name__icontains=first_name) else: q_2 = Q(user__first_name__icontains=first_name) \ | Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ | Q(user__user__last_name__icontains=first_name) physicians = [] np_pas = [] manager_user_ids = [] office_staffs = [] if type == 'providers': np_pas = NP_PA.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') physicians = Physician.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') elif type == 'staffs': manager_user_ids = Office_Manager.active_objects.filter(q_1).distinct().\ values_list("user__id", flat=True) office_staffs = OfficeStaff.active_objects.filter(q_2).distinct().\ select_related('user', 'user__user') else: np_pas = NP_PA.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') physicians = Physician.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') manager_user_ids = Office_Manager.active_objects.filter(q_1).\ distinct().values_list("user__id", flat=True) office_staffs = OfficeStaff.active_objects.filter(q_2).distinct().\ select_related('user', 'user__user') return_set = [] for phy in physicians: u = phy.user user_info = { 'id': u.user.id, 'fullname':get_fullname(u), 'user_type': _('Doctor'), 'office_address': ' '.join([u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip]), 'specialty': '' } if ('specialty' in dir(phy) and phy.specialty): user_info['specialty'] = phy.get_specialty_display() if u.clinical_clerk: user_info['user_type'] = _('Medical Student') return_set.append(user_info) for np_pa in np_pas: u = np_pa.user user_info = { 'id': u.user.id, 'fullname':get_fullname(u), 'user_type': _('NP/PA/Midwife'), 'office_address': ' '.join([u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip]), 'specialty': 'NP/PA/Midwife' } return_set.append(user_info) for staff in office_staffs: user_info = { 'id':staff.user.id, 'fullname':get_fullname(staff), 'user_type': _('Staff'), 'office_address': ' '.join([staff.user.address1, staff.user.address2, staff.user.city, staff.user.state, staff.user.zip]), 'specialty': 'N/A' } if len(manager_user_ids) > 0 and staff.id in manager_user_ids: user_info['user_type'] = _('Manager') return_set.append(user_info) return HttpResponse(json.dumps(sorted(return_set, key=lambda item: "%s" % (item['fullname']))))
def getEvents(request, practice_id, callgroup_id=None): """ gets events associated with a callgroup retuns eventList serialized in json format """ callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id) if (not canAccessMultiCallGroup(request.user, long(callgroup_id), practice_id)): return err403(request) fromDateTmp = datetime.date.today() - datetime.timedelta(days=15) # defaults toDateTmp = datetime.date.today() + datetime.timedelta(days=30) eventList = [] if request.method == 'POST': form = DateEntryForm(request.POST) # ok - checking for is_valid() on the form is buggy with DateTime - it seems?! if form.is_valid(): # get fromDate and toDate and fetch the events fromDateTmp = form.cleaned_data['fromDate'] logger.debug('fromDate from request is %s' % (fromDateTmp)) toDateTmp = form.cleaned_data['toDate'] logger.debug('toDate from request is %s' % (toDateTmp)) callGroupId = callgroup_id logger.debug('callGroupId from request is %d' % int(callGroupId)) user = MHLUser.objects.get(pk=request.user.pk) # get the user's callGroup id? # need to check if user is office manager or physician in the callGroup if (user): eventList = EventEntry.objects.filter( Q(eventStatus='1'), Q(callGroup=callGroupId), startDate__lt=toDateTmp, endDate__gt=fromDateTmp ) else: raise Exception('Only users can view scheduled events') data = serializers.serialize("json", eventList, fields=('oncallPerson', 'oncallPerson__user', 'eventType', 'startDate', 'endDate', 'checkString')) addData = json.loads(data) members = CallGroupMember.objects.filter( call_group__id=callgroup_id).values_list('member__user__id') for d in addData: id = d['fields']['oncallPerson'] user = MHLUser.objects.get(id=id) d['fields']['fullname'] = get_fullname(user) if (long(id),) in members: d['fields']['hasDeleted'] = 0 else: d['fields']['hasDeleted'] = 1 data = json.dumps(addData) logger.debug('user %s - got back %d events' % (user, eventList.count())) SessionHelper.clearSessionStack(request, SessionHelper.SCHEDULE_UNDOSTACK_NAME) SessionHelper.clearSessionStack(request, SessionHelper.SCHEDULE_REDOSTACK_NAME) return HttpResponse(content=json.dumps({'datas': data, 'undoSize': 0, 'redoSize': 0}), mimetype='application/json') else: r = HttpResponse() r.status_code = 403 return r else: form = DateEntryForm(initial={'fromDate': fromDateTmp, 'toDate': toDateTmp, }) return render_to_response("DateEntry.html", {'form': form, })
def getEvents(request, practice_id, callgroup_id=None): """ gets events associated with a callgroup retuns eventList serialized in json format """ callgroup_id = checkMultiCallGroupId(practice_id, callgroup_id) if (not canAccessMultiCallGroup(request.user, long(callgroup_id), practice_id)): return err403(request) fromDateTmp = datetime.date.today() - datetime.timedelta( days=15) # defaults toDateTmp = datetime.date.today() + datetime.timedelta(days=30) eventList = [] if request.method == 'POST': form = DateEntryForm(request.POST) # ok - checking for is_valid() on the form is buggy with DateTime - it seems?! if form.is_valid(): # get fromDate and toDate and fetch the events fromDateTmp = form.cleaned_data['fromDate'] logger.debug('fromDate from request is %s' % (fromDateTmp)) toDateTmp = form.cleaned_data['toDate'] logger.debug('toDate from request is %s' % (toDateTmp)) callGroupId = callgroup_id logger.debug('callGroupId from request is %d' % int(callGroupId)) user = MHLUser.objects.get(pk=request.user.pk) # get the user's callGroup id? # need to check if user is office manager or physician in the callGroup if (user): eventList = EventEntry.objects.filter(Q(eventStatus='1'), Q(callGroup=callGroupId), startDate__lt=toDateTmp, endDate__gt=fromDateTmp) else: raise Exception('Only users can view scheduled events') data = serializers.serialize( "json", eventList, fields=('oncallPerson', 'oncallPerson__user', 'eventType', 'startDate', 'endDate', 'checkString')) addData = json.loads(data) members = CallGroupMember.objects.filter( call_group__id=callgroup_id).values_list('member__user__id') for d in addData: id = d['fields']['oncallPerson'] user = MHLUser.objects.get(id=id) d['fields']['fullname'] = get_fullname(user) if (long(id), ) in members: d['fields']['hasDeleted'] = 0 else: d['fields']['hasDeleted'] = 1 data = json.dumps(addData) logger.debug('user %s - got back %d events' % (user, eventList.count())) SessionHelper.clearSessionStack( request, SessionHelper.SCHEDULE_UNDOSTACK_NAME) SessionHelper.clearSessionStack( request, SessionHelper.SCHEDULE_REDOSTACK_NAME) return HttpResponse(content=json.dumps({ 'datas': data, 'undoSize': 0, 'redoSize': 0 }), mimetype='application/json') else: r = HttpResponse() r.status_code = 403 return r else: form = DateEntryForm(initial={ 'fromDate': fromDateTmp, 'toDate': toDateTmp, }) return render_to_response("DateEntry.html", { 'form': form, })
def message_edit(request, message_id=None): """ Handles message composition, editing, and drafts. :param request: The HTTP request :type request: django.core.handlers.wsgi.WSGIRequest :param message_id: Message id :type message_id: int :returns: django.http.HttpResponse -- the result in an HttpResonse object :raises: InvalidRecipientException, Http404 """ context = get_context(request) context['show_subscribe'] = False context['ioerror'] = '' recipients = [] form_initial_data = {'recipients': None} current_site = None if ('Provider' in request.session['MHL_Users']): current_site = request.session['MHL_Users']['Provider'].current_site if ('OfficeStaff' in request.session['MHL_Users']): current_practice = request.session['MHL_Users']['OfficeStaff'].current_practice requestDataDict = request.GET if(request.method == 'POST'): requestDataDict = request.POST recipientsform = MessageOptionsForm(requestDataDict) if (recipientsform.is_valid()): data = recipientsform.cleaned_data if ('user_recipients' in recipientsform.cleaned_data and recipientsform.cleaned_data['user_recipients']): form_initial_data['user_recipient'] = recipientsform.cleaned_data['user_recipients'] if (type(form_initial_data['user_recipient']) is list): form_initial_data['user_recipient'] = form_initial_data['user_recipient'][0] context['user_recipient'] = MHLUser.objects.get(pk=form_initial_data['user_recipient']) user_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_recipients']) user_recipientst=[] for user_recipient in user_recipients: user_recipientst=[{ 'id':user_recipient.id, 'fullname':get_fullname(user_recipient) }] context['user_recipients']=user_recipientst user_cc_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_cc_recipients']) user_cc_recipientst=[] for user_cc_recipient in user_cc_recipients: user_cc_recipientst=[{ 'id':user_cc_recipient.id, 'fullname':get_fullname(user_cc_recipient) }] context['user_cc_recipients']=user_cc_recipientst if 'msg_prefix' in data and data['msg_prefix']: user_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_recipients']) user_cc_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_cc_recipients']) elif ('practice_recipients' in recipientsform.cleaned_data and recipientsform.cleaned_data['practice_recipients']): form_initial_data['practice_recipient'] = recipientsform.cleaned_data['practice_recipients'] if (type(form_initial_data['practice_recipient']) is list): form_initial_data['practice_recipient'] = form_initial_data['practice_recipient'][0] context['practice_recipient'] = PracticeLocation.objects.get( pk=form_initial_data['practice_recipient']) if 'msg_id' in data and data['msg_id'] and 'msg_prefix' in data and data['msg_prefix']: origin_msg = Message.objects.get(uuid=data['msg_id']) if data['msg_prefix'] == "RE": form_initial_data['subject'] = get_format_subject( origin_msg.subject, data['msg_prefix']) elif data['msg_prefix'] == "FW": origin_attachment = MessageAttachment.objects.filter(message=origin_msg) file_list = [] for att in origin_attachment: f = att.get_content_file(request) file_name = FileHelper.generateTempFile(f, utils.get_user_key(request)) file_list.append( { 'file_saved_name': file_name, 'file_display_name': att.decrypt_filename(request), 'file_charset': att.charset, 'file_size': att.size, }) refer = MessageRefer.objects.filter(message=origin_msg) if refer: f = refer[0].decrypt_file(request) file_name = FileHelper.generateTempFile(f, utils.get_user_key(request)) file_list.append( { 'file_saved_name': file_name, 'file_display_name': 'refer.pdf', 'file_charset': '', 'file_size': len(f) }) context['file_list'] = file_list form_initial_data['subject'] = get_format_subject( origin_msg.subject, data['msg_prefix']) msg_body = MessageBody.objects.filter(message=origin_msg)[0] form_initial_data['body'] = get_text_from_messge(request, origin_msg, msg_body, context['current_practice']) data['msg_id'] = '' # else: # raise Http404 data['user_recipients'] = ','.join(str(x) for x in data['user_recipients'] if x) data['practice_recipients'] = ','.join(str(x) for x in data['practice_recipients'] if x) context['recipientsform'] = MessageOptionsForm(initial=recipientsform.cleaned_data) if (request.method == 'POST'): form = MessageForm(request.POST, request.FILES) if (form.is_valid()): logger.debug('Form is valid') manager_list = [] if(form.cleaned_data['practice_recipient']): managers = Office_Manager.active_objects.filter( practice=form.cleaned_data['practice_recipient']) manager_list.extend(m.user.user.pk for m in managers) recipients, ccs = getFormatToAndCc(form.cleaned_data['user_recipients'], form.cleaned_data['user_cc_recipients'], manager_list=manager_list) # Build the message and body thread_uuid = recipientsform.cleaned_data['thread_uuid'] if \ recipientsform.cleaned_data['thread_uuid'] else uuid.uuid4().hex msg = Message( sender=request.user, sender_site=current_site, subject=form.cleaned_data['subject'], thread_uuid=thread_uuid, ) msg.save() msg_body = msg.save_body(form.cleaned_data['body']) for recipient in recipients: MessageRecipient(message=msg, user_id=recipient).save() for cc in ccs: MessageCC(message=msg, user_id=cc).save() len_attachments = len(request.POST.getlist('file_saved_name')) if can_send_msg_with_attachments(request.user, recipients, ccs, len_attachments) \ or 'Broker' in request.session['MHL_Users']: # Build the attachments attachments = save_attachments(request, context, msg, form) msg.send(request, msg_body, attachments) return HttpResponseRedirect('/') else: context['show_subscribe'] = True transaction.rollback() logger.debug('Form is invalid') file_saved_names = request.POST.getlist('file_saved_name') file_display_names = request.POST.getlist('file_display_name') file_charsets = request.POST.getlist('file_charset') file_sizes = request.POST.getlist('file_size') file_len = len(file_saved_names) file_list = [ { 'file_saved_name':file_saved_names[i], 'file_display_name':file_display_names[i], 'file_charset':file_charsets[i], 'file_size':file_sizes[i], } for i in range(file_len) ] context['file_list'] = file_list context['form'] = form if (not message_id and request.method == 'GET'): # clean temp files FileHelper.cleanTempFile() context['form'] = MessageForm(initial=form_initial_data) elif(message_id): # Grab the message in question msg = Message.objects.get(uuid=message_id) # Check to ensure that the user has rights to mess with this message if (request.user != msg.owner): errlib.err403(err_msg='') context['MAX_UPLOAD_SIZE'] = settings.MAX_UPLOAD_SIZE return render_to_response('DoctorCom/Messaging/MessageEditForm.html', context)
def refer_home(request): context = get_context(request) sender = None if ('Provider' in request.session['MHL_Users']): sender = request.session['MHL_Users']['Provider'] elif ('OfficeStaff' in request.session['MHL_Users']): sender = request.session['MHL_Users']['OfficeStaff'] if sender is None: return err403(request) mhluser = request.session['MHL_Users']['MHLUser'] sender_id = mhluser.id recipient_id = request.REQUEST.get("user_recipients", None) if not recipient_id: return HttpResponseRedirect('/') recipient_provider = None try: recipient_provider = Provider.objects.get(pk=recipient_id) except: return err403(request, err_msg=_("This recipient is not a Provider.")) recipient_pracs = recipient_provider.practices.filter( organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) if len(recipient_pracs) <= 0: return err403( request, err_msg=_( "This Provider has no organization that can be selected.")) common_org_ids = get_common_org_ids(sender_id, recipient_id) selected_prac_id_init = common_org_ids[0] if common_org_ids else None if selected_prac_id_init is None: selected_prac_id_init = recipient_pracs[0].id cli_form, dem_form, ins_form = get_refer_info(request, context) if request.method == "POST": if not PREVENT_REPEAT_COMMIT_TOKEN in request.session\ or not request.session[PREVENT_REPEAT_COMMIT_TOKEN]: context['user_recipients'] = recipient_id # context['message'] = MESSAGE_REPEAT_COMMIT return render_to_response('DoctorCom/Messaging/refer_success.html', context) if (cli_form.is_valid() and dem_form.is_valid() and\ ins_form.is_valid()): form_data = cli_form.cleaned_data form_data.update(dem_form.cleaned_data) form_data.update(ins_form.cleaned_data) cur_prac = sender.current_practice sel_practice = int(form_data['selected_practice']) if common_org_ids and len(common_org_ids) > 0: return save_refer(request, form_data, recipient_provider, context) phys = list(Physician.objects.filter(user=recipient_provider)) if len(phys) <= 0 or not phys[0].specialty: return save_refer(request, form_data, recipient_provider, context) base_geo = None if cur_prac: base_geo = { "longit": cur_prac.practice_longit, "lat": cur_prac.practice_lat, "base_flag": 1 } else: base_geo = { "longit": sender.user.longit, "lat": sender.user.lat, "base_flag": 2 } more_providers = get_more_providers(mhluser.id, phys[0].specialty, base_geo=base_geo) if not more_providers or len(more_providers) <= 0: return save_refer(request, form_data, recipient_provider, context) form_data["file_list"] = get_file_list(request) request.session[REFER_CACHE_SESSION_KEY] = form_data context['providers'] = more_providers context['recipient'] = get_fullname(recipient_provider) context['user_photo'] = ImageHelper.get_image_by_type( recipient_provider.photo, type="Provider") context['sel_practice'] = sel_practice context['user_recipients'] = recipient_id return render_to_response( 'DoctorCom/Messaging/refer_more_providers.html', context) else: request.session[PREVENT_REPEAT_COMMIT_TOKEN] = uuid.uuid4().hex get_recipient_info(request, recipient_provider, mhluser.mobile_phone, context,\ recipient_pracs, selected_practice_id=selected_prac_id_init) return render_to_response('DoctorCom/Messaging/refer.html', context)
def get_recipient_info(request, recipient_provider, current_user_mobile, context,\ recipient_pracs=None, selected_practice_id=None): """ GetRecipientInfo :param request: http request :type request: HttpRequest :param recipient_provider: Recipient info :type recipient_provider: Provider or int :param current_user_mobile: current_user_mobile :type current_user_mobile: string :param context: RequestContext :type context: dict :param recipient_pracs: practice list of recipient :type recipient_pracs: list of PracticeLocation :param selected_practice_id: selected practice id :type selected_practice_id: int :returns: None """ if recipient_provider: if not isinstance(recipient_provider, Provider): recipient_provider = int(recipient_provider) recipient_provider = get_object_or_404(Provider, pk=recipient_provider) phys = Physician.objects.filter(user=recipient_provider) if phys: phy = phys[0] clinical_clerk = phy.user.clinical_clerk context['specialty'] = "" if clinical_clerk \ else phy.get_specialty_display() context['title'] = "" if clinical_clerk else "Dr." context['practice_photo'] = get_prefer_logo( recipient_provider.user.id, current_practice=recipient_provider.current_practice) context['user_photo'] = ImageHelper.get_image_by_type( recipient_provider.photo, type='Provider') context['provider'] = recipient_provider context['fullname'] = get_fullname(recipient_provider) if not recipient_pracs: recipient_pracs = recipient_provider.practices.filter( organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) context['practices'] = recipient_pracs try: selected_practice = PracticeLocation.objects.get(\ pk=selected_practice_id) except: selected_practice = recipient_pracs[0] if recipient_pracs else None if selected_practice: context['selected_practice_id'] = selected_practice.id else: context['selected_practice_id'] = "" context['call_available'] = bool(recipient_provider.user.mobile_phone) and \ current_user_mobile and settings.CALL_ENABLE context['pager_available'] = bool(recipient_provider.pager) \ and settings.CALL_ENABLE practice_membersDict = dict() practice_members = all_staff_members(selected_practice) practice_membersDict['users'] = set_practice_members_result( practice_members, request) context['practice_members'] = render_to_string('allStaffs2.html', practice_membersDict)
def save_refer(request, data, recipient_provider, context, file_list=None): sender = None if ('Provider' in request.session['MHL_Users']): sender = request.session['MHL_Users']['Provider'] elif ('OfficeStaff' in request.session['MHL_Users']): sender = request.session['MHL_Users']['OfficeStaff'] if sender is None: return err403(request) form = MessageReferForm(data) if form.is_valid(): try: cur_prac = sender.current_practice user_recipients = data['user_recipients'] context['user_recipients'] = user_recipients sel_practice = int(data['selected_practice']) mhluser = request.session['MHL_Users']['MHLUser'] msg = Message(sender=request.user, subject=_('Refer')) msg.save() msg_body = msg.save_body(data['reason_of_refer']) forward_to_manager = True mgrs = list( Office_Manager.active_objects.filter( practice__pk=sel_practice)) if REFER_FORWARD_CHOICES_ONLY_MANAGER == recipient_provider.user.refer_forward \ and len(mgrs) > 0: forward_to_manager = False for recipient in mgrs: MessageRecipient(message=msg, user_id=recipient.user.user.id).save() else: MessageRecipient(message=msg, user_id=user_recipients).save() refer = form.save(commit=False) form.cleaned_data.update({ 'message': msg, 'status': 'NO', 'alternative_phone_number': '' }) refer = encrypt_object( MessageRefer, form.cleaned_data, opub=OwnerPublicKey.objects.get_pubkey(owner=request.user)) if file_list is None: file_list = get_file_list(request) attachments = generateAttachement(request, context, msg, file_list) msg.send(request, msg_body, attachment_objs=attachments, refer_objs=[refer]) refer.refer_pdf = refer.uuid if cur_prac: refer.practice = cur_prac refer.save() data['today'] = datetime.date.today() context['refer_form'] = data try: rec = MHLUser.objects.get(pk=data['user_recipients']) context['user_recipient_name'] = get_fullname(rec) except: pass if cur_prac: context['current_practice_photo'] = ImageHelper.get_image_by_type(\ cur_prac.practice_photo, size="Middle", type='Practice') context['current_practice'] = cur_prac else: context['current_practice_photo'] = "" context['current_practice'] = "" context['referring_physician_name'] = get_fullname(mhluser) context['physician_phone_number'] = '' if mhluser and mhluser.mobile_phone: context['physician_phone_number'] = mhluser.mobile_phone generate_pdf(refer, request, context) send_refer_forward(refer, request, data, mgrs=mgrs, forward_to_manager=forward_to_manager) request.session[REFER_CACHE_SESSION_KEY] = None request.session[PREVENT_REPEAT_COMMIT_TOKEN] = None except KeyInvalidException: context["err_message"] = _( "Sorry. Security Key Error. Please contact " "system administrator.") return render_to_response('DoctorCom/Messaging/refer_success.html', context)
def getUserInvitationPendings(mhluser, user_type, all_in_one=True): """ Get user's all invitation pendings list. :param mhluser: is an instance of MHLUser. :parm user_type: is user's type. About the number of user_type, please read USER_TYPE_CHOICES in the MHLogin.utils.contants.py :parm all_in_one: use only one key to store all types of pendings, or not. The items in the list like following structure: { "pending_id": pending id, "type": pending type, "content": { # some custom data, related pending type. }, } """ # get organization pendding list org_invitations = [] pend_org = Pending_Association.objects.filter(to_user=mhluser).exclude( practice_location__organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE).\ order_by('created_time') for p in pend_org: from_user = p.from_user org = p.practice_location p = { "pending_id": p.pk, "type": "Org", "content": { "invitation_sender": get_fullname(from_user), "org_logo": ImageHelper.get_image_by_type(org.practice_photo, size='Large', type='', resize_type='img_size_logo'), "org_name": org.practice_name, 'role': 'provider' }, } org_invitations.append(p) # get practice pendding list practice_invitations = [] if 1 == user_type: pend_practice = Pending_Association.objects.filter(to_user=mhluser, practice_location__organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE).\ order_by('created_time') for p in pend_practice: from_user = p.from_user practice = p.practice_location p = { "pending_id": p.pk, "type": "Practice", "content": { "invitation_sender": get_fullname(from_user), "role": 'provider', "practice_logo": ImageHelper.get_image_by_type(practice.practice_photo, size='Large', type='', resize_type='img_size_logo'), "practice_name": practice.practice_name, 'practice_addr1': practice.practice_address1, 'practice_addr2': practice.practice_address2, 'practice_zip': practice.practice_zip, 'practice_id': practice.id, 'practice_city': practice.practice_city, 'practice_state': practice.practice_state, }, } practice_invitations.append(p) if all_in_one: org_invitations.extend(practice_invitations) return {'invitations': org_invitations} else: return { 'org_invitationst': org_invitations, 'practice_invitations': practice_invitations }
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
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
def save_refer(request, data, recipient_provider, context, file_list=None): sender = None if ('Provider' in request.session['MHL_Users']): sender = request.session['MHL_Users']['Provider'] elif ('OfficeStaff' in request.session['MHL_Users']): sender = request.session['MHL_Users']['OfficeStaff'] if sender is None: return err403(request) form = MessageReferForm(data) if form.is_valid(): try: cur_prac = sender.current_practice user_recipients = data['user_recipients'] context['user_recipients'] = user_recipients sel_practice = int(data['selected_practice']) mhluser = request.session['MHL_Users']['MHLUser'] msg = Message(sender=request.user, subject=_('Refer')) msg.save() msg_body = msg.save_body(data['reason_of_refer']) forward_to_manager = True mgrs = list(Office_Manager.active_objects.filter(practice__pk=sel_practice)) if REFER_FORWARD_CHOICES_ONLY_MANAGER == recipient_provider.user.refer_forward \ and len(mgrs) > 0: forward_to_manager = False for recipient in mgrs: MessageRecipient(message=msg, user_id=recipient.user.user.id).save() else: MessageRecipient(message=msg, user_id=user_recipients).save() refer = form.save(commit=False) form.cleaned_data.update({ 'message': msg, 'status': 'NO', 'alternative_phone_number': '' }) refer = encrypt_object( MessageRefer, form.cleaned_data, opub=OwnerPublicKey.objects.get_pubkey(owner=request.user)) if file_list is None: file_list = get_file_list(request) attachments = generateAttachement(request, context, msg, file_list) msg.send(request, msg_body, attachment_objs=attachments, refer_objs=[refer]) refer.refer_pdf = refer.uuid if cur_prac: refer.practice = cur_prac refer.save() data['today'] = datetime.date.today() context['refer_form'] = data try: rec = MHLUser.objects.get(pk=data['user_recipients']) context['user_recipient_name'] = get_fullname(rec) except: pass if cur_prac: context['current_practice_photo'] = ImageHelper.get_image_by_type(\ cur_prac.practice_photo, size="Middle", type='Practice') context['current_practice'] = cur_prac else: context['current_practice_photo'] = "" context['current_practice'] = "" context['referring_physician_name'] = get_fullname(mhluser) context['physician_phone_number'] = '' if mhluser and mhluser.mobile_phone: context['physician_phone_number'] = mhluser.mobile_phone generate_pdf(refer, request, context) send_refer_forward(refer, request, data, mgrs=mgrs, forward_to_manager=forward_to_manager) request.session[REFER_CACHE_SESSION_KEY] = None request.session[PREVENT_REPEAT_COMMIT_TOKEN] = None except KeyInvalidException: context["err_message"] = _("Sorry. Security Key Error. Please contact " "system administrator.") return render_to_response('DoctorCom/Messaging/refer_success.html', context)
def get_all_providers_and_staffs(request): if (request.method != 'POST'): return err_GE002() response = { 'users': {} } practice = None try: practice = Provider.objects.get(pk=request.user).current_practice except: try: practice = OfficeStaff.objects.get(pk=request.user).current_practice except: pass q_1 = Q() q_2 = Q() if 'name' in request.POST: search_terms = unicode.split(request.POST['name']) if search_terms: if len(search_terms) == 1: first_name = search_terms[0] last_name2 = '' else: first_name = search_terms[0] last_name = search_terms[1:] last_name2 = ' '.join(last_name) if last_name2: q_2 = Q(user__first_name__icontains=first_name) \ & Q(user__last_name__icontains=last_name2) \ | Q(user__first_name__icontains=last_name2) \ & Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ & Q(user__user__last_name__icontains=last_name2) \ | Q(user__user__first_name__icontains=last_name2) \ & Q(user__user__last_name__icontains=first_name) else: q_2 = Q(user__first_name__icontains=first_name) \ | Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ | Q(user__user__last_name__icontains=first_name) np_pas = NP_PA.active_objects.filter(q_1).\ select_related('user', 'user__user', 'user__user__user') physicians = Physician.active_objects.filter(q_1).\ select_related('user', 'user__user', 'user__user__user') office_managers = Office_Manager.active_objects.\ filter(q_1).select_related('user', 'user__user') office_staffs = OfficeStaff.active_objects.filter(q_2).\ filter(practices=practice).select_related('user', 'user__user') return_set = [] for phy in physicians: u = phy.user user_info = { 'id': u.user.id, 'first_name': u.user.first_name, 'last_name': u.user.last_name, 'user_type': 'Physican', 'office_address': ' '.join([u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip]), 'specialty': _('N/A'), 'fullname':get_fullname(u.user) } if ('specialty' in dir(phy) and phy.specialty): user_info['specialty'] = phy.get_specialty_display() if u.clinical_clerk: user_info['specialty'] = '' user_info['user_type'] = 'Medical Student' return_set.append(user_info) for np_pa in np_pas: u = np_pa.user user_info = { 'id': u.user.id, 'first_name': u.user.first_name, 'last_name': u.user.last_name, 'user_type': 'NP/PA/Midwife', 'office_address': ' '.join([u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip]), 'specialty': 'NP/PA/Midwife', 'fullname':get_fullname(u.user) } return_set.append(user_info) for staff in office_staffs: user_info = { 'id': staff.user.id, 'first_name': staff.user.first_name, 'last_name': staff.user.last_name, 'user_type': 'Staff', 'office_address': ' '.join([staff.user.address1, staff.user.address2, staff.user.city, staff.user.state, staff.user.zip]), 'specialty': 'N/A', 'fullname':get_fullname(staff) } if office_managers.filter(user=staff).exists(): user_info['user_type'] = 'Manager' return_set.append(user_info) response['users'] = sorted_uses(return_set) return HttpResponse(json.dumps(response))
def get_recipient_info(request, recipient_provider, current_user_mobile, context,\ recipient_pracs=None, selected_practice_id=None): """ GetRecipientInfo :param request: http request :type request: HttpRequest :param recipient_provider: Recipient info :type recipient_provider: Provider or int :param current_user_mobile: current_user_mobile :type current_user_mobile: string :param context: RequestContext :type context: dict :param recipient_pracs: practice list of recipient :type recipient_pracs: list of PracticeLocation :param selected_practice_id: selected practice id :type selected_practice_id: int :returns: None """ if recipient_provider: if not isinstance(recipient_provider, Provider): recipient_provider = int(recipient_provider) recipient_provider = get_object_or_404(Provider, pk=recipient_provider) phys = Physician.objects.filter(user=recipient_provider) if phys: phy = phys[0] clinical_clerk = phy.user.clinical_clerk context['specialty'] = "" if clinical_clerk \ else phy.get_specialty_display() context['title'] = "" if clinical_clerk else "Dr." context['practice_photo'] = get_prefer_logo(recipient_provider.user.id, current_practice=recipient_provider.current_practice) context['user_photo'] = ImageHelper.get_image_by_type(recipient_provider.photo, type='Provider') context['provider'] = recipient_provider context['fullname']=get_fullname(recipient_provider) if not recipient_pracs: recipient_pracs = recipient_provider.practices.filter( organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) context['practices'] = recipient_pracs try: selected_practice = PracticeLocation.objects.get(\ pk=selected_practice_id) except: selected_practice = recipient_pracs[0] if recipient_pracs else None if selected_practice: context['selected_practice_id'] = selected_practice.id else: context['selected_practice_id'] = "" context['call_available'] = bool(recipient_provider.user.mobile_phone) and \ current_user_mobile and settings.CALL_ENABLE context['pager_available'] = bool(recipient_provider.pager) \ and settings.CALL_ENABLE practice_membersDict = dict() practice_members = all_staff_members(selected_practice) practice_membersDict['users'] = set_practice_members_result(practice_members, request) context['practice_members'] = render_to_string('allStaffs2.html', practice_membersDict)
def message_edit(request, message_id=None): """ Handles message composition, editing, and drafts. :param request: The HTTP request :type request: django.core.handlers.wsgi.WSGIRequest :param message_id: Message id :type message_id: int :returns: django.http.HttpResponse -- the result in an HttpResonse object :raises: InvalidRecipientException, Http404 """ context = get_context(request) context['show_subscribe'] = False context['ioerror'] = '' recipients = [] form_initial_data = {'recipients': None} current_site = None if ('Provider' in request.session['MHL_Users']): current_site = request.session['MHL_Users']['Provider'].current_site if ('OfficeStaff' in request.session['MHL_Users']): current_practice = request.session['MHL_Users'][ 'OfficeStaff'].current_practice requestDataDict = request.GET if (request.method == 'POST'): requestDataDict = request.POST recipientsform = MessageOptionsForm(requestDataDict) if (recipientsform.is_valid()): data = recipientsform.cleaned_data if ('user_recipients' in recipientsform.cleaned_data and recipientsform.cleaned_data['user_recipients']): form_initial_data['user_recipient'] = recipientsform.cleaned_data[ 'user_recipients'] if (type(form_initial_data['user_recipient']) is list): form_initial_data['user_recipient'] = form_initial_data[ 'user_recipient'][0] context['user_recipient'] = MHLUser.objects.get( pk=form_initial_data['user_recipient']) user_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_recipients']) user_recipientst = [] for user_recipient in user_recipients: user_recipientst = [{ 'id': user_recipient.id, 'fullname': get_fullname(user_recipient) }] context['user_recipients'] = user_recipientst user_cc_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_cc_recipients']) user_cc_recipientst = [] for user_cc_recipient in user_cc_recipients: user_cc_recipientst = [{ 'id': user_cc_recipient.id, 'fullname': get_fullname(user_cc_recipient) }] context['user_cc_recipients'] = user_cc_recipientst if 'msg_prefix' in data and data['msg_prefix']: user_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_recipients']) user_cc_recipients = MHLUser.objects.filter( pk__in=recipientsform.cleaned_data['user_cc_recipients']) elif ('practice_recipients' in recipientsform.cleaned_data and recipientsform.cleaned_data['practice_recipients']): form_initial_data[ 'practice_recipient'] = recipientsform.cleaned_data[ 'practice_recipients'] if (type(form_initial_data['practice_recipient']) is list): form_initial_data['practice_recipient'] = form_initial_data[ 'practice_recipient'][0] context['practice_recipient'] = PracticeLocation.objects.get( pk=form_initial_data['practice_recipient']) if 'msg_id' in data and data[ 'msg_id'] and 'msg_prefix' in data and data['msg_prefix']: origin_msg = Message.objects.get(uuid=data['msg_id']) if data['msg_prefix'] == "RE": form_initial_data['subject'] = get_format_subject( origin_msg.subject, data['msg_prefix']) elif data['msg_prefix'] == "FW": origin_attachment = MessageAttachment.objects.filter( message=origin_msg) file_list = [] for att in origin_attachment: f = att.get_content_file(request) file_name = FileHelper.generateTempFile( f, utils.get_user_key(request)) file_list.append({ 'file_saved_name': file_name, 'file_display_name': att.decrypt_filename(request), 'file_charset': att.charset, 'file_size': att.size, }) refer = MessageRefer.objects.filter(message=origin_msg) if refer: f = refer[0].decrypt_file(request) file_name = FileHelper.generateTempFile( f, utils.get_user_key(request)) file_list.append({ 'file_saved_name': file_name, 'file_display_name': 'refer.pdf', 'file_charset': '', 'file_size': len(f) }) context['file_list'] = file_list form_initial_data['subject'] = get_format_subject( origin_msg.subject, data['msg_prefix']) msg_body = MessageBody.objects.filter(message=origin_msg)[0] form_initial_data['body'] = get_text_from_messge( request, origin_msg, msg_body, context['current_practice']) data['msg_id'] = '' # else: # raise Http404 data['user_recipients'] = ','.join( str(x) for x in data['user_recipients'] if x) data['practice_recipients'] = ','.join( str(x) for x in data['practice_recipients'] if x) context['recipientsform'] = MessageOptionsForm( initial=recipientsform.cleaned_data) if (request.method == 'POST'): form = MessageForm(request.POST, request.FILES) if (form.is_valid()): logger.debug('Form is valid') manager_list = [] if (form.cleaned_data['practice_recipient']): managers = Office_Manager.active_objects.filter( practice=form.cleaned_data['practice_recipient']) manager_list.extend(m.user.user.pk for m in managers) recipients, ccs = getFormatToAndCc( form.cleaned_data['user_recipients'], form.cleaned_data['user_cc_recipients'], manager_list=manager_list) # Build the message and body thread_uuid = recipientsform.cleaned_data['thread_uuid'] if \ recipientsform.cleaned_data['thread_uuid'] else uuid.uuid4().hex msg = Message( sender=request.user, sender_site=current_site, subject=form.cleaned_data['subject'], thread_uuid=thread_uuid, ) msg.save() msg_body = msg.save_body(form.cleaned_data['body']) for recipient in recipients: MessageRecipient(message=msg, user_id=recipient).save() for cc in ccs: MessageCC(message=msg, user_id=cc).save() len_attachments = len(request.POST.getlist('file_saved_name')) if can_send_msg_with_attachments(request.user, recipients, ccs, len_attachments) \ or 'Broker' in request.session['MHL_Users']: # Build the attachments attachments = save_attachments(request, context, msg, form) msg.send(request, msg_body, attachments) return HttpResponseRedirect('/') else: context['show_subscribe'] = True transaction.rollback() logger.debug('Form is invalid') file_saved_names = request.POST.getlist('file_saved_name') file_display_names = request.POST.getlist('file_display_name') file_charsets = request.POST.getlist('file_charset') file_sizes = request.POST.getlist('file_size') file_len = len(file_saved_names) file_list = [{ 'file_saved_name': file_saved_names[i], 'file_display_name': file_display_names[i], 'file_charset': file_charsets[i], 'file_size': file_sizes[i], } for i in range(file_len)] context['file_list'] = file_list context['form'] = form if (not message_id and request.method == 'GET'): # clean temp files FileHelper.cleanTempFile() context['form'] = MessageForm(initial=form_initial_data) elif (message_id): # Grab the message in question msg = Message.objects.get(uuid=message_id) # Check to ensure that the user has rights to mess with this message if (request.user != msg.owner): errlib.err403(err_msg='') context['MAX_UPLOAD_SIZE'] = settings.MAX_UPLOAD_SIZE return render_to_response('DoctorCom/Messaging/MessageEditForm.html', context)
def refer_home(request): context = get_context(request) sender = None if ('Provider' in request.session['MHL_Users']): sender = request.session['MHL_Users']['Provider'] elif ('OfficeStaff' in request.session['MHL_Users']): sender = request.session['MHL_Users']['OfficeStaff'] if sender is None: return err403(request) mhluser = request.session['MHL_Users']['MHLUser'] sender_id = mhluser.id recipient_id = request.REQUEST.get("user_recipients", None) if not recipient_id: return HttpResponseRedirect('/') recipient_provider = None try: recipient_provider = Provider.objects.get(pk=recipient_id) except: return err403(request, err_msg=_("This recipient is not a Provider.")) recipient_pracs = recipient_provider.practices.filter( organization_type__id=RESERVED_ORGANIZATION_TYPE_ID_PRACTICE) if len(recipient_pracs) <= 0: return err403(request, err_msg=_("This Provider has no organization that can be selected.")) common_org_ids = get_common_org_ids(sender_id, recipient_id) selected_prac_id_init = common_org_ids[0] if common_org_ids else None if selected_prac_id_init is None: selected_prac_id_init = recipient_pracs[0].id cli_form, dem_form, ins_form = get_refer_info(request, context) if request.method == "POST": if not PREVENT_REPEAT_COMMIT_TOKEN in request.session\ or not request.session[PREVENT_REPEAT_COMMIT_TOKEN]: context['user_recipients'] = recipient_id # context['message'] = MESSAGE_REPEAT_COMMIT return render_to_response('DoctorCom/Messaging/refer_success.html', context) if (cli_form.is_valid() and dem_form.is_valid() and\ ins_form.is_valid()): form_data = cli_form.cleaned_data form_data.update(dem_form.cleaned_data) form_data.update(ins_form.cleaned_data) cur_prac = sender.current_practice sel_practice = int(form_data['selected_practice']) if common_org_ids and len(common_org_ids) > 0: return save_refer(request, form_data, recipient_provider, context) phys = list(Physician.objects.filter(user=recipient_provider)) if len(phys) <= 0 or not phys[0].specialty: return save_refer(request, form_data, recipient_provider, context) base_geo = None if cur_prac: base_geo = { "longit": cur_prac.practice_longit, "lat": cur_prac.practice_lat, "base_flag": 1 } else: base_geo = { "longit": sender.user.longit, "lat": sender.user.lat, "base_flag": 2 } more_providers = get_more_providers( mhluser.id, phys[0].specialty, base_geo=base_geo) if not more_providers or len(more_providers) <= 0: return save_refer(request, form_data, recipient_provider, context) form_data["file_list"] = get_file_list(request) request.session[REFER_CACHE_SESSION_KEY] = form_data context['providers'] = more_providers context['recipient'] = get_fullname(recipient_provider) context['user_photo'] = ImageHelper.get_image_by_type( recipient_provider.photo, type="Provider") context['sel_practice'] = sel_practice context['user_recipients'] = recipient_id return render_to_response( 'DoctorCom/Messaging/refer_more_providers.html', context) else: request.session[PREVENT_REPEAT_COMMIT_TOKEN] = uuid.uuid4().hex get_recipient_info(request, recipient_provider, mhluser.mobile_phone, context,\ recipient_pracs, selected_practice_id=selected_prac_id_init) return render_to_response('DoctorCom/Messaging/refer.html', context)
def get_providers_by_conds(request): if (request.method == 'POST'): type = request.POST['type'] search_terms = unicode.split(request.POST['name']) q_1 = Q() q_2 = Q() if search_terms: if len(search_terms) == 1: first_name = search_terms[0] last_name2 = '' else: first_name = search_terms[0] last_name = search_terms[1:] last_name2 = ' '.join(last_name) if last_name2: q_2 = Q(user__first_name__icontains=first_name) \ & Q(user__last_name__icontains=last_name2) \ | Q(user__first_name__icontains=last_name2) \ & Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ & Q(user__user__last_name__icontains=last_name2) \ | Q(user__user__first_name__icontains=last_name2) \ & Q(user__user__last_name__icontains=first_name) else: q_2 = Q(user__first_name__icontains=first_name) \ | Q(user__last_name__icontains=first_name) q_1 = Q(user__user__first_name__icontains=first_name) \ | Q(user__user__last_name__icontains=first_name) physicians = [] np_pas = [] manager_user_ids = [] office_staffs = [] if type == 'providers': np_pas = NP_PA.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') physicians = Physician.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') elif type == 'staffs': manager_user_ids = Office_Manager.active_objects.filter(q_1).distinct().\ values_list("user__id", flat=True) office_staffs = OfficeStaff.active_objects.filter(q_2).distinct().\ select_related('user', 'user__user') else: np_pas = NP_PA.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') physicians = Physician.active_objects.filter(q_1).distinct().\ select_related('user', 'user__user', 'user__user__user') manager_user_ids = Office_Manager.active_objects.filter(q_1).\ distinct().values_list("user__id", flat=True) office_staffs = OfficeStaff.active_objects.filter(q_2).distinct().\ select_related('user', 'user__user') return_set = [] for phy in physicians: u = phy.user user_info = { 'id': u.user.id, 'fullname': get_fullname(u), 'user_type': _('Doctor'), 'office_address': ' '.join([ u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip ]), 'specialty': '' } if ('specialty' in dir(phy) and phy.specialty): user_info['specialty'] = phy.get_specialty_display() if u.clinical_clerk: user_info['user_type'] = _('Medical Student') return_set.append(user_info) for np_pa in np_pas: u = np_pa.user user_info = { 'id': u.user.id, 'fullname': get_fullname(u), 'user_type': _('NP/PA/Midwife'), 'office_address': ' '.join([ u.user.address1, u.user.address2, u.user.city, u.user.state, u.user.zip ]), 'specialty': 'NP/PA/Midwife' } return_set.append(user_info) for staff in office_staffs: user_info = { 'id': staff.user.id, 'fullname': get_fullname(staff), 'user_type': _('Staff'), 'office_address': ' '.join([ staff.user.address1, staff.user.address2, staff.user.city, staff.user.state, staff.user.zip ]), 'specialty': 'N/A' } if len(manager_user_ids) > 0 and staff.id in manager_user_ids: user_info['user_type'] = _('Manager') return_set.append(user_info) return HttpResponse( json.dumps( sorted(return_set, key=lambda item: "%s" % (item['fullname']))))
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}
def user_info(request, user_id): current_user = request.role_user current_user_mobile = current_user.user.mobile_phone try: mhluser = MHLUser.objects.get(pk=user_id) except MHLUser.DoesNotExist: err_obj = { 'errno': 'PF001', 'descr': _('User not found.'), } return HttpResponseBadRequest(content=json.dumps(err_obj), mimetype='application/json') response = { 'data': { 'first_name': mhluser.first_name, 'last_name': mhluser.last_name, 'specialty': _('N/A'), 'mdcom_phone': '', # In order to avoid modifying client's code, don't change the key. 'office_address1': mhluser.address1, 'office_address2': mhluser.address2, 'office_city': mhluser.city, 'office_state': mhluser.state, 'office_zip': mhluser.zip, 'accepting_patients': False, 'photo': ''.join([settings.MEDIA_URL, 'images/photos/generic_128.png']), 'current_practice': {}, 'skill': mhluser.skill, 'has_mobile': False, 'has_pager': False, 'custom_logos': [], 'is_favorite': is_favorite(request.user, OBJECT_TYPE_FLAG_MHLUSER, user_id), 'fullname':get_fullname(mhluser) }, 'warnings': {}, } data = response['data'] current_practice = None try: p = Provider.objects.get(user=mhluser) except Provider.DoesNotExist: p = None if (p): # data['office_address1'] = p.office_address1 # data['office_address2'] = p.office_address2 # data['office_city'] = p.office_city # data['office_state'] = p.office_state # data['office_zip'] = p.office_zip data['mdcom_phone'] = p.mdcom_phone data['photo'] = get_image_by_type(mhluser.photo, "Middle", "Provider") data['user_photo_m'] = get_image_by_type(mhluser.photo, "Middle", "Provider") data['current_practice'] = get_current_practice_for_user( p.current_practice, current_user, USER_TYPE_DOCTOR) data['has_mobile'] = bool(mhluser.mobile_phone) and \ bool(current_user_mobile) and settings.CALL_ENABLE data['has_pager'] = bool(p.pager) and settings.CALL_ENABLE current_practice = p.current_practice phys = Physician.objects.filter(user=p) if (phys.exists()): phys = phys.get() if phys.user.clinical_clerk: data['specialty'] = '' elif phys.specialty: data['specialty'] = phys.get_specialty_display() data['accepting_patients'] = phys.accepting_new_patients nppas = NP_PA.active_objects.filter(user=p) if (nppas.exists()): data['specialty'] = 'NP/PA/Midwife' try: ostaff = OfficeStaff.objects.get(user=mhluser) # data['office_address1'] = ostaff.office_address1 # data['office_address2'] = ostaff.office_address2 # data['office_city'] = ostaff.office_city # data['office_state'] = ostaff.office_state # data['office_zip'] = ostaff.office_zip data['photo'] = get_image_by_type(mhluser.photo, "Middle", "Staff") data['user_photo_m'] = get_image_by_type(mhluser.photo, "Middle", "Staff") data['specialty'] = "Office Staff" data['current_practice'] = get_current_practice_for_user(ostaff.current_practice, current_user, USER_TYPE_OFFICE_STAFF) if ostaff.current_practice: data['mdcom_phone'] = ostaff.current_practice.mdcom_phone try: Nurse.objects.get(user=ostaff) data['photo'] = get_image_by_type(mhluser.photo, "Middle", "Nurse") data['user_photo_m'] = get_image_by_type(mhluser.photo, "Middle", "Nurse") except Nurse.DoesNotExist: pass except OfficeStaff.DoesNotExist: ostaff = None if (ostaff): current_practice = ostaff.current_practice if Office_Manager.objects.filter(user=ostaff).exists(): data['photo'] = get_image_by_type(mhluser.photo, "Middle", "Staff") data['user_photo_m'] = get_image_by_type(mhluser.photo, "Middle", "Staff") data['specialty'] = "Office Manager" data['has_mobile'] = bool(mhluser.mobile_phone) and \ bool(current_user_mobile) and settings.CALL_ENABLE data['has_pager'] = bool(ostaff.pager) and settings.CALL_ENABLE data['other_orgs'] = get_other_organizations(user_id) data['custom_logos'] = get_custom_logos(user_id, current_practice=current_practice) return HttpResponse(content=json.dumps(response), mimetype='application/json')