Exemple #1
0
        public ServiceResult UpdateSymptomLogField(string symptomLogUUID, string fieldName, string fieldValue)
        {
            if (string.IsNullOrWhiteSpace(symptomLogUUID))
            {
                return(ServiceResponse.Error("You must provide a UUID."));
            }

            if (string.IsNullOrWhiteSpace(fieldName))
            {
                return(ServiceResponse.Error("You must provide a field name."));
            }

            if (string.IsNullOrWhiteSpace(fieldValue))
            {
                return(ServiceResponse.Error("You must provide a field value."));
            }

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

            SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            SymptomLog sl = symptomManager.GetSymptomLogBy(symptomLogUUID);

            if (sl == null)
            {
                return(ServiceResponse.Error("Could not find the log item."));
            }

            if (CurrentUser.UUID != sl.CreatedBy)
            {
                return(ServiceResponse.Error("You are not authorized to change this item."));
            }

            bool success = false;

            fieldName = fieldName.ToLower();

            switch (fieldName)
            {
            case "duration":
                sl.Duration = fieldValue.ConvertTo <float>(out success);
                if (!success)
                {
                    return(ServiceResponse.Error("Invalid field value."));
                }
                break;

            case "durationmeasure":
                sl.DurationMeasure = fieldValue;
                break;

            default:
                return(ServiceResponse.Error("Field " + fieldName + " not supported."));
            }
            return(symptomManager.Update(sl));
        }
Exemple #2
0
        public ServiceResult Update(SymptomLog s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid SymptomLog sent to server."));
            }

            SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            var dbS = symptomManager.GetSymptomLogBy(s.UUID);

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

            if (s.Efficacy < -5 || s.Efficacy > 5)
            {
                return(ServiceResponse.Error("Efficacy is out of range."));
            }

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

            if (CurrentUser.UUID != dbS.CreatedBy)
            {
                return(ServiceResponse.Error("You are not authorized to change this item."));
            }

            dbS.Name            = s.Name;
            dbS.Status          = s.Status;
            dbS.Duration        = s.Duration;
            dbS.DurationMeasure = s.DurationMeasure;
            dbS.Efficacy        = s.Efficacy;
            dbS.Severity        = s.Severity;
            dbS.SymptomDate     = s.SymptomDate;

            //test this.make sure date, status, severity, efficacy etc is copied over.

            return(symptomManager.Update(dbS));
        }
Exemple #3
0
        public void SymptomManager_GetSymptomLogBy()
        {
            SymptomManager m = new SymptomManager(new TreeMonDbContext(connectionKey));

            Assert.AreEqual(
                m.InsertLog(new SymptomLog()
            {
                AccountId   = "a",
                Name        = "TESTRECORD",
                DateCreated = DateTime.UtcNow
                ,
                DoseUUID = "D"
            }, false)
                .Code, 200);
            SymptomLog s = m.GetSymptomLog("TESTRECORD");

            Assert.IsNotNull(s);
            SymptomLog suid = m.GetSymptomLogBy(s.UUID);

            Assert.IsNotNull(suid);
        }
Exemple #4
0
        public ServiceResult SetRating(string uuid, string type, float score)
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }


            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must supply a unique identifier."));
            }
            if (string.IsNullOrWhiteSpace(type))
            {
                return(ServiceResponse.Error("You must supply a type identifier."));
            }

            type = type.ToUpper().Trim();
            switch (type)
            {
            case "SYMPTOMLOG":
                SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
                SymptomLog     sl             = symptomManager.GetSymptomLogBy(uuid);
                if (sl == null)
                {
                    return(ServiceResponse.Error("Could not find symptom."));
                }

                if (sl.CreatedBy != CurrentUser.UUID)    //|| sl.AccountId != currentUser.AccountId)
                {
                    return(ServiceResponse.Error("You are not authorized to rate this item."));
                }

                sl.Efficacy = score;
                return(symptomManager.Update(sl));
            }

            return(ServiceResponse.Error("Invalid type:" + type));
        }
Exemple #5
0
        public ServiceResult AddSymptomLog(SymptomLog s)
        {
            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            if (string.IsNullOrWhiteSpace(s.AccountUUID) || s.AccountUUID == SystemFlag.Default.Account)
            {
                s.AccountUUID = CurrentUser.AccountUUID;
            }

            if (string.IsNullOrWhiteSpace(s.CreatedBy))
            {
                s.CreatedBy = CurrentUser.UUID;
            }

            SymptomManager symptomManager = new SymptomManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            if (!string.IsNullOrWhiteSpace(s.UUParentID))
            {
                SymptomLog parentLog = symptomManager.GetSymptomLogBy(s.UUParentID);
                if (parentLog == null)
                {
                    return(ServiceResponse.Error("Invalid log parent id. The UUParentID must belong to a valid Symptom Log entry."));
                }

                s.DoseUUID = parentLog.DoseUUID;
                if (string.IsNullOrWhiteSpace(s.UUParentIDType))
                {
                    s.UUParentIDType = parentLog.UUIDType;
                }
            }

            s.Active = true;

            if (string.IsNullOrWhiteSpace(s.UUIDType))
            {
                s.UUIDType = "SymptomLog";
            }

            //backlog go to dosehistory selsect a dose and in the symptomps list
            //click add . fill in the data and click
            //VERIFY the fields here.
            //rules for parent list symptom creation
            //Name <- may need to create
            //SymptomUUID <- may need to create
            if (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID))
            {
                return(ServiceResponse.Error("You must select a symptom."));
            }
            else if (string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID) == false)
            {   //get and assign the name
                var res = symptomManager.Get(s.SymptomUUID);
                if (res.Code != 200)
                {
                    return(res);
                }

                Symptom symptom = (Symptom)res.Result;

                s.Name = symptom.Name;
            }
            else if (!string.IsNullOrWhiteSpace(s.Name) && string.IsNullOrWhiteSpace(s.SymptomUUID))
            {   //create the symptoms and assign it to the symptomuuid
                Symptom symptom = (Symptom)symptomManager.Search(s.Name)?.FirstOrDefault();

                if (symptom != null)
                {
                    s.SymptomUUID = symptom.UUID;
                }
                else
                {
                    symptom = new Symptom()
                    {
                        Name        = s.Name,
                        AccountUUID = s.AccountUUID,
                        Active      = true,
                        CreatedBy   = CurrentUser.UUID,
                        DateCreated = DateTime.UtcNow,
                        Deleted     = false,
                        UUIDType    = "Symptom",
                        Category    = "General"
                    };

                    ServiceResult sr = symptomManager.Insert(symptom);
                    if (sr.Code == 500)
                    {
                        return(ServiceResponse.Error(sr.Message));
                    }

                    s.SymptomUUID = symptom.UUID;
                }
            }

            if (s.SymptomDate == null || s.SymptomDate == DateTime.MinValue)
            {
                s.SymptomDate = DateTime.UtcNow;
            }

            if (string.IsNullOrWhiteSpace(s.Status))//Status start middle end. Query StatusMessage table
            {
                return(ServiceResponse.Error("You must provide a status."));
            }

            if (s.Severity > 5)
            {
                return(ServiceResponse.Error("Severity must not be greater than 5."));
            }
            if (s.Efficacy > 5)
            {
                return(ServiceResponse.Error("Efficacy must not be greater than 5."));
            }

            return(symptomManager.Insert(s));
        }