public async Task <Guid> CreateUnsavedQueryAsync(PatientCohort cohort, IUserContext user) { var nonce = NonceOrThrowIfNull(user); log.LogInformation("Creating Unsaved Cohort."); using (var cn = new SqlConnection(dbOptions.ConnectionString)) { await cn.OpenAsync(); var queryId = await cn.ExecuteScalarAsync <Guid>( queryCreateUnsaved, new { user = user.UUID, nonce }, commandType : CommandType.StoredProcedure, commandTimeout : dbOptions.DefaultTimeout ); if (cohort.Count <= cohortOptions.RowLimit) { var cohortTable = new PatientCohortTable(queryId, cohort.SeasonedPatients(cohortOptions.ExportLimit, queryId)); using (var bc = new SqlBulkCopy(cn)) { bc.DestinationTableName = PatientCohortTable.Table; await bc.WriteToServerAsync(cohortTable.Rows); } } return(queryId); } }
public void SeasonedPatients_Should_Only_Export_Up_To_MaxSize() { var cohort = new PatientCohort { PatientIds = new HashSet <string>(new string[] { "a", "b", "c", "d", "e", "f", "g" }) }; }