Ejemplo n.º 1
0
        public void TestInitialise()
        {
            //ARRANGE
            var p = new Sickness.Sickness(); 
            //ACT

            //ASSERT
            
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new sickness absence
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public JsonResult Create(SicknessAbsenceViewModel data)
        {
            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {
                    var classification = orgSession.Query<SicknessClassification>().FirstOrDefault();
                    var subject = orgSession.Load<User>(data.UserId);
                    var reason = classification.GetReason(data.SicknessReasonId);
                    var sickness = new Sickness
                                       {
                                           Subject = subject.ToSimpleUser(),
                                           SicknessReason = SicknessReasonSimple.Create(reason),
                                           StartOfProcess = data.StartOfProcess,
                                           EndOfProcess = data.EndOfProcess,
                                           ConsolidatedCompletionDate = data.EndOfProcess ?? DateTime.Now,
                                           Title = data.Title,
                                           Summary = data.Summary,
                                           UserCreatedProcess = OrgUser.ToSimpleUser(),
                                           CurrentProcessOwner = OrgUser.ToSimpleUser(), //TODO: What if self created? Should be manager.
                                           Id = IlluminateDatabase.GenerateId<Sickness>()
                                       };

                    orgSession.Store(sickness);

                    //update the user state. 
                    if (sickness.StartOfProcess.Date <= DateTime.Today && sickness.ConsolidatedCompletionDate.Date  >= DateTime.Today)
                    {
                        subject.CurrentState = "onsick"; 
                    }

                    //get the workflow config
                    var config = SicknessWorkflowConfiguration.Generate(orgSession);
                    
                    //definition should already exist
                    //create a new default sickness workflow and assign it to the sickness
                    var workflow = new DefaultSicknessWorkflow(config);
                    sickness.Workflow = workflow;
                    //handle the created event of the sickness
                    sickness.HandleEvent(OrgStore,"Sickness", "Create", sickness);
                    orgSession.SaveChanges();

                    return JsonSuccess(sickness.ToTimelineItems(), "Sickness item created");
                }
            }
            return JsonError("Invalid data: " + ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1));
        }
Ejemplo n.º 3
0
 public List<Sickness> GetTestSicknesses(User user, int number)
 {
     var Sicknesses = new List<Sickness>();
     for (int i = 1; i <= number; i++)
     {
         var date = DateTime.Now.AddMonths(0 - i);
         var Sickness = new Sickness();
         string SicknessNumber = i.ToString();
         Sickness.Id = IlluminateDatabase.GenerateId<Sickness>();
         Sickness.Subject = new SimpleUser();
         Sickness.Subject.UserId = user.Id;
         Sickness.Subject.FullName = user.FirstName + " " + user.LastName;
         Sickness.StartOfProcess = date;
         Sickness.EndOfProcess = date.AddDays(1);
         Sicknesses.Add(Sickness);
     }
     return Sicknesses;
 }
Ejemplo n.º 4
0
        private void CreateTestSickness(IDocumentStore store)
        {

            using (var session = store.OpenSession())
            {
                //for user 1 generate sickness with same reason that should cause inference
                var startDate = DateTime.Today.AddDays(0 - _typeConfig.PeriodDays).AddDays(1);
                var sicknessReason1 = GetTestSicknessReason1();
                for (var count = 0; count < _typeConfig.NumberInPeriod + 1; count++)
                {
                    var sickness = new Sickness
                    {
                     StartOfProcess  = startDate,
                     SicknessReason = sicknessReason1,
                        Id = IlluminateDatabase.GenerateId<Sickness>(),
                        Subject = _user1.ToSimpleUser()
                    };
                    session.Store(sickness);
                    startDate = startDate.AddDays(1);
                }
                startDate = DateTime.Today.AddDays(0 - _typeConfig.PeriodDays).AddDays(1);

                //for user 2 add sickness but all with different reasons
                for (var count = 0; count < _typeConfig.NumberInPeriod - 1; count++)
                {
                    var sickness = new Sickness
                    {
                        StartOfProcess = startDate,
                        SicknessReason = new SicknessReasonSimple { FullName = IlluminateDatabase.GenerateId<SicknessReasonSimple>(), Id = IlluminateDatabase.GenerateId<SicknessReasonSimple>() },
                        Id = IlluminateDatabase.GenerateId<Sickness>(),
                        Subject = _user1.ToSimpleUser()
                    };
                    session.Store(sickness);
                    startDate = startDate.AddDays(1);
                }

                session.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        private Sickness GenerateASickness(bool isCurrent,IUser user,Random rand)
        {
            
            var sicknessReason = _sicknessClassification.GetRandomReason(rand);
            var manager = user.Relationships.FirstOrDefault(r => r.RelationshipName == "LineManager");
            if (manager == null)
            {
                return null;
            }
            var sickness = new Sickness
                               {
                                   CurrentProcessOwner = manager,
                                   Id = IlluminateDatabase.GenerateId<Sickness>(),
                                   SicknessReason = SicknessReasonSimple.Create(sicknessReason),
                                   Subject = user.ToSimpleUser(),
                                   UserCreatedProcess = manager,
                                   Title = sicknessReason.FullName,
                                   Summary = sicknessReason.Description


                               };
            var now = DateTime.UtcNow.Date;
            if (isCurrent)
            {
                sickness.StartOfProcess = RandomDate(rand, now.AddDays(0 - _config.SicknessConfig.MaxDurationDays), now);
                sickness.ConsolidatedCompletionDate = now;
            }
            else
            {
                var startDate = RandomDate(rand, now.AddDays(0 - _config.DaysHistory), now);
                var endDate = startDate.AddDays(rand.Next(1, _config.SicknessConfig.MaxDurationDays));
                if (endDate >= now)
                    endDate = now.AddDays(-1);
                sickness.ConsolidatedCompletionDate = endDate;
                sickness.EndOfProcess = endDate;
                sickness.StartOfProcess = startDate;
            }
            
            return sickness;
        }
Ejemplo n.º 6
0
        public override void Import(Stream stream)
        {
            ErrorLines.Clear();

            var reader = new StreamReader(stream);
            string line;
            //ignore first line(s). 
            for (var i = 0; i < IgnoreLines; i++)
            {
                reader.ReadLine();
            }

            //parse each line
            var re =
                new Regex(
                    @"^(?<personnelnumber>[^\t]+)\t(?<startdate>[^\t]+)\t(?<enddate>[^\t]+)\t(?<code>[^\t]+)\t(?<description>[^\t]+)$");
                //TODO: more sophisticated regex for dates etc. 



            while ((line = reader.ReadLine()) != null)
            {
                var match = re.Match(line);
                if (match.Success)
                {
                    using (var Session = Store.OpenSession())
                    {
                        var personnelnumber = match.Groups["personnelnumber"].Captures[0].Value;
                        var user = Session.Query<User>().FirstOrDefault(u => u.PersonnelNumber == personnelnumber);
                        if (user == null)
                        {
                            ErrorLines.Add(line);
                            continue;
                        }

                        var reasoncode = match.Groups["code"].Captures[0].Value;
                        var reason = Session.Query<SicknessReason>().FirstOrDefault(r => r.Code == reasoncode);



                        if (reason == null)
                        {
                            //get default reason
                            reason =
                                Session.Query<SicknessReason>().FirstOrDefault(r => r.Code == "DEFAULT");
                            if (reason == null)
                            {
                                //!!
                                reason = new SicknessReason
                                             {
                                                 Code = "DEFAULT",
                                                 Description = "Default Sickness",
                                                 FullName = "Default Sickness",
                                                 Name = "Default Sickness"
                                             };
                                Session.Store(reason);
                            }
                        }


                        //save sickness
                        var s = new Sickness
                                    {
                                        Id = IlluminateDatabase.GenerateId<Sickness>(),
                                        Subject = user.ToSimpleUser(),
                                        StartOfProcess = DateTime.Parse(match.Groups["startdate"].Captures[0].Value),
                                        EndOfProcess = DateTime.Parse(match.Groups["enddate"].Captures[0].Value),
                                        ConsolidatedCompletionDate =
                                            DateTime.Parse(match.Groups["enddate"].Captures[0].Value),
                                        Title = "Sickness",
                                        Summary = match.Groups["description"].Captures[0].Value,
                                        SicknessReason = SicknessReasonSimple.Create(reason),

                                    };

                        Session.Store(s);


                        //should we save if there were errors?
                        Session.SaveChanges();
                    }
                }
                else
                {
                    ErrorLines.Add(line);
                }

                


            }
        }
 // need to create some sicknesses for each user
 public List<Sickness> GetTestSicknesses(User user, int number)
 {
     var Sicknesses = new List<Sickness>();
     for (int i = 1; i <= number; i++)
     {
         var Sickness = new Sickness();
         string SicknessNumber = i.ToString();
         Sickness.Id = user.FirstName + SicknessNumber;
         Sickness.Subject = new SimpleUser();
         Sickness.Subject.UserId = user.Id;
         Sickness.Subject.FullName = user.FirstName +" "+ user.LastName;
         Sicknesses.Add(Sickness);
     }
     return Sicknesses;
 }
Ejemplo n.º 8
0
 public void SicknessCostTest2()
 {
     var sickness1 = new Sickness();
     sickness1.StartOfProcess = new DateTime(2013, 1, 1);
     sickness1.EndOfProcess = new DateTime(2013, 9, 10);
     var store = CreateTestDatabase();
     using (var session = store.OpenSession())
     {
         session.Store(sickness1);
         session.SaveChanges();
     }
     var result = Sickness.GetSicknessCosts(store);
     //out of 31 days in january, 8 are on the weekend and 1 is a bank holiday. 28 days in feb, 8 weekend, no bank holidays, 15 working days in March
     var sicknessCosts = new int[12, 2] { { 1, 22 }, { 2, 20 }, { 3, 20 }, { 4, 21 }, { 5, 21 }, { 6, 20 }, { 7, 23 }, { 8, 21 }, { 9, 8 }, { 10, 0 }, { 11, 0 }, { 12, 0 }, };
     //sicknessCosts[0, 1] += 22;// business days in jan (1 bank holiday)
     //sicknessCosts[1, 1] += 20;//business days in feb
     //sicknessCosts[2, 1] += 20;// business days in march (1 bank holiday)
     //sicknessCosts[3, 1] += 21;// business days in april (1 bank holiday)// 21 work days in aug// 23 in july// 20 in june// 20 in may
     int number = 0;
     for (int i = 0; i < 12; i++)
     {
         number += sicknessCosts[i, 0] - result[i, 0];
         number += sicknessCosts[i, 1] - result[i, 1];
     }
     Assert.AreEqual(number, 0);
     var sickness2 = new Sickness();
     sickness2.StartOfProcess = new DateTime(2012, 12, 31);
     sickness2.EndOfProcess = new DateTime(2013, 1, 5);// should be two days, one in dec, one in jan
     using (var session = store.OpenSession())
     {
         session.Store(sickness2);
         session.SaveChanges();
     }
     sicknessCosts[11, 1] += 1;
     sicknessCosts[0, 1] += 3;
     //sicknessCosts[0, 1] += 1;- argh, does it ending on 2nd mean back to work on 2nd or 3rd?
     var result2 = Sickness.GetSicknessCosts(store);
     number = 0;
     for (int i = 0; i < 12; i++)
     {
         number += sicknessCosts[i, 0] - result2[i, 0];
         number += sicknessCosts[i, 1] - result2[i, 1];
     }
     Assert.AreEqual(number, 0);
     var sickness3 = new Sickness();
     sickness3.StartOfProcess = new DateTime(2012, 11, 11);// end of process being null means this one will only work today.
     sickness3.EndOfProcess = new DateTime(2013, 05, 11);// 1 day in december, 23 in jan, 20 feb, 18 in march, 20 in april, 8 in may
     using (var session = store.OpenSession())
     {
         session.Store(sickness3);
         session.SaveChanges();
     }
     sicknessCosts[0, 1] += 22;// business days in jan (1 bank holiday)
     sicknessCosts[1, 1] += 20;//business days in feb
     sicknessCosts[2, 1] += 20;// business days in march (1 bank holiday)
     sicknessCosts[3, 1] += 21;// business days in april (1 bank holiday)
     sicknessCosts[4, 1] += 7;
     sicknessCosts[11, 1] += 21;// last year bank holidays not included...
     sicknessCosts[10, 1] += 15;
     var result3 = Sickness.GetSicknessCosts(store);
     number = 0;
     for (int i = 0; i < 12; i++)
     {
         number += sicknessCosts[i, 0] - result3[i, 0];
         number += sicknessCosts[i, 1] - result3[i, 1];
     }
     Assert.AreEqual(number, 0);
 }