public CohortRuleResponse Run(CareTeam careTeam, CohortRuleCheckData data) { var response = new CohortRuleResponse(); try { if (careTeam == null) { throw new ArgumentNullException("careTeam"); } //For each member in the careteam that is a user, add an ATO cohort for the referenced individual var contactIdsToAdd = new List <string>(); foreach (var member in careTeam.Members) { if (member.StatusId == (int)CareTeamMemberStatus.Active) { if (data.UsersContactIds.Contains(member.ContactId)) { contactIdsToAdd.Add(member.ContactId); } } } _contactEndpointUtil.AssignContactsToCohortPatientView(data.PatientId, contactIdsToAdd.Distinct().ToList(), data.Version, data.ContractNumber, data.UserId); response.IsSuccessful = true; } catch (Exception ex) { response.IsSuccessful = false; response.ErrorCode = "AssignedToMeRule.Cohort.Error"; response.Message = ex.Message; _logger.Log(ex); } return(response); }