/// <summary> /// Parse Row /// </summary> /// <param name="baseResourceId"></param> /// <param name="baseReferenceUrl"></param> /// <param name="prop"></param> /// <param name="columns"></param> public void Parse(string baseResourceId, string baseReferenceUrl, FHIRPropertyMapping prop, CSVRow columns) { //1. Find Column in the dataset CSVColumn column = null; if (prop.ColumnIndex.HasValue) { column = columns.Where(e => e.ColumnIndex.HasValue) .FirstOrDefault(e => e.ColumnIndex.Value == prop.ColumnIndex.Value); } if (column == null && !string.IsNullOrEmpty(prop.ColumnName)) { column = columns.FirstOrDefault(e => e.ColumnName == prop.ColumnName); } if (column == null) { throw new ArgumentNullException(); } object root = null; if (string.IsNullOrEmpty(prop.ResourceBaseType)) { throw new ResourceBaseTypeNotDefined(); } //Get Base Resource Identifier based on base ResourceId and property Resource Id var resourceId = GetBaseResourceId(baseResourceId + prop.ResourceId, columns); //if the resource already exists then the property is assigned to the existing resource if (_resourceDictionary.ContainsKey(resourceId)) { root = _resourceDictionary[resourceId].Item2; FHIRTranslator.SetProperty(root, prop.ResourcePath, column.Value, prop.ResourcePathTypes, prop.ValueTemplate); } else { //Create a new resource root = FHIRTranslator.SetProperty(prop.ResourcePath, prop.ResourcePathTypes, column.Value, prop.ValueTemplate); //Set Resource Id if (root != null && root is Resource && string.IsNullOrEmpty((root as Resource).Id)) { (root as Resource).Id = resourceId; } // Add to resource dictionary with the corresponding resource URL for reference _resourceDictionary.Add(resourceId, Tuple.Create(prop.ResourceBaseType, root, GetUrl(baseReferenceUrl, prop.ResourceBaseType, root as Resource))); } //Create Fix properties on the Resource if (root != null && prop.FixedProperties != null) { CreateFixProperties(root, prop.FixedProperties, columns); } }