예제 #1
0
        //
        // - Methods -
        //

        /// <summary>
        /// Add a Context Group this this instance.
        /// </summary>
        /// <param name="contextGroup">The Context Group to add.</param>
        private void AddCodedConceptsToDictionary(ContextGroup contextGroup)
        {
            foreach (CodedConceptOrInclude codedConceptOrInclude in contextGroup.CodedConceptsOrIncludes)
            {
                if (codedConceptOrInclude is CodedConcept)
                {
                    CodedConcept codedConcept = codedConceptOrInclude as CodedConcept;

                    CodingSchemeDesignatorCodeValuePair codingSchemeDesignatorCodeValuePair = new CodingSchemeDesignatorCodeValuePair(codedConcept.CodingSchemeDesignator, codedConcept.CodeValue);

                    List <CodedConcept> codedConcepts = null;

                    if (this.codedConceptDictionary.TryGetValue(codingSchemeDesignatorCodeValuePair, out codedConcepts))
                    {
                        codedConcepts.Add(codedConcept);
                    }
                    else
                    {
                        codedConcepts = new List <CodedConcept>();
                        codedConcepts.Add(codedConcept);
                        this.codedConceptDictionary.Add(codingSchemeDesignatorCodeValuePair, codedConcepts);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Load Context Group instances from xml files.
        /// </summary>
        /// <param name="path">The path to the xml files.</param>
        /// <param name="searchPattern">
        /// The search pattern for the file names to use to determine which xml files to load.
        /// </param>
        public void LoadContextGroupsFromXml(String path, String searchPattern)
        {
            String[] fullFileNames = Directory.GetFiles(path, searchPattern);

            foreach (String fullFileName in fullFileNames)
            {
                try
                {
                    ContextGroup contextGroup = ContextGroup.LoadInstanceFromXml(fullFileName);


                    //
                    // Add this Context Group to the contextGroupDictionary.
                    //

                    this.contextGroupDictionary.Add(contextGroup.Id, contextGroup);


                    //
                    // Add all Coded Concepts in the Context Group to the codedConceptDictionary.
                    //

                    AddCodedConceptsToDictionary(contextGroup);
                }
                catch
                {
                    // TODO: log this somehow.
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Get a list of all Coded Concepts from the Context Group specified by the supplied CID
        /// that have the supplied Coding Scheme Designator and Code Value.
        /// </summary>
        /// <param name="cid">The Context ID.</param>
        /// <param name="codingSchemeDesignator">The Coding Scheme Designator.</param>
        /// <param name="codeValue">The Code Value.</param>
        /// <returns>
        /// Null of the Content Group specified by the supplied CID does not exist.
        /// Otherwise a list of Coded Concepts.
        /// </returns>
        public IList <CodedConcept> GetCodedConcepts(string cid, string codingSchemeDesignator, string codeValue)
        {
            List <CodedConcept> codedConcepts = null;

            ContextGroup contextGroup = null;

            if (!this.contextGroupDictionary.TryGetValue(cid, out contextGroup))
            // Key not found and contextGroup contains null;
            {
                codedConcepts = null;
            }
            else
            {
                codedConcepts = new List <CodedConcept>();

                foreach (CodedConceptOrInclude codedConceptOrInclude in contextGroup.CodedConceptsOrIncludes)
                {
                    if (codedConceptOrInclude is CodedConcept)
                    {
                        CodedConcept codedConcept = codedConceptOrInclude as CodedConcept;

                        if ((codingSchemeDesignator == codedConcept.CodingSchemeDesignator) && (codeValue == codedConcept.CodeValue))
                        {
                            codedConcepts.Add(codedConcept);
                        }
                    }
                    else if (codedConceptOrInclude is IncludedContextGroup)
                    {
                        IncludedContextGroup includedContextGroup = codedConceptOrInclude as IncludedContextGroup;

                        IList <CodedConcept> matchingCodedConceptsFromIncludedContentGroup = GetCodedConcepts(includedContextGroup.Id, codingSchemeDesignator, codeValue);

                        if (matchingCodedConceptsFromIncludedContentGroup != null)
                        {
                            codedConcepts.AddRange(matchingCodedConceptsFromIncludedContentGroup);
                        }
                    }
                }
            }

            return(codedConcepts);
        }
예제 #4
0
        /// <summary>
        /// Creates a string dump for a single Context Group.
        /// </summary>
        /// <param name="prefix">The prefix to use in the string dump.</param>
        /// <param name="contextGroup">The Context Group.</param>
        /// <returns>The string dump.</returns>
        private static String ContextGroupStringDump(String prefix, ContextGroup contextGroup)
        {
            StringBuilder stringDump = new StringBuilder();

            stringDump.Append(prefix + "Context ID \"" + contextGroup.Id + "\", Context Group Name \"" + contextGroup.Name + "\"\r\n");
            stringDump.Append(prefix + "  CODING SCHEME DESIGNATOR, CODE VALUE, CODE MEANING\r\n");
            stringDump.Append(prefix + "  ------------------------  ----------  ------------");


            foreach (CodedConceptOrInclude codedConceptOrInclude in contextGroup.CodedConceptsOrIncludes)
            {
                if (codedConceptOrInclude is CodedConcept)
                {
                    CodedConcept codedConcept = codedConceptOrInclude as CodedConcept;
                    stringDump.Append("\r\n" + prefix + "  " + codedConcept.CodingSchemeDesignator);

                    if (codedConcept.CodingSchemeVersion != null)
                    {
                        stringDump.Append(" [" + codedConcept.CodingSchemeVersion + "]");
                    }

                    stringDump.Append(", " + codedConcept.CodeValue + ", \"" + codedConcept.CodeMeaning + "\"");
                }
                else if (codedConceptOrInclude is IncludedContextGroup)
                {
                    IncludedContextGroup includedContextGroup = codedConceptOrInclude as IncludedContextGroup;

                    stringDump.Append("\r\n" + prefix + "  Include CONTEXT ID " + includedContextGroup.Id);
                }
                else
                {
                    throw new Exception("Not supposed to get here.");
                }
            }

            return(stringDump.ToString());
        }
예제 #5
0
        //
        // - Methods -
        //
        /// <summary>
        /// Add a Context Group this this instance.
        /// </summary>
        /// <param name="contextGroup">The Context Group to add.</param>
        private void AddCodedConceptsToDictionary(ContextGroup contextGroup)
        {
            foreach (CodedConceptOrInclude codedConceptOrInclude in contextGroup.CodedConceptsOrIncludes)
            {
                if (codedConceptOrInclude is CodedConcept)
                {
                    CodedConcept codedConcept = codedConceptOrInclude as CodedConcept;

                    CodingSchemeDesignatorCodeValuePair codingSchemeDesignatorCodeValuePair = new CodingSchemeDesignatorCodeValuePair(codedConcept.CodingSchemeDesignator, codedConcept.CodeValue);

                    List<CodedConcept> codedConcepts = null;

                    if (this.codedConceptDictionary.TryGetValue(codingSchemeDesignatorCodeValuePair, out codedConcepts))
                    {
                        codedConcepts.Add(codedConcept);
                    }
                    else
                    {
                        codedConcepts = new List<CodedConcept>();
                        codedConcepts.Add(codedConcept);
                        this.codedConceptDictionary.Add(codingSchemeDesignatorCodeValuePair, codedConcepts);
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Creates a string dump for a single Context Group.
        /// </summary>
        /// <param name="prefix">The prefix to use in the string dump.</param>
        /// <param name="contextGroup">The Context Group.</param>
        /// <returns>The string dump.</returns>
        private static String ContextGroupStringDump(String prefix, ContextGroup contextGroup)
        {
            StringBuilder stringDump = new StringBuilder();

            stringDump.Append(prefix + "Context ID \"" + contextGroup.Id + "\", Context Group Name \"" + contextGroup.Name + "\"\r\n");
            stringDump.Append(prefix + "  CODING SCHEME DESIGNATOR, CODE VALUE, CODE MEANING\r\n");
            stringDump.Append(prefix + "  ------------------------  ----------  ------------");

            foreach (CodedConceptOrInclude codedConceptOrInclude in contextGroup.CodedConceptsOrIncludes)
            {
                if (codedConceptOrInclude is CodedConcept)
                {
                    CodedConcept codedConcept = codedConceptOrInclude as CodedConcept;
                    stringDump.Append("\r\n" + prefix + "  " + codedConcept.CodingSchemeDesignator);

                    if (codedConcept.CodingSchemeVersion != null)
                    {
                        stringDump.Append(" [" + codedConcept.CodingSchemeVersion + "]");
                    }

                    stringDump.Append(", " + codedConcept.CodeValue + ", \"" + codedConcept.CodeMeaning + "\"");
                }
                else if (codedConceptOrInclude is IncludedContextGroup)
                {
                    IncludedContextGroup includedContextGroup = codedConceptOrInclude as IncludedContextGroup;

                    stringDump.Append("\r\n" + prefix + "  Include CONTEXT ID " + includedContextGroup.Id);
                }
                else
                {
                    throw new Exception("Not supposed to get here.");
                }
            }

            return (stringDump.ToString());
        }