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 getOrganizationsOfUser(mhluser, current_practice=None): current_practice_id = None if current_practice: current_practice_id = current_practice.id orgs = which_orgs_contain_this_user(mhluser.id, exclude_org_ids=current_practice_id) if orgs and len(orgs): return [{ 'id': u.pk, 'name': u.practice_name, 'logo': ImageHelper.get_image_by_type(u.practice_photo, "Small", '', resize_type='img_size_logo'), 'logo_middle': ImageHelper.get_image_by_type(u.practice_photo, "Middle", '', resize_type='img_size_logo'), } for u in orgs] else: return []
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 getOrganizationsOfUser(mhluser, current_practice=None): current_practice_id = None if current_practice: current_practice_id = current_practice.id orgs = which_orgs_contain_this_user(mhluser.id, exclude_org_ids=current_practice_id) if orgs and len(orgs): return [{ 'id':u.pk, 'name':u.practice_name, 'logo': ImageHelper.get_image_by_type(u.practice_photo, "Small", '', resize_type='img_size_logo'), 'logo_middle': ImageHelper.get_image_by_type(u.practice_photo, "Middle", '', resize_type='img_size_logo'), }for u in orgs] else: return []
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 _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 setSubProviderResultList(providers, current_user=None): current_user_mobile = None if current_user: current_user_mobile = current_user.user.mobile_phone user_list = [] for p in providers: call_available = bool(p.user.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE pager_available = bool(p.user.pager) and settings.CALL_ENABLE photo = ImageHelper.get_image_by_type(p.user.user.photo, "Small", "Provider") user_info = { 'id': p.user.user.id, 'first_name': p.user.first_name, 'last_name': p.user.last_name, 'specialty': '', 'call_available': call_available, 'pager_available': pager_available, # reserved 'refer_available': True, # 'msg_available': True, 'photo': photo, # Following three keys's name is not very good. As compatibility reason, reserve them. # We use call_available, pager_available, photo replace has_mobile, has_pager, thumbnail 'has_mobile': call_available, 'has_pager': pager_available, 'thumbnail': photo, } if ('specialty' in dir(p) and p.specialty): user_info['specialty'] = p.get_specialty_display() else: user_info['specialty'] = "NP/PA/Midwife" user_list.append(user_info) return user_list
def member_org_invite_step2(request): context = get_context_for_organization(request) form = OrganizationSearchForm(request.POST) context["org_list"] = [] context["org_count"] = 0 if form.is_valid(): org_name = form.cleaned_data["org_name"] current_org_id = request.org.id pending_ids = Pending_Org_Association.objects.filter( from_practicelocation__id=current_org_id).\ values_list("to_practicelocation__id", flat=True) member_ids = OrganizationMemberOrgs.objects.filter( from_practicelocation__id=current_org_id).\ values_list("to_practicelocation__id", flat=True) orgs = PracticeLocation.objects.filter(practice_name__icontains=org_name).\ exclude(id__in=member_ids).exclude(id__in=pending_ids).exclude(id=request.org.id) orgs = [ { 'id': org.id, 'practice_name': org.practice_name, 'practice_address1': org.practice_address1, 'practice_address2': org.practice_address2, 'practice_city': org.practice_city, 'practice_state': org.practice_state, 'practice_photo': ImageHelper.get_image_by_type(org.practice_photo, "Middle", 'Practice', 'img_size_practice') } for org in orgs] context["org_list"] = orgs context["org_count"] = len(orgs) return render_to_response('MHLOrganization/MemberOrg/invite_step2.html', context)
def member_org_invite_incoming(request): context = get_context(request) if ('Office_Manager' in request.session['MHL_Users']): manager = request.session['MHL_Users']['Office_Manager'] # get_managed_practice can only get the root managed practices managed_organizations = get_managed_practice(manager.user) org_ids = [org.id for org in managed_organizations] pendings = Pending_Org_Association.objects.filter(to_practicelocation__id__in=org_ids).\ select_related('from_practicelocation', 'to_practicelocation') org_pendings = [ { 'pending_id': pending.id, 'sender_name': " ".join([pending.sender.first_name, pending.sender.last_name]), 'from_practicelocation_logo': ImageHelper.get_image_by_type( pending.from_practicelocation.practice_photo, "Middle", 'Practice', 'img_size_practice'), 'from_practicelocatin_type': pending.from_practicelocation.organization_type.name, 'from_practicelocation_name': pending.from_practicelocation.practice_name, 'to_practicelocation_name': pending.to_practicelocation.practice_name, 'to_practicelocatin_type': pending.to_practicelocation.organization_type.name, } for pending in pendings] org_pendings_ret = [ render_to_string('MHLOrganization/MemberOrg/invitation_notification.html', p) for p in org_pendings] return HttpResponse(json.dumps(org_pendings_ret), mimetype='application/json')
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 member_org_show_invite(request): context = get_context_for_organization(request) current_org_id = request.org.id pendings = Pending_Org_Association.objects.filter(from_practicelocation__id=current_org_id) context['total_count'] = len(pendings) user = request.session['MHL_Users']['MHLUser'] local_tz = getCurrentTimeZoneForUser(user, \ current_practice=context['current_practice']) context['index'] = index = int(request.REQUEST.get('index', 0)) context['count'] = count = int(request.REQUEST.get('count', 10)) # get member organization invitations context['member_org_invitations'] = [{ 'pending_id': pending.id, 'to_id': pending.to_practicelocation.id, 'to_name': pending.to_practicelocation.practice_name, 'provider_count': Provider.active_objects.filter(\ Q(practices=pending.to_practicelocation)).count(), 'to_logo': ImageHelper.get_image_by_type(\ pending.to_practicelocation.practice_photo, "Small", "Practice"), 'create_date': formatTimeSetting(user, pending.create_time, local_tz) } for pending in pendings[index*count:(index+1)*count]] return render_to_response('MHLOrganization/MemberOrg/member_org_invite_list.html', context)
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 providerProfileView(role_user): mhluser = role_user.user mhluser_data = model_to_dict( mhluser, fields=('id', 'username', 'first_name', 'last_name', 'email', 'email_confirmed', 'mobile_phone', 'mobile_confirmed', 'phone', 'address1', 'address2', 'city', 'state', 'zip')) role_user_data = model_to_dict( role_user, fields=('office_phone', 'pager', 'pager_confirmed', 'pager_extension', 'clinical_clerk')) ret_data = dict(mhluser_data.items() + role_user_data.items()) ret_data["current_site"] = role_user.current_site.id ret_data["sites"] = list( role_user.sites.values('id', 'name', 'address1', 'address2', 'city', 'state', 'zip')) ret_data["current_practice"] = role_user.current_practice.id ret_data["practices"] = list(role_user.practices.values('id', 'practice_name', 'practice_address1', 'practice_address2',\ 'practice_city', 'practice_state', 'practice_zip')) ret_data["licensure_states"] = list( role_user.licensure_states.values('id', 'state')) ret_data["photo"] = ImageHelper.get_image_by_type(mhluser.photo, "Middle", "Provider") phys = Physician.objects.filter(user=role_user) if (phys.exists()): phy = phys[0] ret_data['specialty'] = phy.get_specialty_display() ret_data['accepting_patients'] = phy.accepting_new_patients else: ret_data['specialty'] = 'NP/PA/Midwife' return ret_data
def getPenddings(request): pend_assoc = Pending_Association.objects.filter(to_user=request.user).order_by('created_time') assoc_lst = [{'practice_location':e.practice_location, 'from_user':e.from_user, 'associa_id':e.pk} for e in pend_assoc] pend_list = [] for e in assoc_lst: p = {} p['user'] = e['from_user'].first_name + ' ' + e['from_user'].last_name p['practice_name'] = e['practice_location'].practice_name p['type'] = 'provider' p['practice_addr1'] = e['practice_location'].practice_address1 p['practice_addr2'] = e['practice_location'].practice_address2 p['practice_zip'] = e['practice_location'].practice_zip p['pract_id'] = e['practice_location'].pk p['assoc_id'] = e['associa_id'] p['city'] = e['practice_location'].practice_city p['state'] = e['practice_location'].practice_state p['org_type'] = get_org_type_name(e['practice_location']) addr_list = [p['practice_addr1'], p['practice_addr2'], p['city'], p['state']] addr_list = [l for l in addr_list if l] p['addr'] = ', '.join(addr_list) p['practice_photo'] = '' if e['practice_location'].practice_photo: p['practice_photo'] = ImageHelper.get_image_by_type( e['practice_location'].practice_photo, size='Large', type='Practice', resize_type='img_size_practice') p['logo_width'] = ImageHelper.get_image_width( e['practice_location'].practice_photo, size='Large', type='Practice') p['logo_height'] = ImageHelper.get_image_height( e['practice_location'].practice_photo, size='Large', type='Practice') pend_list.append(p) return HttpResponse(json.dumps(pend_list), mimetype='application/json')
def get_org_logo(org): """ Get org's logo. :param org: an instance of PracticeLocation :returns: logo url string """ if org and isinstance(org, PracticeLocation): logo = ImageHelper.get_image_by_type(org.practice_photo, size='Large',\ type='Practice', resize_type='img_size_logo') return logo
def setProviderResultList(providers, current_user=None): current_user_mobile = None if current_user: current_user_mobile = current_user.user.mobile_phone user_list = [] provider_ids = [p.id for p in providers] physician_set = Physician.objects.filter(user__id__in=provider_ids) for p in providers: call_available = bool(p.user.mobile_phone) and bool( current_user_mobile) and settings.CALL_ENABLE pager_available = bool(p.pager) and settings.CALL_ENABLE photo = ImageHelper.get_image_by_type(p.user.photo, "Small", "Provider") current_practice = {} if p.current_practice: current_practice = model_to_dict(p.current_practice, fields=('id', 'practice_name')) current_site = {} if p.current_site: current_site = model_to_dict(p.current_site, fields=('id', 'name')) user_info = { 'id': p.user.id, 'first_name': p.user.first_name, 'last_name': p.user.last_name, 'current_practice': current_practice, 'current_site': current_site, # 'specialty': '', 'call_available': call_available, 'pager_available': pager_available, # reserved 'refer_available': True, # 'msg_available': True, 'photo': photo, # Following three keys's name is not very good. As compatibility reason, reserve them. # We use call_available, pager_available, photo replace has_mobile, has_pager, thumbnail 'has_mobile': call_available, 'has_pager': pager_available, 'thumbnail': photo, } physician = physician_set.filter(user__id=p.id) if physician and 'specialty' in dir( physician[0]) and physician[0].specialty: user_info['specialty'] = physician[0].get_specialty_display() else: user_info['specialty'] = "NP/PA/Midwife" user_list.append(user_info) return user_list
def local_office(request): role_user = request.role_user response = { 'data': {}, 'warnings': {}, } current_user_mobile = role_user.user.mobile_phone current_practice = role_user.current_practice if current_practice: object_ids = get_my_favorite_ids(request.user, object_type_flag=OBJECT_TYPE_FLAG_ORG) practices = list( get_practices_by_position(current_practice.practice_lat, current_practice.practice_longit).only( 'practice_name', 'id')) managed_prac_ids = list(Office_Manager.active_objects.all().\ values_list("practice__id", flat=True)) practice_list = [] for p in practices: practice_photo = ImageHelper.get_image_by_type( p.practice_photo, "Large", 'Practice', 'img_size_practice') practice_photo_m = ImageHelper.get_image_by_type( p.practice_photo, "Middle", 'Practice', 'img_size_practice') has_manager = p.id in managed_prac_ids practice_list.append({ 'id': p.id, 'practice_photo': practice_photo, 'practice_photo_m': practice_photo_m, 'practice_name': p.practice_name, 'has_mobile': (bool(p.backline_phone) or bool(p.practice_phone))\ and bool(current_user_mobile)\ and settings.CALL_ENABLE, 'has_manager': has_manager, 'is_favorite': p.id in object_ids }) response['data']['practices'] = sorted(practice_list, key=lambda item: "%s" % (item['practice_name'].lower())) else: response['data']['practices'] = [] return HttpResponse(content=json.dumps(response), mimetype='application/json')
def org_view(request): context = get_context_for_organization(request) org = request.org get_context_manager_role(request, context) mhluser = request.session['MHL_Users']['MHLUser'] context['has_move_btn'] = True if org.id != RESERVED_ORGANIZATION_ID_SYSTEM else False context['has_remove_btn'] = True if org.id != RESERVED_ORGANIZATION_ID_SYSTEM and \ 'Administrator' in request.session['MHL_Users'] else False # get the office location info context['org_type'] = org.organization_type.name if org.organization_type\ else "" parent_org = OrganizationRelationship.active_objects.filter(\ organization__pk=request.org.id)[0].parent context['org_parent_org_name'] = parent_org.practice_name if parent_org else "" context['office_name'] = org.practice_name context['office_address1'] = org.practice_address1 context['office_address2'] = org.practice_address2 context['office_city'] = org.practice_city context['office_state'] = org.practice_state context['office_zip'] = org.practice_zip tz = getDisplayedTimeZone(org.time_zone) context['office_time_zone'] = tz if tz else _("(none)") context['office_phone'] = phone_formater(org.practice_phone) context['backline_phone'] = phone_formater(org.backline_phone) context['office_logo'] = ImageHelper.get_image_by_type(\ org.practice_photo, size='Middle', type='Practice',\ resize_type='img_size_practice') #now we need to get office hours practiceHoursList = PracticeHours.objects.filter(practice_location=org.id) result = [] for p in practiceHoursList: obj = {} obj['open'] = hour_format(mhluser, p.open) obj['close'] = hour_format(mhluser, p.close) obj['lunch_start'] = hour_format(mhluser, p.lunch_start) obj['lunch_duration'] = p.lunch_duration obj['day_of_week'] = p.day_of_week result.append(obj) context['hours'] = result practiceHolidayList = PracticeHolidays.objects.filter(practice_location=org.id) context['holidays'] = practiceHolidayList #get whether we can remove this org can_remove_org = can_we_remove_this_org(org.id, mhluser.id) context['can_remove_org'] = can_remove_org context['member_of'] = which_orgs_contain_this_org(org.id) return render_to_response('MHLOrganization/Information/org_view.html', context)
def officeStaffProfileView(role_user): mhluser = role_user.user mhluser_data = model_to_dict(mhluser, fields=('id', 'username', 'first_name', 'last_name', 'email', 'email_confirmed', 'mobile_phone', 'mobile_confirmed', 'phone')) role_user_data = model_to_dict(role_user, fields=('office_phone', 'pager', 'pager_confirmed', 'pager_extension')) ret_data = dict(mhluser_data.items() + role_user_data.items()) ret_data["photo"] = ImageHelper.get_image_by_type(mhluser.photo, "Middle", "Staff") nurses = Nurse.objects.filter(user=role_user) if (nurses.exists()): ret_data['photo'] = ImageHelper.get_image_by_type( mhluser.photo, "Middle", "Nurse") return ret_data
def practice_info(request, practice_id): role_user = request.role_user current_user_mobile = role_user.user.mobile_phone try: practice = PracticeLocation.objects.get(pk=practice_id) practice_photo = ImageHelper.get_image_by_type(practice.practice_photo, "Large", 'Practice', 'img_size_practice') practice_photo_m = ImageHelper.get_image_by_type( practice.practice_photo, "Middle", 'Practice', 'img_size_practice') has_manager = Office_Manager.active_objects.filter( practice__id=practice_id).exists() response = { 'data': { 'id': practice.id, 'practice_name': practice.practice_name, 'practice_photo': practice_photo, 'practice_photo_m': practice_photo_m, 'practice_address1': practice.practice_address1, 'practice_address2': practice.practice_address2, 'practice_city': practice.practice_city, 'practice_state': practice.practice_state, 'practice_zip': practice.practice_zip, 'mdcom_phone': practice.mdcom_phone, 'has_mobile': (bool(practice.backline_phone)\ or bool(practice.practice_phone))\ and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_manager': has_manager, 'is_favorite': is_favorite(request.user, OBJECT_TYPE_FLAG_ORG, practice.id) }, 'warnings': {}, } return HttpResponse(content=json.dumps(response), mimetype='application/json') except PracticeLocation.DoesNotExist: err_obj = { 'errno': 'PF003', 'descr': _('Requested practice not found.'), } return HttpResponseBadRequest(content=json.dumps(err_obj), 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 setProviderResultList(providers, current_user=None): current_user_mobile = None if current_user: current_user_mobile = current_user.user.mobile_phone user_list = [] provider_ids = [p.id for p in providers] physician_set = Physician.objects.filter(user__id__in=provider_ids) for p in providers: call_available = bool(p.user.mobile_phone) and bool(current_user_mobile) and settings.CALL_ENABLE pager_available = bool(p.pager) and settings.CALL_ENABLE photo = ImageHelper.get_image_by_type(p.user.photo, "Small", "Provider") current_practice = {} if p.current_practice: current_practice = model_to_dict(p.current_practice, fields=('id', 'practice_name')) current_site = {} if p.current_site: current_site = model_to_dict(p.current_site, fields=('id', 'name')) user_info = { 'id': p.user.id, 'first_name': p.user.first_name, 'last_name': p.user.last_name, 'current_practice': current_practice, 'current_site': current_site, # 'specialty': '', 'call_available': call_available, 'pager_available': pager_available, # reserved 'refer_available': True, # 'msg_available': True, 'photo': photo, # Following three keys's name is not very good. As compatibility reason, reserve them. # We use call_available, pager_available, photo replace has_mobile, has_pager, thumbnail 'has_mobile': call_available, 'has_pager': pager_available, 'thumbnail': photo, } physician = physician_set.filter(user__id=p.id) if physician and 'specialty' in dir(physician[0]) and physician[0].specialty: user_info['specialty'] = physician[0].get_specialty_display() else: user_info['specialty'] = "NP/PA/Midwife" user_list.append(user_info) return user_list
def local_office(request): role_user = request.role_user response = { 'data': {}, 'warnings': {}, } current_user_mobile = role_user.user.mobile_phone current_practice = role_user.current_practice if current_practice: object_ids = get_my_favorite_ids(request.user, object_type_flag=OBJECT_TYPE_FLAG_ORG) practices = list(get_practices_by_position(current_practice.practice_lat, current_practice.practice_longit).only('practice_name', 'id')) managed_prac_ids = list(Office_Manager.active_objects.all().\ values_list("practice__id", flat=True)) practice_list = [] for p in practices: practice_photo = ImageHelper.get_image_by_type( p.practice_photo, "Large", 'Practice', 'img_size_practice') practice_photo_m = ImageHelper.get_image_by_type( p.practice_photo, "Middle", 'Practice', 'img_size_practice') has_manager = p.id in managed_prac_ids practice_list.append({ 'id': p.id, 'practice_photo': practice_photo, 'practice_photo_m': practice_photo_m, 'practice_name': p.practice_name, 'has_mobile': (bool(p.backline_phone) or bool(p.practice_phone))\ and bool(current_user_mobile)\ and settings.CALL_ENABLE, 'has_manager': has_manager, 'is_favorite': p.id in object_ids }) response['data']['practices'] = sorted(practice_list, key=lambda item: "%s" % (item['practice_name'].lower())) else: response['data']['practices'] = [] return HttpResponse(content=json.dumps(response), 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 practice_info(request, practice_id): role_user = request.role_user current_user_mobile = role_user.user.mobile_phone try: practice = PracticeLocation.objects.get(pk=practice_id) practice_photo = ImageHelper.get_image_by_type( practice.practice_photo, "Large", 'Practice', 'img_size_practice') practice_photo_m = ImageHelper.get_image_by_type( practice.practice_photo, "Middle", 'Practice', 'img_size_practice') has_manager = Office_Manager.active_objects.filter(practice__id=practice_id).exists() response = { 'data': { 'id': practice.id, 'practice_name': practice.practice_name, 'practice_photo': practice_photo, 'practice_photo_m': practice_photo_m, 'practice_address1': practice.practice_address1, 'practice_address2': practice.practice_address2, 'practice_city': practice.practice_city, 'practice_state': practice.practice_state, 'practice_zip': practice.practice_zip, 'mdcom_phone': practice.mdcom_phone, 'has_mobile': (bool(practice.backline_phone)\ or bool(practice.practice_phone))\ and bool(current_user_mobile) and settings.CALL_ENABLE, 'has_manager': has_manager, 'is_favorite': is_favorite(request.user, OBJECT_TYPE_FLAG_ORG, practice.id) }, 'warnings': {}, } return HttpResponse(content=json.dumps(response), mimetype='application/json') except PracticeLocation.DoesNotExist: err_obj = { 'errno': 'PF003', 'descr': _('Requested practice not found.'), } return HttpResponseBadRequest(content=json.dumps(err_obj), 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 profile(request): """ Return Sales profile view :param request: The HTTP request, POST with with argument :type request: django.core.handlers.wsgi.WSGIRequest :returns: django.http.HttpResponse -- the result data in html format """ context = get_context(request) user = MHLUser.objects.get(username=request.user) context['user'] = user context['photo'] = ImageHelper.get_image_by_type(user.photo, size='Middle', type='Provider') return render_to_response('sales_profile_view.html', context)
def get_invite_valid_providers(request, index): if not request.method == 'POST': return form = ProviderByMailForm(request.POST) if form.is_valid(): practice = request.org email = form.cleaned_data['email'] fname = form.cleaned_data['fullname'] first_name = form.cleaned_data['firstName'] last_name = form.cleaned_data['lastName'] uname = form.cleaned_data['username'] fname = fname.split() q = name_filter(first_name, last_name, query=Q()) all_providers = Provider.active_objects.filter(Q(email__icontains=email),\ Q(username__icontains=uname)).filter(q) exclude_provider_ids = get_exclude_provider_ids(practice) if exclude_provider_ids and len(exclude_provider_ids) > 0: all_providers = all_providers.exclude(id__in=exclude_provider_ids) providers = all_providers.filter(~Q(practices=practice)) associ = list(Pending_Association.objects.filter(practice_location=practice) .values_list('to_user', flat=True)) associ = associ + list(Pending_Association.objects.filter(practice_location=practice) .values_list('from_user', flat=True)) providers = list(providers.exclude(id__in=associ)) invited_providers = list(set(all_providers) - set(providers)) count = len(providers) return_set = [ { 'id':u.user.pk, 'name':', '.join([u.user.last_name, u.user.first_name, ]), 'photo': ImageHelper.get_image_by_type(u.photo, 'Small', 'Provider'), 'address1': u.user.address1, 'address2': u.user.address2, 'specialty':_get_specialty(u), } for u in providers[index*4:(index+1)*4] ] err_tip = get_exist_user_names_in_invitation(invited_providers) return return_set, count, err_tip
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 getPenddings(request): pend_assoc = Pending_Association.objects.filter( to_user=request.user).order_by('created_time') assoc_lst = [{ 'practice_location': e.practice_location, 'from_user': e.from_user, 'associa_id': e.pk } for e in pend_assoc] pend_list = [] for e in assoc_lst: p = {} p['user'] = e['from_user'].first_name + ' ' + e['from_user'].last_name p['practice_name'] = e['practice_location'].practice_name p['type'] = 'provider' p['practice_addr1'] = e['practice_location'].practice_address1 p['practice_addr2'] = e['practice_location'].practice_address2 p['practice_zip'] = e['practice_location'].practice_zip p['pract_id'] = e['practice_location'].pk p['assoc_id'] = e['associa_id'] p['city'] = e['practice_location'].practice_city p['state'] = e['practice_location'].practice_state p['org_type'] = get_org_type_name(e['practice_location']) addr_list = [ p['practice_addr1'], p['practice_addr2'], p['city'], p['state'] ] addr_list = [l for l in addr_list if l] p['addr'] = ', '.join(addr_list) p['practice_photo'] = '' if e['practice_location'].practice_photo: p['practice_photo'] = ImageHelper.get_image_by_type( e['practice_location'].practice_photo, size='Large', type='Practice', resize_type='img_size_practice') p['logo_width'] = ImageHelper.get_image_width( e['practice_location'].practice_photo, size='Large', type='Practice') p['logo_height'] = ImageHelper.get_image_height( e['practice_location'].practice_photo, size='Large', type='Practice') pend_list.append(p) return HttpResponse(json.dumps(pend_list), mimetype='application/json')
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 setPracticeResult(p, logo_size): ele = model_to_dict(p, fields=('id', 'practice_name', 'practice_address1', 'practice_address2', 'practice_city', 'practice_state', 'practice_zip', 'mdcom_phone')) ele["practice_photo"] = ImageHelper.get_image_by_type( p.practice_photo, logo_size, 'Practice') has_manager = Office_Manager.active_objects.filter( practice__id=p.id).exists() # If mobile app use this function, the keys 'has_mobile', 'has_manager' is useful. has_mobile = bool(p.practice_phone) ele["has_mobile"] = has_mobile ele["call_available"] = has_manager ele["has_manager"] = has_manager ele["msg_available"] = has_manager return ele
def profile(request): """ Return Sales profile view :param request: The HTTP request, POST with with argument :type request: django.core.handlers.wsgi.WSGIRequest :returns: django.http.HttpResponse -- the result data in html format """ context = get_context(request) user = MHLUser.objects.get(username=request.user) context['user'] = user context['photo'] = ImageHelper.get_image_by_type(user.photo, size='Middle', type='Provider') return render_to_response('sales_profile_view.html', context)
def brokerProfileView(role_user): mhluser = role_user.user mhluser_data = model_to_dict( mhluser, fields=('id', 'username', 'first_name', 'last_name', 'email', 'email_confirmed', 'mobile_phone', 'mobile_confirmed', 'phone', 'address1', 'address2', 'city', 'state', 'zip')) role_user_data = model_to_dict(role_user, fields=('office_phone', 'pager', 'pager_confirmed', 'pager_extension')) ret_data = dict(mhluser_data.items() + role_user_data.items()) ret_data["photo"] = ImageHelper.get_image_by_type(mhluser.photo, "Middle", "Broker") ret_data["licensure_states"] = list( role_user.licensure_states.values('id', 'state')) return ret_data
def setPracticeResult(p, logo_size): ele = model_to_dict(p, fields=('id', 'practice_name', 'practice_address1', 'practice_address2', 'practice_city', 'practice_state', 'practice_zip', 'mdcom_phone')) ele["practice_photo"] = ImageHelper.get_image_by_type(p.practice_photo, logo_size, 'Practice') has_manager = Office_Manager.active_objects.filter(practice__id=p.id).exists(); # If mobile app use this function, the keys 'has_mobile', 'has_manager' is useful. has_mobile = bool(p.practice_phone) ele["has_mobile"] = has_mobile ele["call_available"] = has_manager ele["has_manager"] = has_manager ele["msg_available"] = has_manager return ele
def member_org_show_org(request): context = get_context_for_organization(request) member_orgs = OrganizationMemberOrgs.objects.filter(\ from_practicelocation__pk=request.org.id)\ .select_related('to_practicelocation')\ .order_by('to_practicelocation__practice_name') qf = Q() context['search_input'] = "" if request.method == "POST": search_input = request.POST.get("search_input", "") if search_input: context['search_input'] = search_input qf = Q(to_practicelocation__practice_name__icontains=search_input) member_orgs = member_orgs.filter(qf) context['member_org_count'] = len(member_orgs) user = request.session['MHL_Users']['MHLUser'] local_tz = getCurrentTimeZoneForUser(user, \ current_practice=context['current_practice']) context['index'] = index = int(request.REQUEST.get('index', 0)) context['count'] = count = int(request.REQUEST.get('count', 10)) return_set = [{ 'id': mo.id, 'to_name': mo.to_practicelocation.practice_name, 'provider_count': Provider.active_objects.filter(\ Q(practices=mo.to_practicelocation)).count(), 'to_logo': ImageHelper.get_image_by_type(\ mo.to_practicelocation.practice_photo, "Small", "Practice"), 'create_date': formatTimeSetting(user, mo.create_time, local_tz), 'billing_flag': mo.billing_flag } for mo in member_orgs[index*count:(index+1)*count]] context['member_orgs'] = return_set return render_to_response('MHLOrganization/MemberOrg/member_org_list.html', context)
def getContextOfPractice(request, context, user): """ getContextOfPractice :param request: Request info :type request: django.core.handlers.wsgi.WSGIRequest :param context: Context info :type context: TODO :returns: ??? """ practice_photo = ImageHelper.DEFAULT_PICTURE['Practice'] context['current_practice'] = '' context['current_practice_photo'] = practice_photo context['physician_phone_number'] = '' if user and user.user and user.user.mobile_phone: context['physician_phone_number'] = user.user.mobile_phone if user and user.current_practice: current_practice = user.current_practice context['current_practice'] = current_practice context['current_practice_photo'] = \ ImageHelper.get_image_by_type(current_practice.practice_photo, size="Middle", type='Practice')
def getContextOfPractice(request, context, user): """ getContextOfPractice :param request: Request info :type request: django.core.handlers.wsgi.WSGIRequest :param context: Context info :type context: TODO :returns: ??? """ practice_photo = ImageHelper.DEFAULT_PICTURE['Practice'] context['current_practice'] = '' context['current_practice_photo'] = practice_photo context['physician_phone_number'] = '' if user and user.user and user.user.mobile_phone: context['physician_phone_number'] = user.user.mobile_phone if user and user.current_practice: current_practice = user.current_practice context['current_practice'] = current_practice context['current_practice_photo'] = \ ImageHelper.get_image_by_type(current_practice.practice_photo, size="Middle", type='Practice')
def setSubProviderResultList(providers, current_user=None): current_user_mobile = None if current_user: current_user_mobile = current_user.user.mobile_phone user_list = [] for p in providers: call_available = bool(p.user.user.mobile_phone) and bool( current_user_mobile) and settings.CALL_ENABLE pager_available = bool(p.user.pager) and settings.CALL_ENABLE photo = ImageHelper.get_image_by_type(p.user.user.photo, "Small", "Provider") user_info = { 'id': p.user.user.id, 'first_name': p.user.first_name, 'last_name': p.user.last_name, 'specialty': '', 'call_available': call_available, 'pager_available': pager_available, # reserved 'refer_available': True, # 'msg_available': True, 'photo': photo, # Following three keys's name is not very good. As compatibility reason, reserve them. # We use call_available, pager_available, photo replace has_mobile, has_pager, thumbnail 'has_mobile': call_available, 'has_pager': pager_available, 'thumbnail': photo, } if ('specialty' in dir(p) and p.specialty): user_info['specialty'] = p.get_specialty_display() else: user_info['specialty'] = "NP/PA/Midwife" user_list.append(user_info) return user_list
def practice_profile_view(request): # Permissions checks. We need to check to see if this user is a manager # for this office. if (not 'OfficeStaff' in request.session['MHL_UserIDs']): return err403(request) user = request.session['MHL_Users']['MHLUser'] office_staff = request.session['MHL_Users']['OfficeStaff'] office_mgr = Office_Manager.objects.filter(user=office_staff, practice=office_staff.current_practice) if (not office_mgr.exists()): return err403(request) context = get_context(request) #is this office manager super manager or not context['manager_role'] = office_mgr[0].manager_role #until, we convert all practices to have accounts, only show links to #practices that actually have billing account if (office_mgr[0].manager_role == 2): try: account = Account.objects.get(practice_group_new=office_mgr[0].practice.get_parent_org()) except ObjectDoesNotExist: context['manager_role'] = 1 #only for practice with group set set up and if this is super manager show manage CC link context['show_cc'] = office_mgr[0].manager_role if (office_mgr[0].manager_role == 2): practice_group = office_mgr[0].practice.get_parent_org() if (practice_group is None): context['show_cc'] = 1 # get the office location info context['office_name'] = office_staff.current_practice.practice_name context['office_address1'] = office_staff.current_practice.practice_address1 context['office_address2'] = office_staff.current_practice.practice_address2 context['office_city'] = office_staff.current_practice.practice_city context['office_state'] = office_staff.current_practice.practice_state context['office_zip'] = office_staff.current_practice.practice_zip context['office_time_zone'] = getDisplayedTimeZone(office_staff.current_practice.time_zone) context['office_phone'] = phone_formater(office_staff.current_practice.practice_phone) context['backline_phone'] = phone_formater(office_staff.current_practice.backline_phone) context['office_logo'] = ImageHelper.DEFAULT_PICTURE['Practice'] if office_staff.current_practice: context['office_logo'] = ImageHelper.get_image_by_type( office_staff.current_practice.practice_photo, size='Middle', type='Practice', resize_type='img_size_practice') #now we need to get office hours practiceHoursList = PracticeHours.objects.filter( practice_location=office_staff.current_practice.id) result = [] for p in practiceHoursList: obj = {} obj['open'] = hour_format(user, p.open) obj['close'] = hour_format(user, p.close) obj['lunch_start'] = hour_format(user, p.lunch_start) obj['lunch_duration'] = p.lunch_duration obj['day_of_week'] = p.day_of_week result.append(obj) context['hours'] = result practiceHolidayList = PracticeHolidays.objects.filter( practice_location=office_staff.current_practice.id) context['holidays'] = practiceHolidayList return render_to_response('Profile/practice_profile_view.html', context)
def practice_profile_view(request): # Permissions checks. We need to check to see if this user is a manager # for this office. if (not 'OfficeStaff' in request.session['MHL_UserIDs']): return err403(request) user = request.session['MHL_Users']['MHLUser'] office_staff = request.session['MHL_Users']['OfficeStaff'] office_mgr = Office_Manager.objects.filter( user=office_staff, practice=office_staff.current_practice) if (not office_mgr.exists()): return err403(request) context = get_context(request) #is this office manager super manager or not context['manager_role'] = office_mgr[0].manager_role #until, we convert all practices to have accounts, only show links to #practices that actually have billing account if (office_mgr[0].manager_role == 2): try: account = Account.objects.get( practice_group_new=office_mgr[0].practice.get_parent_org()) except ObjectDoesNotExist: context['manager_role'] = 1 #only for practice with group set set up and if this is super manager show manage CC link context['show_cc'] = office_mgr[0].manager_role if (office_mgr[0].manager_role == 2): practice_group = office_mgr[0].practice.get_parent_org() if (practice_group is None): context['show_cc'] = 1 # get the office location info context['office_name'] = office_staff.current_practice.practice_name context[ 'office_address1'] = office_staff.current_practice.practice_address1 context[ 'office_address2'] = office_staff.current_practice.practice_address2 context['office_city'] = office_staff.current_practice.practice_city context['office_state'] = office_staff.current_practice.practice_state context['office_zip'] = office_staff.current_practice.practice_zip context['office_time_zone'] = getDisplayedTimeZone( office_staff.current_practice.time_zone) context['office_phone'] = phone_formater( office_staff.current_practice.practice_phone) context['backline_phone'] = phone_formater( office_staff.current_practice.backline_phone) context['office_logo'] = ImageHelper.DEFAULT_PICTURE['Practice'] if office_staff.current_practice: context['office_logo'] = ImageHelper.get_image_by_type( office_staff.current_practice.practice_photo, size='Middle', type='Practice', resize_type='img_size_practice') #now we need to get office hours practiceHoursList = PracticeHours.objects.filter( practice_location=office_staff.current_practice.id) result = [] for p in practiceHoursList: obj = {} obj['open'] = hour_format(user, p.open) obj['close'] = hour_format(user, p.close) obj['lunch_start'] = hour_format(user, p.lunch_start) obj['lunch_duration'] = p.lunch_duration obj['day_of_week'] = p.day_of_week result.append(obj) context['hours'] = result practiceHolidayList = PracticeHolidays.objects.filter( practice_location=office_staff.current_practice.id) context['holidays'] = practiceHolidayList return render_to_response('Profile/practice_profile_view.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 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 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 getProviderByEmailOrNameInCallGroup(request): if (request.method == 'POST'): form = ProviderByMailForm(request.POST) if form.is_valid(): office_staff = request.session['MHL_Users']['OfficeStaff'] practice = office_staff.current_practice email = form.cleaned_data['email'] fname = form.cleaned_data['fullname'] firstName = form.cleaned_data['firstName'] lastName = form.cleaned_data['lastName'] uname = form.cleaned_data['username'] call_group = request.POST['call_group'] filter = Q() fname = fname.split() if lastName == '': filter = Q(first_name__icontains=firstName) | Q(last_name__icontains=firstName) else: filter = Q(first_name__icontains=firstName) & Q(last_name__icontains=lastName) | \ Q(first_name__icontains=lastName) & Q(last_name__icontains=firstName) #providers = Provider.active_objects.filter(~Q(practices=practice), \ #Q(email__icontains=email) , Q(username__icontains=uname)).filter(filter) providers = Provider.active_objects.filter(Q(email__icontains=email), Q(username__icontains=uname)).filter(filter) #associ = list(Pending_Association.objects.filter(practice_location=practice).\ # values_list('to_user', flat=True)) #associ = associ + list(Pending_Association.objects.filter( # practice_location=practice).values_list('from_user', flat=True)) associ = list(CallGroupMemberPending.objects.filter(practice=practice, call_group=call_group).values_list('to_user', flat=True)) sets = [] prviderIn = [] provider_in_associa = 0 for provider in providers: if (provider.id not in associ): sets.append(provider) else: prviderIn.append(provider) provider_in_associa = provider_in_associa + 1 return_set = [ { 'id':u.user.pk, 'name':', '.join([u.user.last_name, u.user.first_name, ]), 'photo': ImageHelper.get_image_by_type(u.photo, 'Small', 'Provider'), # In order to avoid modifying client's code, don't change the key. 'address1': u.user.address1, 'address2': u.user.address2, 'specialty':_get_specialty(u), } for u in sets ] names = '' if len(return_set) > 0: return HttpResponse(json.dumps(return_set)) else: filter = Q() if lastName == '': filter = Q(first_name__icontains=firstName) | \ Q(last_name__icontains=firstName) else: filter = Q(first_name__icontains=firstName) & \ Q(last_name__icontains=lastName) | \ Q(first_name__icontains=lastName) & \ Q(last_name__icontains=firstName) current_provider = Provider.active_objects.filter(practices=practice, email__icontains=email, username__icontains=uname).filter(filter) rs = [{'id':u.user.pk}for u in current_provider] names = '' for n in current_provider: names = names + str(n) + ', ' for fn in prviderIn: names = names + str(fn) + ', ' if names: names = names[0:len(names) - 2] if names.find(',') == -1: return HttpResponse(json.dumps({'err': _('BTW, we find 1 person ' '(%s) matching conditions who is already in your call ' 'group or has been invited.') % names})) else: return HttpResponse(json.dumps({'err': _('BTW, we find %(len)s ' 'people (%(names)s) matching conditions who are already in ' 'your call group or have been invited.') % {'len': str(len(prviderIn) + len(rs)), 'names': names}})) else: return HttpResponse(json.dumps(return_set)) else: return HttpResponse(json.dumps({'err': _('A invalid email.')})) else: return HttpResponse(json.dumps({'err': _('A server error has occurred.')}), mimetype='application/json')
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 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 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_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_refer_from_mbus(status_obj, logo_size="Middle", call_enable=False, refers=None): result = None if refers is None and status_obj: refers = MessageRefer.objects.filter( message=status_obj.msg_body.message) if refers: refer = refers[0] referring_physician_id = status_obj.msg_body.message.sender.id practice_name = '' practice_phone_number = '' practice_state = '' practice_city = '' practice_address = '' if refer.practice: practice_logo = ImageHelper.get_image_by_type( refer.practice.practice_photo, logo_size, 'Practice', 'img_size_practice') practice_name = refer.practice.practice_name practice_phone_number = refer.practice.practice_phone if refer.practice.backline_phone: practice_phone_number = refer.practice.backline_phone practice_phone_number = replace_number(practice_phone_number, call_enable) practice_state = refer.practice.practice_state practice_city = refer.practice.practice_city practice_address = ' '.join([ refer.practice.practice_address1, refer.practice.practice_address2 ]) else: practice_logo = ImageHelper.DEFAULT_PICTURE['Practice'] result = { 'patient_name': ' '.join([refer.first_name, refer.middle_name, refer.last_name]), 'previous_name': refer.previous_name, 'gender': dict(GENDER_CHOICES)[refer.gender].capitalize() if refer.gender else "", 'insurance_id': refer.insurance_id, 'insurance_name': refer.insurance_name, 'secondary_insurance_id': refer.secondary_insurance_id, 'secondary_insurance_name': refer.secondary_insurance_name, 'tertiary_insurance_id': refer.tertiary_insurance_id, 'tertiary_insurance_name': refer.tertiary_insurance_name, 'phone_number': replace_number(refer.phone_number, call_enable), 'home_phone_number': replace_number(refer.home_phone_number, call_enable), 'alternative_phone_number': replace_number(refer.alternative_phone_number, call_enable), 'date_of_birth': getStrFrmTime(refer.date_of_birth), 'status': refer.status, 'referring_physician': sender_name_safe(status_obj.msg_body.message, status_obj.sender_title), 'referring_physician_id': referring_physician_id, 'physician_phone_number': replace_number( status_obj.msg_body.message.sender.mhluser.mobile_phone, call_enable), 'uuid': refer.uuid, 'refer_pdf': refer.refer_pdf, 'refer_jpg': refer.refer_jpg, "practice_logo": practice_logo, "practice_name": practice_name, "practice_phone_number": practice_phone_number, "practice_city": practice_city, "practice_state": practice_state, "practice_address": practice_address, "refer_mrn": refer.mrn, "refer_ssn": refer.ssn, "refer_address": refer.address, "prior_authorization_number": refer.prior_authorization_number, "other_authorization": refer.other_authorization, "internal_tracking_number": refer.internal_tracking_number, "notes": refer.notes, "icd_code": refer.icd_code, "ops_code": refer.ops_code, "medication_list": refer.medication_list, "refer_email": refer.email } return result
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)