//---------------------------------------------------------------------------
// String _opacsconnection; 约定的输入变量名
// String _hisconnection; 	约定的输入变量名 
// String _modalitytype; 	约定的输入变量名
// String _requestid; 		约定的输入变量名
// String _patientname; 	约定的输入变量名
// String _examclass; 		约定的输入变量名
// String _examsubclass; 	约定的输入变量名
// TDateTime _startdate; 	约定的输入变量名
// TDateTime _enddate; 	    约定的输入变量名
// TADOQuery _qryStudy		外部已定义的对象
// TADOQuery _qryCustom		外部已定义的对象
// TADOQuery _qryHisStudy   外部已定义的对象
// TADOQuery _qryHisCustom  外部已定义的对象
// TADOQuery _qryHisCommon  外部已定义的对象
//
// 脚本必须实现的函数 int _QueryHisTable();
// 脚本必须实现的函数 int _ConfirmHisLogin(); 	
// 脚本必须实现的函数 int _CancelHisLogin(); 
// 脚本必须实现的函数 int _PatientValidate(); 
//---------------------------------------------------------------------------

#include "..\\Common\\HisCommon.cpp"

String      _opacsconnection;
String      _hisconnection;
String 		_modalitytype;
String      _requestid;
String      _patientname;
String      _examclass;
String      _examsubclass;
TDateTime   _startdate;
TDateTime   _enddate;

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

int ExecSQL()
{
    int iFieldCount = 0;
    string sFieldPairs[2][100];
    SetArrayItem(sFieldPairs, iFieldCount, "patient_name", 		"hzxm");
    SetArrayItem(sFieldPairs, iFieldCount, "patient_address", 	"lxdz");
    SetArrayItem(sFieldPairs, iFieldCount, "patient_telephone", "lxdh");
    SetArrayItem(sFieldPairs, iFieldCount, "patient_guid", 		"blh");
    SetArrayItem(sFieldPairs, iFieldCount, "study_userdef1", 	"fpxmmc");
    SetArrayItem(sFieldPairs, iFieldCount, "study_charge", 		"xmje");
    SetArrayItem(sFieldPairs, iFieldCount, "study_exammethod", 	"dxmmc");
	SetArrayItem(sFieldPairs, iFieldCount, "study_number1",		"fph");
    ////
    string sHisQuery = "select top 100 a.fph as card_number, a.fph, b.hzxm,  b.blh, b.lxdh, b.lxdz,c.xmje,c.fpxmmc, c.dxmmc from SF_BRJSK as a,SF_BRXXK as b,SF_BRJSMXK as c where a.hzxm=b.hzxm and a.sjh=c.jssjh and c.dxmdm='04'";
    ////
    if (_requestid != "")
        sHisQuery = AddWhereCondition(sHisQuery, "fph = '" + _requestid + "'");	// 将XXX替换为对应字段
    if (_patientname != "")
        sHisQuery = AddWhereCondition(sHisQuery, "hzxm = '" + _patientname + "'");
/*
    if (_examclass != "")
        sHisQuery = AddWhereCondition(sHisQuery, );
    if (_examsubclass != "")
        sHisQuery = AddWhereCondition(sHisQuery, );
    if (_startdate != "")
        sHisQuery = AddWhereCondition(sHisQuery, );
    if (_enddate != "")
        sHisQuery = AddWhereCondition(sHisQuery, );
*/
	////
    _qryHisCustom.Close();
    _qryHisCustom.SQL.Text = sHisQuery;
    try
    {
    	_qryHisCustom.Open();  
    }
    except
    {
    	ShowMessage("查询失败！请检查输入条件！");
    	return 0;
	}
    ////
   if (!_qryHisCustom.IsEmpty())
    {
        _qryHisCustom.First();
        while (!_qryHisCustom.Eof)
        {
            _qryHisStudy.Append();
            for (int i = 0; i < iFieldCount; i++)
            {
                if (!_qryHisCustom.FieldByName(sFieldPairs[1][i]).IsNull)
                {
					_qryHisStudy.FieldByName(sFieldPairs[0][i]).Value =
						_qryHisCustom.FieldByName(sFieldPairs[1][i]).Value;
                }
            }
            _qryHisStudy.Post();
            _qryHisCustom.Next();
        }
    }

    return 1;
}
//---------------------------------------------------------------------------

int _QueryHisTable()
{
    // 查询脚本
    return ExecSQL();
}
//---------------------------------------------------------------------------

int _ConfirmHisLogin()
{
    // 登记检查
    return 0;
}
//---------------------------------------------------------------------------

int _CancelHisLogin()
{
    // 撤销登记
    return 0;
}
//---------------------------------------------------------------------------

int _PatientValidate()
{
	return 0;
}
//---------------------------------------------------------------------------

// 主程序
{
    // Nothing need to do.
}
//---------------------------------------------------------------------------
