public byte[] CreateReport(RepositoryItemMetadata item, RepositoryClientBase client)
        {
            // Get the DDI PhysicalInstance (dataset description)
            var dataset = client.GetItem(item.CompositeId, ChildReferenceProcessing.Instantiate)
                          as PhysicalInstance;

            // Populate all its variable information.
            var populator = new GraphPopulator(client);

            dataset.Accept(populator);

            // Use the Colectica.Reporting MigraDoc helper to create a PDF that
            // simply lists all variables with their names, labels, and types.
            var document = new Document();

            document.Info.Title = "Sample Variable Summary";

            // Add a title.
            var section   = document.AddSection();
            var paragraph = section.AddParagraph(dataset.DublinCoreMetadata.Title.Best);

            paragraph.Format.Font.Bold = true;

            // Create the report helper.
            ReportContext context = new ReportContext();
            var           builder = new ItemBuilderBase(document, context);

            // Get all variables in the dataset.
            var allVariables = dataset
                               .DataRelationships
                               .SelectMany(x => x.LogicalRecords)
                               .SelectMany(x => x.VariablesInRecord)
                               .ToList();

            // Make a list with one item for each variable.
            builder.DefineList();
            foreach (var variable in allVariables)
            {
                string lineText = $"{variable.ItemName.Best} - {variable.Label.Best} - {variable.RepresentationType}";
                builder.AddListItem(lineText);
            }

            // Render the PDF and return it.
            var pdfRenderer = new PdfDocumentRenderer(true);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            using (var stream = new MemoryStream())
            {
                pdfRenderer.Save(stream, true);
                var fileContents = stream.ToArray();
                return(fileContents);
            }
        }
        public List <VariableItem> ProcessResults(RepositoryItemMetadata result, List <VariableItem> items, QuestionModel model, string equivalence, int uniqueId, int counter)
        {
            var variables = RepositoryHelper.GetReferences(result.AgencyId, result.Identifier).Where(x => x.ItemType == new Guid("683889c6-f74b-4d5e-92ed-908c0a42bb2d"));

            foreach (var variable in variables)
            {
                VariableItem item = new VariableItem();
                item.name         = null;
                item.description  = variable.DisplayLabel;
                item.counter      = counter;
                item.questionName = variable.ItemName.FirstOrDefault().Value;
                item.questionText = variable.Label.FirstOrDefault().Value;
                item.questionItem = variable.CompositeId.ToString();
                item.parentitem   = result.Identifier.ToString();
                item.studyGroup   = variable.AgencyId;
                item.identifier   = variable.Identifier;

                var concept = (from a in model.AllConcepts
                               where a.ItemType == result.Identifier
                               select a).FirstOrDefault();
                var v = RepositoryHelper.GetConcept(result.AgencyId, result.Identifier);
                RepositoryItemMetadata mainconcept = new RepositoryItemMetadata();
                if (concept != null)
                {
                    mainconcept = RepositoryHelper.GetConcept(concept.AgencyId, concept.Identifier);
                }
                var dataset = RepositoryHelper.GetConcept(variable.AgencyId, variable.Identifier);
                if (concept != null)
                {
                    item.concept = concept.Label.Values.FirstOrDefault() + " - " + mainconcept.Label.Values.FirstOrDefault();
                }
                item.description  = variable.Label.Values.FirstOrDefault();
                item.questionText = item.description;
                item.questionName = variable.ItemName.Values.FirstOrDefault();
                item.study        = RepositoryHelper.GetStudy(result.AgencyId, result.Identifier);
                item.name         = variable.DisplayLabel;

                items.Add(item);
                item.uniqueId    = uniqueId;
                item.equivalence = equivalence.Trim();
                // item.column = RepositoryHelper.GetStudyColumn(item.study, model.StudyId);
                item.selected     = true;
                item.isdeprecated = variable.IsDeprecated;
            }
            return(items);
        }
        public QuestionModel PopulateQuestionMessages(QuestionModel model, List <TreeViewNode> selecteditems, string type)
        {
            List <VariableItem> items = new List <VariableItem>();
            int    i        = 0;
            int    j        = 0;
            string question = null;

            List <Word> words1 = new List <Word>();

            List <RepositoryItemMetadata> questions = new List <RepositoryItemMetadata>();

            foreach (var selectedwords in model.WordList)
            {
                questions = model.AllQuestions;
                List <Word>   words2    = new List <Word>();
                List <string> wordList2 = selectedwords.Value.Split(' ').ToList();
                foreach (var word2 in wordList2)
                {
                    Word currentword = new Word();
                    currentword.Value = word2;
                    words2.Add(currentword);
                }
                string selectedword = "";
                foreach (var currentword in words2)
                {
                    selectedword = " " + currentword.Value + " ";
                    questions    = (from a in questions
                                    where words2.Any(word => a.Summary.FirstOrDefault().Value.ToLower().Contains(selectedword.ToLower()))
                                    select a).ToList();
                }

                if (questions.Count != 0)
                {
                    i++;

                    foreach (var result in questions)
                    {
                        var question4 = questions.FirstOrDefault(x => x.Identifier == result.Identifier);

                        j++;
                        if (type == "Question")
                        {
                            VariableItem item = new VariableItem();
                            item.name         = null;
                            item.description  = question4.DisplayLabel;
                            item.counter      = j;
                            item.questionName = question4.ItemName.FirstOrDefault().Value;
                            item.questionText = question4.DisplayLabel;
                            item.questionItem = question4.CompositeId.ToString();
                            item.parentitem   = question4.ItemType.ToString();
                            item.studyGroup   = question4.AgencyId;
                            item.identifier   = question4.Identifier;

                            var concept = (from a in model.AllConcepts
                                           where a.ItemType == question4.Identifier
                                           select a).FirstOrDefault();
                            var v = RepositoryHelper.GetConcept(question4.AgencyId, question4.Identifier);
                            RepositoryItemMetadata mainconcept = new RepositoryItemMetadata();
                            if (concept != null)
                            {
                                mainconcept = RepositoryHelper.GetConcept(concept.AgencyId, concept.Identifier);
                            }
                            var dataset = RepositoryHelper.GetConcept(question4.AgencyId, question4.Identifier);
                            if (concept != null)
                            {
                                item.concept = concept.Label.Values.FirstOrDefault() + " - " + mainconcept.Label.Values.FirstOrDefault();
                            }
                            item.description  = question4.Summary.Values.FirstOrDefault();
                            item.questionText = item.description;
                            item.questionName = question4.ItemName.Values.FirstOrDefault();
                            item.study        = RepositoryHelper.GetStudy(question4.AgencyId, question4.Identifier);
                            item.name         = question4.DisplayLabel;

                            items.Add(item);
                            item.uniqueId    = i;
                            item.equivalence = selectedword.Trim();
                            // item.column = RepositoryHelper.GetStudyColumn(item.study, model.StudyId);
                            item.selected     = true;
                            item.isdeprecated = question4.IsDeprecated;
                            question          = question4.DisplayLabel;
                        }
                        else
                        {
                            items = ProcessResults(result, items, model, selectedword, i, j);
                        }
                        if (model.SelectedStudies.Count == 1)
                        {
                            model.StudyName = RepositoryHelper.GetStudy(result.AgencyId, result.Identifier);
                        }
                    }
                }
            }
            model.AllResults = items;
            return(model);
        }
 public bool CanCreateReport(RepositoryItemMetadata item) => item.ItemType == DdiItemType.PhysicalInstance;