//---------------------------------------------------------------------------
// String _hisconnection; 	约定的输入变量名
// String _opacsconnection; 约定的输入变量名
// String _modalitytype; 	约定的输入变量名
// String _configsection; 	约定的输入变量名
// TADOQuery _qryStudy 	    外部已定义的对象
// TADOQuery _qryReport 	外部已定义的对象
// TADOQuery _qryImage      外部已定义的对象
// TADOQuery _qryCustom     外部已定义的对象
// TADOQuery _qryHisPatient 外部已定义的对象
// TADOQuery _qryHisReport  外部已定义的对象
// TADOQuery _qryHisImage   外部已定义的对象
// TADOQuery _qryHisCommon  外部已定义的对象
// TADOQuery _qryHisCustom  外部已定义的对象
//---------------------------------------------------------------------------
#include "..\\Common\\HisCommon.cpp"

String      _hisconnection;
String      _opacsconnection;
String      _modalitytype;
String 		_configsection;
//---------------------------------------------------------------------------

String BuildQuerySQL()
{
	// 图像保留天数
	int iRemainDay = 180;
	
    // 构造查询语句
	String sQuerySQL = "select * from images where image_state > 0 and study_key in " +
		"(select study_key from study where study_modalitytype='" + _modalitytype + "')";
	if (IsConnetSQLServer(_opacsconnection))
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff(day, image_dttm, GetDate()) > " + IntToStr(iRemainDay));
        sQuerySQL = AccessToSQL(sQuerySQL);
	}
	else
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff('d', image_dttm, Date()) > " + IntToStr(iRemainDay));
	}
    
    return sQuerySQL;
}
//---------------------------------------------------------------------------

void ExecImageDelete()
{
    // 构造删除图像查询语句
	String sQuerySQL = BuildQuerySQL();

	// 根据查询结果删除图像
	int iResult = DeleteOPImage(sQuerySQL);
	ShowLog("SyncServer", "已成功删除图像文件【" + IntToStr(iResult) + "】个！");
}

//---------------------------------------------------------------------------
// 主程序
{
	try
	{	
    	ExecImageDelete();
    }
    except
    {
	}
}
//---------------------------------------------------------------------------