예제 #1
0
파일: utils.py 프로젝트: cnzhuran/mdcom
def get_practices_by_position(lat, longit, distance=None):
    if (not distance):
        distance = settings.PROXIMITY_RANGE
    latmin, latmax, longitmin, longitmax = miles2latlong_range(
        lat, longit, distance)
    return PracticeLocation.active_practice.filter(
        practice_lat__range=(latmin, latmax),
        practice_longit__range=(longitmin, longitmax))
예제 #2
0
def get_clinical_clerks_by_coords(lat, longit, miles=settings.PROXIMITY_RANGE):
	if not lat and not longit:
		return get_all_clinical_clerks()

	latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit, miles)

	users = list(Physician.active_objects.filter(user__user__lat__range=(latmin, latmax), 
		user__user__longit__range=(longitmin, longitmax), 
			user__clinical_clerk='True').select_related('user', 'user__user'))
	users.sort(lambda x, y: cmp(x.user.user.last_name.lower(), y.user.user.last_name.lower()))
	return users
예제 #3
0
파일: views.py 프로젝트: cnzhuran/mdcom
def site_admin(request):
    context = get_context(request)

    context['sites'] = Site.objects.all()

    if (request.POST):
        if (request.POST['searchRadio'] == 'ST'):
            if ('state' in request.POST):
                state = request.POST['state']
                context['sites'] = Site.objects.filter(state__iexact=state)
        elif (request.POST['searchRadio'] == 'PR'):
            if ('proximity' in request.POST):
                user = user_is_provider(request.user)
                # use MHLUser's lat, longit instead of Provider's office_lat, office_longit
                mylat = user.user.lat
                mylongit = user.user.longit
                miles = float(request.POST['proximity'])
                latmin, latmax, longitmin, longitmax = miles2latlong_range(
                    mylat, mylongit, miles)
                nearbySites = Site.objects.filter(
                    lat__range=(latmin,
                                latmax)).filter(longit__range=(longitmin,
                                                               longitmax))
                context['sites'] = nearbySites
        elif (request.POST['searchRadio'] == 'CI'):
            if ('city' in request.POST):
                city = request.POST['city']
                context['sites'] = Site.objects.filter(city__istartswith=city)
        elif (request.POST['searchRadio'] == 'ZI'):
            if ('zip' in request.POST):
                zip = request.POST['zip']
                context['sites'] = Site.objects.filter(zip__istartswith=zip)
        elif (request.POST['searchRadio'] == 'NA'):
            if ('name' in request.POST):
                name = request.POST['name']
                context['sites'] = Site.objects.filter(name__istartswith=name)
        #raise Exception(request.POST)
        else:
            context['sites'] = Site.objects.all()

    context['searchby'] = SiteSearchForm()

    return render_to_response('Sites/sites_view.html', context)
예제 #4
0
def get_providers_for_staff(practice):
	lat = practice.practice_lat
	longit = practice.practice_longit

	latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit)

	#raise Exception(doctor, doctor.user.office_address1, doctor.user.office_city, 
	# latmin,latmax, longitmin, longitmax)
	# get list of docotors and nurse practitioners
	physicians = Physician.active_objects.filter(user__sites=None, 
		user__user__lat__range=(latmin, latmax), 
			user__user__longit__range=(longitmin, longitmax)).\
				exclude(user__clinical_clerk='True')
	np_pas = NP_PA.active_objects.filter(user__sites=None, 
		user__user__lat__range=(latmin, latmax), 
			user__user__longit__range=(longitmin, longitmax))
	users = list(Provider.active_objects.filter(Q(physician__in=physicians) | 
		Q(np_pa__in=np_pas)).select_related('user'))
	users.sort(lambda x, y: cmp(x.last_name.lower(), y.last_name.lower()))

	return users
예제 #5
0
파일: views.py 프로젝트: DongHuaLu/mdcom
def site_admin(request):
	context = get_context(request)

	context['sites'] = Site.objects.all()

	if (request.POST):
		if (request.POST['searchRadio'] == 'ST'):
			if ('state' in request.POST):
				state = request.POST['state']
				context['sites'] = Site.objects.filter(state__iexact=state)
		elif (request.POST['searchRadio'] == 'PR'):
			if ('proximity' in request.POST):
				user = user_is_provider(request.user)
				# use MHLUser's lat, longit instead of Provider's office_lat, office_longit
				mylat = user.user.lat
				mylongit = user.user.longit
				miles = float(request.POST['proximity'])
				latmin, latmax, longitmin, longitmax = miles2latlong_range(mylat, mylongit, miles)
				nearbySites = Site.objects.filter(lat__range=(latmin, latmax)).filter(longit__range=(longitmin, longitmax))
				context['sites'] = nearbySites
		elif (request.POST['searchRadio'] == 'CI'):
			if ('city' in request.POST):
				city = request.POST['city']
				context['sites'] = Site.objects.filter(city__istartswith=city)
		elif (request.POST['searchRadio'] == 'ZI'):
			if ('zip' in request.POST):
				zip = request.POST['zip']
				context['sites'] = Site.objects.filter(zip__istartswith=zip)
		elif (request.POST['searchRadio'] == 'NA'):
			if ('name' in request.POST):
				name = request.POST['name']
				context['sites'] = Site.objects.filter(name__istartswith=name)
		#raise Exception(request.POST)
		else:
			context['sites'] = Site.objects.all()

	context['searchby'] = SiteSearchForm()

	return render_to_response('Sites/sites_view.html', context)
예제 #6
0
def get_community_providers_by_coords(lat, longit, miles=settings.PROXIMITY_RANGE, licensure=None):
	if lat and  longit:
		latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit, miles)
		#raise Exception(doctor, doctor.user.office_address1, doctor.user.office_city, 
		#latmin,latmax, longitmin, longitmax)
		# TODO: Update this to include nurses and office managers
		physicians = Physician.active_objects.filter(user__user__lat__range=(latmin, latmax), 
			user__user__longit__range=(longitmin, longitmax)).\
				exclude(user__clinical_clerk='True').select_related('user', 'user__user')
		np_pas = NP_PA.active_objects.filter(user__user__lat__range=(latmin, latmax), 
			user__user__longit__range=(longitmin, longitmax)).select_related('user', 'user__user')

		if licensure:
			physicians = physicians.filter(user__licensure_states__state=licensure)
			np_pas = np_pas.filter(user__licensure_states__state=licensure)

		users = list(physicians)	
		users.extend(list(np_pas))
		users.sort(lambda x, y: cmp(x.user.user.last_name.lower(), y.user.user.last_name.lower()))

		return users
	else:
		return get_all_community_providers(licensure)
예제 #7
0
파일: views.py 프로젝트: cnzhuran/mdcom
def manage_sites(request):
    provider = user_is_provider(request.user)
    staffer = user_is_office_staff(request.user)
    if (not (provider or staffer)):
        return HttpResponseRedirect('/')

    try:
        if (provider):
            user = provider
            lat = float(user.lat)
            longit = float(user.longit)
        elif (staffer):
            user = staffer
            if user.current_practice:
                lat = float(user.current_practice.practice_lat)
                longit = float(user.current_practice.practice_longit)
            else:
                geocode_response = geocode2(user.office_address1, \
                  user.office_city, user.office_state, user.office_zip)
                lat = geocode_response['lat']
                longit = geocode_response['lng']
    except:
        lat, longit = (0, 0)

    context = get_context(request)

    # get the latitutde, longitude range to search for nearby sites
    if not lat and not longit:
        latmin, latmax, longitmin, longitmax = (0, 0, 0, 0)
    else:
        latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit)

    sites = user.sites.all()

    if (request.method == "POST"):

        searchby = ''
        searchbyvalue = ''
        """
		#raise Exception(request.POST)
		if ('submit_search_criteria' and 'searchby' and 'searchbyvalue' in request.POST):
			raise Exception(request.POST)
			searchby = request.POST['searchby']
			searchbyvalue = request.POST['searchbyvalue']
			#raise Exception(request.POST)

			if (searchby == 'proximity'):
					miles = float(searchbyvalue)
					del_lat, del_longit = miles2latlong(miles, lat, longit)
					latmin = lat - del_lat
					latmax = lat + del_lat
					longitmin = longit - del_longit
					longitmax = longit + del_longit
					#raise Exception(miles, latmin, latmax, longitmin, longitmax)
		"""

        context['site_form'] = CurrentSiteForm(sites, request.POST)
        site_list_ids = [site.id for site in sites]
        context['affiliation_form'] = SiteManagementForm(
            searchby, searchbyvalue, latmin, latmax, longitmin, longitmax,
            site_list_ids, request.POST)
        #		context['affiliation_form'] = SiteManagementForm(request.POST)

        if (context['site_form'].is_valid()):
            new_site_id = int(context['site_form'].cleaned_data['current'])
            if (new_site_id == 0):
                new_site = None
            else:
                site_ids = [site.id for site in sites]
                if (not new_site_id in site_ids):
                    raise Exception(
                        _("User tried to select site id ") + str(new_site_id) +
                        _(", but isn't affiliated with that site."))

                # Check to see if the site exists
                new_site = Site.objects.filter(id=new_site_id).all()
                if (new_site.count() != 1):
                    raise Exception(
                        _("Incorrect number of sites found for id ") +
                        str(new_site_id))
                new_site = new_site[0]

            user.current_site = new_site
            user.save()
            return HttpResponseRedirect(
                reverse('MHLogin.MHLUsers.views.profile_view'))

        elif (context['affiliation_form'].is_valid()):
            new_sites = context['affiliation_form'].cleaned_data['site_list']
            new_site_ids = [site.id for site in new_sites]

            # This ensures that providers can't remove their current site. The outer check
            # is just to make sure that an error doesn't occur when the provider doesn't have
            # a current site.
            site_match = True
            if (user.current_site != None):
                site_match = False
                for site in new_site_ids:
                    if (user.current_site.id == site):
                        site_match = True

            if (site_match):
                user.sites = new_sites
                user.save()
                return HttpResponseRedirect(
                    reverse('MHLogin.MHLUsers.views.profile_view'))
            else:
                context['affiliation_form'].error_current_site_removal()
    else:
        if (user.sites):
            site_list_ids = [site.id for site in user.sites.all()]
            site_list = {
                'site_list': site_list_ids,
                'record_key': '1IFSWP3s8gjRpqzJyvhM',
            }
            context['affiliation_form'] = SiteManagementForm('proximity',
                                                             'none',
                                                             latmin,
                                                             latmax,
                                                             longitmin,
                                                             longitmax,
                                                             site_list_ids,
                                                             initial=site_list)
#			context['affiliation_form'] = SiteManagementForm(initial=site_list)
        else:
            site_list = dict()
            site_list = {
                'record_key': '1IFSWP3s8gjRpqzJyvhM',
            }
            context['affiliation_form'] = SiteManagementForm('proximity',
                                                             'none',
                                                             latmin,
                                                             latmax,
                                                             longitmin,
                                                             longitmax, [],
                                                             initial=site_list)
#			context['affiliation_form'] = SiteManagementForm(initial=site_list)

    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['new_affiliation_form'] = NewSiteManagementForm(initial=site_list)
    return render_to_response("Sites/sites_edit.html", context)
예제 #8
0
파일: views.py 프로젝트: DongHuaLu/mdcom
def manage_sites(request):
	provider = user_is_provider(request.user)
	staffer = user_is_office_staff(request.user)
	if (not (provider or staffer)):
		return HttpResponseRedirect('/')

	try:
		if (provider):
			user = provider
			lat = float(user.lat)
			longit = float(user.longit)
		elif (staffer):
			user = staffer
			if user.current_practice:
				lat = float(user.current_practice.practice_lat)
				longit = float(user.current_practice.practice_longit)
			else:
				geocode_response = geocode2(user.office_address1, \
						user.office_city, user.office_state, user.office_zip)
				lat = geocode_response['lat']
				longit = geocode_response['lng']
	except:
		lat, longit = (0, 0)

	context = get_context(request)

	# get the latitutde, longitude range to search for nearby sites
	if not lat and not longit:
		latmin, latmax, longitmin, longitmax = (0, 0, 0, 0)
	else:
		latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit)

	sites = user.sites.all()

	if (request.method == "POST"):

		searchby = ''
		searchbyvalue = ''
		"""
		#raise Exception(request.POST)
		if ('submit_search_criteria' and 'searchby' and 'searchbyvalue' in request.POST):
			raise Exception(request.POST)
			searchby = request.POST['searchby']
			searchbyvalue = request.POST['searchbyvalue']
			#raise Exception(request.POST)

			if (searchby == 'proximity'):
					miles = float(searchbyvalue)
					del_lat, del_longit = miles2latlong(miles, lat, longit)
					latmin = lat - del_lat
					latmax = lat + del_lat
					longitmin = longit - del_longit
					longitmax = longit + del_longit
					#raise Exception(miles, latmin, latmax, longitmin, longitmax)
		"""

		context['site_form'] = CurrentSiteForm(sites, request.POST)
		site_list_ids = [site.id for site in sites]
		context['affiliation_form'] = SiteManagementForm(searchby, searchbyvalue, latmin, latmax, longitmin, longitmax, site_list_ids, request.POST)
#		context['affiliation_form'] = SiteManagementForm(request.POST)

		if (context['site_form'].is_valid()):
			new_site_id = int(context['site_form'].cleaned_data['current'])
			if (new_site_id == 0):
				new_site = None
			else:
				site_ids = [site.id for site in sites]
				if (not new_site_id in site_ids):
					raise Exception(_("User tried to select site id ") + str(new_site_id) + _(", but isn't affiliated with that site."))

				# Check to see if the site exists
				new_site = Site.objects.filter(id=new_site_id).all()
				if (new_site.count() != 1):
					raise Exception(_("Incorrect number of sites found for id ") + str(new_site_id))
				new_site = new_site[0]

			user.current_site = new_site
			user.save()
			return HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))

		elif (context['affiliation_form'].is_valid()):
			new_sites = context['affiliation_form'].cleaned_data['site_list']
			new_site_ids = [site.id for site in new_sites]

			# This ensures that providers can't remove their current site. The outer check
			# is just to make sure that an error doesn't occur when the provider doesn't have
			# a current site.
			site_match = True
			if (user.current_site != None):
				site_match = False
				for site in new_site_ids:
					if (user.current_site.id == site):
						site_match = True

			if (site_match):
				user.sites = new_sites
				user.save()
				return HttpResponseRedirect(reverse('MHLogin.MHLUsers.views.profile_view'))
			else:
				context['affiliation_form'].error_current_site_removal()
	else:
		if (user.sites):
			site_list_ids = [site.id for site in user.sites.all()]
			site_list = {
					'site_list': site_list_ids,
					'record_key': '1IFSWP3s8gjRpqzJyvhM',
				}
			context['affiliation_form'] = SiteManagementForm('proximity', 'none', latmin, 
				latmax, longitmin, longitmax, site_list_ids, initial=site_list)
#			context['affiliation_form'] = SiteManagementForm(initial=site_list)
		else:
			site_list = dict()
			site_list = {
					'record_key': '1IFSWP3s8gjRpqzJyvhM',
				}
			context['affiliation_form'] = SiteManagementForm('proximity', 'none', latmin, 
				latmax, longitmin, longitmax, [], initial=site_list)
#			context['affiliation_form'] = SiteManagementForm(initial=site_list)

	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['new_affiliation_form'] = NewSiteManagementForm(initial=site_list)
	return render_to_response("Sites/sites_edit.html", context)
예제 #9
0
def getProviderList(condition_dict, current_user=None, exclude_clerk=True):
	q_condition = Q()
	limit = None
	if condition_dict:
		if 'name' in condition_dict and condition_dict['name']:
			name = condition_dict['name']
			search_terms = unicode.split(name)
			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_condition.add(Q(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.AND)
			else:
				q_condition.add(Q(Q(user__first_name__icontains=first_name) | Q(user__last_name__icontains=first_name)), Q.AND)

		if 'address' in condition_dict and condition_dict['address']:
			address = condition_dict['address']
			q_condition.add(Q(Q(user__address1__icontains=address) | Q(user__address2__icontains=address)), Q.AND)

		if 'city' in condition_dict and condition_dict['city']:
			city = condition_dict['city']
			q_condition.add(Q(user__city__icontains=city), Q.AND)

		if 'state' in condition_dict and condition_dict['state']:
			state = condition_dict['state']
			q_condition.add(Q(user__state=state), Q.AND)

		if 'zip' in condition_dict and condition_dict['zip']:
			zip = condition_dict['zip']
			result = geocode2('', '', '', zip)
			if (result['lat'] != 0.0 and result['lng'] != 0.0):
				lat = result['lat'] 
				longit = result['lng']
				distance = settings.PROXIMITY_RANGE
				if 'distance' in condition_dict and condition_dict['distance']:
					distance = condition_dict['distance']
				latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit, distance)
				q_condition.add(Q(user__lat__range=(latmin, latmax), user__longit__range=(longitmin, longitmax)), Q.AND)

		if 'current_hospital' in condition_dict and condition_dict['current_hospital']:
			current_hospital = condition_dict['current_hospital']
			q_condition.add(Q(current_site__name__icontains=current_hospital), Q.AND)

		if 'hospital' in condition_dict and condition_dict['hospital']:
			hospital = condition_dict['hospital']
			q_condition.add(Q(sites__name__icontains=hospital), Q.AND)

		if 'current_practice' in condition_dict and condition_dict['current_practice']:
			current_practice = condition_dict['current_practice']
			q_condition.add(Q(current_practice__practice_name__icontains=current_practice), Q.AND)

		if 'practice' in condition_dict and condition_dict['practice']:
			practice = condition_dict['practice']
			q_condition.add(Q(practices__practice_name__icontains=practice), Q.AND)

		if 'specialty' in condition_dict and condition_dict['specialty']:
			specialty = condition_dict['specialty']
			provider_ids = None
			if specialty != "NP/PA/Midwife":
				provider_ids = Physician.objects.filter(specialty__icontains=specialty).values_list('user')
			else:
				physician_ids = Physician.objects.filter(Q(specialty=None) | Q(specialty='')).values_list('user')
				physician_ids = [pid[0] for pid in physician_ids]
				nppa_ids = NP_PA.objects.values_list('user')
				nppa_ids = [pid[0] for pid in nppa_ids]
				provider_ids = physician_ids + nppa_ids
			if provider_ids:
				q_condition.add(Q(pk__in=provider_ids), Q.AND)

		if 'limit' in condition_dict and condition_dict['limit']:
			limit = condition_dict['limit']

	query_rs = Provider.active_objects.filter(q_condition)
	if exclude_clerk:
		query_rs = query_rs.exclude(clinical_clerk='True')

	total_count = query_rs.count()
	if limit and query_rs.count() > limit:
		query_rs = query_rs[:limit]

	data = {}
	data['total_count'] = total_count
	data['results'] = setProviderResultList(query_rs, current_user)
	return data
예제 #10
0
def getProviderList(condition_dict, current_user=None, exclude_clerk=True):
    q_condition = Q()
    limit = None
    if condition_dict:
        if 'name' in condition_dict and condition_dict['name']:
            name = condition_dict['name']
            search_terms = unicode.split(name)
            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_condition.add(
                    Q(
                        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.AND)
            else:
                q_condition.add(
                    Q(
                        Q(user__first_name__icontains=first_name)
                        | Q(user__last_name__icontains=first_name)), Q.AND)

        if 'address' in condition_dict and condition_dict['address']:
            address = condition_dict['address']
            q_condition.add(
                Q(
                    Q(user__address1__icontains=address)
                    | Q(user__address2__icontains=address)), Q.AND)

        if 'city' in condition_dict and condition_dict['city']:
            city = condition_dict['city']
            q_condition.add(Q(user__city__icontains=city), Q.AND)

        if 'state' in condition_dict and condition_dict['state']:
            state = condition_dict['state']
            q_condition.add(Q(user__state=state), Q.AND)

        if 'zip' in condition_dict and condition_dict['zip']:
            zip = condition_dict['zip']
            result = geocode2('', '', '', zip)
            if (result['lat'] != 0.0 and result['lng'] != 0.0):
                lat = result['lat']
                longit = result['lng']
                distance = settings.PROXIMITY_RANGE
                if 'distance' in condition_dict and condition_dict['distance']:
                    distance = condition_dict['distance']
                latmin, latmax, longitmin, longitmax = miles2latlong_range(
                    lat, longit, distance)
                q_condition.add(
                    Q(user__lat__range=(latmin, latmax),
                      user__longit__range=(longitmin, longitmax)), Q.AND)

        if 'current_hospital' in condition_dict and condition_dict[
                'current_hospital']:
            current_hospital = condition_dict['current_hospital']
            q_condition.add(Q(current_site__name__icontains=current_hospital),
                            Q.AND)

        if 'hospital' in condition_dict and condition_dict['hospital']:
            hospital = condition_dict['hospital']
            q_condition.add(Q(sites__name__icontains=hospital), Q.AND)

        if 'current_practice' in condition_dict and condition_dict[
                'current_practice']:
            current_practice = condition_dict['current_practice']
            q_condition.add(
                Q(current_practice__practice_name__icontains=current_practice),
                Q.AND)

        if 'practice' in condition_dict and condition_dict['practice']:
            practice = condition_dict['practice']
            q_condition.add(Q(practices__practice_name__icontains=practice),
                            Q.AND)

        if 'specialty' in condition_dict and condition_dict['specialty']:
            specialty = condition_dict['specialty']
            provider_ids = None
            if specialty != "NP/PA/Midwife":
                provider_ids = Physician.objects.filter(
                    specialty__icontains=specialty).values_list('user')
            else:
                physician_ids = Physician.objects.filter(
                    Q(specialty=None) | Q(specialty='')).values_list('user')
                physician_ids = [pid[0] for pid in physician_ids]
                nppa_ids = NP_PA.objects.values_list('user')
                nppa_ids = [pid[0] for pid in nppa_ids]
                provider_ids = physician_ids + nppa_ids
            if provider_ids:
                q_condition.add(Q(pk__in=provider_ids), Q.AND)

        if 'limit' in condition_dict and condition_dict['limit']:
            limit = condition_dict['limit']

    query_rs = Provider.active_objects.filter(q_condition)
    if exclude_clerk:
        query_rs = query_rs.exclude(clinical_clerk='True')

    total_count = query_rs.count()
    if limit and query_rs.count() > limit:
        query_rs = query_rs[:limit]

    data = {}
    data['total_count'] = total_count
    data['results'] = setProviderResultList(query_rs, current_user)
    return data
예제 #11
0
파일: utils.py 프로젝트: DongHuaLu/mdcom
def get_practices_by_position(lat, longit, distance=None):
	if (not distance):
		distance = settings.PROXIMITY_RANGE
	latmin, latmax, longitmin, longitmax = miles2latlong_range(lat, longit, distance)
	return PracticeLocation.active_practice.filter(practice_lat__range=(latmin, latmax), 
		practice_longit__range=(longitmin, longitmax))