using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Common;
using PTMedicalInsurance.Entity;
using PTMedicalInsurance.Forms;
using PTMedicalInsurance.Helper;
using PTMedicalInsurance.Variables;

namespace PTMedicalInsurance.Business
{
    class STA
    {
        //设置业务实例
        CenterBusiness cBus = new CenterBusiness();
        HisMainBusiness hBus = new HisMainBusiness();
        HisIrisServices hIS = new HisIrisServices();
        MIIrisServices mIS = new MIIrisServices();
        InvokeHelper invoker = new InvokeHelper();
        private XmlHelper xmler = new XmlHelper();

        public delegate void callBack(string errMsg);

        [STAThread]
        public void ReadCard(object o)
        {

            string outParam = "";
            ChooseCard cc = new ChooseCard();
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                if (cc.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    Global.pat.card.ecBizType = cc.businessType;
                }
                else
                {
                    ((object[])o)[0] = -1;
                    ((object[])o)[1] = "收款员取消结算！";
                }
                InvokeComCenter carder = new InvokeComCenter();
                JObject joInput = new JObject();
                joInput.Add("akb020", "H65010200152");
                joInput.Add("psnNo", "111111");
                string input = joInput.ToString();
                if (carder.Business("1401", ref input, ref outParam) != 0)
                {
                    ((object[])o)[0] = -1;
                    ((object[])o)[1] = outParam;
                }
                else
                {
                    Resp1101 info = JsonHelper.getOutput<Resp1101>(JObject.Parse(outParam));
                    Global.pat.card.NO = info.data.cardNo;
                    Global.pat.card.SN = info.data.cardSn;
                    Global.pat.mdtrtcertType = info.data.mdtrtCertType;
                    Global.pat.mdtrtcertNO = info.data.mdtrtCertNo;
                    Global.pat.certNO = info.data.certNo;
                    Global.pat.certType = info.data.psnCertType;
                    Global.pat.name = info.data.psnName;
                    Global.pat.insuplc_admdvs = info.data.insuplcAdmdvs;

                    ((object[])o)[0] = 0;
                    ((object[])o)[1] = outParam;
                }
            }
            catch (Exception ex)
            {
                outParam = JsonHelper.setIrisReturnValue(-1, "门诊结算异常：" + ex.Message, null).ToString();
                ((object[])o)[0] = -1;
                ((object[])o)[1] = outParam;
            }
        }

        public void CallBack(string errMsg)
        {
            MessageBox.Show(errMsg);
        }

        [STAThread]
        public void showPatInfo(object o)
        {

            string outParam = "";
            JObject joOutparam = JObject.Parse(((object[])o)[1].ToString());
            JObject joOutput = JObject.Parse(JsonHelper.getDestValue(joOutparam, "output"));

            //编码转换
            JArray jaConvertCode = new JArray();
            JObject joConvertCodeParam = new JObject();
            joConvertCodeParam.Add("hospitalDr", Global.inf.hospitalDr);
            joConvertCodeParam.Add("interfaceDr", Global.inf.interfaceDr);
            joConvertCodeParam.Add("output", joOutput);
            jaConvertCode.Add(joConvertCodeParam);
            JObject joConvertCode = new JObject();
            joConvertCode.Add("code", "09010054");
            joConvertCode.Add("params", jaConvertCode);

            InvokeHelper invoker = new InvokeHelper();
            JObject joConvertCodeRtn = invoker.invokeInsuService(joConvertCode.ToString(), "患者信息编码转换");

            PatientInsuInfo frmPatientInfo = new PatientInsuInfo(joConvertCodeRtn);
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                frmPatientInfo.StartPosition = FormStartPosition.CenterScreen;
                frmPatientInfo.BringToFront();
                if (frmPatientInfo.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    //原来用的是转换后的
                    //frmPatientInfo.joSelectedInsuInfo.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
                    //frmPatientInfo.joSelectedInsuInfo.Add("mdtrt_cert_no", Global.pat.mdtrtcertNO);
                    //joOutparam.Property("output").AddBeforeSelf(new JProperty("selectedInsuInfo", frmPatientInfo.joSelectedInsuInfo));

                    //现在用转换之前的
                    JArray jaInsuInfo = JArray.Parse(JsonHelper.getDestValue(joOutput, "insuinfo"));
                    JArray jaIdInfo = JArray.Parse(JsonHelper.getDestValue(joOutput, "idetinfo"));
                    JObject joSelectedInsuInfo = (JObject)jaInsuInfo[frmPatientInfo.insuInfoIndex];
                    JObject joSelectedIdInfo;
                    if (jaIdInfo.Count != 0)
                    {
                        joSelectedIdInfo = (JObject)jaIdInfo[frmPatientInfo.idInfoIndex];
                    }
                    else
                    {
                        joSelectedIdInfo = new JObject();
                    }
                    joSelectedInsuInfo.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
                    joSelectedInsuInfo.Add("mdtrt_cert_no", Global.pat.mdtrtcertNO);
                    if (joOutparam["selectedInsuInfo"] != null)
                    {
                        joOutparam["selectedInsuInfo"] = joSelectedInsuInfo;
                    }
                    else
                    {
                        joOutparam.Property("output").AddBeforeSelf(new JProperty("selectedInsuInfo", joSelectedInsuInfo));
                    }

                    if (joOutparam["selectedIdInfo"] != null)
                    {
                        joOutparam["selectedIdInfo"] = joSelectedInsuInfo;
                    }
                    else
                    {
                        joOutparam.Property("output").AddBeforeSelf(new JProperty("selectedIdInfo", joSelectedInsuInfo));
                    }


                    outParam = joOutparam.ToString();
                    ((object[])o)[0] = 0;
                    ((object[])o)[2] = outParam;
                }
                else
                {
                    ((object[])o)[0] = -1;
                    ((object[])o)[2] = "收款员取消结算！";
                }
            }
            catch (Exception ex)
            {
                outParam = JsonHelper.setIrisReturnValue(-1, "门诊结算异常：" + ex.Message, null).ToString();
                ((object[])o)[0] = -1;
                ((object[])o)[2] = outParam;
            }
        }

        [STAThread]
        public void showOutPatRegisterForm(object o)
        {

            string outParam = "";
            //调用服务获取门诊诊断信息
            string diagnoses;
            if (hIS.getPatDiagnoses(Global.pat, out diagnoses) != 0)
            {
                ((object[])o)[0] = -1;
                ((object[])o)[1] = JsonHelper.setExceptionJson(-1, "getPatDiagnoses", diagnoses).ToString(); 
                return ;
            }
            JObject joHisRtnInfo = JObject.Parse(diagnoses);

            JObject joReg = new JObject();
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                JArray jaDiagnoses = JArray.Parse(JsonHelper.getDestValue(joHisRtnInfo, "diseinfo"));
                //登记面板实例
                OutpatientRegistration frmReg = new OutpatientRegistration();
                //frmReg.dblkcbxSettelmentWay.Enabled = false;

                //险种类型
                DataTable dtInsuType = (DataTable)frmReg.dblkcbxInsuranceType.DataSource;
                for (int i = 0; i < dtInsuType.Rows.Count; i++)
                {
                    if (dtInsuType.Rows[i]["Code"].ToString() == Global.pat.insuType)
                    {
                        frmReg.dblkcbxInsuranceType.Text = dtInsuType.Rows[i]["Name"].ToString();
                        frmReg.insuType = dtInsuType.Rows[i]["Code"].ToString();

                        if (Global.pat.isWorkInjury)
                        {
                            frmReg.dblkcbxInsuranceType.Text = "工伤保险";
                        }

                    }
                }

                //医疗类别
                DataTable dtMedType = (DataTable)frmReg.dblkcbxMedicalType.DataSource;
                for (int i = 0; i < dtMedType.Rows.Count; i++)
                {
                    if (dtMedType.Rows[i]["Code"].ToString() == "11")
                    {
                        frmReg.dblkcbxMedicalType.Text = dtMedType.Rows[i]["Name"].ToString();
                        frmReg.med_type = dtMedType.Rows[i]["Code"].ToString();
                    }
                }

                //结算方式
                DataTable dtSettlWay = (DataTable)frmReg.dblkcbxSettelmentWay.DataSource;
                for (int i = 0; i < dtSettlWay.Rows.Count; i++)
                {
                    if (dtSettlWay.Rows[i]["Code"].ToString() == "01")
                    {
                        frmReg.dblkcbxSettelmentWay.Text = dtSettlWay.Rows[i]["Name"].ToString();
                        frmReg.psn_setlway = dtSettlWay.Rows[i]["Code"].ToString();
                    }
                }

                //转换下主要诊断
                for (int i = 0; i < jaDiagnoses.Count; i++)
                {
                    string diag_type = JsonHelper.getDestValue((JObject)jaDiagnoses[i], "diag_type");
                    switch (diag_type)
                    {
                        case "1":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "西医主要诊断";
                                break;
                            }
                        case "2":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "西医其他诊断";
                                break;
                            }
                        case "3":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "中医主病诊断";
                                break;
                            }
                        case "4":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "中医主证诊断";
                                break;
                            }
                    }

                }
                frmReg.DtDiagnose = (DataTable)jaDiagnoses.ToObject(typeof(DataTable));
                //展示登记面板
                if (frmReg.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    string diseCodg = frmReg.diseCodg, diseName = frmReg.diseName;
                    //哈尔滨要求必须传病种。普通疾病传主诊断
                    if (string.IsNullOrEmpty(diseCodg))
                    {
                        diseCodg = JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.dscg_maindiag_code");
                    };
                    Global.pat.disCode = diseCodg;
                    if (string.IsNullOrEmpty(diseName))
                    {
                        diseName = JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.dscg_maindiag_name");
                    };
                    //组织挂号入参
                    JObject joRegInpar = new JObject();
                    string occurTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    joRegInpar.Add("psn_no", Global.pat.psn_no);
                    joRegInpar.Add("insutype", frmReg.insuType);
                    joRegInpar.Add("begntime", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.begntime"));//挂号时间 occurTime
                    joRegInpar.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
                    joRegInpar.Add("mdtrt_cert_no", Global.pat.mdtrtcertNO);

                    string admDr = Utils.convertAdmDr(Global.pat.adm_Dr.ToString());
                    joRegInpar.Add("ipt_otp_no", admDr);

                    joRegInpar.Add("atddr_no", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.atddr_no"));
                    joRegInpar.Add("dr_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.chfpdr_name"));
                    joRegInpar.Add("dept_code", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_dept_codg"));
                    joRegInpar.Add("dept_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_dept_name"));
                    joRegInpar.Add("exp_content", "");
                    joRegInpar.Add("caty", "72");
                    joReg.Add("data", joRegInpar);

                    //组织就诊信息入参
                    JObject joMdtrtinfo = new JObject();
                    for (int i = 0; i < jaDiagnoses.Count; i++)
                    {
                        jaDiagnoses[i]["vali_flag"] = new JObject();
                        jaDiagnoses[i]["vali_flag"] = "1";
                    }
                    joMdtrtinfo.Add("mdtrt_id", Global.pat.mdtrtID);
                    joMdtrtinfo.Add("psn_no", Global.pat.psn_no);          //人员编号
                    Global.pat.medType = frmReg.med_type;
                    joMdtrtinfo.Add("med_type", frmReg.med_type);          //医疗类别
                    joMdtrtinfo.Add("begntime", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.begntime"));          //开始时间
                    joMdtrtinfo.Add("main_cond_dscr", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.main_cond_dscr"));          //主要病情描述
                    joMdtrtinfo.Add("dise_codg", diseCodg);          //病种编码
                    joMdtrtinfo.Add("dise_name", diseName);          //病种名称
                    joMdtrtinfo.Add("birctrl_type", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.birctrl_type"));          //计划生育手术类别
                    //joMdtrtinfo.Add("birctrl_matn_date", "");          //计划生育手术或生育日期 JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.birctrl_matn_date") 20230228医保中心校验传正确时间或空
                    joMdtrtinfo.Add("matn_type", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.matn_type"));          //生育类别
                    //joMdtrtinfo.Add("geso_val", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.geso_val"));          //孕周数
                    joMdtrtinfo.Add("exp_content", "");          //字段扩展

                    //组织结算入参
                    JObject joSetlInpar = new JObject();
                    joSetlInpar.Add("psn_no", Global.pat.psn_no);
                    joSetlInpar.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);
                    joSetlInpar.Add("mdtrt_cert_no", Global.pat.mdtrtcertNO);
                    joSetlInpar.Add("med_type", Global.pat.medType);
                    joSetlInpar.Add("medfee_sumamt", "");
                    joSetlInpar.Add("psn_setlway", frmReg.psn_setlway); //结算方式
                    joSetlInpar.Add("mdtrt_id", Global.pat.mdtrtID);
                    joSetlInpar.Add("chrg_bchno", Global.pat.adm_Dr.ToString());
                    joSetlInpar.Add("acct_used_flag", frmReg.personAccountUsedFlag);//个人账户使用标志
                    joSetlInpar.Add("insutype", frmReg.insuType);//险种类型
                    joSetlInpar.Add("pub_hosp_rfom_flag", "");
                    joSetlInpar.Add("exp_content11", "");

                    joReg.Add("mdtrtinfo", joMdtrtinfo);
                    joReg.Add("diseinfo", jaDiagnoses);
                    joReg.Add("settlement", joSetlInpar);

                    ((object[])o)[0] =0;
                    ((object[])o)[1] = joReg.ToString();
                    return;
                }
                else
                {
                    ((object[])o)[0] = -1;
                    ((object[])o)[1] = "收费员取消操作！";
                    return;
                }
            }
            catch (Exception ex)
            {
                ((object[])o)[0] = -1;
                ((object[])o)[1] = "登记界面显示异常：" + ex.Message;
                return;
            }
        }

        [STAThread]
        public void showInPatRegisterForm(object o)
        {

            //调用服务获取门诊诊断信息
            string diagnoses;
            if (hIS.getPatDiagnoses(Global.pat, out diagnoses) != 0)
            {
                ((object[])o)[0] = -1;
                ((object[])o)[1] = JsonHelper.setExceptionJson(-1, "getPatDiagnoses", diagnoses).ToString();
                return;
            }
            JObject joHisRtnInfo = JObject.Parse(diagnoses);

            JObject joReg = new JObject();
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                JArray jaDiagnoses = JArray.Parse(JsonHelper.getDestValue(joHisRtnInfo, "diseinfo"));
                string dscg_maindiag_code = "", dscg_maindiag_name = "";
                //  对诊断数组进行转换 转换下主要诊断
                JArray jaConvertedDiagnoses = new JArray();
                JArray jaInPatDiagnoses = new JArray();
                JArray jaOutPatDiagnoses = new JArray();
                for (int i = 0; i < jaDiagnoses.Count; i++)
                {

                    string diag_type = JsonHelper.getDestValue((JObject)jaDiagnoses[i], "diag_type");
                    switch (diag_type)
                    {
                        case "1":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "西医主要诊断";
                                break;
                            }
                        case "2":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "西医其他诊断";
                                break;
                            }
                        case "3":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "中医主病诊断";
                                break;
                            }
                        case "4":
                            {
                                jaDiagnoses[i]["diag_type_name"] = new JObject();
                                jaDiagnoses[i]["diag_type_name"] = "中医主证诊断";
                                break;
                            }
                    }


                    if (jaDiagnoses[i]["diaTypeCode"].ToString() == "ADD") //ADD 入院 OPD 门诊
                    {
                        jaInPatDiagnoses.Add(jaDiagnoses[i]);
                    }
                    if (jaDiagnoses[i]["diaTypeCode"].ToString() == "OPD") //ADD 入院 OPD 门诊
                    {
                        jaOutPatDiagnoses.Add(jaDiagnoses[i]);
                    }
                }

                if (jaInPatDiagnoses.Count > 0)
                {
                    jaConvertedDiagnoses = (JArray)jaInPatDiagnoses.DeepClone();
                }
                else
                {
                    jaConvertedDiagnoses = (JArray)jaOutPatDiagnoses.DeepClone();
                }

                for (int i = 0; i < jaConvertedDiagnoses.Count; i++)
                {
                    jaConvertedDiagnoses[i]["diag_srt_no"] = i + 1;
                    if (jaConvertedDiagnoses[i]["maindiag_flag"].ToString() == "1")
                    {
                        dscg_maindiag_code = jaConvertedDiagnoses[i]["diag_code"].ToString();
                        dscg_maindiag_name = jaConvertedDiagnoses[i]["diag_name"].ToString();
                    }
                }


                //登记面板实例
                OutpatientRegistration frmReg = new OutpatientRegistration();
                //frmReg.dblkcbxSettelmentWay.Enabled = false;
                DataTable dt = (DataTable)frmReg.dblkcbxInsuranceType.DataSource;
                int selectedIndex = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["Code"].ToString() == Global.pat.insuType)
                    {
                        selectedIndex = i;
                        frmReg.dblkcbxInsuranceType.Text = dt.Rows[i]["Name"].ToString();
                        frmReg.insuType = dt.Rows[i]["Code"].ToString();
                    }
                }

                DataTable dtMedType = (DataTable)frmReg.dblkcbxMedicalType.DataSource;
                for (int i = 0; i < dtMedType.Rows.Count; i++)
                {
                    if (dtMedType.Rows[i]["Code"].ToString() == "21")
                    {
                        frmReg.dblkcbxMedicalType.Text = dtMedType.Rows[i]["Name"].ToString();
                        frmReg.med_type = dtMedType.Rows[i]["Code"].ToString();
                    }
                }
                frmReg.DtDiagnose = (DataTable)jaConvertedDiagnoses.ToObject(typeof(DataTable));
                //展示登记面板
                if (frmReg.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    string diseCodg = "", diseName = "";

                    diseCodg = frmReg.diseCodg;
                    diseName = frmReg.diseName;

                    JObject joMdtrtinfo = new JObject();
                    joMdtrtinfo.Add("psn_no", Global.pat.psn_no);          //人员编号
                    joMdtrtinfo.Add("insutype", Global.pat.insuType);          //险种类型
                    joMdtrtinfo.Add("coner_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.coner_name"));          //联系人姓名
                    joMdtrtinfo.Add("tel", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.tel"));          //联系电话
                    joMdtrtinfo.Add("begntime", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.begntime"));          //开始时间
                    joMdtrtinfo.Add("mdtrt_cert_type", Global.pat.mdtrtcertType);          //就诊凭证类型
                    joMdtrtinfo.Add("mdtrt_cert_no", Global.pat.mdtrtcertNO);          //就诊凭证编号
                    joMdtrtinfo.Add("med_type", frmReg.med_type);          //医疗类别

                    //string ipAdmNo = Utils.convertAdmDr(JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.ipt_no"));

                    joMdtrtinfo.Add("ipt_no", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.ipt_no"));          //住院号
                    joMdtrtinfo.Add("medrcdno", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.medrcdno"));          //病历号
                    joMdtrtinfo.Add("atddr_no", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.atddr_no"));          //主治医生编码
                    joMdtrtinfo.Add("chfpdr_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.chfpdr_name"));          //主诊医师姓名
                    //joMdtrtinfo.Add("adm_diag_dscr", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_diag_dscr"));          //入院诊断描述
                    joMdtrtinfo.Add("adm_diag_dscr", "");
                    joMdtrtinfo.Add("adm_dept_codg", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_dept_codg"));          //入院科室编码
                    joMdtrtinfo.Add("adm_dept_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_dept_name"));          //入院科室名称
                    joMdtrtinfo.Add("adm_bed", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.adm_bed"));          //入院床位
                    joMdtrtinfo.Add("dscg_maindiag_code", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.dscg_maindiag_code"));          //住院主诊断代码
                    joMdtrtinfo.Add("dscg_maindiag_name", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.dscg_maindiag_name"));          //住院主诊断名称
                    //joMdtrtinfo.Add("dscg_maindiag_code", dscg_maindiag_code);          //住院主诊断代码
                    //joMdtrtinfo.Add("dscg_maindiag_name", dscg_maindiag_name);          //住院主诊断名称
                    joMdtrtinfo.Add("main_cond_dscr", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.main_cond_dscr"));          //主要病情描述
                    joMdtrtinfo.Add("dise_codg", diseCodg);          //病种编码
                    joMdtrtinfo.Add("dise_name", diseName);          //病种名称
                    joMdtrtinfo.Add("oprn_oprt_code", frmReg.oprn_oprt_code);          //手术操作代码
                    joMdtrtinfo.Add("oprn_oprt_name", frmReg.oprn_oprt_name);          //手术操作名称
                    joMdtrtinfo.Add("fpsc_no", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.fpsc_no"));          //计划生育服务证号
                    joMdtrtinfo.Add("matn_type", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.matn_type"));          //生育类别
                    joMdtrtinfo.Add("birctrl_type", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.birctrl_type"));          //计划生育手术类别
                    joMdtrtinfo.Add("latechb_flag", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.latechb_flag"));          //晚育标志
                    //joMdtrtinfo.Add("geso_val", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.geso_val"));          //孕周数
                    //joMdtrtinfo.Add("fetts", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.fetts"));          //胎次
                    //joMdtrtinfo.Add("fetus_cnt", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.fetus_cnt"));          //胎儿数
                    //joMdtrtinfo.Add("pret_flag", JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.pret_flag"));          //早产标志
                    //joMdtrtinfo.Add("birctrl_matn_date", "");          //计划生育手术或生育日期 JsonHelper.getDestValue(joHisRtnInfo, "mdtrtinfo.birctrl_matn_date") 20230228医保中心校验传正确时间或空
                    joMdtrtinfo.Add("dise_type_code", frmReg.dise_type_code);          //病种类型
                    joMdtrtinfo.Add("insuplc_admdvs", Global.pat.insuplc_admdvs);          //参保地医保区划
                    joMdtrtinfo.Add("mdtrtarea_admvs", Global.inf.areaCode);          //就医地医保区划

                    joReg.Add("mdtrtinfo", joMdtrtinfo);
                    joReg.Add("diseinfo", jaConvertedDiagnoses);


                    Global.pat.disCode = diseCodg;
                    Global.pat.disName = diseName;
                    Global.pat.medType = frmReg.med_type;

                    if (Global.pat.isWorkInjury)
                    {
                        Global.pat.ExpContent = "GGS";
                    }

                    ((object[])o)[0] = 0;
                    ((object[])o)[1] = joReg.ToString();
                    return;
                }
                else
                {
                    ((object[])o)[0] = -1;
                    ((object[])o)[1] = "收费员取消操作！";
                    return;
                }
            }
            catch (Exception ex)
            {
                ((object[])o)[0] = -1;
                ((object[])o)[1] = "登记界面显示异常：" + ex.Message;
                return;
            }
        }

        [STAThread]
        public void uploadFee(object o)
        {
            string outParam = "";
            object[] oArr = (object[])o;
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                
                string funNO = oArr[1].ToString();
                int singleCount = int.Parse(oArr[2].ToString());
                PTMedicalInsurance.Forms.FeeUpload pb = new PTMedicalInsurance.Forms.FeeUpload(funNO, singleCount);
                pb.StartPosition = FormStartPosition.CenterScreen;
                if (pb.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    ((object[])o)[0] = 0;
                    ((object[])o)[3] = pb.outParam;

                }
                else
                {
                    outParam = "收款员取消";
                    ((object[])o)[0] = -1;
                    ((object[])o)[3] = outParam;
                }
            }
            catch (Exception ex)
            {
                outParam = "uploadFee 异常：" + ex.Message;
                ((object[])o)[0] = -1;
                ((object[])o)[3] = outParam;
                o = oArr;
                return;
            }
        }
        [STAThread]
        public void showSettlementForm(object o)
        {
            string outParam = "";
            JObject joSettlement = JObject.Parse(((object[])o)[1].ToString());
            try
            {
                IntPtr hwnd = WinApi.GetWindowsHandle("prBrowser");
                SettlementInfo frmSettlment = new SettlementInfo(joSettlement);
                //相关信息转换到结算信息面板
                if (frmSettlment.ShowDialog(new WindowWrapper(hwnd)) == DialogResult.OK)
                {
                    ((object[])o)[0] = 0;
                    ((object[])o)[1] = outParam;
                }
                else
                {
                    outParam = "收款员取消";
                    ((object[])o)[0] = -1;
                    ((object[])o)[1] = outParam;
                }
            }
            catch (Exception ex)
            {
                outParam = "showSettlementForm 异常：" + ex.Message;
                ((object[])o)[0] = -1;
                ((object[])o)[1] = outParam;
            }
        }
        [STAThread]
        public void Exception(object o)
        {
            try
            {
                //显示异常处理界面
                HandleException frmEX = new HandleException();
                frmEX.WindowState = FormWindowState.Maximized;
                frmEX.ShowDialog();

            }
            catch (Exception ex)
            {
                CallBack(ex.Message);
            }

        }

        [STAThread]
        public void CheckAndClearing(object o)
        {
            try
            {
                //显示对账界面
                Clearing frm = new Clearing();
                frm.WindowState = FormWindowState.Maximized;
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                CallBack(ex.Message);
            }

        }

        [STAThread]
        public void PrescribeCirculation(object o)
        {
            try
            {
                //显示处方上传
                PrescriptionCirculation PresCir = new PrescriptionCirculation("");
                //PresCir.WindowState = FormWindowState.Minimized;                            
                PresCir.ShowDialog();
            }
            catch (Exception ex)
            {
                CallBack(ex.Message);
            }

        }

        [STAThread]
        public void BasicData(object o)
        {
            try
            {
                //显示异常处理界面
                BasicData frm = new BasicData();
                frm.WindowState = FormWindowState.Maximized;
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                CallBack(ex.Message);
            }
        }
    }


    public class WindowWrapper : System.Windows.Forms.IWin32Window
    {
        public WindowWrapper(IntPtr handle)
        {
            _hwnd = handle;
        }

        public IntPtr Handle
        {
            get { return _hwnd; }
        }

        private IntPtr _hwnd;
    }
}
