//---------------------------------------------------------------------------
// 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;
//---------------------------------------------------------------------------

void ExecReportDelete()
{
	// 报告保留天数
	int iRemainDay = 5;
	
	// 指定要删除的报告
	String sQuerySQL = "SELECT * FROM CC_REPORT";
	sQuerySQL = AddWhereCondition(sQuerySQL, "study_modalitytype = '" + _modalitytype + "'");
	sQuerySQL = AddWhereCondition(sQuerySQL, "report_state = 1");
	if (IsConnetSQLServer(_opacsconnection))
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff(day, print_dttm, GetDate()) > " + IntToStr(iRemainDay));
        sQuerySQL = AccessToSQL(sQuerySQL);
	}
	else
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff('d', print_dttm, Date()) > " + IntToStr(iRemainDay));
	}
	
	// 根据查询结果删除报告
	int iResult = DeleteVPReport(sQuerySQL);
	ShowLog("SyncServer", "已成功删除报告文件【" + IntToStr(iResult) + "】个！");
}

//---------------------------------------------------------------------------

void ExecFilmDelete()
{
	// 胶片保留天数
	int iRemainDay = 5;
	
	// 指定要删除的胶片
	String sQuerySQL = "SELECT * FROM CC_FILMSESSION";
	sQuerySQL = AddWhereCondition(sQuerySQL, "modality_type='" + _modalitytype + "'");
	sQuerySQL = AddWhereCondition(sQuerySQL, "filmsession_state = 1");
	if (IsConnetSQLServer(_opacsconnection))
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff(day, filmsession_dttm, GetDate()) > " + IntToStr(iRemainDay));
        sQuerySQL = AccessToSQL(sQuerySQL);
	}
	else
	{
		sQuerySQL = AddWhereCondition(sQuerySQL, "datediff('d', filmsession_dttm, Date()) > " + IntToStr(iRemainDay));
	}

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

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