//---------------------------------------------------------------------------
// String _hisconnection;  	  约定的输入变量名
// String _opacsconnection;   约定的输入变量名
// String _modalitytype; 	  约定的输入变量名
// TADOQuery _qryHisCommon    外部已定义的对象
// TADOQuery _qryHisCustom    外部已定义的对象
// TADOQuery _qryFilmSession  外部已定义的对象
// TADOQuery _qryCCReport  	  外部已定义的对象  
//---------------------------------------------------------------------------
#include "..\\Common\\HisCommon.cpp"

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

int _OcrFilmVerity()
{
	String sQuery = "select * from study where 0 > 1";
	_qryHisCustom.Close();
	_qryHisCustom.SQL.Text = sQuery;
	try
	{
		_qryHisCustom.Open();
	}
	except
	{
		ShowMessage("校验数据库打开失败！");
		return 0;
	}
	
	if (!_qryFilmSession.IsEmpty())
    {   	
        _qryFilmSession.First();
        while (!_qryFilmSession.Eof)
        {            
        	int iState = _qryFilmSession.FieldByName("filmsession_state").Value;
        	if (iState > 0) 	// 优化效率 大于未校验状态的不再进行校验
        		_qryFilmSession.Next();	
        	// 根据识别信息配置校验查询语句
        	String sVerityQuery = "select top 10 * from study ";
        	String sPatientName = _qryFilmSession.FieldByName("filmsession_patientname").AsString;
        	String sPatientID = _qryFilmSession.FieldByName("filmsession_patientid").AsString;
        	String sStudyID = _qryFilmSession.FieldByName("filmsession_studyid").AsString;
        	String sAccession = _qryFilmSession.FieldByName("filmsession_accessionnumber").AsString;  
        	if (Length(sPatientName) > 0)
        	{
        		if (Pos(" where ", sVerityQuery) == 0)
        			sVerityQuery = sVerityQuery + " where patient_name = '" + sPatientName + "' ";	
        		else
        			sVerityQuery = sVerityQuery + " or patient_name = '" + sPatientName + "' ";
        	}
        	if (Length(sPatientID) > 0)
        	{
        		if (Pos(" where ", sVerityQuery) == 0)
        			sVerityQuery = sVerityQuery + " where patient_guid = '" + sPatientID + "' ";	
        		else
        			sVerityQuery = sVerityQuery + " or patient_guid = '" + sPatientID + "' ";
        	}
        	if (Length(sStudyID) > 0)
        	{
        		if (Pos(" where ", sVerityQuery) == 0)
        			sVerityQuery = sVerityQuery + " where study_guid = '" + sStudyID + "' ";	
        		else
        			sVerityQuery = sVerityQuery + " or study_guid = '" + sStudyID + "' ";
        	}
        	if (Length(sAccession) > 0)
        	{
        		if (Pos(" where ", sVerityQuery) == 0)
        			sVerityQuery = sVerityQuery + " where study_ordinal = '" + sAccession + "' ";	
        		else
        			sVerityQuery = sVerityQuery + " or study_ordinal = '" + sAccession + "' ";
        	}
        	_qryHisCustom.Close();
		    _qryHisCustom.SQL.Text = sVerityQuery;
        	try
        	{
			    _qryHisCustom.Open();			    
        	}
			except
			{
				ShowMessage("校验数据库查询失败！");
				return 0;
			}
			
			if (GetRecordCount(_qryHisCustom) > 0)
			{
				// 查询到相应记录	0 未校验 1 已校验 2 已打印		
				_qryFilmSession.Edit();	
				_qryFilmSession.FieldByName("filmsession_state").Value = 1;		
				_qryFilmSession.Post();
			}
			else
			{
				// do nothing 
			}
			
            _qryFilmSession.Next();
        }
    }
}
//---------------------------------------------------------------------------


// 主程序
{
	// do nothing
}
//---------------------------------------------------------------------------
