public ServiceResult Update(UnitOfMeasure s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid UnitsOfMeasure sent to server."));
            }

            UnitOfMeasureManager UnitsOfMeasureManager = new UnitOfMeasureManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);



            var dbS = (UnitOfMeasure)UnitsOfMeasureManager.GetBy(s.UUID);

            if (dbS == null)
            {
                return(ServiceResponse.Error("UnitsOfMeasure was not found."));
            }

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }
            dbS.Deleted   = s.Deleted;
            dbS.Name      = s.Name;
            dbS.Status    = s.Status;
            dbS.SortOrder = s.SortOrder;
            dbS.Category  = s.Category;
            dbS.ShortName = s.ShortName;
            return(UnitsOfMeasureManager.Update(dbS));
        }
        public ServiceResult GetBy(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must provide a name for the UnitsOfMeasure."));
            }

            UnitOfMeasureManager UnitsOfMeasureManager = new UnitOfMeasureManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            UnitOfMeasure s = (UnitOfMeasure)UnitsOfMeasureManager.GetBy(uuid);

            if (s == null)
            {
                return(ServiceResponse.Error("UnitsOfMeasure could not be located for the uuid " + uuid));
            }

            return(ServiceResponse.OK("", s));
        }
        public ServiceResult Delete(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("Invalid id was sent."));
            }

            UnitOfMeasureManager UnitsOfMeasureManager = new UnitOfMeasureManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            UnitOfMeasure fa = (UnitOfMeasure)UnitsOfMeasureManager.GetBy(uuid);

            if (fa == null)
            {
                return(ServiceResponse.Error("Could not find measure."));
            }

            return(UnitsOfMeasureManager.Delete(fa));
        }
Пример #4
0
        public ServiceResult Insert(DoseLogForm d)
        {
            string authToken = Request.Headers?.Authorization?.Parameter;

            //d.UserUUID  <= patient id. for now make this a hidden field and use the cookie value.
            //               for an app that uses multiple patients then we'll need make a combobox or some list to select
            //whom we're logging for.


            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }


            UserSession us = SessionManager.GetSession(authToken);

            if (us == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }



            if (us.Captcha?.ToUpper() != d.Captcha?.ToUpper())
            {
                return(ServiceResponse.Error("Invalid code."));
            }


            if (string.IsNullOrWhiteSpace(d.AccountUUID))
            {
                d.AccountUUID = CurrentUser.AccountUUID;
            }

            if (string.IsNullOrWhiteSpace(d.CreatedBy))
            {
                d.CreatedBy = us.UUID;
            }

            if (d.DateCreated == DateTime.MinValue)
            {
                d.DateCreated = DateTime.UtcNow;
            }


            d.Active  = true;
            d.Deleted = false;

            if (d.DoseDateTime == null || d.DoseDateTime == DateTime.MinValue)
            {
                return(ServiceResponse.Error("You must a date time for the dose."));
            }

            if (string.IsNullOrWhiteSpace(d.ProductUUID))
            {
                return(ServiceResponse.Error("You must select a product."));
            }

            ProductManager productManager = new ProductManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            Product        p = (Product)productManager.GetBy(d.ProductUUID);

            if (p == null)
            {
                return(ServiceResponse.Error("Product could not be found. You must select a product, or create one from the products page."));
            }

            if (string.IsNullOrWhiteSpace(d.Name))
            {
                d.Name = string.Format("{0} {1} {2}", p.Name, d.Quantity, d.UnitOfMeasure);
            }


            if (d.Quantity <= 0)
            {
                return(ServiceResponse.Error("You must enter a quantity"));
            }

            if (string.IsNullOrWhiteSpace(d.UnitOfMeasure))
            {
                return(ServiceResponse.Error("You must select a unit of measure."));
            }

            UnitOfMeasureManager uomm = new UnitOfMeasureManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            if (uomm.GetBy(d.UnitOfMeasure) == null)
            {
                UnitOfMeasure uom = (UnitOfMeasure)uomm.Get(d.UnitOfMeasure);
                if (uom == null)
                {
                    uom             = new UnitOfMeasure();
                    uom.Name        = d.UnitOfMeasure.Trim();
                    uom.AccountUUID = CurrentUser.AccountUUID;
                    uom.Active      = true;
                    uom.Deleted     = false;
                    uom.Private     = true;
                    ServiceResult uomSr = uomm.Insert(uom);
                    if (uomSr.Code != 200)
                    {
                        return(uomSr);
                    }
                }
                d.UnitOfMeasure = uom.UUID;
            }

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <DoseLogForm, DoseLog>();
            });

            IMapper mapper = config.CreateMapper();
            var     dest   = mapper.Map <DoseLogForm, DoseLog>(d);

            DoseManager   DoseManager = new DoseManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            ServiceResult sr          = DoseManager.Insert(dest, false);

            if (sr.Code != 200)
            {
                return(sr);
            }

            SymptomManager sm            = new SymptomManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            string         symptomErrors = "";

            int index = 1;

            foreach (SymptomLog s in d.Symptoms)
            {
                if (string.IsNullOrWhiteSpace(s.UUID))
                {
                    symptomErrors += "Symptom " + index + " UUID must be set! <br/>";
                    Debug.Assert(false, "SYMPTOM UUID MUST BE SET!!");
                    continue;
                }

                Symptom stmp = (Symptom)sm.GetBy(s.UUID);

                if (stmp == null)
                {
                    stmp = (Symptom)sm.GetBy(s.UUID);
                }

                if (stmp == null)
                {
                    symptomErrors += "Symptom " + s.UUID + " could not be found! <br/>";
                    continue;
                }
                s.Name = stmp.Name;

                if (s.SymptomDate == null || s.SymptomDate == DateTime.MinValue)
                {
                    symptomErrors += "Symptom " + s.UUID + " date must be set! <br/>";
                    continue;
                }
                //s.Status
                s.AccountUUID = CurrentUser.AccountUUID;
                s.Active      = true;
                s.CreatedBy   = CurrentUser.UUID;
                s.DateCreated = DateTime.UtcNow;
                s.Deleted     = false;
                s.DoseUUID    = dest.UUID;
                s.Private     = true;
                ServiceResult slSr = sm.Insert(s, false);

                if (slSr.Code != 200)
                {
                    symptomErrors += "Symptom " + index + " failed to save. " + slSr.Message;
                }
                index++;
            }
            return(ServiceResponse.OK("", dest));
        }