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.Core.SelfServiceMachine.Process.InPat
{
    class PreSettlement : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {
            JObject jo2303Inpar = JObject.Parse(JsonHelper.getDestValue(input, "Settlement"));

            //预结算 
            JObject jo2303Data = new JObject();
            jo2303Data.Add("data", jo2303Inpar);
            JObject jo2303Rtn = invoker.invokeCenterService("2303", JsonHelper.setCenterInpar("2303", jo2303Data));
            if (JsonHelper.parseCenterRtnValue(jo2303Rtn, out outParam) != 0)
            {
                outParam = JsonHelper.setExceptionJson(-1, "出院预结算", outParam).ToString();
                return Exception();
            }

            //预结算结果传给HIS进行HIS判断 

            //返回给HIS
            JObject joSetlinfo = JObject.Parse(JsonHelper.getDestValue(jo2303Rtn, "output.setlinfo"));
            JObject joParam = new JObject();
            joParam.Add("admID", Global.pat.adm_Dr);
            joParam.Add("recordID", Global.pat.recordID);
            joParam.Add("billID", Global.pat.billID);

            if (hIS.preSettlementInfo(joParam, joSetlinfo, out outParam) != 0)
            {
                outParam = JsonHelper.setExceptionJson(-1, "出院预结算", outParam).ToString();
                return Exception();
            }

            outParam = input.ToString();
            return Success();

        }
    }
}
