// GET: api/Main/Origin public List<TravelTime> Get(string origin, string destination) { var svc = new HealthBuddy.Api.Directions.DirectionsService(); var times = svc.GetTravelTimes(new Location { Suburb = origin }, new Location { Suburb = destination }); return times; }
public FacilitySearchResult Get(string latitude, string longitude, string gender, bool isChild, FacilityType type) { FacilitySearchResult result = new FacilitySearchResult(); result.Origin = new Location { Latitude = latitude, Longitude = longitude }; // Get the suburb and postcode for the origin location var google = new HealthBuddy.Api.Directions.DirectionsService(); google.Lookup(result.Origin); double lat = double.Parse(result.Origin.Latitude); double lng = double.Parse(result.Origin.Longitude); if (type == FacilityType.Hospital) { // Use GovHack data sets - my hospitals contact list, length of stay data, etc. var hospitals = db.myhospitals_contact_data .Where( a => (!a.Emergency.HasValue || a.Emergency.Value) && (!a.Child.HasValue || a.Child == isChild) && (a.Gender == null || a.Gender == gender)) .OrderBy( a => (a.Latitude - lat) * (a.Latitude - lat) + (a.Longitude - lng) * (a.Longitude - lng)) .Take(5).ToList(); var ids = hospitals.Select(a => a.Id).ToArray(); var codes = hospitals.Select(a => a.HospitalCode).ToArray(); var lengthsOfStay = db.emergencydept4hourlengthofstaymetadata.Where(a => ids.Contains(a.MyHospitalsId.Value)).OrderBy(a => a.ID).ToList(); var emergencyStats = db.ED001_HospitalStatus.Where(a => codes.Contains(a.HospitalCode)).OrderBy(a => a.Id).ToList(); result.Facilities.AddRange(hospitals.Select(hosp => new Facility { Name = hosp.Hospital_name, LessThan4HrsPct = GetLengthOfStay(hosp, lengthsOfStay), EmergencyDepartmentStatus = GetEDStatus(hosp, emergencyStats), Location = GetLocation(hosp), TwitterSentiment = EventHub.EventService.GetTwitterSentiment(hosp.HospitalCode), OpenNow = "true", })); } else if (type == FacilityType.Community) { // Use ACHC20150617_DataDotGov var charities = db.ACHC20150617_DataDotGov .Where( a => (a.Advancing_Health == "Y") && (!isChild || a.Children == "Y") && (a.Latitude.HasValue && a.Longitude.HasValue)) .OrderBy( a => (a.Latitude - lat) * (a.Latitude - lat) + (a.Longitude - lng) * (a.Longitude - lng)) .Take(5).ToList(); result.Facilities.AddRange(charities.Select(hosp => new Facility { Name = hosp.Charity_Legal_Name, Location = GetLocation(hosp) })); } else { // Use NHSD lookup. var nhsd = new HealthBuddy.Api.Nhsd.NhsdService(); result.Facilities.AddRange(nhsd.Search(result.Origin, type)); } // Get the travel times by driving and transit to each facility. foreach (var facility in result.Facilities) { facility.TravelTimes = google.GetTravelTimes(result.Origin, facility.Location); } return result; }