public Patient(string name, PatientCondition condition, ConditionTopography topography = ConditionTopography.None) { Name = name; Condition = condition; if (Condition == PatientCondition.Cancer && topography == ConditionTopography.None) { throw new ArgumentException("Missing Condition Topography..."); } PatientConditionTopography = topography; }
private static void RunTask(int id, StreamWriter logFile, CancellationToken cancelToken) { ss.Release(); WriteLine(string.Format("Starting task ID: {0}", id), logFile); Thread.Sleep(1000); var optionRandom = new Random(); var conditionRandom = new Random(); var topographyRandom = new Random(); var nameRandom = new Random(); for (int j = 1; j < noOfOperations; j++) { if (cancelToken.IsCancellationRequested) { WriteLine(string.Format("Task [{0}] cancelled", id), logFile); break; } var option = optionRandom.Next(1, 5); switch (option) { case 1: var cr = conditionRandom.Next(1, 19) % conditionRandom.Next(1, 19); PatientCondition pc = PatientCondition.Flu; if (cr % 2 == 0) { pc = PatientCondition.Cancer; } ConditionTopography ct = ConditionTopography.None; if (pc == PatientCondition.Cancer) { var t = topographyRandom.Next(1, 29) % topographyRandom.Next(1, 29); ct = ConditionTopography.HeadAndNeck; if (t % 3 == 0) { ct = ConditionTopography.Breast; } } var p = new Patient(string.Format("Test_{0} Patient_{1}", id * j, id * j + 1), pc, ct); patientNames.TryAdd(p.Name, p.Name); Program.RegisterPatient(p); WriteLine(string.Format("Initiated Registration for Patient '{0}'", p), logFile); break; case 2: var names = patientNames.ToList(); if (!names.Any()) { Thread.Sleep(100); continue; } var nameIndex = nameRandom.Next(0, names.Count); var result = Program.IsRegistrationSuccessful(names[nameIndex].Key); if (!result.Item1) { WriteLine(string.Format("Failed to Register patient: '{0}' will check later", names[nameIndex].Key), logFile); } break; case 3: Program.GetRegisteredPatients(logFile); break; case 4: Program.GetScheduledConsultations(logFile); break; default: break; } } WriteLine(string.Format("Task [{0}] End", id), logFile); }