public ManualPrescription ImportManualPrescription(ISOTask task, WorkItem workItem)
        {
            ManualPrescription manualRx = null;

            if (task.DefaultTreatmentZone != null)
            {
                foreach (ISOProcessDataVariable pdv in task.DefaultTreatmentZone.ProcessDataVariables)
                {
                    if (manualRx == null)
                    {
                        manualRx             = new ManualPrescription();
                        manualRx.ProductUses = new List <ProductUse>();
                        manualRx.ProductIds  = new List <int>();
                        ImportSharedPrescriptionProperties(task, workItem, manualRx);
                    }

                    if (pdv.ProductIdRef != null) //Products on ISO Rxs are optional, but without a place to store a product-agnostic prescription, those will not be imported here.
                    {
                        ProductUse productUse = new ProductUse();
                        int?       productID  = TaskDataMapper.InstanceIDMap.GetADAPTID(pdv.ProductIdRef);
                        if (productID.HasValue)
                        {
                            productUse.ProductId = productID.Value;
                            manualRx.ProductIds.Add(productID.Value);
                        }
                        productUse.Rate = pdv.ProcessDataValue.AsNumericRepresentationValue(pdv.ProcessDataDDI, RepresentationMapper);
                        manualRx.ProductUses.Add(productUse);
                    }
                }
            }
            return(manualRx);
        }
 public bool ProductUseExists(ProductUse productUse)
 {
     try
     {
         return(_ctx.ProductUses.Any(c => c.ProductUseName == productUse.ProductUseName && c.ProductUseId != productUse.ProductUseId));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed in ProductUseExists: {ex}");
         return(false);
     }
 }
        public ProductUse CreateProductUse(ProductUse addressUse, int userId = -1)
        {
            try
            {
                var addressUseEntityEntry = _ctx.ProductUses.Add(addressUse);

                if (!Save(userId))
                {
                    return(null);
                }
                return(addressUseEntityEntry.Entity);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in CreateProductUse: {ex}");
                return(null);
            }
        }
        public ProductUse GetProductUse(int addressUseId, string propertyToInclude = null)
        {
            try
            {
                ProductUse addressUse = null;
                if (!String.IsNullOrEmpty(propertyToInclude))
                {
                    addressUse = _ctx.ProductUses.Include(propertyToInclude)
                                 .Where(c => c.ProductUseId == addressUseId)
                                 .FirstOrDefault();
                }
                addressUse = _ctx.ProductUses
                             .Where(c => c.ProductUseId == addressUseId).FirstOrDefault();

                return(addressUse);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in GetProductUse: {ex}");
                return(null);
            }
        }
        public ProductUse UpdateProductUse(int addressUseId, ProductUse addressUse, int userId = -1)
        {
            try
            {
                var existingProductUse = GetProductUse(addressUseId);
                _ctx.Entry(existingProductUse).CurrentValues.SetValues(addressUse);
                _ctx.Entry(existingProductUse).Property(x => x.AdmCreated).IsModified   = false;
                _ctx.Entry(existingProductUse).Property(x => x.AdmCreatedBy).IsModified = false;
                var addressUseEntityEntry = _ctx.Entry(existingProductUse);

                if (!Save(userId))
                {
                    return(null);
                }
                return(addressUseEntityEntry.Entity);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed in UpdateProductUse: {ex}");
                return(null);
            }
        }