private IEnumerable <int> Subspecialty(int proKey)
        {
            if (subsByPractice.ContainsKey(proKey))
            {
                return(subsByPractice[proKey].RandomSubset());
            }

            var        query = $"Select SubSpecialty from provider.PracticeSubSpecialty s join provider.PracticeLocation p on s.Practice = p.Practice  where p.PracticeLocationKey={proKey}";
            SqlCommand cmd   = new SqlCommand(query, conn, transaction);

            using (var rs = cmd.ExecuteReader())
            {
                List <int> subs = new List <int>();
                while (rs.Read())
                {
                    var spe = (int)rs.GetSqlInt32(0);
                    subs.Add(spe);
                }
                rs.Close();
                ContentIterator c = new ContentIterator(subs);
                subsByPractice.Add(proKey, c);

                return(c.RandomSubset());
            }
        }
        private IEnumerable <int> PractitionerPayerPlans(string strZip)
        {
            int zip = 0;

            if (!int.TryParse(strZip, out zip))
            {
                throw new InvalidCastException();
            }

            if (plansByZip.ContainsKey(zip))
            {
                return(plansByZip[zip].RandomSubset(33));
            }

            var        query = $"Select PayerPlan from geo.ZipCodePayerPlan where ZipCode='{zip}'";
            SqlCommand cmd   = new SqlCommand(query, conn, transaction);

            using (var rs = cmd.ExecuteReader())
            {
                List <int> plans = new List <int>();
                while (rs.Read())
                {
                    var plan = (int)rs.GetSqlInt32(0);
                    plans.Add(plan);
                }
                rs.Close();

                ContentIterator c = new ContentIterator(plans);
                plansByZip.Add(zip, c);
                return(c.RandomSubset(33));
            }
        }
 public static int Next()
 {
     if (iterator == null)
     {
         iterator = new ContentIterator(list);
     }
     return(iterator.Next());
 }
        private int PracticeLocation(string zip, string countryCode)
        {
            if (countryCode != "US")
            {
                return(PracticeLocationOpenMaket.Next());
            }
            int zipCode = 0;

            if (!int.TryParse(zip, out zipCode))
            {
                throw new InvalidCastException();
            }

            if (practiceByZip.ContainsKey(zipCode))
            {
                return(practiceByZip[zipCode].Next());
            }

            var query = $"select PracticeLocationKey from provider.practiceLocation pl join provider.Address a on pl.address = a.Addresskey where a.ZipCode='{zipCode}'";
            var comnd = new SqlCommand(query, conn, transaction);

            using (var rs = comnd.ExecuteReader())
            {
                if (!rs.HasRows)
                {
                    return(PracticeLocationOpenMaket.Next());
                }

                List <int> keys = new List <int>();
                while (rs.Read())
                {
                    var key = (int)rs.GetSqlInt32(0);
                    keys.Add(key);
                }

                rs.Close();
                ContentIterator loc = new ContentIterator(keys);
                practiceByZip.Add(zipCode, loc);
                return(loc.Next());
            }
        }