public async Task <CohortGroupDetailDto> Handle(AddCohortGroupCommand message, CancellationToken cancellationToken) { var conditionFromRepo = await _conditionRepository.GetAsync(c => c.Description == message.ConditionName); if (conditionFromRepo == null) { throw new KeyNotFoundException("Unable to locate condition"); } if (_cohortGroupRepository.Exists(cg => cg.CohortName == message.CohortName || cg.CohortCode == message.CohortCode)) { throw new DomainException("Cohort group with same name already exists"); } var newCohortGroup = new CohortGroup(message.CohortName, message.CohortCode, conditionFromRepo, message.StartDate, message.FinishDate); await _cohortGroupRepository.SaveAsync(newCohortGroup); _logger.LogInformation($"----- Cohort group {message.CohortName} created"); var mappedCohortGroup = _mapper.Map <CohortGroupDetailDto>(newCohortGroup); return(CreateLinks(mappedCohortGroup)); }
public void MapCohortGroup_WhenCreatingMap() { //arrange List <CohortMember> cohortMembers = new List <CohortMember>() { new CohortMember { CustomerId = 1, OrderNumber = 0, TransactionDate = new DateTime(2015, 01, 01), CohortDate = new DateTime(2015, 01, 01), CohortIdentifier = new DateTime(2015, 01, 01), CohortPeriod = 1.0, }, new CohortMember { CustomerId = 2, OrderNumber = 0, TransactionDate = new DateTime(2015, 01, 01), CohortDate = new DateTime(2015, 01, 01), CohortIdentifier = new DateTime(2015, 01, 01), CohortPeriod = 2.0, }, new CohortMember { CustomerId = 1, OrderNumber = 0, TransactionDate = new DateTime(2015, 01, 02), CohortDate = new DateTime(2015, 01, 02), CohortIdentifier = new DateTime(2015, 01, 02), CohortPeriod = 2.0, }, }; Mock <IOptions <Settings> > mockSettings = new Mock <IOptions <Settings> >(); mockSettings.Setup(ap => ap.Value).Returns(new Settings { LifeCycleRange = 7, CohortDateFormat = "MM/dd/yy" }); CohortCalculationLogic calculationLogic = new CohortCalculationLogic(mockSettings.Object); IEnumerable <IGrouping <DateTime, CohortMember> > bucket = cohortMembers.GroupBy(cm => cm.CohortIdentifier); //act CohortGroup result = calculationLogic.MapCohortGroup(bucket.First()); //assert Assert.Equal("01/01/15 - 01/01/15", result.CohortRange); Assert.Equal(2, result.Customers); Assert.Equal(2, result.Buckets.Count()); }
protected void Page_Init(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { _id = Convert.ToInt32(Request.QueryString["id"]); _cohort = GetCohortGroup(_id); txtCohortName.Value = _cohort.CohortName; txtCohortCode.Value = _cohort.CohortCode; } else { throw new Exception("id not passed as parameter"); } }
protected void Page_Init(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { _id = Convert.ToInt32(Request.QueryString["id"]); _cohort = GetCohortGroup(_id); _cohortSummary = new CohortSummary() { CohortGroupId = _id }; txtCohortName.Value = _cohort.CohortName; txtCohortCode.Value = _cohort.CohortCode; txtCohortCondition.Value = _cohort.Condition != null ? _cohort.Condition.Description : ""; } else { throw new Exception("id not passed as parameter"); } }
public ActionResult AddCohort(CohortAddModel model) { ViewBag.MenuItem = CurrentMenuItem; if (ModelState.IsValid) { if (unitOfWork.Repository <CohortGroup>().Queryable().Any(cg => cg.CohortName == model.CohortName)) { ModelState.AddModelError("CohortName", "A cohort with the specified name already exists."); } if (Regex.Matches(model.CohortName, @"[a-zA-Z0-9 ']").Count < model.CohortName.Length) { ModelState.AddModelError("CohortName", "Cohort name contains invalid characters (Enter A-Z, a-z, 0-9)"); } if (unitOfWork.Repository <CohortGroup>().Queryable().Any(cg => cg.CohortCode == model.CohortCode)) { ModelState.AddModelError("CohortCode", "A cohort with the specified code already exists."); } if (Regex.Matches(model.CohortCode, @"[-a-zA-Z0-9 ']").Count < model.CohortCode.Length) { ModelState.AddModelError("CohortCode", "Cohort code contains invalid characters (Enter -, A-Z, a-z, 0-9)"); } if (model.StartDate != null) { if (model.StartDate > DateTime.Today) { ModelState.AddModelError("StartDate", "Start Date should be before current date"); } } else { ModelState.AddModelError("StartDate", "Start Date is mandatory"); } if (model.FinishDate != null) { if (model.FinishDate > DateTime.Today.AddYears(20)) { ModelState.AddModelError("FinishDate", "End Date should be within 20 years"); } if (model.FinishDate < model.StartDate) { ModelState.AddModelError("FinishDate", "End Date should be after Start Date"); } } var encodedName = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.CohortName, false); var encodedCode = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.CohortCode, false); var condition = unitOfWork.Repository <Condition>().Queryable().SingleOrDefault(cg => cg.Id == model.ConditionId); var newCohort = new CohortGroup { CohortName = encodedName, CohortCode = encodedCode, Condition = condition, FinishDate = model.FinishDate, StartDate = Convert.ToDateTime(model.StartDate), MaxEnrolment = 0, MinEnrolment = 0, LastPatientNo = 0 }; try { if (ModelState.IsValid) { unitOfWork.Repository <CohortGroup>().Save(newCohort); return(Redirect("/Cohort/CohortSearch.aspx")); } } catch (Exception ex) { ModelState.AddModelError("CohortName", string.Format("Unable to add the cohort: {0}", ex.Message)); } } var conditions = unitOfWork.Repository <Condition>() .Queryable() .ToList(); var cgList = new List <SelectListItem> { { new SelectListItem { Value = "", Text = "" } } }; cgList.AddRange(conditions.Select(cg => new SelectListItem { Value = cg.Id.ToString(), Text = cg.Description })); ViewBag.Conditions = cgList; return(View(model)); }