/// <summary> /// Create a new SYS_Medicine object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> public static SYS_Medicine CreateSYS_Medicine(global::System.Int32 id, global::System.String name) { SYS_Medicine sYS_Medicine = new SYS_Medicine(); sYS_Medicine.Id = id; sYS_Medicine.Name = name; return sYS_Medicine; }
private static void SaveLeafletsToDb(CerebelloEntities db, List<MedicineRaw> medicines, Action<int, int> progress = null) { db.ExecuteStoreCommand("delete from SYS_MedicineActiveIngredient"); db.ExecuteStoreCommand("delete from SYS_ActiveIngredient"); db.ExecuteStoreCommand("delete from SYS_Medicine"); db.ExecuteStoreCommand("delete from SYS_Laboratory"); int count, max; { // INGREDIENTS Console.WriteLine("SYS_ActiveIngredient"); List<string> activeIngredientNames = (from m in medicines from ai in m.ActiveIngredient.Split('+') select StringHelper.CapitalizeFirstLetters( Regex.Replace(ai.Trim(), @"\s+", " "), new[] { "a", "o", "ao", "e", "de", "da", "do", "as", "as", "os", "das", "dos", "des" })) .Distinct() .ToList(); count = 0; max = activeIngredientNames.Count; foreach (string activeIngredientName in activeIngredientNames) { if (progress != null) progress(count, max); if (!string.IsNullOrEmpty(activeIngredientName) && activeIngredientName != "-") db.SYS_ActiveIngredient.AddObject(new SYS_ActiveIngredient { Name = activeIngredientName }); if (count % 100 == 0) db.SaveChanges(); count++; } if (progress != null) progress(count, max); // LABORATORIES Console.WriteLine("SYS_Laboratory"); List<string> laboratoryNames = (from m in medicines.ToList() select m.Laboratory).Distinct().ToList(); count = 0; max = laboratoryNames.Count; foreach (string laboratoryName in laboratoryNames) { if (progress != null) progress(count, max); if (!string.IsNullOrEmpty(laboratoryName) && laboratoryName != "-") db.SYS_Laboratory.AddObject(new SYS_Laboratory { Name = laboratoryName }); if (count % 100 == 0) db.SaveChanges(); count++; } if (progress != null) progress(count, max); } db.SaveChanges(); // MEDICINES Console.WriteLine("SYS_Medicine"); var medicinesList = (from m in medicines group m by new { m.Name, m.Concentration }) .Where(mg => mg.Key.Name != "-") .ToList(); count = 0; max = medicinesList.Count; foreach (var medicinesGrouped in medicinesList) { if (progress != null) progress(count, max); string medicineName = medicinesGrouped.Key.Name; var medicine = new SYS_Medicine { Name = medicineName + " (" + medicinesGrouped.Key.Concentration + ")" }; // associating active ingredients with medicine List<string> activeIngredientNames = (from ai in medicinesGrouped.ElementAt(0).ActiveIngredient.Split('+') select StringHelper.CapitalizeFirstLetters( Regex.Replace(ai.Trim(), @"\s+", " "), new[] { "a", "o", "ao", "e", "de", "da", "do", "as", "as", "os", "das", "dos", "des" })) .ToList(); activeIngredientNames = activeIngredientNames .Where(ain => !string.IsNullOrEmpty(ain) && ain != "-") .ToList(); foreach (string ain in activeIngredientNames) { SYS_ActiveIngredient activeIngredient = db.SYS_ActiveIngredient.First(ai => ai.Name == ain); medicine.ActiveIngredients.Add(activeIngredient); } // associating the medicine with the laboratory if (!string.IsNullOrEmpty(medicinesGrouped.ElementAt(0).Laboratory)) { string laboratoryName = medicinesGrouped.ElementAt(0).Laboratory; medicine.Laboratory = db.SYS_Laboratory.First(l => l.Name == laboratoryName); } foreach (var leaflet in medicinesGrouped.Select(mg => new { Description = mg.LeafletType, Url = mg.LeafletUrl })) medicine.Leaflets.Add(new SYS_Leaflet { Description = leaflet.Description, Url = leaflet.Url }); db.SYS_Medicine.AddObject(medicine); db.SaveChanges(); count++; } if (progress != null) progress(count, max); db.SaveChanges(); }
/// <summary> /// Deprecated Method for adding a new object to the SYS_Medicine EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSYS_Medicine(SYS_Medicine sYS_Medicine) { base.AddObject("SYS_Medicine", sYS_Medicine); }