public HierarchyMutableObjectBaseCore( IHierarchyObjectBase<IHierarchicalCodelistObjectBase> hierarchyObject) : base(hierarchyObject) { this._codeRefs = new List<ICodeRefMutableObjectBase>(); /* foreach */ foreach (IHierarchicalCodeObjectBase currentCodeRef in hierarchyObject.Codes) { _codeRefs.Add(new CodeRefMutableObjectBaseCore(currentCodeRef)); } if (hierarchyObject.Level != null) { this._childLevel = new LevelMutableCore(hierarchyObject.Level); } this._hasFormalLevels = hierarchyObject.HasFormalLevels(); }
/// <summary> /// Initializes a new instance of the <see cref="LevelMutableCore"/> class. /// </summary> /// <param name="level"> /// The level. /// </param> public LevelMutableCore(ILevelObject level) : base(level) { if (level.HasChild()) { this.childLevel = new LevelMutableCore(level.ChildLevel); } if (level.CodingFormat != null) { this.codingFormat = new TextFormatMutableCore(level.CodingFormat); } }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECT ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="LevelCore"/> class. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <param name="levelMutable"> /// The level mutable. /// </param> public LevelCore(IIdentifiableObject parent, ILevelMutableObject levelMutable) : base(levelMutable, parent) { if (levelMutable.CodingFormat != null) { this.textFormat = new TextFormatObjectCore(levelMutable.CodingFormat, this); } if (levelMutable.ChildLevel != null) { this.childLevel = new LevelCore(this, levelMutable.ChildLevel); } }
/// <summary> /// Gets the normalized level. /// </summary> /// <param name="currentLevel">The current level.</param> /// <param name="levelRef">The level reference.</param> /// <returns>The <see cref="System.String"/>.</returns> private static string GetNormalizedLevel(ILevelMutableObject currentLevel, string levelRef) { List <string> levels = new List <string>(); string normalizedLevel = null; while (currentLevel != null) { levels.Add(currentLevel.Id); if (currentLevel.Id.Equals(levelRef)) { normalizedLevel = string.Join(".", levels); break; } currentLevel = currentLevel.ChildLevel; } return(normalizedLevel); }
/// <summary> /// Initializes a new instance of the <see cref="HierarchyMutableCore"/> class. /// </summary> /// <param name="objTarget"> /// The obj target. /// </param> public HierarchyMutableCore(IHierarchy objTarget) : base(objTarget) { this._codeRefs = new List<ICodeRefMutableObject>(); if (objTarget.HierarchicalCodeObjects != null) { foreach (IHierarchicalCode hierarchicalCode in objTarget.HierarchicalCodeObjects) { this.AddHierarchicalCode(new CodeRefMutableCore(hierarchicalCode)); } } if (objTarget.Level != null) { this._level = new LevelMutableCore(objTarget.Level); } this._hasFormalLevels = objTarget.HasFormalLevels(); }
/// <summary> /// The write level. /// </summary> /// <param name="level"> /// The level. /// </param> /// <param name="order"> /// The level order /// </param> private void WriteLevel(ILevelMutableObject level, int order) { this.WriteStartElement(this.DefaultNS, ElementNameTable.Level); this.WriteIdentifiableArtefactAttributes(level); this.WriteIdentifiableArtefactContent(level); this.WriteElement(this.DefaultNS, ElementNameTable.Order, order); if (level.CodingFormat != null) { this.WriteTextFormat(ElementNameTable.CodingType, level.CodingFormat); } this.WriteAnnotations(ElementNameTable.Annotations, level.Annotations); this.WriteEndElement(); }
/// <summary> /// Handles the Level type element text only child elements /// </summary> /// <param name="parent"> /// The parent ILevelMutableObject object /// </param> /// <param name="localName"> /// The name of the current xml element /// </param> private void HandleTextChildElement(ILevelMutableObject parent, object localName) { if (NameTableCache.IsElement(localName, ElementNameTable.Order)) { this._currentLevels.Add(XmlConvert.ToInt32(this.Text), parent); } }
/// <summary> /// Handles the Level type element child elements /// </summary> /// <param name="parent"> /// The parent ILevelMutableObject object /// </param> /// <param name="localName"> /// The name of the current xml element /// </param> /// <returns> /// The <see cref="StructureReaderBaseV20.ElementActions"/>. /// </returns> private ElementActions HandleChildElements(ILevelMutableObject parent, object localName) { if (NameTableCache.IsElement(localName, ElementNameTable.CodingType)) { parent.CodingFormat = HandleTextFormat(this.Attributes); return ElementActions.Empty; } return null; }
/// <summary> /// Retrieve and populate the <see cref="IHierarchyMutableObject.HierarchicalCodeObjects"/> for the HIERARCHY with specified Primary KEY /// </summary> /// <param name="artefact"> /// The <see cref="IHierarchyMutableObject"/> instance to populate /// </param> /// <param name="hid"> /// The Hierarchy Mapping store Primary KEY /// </param> private void FillCodeRef(IHierarchyMutableObject artefact, long hid) { IDictionary <long, ICodeRefMutableObject> allItems = new ListDictionary <long, ICodeRefMutableObject>(); var childItems = new Dictionary <long, long>(); using (DbCommand command = this._itemCommandBuilder.Build(new ItemSqlQuery(this._codeRefQueryInfo, hid))) { using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command)) { int sysIdIdx = dataReader.GetOrdinal("SYSID"); int idIdx = dataReader.GetOrdinal("CODE_ID"); int parentIdx = dataReader.GetOrdinal("PARENT"); int nodeAliasIdIdx = dataReader.GetOrdinal("NodeAliasID"); //// TODO check how to set the version (it seems supported in v2.1) int levelRefIdx = dataReader.GetOrdinal("LEVEL_REF"); int clidIdx = dataReader.GetOrdinal("CLID"); int clversionIdx = dataReader.GetOrdinal("CLVERSION"); int clagencyIdx = dataReader.GetOrdinal("CLAGENCY"); int validFromIdx = dataReader.GetOrdinal("VALID_FROM"); int validToIdx = dataReader.GetOrdinal("VALID_TO"); while (dataReader.Read()) { var codeRef = new CodeRefMutableCore { CodelistAliasRef = BuildCodelistRefAlias( DataReaderHelper.GetString(dataReader, clidIdx), DataReaderHelper.GetString(dataReader, clagencyIdx), DataReaderHelper.GetString(dataReader, clversionIdx)), Id = DataReaderHelper.GetString(dataReader, nodeAliasIdIdx), CodeId = DataReaderHelper.GetString(dataReader, idIdx) }; if (artefact.ChildLevel != null) { var levelRef = DataReaderHelper.GetString(dataReader, levelRefIdx); ILevelMutableObject currentLevel = artefact.ChildLevel; var normalizedLevel = GetNormalizedLevel(currentLevel, levelRef); codeRef.LevelReference = normalizedLevel; } if (string.IsNullOrWhiteSpace(codeRef.Id)) { codeRef.Id = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", codeRef.CodelistAliasRef.Replace('@', '_'), '_', codeRef.CodeId); } DateTime?validFrom = DataReaderHelper.GetStringDate(dataReader, validFromIdx); if (validFrom != null) { codeRef.ValidFrom = validFrom.Value; } DateTime?validTo = DataReaderHelper.GetStringDate(dataReader, validToIdx); if (validTo != null) { codeRef.ValidTo = validTo.Value; } long sysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx); long parentItemId = DataReaderHelper.GetInt64(dataReader, parentIdx); if (parentItemId > long.MinValue) { childItems.Add(sysId, parentItemId); } allItems.Add(sysId, codeRef); } } } this._hierarchalCodeAnnotationRetrieverEngine.RetrieveAnnotations(hid, allItems); ICollection <KeyValuePair <long, ICodeRefMutableObject> > collection = allItems; foreach (KeyValuePair <long, ICodeRefMutableObject> item in collection) { long sysId = item.Key; ICodeRefMutableObject codeRef = item.Value; long parentItemId; if (childItems.TryGetValue(sysId, out parentItemId)) { // has parent ICodeRefMutableObject parent = allItems[parentItemId]; parent.AddCodeRef(codeRef); } else { // add only root elements artefact.AddHierarchicalCode(codeRef); } } }