Ejemplo n.º 1
0
        string ValidateEnvelopeSoftErrors()
        {
            if (!IsValid())
            {
                throw new InvalidOperationException("Can only validate soft errors after hard errors have been removed");
            }
            if (!WasEnvelopeRandomised)
            {
                return(null);
            }
            string envelopeSoftError = ((IDataErrorInfo)_patient)["EnvelopeNumber"];

            if (envelopeSoftError != null)
            {
                string userMsg = string.Format(Strings.NewPatientViewModel_SoftError_Envelope, envelopeSoftError);
                var    result  = MessageBox.Show(userMsg, Strings.NewPatientViewModel_SoftError_WarningMsg, MessageBoxButton.OKCancel, MessageBoxImage.Warning);
                if (result == MessageBoxResult.Cancel)
                {
                    return(CancelString);
                }
                Envelope envelope          = EnvelopeDetails.GetEnvelope(EnvelopeNumber.Value);
                int      bottomWeightRange = envelope.WeightLessThan == 1000 ?
                                             0 :
                                             envelope.WeightLessThan - 500;
                return(string.Format("Randomised incorrectly - envelope {0} was designated for a {1}-{2}g {3}, but patient is a {4}g {5}",
                                     EnvelopeNumber,
                                     bottomWeightRange,
                                     envelope.WeightLessThan - 1,
                                     envelope.IsMale ? "Male" : "Female",
                                     AdmissionWeight,
                                     IsMale.Value ? "Male" : "Female"));
            }
            return(null);
        }
Ejemplo n.º 2
0
 string ValidateEnvelopeNumber(bool hardErrorsOnly)
 {
     if (!WasEnvelopeRandomised || !OkToRandomise() || (!IsNewRecord && !EnvelopeNumber.HasValue)) //last logical condition because those siblings who followed randomised to the same arm as another sibbling during envelope randomisation phase
     {
         return(null);
     }
     if (!MultipleSiblingId.HasValue && !EnvelopeNumber.HasValue)
     {
         return(Strings.Field_Error_Empty);
     }
     else if (EnvelopeNumber > StudyCentre.MaxIdForSite || EnvelopeNumber < StudyCentre.Id)
     {
         return(string.Format(Strings.NewPatientModel_Error_IdOutOfRangeForSite, StudyCentre.Id, StudyCentre.MaxIdForSite));
     }
     else
     {
         var envelope = EnvelopeDetails.GetEnvelope(EnvelopeNumber.Value);
         if (envelope == null)
         {
             return(Strings.NewPatientModel_Error_EnvelopeNotFound);
         }
         if (!hardErrorsOnly)
         {
             if (AdmissionWeight >= envelope.WeightLessThan ||
                 (envelope.WeightLessThan != 1000 && AdmissionWeight < envelope.WeightLessThan - 500))
             {
                 if (envelope.IsMale != IsMale)
                 {
                     return(Strings.NewPatientModel_Error_EnvelopeDualIncorrect);
                 }
                 return(Strings.NewPatientModel_Error_EnvelopeWeightIncorrect);
             }
             if (envelope.IsMale != IsMale)
             {
                 return(Strings.NewPatientModel_Error_EnvelopeGenderIncorrect);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        public Participant AddParticipant(
            string name,
            string mothersName,
            string hospitalIdentifier,
            int admissionWeight,
            double gestAgeBirth,
            DateTime dateTimeBirth,
            string AdmissionDiagnosis,
            string phoneNumber,
            bool isMale,
            bool?inborn,
            DateTime registeredAt,
            int centreId,
            MaternalBCGScarStatus maternalBCGScar,
            int?multipleSiblingId,
            int?envelopeNumber = null)
        {
            Participant newParticipant = new Participant
            {
                Name                    = name,
                MothersName             = mothersName,
                HospitalIdentifier      = hospitalIdentifier.Trim(),
                AdmissionWeight         = admissionWeight,
                GestAgeBirth            = gestAgeBirth,
                DateTimeBirth           = dateTimeBirth,
                AdmissionDiagnosis      = AdmissionDiagnosis,
                PhoneNumber             = phoneNumber,
                IsMale                  = isMale,
                Inborn                  = inborn,
                RegisteredAt            = registeredAt,
                RegisteringInvestigator = System.Threading.Thread.CurrentPrincipal.Identity.Name,
                CentreId                = centreId,
                WasEnvelopeRandomised   = envelopeNumber.HasValue,
                MaternalBCGScar         = maternalBCGScar,
                AppVersionAtEnrollment  = App.CurrentAppVersion,
                VaccinesAdministered    = new List <VaccineAdministered>()
            };

            if (multipleSiblingId.HasValue)
            {
                var multipleSibling = _dbContext.Participants.Find(multipleSiblingId.Value);
                if (multipleSibling == null)
                {
                    throw new ArgumentException("Participant Not Found", "multipleSiblingId");
                }
                if (multipleSibling.IsMale == newParticipant.IsMale)
                {
                    newParticipant.TrialArm          = multipleSibling.TrialArm;
                    newParticipant.MultipleSiblingId = multipleSiblingId;
                    if (envelopeNumber.HasValue)
                    {
                        newParticipant.Id = (from p in _dbContext.Participants
                                             where p.Id > EnvelopeDetails.MaxEnvelopeNumber
                                             orderby p.Id descending
                                             select p.Id).FirstOrDefault();
                        if (newParticipant.Id == 0)
                        {
                            newParticipant.Id = EnvelopeDetails.MaxEnvelopeNumber;
                        }
                        newParticipant.Id += 1;
                    }
                    else
                    {
                        newParticipant.Id = GetNextId(_dbContext.Participants, centreId);
                        Engine.ForceAllocationToArm(newParticipant, _dbContext);
                    }
                }
            }
            if (!newParticipant.MultipleSiblingId.HasValue)
            {
                if (envelopeNumber.HasValue)
                {
                    Envelope envelope = EnvelopeDetails.GetEnvelope(envelopeNumber.Value);
                    if (!_dbContext.AllocationBlocks.Any(a => a.Id == envelope.BlockNumber))
                    {
                        _dbContext.AllocationBlocks.Add(new AllocationBlock
                        {
                            Id                    = envelope.BlockNumber,
                            GroupRepeats          = (byte)(envelope.BlockSize / 2),
                            AllocationGroup       = AllocationGroups.India2Arm,
                            RandomisationCategory = envelope.RandomisationCategory
                        });
                    }
                    newParticipant.AllocationBlockId = envelope.BlockNumber;
                    newParticipant.TrialArm          = envelope.IsInterventionArm ? RandomisationArm.RussianBCG : RandomisationArm.Control;
                    newParticipant.Id = envelopeNumber.Value;
                }
                else
                {
                    newParticipant.Id = GetNextId(_dbContext.Participants, centreId);
                    Engine.CreateAllocation(newParticipant, _dbContext);
                }
            }
            Add(newParticipant);
            return(newParticipant);
        }