public void UpdateHospitalBasicDetails(string HospID, HospitalBasicDetails HospitalData)
        {
            if (HospID == null)
                return;

            #if DEBUG
            account = CloudStorageAccount.DevelopmentStorageAccount;
            #else
            account = new CloudStorageAccount(accountAndKey, true);
            #endif
            client = account.CreateCloudTableClient();
            client.CreateTableIfNotExist("DoctorDetails");
            tableContext = new TableServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            IQueryable<HospitalBasicDetails> data = (from i in tableContext.CreateQuery<HospitalBasicDetails>("DoctorDetails") where i.PartitionKey == "HospitalBasicDetails" select i).AsQueryable<HospitalBasicDetails>();
            //Label1.Text = "";
            if (data.AsEnumerable<HospitalBasicDetails>().Any<HospitalBasicDetails>())
            {

                HospitalBasicDetails z = new HospitalBasicDetails();

                var x = (from HospitalBasicDetails i in data where i.HospitalID == HospID select i).FirstOrDefault<HospitalBasicDetails>() as HospitalBasicDetails;

                if (x != null)
                {

                    //x.HospitalID = HospitalData.HospitalID;
                    x.HospitalName = HospitalData.HospitalName;
                    x.Address = HospitalData.Address;
                    x.Latitude = HospitalData.Latitude;
                    x.Longitude = HospitalData.Longitude;
                    x.Facilities = HospitalData.Facilities;
                    x.Departments = HospitalData.Departments;
                    x.Beds_Rooms = HospitalData.Beds_Rooms;
                    x.Type = HospitalData.Type;

                    tableContext.UpdateObject(x);
                    tableContext.SaveChanges();

                }

            }
        }
        public void AddHospitalBasicDetails(HospitalBasicDetails HospitalData)
        {
            #if DEBUG
            account = CloudStorageAccount.DevelopmentStorageAccount;
            #else
            account = new CloudStorageAccount(accountAndKey, true);
            #endif
            client = account.CreateCloudTableClient();
            client.CreateTableIfNotExist("DoctorDetails");
            tableContext = new TableServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            HospitalBasicDetails x = new HospitalBasicDetails();

            x.HospitalID = HospitalData.HospitalID;
            x.HospitalName = HospitalData.HospitalName;
            x.Address = HospitalData.Address;
            x.Latitude = HospitalData.Latitude;
            x.Longitude = HospitalData.Longitude;
            x.Facilities = HospitalData.Facilities;
            x.Departments = HospitalData.Departments;
            x.Beds_Rooms = HospitalData.Beds_Rooms;
            x.Type = HospitalData.Type;

            tableContext.AddObject("DoctorDetails", x);
            tableContext.SaveChanges();
        }
        public HospitalBasicDetails SeeHospitalBasicDetails(string HospID)
        {
            if (HospID == null)
                return null;

            #if DEBUG
            account = CloudStorageAccount.DevelopmentStorageAccount;
            #else
            account = new CloudStorageAccount(accountAndKey, true);
            #endif
            client = account.CreateCloudTableClient();
            client.CreateTableIfNotExist("DoctorDetails");
            tableContext = new TableServiceContext(account.TableEndpoint.ToString(), account.Credentials);

            IQueryable<HospitalBasicDetails> data = (from i in tableContext.CreateQuery<HospitalBasicDetails>("DoctorDetails") where i.PartitionKey == "HospitalBasicDetails" select i).AsQueryable<HospitalBasicDetails>();
            //Label1.Text = "";
            if (data.AsEnumerable<HospitalBasicDetails>().Any<HospitalBasicDetails>())
            {

                HospitalBasicDetails z = new HospitalBasicDetails();

                var y = (from HospitalBasicDetails i in data where i.HospitalID == HospID select i).FirstOrDefault<HospitalBasicDetails>() as HospitalBasicDetails;

                if (y != null)
                {

                    z = y;

                }

                else
                {
                    z = null;

                }
                return z;

            }
            else return null;
        }
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("$projectname$ entry point called", "Information");

            while (true)
            {
                if (q.Exists())
                {
                    q.RetrieveApproximateMessageCount();
                    if (q.ApproximateMessageCount > 0)
                    {
                        Trace.WriteLine("Working", "Information");

                        var message = q.GetMessage();
                        q.DeleteMessage(message);
                        var request = message.AsString;
                        var parts = request.Split('|');

                        string ICD9Code = parts[0];
                        DateTime starttime = new DateTime(long.Parse(parts[1]));
                        DateTime endtime = new DateTime(long.Parse(parts[2]));
                        string OperationID = parts[3];
                        try
                        {
                            IQueryable<AilmentDetails> data = (from i in tableContext.CreateQuery<AilmentDetails>("PatientDetails") where i.PartitionKey == "AilmentDetails" && i.DiagnosisID == ICD9Code select i).AsQueryable<AilmentDetails>();

                            if (data.AsEnumerable<AilmentDetails>().Any<AilmentDetails>())
                            {
                                foreach (AilmentDetails x in data)
                                {
                                    if (DateTime.Compare(x.TimeIn, starttime) >= 0 && DateTime.Compare(x.TimeIn, endtime) <= 0)
                                    {
                                        string searchHospital = x.Hospital;

                                        IQueryable<HospitalBasicDetails> data2 = (from i in tableContext.CreateQuery<HospitalBasicDetails>("DoctorDetails") where i.PartitionKey == "HospitalBasicDetails" select i).AsQueryable<HospitalBasicDetails>();
                                        if (data2.AsEnumerable<HospitalBasicDetails>().Any<HospitalBasicDetails>())
                                        {
                                            HospitalBasicDetails z = new HospitalBasicDetails();
                                            var y = (from HospitalBasicDetails i in data2 where i.HospitalID == searchHospital select i).FirstOrDefault<HospitalBasicDetails>() as HospitalBasicDetails;
                                            if (y != null)
                                            {
                                                ICD9MapPlotResultEntry temp = new ICD9MapPlotResultEntry();
                                                temp.Latitude = y.Latitude;
                                                temp.Longitude = y.Longitude;
                                                temp.Time = x.TimeIn;
                                                rows.Add(temp);

                                            }

                                        }
                                    }
                                }
                            }
                            var serializer = new XmlSerializer(typeof(List<ICD9MapPlotResultEntry>));
                            var stringBuilder = new StringBuilder();
                            XmlWriter writer = XmlWriter.Create(stringBuilder);
                            serializer.Serialize(writer, rows);
                            Encoding encoding = Encoding.Default;
                            blob = container.GetBlobReference(OperationID + ".xml");
                            blob.UploadByteArray(encoding.GetBytes(stringBuilder.ToString()));

                            var resultrecord = new ICD9MapPlotResult(ICD9Code, OperationID);
                            resultrecord.SearchTimeStart = starttime;
                            resultrecord.SearchTimeEnd = endtime;
                            resultrecord.ResultURL = blob.Uri.ToString();
                            tableContext.AddObject("ICD9MapPlotResult", resultrecord);
                            tableContext.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message, "Error");
                        }
                    }
                }
                Thread.Sleep(10000);

            }
        }