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;
using System.Windows.Forms;

namespace PTMedicalInsurance.Business
{
    /// <summary>
    /// 模拟医保挂号流程
    /// </summary>
    class OPRegFakeProcess : AbstractProcess
    {
        public override CallResult Process(JObject joInput)
        {
            JObject jo2201Rtn = new JObject();
            Global.pat.mdtrtID = DateTime.Now.Ticks.ToString();
            //插入患者本次就诊用的参保信息
            if (hBus.insertPatCurInsuInfo(joInput["patInfo"].ToString(), out outParam) != 0)
            {
                if (DialogResult.Yes != MessageBox.Show(outParam, " 是否继续？ ", MessageBoxButtons.YesNo))
                {
                    return Error(-1, "插入患者本次就诊用的参保信息，请联系管理员！是否继续？");
                }
            }

            JObject jo2203Inpar = new JObject();
            JObject jo2203Inpar_plain = new JObject();
            jo2203Inpar.Add("mdtrtinfo", JObject.Parse(JsonHelper.getDestValue(joInput, "mdtrtinfo")));
            jo2203Inpar.Add("diseinfo", JArray.Parse(JsonHelper.getDestValue(joInput, "diseinfo")));

            jo2203Inpar["mdtrtinfo"]["mdtrt_id"] = Global.pat.mdtrtID;
            jo2203Inpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2203", jo2203Inpar));
            jo2203Inpar = JObject.Parse(JsonHelper.setCenterInpar("2203", jo2203Inpar));

            //门诊登记信息，插入云医保平台
            jo2201Rtn.Add("validflag", 1);
            jo2201Rtn.Add("regstate", 1);
            jo2201Rtn.Add("type", 3);

            JObject jo2201Inpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2201", JsonHelper.getDestProperty(joInput,"data")));

            if (mIS.saveOutpatRegisterInfo(jo2201Inpar_plain, jo2201Rtn, jo2203Inpar_plain, out outParam) != 0)
            {
                return Error(-1, "中心登记成功但医保平台保存失败，请联系管理员！");
            }
            // 返回病人信息
            outParam = joInput.ToString();
            return Success();
        }
    }
}
