/// <summary> /// Loads from reader. /// </summary> /// <param name="dr">The dr.</param> /// <returns></returns> public override Hospital LoadFromReader(System.Data.IDataReader dr) { var cmsProviderId = dr.Guard <string>("PRVDR_NUM_MOD").Replace("'", string.Empty); // look for match in db var hosp = this.session.Query <Hospital>() .Where(h => h.CmsProviderID == cmsProviderId) .OrderByDescending(h => h.Id) .FirstOrDefault(); if (hosp == null) { // create new record for insert hosp = new Hospital(); Registry.Hospitals.Add(hosp); this.additions++; } else if (!hosp.IsSourcedFromBaseData) { // match was entered by hand; don't do anything return(null); } else { this.updates++; } // overwrite everything with new data this.PopulateHospitalFromDataRow(hosp, dr); // load relationships this.MapHrrAndHsa(hosp); // Get the hospital category ID from the file. var hospCatId = dr.Guard <int>("PRVDR_CTGRY_SBTYP_CD"); var hospCat = HospitalCategories.FirstOrDefault(x => x.CategoryID == hospCatId); if (hospCat != null && !hosp.Categories.Contains(hospCat)) { hosp.Categories.Add(hospCat); } // update if this is an existing hospital this.session.SaveOrUpdate(hosp); return(null); }