using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Business;
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.ReadCard
{
    class SetGlobalVariablesAfaterShowPatInfo : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {
            JObject joPatInfo;
            try
            {
                joPatInfo = input;

                //基本信息
                Global.pat.certNO = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.certno");
                Global.pat.psn_no = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.psn_no");
                Global.pat.gend = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.gend");
                Global.pat.brdy = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.brdy");
                Global.pat.naty = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.naty");
                Global.pat.age = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.age");
                Global.pat.certType = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.psn_cert_type");

                //if (Global.pat.name != JsonHelper.getDestValue(joPatInfo, "output.baseinfo.psn_name"))
                //{
                //    errMsg = "患者姓名(" + Global.pat.name + ")与参保人姓名(" + JsonHelper.getDestValue(joPatInfo, "output.baseinfo.psn_name") + ")不一致，请检查！";
                //    return -1;
                //}

                Global.pat.name = JsonHelper.getDestValue(joPatInfo, "output.baseinfo.psn_name");
                //选中的参保信息
                Global.pat.insuplc_admdvs = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.insuplc_admdvs");
                Global.pat.psn_insu_date = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.psn_insu_date");
                Global.pat.cvlserv_flag = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.cvlserv_flag");
                Global.pat.balc = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.balc");
                Global.pat.emp_name = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.emp_name");
                Global.pat.psn_type = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.psn_type");
                Global.pat.psn_insu_stas = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.psn_insu_stas");
                Global.pat.insuType = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.insutype");
                Global.pat.paus_insu_date = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.paus_insu_date");

                outParam = input.ToString();
                //卡片信息
                //Global.pat.cardSN = JsonHelper.getDestValue(joPatInfo, "selectedInsuInfo.paus_insu_date");
                //选中的身份信息
                return Success();
            }
            catch (Exception ex)
            {
                outParam = "获取患者信息发生异常：" + ex.Message;
                return Exception(-1,"",outParam);
            }
        }
    }
}
