Esempio n. 1
0
        /// <summary>
        /// Adds inlines for text that will not break unless necessary.
        /// </summary>
        /// <param name="textBlock">The text block to add the inlines too.</param>
        /// <param name="text">The text to add.</param>
        /// <param name="fontWeight">The desired font weight of the text.</param>
        private static void AddNonBreakingInlines(TextBlock textBlock, string text, FontWeight fontWeight)
        {
            // Split text into parts around a long dash
            // e.g. oral ― modified-release becomes "oral", "modified-release"
            string[] parts = text.Split("―".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (text.StartsWith("― ", StringComparison.CurrentCulture))
            {
                textBlock.Inlines.Add(new Run()
                {
                    Text       = "― ",
                    FontWeight = fontWeight,
                });
            }

            for (int p = 0; p < parts.Length; p++)
            {
                // Split words by space,
                string[] words = parts[p].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < words.Length; i++)
                {
                    CompletedPrescriptionToMedsLineConverter.ReplaceHyphensWithNonBreakingCharacter(textBlock, words[i], fontWeight);
                    if (i != words.Length - 1)
                    {
                        AddCharacterJoin(textBlock);
                    }
                }

                if (p != parts.Length - 1)
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Convert forward function.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <param name="targetType">The target type.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture info.</param>
        /// <returns>The converted value.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            CompletedPrescription prescription = value as CompletedPrescription;

            if (prescription != null)
            {
                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;

                if (!string.IsNullOrEmpty(prescription.Name))
                {
                    string[] ingredients = prescription.Name.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < ingredients.Length; i++)
                    {
                        CompletedPrescriptionToMedsLineConverter.ReplaceHyphensWithNonBreakingCharacter(textBlock, ingredients[i].Trim(), FontWeights.Bold);
                        if (i < ingredients.Length - 1)
                        {
                            CompletedPrescriptionToMedsLineConverter.AddCharacterJoin(textBlock);
                            textBlock.Inlines.Add(new Run()
                            {
                                Text       = "+ ",
                                FontWeight = FontWeights.Bold
                            });
                        }
                    }
                }

                if (!string.IsNullOrEmpty(prescription.BrandName))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    string[] parts = prescription.BrandName.Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < parts.Length; i++)
                    {
                        CompletedPrescriptionToMedsLineConverter.ReplaceHyphensWithNonBreakingCharacter(textBlock, parts[i].Trim(), FontWeights.Normal);
                        if (i < parts.Length - 1)
                        {
                            CompletedPrescriptionToMedsLineConverter.AddCharacterJoin(textBlock);
                            textBlock.Inlines.Add(new Run()
                            {
                                Text = "+ ",
                            });
                        }
                    }
                }

                if (!string.IsNullOrEmpty(prescription.Strength))
                {
                    textBlock.Inlines.Add(new Run()
                    {
                        Text = " "
                    });

                    AddNonBreakingInlines(textBlock, prescription.Strength, FontWeights.Normal);
                }

                if (!string.IsNullOrEmpty(prescription.Form))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    AddNonBreakingInlines(textBlock, prescription.Form, FontWeights.Normal);
                }

                if (!string.IsNullOrEmpty(prescription.Dose))
                {
                    AddCharacterJoin(textBlock);
                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    textBlock.Inlines.Add(new Run()
                    {
                        Text       = "DOSE",
                        FontFamily = new FontFamily("Courier New"),
                        Foreground = SystemParameters.HighContrast ? new SolidColorBrush(Color.FromArgb(0xff, 0x00, 0xff, 0xf0)) : new SolidColorBrush(Color.FromArgb(0xff, 0x50, 0x8d, 0xc2))
                    });

                    AddCharacterJoin(textBlock);

                    AddNonBreakingInlines(textBlock, prescription.Dose, FontWeights.Bold);
                }

                if (!string.IsNullOrEmpty(prescription.Method))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    textBlock.Inlines.Add(new Run()
                    {
                        Text       = "METHOD",
                        FontFamily = new FontFamily("Courier New"),
                        Foreground = SystemParameters.HighContrast ? new SolidColorBrush(Color.FromArgb(0xff, 0x00, 0xff, 0xf0)) : new SolidColorBrush(Color.FromArgb(0xff, 0x50, 0x8d, 0xc2))
                    });

                    AddCharacterJoin(textBlock);

                    AddNonBreakingInlines(textBlock, prescription.Method, FontWeights.Normal);
                }

                if (!string.IsNullOrEmpty(prescription.Site))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    AddNonBreakingInlines(textBlock, prescription.Site, FontWeights.Normal);
                }

                if (!string.IsNullOrEmpty(prescription.Route))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    AddNonBreakingInlines(textBlock, prescription.Route, FontWeights.Normal);
                }

                if (!string.IsNullOrEmpty(prescription.Frequency))
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    AddNonBreakingInlines(textBlock, prescription.Frequency, FontWeights.Normal);
                }

                if (prescription.IsAsRequired)
                {
                    AddCharacterJoin(textBlock);

                    textBlock.Inlines.Add(new Run()
                    {
                        Text = "― "
                    });

                    AddNonBreakingInlines(textBlock, "as required", FontWeights.Normal);
                }

                return(textBlock);
            }

            return(null);
        }