using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Helper;
using PTMedicalInsurance.Variables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PTMedicalInsurance.Business
{
    class IPQuerySettlementProcess : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {
            //查询结算表
            string sqlStr = "SELECT * FROM  BS_MedInsuSettlement WHERE billType = 1 and Hospital_Dr=" + Global.inf.hospitalDr
                          + " and Adm_Dr='" + Global.pat.adm_Dr + "'"
                          + " and MdtrtID='" + Global.pat.mdtrtID + "'"
                          + " Order By ID DESC ";

            JObject joSql = new JObject();
            joSql.Add("sqlStr", sqlStr);
            JObject joSettlInfo = mIS.QuerySettlementInfo(joSql);
            //if (JsonHelper.parseIrisRtnValue(joSettlInfo, out errMsg) != 0)
            //{
            //    rtnResult = JsonHelper.setExceptionJson(-1, "查询结算信息失败！", errMsg).ToString();
            //    return rtnResult;
            //}

            //MessageBox.Show(joSettlInfo.ToString());

            Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joSettlInfo, "result.data[0].insuplc_admdvs");

            Global.pat.SettID_YBJSB = JsonHelper.getDestValue(joSettlInfo, "result.data[0].SettlementID");

            //if (Global.pat.settlID != Global.pat.SettID_YBJSB)
            //{
            //    rtnResult = JsonHelper.setExceptionJson(-1, "Settlement 交易", "通过09010059服务获取到的SettlementID<" + Global.pat.settlID + ">与DLL通过SQL语句" +
            //joSql + ",获取到的SettlementID<" + Global.pat.SettID_YBJSB + ">不同,可能存在HIS单边账,请联系医保开发人员处理该笔结算记录！").ToString();
            //return rtnResult;
            //}
            if (!string.IsNullOrEmpty(Global.pat.SettID_YBJSB))
            {
                Global.pat.settlID = Global.pat.SettID_YBJSB;
            }

            return Success();
        }
    }
}
