Our CarePrecise Gold™ and CarePrecise Platinum™ customers have been wild about the geographic lookup of healthcare providers since we first introduced geographic radius search more than ten years ago in our CP ListMaker™ software. It's not a hard thing to do, and I'll show you how it works so you can use it in your own applications!
All you need is a Zip Code® table that incudes longitude and latitude for the center of each zip if you want a rough estimation of distance (included in CarePrecise Gold and Platinum), or you can purchase our SelectGeo database that has the rooftop-level latitude/longitude pair ("geocode") for every U.S. healthcare provider's address.
The code we offer here is also included in CP ListMaker as open source, and it relies on some of the built-in functions available in VBA: the Sin() and Cos() math functions (sine and cosine), and a few others like the Abs() function (returns the absolute of a number). All of the build-in functions can be found fully described at support.microsoft.com.
You can use the first function, CalcDistance(), to just return the distance between two points, or along with the others to list all of the spots in a miles radius from a central point. If you want to see only all of the physicians located within a radius, you would first create a query that filters for just physician locations.
The Calculations
Here's the VB/VBA code (shown as used in a Microsoft Access module)...
CalcDistance
Public Function CalcDistance(lat1, lon1, lat2, lon2) As Variant
'This function calculates the distance between two latitude/longitude pairs.
Dim theta
Dim dist As Double
theta = lon1 - lon2
dist = Sin(deg2rad(lat1)) * Sin(deg2rad(lat2)) + Cos(deg2rad(lat1)) * Cos(deg2rad(lat2)) * Cos(deg2rad(theta))
If dist > 0 Then
dist = dist - 0.00000000000001
End If
dist = acos(dist)
dist = rad2deg(dist)
dist = dist * 69.09
CalcDistance = dist
End Function
The Radius Functions
Public Function acos(Rad)
If CDbl(Abs(Rad)) <> 1 Then
acos = (pi / 2) - Atn(Rad / Sqr(1 - Rad * Rad))
ElseIf Rad = -1 Then
acos = pi
End If
End Function
Public Function deg2rad(Deg)
deg2rad = CDbl(Deg * pi / 180)
End Function
Public Function rad2deg(Rad)
rad2deg = CDbl(Rad * 180 / pi)
End Function
Geocoding Applications
Once a patient has chosen a nearby provider, the CalcDistance() function is used to say just how far away it is. Integration with Google Maps or another mapping API can then map the route using the coordinates from our SelectGeo database.
This is some of the hardest working code out there, and the uses abound. Play with it!
No comments:
Post a Comment