예제 #1
0
        /// <summary>
        /// Parse all SNOMED realtionships and create applicadia attributes for each one.
        /// </summary>
        void CreateRelationships()
        {
            // We cant resize SnomedQueryConcept[]'s efficiently, so map all the parent and
            // children to lists and set the objects IsAXXX to the list.ToArray() when
            // we have collated all concepts.
            ConcurrentDictionary <Int64, List <SnomedQueryConcept> > parentMap =
                new ConcurrentDictionary <long, List <SnomedQueryConcept> >();
            ConcurrentDictionary <Int64, List <SnomedQueryConcept> > childMap =
                new ConcurrentDictionary <long, List <SnomedQueryConcept> >();

            foreach (KeyValuePair <Int64, RF2RelationshipGroup> kvp in this.rf2Parser.RelationshipGroups)
            {
                RF2RelationshipGroup rf2RelationshipGroup = kvp.Value;
                this.CreateRelationship(rf2RelationshipGroup, parentMap, childMap);
            }

            // Copy all parent lists to parent array in each concept.
            foreach (KeyValuePair <Int64, List <SnomedQueryConcept> > kvp in parentMap)
            {
                SnomedQueryConcept item = this.FindConcept(kvp.Key);
                item.IsAParents = kvp.Value.ToArray();
            }


            // Copy all child lists to child array in each concept.
            foreach (KeyValuePair <Int64, List <SnomedQueryConcept> > kvp in childMap)
            {
                SnomedQueryConcept item = this.FindConcept(kvp.Key);
                item.IsAChildren = kvp.Value.ToArray();
            }
        }
예제 #2
0
        /// <summary>
        /// Add a destination relationship to concept group.
        /// </summary>
        /// <param name="relationshipGroup">Relationship in which this instance is the destination</param>
        public void AddDestinationRelationship(RF2RelationshipGroup relationshipGroup)
        {
            if (this.destinationRelationshipIds.Contains(relationshipGroup.Id) == true)
            {
                return;
            }
            this.destinationRelationshipIds.Add(relationshipGroup.Id);

            // force lazy reloading of source relationship groups id called.
            this.destinationRelationshipGroups = null;
        }
예제 #3
0
        /// <summary>
        /// Pathc relationships.
        /// This must be run after concepts are read in.
        /// </summary>
        /// <param name="path"></param>
        void FixRelationships()
        {
            foreach (KeyValuePair <Int64, RF2RelationshipGroup> kvp in this.RelationshipGroups)
            {
                RF2RelationshipGroup relationshipGroup = kvp.Value;

                RF2Relationship relationship = relationshipGroup.Active;
                if (relationship != null)
                {
                    RF2ConceptGroup sourceConcept      = this.GetConceptGroup(relationship.SourceId);
                    RF2ConceptGroup destinationConcept = this.GetConceptGroup(relationship.DestinationId);

                    sourceConcept.AddSourceRelationship(relationshipGroup);
                    destinationConcept.AddDestinationRelationship(relationshipGroup);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Parse all SNOMED realtionships and create applicadia attributes for each one.
        /// </summary>
        void CreateRelationship(RF2RelationshipGroup rf2RelationshipGroup,
                                ConcurrentDictionary <Int64, List <SnomedQueryConcept> > parentMap,
                                ConcurrentDictionary <Int64, List <SnomedQueryConcept> > childMap)
        {
            RF2Relationship rf2Relationship = rf2RelationshipGroup.Active;

            if (rf2Relationship == null)
            {
                return;
            }

            switch (rf2Relationship.TypeId)
            {
            case RF2Parser.IsAConceptId:
                SnomedQueryConcept source = this.FindConcept(rf2Relationship.Source.Id);
                SnomedQueryConcept dest   = this.FindConcept(rf2Relationship.Destination.Id);
                this.Add(parentMap, source, dest);
                this.Add(childMap, dest, source);
                break;
            }
        }
예제 #5
0
        /// <summary>
        /// Load raw snomed description data into memory.
        /// </summary>
        /// <param name="path"></param>
        void LoadRelationships(String path)
        {
            StreamReader reader = new StreamReader(File.OpenRead(path));

            String[] parts = reader.ReadLine().Split('\t');
            if (
                (parts.Length != 10) ||
                (String.Compare(parts[0], "id") != 0) ||
                (String.Compare(parts[1], "effectiveTime") != 0) ||
                (String.Compare(parts[2], "active") != 0) ||
                (String.Compare(parts[3], "moduleId") != 0) ||
                (String.Compare(parts[4], "sourceId") != 0) ||
                (String.Compare(parts[5], "destinationId") != 0) ||
                (String.Compare(parts[6], "relationshipGroup") != 0) ||
                (String.Compare(parts[7], "typeId") != 0) ||
                (String.Compare(parts[8], "characteristicTypeId") != 0) ||
                (String.Compare(parts[9], "modifierId") != 0)
                )
            {
                throw new ApplicationException("Invalid header line to Relationship file");
            }

            RF2RelationshipGroup relationshipGroup = null;

            while (true)
            {
                String line = reader.ReadLine();
                if (line == null)
                {
                    break;
                }

                RF2Relationship relationship = RF2Relationship.Parse(this, line);
                if (relationship != null)
                {
                    /*
                     * Relationships in a common group are usually grouped together, so check
                     * last relationship to see if it is same group first.
                     */
                    if ((relationshipGroup != null) && (relationshipGroup.Id != relationship.Id))
                    {
                        relationshipGroup = null;
                    }

                    if (
                        (relationshipGroup == null) &&
                        (this.RelationshipGroups.TryGetValue(relationship.Id, out relationshipGroup) == false)
                        )
                    {
                        relationshipGroup = null;
                    }

                    if (relationshipGroup == null)
                    {
                        relationshipGroup = new RF2RelationshipGroup()
                        {
                            Parser = this,
                            Id     = relationship.Id
                        };
                        if (this.RelationshipGroups.TryAdd(relationship.Id, relationshipGroup) == false)
                        {
                            throw new ApplicationException("Error adding relationship to dictionary");
                        }
                    }
                    relationshipGroup.AddRelationship(relationship);
                }
            }
        }