Exemple #1
0
        public Patient(string p_unitnum)
        {
            unitnum = p_unitnum;

            relativeID = 1;
            relationship = "Self";

            FHx = new FamilyHistory(this);
            owningFHx = FHx;

            MedHx = new MedicationHx(this);
            SocialHx = new SocialHistory(this);
            PhysicalExam = new PhysicalExamination(this);
            ObGynHx = new ObGynHistory(this);
            // deprecated diet = new Diet(this);
            procedureHx = new ProcedureHx(this);
            breastImagingHx = new BreastImagingHx(this);
            transvaginalImagingHx = new TransvaginalImagingHx(this);
            labsHx = new LabsHx(this);
            follupSatus = new FollowupStatus(unitnum, apptid);
            Tasks = new TaskList(this);
            Providers = new ProviderList(this);
            cdsBreastOvary = new CDSBreastOvary(this);
            guiPreferences = new GUIPreferenceList(this);
            PediatricCDS = new PediatricConsiderations(this);
            SurveyReponses = new SurveyResponseList(this);
            MammographyHx = new MammographyHx(this);
        }
Exemple #2
0
        public void AddRelative(RiskApps3.Model.PatientRecord.Patient proband, ViewModels.FamilyHistoryRelative obj)
        {
            /*==============================*/

            RiskApps3.Model.PatientRecord.FHx.FamilyHistory FHX = new RiskApps3.Model.PatientRecord.FHx.FamilyHistory(proband);

            proband.FHx.BackgroundListLoad();

            string relationship = "";
            string bloodline = "";

            int count = 1;

            switch (obj.Relationship)
            {
                case "Son":
                case "Daughter":
                case "Brother":
                case "Sister":
                case "Cousin":
                case "Cousin (Male)":
                case "Cousin (Female)":
                case "Niece":
                case "Nephew":
                case "Other":
                case "Other (Male)":
                case "Other (Female)":
                    relationship = obj.Relationship;
                    break;
                case "Aunt - Maternal":
                    relationship = "Aunt";
                    bloodline = "Maternal";
                    break;
                case "Aunt - Paternal":
                    relationship = "Aunt";
                    bloodline = "Paternal";
                    break;
                case "Uncle - Maternal":
                    relationship = "Uncle";
                    bloodline = "Maternal";
                    break;
                case "Uncle - Paternal":
                    relationship = "Uncle";
                    bloodline = "Paternal";
                    break;

            }

            if (relationship.Length > 0)
            {
                string new_rel_type;

                List<Person> retval = new List<Person>();

                RelationshipEnum re = Relationship.Parse(relationship);
                GenderEnum ge = Relationship.getGenderFromRelationshipType(re);
                if (Relationship.isOffspring(re))
                {
                    Person newSpouse = null;
                    foreach (Person q in proband.FHx)
                    {
                        if (q.relationshipOther == "Spouse of Self")
                        {
                            newSpouse = q;
                            break;
                        }
                    }
                    if (newSpouse == null)
                    {
                        newSpouse = proband.FHx.CreateSpouse(proband);

                        HraModelChangedEventArgs args = new HraModelChangedEventArgs(null);
                        args.updatedMembers.Add(newSpouse.GetMemberByName("relativeID")); // Edit And save
                        args.updatedMembers.Add(newSpouse.GetMemberByName("relationship"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("relationshipOther"));
                        //args.updatedMembers.Add(newSpouse.GetMemberByName("bloodline"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("motherID"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("fatherID"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("gender"));
                        //args.updatedMembers.Add(newSpouse.GetMemberByName("vitalStatus"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("twinID"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("x_position"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("y_position"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("x_norm"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("y_norm"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("pedigreeGroup"));
                        args.updatedMembers.Add(newSpouse.GetMemberByName("consanguineousSpouseID"));
                        newSpouse.BackgroundPersistWork(args);

                       // newSpouse.BackgroundPersistWork();
                        //this.AddToList(newSpouse, new HraModelChangedEventArgs(null));
                    }

                    for (int i = 0; i < count; i++)
                    {
                        proband.FHx.BackgroundListLoad();

                        int nextID = proband.FHx.GetNewRelativeID();
                        Person newRel = new Person(proband.FHx);
                        newRel.HraState = RiskApps3.Model.HraObject.States.Ready;
                        newRel.relativeID = nextID;
                        newRel.motherID = 0;
                        newRel.fatherID = 0;

                        newRel.owningFHx = proband.FHx;
                        newRel.vitalStatus = "Alive";
                        newRel.gender = Gender.toString(ge);
                        newRel.relationship = relationship;
                        newRel.bloodline = bloodline;

                        if (proband.gender == "Female")
                        {
                            newRel.motherID = proband.relativeID;
                            newRel.fatherID = newSpouse.relativeID;
                        }
                        else
                        {
                            newRel.motherID = newSpouse.relativeID;
                            newRel.fatherID = proband.relativeID;
                        }

                        HraModelChangedEventArgs args = new HraModelChangedEventArgs(null);
                        args.updatedMembers.Add(newRel.GetMemberByName("relativeID")); // Edit And save
                        args.updatedMembers.Add(newRel.GetMemberByName("relationship"));
                        args.updatedMembers.Add(newRel.GetMemberByName("bloodline"));
                        args.updatedMembers.Add(newRel.GetMemberByName("motherID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("fatherID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("gender"));
                        args.updatedMembers.Add(newRel.GetMemberByName("vitalStatus"));
                        args.updatedMembers.Add(newRel.GetMemberByName("twinID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("x_position"));
                        args.updatedMembers.Add(newRel.GetMemberByName("y_position"));
                        args.updatedMembers.Add(newRel.GetMemberByName("x_norm"));
                        args.updatedMembers.Add(newRel.GetMemberByName("y_norm"));
                        args.updatedMembers.Add(newRel.GetMemberByName("pedigreeGroup"));
                        args.updatedMembers.Add(newRel.GetMemberByName("consanguineousSpouseID"));
                        newRel.BackgroundPersistWork(args);
                        //this.AddToList(newRel, new HraModelChangedEventArgs(null));
                        retval.Add(newRel);
                    }
                    //AddChild(proband, false, count, ge);
                    //List<Person> newFolks = AddChild(proband, false, count, ge);
                    //foreach (Person np in newFolks)
                    //{
                    //    retval.Add(np);
                    //    //np.SignalModelChanged(new HraModelChangedEventArgs(null));
                    //}
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        int nextID = proband.FHx.GetNewRelativeID();
                        Person newRel = new Person(proband.FHx);
                        newRel.HraState = RiskApps3.Model.HraObject.States.Ready;
                        newRel.relativeID = nextID;
                        newRel.motherID = 0;
                        newRel.fatherID = 0;

                        newRel.owningFHx = proband.FHx;
                        newRel.vitalStatus = "Alive";
                        newRel.gender = Gender.toString(ge);
                        newRel.relationship = relationship;
                        newRel.bloodline = bloodline;
                        proband.FHx.SetIDsFromRelationship(ref newRel);

                        HraModelChangedEventArgs args = new HraModelChangedEventArgs(null);
                        args.updatedMembers.Add(newRel.GetMemberByName("relativeID")); // Edit And save
                        args.updatedMembers.Add(newRel.GetMemberByName("relationship"));
                        args.updatedMembers.Add(newRel.GetMemberByName("bloodline"));
                        args.updatedMembers.Add(newRel.GetMemberByName("motherID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("fatherID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("gender"));
                        args.updatedMembers.Add(newRel.GetMemberByName("vitalStatus"));
                        args.updatedMembers.Add(newRel.GetMemberByName("twinID"));
                        args.updatedMembers.Add(newRel.GetMemberByName("x_position"));
                        args.updatedMembers.Add(newRel.GetMemberByName("y_position"));
                        args.updatedMembers.Add(newRel.GetMemberByName("x_norm"));
                        args.updatedMembers.Add(newRel.GetMemberByName("y_norm"));
                        args.updatedMembers.Add(newRel.GetMemberByName("pedigreeGroup"));
                        args.updatedMembers.Add(newRel.GetMemberByName("consanguineousSpouseID"));
                        newRel.BackgroundPersistWork(args);

                        /*
                        proband.FHx.AddToList(newRel, new HraModelChangedEventArgs(null));
                         */
                        retval.Add(newRel);
                    }
                }

            }
        }
Exemple #3
0
 /**************************************************************************************************/
 // This way of creating a person is used to create relatives in the family history
 public Person(FamilyHistory fhx)
 {
     owningFHx = fhx;
     Nationality = new NationalityList(this);
     Ethnicity = new EthnicBackground(this);
     PMH = new PastMedicalHistory(this);
     RP = new RiskProfile(this);
 }
Exemple #4
0
        public List<ViewModels.FamilyHistoryRelative> GetFamilyHistoryRelative(string unitnum, int apptid)
        {
            string assignedBy = "";

            if (SessionManager.Instance.ActiveUser != null)
            {
                if (string.IsNullOrEmpty(SessionManager.Instance.ActiveUser.ToString()) == false)
                {
                    assignedBy = SessionManager.Instance.ActiveUser.ToString();

                }
            }
            string _userlogin = SessionManager.Instance.ActiveUser.userLogin;
            SessionManager.Instance.SetActivePatient(unitnum, apptid);
            SessionManager.Instance.GetActivePatient().BackgroundLoadWork();
            RiskApps3.Model.PatientRecord.Patient proband = SessionManager.Instance.GetActivePatient();

            RiskApps3.Model.PatientRecord.PastMedicalHistory pmh = new RiskApps3.Model.PatientRecord.PastMedicalHistory(proband);
            RiskApps3.Model.PatientRecord.FHx.FamilyHistory FHX = new RiskApps3.Model.PatientRecord.FHx.FamilyHistory(proband)  ;

            proband.FHx.BackgroundListLoad();

            /*
            RiskApps3.Model.PatientRecord.Person relative1 = new RiskApps3.Model.PatientRecord.Person(proband.FHx);
            relative1.BackgroundLoadWork();
             */

            //RiskApps3.Model.PatientRecord.FHx.FamilyHistory proband = SessionManager.Instance.GetActivePatient().FHx;

            List<ViewModels.FamilyHistoryRelative> lst = new List<VM.FamilyHistoryRelative>();

            //foreach (Person p in proband.FHx.Relatives)
            //foreach (Person p in FHX.Relatives)
            foreach (Person p in proband.FHx.Relatives)
            {

                ViewModels.FamilyHistoryRelative obj = new ViewModels.FamilyHistoryRelative();

                //Person relative = p;
                relative = p;

                obj.Relationship = "";

               // pmh = relative.PMH;

                if (string.IsNullOrEmpty(relative.bloodline) || relative.relationship.ToLower() == "mother" || relative.relationship.ToLower() == "father")
                {
                    if (relative.relationship.ToLower() != "other")
                        obj.Relationship = relative.relationship;
                }
                else
                {
                    if (relative.bloodline.ToLower() != "unknown" && relative.bloodline.ToLower() != "both")
                        obj.Relationship = relative.bloodline + " " + relative.relationship;
                    else
                        obj.Relationship = relative.relationship;
                }

                if (obj.Relationship.Length == 0)
                {
                    if (!string.IsNullOrEmpty(relative.relationshipOther))
                    {
                        obj.Relationship = relative.relationshipOther;
                    }
                }

                obj.RelativeAge = relative.age;

                obj.VitalStatus = relative.vitalStatus;

                obj.RelativeId = relative.relativeID;
                relative.PMH.BackgroundLoadWork();
                pmh = relative.PMH;

                obj.DeleteFlag = SetDeleteButtonFlag(relative);

                for (int i = 0; i < pmh.Observations.Count; i++)
                {
                    ClincalObservation co = (ClincalObservation)pmh.Observations[i];
                    switch (i)
                    {
                        case 0:

                            obj.FirstDx = co.disease;
                            obj.FirstAgeOnset= co.ageDiagnosis;

                            break;
                        case 1:
                           obj.SecondDx = co.disease;
                            obj.SecondAgeOnset= co.ageDiagnosis;
                            break;
                        case 2:
                           obj.ThirdDx = co.disease;
                            obj.ThirdAgeOnset= co.ageDiagnosis;
                            break;
                        default:
                            break;
                    }
                }

                /**/
                lst.Add(obj);

            }

            return lst;
        }

        public List<VM.Tasks> GetTasks(int InstitutionId, string unitnum)
        {
            if (InstitutionId != null)
            {
                _institutionId = InstitutionId;
                //SetUserSession();
                Patient p = new Patient();
                p.unitnum = unitnum;
                var list = new TaskList(p);
                list.BackgroundListLoad();
                return list.FromRATaskList();
            }

            return new List<VM.Tasks>();
        }

        /// <summary>
        /// for loading Test patient page
        /// </summary>
        /// <returns></returns>
        public VM.TestPatient LoadCreateTestPatients()
        {
            VM.TestPatient tp = new VM.TestPatient();
            TestPatientManager Tpm = new TestPatientManager();
            tp.Surveys = Tpm.GetSurveys();
            tp.Clinics = GetClinicList();
            tp.InitateTestPatients = Tpm.InitiateTestPatients();

            return tp;
        }

        /// <summary>
        /// To Show Risk Score on Click of Run Risk Models Button. It calculates Risk Score
        /// </summary>
        /// <param name="apptid">Appointment Id</param>
        /// <param name="MRN">MRN Number</param>
        /// <returns></returns>
        public VM.RiskScore RiskCalculateAndRunAutomation(int apptid, string MRN)
        {
            Patient proband = CalculateRiskAndRunAutomation(apptid, MRN);
            proband.RP.LoadFullObject();
            VM.RiskScore RS = RiskScoreMapper.ToRiskScore(proband.RP);
            RS.ApptId = apptid;
            RS.MRN = MRN;
            return RS;
        }

        /// <summary>
        ///To show Risk Score on Click of Risk Calculation  
        /// </summary>
        /// <param name="apptid">Appointment Id</param>
        /// <param name="MRN">MRN Number</param>
        /// <returns>Risk Score Model</returns>
        public VM.RiskScore RiskScore(int apptid, string MRN)
        {
            SessionManager.Instance.SetActivePatient(MRN, apptid);
            Patient proband = SessionManager.Instance.GetActivePatient();
            proband.RP.LoadFullObject();
            VM.RiskScore RS = RiskScoreMapper.ToRiskScore(proband.RP);
            RS.ApptId = apptid;
            RS.MRN = MRN;
            return RS;
        }

        /// <summary>
        /// To do process of Run Automation Documents
        /// </summary>
        /// <param name="InstitutionId">Institution Id</param>
        /// <param name="apptid">Appointment Id</param>
        /// <param name="MRN">MRN Number</param>
        /// <returns></returns>
        public FileInfo RunAutomationDocuments(int InstitutionId, int apptid, string MRN)
        {
            Patient proband = CalculateRiskAndRunAutomation(apptid, MRN);
            return proband.file;
        }

        /// <summary>
        /// To Save Appointments
        /// </summary>
        /// <param name="Appt">Appointment Object to Save</param>
        /// <param name="InstitutionId">Institution Id</param>
        public void SaveAppointments(VM.Appointment Appt, int InstitutionId)
        {
            SaveAppointments(Appt);
            UpdateMarkAsComplete(Appt, InstitutionId);
        }

        public string SaveImage(string base64, int _institutionId, string _userlogin, int apptid, string PedigreeImageSavePath)
        {
            string _ImagePath = string.Empty;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Convert.FromBase64String(base64)))
            {
                using (Bitmap bm2 = new Bitmap(ms))
                {

                    //  PedigreeImagePath = System.Web.Serv
                    string _ImageName = _institutionId.ToString() + "_" + _userlogin + "_" + apptid.ToString() + ".png";

                    bm2.Save(PedigreeImageSavePath + _ImageName);
                    _ImagePath = _ImageName;
                }
            }

            return _ImagePath;
        }

        public void SaveSurvey(string unitnum, int apptid, ViewModels.FamilyHistoryRelative obj , int type )
        {
            SessionManager.Instance.SetActivePatient(unitnum, apptid);
            SessionManager.Instance.GetActivePatient().BackgroundLoadWork();
            RiskApps3.Model.PatientRecord.Patient proband = SessionManager.Instance.GetActivePatient();
            proband.FHx.BackgroundListLoad();

            if (type == 0)
            {

                AddRelative(proband, obj);
            }
            else if (type == 1)
            {
                EditSurvey(proband, obj);

            }
            else
            {
                DeleteSurvey(proband, obj);
            }
        }

        public bool SetDeleteButtonFlag(Person relative)
        {
            bool retval = true;

            if (relative == null)
                return false ;

            if (relative.relativeID < 8)
            {
                retval = false;
            }
            else
            {
                foreach (Person p in relative.owningFHx)
                {
                    if (p.motherID == relative.relativeID || p.fatherID == relative.relativeID)
                    {
                        retval = false;
                        break;
                    }
                }
            }

            return retval;
        }

        public string ShowPedigreeImage(int _institutionId, string unitnum, int apptid, string PedigreeImageSavePath)
        {
            int Width = 625;
            int Height = 625;
            string _ImagePath = string.Empty;
            string assignedBy = "";

            if (SessionManager.Instance.ActiveUser != null)
            {
                if (string.IsNullOrEmpty(SessionManager.Instance.ActiveUser.ToString()) == false)
                {
                    assignedBy = SessionManager.Instance.ActiveUser.ToString();

                }
            }
            string _userlogin = SessionManager.Instance.ActiveUser.userLogin;
            SessionManager.Instance.SetActivePatient(unitnum, apptid);

            RiskApps3.Model.PatientRecord.Patient proband = SessionManager.Instance.GetActivePatient();    // TODO:  Check this!!

            PedigreeGenerator pg = new PedigreeGenerator(Width, Height, proband);
            Bitmap bmp;
            if (proband != null)
            {
                bmp = pg.GeneratePedigreeImage(proband);
            }
            else
            {
                bmp = pg.GeneratePedigreeImage();
            }
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            var base64Data = Convert.ToBase64String(stream.ToArray());
            /*
            _ImagePath = SaveImage(base64Data, _institutionId, _userlogin, apptid, PedigreeImageSavePath);
               return _ImagePath;
            */
            return base64Data;
        }
Exemple #5
0
        public PedigreeModel(FamilyHistory p_familyHistory)
        {
            familyHistory = p_familyHistory;

            //Store the individuals as PedigreeIndividuals
            lock (familyHistory.Relatives)
            {
                foreach (Person Person in familyHistory.Relatives)
                {
                    PedigreeIndividual pedigreeIndividual = new PedigreeIndividual(Person);
                    individuals.Add(pedigreeIndividual);
                    individualsDictionary[Person.relativeID] = pedigreeIndividual;
                    points.Add(pedigreeIndividual.point);
                }
            }
            //here keys are the couple ids, values are the couples to which they map
            couplesDictionary = new Dictionary<CoupleID, PedigreeCouple>();

            //Link PedigreeIndividuals with their parents in the object model, derive couples
            foreach (PedigreeIndividual child in individuals)
            {
                //determine whether or not each parent exists in the data
                bool hasMother = individualsDictionary.ContainsKey(child.HraPerson.motherID);
                bool hasFather = individualsDictionary.ContainsKey(child.HraPerson.fatherID);
                CoupleID coupleId = new CoupleID(child.HraPerson.fatherID, child.HraPerson.motherID);
                if (hasMother || hasFather)
                {
                    //link individuals with their parents in the object model, forming a pointer graph
                    if (hasMother)
                        child.Mother = individualsDictionary[child.HraPerson.motherID];
                    if (hasFather)
                        child.Father = individualsDictionary[child.HraPerson.fatherID];

                    //derive couples and store them
                    {
                        //if this individual has parents, set it's "parents" pointer to the
                        //couple representing it's parents (deriving couples from the data as needed).

                        //get the parents couple
                        PedigreeCouple parents = null;
                        {
                            //check if the parents have already been stored as a couple

                            if (couplesDictionary.ContainsKey(coupleId))
                                //if so, then use the previously stored couple.
                                parents = couplesDictionary[coupleId];
                            else
                            {
                                //if not store parents as a couple if they haven't been already
                                parents = new PedigreeCouple(child.Mother, child.Father);
                                couplesDictionary[coupleId] = parents;
                                couples.Add(parents);
                                points.Add(parents.point);

                                //link participating individuals with the new couple
                                if (child.Mother != null)
                                    if (child.Mother.spouseCouples != null)
                                        child.Mother.spouseCouples.Add(parents);

                                if (child.Father != null)
                                    if (child.Father.spouseCouples != null)
                                        child.Father.spouseCouples.Add(parents);
                            }
                        }
                        //set this individual's "parents" pointer to the parents couple
                        child.Parents = parents;

                        //add the child to the children of the parents couple
                        parents.children.Add(child);
                    }
                }
            }

            // derive the intergenerational edges of the couples graph
            foreach (PedigreeIndividual parent in individuals)
            {
                bool parentHasGrandparents = parent.Parents != null;
                bool parentIsPartOfACouple = parent.spouseCouples.Count != 0;

                if (parentHasGrandparents && parentIsPartOfACouple)
                {
                    foreach (PedigreeCouple parents in parent.spouseCouples)
                    {
                        PedigreeCouple grandparents = parent.Parents;
                        bool intergenerational = true;
                        coupleEdges.Add(new PedigreeCoupleEdge(grandparents, parents, intergenerational));
                    }
                }
            }

            // derive the intragenerational edges of the couples graph
            // (from half sibling relationships)
            foreach (PedigreeIndividual parent in individuals)
            {
                if (parent.spouseCouples.Count == 2)
                {
                    PedigreeCouple u = parent.spouseCouples[0];
                    PedigreeCouple v = parent.spouseCouples[1];
                    bool intergenerational = false;
                    coupleEdges.Add(new PedigreeCoupleEdge(u, v, intergenerational));
                }
                //else if (parent.spouseCouples.Count > 2)
                //    throw new Exception("Pedigree not drawable: individual " + parent.relativeID + " has more than two spouses");
            }

            //derive generational levels
            bool undefinedLevelsRemain = true;
            int minGenerationalLevel = 0;
            int maxGenerationalLevel = 0;
            if (couples.Count > 0)
            {
                //assign the seed level
                couples[0].GenerationalLevel = 0;

                //propagate the seed level through the graph
                int NULL = PedigreeCouple.UNDEFINED_GENERATION;
                while (undefinedLevelsRemain)
                {
                    undefinedLevelsRemain = false;
                    foreach (PedigreeCoupleEdge e in coupleEdges)
                    {
                        if (e.intergenerational)
                        {
                            PedigreeCouple grandparents = e.u;
                            PedigreeCouple parents = e.v;

                            bool parentsHaveLevel = parents.GenerationalLevel != NULL;
                            bool grandparentsHaveLevel = grandparents.GenerationalLevel != NULL;

                            if (!parentsHaveLevel || !grandparentsHaveLevel)
                                undefinedLevelsRemain = true;

                            if (!parentsHaveLevel && !grandparentsHaveLevel)
                            {
                                undefinedLevelsRemain = false;
                            }

                            if (parentsHaveLevel && !grandparentsHaveLevel)
                            {
                                grandparents.GenerationalLevel = parents.GenerationalLevel - 1;
                                if (grandparents.GenerationalLevel < minGenerationalLevel)
                                    minGenerationalLevel = grandparents.GenerationalLevel;
                            }
                            else if (!parentsHaveLevel && grandparentsHaveLevel)
                            {
                                parents.GenerationalLevel = grandparents.GenerationalLevel + 1;
                                if (parents.GenerationalLevel > maxGenerationalLevel)
                                    maxGenerationalLevel = parents.GenerationalLevel;
                            }

                        }
                        else
                        {
                            //propagate levels through intragenerational edges (half siblings)
                            if (e.u.GenerationalLevel == NULL)
                                e.u.GenerationalLevel = e.v.GenerationalLevel;
                            else if (e.v.GenerationalLevel == NULL)
                                e.v.GenerationalLevel = e.u.GenerationalLevel;
                        }
                    }
                }
            }

            //normalize the levels
            foreach (PedigreeCouple couple in couples)
                couple.GenerationalLevel -= minGenerationalLevel;

            //store the (normalized) max level in the model
            this.maxGenerationalLevel = maxGenerationalLevel - minGenerationalLevel;

            //when a parent set of half siblings (father, mother, father)
            //is detedted, the mother id is added to this list. If a
            //couple involving this mother is detected later, this
            //list is checked to see if she has already been counted.
            List<int> halfSiblingParentsMotherIds = new List<int>();

            //derive individual sets
            foreach (PedigreeCouple couple in couples)
            {
                //add the [mother,father] individual sets
                if (couple.mother != null && couple.father != null)
                {
                    if (couple.mother.Parents == null && couple.father.Parents == null)
                    {
                        //if the mother has a single spouse
                        if (couple.mother.spouseCouples.Count == 1)
                        {
                            PedigreeIndividualSet parentsIndividualSet = new PedigreeIndividualSet(couple);
                            parentsIndividualSet.Add(couple.mother);
                            parentsIndividualSet.Add(couple.father);
                            AddIndividualSet(couple.GenerationalLevel, parentsIndividualSet);
                        }
                        //if the mother has a two spouses
                        else if (couple.mother.spouseCouples.Count == 2)
                        {
                            //collapse parents of half siblings into a single individual set
                            if (!halfSiblingParentsMotherIds.Contains(couple.mother.HraPerson.relativeID))
                            {
                                halfSiblingParentsMotherIds.Add(couple.mother.HraPerson.relativeID);
                                PedigreeIndividualSet parentsIndividualSet = new PedigreeIndividualSet(couple);
                                parentsIndividualSet.Add(couple.mother);
                                parentsIndividualSet.Add(couple.mother.spouseCouples[0].father);
                                parentsIndividualSet.Add(couple.mother.spouseCouples[1].father);
                                AddIndividualSet(couple.GenerationalLevel, parentsIndividualSet);
                            }
                        }
                    }

                    try
                    {

                        //add the children individual sets
                        PedigreeIndividualSet childrenIndividualSet = new PedigreeIndividualSet(couple);
                        foreach (PedigreeIndividual child in couple.children)
                        {
                            childrenIndividualSet.Add(child);
                            foreach (PedigreeCouple pc in child.spouseCouples)
                            {
                                if (pc.mother.HraPerson.relativeID == child.HraPerson.relativeID)
                                {
                                    childrenIndividualSet.Add(pc.father);
                                }
                                else
                                {
                                    childrenIndividualSet.Add(pc.mother);
                                }
                            }
                        }
                        AddIndividualSet(couple.GenerationalLevel + 1, childrenIndividualSet);
                    }
                    catch (Exception e)
                    {
                        Logger.Instance.WriteToLog(e.ToString());
                    }
                }
            }

            if (individualsDictionary.ContainsKey(1))
                SetBloodRelatives(individualsDictionary[1]);

            foreach(PedigreeIndividual pi in individuals)
            {
                if (pi.bloodRelative == false)
                {
                    if (pi.spouseCouples.Count == 0)
                    {
                        pi.bloodRelative = true;
                    }
                    else
                    {
                        bool bloodFound = false;
                        foreach (PedigreeCouple pc in pi.spouseCouples)
                        {
                            if ((pc.mother != null) && (pc.father != null))
                            {
                                if (pc.mother.bloodRelative == true || pc.father.bloodRelative == true)
                                    bloodFound = true;
                            }
                        }
                        if (bloodFound == false)
                        {
                            foreach (PedigreeCouple pc in pi.spouseCouples)
                            {
                                if (pc.mother != null) pc.mother.bloodRelative = true;
                                if (pc.father != null) pc.father.bloodRelative = true;
                            }
                        }
                    }
                }
            }
            this.FamilialVariants = p_familyHistory.ReloadFamilialVariants();
        }