public void AddOrUpdate(ProtocolViolation violation) { if (violation.ParticipantId == 0) { throw new ArgumentException("Participant Id must have a value"); } bool isToAdd = violation.Id == 0; if (isToAdd) { int centreId = (from p in _dbContext.Participants where p.Id == violation.ParticipantId select p.CentreId).First(); violation.Id = GetNextId(_dbContext.ProtocolViolations, centreId); violation.ReportingTimeLocal = DateTime.Now; violation.ReportingInvestigator = System.Threading.Thread.CurrentPrincipal.Identity.Name; _dbContext.ProtocolViolations.Add(violation); } else { ((DbContext)_dbContext).AttachAndMarkModified(violation); } _dbContext.SaveChanges(true); this.ProtocolViolationAddOrUpdate?.Invoke(this, new ProtocolViolationEventArgs(violation, isToAdd ? CRUD.Created : CRUD.Updated)); }
public void TestRequiredChange() { //var context = new Mock<ITrialDataContext>(); //var repo = new Repository(() => context.Object); var emptyViol = new ProtocolViolation[0]; var now = DateTime.Now; var part = new ParticipantProgressModel { Id = 1, TrialArm = RandomisationArm.RussianBCG, VaccinesAdministered = new VaccineAdministered[0], ProtocolViolations = emptyViol, RegisteredAt = now.AddDays(-1), DateTimeBirth = now.AddHours(-26) }; var partVM = new ParticipantListItemViewModel(part); var changeList = new HashSet <string>(); partVM.PropertyChanged += (o, e) => changeList.Add(e.PropertyName); Assert.AreEqual(DataRequiredOption.BcgDataRequired, partVM.DataRequired); partVM.ProtocolViolations = new ProtocolViolation[] { new ProtocolViolation { Details = "test", Id = 1, ParticipantId = 1, ReportingTimeLocal = now, ViolationType = ViolationTypeOption.MajorWrongTreatment } }; Assert.IsTrue(changeList.Contains("DataRequired"), "DataRequired was not included as a PropertyChanged argument"); Assert.AreEqual(DataRequiredOption.AwaitingOutcomeOr28, partVM.DataRequired); changeList.Clear(); partVM.ProtocolViolations = emptyViol; Assert.IsTrue(changeList.Contains("DataRequired"), "DataRequired was not included as a PropertyChanged argument"); Assert.AreEqual(DataRequiredOption.BcgDataRequired, partVM.DataRequired); changeList.Clear(); partVM.VaccinesAdministered = new VaccineAdministered[] { new VaccineAdministered { AdministeredAt = now, ParticipantId = 1, Id = 1, VaccineGiven = DataContextInitialiser.RussianBcg, VaccineId = DataContextInitialiser.RussianBcg.Id } }; Assert.IsTrue(changeList.Contains("DataRequired"), "DataRequired was not included as a PropertyChanged argument"); Assert.AreEqual(DataRequiredOption.AwaitingOutcomeOr28, partVM.DataRequired); }
void Save(object param) { ProtocolViolation violation = new ProtocolViolation { ViolationType = _violation.ViolationType, Details = _violation.Details, ParticipantId = _violation.Participant.Id }; if (!IsNewRecord) { violation.Id = _violation.Id; violation.ReportingInvestigator = _violation.ReportingInvestigator; violation.ReportingTimeLocal = _violation.ReportingTimeLocal; } _repository.AddOrUpdate(violation); _isRecordAltered = false; OnRequestClose(); }
/// <summary> /// Saves the customer to the repository. This method is invoked by the SaveCommand. /// </summary> /// public void Randomise(object parameter) { #if DEBUG if (!IsValid() || !_patient.OkToRandomise()) { throw new InvalidOperationException("Underlying NewPatientModel does not validate"); } #endif string violationString = null; if (WasEnvelopeRandomised) { violationString = ValidateEnvelopeSoftErrors(); if (violationString == CancelString) { return; } } var newParticipant = _repository.AddParticipant( _patient.Name, _patient.MothersName, _patient.HospitalIdentifier, _patient.AdmissionWeight.Value, _patient.GestAgeBirth.Value, _patient.DateTimeBirth.Value, _patient.AdmissionDiagnosis, _patient.HasNoPhone?null:_patient.PhoneNumber, _patient.IsMale.Value, _patient.IsInborn, _patient.DateTimeOfEnrollment ?? DateTime.Now, StudyCentre.Id, _patient.MaternalBCGScar, HasSiblingEnrolled?_patient.MultipleSiblingId:null, WasEnvelopeRandomised?_patient.EnvelopeNumber:null ); if (violationString != null) { var violation = new ProtocolViolation { ViolationType = ViolationTypeOption.MajorWrongAllocation, Details = violationString, ParticipantId = newParticipant.Id, }; _repository.AddOrUpdate(violation); } if (!false.Equals(parameter)) // for testing purposes, supress dialog { string userMsg; if (newParticipant.TrialArm == Domain.Outcomes.RandomisationArm.Control) { userMsg = string.Format(Strings.NewPatient_ToControl + ' ', newParticipant.Name + '(' + newParticipant.HospitalIdentifier + ')', newParticipant.Id); } else { userMsg = string.Format(Strings.NewPatient_ToIntervention + ' ', newParticipant.Name + '(' + newParticipant.HospitalIdentifier + ')', newParticipant.Id); } userMsg += Environment.NewLine + StudyCentre.RandomisedMessage.InstructionsFor(newParticipant.TrialArm); MessageBox.Show(userMsg, Strings.NewPatient_SuccesfullyRandomised, MessageBoxButton.OK, MessageBoxImage.Information); } ClearAllFields(); }
public ProtocolViolationEventArgs(ProtocolViolation violation, CRUD eventType) { this.Violation = violation; this.EventType = eventType; }