private static List <RxRates> LoadRatesFromTreatmentZones(GridDescriptor gridDescriptor, Dictionary <int, TreatmentZone> treatmentZones, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxRates>(); foreach (var treatmentZoneId in gridDescriptor.TreatmentZones) { var treatmentZone = treatmentZones.FindById(treatmentZoneId); if (treatmentZone == null) { return(null); } var rate = new RxRates { RxRate = new List <RxRate>() }; for (int i = 0; i < treatmentZone.Variables.Count; i++) { var dataVariable = treatmentZone.Variables[i]; AddRate(productIds[i], dataVariable.Value, rate, prescription, treatmentZone.Variables[i].IsoUnit.ToAdaptUnit()); } rates.Add(rate); } return(rates); }
private static void AddRate(int productId, double productRate, RxRates rates, RasterGridPrescription prescription, UnitOfMeasure uom) { RxProductLookup rxProductLookup; if (prescription.RxProductLookups.Any(x => x.ProductId == productId)) { rxProductLookup = prescription.RxProductLookups.Single(x => x.ProductId == productId); } else { rxProductLookup = new RxProductLookup { ProductId = productId, UnitOfMeasure = uom }; prescription.RxProductLookups.Add(rxProductLookup); } var rxRate = new RxRate { Rate = productRate, RxProductLookupId = rxProductLookup.Id.ReferenceId, }; rates.RxRate.Add(rxRate); }
//Determines a unique key that describes the products and rates assigned to each cell. private string GetRxRatesKey(RxRates rates) { string key = string.Empty; rates.RxRate.ForEach(r => key += $"{r.RxProductLookupId}:{r.Rate}|"); return(key); }
private List <RxRates> ImportRatesFromTreatmentZones(GridDescriptor gridDescriptor, IEnumerable <ISOTreatmentZone> treatmentZones, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxRates>(); foreach (var treatmentZoneCode in gridDescriptor.TreatmentZoneCodes) { ISOTreatmentZone treatmentZone = treatmentZones.FirstOrDefault(t => t.TreatmentZoneCode == treatmentZoneCode); if (treatmentZone == null) { return(null); } var rate = new RxRates { RxRate = new List <RxRate>() }; foreach (ISOProcessDataVariable pdv in treatmentZone.ProcessDataVariables) { if (!string.IsNullOrEmpty(pdv.ProductIdRef)) { int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef); if (productID.HasValue) { rate.RxRate.Add(PrescriptionMapper.ImportAndConvertRate(productID.Value, pdv, prescription)); } } } rates.Add(rate); } return(rates); }
//Adds a treatment zone for a new rate combination private ISOTreatmentZone GetNewType1TreatmentZone(RxRates rates, byte counter, Prescription rx) { ISOTreatmentZone treatmentZone = new ISOTreatmentZone() { TreatmentZoneCode = counter, TreatmentZoneDesignator = $"TreatmentZone {counter.ToString()}" }; foreach (RxRate rate in rates.RxRate) { treatmentZone.ProcessDataVariables.Add(ExportProcessDataVariable(rate, rx)); } return(treatmentZone); }
private List <RxRates> ImportRatesFromProducts(GridDescriptor gridDescriptor, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxRates>(); foreach (var productRates in gridDescriptor.ProductRates) { var rate = new RxRates { RxRate = new List <RxRate>() }; for (int productIndex = 0; productIndex < productRates.Count; productIndex++) { int adaptProductId = productIds[productIndex]; rate.RxRate.Add(PrescriptionMapper.ImportRate(adaptProductId, productRates[productIndex], prescription)); } rates.Add(rate); } return(rates); }
private List <RxRates> LoadRatesFromProducts(GridDescriptor gridDescriptor, List <int> productIds, RasterGridPrescription prescription) { var rates = new List <RxRates>(); foreach (var productRates in gridDescriptor.ProductRates) { var rate = new RxRates { RxRate = new List <RxRate>() }; for (int productIndex = 0; productIndex < productRates.Count; productIndex++) { var adaptProductId = productIds[productIndex]; UnitOfMeasure uom = null; AddRate(adaptProductId, productRates[productIndex], rate, prescription, uom); } rates.Add(rate); } return(rates); }