정규 표현 식 클래스 를 이용 하여 SQL 문 구 를 해석 하여 Worklist 가 각 RIS 데이터 베 이 스 를 호 환 하 는 목적 을 달성 합 니 다.

   RIS          ,   Worklist     RIS   ,            。  
 1.xml     RIS       ,  
 2.xml         /      SQL  ,     /      {x}   。  {0}        
 3.xml   Worklist SCU query            ,    Tag ID  Tag Name      Column    。 
 4.    : Worklist SCU  Query, WorklistSCP         ,        column  ,  xml       xml   ,     Sql    。     API  Sql  。  


  public class RISQueryHelper     {         public string BuildSelectQuery(string select)         {             if (String.IsNullOrEmpty(select))             {                 throw new ArgumentNullException("input select query is null.");             }               string query = select.Replace("@", "").Replace("&apos;", "'");               return query;         }           public string BuildUpdateQuery(string update, params object[] columnValues)         {             if (String.IsNullOrEmpty(update))             {                 throw new ArgumentNullException("input sql statement is null or empty.");             }               BuildTableRelationship(update);               string sql = update.Replace("@", "").Replace("&apos;", "'");               //Sql template mark the parameter by{x},x like: 1,2,3,4,5,...n             //For example: UPDATE @RequestedProcedure SET @Status='{0}' WHERE @Order_Refid IN (SELECT @Refid FROM @Orders WHERE @AccessionNo='{1}';             //So we can use String.Format to replace {x} by our real value.             {                 sql = String.Format(sql, columnValues);             }               return sql;         }           public void BuildTableRelationship(string update)         {             //{Get table & column name, we will use these data to construct relationship between tables and column for further.             string[] tables = null;             string[] cols = null;               if (!BuildUpdateQueryArgs(update, out tables, out cols))             {                 throw new Exception("Build sql statement failed. Input sql is : " + update);             }             //end, need to parse when statement has many tables.}         }           public bool BuildUpdateQueryArgs(string update, out string[] tableNames, out string[] columnNames)         {             if (String.IsNullOrEmpty(update))             {                 throw new ArgumentNullException("input select query is null.");             }               List<string> tables = new List<string>();             List<string> columns = new List<string>();             string sql = update;               BuildTableNames(ref sql, ref tables);             BuildColumnNames(ref sql, ref columns);               tableNames = tables.ToArray();             columnNames = columns.ToArray();               return true;         }           private void BuildTableNames(ref string sql, ref List<string> tables)         {             var statement = Regex.Matches(                 sql,                 @"\bfrom\b.+?\bwhere\b|\bupdate\b.+?\bset\b",                 RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);               foreach (Match t in statement)             {                 //delete table operation from sql statement.                 sql = sql.Replace(t.Value, "");                   //save table name                 tables.Add(Regex.Replace(t.Value, @"\bupdate\b|@|\bset\b|\s|\bfrom\b|\bwhere\b", "", RegexOptions.IgnoreCase));             }         }           private void BuildColumnNames(ref string sql, ref List<string> columns)         {             var statement = Regex.Matches(                 sql,                 @"@\w+\b\s*=",                 RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);               foreach (Match t in statement)             {                 //delete column operation from sql statement.                 sql = sql.Replace(t.Value, "");                   //save column name                 columns.Add(Regex.Replace(t.Value, @"@|\s|=", "", RegexOptions.IgnoreCase));             }         }     } 

좋은 웹페이지 즐겨찾기