Exemplo n.º 1
0
 string ValidateWeight()
 {
     if (LastContactWeight.HasValue)
     {
         var weightChange    = (double)LastContactWeight / (double)AdmissionWeight;
         var weightCat       = RandomisingExtensions.RandomisationCategory(AdmissionWeight, true); // a slight hack making everone male to test weight cats!
         int?daysOldAtWeight = (LastWeightDate.HasValue)?
                               (LastWeightDate.Value - DateTimeBirth.Date).Days
             :(int?)null;
         if (weightChange < 0.8 ||
             weightChange > 1.6 ||
             (weightCat == RandomisationStrata.MidWeightMale && weightChange > 1.5) ||
             (weightCat == RandomisationStrata.SmallestWeightMale && weightChange > 1.5) ||
             (daysOldAtWeight.HasValue &&
              (daysOldAtWeight < 21 && (weightChange > 1.4 ||
                                        (weightCat == RandomisationStrata.MidWeightMale && weightChange > 1.4) ||
                                        (weightCat == RandomisationStrata.SmallestWeightMale && weightChange > 1.4))) ||
              (daysOldAtWeight < 14 && weightChange > 1.3)))
         {
             return(string.Format(Strings.ParticipantModel_Error_LastWeightChange, AdmissionWeight));
         }
     }
     else if (LastWeightDate.HasValue)
     {
         return(Strings.ParticipantModel_Error_WeightNotFound);
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="isMale"></param>
        /// <param name="phoneNumber"></param>
        /// <param name="AdmissionDiagnosis"></param>
        /// <param name="admissionWeight"></param>
        /// <param name="dateTimeBirth"></param>
        /// <param name="gestAgeBirth"></param>
        /// <param name="hospitalIdentifier"></param>
        /// <param name="isInborn"></param>
        /// <param name="multipleSibblingId"></param>
        /// <param name="registeredAt"></param>
        /// <returns>Whether a protocol violation has been logged due to randomising criteria being altered</returns>
        public UpdateParticipantViolationType UpdateParticipant(int id,
                                                                string name,
                                                                bool isMale,
                                                                string phoneNumber,
                                                                string AdmissionDiagnosis,
                                                                int admissionWeight,
                                                                DateTime dateTimeBirth,
                                                                double gestAgeBirth,
                                                                string hospitalIdentifier,
                                                                bool?isInborn,
                                                                int?multipleSibblingId,
                                                                MaternalBCGScarStatus maternalBCGScar,
                                                                DateTime registeredAt,
                                                                bool isEnvelopeRandomising)
        {
            Participant participant = _dbContext.Participants.Find(id);
            var         pv          = new List <ProtocolViolation>();
            UpdateParticipantViolationType returnVar = UpdateParticipantViolationType.NoViolations;

            if (!RandomisingExtensions.IsSameRandomisingCategory(participant.IsMale, isMale, participant.AdmissionWeight, admissionWeight))
            {
                pv.Add(new ProtocolViolation
                {
                    Details = string.Format(BlockRandomisationViolation + "Block randomising information changed from {0}g {1} to {2}g {3}",
                                            participant.AdmissionWeight,
                                            GenderString(participant.IsMale),
                                            admissionWeight,
                                            GenderString(isMale))
                });
                Engine.RemoveAllocationFromArm(participant, _dbContext);
                returnVar |= UpdateParticipantViolationType.BlockCriteriaChanged;
            }
            if (admissionWeight > Engine.MaxBirthWeightGrams)
            {
                pv.Add(new ProtocolViolation
                {
                    Details = string.Format("Retrospectively inelligible participant!: Weight changed from {0} to {1}", participant.AdmissionWeight, admissionWeight)
                });

                participant.AdmissionWeight = admissionWeight;
                returnVar |= UpdateParticipantViolationType.IneligibleWeight;
            }
            if (participant.MultipleSiblingId != multipleSibblingId)
            {
                pv.Add(new ProtocolViolation
                {
                    Details = string.Format(BlockRandomisationViolation + "Twin/tripplet ID changed from '{0}' to '{1}';", participant.MultipleSiblingId, multipleSibblingId)
                });
                participant.MultipleSiblingId = multipleSibblingId;
                returnVar |= UpdateParticipantViolationType.MultipleSiblingIdChanged;
            }
            int nextPvId = GetNextId(_dbContext.ProtocolViolations, participant.CentreId);

            foreach (var p in pv)
            {
                p.ParticipantId         = participant.Id;
                p.Id                    = nextPvId++;
                p.ViolationType         = ViolationTypeOption.MajorWrongAllocation;
                p.ReportingTimeLocal    = DateTime.Now;
                p.ReportingInvestigator = System.Threading.Thread.CurrentPrincipal.Identity.Name;
                _dbContext.ProtocolViolations.Add(p);
            }
            participant.Name               = name;
            participant.PhoneNumber        = phoneNumber;
            participant.AdmissionDiagnosis = AdmissionDiagnosis;
            participant.DateTimeBirth      = dateTimeBirth;
            participant.GestAgeBirth       = gestAgeBirth;
            participant.HospitalIdentifier = hospitalIdentifier;
            participant.Inborn             = isInborn;
            participant.RegisteredAt       = registeredAt;
            participant.MaternalBCGScar    = maternalBCGScar;
            if ((returnVar & UpdateParticipantViolationType.BlockCriteriaChanged) != 0)
            {
                Engine.ForceAllocationToArm(participant, _dbContext);
            }
            _dbContext.SaveChanges(true);
            this.ParticipantUpdated?.Invoke(this, new ParticipantEventArgs(participant));
            return(returnVar);
        }