public static List <RepositoryItemMetadata> GetReferences(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-GB";
            List <RepositoryItemMetadata> referenceItems = new List <RepositoryItemMetadata>();
            var client = ClientHelper.GetClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            try
            {
                IVersionable item = client.GetLatestItem(id, agency,
                                                         ChildReferenceProcessing.Populate);
                // Use a graph search to find a list of all items that
                // directly reference this item.
                GraphSearchFacet facet = new GraphSearchFacet();
                facet.TargetItem            = item.CompositeId;
                facet.UseDistinctResultItem = false;

                var referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet);
                referenceItems = referencingItemsDescriptions.ToList();
                var referencingItemsSubject = client.GetRepositoryItemDescriptionsBySubject(facet).ToList();
            }
            catch (Exception e)
            {
                return(referenceItems);
            }
            return(referenceItems);
        }
Exemple #2
0
        public string GetReferenceItem(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-US";

            var client = ClientHelper.GetClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            IVersionable item = client.GetLatestItem(id, agency,
                                                     ChildReferenceProcessing.Populate);
            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();

            facet.TargetItem            = item.CompositeId;
            facet.UseDistinctResultItem = true;

            var    referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet);
            string referenceItem = null;

            if (referencingItemsDescriptions.Count == 3)
            {
                referenceItem = referencingItemsDescriptions.Where(r => r.ItemType.ToString() == "91da6c62-c2c2-4173-8958-22c518d1d40d").FirstOrDefault().DisplayLabel;
            }
            return(referenceItem);
        }
Exemple #3
0
        public static string GetStudy(string agency, Guid id)
        {
            try
            {
                MultilingualString.CurrentCulture = "en-GB";

                var client = ToolkitHelper.RestClient();

                // Retrieve the requested item from the Repository.
                // Populate the item's children, so we can display information about them.
                IVersionable item = client.client.GetLatestItem(id, agency,
                                                                ChildReferenceProcessing.Populate);
                // Use a graph search to find a list of all items that
                // directly reference this item.
                GraphSearchFacet facet = new GraphSearchFacet();
                facet.TargetItem            = item.CompositeId;
                facet.UseDistinctResultItem = true;
                var references = client.client.GetRepositoryItemDescriptionsByObject(facet);
                var referencingItemDescription = (from a in references
                                                  where a.ItemType == new Guid("0a63fcf6-ffdd-4214-b38c-147d6689d6a1")
                                                  select a).FirstOrDefault();
                for (int i = 1; i < 3; i++)
                {
                    if (referencingItemDescription != null)
                    {
                        referencingItemDescription = GetReference(referencingItemDescription.AgencyId, referencingItemDescription.Identifier);
                    }
                }
                if (referencingItemDescription == null)
                {
                    return(null);
                }
                else
                {
                    return(referencingItemDescription.DisplayLabel);
                }
            }
            catch
            {
                return(null);
            }
        }
        public void RelationshipSearch()
        {
            var physicalInstanceIdentifier = new IdentifierTriple(new Guid(), 1, "int.example");

            // Search for all VariableStatistics related to the PhysicalInstance.
            var facet = new GraphSearchFacet();
            facet.TargetItem = physicalInstanceIdentifier;
            facet.UseDistinctTargetItem = true;
            facet.UseDistinctResultItem = true;
            facet.ItemTypes.Add(DdiItemType.VariableStatistic);

            // Perform the search.
            var results = client.GetRepositoryItemDescriptionsBySubject(facet);

            // Write a line for each result.
            foreach (var result in results)
            {
                Console.WriteLine(result.Label["en-US"]);
            }
        }
Exemple #5
0
        public static RepositoryItemMetadata GetReference(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-GB";

            var client = ToolkitHelper.RestClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            IVersionable item = client.client.GetLatestItem(id, agency,
                                                            ChildReferenceProcessing.Populate);
            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();

            facet.TargetItem            = item.CompositeId;
            facet.UseDistinctResultItem = true;

            var referencingItemDescription = client.client.GetRepositoryItemDescriptionsByObject(facet).FirstOrDefault();

            return(referencingItemDescription);
        }
        public List <RepositoryItemMetadata> GetConcept(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-US";

            var client = ClientHelper.GetClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            IVersionable item = client.GetLatestItem(id, agency);
            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();

            facet.TargetItem            = item.CompositeId;
            facet.UseDistinctResultItem = true;
            var referencingItemsDescriptions             = client.GetRepositoryItemDescriptionsByObject(facet);
            List <RepositoryItemMetadata> referenceItems = referencingItemsDescriptions.ToList();
            var items = client.GetRepositorySettings();

            return(referenceItems);
        }
        public void RelationshipSearch()
        {
            var physicalInstanceIdentifier = new IdentifierTriple(new Guid(), 1, "int.example");

            // Search for all VariableStatistics related to the PhysicalInstance.
            var facet = new GraphSearchFacet();

            facet.TargetItem            = physicalInstanceIdentifier;
            facet.UseDistinctTargetItem = true;
            facet.UseDistinctResultItem = true;
            facet.ItemTypes.Add(DdiItemType.VariableStatistic);

            // Perform the search.
            var results = client.GetRepositoryItemDescriptionsBySubject(facet);

            // Write a line for each result.
            foreach (var result in results)
            {
                Console.WriteLine(result.Label["en-US"]);
            }
        }
        //
        // GET: /Item/
        public ActionResult Index(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-US";

            var client = ClientHelper.GetClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            IVersionable item = client.GetLatestItem(id, agency,
                 ChildReferenceProcessing.Populate);

            // To populate more than one level of children, you can use the GraphPopulator.
            //GraphPopulator populator = new GraphPopulator(client);
            //item.Accept(populator);

            // The type of model and the view we want depends on the item type.
            // This sample only provides specific support for a few item types,
            // so we will just hard-code the type checking below.
            ItemModel model = null;
            string viewName = string.Empty;

            if (item is CategoryScheme)
            {
                var categoryList = item as CategoryScheme;

                // Create the model and set the item as a property, so it's contents can be displayed
                var categorySchemeModel = new CategorySchemeModel();
                categorySchemeModel.CategoryScheme = categoryList;

                model = categorySchemeModel;
                viewName = "CategoryList";
            }
            else if (item is StudyUnit)
            {
                var studyUnit = item as StudyUnit;

                // Create the model and set the item as a property, so it's contents can be displayed
                var studyModel = new StudyUnitModel();
                studyModel.StudyUnit = studyUnit;

                foreach (var qualityStatement in studyUnit.QualityStatements)
                {
                    client.PopulateItem(qualityStatement);
                }

                // Use a set search to get a list of all questions that are referenced
                // by the study. A set search will return items that may be several steps
                // away.
                SetSearchFacet setFacet = new SetSearchFacet();
                setFacet.ItemTypes.Add(DdiItemType.QuestionItem);

                var matches = client.SearchTypedSet(studyUnit.CompositeId,
                    setFacet);
                var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection());

                foreach (var info in infoList)
                {
                    studyModel.Questions.Add(info);
                }

                model = studyModel;
                viewName = "StudyUnit";
            }
            else if (item is CodeScheme)
            {
                var codeScheme = item as CodeScheme;

                // Create the model and set the item as a property, so it's contents can be displayed
                var codeSchemeModel = new CodeSchemeModel();
                codeSchemeModel.CodeScheme = codeScheme;

                model = codeSchemeModel;
                viewName = "CodeList";
            }
            else if (item is QualityStatement)
            {
                var qualityStatement = item as QualityStatement;

                var qualityStatementModel = new QualityStatementModel(qualityStatement);

                model = qualityStatementModel;
                viewName = "QualityStatement";
            }
            else
            {
                model = new ItemModel();
                viewName = "GenericItem";
            }

            // Fopr all item types, get the version history of the item,
            // and add the information to the model.
            var history = client.GetVersionHistory(id, agency);
            foreach (var version in history)
            {
                model.History.Add(version);
            }

            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();
            facet.TargetItem = item.CompositeId;
            facet.UseDistinctResultItem = true;

            var referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet);

            // Add the list of referencing items to the model.
            foreach (var info in referencingItemsDescriptions)
            {
                model.ReferencingItems.Add(info);
            }

            // Return the appropriate view, sending in the model.
            return View(viewName, model);
        }
        public object GetRepository(string agency, Guid id)
        {
            MultilingualString.CurrentCulture = "en-US";

            var client = ClientHelper.GetClient();

            // Retrieve the requested item from the Repository.
            // Populate the item's children, so we can display information about them.
            var          v     = client.GetLatestVersionNumber(id, agency);
            IVersionable item1 = client.GetItem(id, agency, v);


            IVersionable item = client.GetLatestItem(id, agency,
                                                     ChildReferenceProcessing.Populate);



            // To populate more than one level of children, you can use the GraphPopulator.
            //GraphPopulator populator = new GraphPopulator(client);
            //item.Accept(populator);

            // The type of model and the view we want depends on the item type.
            // This sample only provides specific support for a few item types,
            // so we will just hard-code the type checking below.
            ItemModel model    = null;
            string    viewName = string.Empty;

            if (item is CategoryScheme)
            {
                var categoryList = item as CategoryScheme;

                // Create the model and set the item as a property, so it's contents can be displayed
                var categorySchemeModel = new CategorySchemeModel();
                categorySchemeModel.CategoryScheme = categoryList;

                model    = categorySchemeModel;
                viewName = "CategoryList";
            }
            else if (item is StudyUnit)
            {
                var studyUnit = item as StudyUnit;

                // Create the model and set the item as a property, so it's contents can be displayed
                var studyModel = new StudyUnitModel();
                studyModel.StudyUnit = studyUnit;
                var QualityStatements = studyUnit.QualityStatements.OrderBy(x => x.Identifier).ToList();
                foreach (var qualityStatement in QualityStatements)
                {
                    client.PopulateItem(qualityStatement);
                }

                // Use a set search to get a list of all questions that are referenced
                // by the study. A set search will return items that may be several steps
                // away.
                SetSearchFacet setFacet = new SetSearchFacet();

                setFacet.ItemTypes.Add(DdiItemType.QuestionItem);

                var matches = client.SearchTypedSet(studyUnit.CompositeId,
                                                    setFacet);
                var infoList  = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection());
                var infoList1 = from x in infoList
                                orderby x.DisplayLabel
                                select x;

                foreach (var info in infoList1)
                {
                    studyModel.Questions.Add(info);
                }

                model    = studyModel;
                viewName = "StudyUnit";
            }
            else if (item is CodeList)
            {
                var codeList = item as CodeList;

                // Create the model and set the item as a property, so it's contents can be displayed
                var codeListModel = new CodeListModel();
                codeListModel.CodeList = codeList;

                model    = codeListModel;
                viewName = "CodeList";
            }
            else if (item is QualityStatement)
            {
                var qualityStatement = item as QualityStatement;

                var qualityStatementModel = new QualityStatementModel(qualityStatement);

                model    = qualityStatementModel;
                viewName = "QualityStatement";
            }
            else
            {
                model    = new ItemModel();
                viewName = "GenericItem";
            }

            // Fopr all item types, get the version history of the item,
            // and add the information to the model.
            var history = client.GetVersionHistory(id, agency);

            foreach (var version in history)
            {
                model.History.Add(version);
            }

            // Use a graph search to find a list of all items that
            // directly reference this item.
            GraphSearchFacet facet = new GraphSearchFacet();

            facet.TargetItem            = item.CompositeId;
            facet.UseDistinctResultItem = true;

            var referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet);

            // Add the list of referencing items to the model.

            foreach (var info in referencingItemsDescriptions)
            {
                model.ReferencingItems.Add(info);
            }
            return(model);
        }
Exemple #10
0
        public ActionResult Details(Guid id, string agency, Guid fileId)
        {
            var client = RepositoryHelper.GetClient();

            // Basic variable details.
            var variable = client.GetLatestItem(id, agency) as Variable;

            if (variable.CodeRepresentation != null &&
                variable.CodeRepresentation.Codes != null)
            {
                client.PopulateItem(variable.CodeRepresentation.Codes, false, ChildReferenceProcessing.PopulateLatest);
            }

            var model = new VariableModel()
            {
                Id                  = variable.Identifier.ToString(),
                Agency              = variable.AgencyId,
                Name                = variable.ItemName.Current,
                Label               = variable.Label.Current,
                Description         = variable.Description.Current,
                ResponseUnit        = variable.ResponseUnit,
                AnalysisUnit        = variable.AnalysisUnit,
                ClassificationLevel = variable.ActiveRepresentation != null?variable.ActiveRepresentation.ClassificationLevel.ToString() : string.Empty,
                                          Version     = variable.Version,
                                          LastUpdated = variable.VersionDate.ToShortDateString()
            };

            if (variable.RepresentationType == RepresentationType.Text)
            {
                model.RepresentationType = "Text";
            }
            else if (variable.RepresentationType == RepresentationType.Numeric)
            {
                model.RepresentationType = "Numeric";
            }
            else if (variable.RepresentationType == RepresentationType.Code)
            {
                model.RepresentationType = "Code";
            }


            // Summary statistics.
            var facet = new GraphSearchFacet();

            facet.TargetItem            = variable.CompositeId;
            facet.UseDistinctTargetItem = true;
            facet.ItemTypes.Add(DdiItemType.VariableStatistic);
            var statsId = client.GetRelationshipByObject(facet).FirstOrDefault();

            if (statsId != null)
            {
                var stats = client.GetItem(statsId.CompositeId, ChildReferenceProcessing.Populate) as VariableStatistic;

                model.Valid   = stats.Valid;
                model.Invalid = stats.Invalid;
                model.Minimum = stats.Minimum;
                model.Maximum = stats.Maximum;

                model.Mean = Round(variable, stats.Mean);
                model.StandardDeviation = Round(variable, stats.StandardDeviation);

                foreach (var catStat in stats.UnfilteredCategoryStatistics)
                {
                    var freqModel = new FrequencyModel();
                    freqModel.CategoryValue = catStat.CategoryValue;
                    freqModel.Frequency     = catStat.Frequency;
                    SetIdAndLabelForCategory(catStat.CategoryValue, variable, freqModel);
                    model.Frequencies.Add(freqModel);
                }

                // Calculate bar widths.
                double maxWidth = 200;
                if (model.Frequencies.Count > 0)
                {
                    double maxFrequency = model.Frequencies.Select(x => x.Frequency).Max();
                    foreach (var freq in model.Frequencies)
                    {
                        double w = freq.Frequency * maxWidth / maxFrequency;
                        freq.NormalizedWidth = ((int)w).ToString() + "px";
                    }
                }
            }


            // Comments
            using (var db = ApplicationDbContext.Create())
            {
                var comments = db.Notes.Where(x => x.File.Id == fileId &&
                                              x.VariableAgency == agency &&
                                              x.VariableId == id)
                               .Include(x => x.User);

                foreach (var comment in comments)
                {
                    model.Comments.Add(new CommentModel
                    {
                        UserName = comment.User.UserName,
                        Date     = comment.Timestamp.ToShortDateString(),
                        Comment  = comment.Text
                    });
                }
            }

            string json = System.Web.Helpers.Json.Encode(model);

            return(Content(json));
        }