/// <summary>
        /// Converts the JSON property data to a <see cref="PersonName"/>, or <c>null</c> if empty.
        /// </summary>
        /// <param name="propertyType">Type of the property.</param>
        /// <param name="source">The source.</param>
        /// <param name="preview">if set to <c>true</c> [preview].</param>
        /// <returns></returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (source == null)
            {
                return(null);
            }

            using (var stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(source.ToString())))
            {
                var js    = new DataContractJsonSerializer(typeof(PersonNameValue));
                var value = (PersonNameValue)js.ReadObject(stream);

                var data = new PersonName();
                if (!String.IsNullOrEmpty(value.Titles))
                {
                    data.Titles.AddRange(value.Titles.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (!String.IsNullOrEmpty(value.GivenNames))
                {
                    data.GivenNames.AddRange(value.GivenNames.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                }
                data.FamilyName = value.FamilyName;
                if (!String.IsNullOrEmpty(value.Suffixes))
                {
                    data.Suffixes.AddRange(value.Suffixes.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                }

                return(data.ToString().Length > 0 ? data : null);
            }
        }
Ejemplo n.º 2
0
        public void Test_PersonName()
        {
            var name  = new PersonName("Pablo");
            var name2 = new PersonName("Pablo");

            Assert.AreEqual(name, name2);


            Assert.AreEqual("Pablo", name.ToString());
        }
Ejemplo n.º 3
0
        public void CreateName()
        {
            string firstName = "Jimmy";
            string lastName  = "John";

            PersonName name = new PersonName(firstName, lastName);

            Assert.AreEqual(firstName, name.FirstName);
            Assert.AreEqual(lastName, name.LastName);
            Assert.AreEqual(firstName + " " + lastName, name.ToString());
        }
Ejemplo n.º 4
0
        private string GetPatientName()
        {
            PersonName p = new PersonName();

            p.Family = textBoxLast.Text;
            p.Given  = textBoxFirst.Text;
            p.Middle = textBoxMiddle.Text;
            p.Prefix = textBoxPrefix.Text;
            p.Suffix = textBoxSuffix.Text;
            return(p.ToString());
        }
        public void AlphabeticalPersonNameFormatter_WithNoKnownAs_ReturnsExpectedString()
        {
            const string expectedResult = "Houston, Philip";

            var name = new PersonName("Philip", "Houston", "Andrew")
            {
                NameFormatter = new AlphabeticalPersonNameFormatter()
            };

            var actualResult = name.ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void DefaultPersonNameFormatter_WithKnownAs_ReturnsExpectedString()
        {
            const string expectedResult = "Phil Houston";

            var name = new PersonName("Philip", "Houston", "Andrew","Phil")
            {
                NameFormatter = new DefaultPersonNameFormatter()
            };

            var actualResult = name.ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void AlphabeticalPersonNameFormatter_WithKnownAs_ReturnsExpectedString()
        {
            const string expectedResult = "Houston, Phil";

            var name = new PersonName("Philip", "Houston", "Andrew", "Phil")
            {
                NameFormatter = new AlphabeticalPersonNameFormatter()
            };

            var actualResult = name.ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void DefaultPersonNameFormatter_WithNoKnownAs_ReturnsExpectedString()
        {
            const string expectedResult = "Philip Houston";

            var name = new PersonName("Philip", "Houston", "Andrew")
            {
                NameFormatter = new DefaultPersonNameFormatter()
            };

            var actualResult = name.ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }
Ejemplo n.º 9
0
        public void ConstructorTest()
        {
            PersonName name;

            name = new PersonName("Sven Erik Matzen");
            Assert.IsTrue(string.IsNullOrEmpty(name.AcademicTitle));
            Assert.AreEqual("Sven", name.FirstName);
            Assert.AreEqual("Erik", name.MiddleName);
            Assert.AreEqual("Matzen", name.LastName);
            Assert.IsTrue(string.IsNullOrEmpty(name.Suffix));
            Assert.IsTrue(string.IsNullOrEmpty(name.FormerName));
            Assert.AreEqual("Matzen, Sven Erik", name.ToString());

            name = new PersonName("Sven Matzen");
            Assert.IsTrue(string.IsNullOrEmpty(name.AcademicTitle));
            Assert.AreEqual("Sven", name.FirstName);
            Assert.IsTrue(string.IsNullOrEmpty(name.MiddleName));
            Assert.AreEqual("Matzen", name.LastName);
            Assert.IsTrue(string.IsNullOrEmpty(name.Suffix));
            Assert.IsTrue(string.IsNullOrEmpty(name.FormerName));
            Assert.AreEqual("Matzen, Sven", name.ToString());

            name = new PersonName("Matzen, Sven Erik");
            Assert.IsTrue(string.IsNullOrEmpty(name.AcademicTitle));
            Assert.AreEqual("Sven", name.FirstName);
            Assert.AreEqual("Erik", name.MiddleName);
            Assert.AreEqual("Matzen", name.LastName);
            Assert.IsTrue(string.IsNullOrEmpty(name.Suffix));
            Assert.IsTrue(string.IsNullOrEmpty(name.FormerName));
            Assert.AreEqual("Matzen, Sven Erik", name.ToString());

            name = new PersonName("Matzen, Sven");
            Assert.IsTrue(string.IsNullOrEmpty(name.AcademicTitle));
            Assert.AreEqual("Sven", name.FirstName);
            Assert.IsTrue(string.IsNullOrEmpty(name.MiddleName));
            Assert.AreEqual("Matzen", name.LastName);
            Assert.IsTrue(string.IsNullOrEmpty(name.Suffix));
            Assert.IsTrue(string.IsNullOrEmpty(name.FormerName));
            Assert.AreEqual("Matzen, Sven", name.ToString());

            name = new PersonName("Matzen (Dr.), Sven Erik");
            Assert.AreEqual("Dr.", name.AcademicTitle);
            Assert.AreEqual("Sven", name.FirstName);
            Assert.AreEqual("Erik", name.MiddleName);
            Assert.AreEqual("Matzen", name.LastName);
            Assert.IsTrue(string.IsNullOrEmpty(name.Suffix));
            Assert.IsTrue(string.IsNullOrEmpty(name.FormerName));
            Assert.AreEqual("Matzen (Dr.), Sven Erik", name.ToString());
        }
Ejemplo n.º 10
0
        public void ToStringTest()
        {
            PersonName name;

            name = new PersonName("Sven Erik Matzen");
            Assert.AreEqual("Matzen, Sven Erik", name.ToString());

            name = new PersonName("Sven Matzen");
            Assert.AreEqual("Matzen, Sven", name.ToString());

            name = new PersonName("Matzen, Sven Erik");
            Assert.AreEqual("Matzen, Sven Erik", name.ToString());

            name = new PersonName("Matzen, Sven");
            Assert.AreEqual("Matzen, Sven", name.ToString());

            name = new PersonName("Matzen (Dr.), Sven Erik");
            Assert.AreEqual("Matzen (Dr.), Sven Erik", name.ToString());
        }
Ejemplo n.º 11
0
        internal static AuditedInstances GetAuditedInstances(IEnumerable <ISelectPresentationsInformation> collection)
        {
            AuditedInstances instances = new AuditedInstances();
            IEnumerator <ISelectPresentationsInformation> enumerator1 = collection.GetEnumerator();

            using (IEnumerator <ISelectPresentationsInformation> enumerator = enumerator1)
            {
                while (enumerator.MoveNext())
                {
                    ISelectPresentationsInformation selectitem = enumerator.Current;
                    IPresentationImage image    = selectitem.Image;
                    IImageSopProvider  provider = image as IImageSopProvider;
                    if (provider != null)
                    {
                        ImageSop   imageSop         = provider.ImageSop;
                        PersonName patientsName     = imageSop.PatientsName;
                        string     studyInstanceUid = imageSop.StudyInstanceUid;
                        instances.AddInstance(imageSop.PatientId, patientsName.ToString(), studyInstanceUid);
                    }
                }
            }
            return(instances);
        }
Ejemplo n.º 12
0
 public void TestToString()
 {
     var name = new PersonName("John", "Doe");
     Assert.AreEqual("John Doe", name.ToString());
 }
Ejemplo n.º 13
0
 public override string ToString()
 {
     return(_name.ToString());
 }
Ejemplo n.º 14
0
        private void btnSearch_Click(object sender, EventArgs e)
        {       //Code for the Search button.
            try
            {   //Makes it so the name list has to be sorted before any searching.
                if (sort == false)
                {
                    throw new Exception("Please sort the names first.");
                }
                else
                {
                    DateTime timeStart = DateTime.Now;

                    //All of the different variables that may be needed are declared.
                    string            searchTerm = txtNameSearch.Text;
                    int               min        = 0;
                    int               middle;
                    int               max      = splitNames.Length - 1;
                    bool              match    = false;
                    int               location = -1;
                    List <PersonName> matches  = new List <PersonName> {
                    };

                    //Gets rid of any extraneous spaces or commas at the end of any names.
                    if (searchTerm.EndsWith(" "))
                    {
                        searchTerm.TrimEnd(' ');
                    }

                    if (searchTerm.EndsWith(","))
                    {
                        searchTerm.TrimEnd(',');
                    }

                    //If any names are highlighted from being searched before, they are un-highlighted.
                    lbNameList.SelectedIndices.Clear();

                    //If the name is set up so it'd (assumedly) be in the format "FirstName LastName", this code executes.
                    if (searchTerm.Length > 1 && searchTerm.Contains(" ") && !searchTerm.Contains(","))
                    {
                        //User input is turned into a PersonName object.
                        string[]   nameSplit = searchTerm.Split(' ');
                        PersonName search    = new PersonName(nameSplit[1], nameSplit[0]);

                        //Binary search to find if the name matches any names.
                        while (min <= max && !match)
                        {
                            middle = (min + max) / 2;

                            if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) == 0)
                            {
                                //If there's a match, while loop is broken (with match), program knows that it found a match (with location), the
                                //matching name is highlighted, the results are added to the Search Matches list box, and it's put into a list called
                                //matches, to be highlighted at the end.
                                match    = true;
                                location = middle;
                                matches.Add(splitNames[middle]);
                                lbSearchMatches.Items.Add("The name " + splitNames[location].ToString(2) + " was found on line " + (location + 1) + ".");
                            }
                            else if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) > 0)
                            {
                                max = middle - 1;
                            }
                            else if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) < 0)
                            {
                                min = middle + 1;
                            }
                        }
                    }
                    //If the name is set up so it'd (assumedly) be in the format "Lastname, FirstName", this code executes.
                    else if (searchTerm.Length > 1 && searchTerm.Contains(" ") && searchTerm.Contains(","))
                    {
                        //More or less the same as the above method.
                        string[]   nameSplit = searchTerm.Split(',');
                        PersonName search    = new PersonName(nameSplit[0], nameSplit[1].TrimStart(' '));

                        while (min <= max && !match)
                        {
                            middle = (min + max) / 2;

                            if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) == 0)
                            {
                                match    = true;
                                location = middle;
                                matches.Add(splitNames[middle]);
                                lbSearchMatches.Items.Add("The name " + splitNames[location].ToString(2) + " was found on line " + (location + 1) + ".");
                                lbNameList.SetSelected(middle, true);
                            }

                            else if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) > 0)
                            {
                                max = middle - 1;
                            }
                            else if (string.Compare(splitNames[middle].ToString(), search.ToString(), true) < 0)
                            {
                                min = middle + 1;
                            }
                        }
                    }

                    //If the name is set up so it'd (assumedly) be in the format "Firstname" or the format "Lastname", this code executes.
                    else if (searchTerm.Length > 1 && !searchTerm.Contains(" ") && !searchTerm.Contains(","))
                    {
                        //A sequential search is used, going through all of the names and seeing if any of them match.
                        for (int start = 0; start < splitNames.Length; start++)
                        {
                            //This is if the last name matches.
                            if (String.Compare(splitNames[start].ToString(0), searchTerm, true) == 0)
                            {
                                match    = true;
                                location = start;
                                matches.Add(splitNames[start]);
                                lbSearchMatches.Items.Add("The name " + splitNames[start].ToString(2) + " was found on line " + (start + 1) + ".");
                            }
                            //This is if the first name matches.
                            else if (String.Compare(searchTerm, splitNames[start].ToString(1), true) == 0)
                            {
                                match    = true;
                                location = start;
                                matches.Add(splitNames[start]);
                                lbSearchMatches.Items.Add("The name " + splitNames[start].ToString(2) + " was found on line " + (start + 1) + ".");
                            }
                        }


                        //This option has the ability to display multiple results, due to using the sequential search method, which is nice.
                    }
                    //If the "name" is set up so it'd (assumedly) be in the format "F" or "L" (first letter of either name),
                    //this code executes.
                    else if (searchTerm.Length == 1)
                    {
                        //The binary search method is used for this.
                        while (min <= max && !match)
                        {
                            middle = (min + max) / 2;

                            //Checks if either the first or last name starts with the letter that was put in.
                            if (splitNames[middle].ToString(0).StartsWith(searchTerm) || splitNames[middle].ToString(1).StartsWith(searchTerm))
                            {
                                location = middle;
                                lbNameList.SetSelected(middle, true);
                                matches.Add(splitNames[middle]);
                                lbSearchMatches.Items.Add("The name " + splitNames[location].ToString(2) + " was found on line " + (location + 1) + ".");
                                match = true;
                            }
                            //If it doesn't, it'll search at first based on how the search relates to the last name...
                            else if (string.Compare(splitNames[middle].ToString(0).Substring(0, 1), searchTerm.ToString(), true) > 0)
                            {
                                max = middle - 1;
                            }
                            else if (string.Compare(splitNames[middle].ToString(0).Substring(0, 1), searchTerm.ToString(), true) < 0)
                            {
                                min = middle + 1;
                            }
                            //...and then the first name.
                            else if (string.Compare(splitNames[middle].ToString(1).Substring(0, 1), searchTerm.ToString(), true) > 0)
                            {
                                max = middle - 1;
                            }
                            else if (string.Compare(splitNames[middle].ToString(1).Substring(0, 1), searchTerm.ToString(), true) < 0)
                            {
                                min = middle + 1;
                            }
                        }
                    }


                    //If nothing is found, location should still be -1, so an Exception is thrown.
                    if (location == -1)
                    {
                        throw new Exception("Unable to find the search term in the list of names.");
                    }

                    //This is where the highlighting is done. Going through all of the names for each name in the matches list, so
                    //the index of the match can be found and then the name in that index is highlighted.
                    for (int mIndex = 0; mIndex < matches.Count; mIndex++)
                    {
                        string p = matches[mIndex].ToString();

                        for (int index = 0; index < lbNameList.Items.Count; index++)
                        {
                            if (p == lbNameList.Items[index].ToString())
                            {
                                lbNameList.SetSelected(index, true);
                            }
                        }
                    }

                    DateTime timeEnd   = DateTime.Now;
                    TimeSpan totalTime = timeEnd - timeStart;
                    string   time      = "Searching for this name took " + totalTime.Milliseconds + " milliseconds.";
                    lbTimeRecords.Items.Add(time);

                    //Moves both time records and search matches to bottom.
                    lbSearchMatches.TopIndex = lbSearchMatches.Items.Count - 1;
                    lbTimeRecords.TopIndex   = lbTimeRecords.Items.Count - 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }