static AllocationGroups GetNextAllocationGroup(Participant participant, RandomisationStrata strata, ITrialDataContext context) { AllocationGroups returnVar = (participant.Centre ?? (participant.Centre = context.StudyCentres.Find(participant.CentreId))).DefaultAllocation; if (returnVar == AllocationGroups.India3ArmUnbalanced) { var alloc = context.BalancedAllocations.First(a => a.RandomisationCategory == strata && a.StudyCentreId == participant.CentreId); if (!alloc.IsEqualised) { var catQuery = from p in context.Participants where p.CentreId == participant.CentreId && p.Block.RandomisationCategory == strata select p; if ((double)catQuery.Count() / catQuery.Count(p => p.TrialArm == RandomisationArm.DanishBcg) <= 3) { alloc.IsEqualised = true; context.SaveChanges(true); if (context.BalancedAllocations.All(a => a.IsEqualised && a.StudyCentreId == participant.CentreId)) { participant.Centre.DefaultAllocation = AllocationGroups.India3ArmBalanced; } } } if (alloc.IsEqualised) { return(AllocationGroups.India3ArmBalanced); } } return(returnVar); }
public static AllocationBlock Get1stUnfilledBlock(Participant participant, out RandomisationStrata strata, ITrialDataContext context) { const string queryTemplate = "SELECT [Id]" + ",[GroupRepeats]" + ",[AllocationGroup]" + ",[RandomisationCategory]" + ",[RecordLastModified]" + " FROM [AllocationBlocks] a" + " JOIN" + " (SELECT AllocationBlockId, COUNT(Id) partCount" + " FROM Participants" + " WHERE Participants.CentreId={0}" + " GROUP BY Participants.AllocationBlockId) s" + " ON s.AllocationBlockId = a.id" + " WHERE a.RandomisationCategory={1} and s.partCount < GroupRepeats *(case a.AllocationGroup {2} end);"; string casestring = string.Join(" ", GetBaseCounts() .Select(kv => string.Format(" when {0} then {1}", (int)kv.Key, kv.Value))); strata = RandomisingExtensions.RandomisationCategory(participant); string query = string.Format(queryTemplate, participant.CentreId, (int)strata, casestring); return(context.AllocationBlocks.SqlQuery(query).FirstOrDefault()); }
static AllocationBlock CreateNewAllocationBlock(Participant participant, RandomisationStrata strata, out BlockComponent component, ITrialDataContext context) { var block = GetNextAllocationGroup(participant, strata, context); component = ArmData.GetRatio(block); if (participant.Centre == null) { participant.Centre = context.StudyCentres.Find(participant.CentreId); } var returnVar = new AllocationBlock { Id = context.AllocationBlocks.GetNextId(participant.CentreId, participant.Centre.MaxIdForSite), AllocationGroup = block, GroupRepeats = component.Repeats, RandomisationCategory = strata }; context.AllocationBlocks.Add(returnVar); return(returnVar); }
static IOrderedQueryable <AllocationBlock> GetDescendingBlocks(StudyCentre centre, RandomisationStrata strata, ITrialDataContext context) { return(from b in context.AllocationBlocks where b.RandomisationCategory == strata && b.Id >= centre.Id && b.Id <= centre.MaxIdForSite orderby b.Id descending select b); }