public static HospitalReadmission ParseCsvRecordToHospitalReadmission(CsvReader csv)
        {
            // Retrieve the data from the row we know we can safely extract
            HospitalReadmission record = new HospitalReadmission()
            {
                FacilityName = csv.GetField <string>("Facility Name"),
                FacilityId   = csv.GetField <int>("Facility ID"),
                State        = csv.GetField <string>("State"),
                MeasureName  = csv.GetField <string>("Measure Name"),
                Footnote     = csv.GetField <string?>("Footnote"),
                StartDate    = csv.GetField <DateTime>("Start Date"),
                EndDate      = csv.GetField <DateTime>("End Date"),
                IndexedAt    = DateTime.Now,
            };

            /*
             * Note: Some of the number values have "N/A" if
             * there is no data present, so to safely parse this
             * value as an int/decimal we will use the TryParse()
             * method and fallback to leaving the field null if
             * the parsing fails.
             */

            if (int.TryParse(csv.GetField <string>("Number of Discharges"), out int numberOfDischarges))
            {
                record.NumberOfDischarges = numberOfDischarges;
            }

            if (decimal.TryParse(csv.GetField <string>("Excess Readmission Ratio"), out decimal excessReadmissionRatio))
            {
                record.ExcessReadmissionRatio = excessReadmissionRatio;
            }

            if (decimal.TryParse(csv.GetField <string>("Predicted Readmission Rate"), out decimal predictedReadmissionRate))
            {
                record.PredictedReadmissionRate = predictedReadmissionRate;
            }

            if (decimal.TryParse(csv.GetField <string>("Expected Readmission Rate"), out decimal expectedReadmissionRate))
            {
                record.ExpectedReadmissionRate = expectedReadmissionRate;
            }

            if (int.TryParse(csv.GetField <string>("Number of Readmissions"), out int numberOfReadmissions))
            {
                record.NumberOfReadmissions = numberOfReadmissions;
            }

            return(record);
        }
        static async Task Main()
        {
            IConfigurationRoot config = new ConfigurationBuilder()
                                        .AddJsonFile($"appsettings.json", true, true)
                                        .Build();

            string IndexName            = config["IndexName"];
            string ElasticsearchHostUrl = config["ElasticsearchHostUrl"];
            string CsvDataPath          = config["CsvDataPath"];

            Console.Out.WriteLine("Connecting to ES");

            // Instantiate an ElasticClient with correct connection info and options
            ElasticClient client = Helpers.CreateElasticClient(ElasticsearchHostUrl);

            Console.Out.WriteLine("Opening CSV");

            // Create a read stream from CSV with data
            using StreamReader reader = new StreamReader(CsvDataPath);
            using CsvReader csv       = new CsvReader(reader, CultureInfo.InvariantCulture);

            Console.Out.WriteLine("Starting read");

            // Start reading and load in the headers
            csv.Read();
            csv.ReadHeader();

            List <HospitalReadmission> documents = new List <HospitalReadmission>();
            int documentCount = 0;

            // Read and process all rows until no more are available
            while (csv.Read())
            {
                HospitalReadmission document = Helpers.ParseCsvRecordToHospitalReadmission(csv);

                documentCount += 1;
                documents.Add(document);

                if (documentCount >= 500)
                {
                    Console.Out.WriteLine("Writing batch");

                    await client.BulkAsync(b => b
                                           .Index(IndexName)
                                           .IndexMany(documents)
                                           );

                    documentCount = 0;
                    documents.Clear();
                }
            }

            Console.Out.WriteLine("Finishing");

            await client.BulkAsync(b => b
                                   .Index(IndexName)
                                   .IndexMany(documents)
                                   );

            Console.Out.WriteLine("Done");
        }