Exemplo n.º 1
0
        public IEnumerable<PatientProcedure> GetPatientProcedures(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientProcedures)
        {
            fixture.Customize<PatientProcedure>(pp => pp.With(x => x.PatientId, demographic.PatientId)
                                                        .Without(x => x.CptHcpcs));

            var procedures = fixture.CreateMany<PatientProcedure>(randomizer.Next(0, maxNumberOfPatientProcedures + 1)).ToList();
            foreach (var procedure in procedures)
            {
                procedure.ProcedureDate = procedure.ProcedureDate.Date;

                var hasFavoredProcedure = randomizer.NextPercent() <= ChanceOfHavingFavoredProcedure;
                procedure.CptHcpcs = hasFavoredProcedure ? randomizer.NextListElement(_favoredProcedureCodes) : GetRandomProcedure(randomizer);

                var isProcedureRecent = randomizer.NextPercent() <= ChanceOfHavingRecentProcedure;
                if(isProcedureRecent)
                {
                    var oldestRecentDateTime = DateTime.Today.AddMonths(-6);
                    if(procedure.ProcedureDate < oldestRecentDateTime)
                    {
                        var maximumNumberOfDaysForRecent = (int)(DateTime.Today - oldestRecentDateTime).TotalDays;
                        var daysAgo = randomizer.Next(1, maximumNumberOfDaysForRecent);
                        procedure.ProcedureDate = DateTime.Today.AddDays(-daysAgo);
                    }
                }
            }

            return procedures.OrderBy(x => x.ProcedureDate);
        }
Exemplo n.º 2
0
        public IEnumerable<PatientTherapy> GetPatientTherapies(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientTherapies)
        {
            fixture.Customize<PatientTherapy>(pt => pt.With(x => x.PatientId, demographic.PatientId)
                                                      .Without(x => x.DDID)
                                                      .Without(x => x.RXNorm)
                                                      .Without(x => x.StopDate));

            var therapies = fixture.CreateMany<PatientTherapy>(randomizer.Next(0, maxNumberOfPatientTherapies + 1));
            foreach (var therapy in therapies)
            {
                var daysOnTherapy = randomizer.Next(1, 365);
                therapy.StopDate = new DateTime(Math.Min(therapy.StartDate.AddDays(daysOnTherapy).Ticks, DateTime.Now.Ticks));

                var hasFavoredTherapy = randomizer.NextPercent() <= ChanceOfHavingFavoredCondition;
                if (hasFavoredTherapy)
                {
                    var pair = randomizer.NextDictionaryPair(_favoredTherapies);
                    therapy.NDC = pair.Key;
                    therapy.DrugName = pair.Value;
                }
                else
                {
                    therapy.NDC = NDCGenerator.GetRandomNDC(randomizer);
                }
            }

            return therapies.OrderBy(x => x.StartDate);
        }
Exemplo n.º 3
0
        public IEnumerable<PatientDiagnosis> GetPatientDiagnoses(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientDiagnoses)
        {
            fixture.Customize<PatientDiagnosis>(pd => pd.With(x => x.PatientId, demographic.PatientId)
                                                        .Without(x => x.DiagnosisDescription)
                                                        .Without(x => x.ICD9)
                                                        .Without(x => x.ICD10));

            var diagnoses = fixture.CreateMany<PatientDiagnosis>(randomizer.Next(0, maxNumberOfPatientDiagnoses + 1)).ToList();
            foreach (var diagnosis in diagnoses)
            {
                var hasFavoredDiagnosis = randomizer.NextPercent() <= ChanceOfHavingFavoredDiagnosis;
                var entry = hasFavoredDiagnosis ? GetSubsetEntry(randomizer, _favoredDiagnosisCodes) : randomizer.NextListElement(_icd9Entries);
                DecoratePatientDiagnosisFromICD9Entry(diagnosis, entry);
            }

            var hasInclusionDiagnosis = randomizer.NextPercent() <= ChanceOfHavingInclusionDiagnosis;
            if (hasInclusionDiagnosis)
            {
                var entry = GetSubsetEntry(randomizer, _inclusionDiagnosisCodes);
                if (entry != null)
                {
                    var diagnosis = fixture.Create<PatientDiagnosis>();
                    DecoratePatientDiagnosisFromICD9Entry(diagnosis, entry);
                    diagnoses.Add(diagnosis);
                }
            }

            var hasExclusionDiagnosis = randomizer.NextPercent() <= ChanceOfHavingExclusionDiagnosis;
            if (hasExclusionDiagnosis)
            {
                var entry = GetSubsetEntry(randomizer, _exclusionDiagnosisCodes);
                if (entry != null)
                {
                    var diagnosis = fixture.Create<PatientDiagnosis>();
                    DecoratePatientDiagnosisFromICD9Entry(diagnosis, entry);
                    diagnoses.Add(diagnosis);
                }
            }

            return diagnoses.OrderBy(x => x.DiagnosisDate);
        }
Exemplo n.º 4
0
        public IEnumerable<PatientLab> GetPatientLabs(Fixture fixture, Random randomizer, PatientDemographics demographic, int maxNumberOfPatientLabs)
        {
            fixture.Customize<PatientLab>(pl => pl.With(x => x.PatientId, demographic.PatientId));

            var labs = fixture.CreateMany<PatientLab>(randomizer.Next(0, maxNumberOfPatientLabs + 1)).OrderBy(x => x.LabDate);
            foreach (var lab in labs)
            {
                var hasFavoredLab = randomizer.NextPercent() <= ChanceOfHavingFavoredLab;
                if (hasFavoredLab)
                {
                    var pair = randomizer.NextDictionaryPair(_favoredLabs);
                    lab.LabName = pair.Key.Replace("[NORMAL]", string.Empty).Replace("[ABNORMAL]", string.Empty);
                    lab.Value = pair.Value.Invoke(randomizer);
                }
            }

            return labs;
        }
Exemplo n.º 5
0
        public double GetBMI(Random randomizer, bool obese = false, double? baseBMI = null)
        {
            var minimumBMI = obese ? MinimumObeseBMI : MinimumNormalBMI;
            var maximumBMI = obese ? MaximumObeseBMI : MaximumNormalBMI;

            var bmi = baseBMI ?? randomizer.Next(minimumBMI, maximumBMI + 1);
            if (baseBMI.HasValue)
            {
                var hasBMIChanged = randomizer.NextPercent() <= ChanceOfBMIChange;
                if (hasBMIChanged)
                {
                    var direction = randomizer.NextDouble() > 0.5 ? 1 : -1;
                    var delta = randomizer.Next(0, MaximumDelta + 1) * direction;
                    bmi += delta;
                }
            }

            return Math.Max(Math.Min(bmi, maximumBMI), minimumBMI);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var randomizer = new Random((int)DateTime.Now.Ticks);

            var allClaimsTherapies = new List<ClaimsTherapy>();
            var allClaimsUtilizations = new List<ClaimsUtilization>();
            var allPatientAllergies = new List<PatientAllergy>();
            var allPatientClinicals = new List<PatientClinical>();
            var allPatientDemographics = new List<PatientDemographics>();
            var allPatientDiagnoses = new List<PatientDiagnosis>();
            var allPatientLabs = new List<PatientLab>();
            var allPatientProcedures = new List<PatientProcedure>();
            var allPatientTherapies = new List<PatientTherapy>();
            var allPatientUtilizations = new List<PatientUtilization>();

            var fixture = new Fixture();
            fixture.Customizations.Add(new PatientSpecimenBuilder());

            int maxNumberOfClaimsTherapies = 5;
            int maxNumberOfClaimsUtilizations = 10;
            int maxNumberOfPatientAllergies = 5;
            int maxNumberOfPatientClinicals = 10;
            int maxNumberOfPatientDiagnoses = 10;
            int maxNumberOfPatientLabs = 20;
            int maxNumberOfPatientProcedures = 5;
            int maxNumberOfPatientTherapies = 20;
            int maxNumberOfPatientUtilizations = 15;
            int numberOfPatients = 50;
            for (int i = 0; i < numberOfPatients; i++)
            {
                var alcoholAbuse = fixture.Create<bool>();
                var drugAbuse = fixture.Create<bool>();
                var smoker = fixture.Create<bool>();

                var chanceOfObesity = 15;
                var obese = randomizer.NextPercent() < chanceOfObesity;

                var demographic = PatientDemographicBuilder.Instance.GetPatientDemographic(randomizer);
                var clinicals = PatientClinicalBuilder.Instance.GetPatientClinicals(fixture, randomizer, demographic, alcoholAbuse, drugAbuse, smoker, obese, maxNumberOfPatientClinicals);
                var utilizations = PatientUtilizationBuilder.Instance.GetPatientUtilizations(fixture, randomizer, demographic, maxNumberOfPatientUtilizations);
                var diagnoses = PatientDiagnosisBuilder.Instance.GetPatientDiagnoses(fixture, randomizer, demographic, maxNumberOfPatientDiagnoses);
                var labs = PatientLabBuilder.Instance.GetPatientLabs(fixture, randomizer, demographic, maxNumberOfPatientLabs);
                var therapies = PatientTherapyBuilder.Instance.GetPatientTherapies(fixture, randomizer, demographic, maxNumberOfPatientTherapies);
                var allergies = PatientAllergyBuilder.Instance.GetPatientAllergies(fixture, randomizer, demographic, maxNumberOfPatientAllergies);
                var procedures = PatientProcedureBuilder.Instance.GetPatientProcedures(fixture, randomizer, demographic, maxNumberOfPatientProcedures);
                var claimsUtilizations = ClaimsUtilizationBuilder.Instance.GetClaimsUtilizations(fixture, randomizer, demographic, alcoholAbuse, drugAbuse, maxNumberOfClaimsUtilizations);
                var claimsTherapies = ClaimsTherapyBuilder.Instance.GetClaimsTherapies(fixture, randomizer, demographic, alcoholAbuse, drugAbuse, maxNumberOfClaimsTherapies);

                allClaimsTherapies.AddRange(claimsTherapies);
                allClaimsUtilizations.AddRange(claimsUtilizations);
                allPatientAllergies.AddRange(allergies);
                allPatientClinicals.AddRange(clinicals);
                allPatientDemographics.Add(demographic);
                allPatientDiagnoses.AddRange(diagnoses);
                allPatientLabs.AddRange(labs);
                allPatientProcedures.AddRange(procedures);
                allPatientTherapies.AddRange(therapies);
                allPatientUtilizations.AddRange(utilizations);
            }

            string FOLDERPATH = "c:\\temp";
            string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
            var writer = new CsvWriter();
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientdemographics.csv", allPatientDemographics);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientclinicals.csv", allPatientClinicals);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientutilizations.csv", allPatientUtilizations);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientdiagnoses.csv", allPatientDiagnoses);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientlabs.csv", allPatientLabs);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patienttherapies.csv", allPatientTherapies);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientallergies.csv", allPatientAllergies);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.patientprocedures.csv", allPatientProcedures);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.claimstherapies.csv", allClaimsTherapies);
            writer.WriteToFile($"{FOLDERPATH}\\{timestamp}.unofficial.claimsutilizations.csv", allClaimsUtilizations);
        }