Пример #1
0
        /// <summary>
        ///  A string builder that formats the header column of the csv file separated by column.
        ///  Returns a stringbuilder
        /// </summary>
        public static StringBuilder FormatHeader(string file)
        {
            CsvExportDto  tsqm  = new CsvExportDto();
            StringBuilder str   = new StringBuilder();
            int           count = 0;

            foreach (var prop in tsqm.GetType().GetProperties())
            {
                if (prop.Name == "TsqmAnswers")
                {
                    if (file == "TSQM2")
                    {
                        while (count < 11)
                        {
                            count++;
                            str.AppendFormat($"{"Question" + count};");
                        }
                    }
                    else if (file == "DASS21")
                    {
                        while (count < 21)
                        {
                            count++;
                            str.AppendFormat($"{"Question" + count};");
                        }
                    }
                    else
                    {
                        while (count < 6)
                        {
                            count++;
                            str.AppendFormat($"{"Question" + count};");
                        }
                    }
                }
                else if (prop.Name != "Id")
                {
                    str.AppendFormat($"{prop.Name};");
                }
            }
            str.Remove(str.Length - 1, 1);
            str.Append("\n");
            return(str);
        }
Пример #2
0
        /// <summary>
        ///  A string builder that formats the contents\data into a string separated by semicolon.
        ///  It separates each value in the list by a semicolon and output as a string.
        ///  The stringbuilder buffer where data is to be stored
        ///  The CsvExportDto tsqm is the IENUMERABLE class
        /// </summary>
        public static void FormatTsqm(StringBuilder buffer, CsvExportDto tsqm)
        {
            if (tsqm != null)
            {
                buffer.AppendFormat($"{tsqm.PatientId};");
                buffer.AppendFormat($"{tsqm.Institute};");
                buffer.AppendFormat($"{tsqm.VisitId};");
                buffer.AppendFormat($"{(tsqm.CompleteDate?.ToString("dd.MM.yyyy hh:mm"))};");
                foreach (var item in tsqm.TsqmAnswers)
                {
                    if (item.Value != null)
                    {
                        buffer.AppendFormat($"{item.Value.GetValue("v1").ToString().Trim(new Char[] { '[', ']', ' ' }).TrimStart().TrimEnd()};");
                    }
                    else
                    {
                        buffer.AppendFormat($"{9999};");
                    }
                }

                buffer.Remove(buffer.Length - 1, 1);
                buffer.Append("\n");
            }
        }