Exemplo n.º 1
0
        public void pathtohis(string F_blh, string yymc)
        {
            string debug   = f.ReadString("savetohis", "debug", "");
            string odbcsql = ZgqClass.GetSz("ZGQJK", "odbcsql", "Data Source=192.168.6.43;Initial Catalog=nysy_pe;User Id=sa;Password=sa;");
            string yhmc    = f.ReadString("yh", "yhmc", "-").Replace("/0", "");

            string txpath = ZgqClass.GetSz("ZGQJK", "txpath", "");

            dbbase.odbcdb aa = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");

            DataTable bljc = new DataTable();

            try
            {
                bljc = aa.GetDataTable("select * from T_jcxx where F_blh='" + F_blh + "'", "jcxx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }

            if (bljc == null)
            {
                MessageBox.Show("病理数据库设置有问题!");
                return;
            }
            if (bljc.Rows.Count < 1)
            {
                MessageBox.Show("病理号有错误!");
                return;
            }

            if (bljc.Rows[0]["F_brlb"].ToString().Trim() != "体检")
            {
                log.WriteMyLog("非体检病人,不处理!");
                return;
            }
            if (bljc.Rows[0]["F_SQXH"].ToString().Trim() == "")
            {
                log.WriteMyLog("无体检申请单号,不处理!");
                return;
            }
            if (bljc.Rows[0]["F_BGZT"].ToString().Trim() == "已审核")
            {
                if (bljc.Rows[0]["F_TXML"].ToString().Trim() != "")
                {
                    DataTable txlb = new DataTable();
                    txlb = aa.GetDataTable("select * from T_tx where F_blh='" + F_blh + "' and F_sfdy='1'", "txlb");


                    if (txlb.Rows.Count > 0)
                    {
                        if (txpath.Trim() == "")
                        {
                            txpath = bljc.Rows[0]["F_TXML"].ToString().Trim() + "\\" + txlb.Rows[0]["F_txm"].ToString().Trim();
                        }
                        else
                        {
                            txpath = txpath + "\\" + bljc.Rows[0]["F_TXML"].ToString().Trim() + "\\" + txlb.Rows[0]["F_txm"].ToString().Trim();
                        }
                    }
                    else
                    {
                        txpath = "";
                    }
                }
                else
                {
                    txpath = "";
                }

                try
                {
                    DataTable TJ_bljc = new DataTable();
                    TJ_bljc = aa.GetDataTable(" select *  from T_TBS_BG where  F_blh='" + F_blh + "'", "blxx");


                    SqlParameter[] mzORAPAR = new SqlParameter[9];
                    for (int j = 0; j < mzORAPAR.Length; j++)
                    {
                        mzORAPAR[j] = new SqlParameter();
                    }
                    mzORAPAR[0].ParameterName = "@applyid";
                    mzORAPAR[0].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[0].Direction     = ParameterDirection.Input;
                    mzORAPAR[0].Size          = 50;

                    mzORAPAR[1].ParameterName = "@patientname";    //
                    mzORAPAR[1].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[1].Direction     = ParameterDirection.Input;
                    mzORAPAR[1].Size          = 50;

                    mzORAPAR[2].ParameterName = "@Diagnosis";    //
                    mzORAPAR[2].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[2].Direction     = ParameterDirection.Input;
                    mzORAPAR[2].Size          = 3000;

                    mzORAPAR[3].ParameterName = "@Feature";    //
                    mzORAPAR[3].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[3].Direction     = ParameterDirection.Input;
                    mzORAPAR[3].Size          = 1024;

                    mzORAPAR[4].ParameterName = "@reportdoctor";    //
                    mzORAPAR[4].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[4].Direction     = ParameterDirection.Input;
                    mzORAPAR[4].Size          = 50;

                    mzORAPAR[5].ParameterName = "@reporttime";    //
                    mzORAPAR[5].SqlDbType     = SqlDbType.DateTime;
                    mzORAPAR[5].Direction     = ParameterDirection.Input;

                    mzORAPAR[6].ParameterName = "@filepath";    //
                    mzORAPAR[6].SqlDbType     = SqlDbType.VarChar;;
                    mzORAPAR[6].Direction     = ParameterDirection.Input;
                    mzORAPAR[6].Size          = 100;

                    mzORAPAR[7].ParameterName = "@sex";    //
                    mzORAPAR[7].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[7].Direction     = ParameterDirection.Input;
                    mzORAPAR[7].Size          = 50;

                    mzORAPAR[8].ParameterName = "@age";    //
                    mzORAPAR[8].SqlDbType     = SqlDbType.VarChar;
                    mzORAPAR[8].Direction     = ParameterDirection.Input;
                    mzORAPAR[8].Size          = 50;

                    //////////////////////////////////////////////////////

                    string tj_blzd = bljc.Rows[0]["F_blzd"].ToString().Trim();
                    string tj_jcsj = bljc.Rows[0]["F_jxsj"].ToString().Trim();

                    if (TJ_bljc.Rows.Count > 0)
                    {
                        if (bljc.Rows[0]["F_BGGS"].ToString().Trim() == "TBS" || bljc.Rows[0]["F_blk"].ToString().Trim().Contains("TCT"))
                        {
                            tj_jcsj = "标本满意度:" + TJ_bljc.Rows[0]["F_TBS_BBMYD"].ToString().Trim() + "\r\n";
                            tj_jcsj = tj_jcsj + "           " + TJ_bljc.Rows[0]["f_tbs_xbl"].ToString().Trim() + "\r\n";
                            tj_jcsj = tj_jcsj + "           " + TJ_bljc.Rows[0]["F_tbs_xbxm1"].ToString().Trim() + "\r\n";
                            tj_jcsj = tj_jcsj + "           " + TJ_bljc.Rows[0]["F_tbs_xbxm2"].ToString().Trim() + "\r\n";
                            tj_jcsj = tj_jcsj + "           " + TJ_bljc.Rows[0]["F_tbs_xbxm3"].ToString().Trim() + "\r\n";

                            tj_jcsj = tj_jcsj + "炎症程度:" + TJ_bljc.Rows[0]["F_TBS_YZCD"].ToString().Trim() + "\r\n";

                            ////////////////////////////////////
                            tj_blzd = TJ_bljc.Rows[0]["F_TBSZD"].ToString().Trim() + "\r\n";
                            if (TJ_bljc.Rows[0]["F_TBS_BCYJ1"].ToString().Trim() != "")
                            {
                                tj_blzd = tj_blzd + "补充意见1:" + TJ_bljc.Rows[0]["F_TBS_BCYJ1"].ToString().Trim() + "\r\n";
                            }
                            if (TJ_bljc.Rows[0]["F_TBS_BCYJ2"].ToString().Trim() != "")
                            {
                                tj_blzd = tj_blzd + "补充意见2:" + TJ_bljc.Rows[0]["F_TBS_BCYJ2"].ToString().Trim() + "\r\n";
                            }
                        }

                        //if (bljc.Rows[0]["F_blk"].ToString().Trim() == "HPV")
                        //{
                        //    tj_jcsj = tj_jcsj + "检测方法:" + TJ_bljc.Rows[0]["F_FZ_JCFF"].ToString().Trim() + "\n" + "检测内容:" + TJ_bljc.Rows[0]["F_FZ_JCWD"].ToString().Trim() + "\n";
                        //    tj_blzd = "检测结果:" + TJ_bljc.Rows[0]["F_FZ_JCJG"].ToString().Trim();// "检查结果:" + TJ_bljc.Rows[0]["F_FZ_YYX"].ToString().Trim();
                        //}
                    }
                    if (debug == "1")
                    {
                        MessageBox.Show(tj_jcsj);
                        MessageBox.Show(tj_blzd);
                        MessageBox.Show(txpath);
                    }
                    /////////////////////////////////////////////////////
                    mzORAPAR[0].Value = bljc.Rows[0]["f_sqxh"].ToString().Trim();                 //体检申请单号
                    mzORAPAR[1].Value = bljc.Rows[0]["f_xm"].ToString().Trim();                   // 姓名
                    mzORAPAR[2].Value = tj_blzd.Trim();                                           // 诊断结论
                    mzORAPAR[3].Value = tj_jcsj.Trim();                                           //描述
                    mzORAPAR[4].Value = bljc.Rows[0]["f_bgys"].ToString().Trim();                 // 检查医生姓名
                    mzORAPAR[5].Value = DateTime.Parse(bljc.Rows[0]["f_bgrq"].ToString().Trim()); //检查时间
                    mzORAPAR[6].Value = txpath;                                                   // 图像绝对路径
                    mzORAPAR[7].Value = bljc.Rows[0]["f_xb"].ToString().Trim();                   // 性别
                    mzORAPAR[8].Value = bljc.Rows[0]["f_nl"].ToString().Trim();                   // 年龄
                    ////////////////////////////////////////////////////
                    SqlConnection ocn = new SqlConnection(odbcsql);
                    try
                    {
                        SqlCommand mzcmd = new SqlCommand();
                        mzcmd.Connection  = ocn;
                        mzcmd.CommandType = CommandType.StoredProcedure;
                        mzcmd.CommandText = "proc_get_bl_result";
                        mzcmd.Parameters.Add(mzORAPAR[0]);
                        mzcmd.Parameters.Add(mzORAPAR[1]);
                        mzcmd.Parameters.Add(mzORAPAR[2]);
                        mzcmd.Parameters.Add(mzORAPAR[3]);
                        mzcmd.Parameters.Add(mzORAPAR[4]);
                        mzcmd.Parameters.Add(mzORAPAR[5]);
                        mzcmd.Parameters.Add(mzORAPAR[6]);
                        mzcmd.Parameters.Add(mzORAPAR[7]);
                        mzcmd.Parameters.Add(mzORAPAR[8]);

                        try
                        {
                            ocn.Open();
                            if (debug == "1")
                            {
                                MessageBox.Show("数据库打开正常");
                            }

                            mzcmd.ExecuteNonQuery();

                            if (debug == "1")
                            {
                                MessageBox.Show("数据库执行正常,回写成功");
                            }

                            ocn.Close();

                            ZgqClass.BGHJ(F_blh, yhmc, "审核", "体检报告回写成功", "ZGQJK", "ZGQJK");
                        }
                        catch (Exception eee)
                        {
                            ocn.Close();
                            log.WriteMyLog("数据库执行异常," + eee.Message);
                            if (debug == "1")
                            {
                                MessageBox.Show("数据库执行异常:" + eee.Message.ToString());
                            }
                            ZgqClass.BGHJ(F_blh, yhmc, "审核", "体检报告回写失败:" + eee.Message, "ZGQJK", "ZGQJK");
                            return;
                        }
                        finally
                        {
                            if (ocn.State == ConnectionState.Open)
                            {
                                ocn.Close();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        log.WriteMyLog("参数错误:" + e.Message.ToString());
                    }
                }
                catch (Exception ee)
                {
                    log.WriteMyLog("参数错误2" + ee.Message.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public string CaQZ(string blh, string bglx, string bgxh, string debug, DataTable dt_cg, string yhmc, string bgzt)
        {
            string msg     = f.ReadString("savetohis", "camsg", "0").Replace("\0", "");
            string logname = "CAZGQJK";

            dbbase.odbcdb aa   = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");
            string        blbh = blh;

            if (bglx == "bc" || bglx == "bd")
            {
                blbh = blh + bglx + bgxh;
            }

            try
            {
                if (debug == "1")
                {
                    log.WriteMyLog("开始签字。。。", logname);
                }

                DataTable dt_bd = new DataTable();
                DataTable dt_bc = new DataTable();
                //补充审核
                string sql_str = "";
                if (bglx == "bc")
                {
                    sql_str = "select * from T_BCBG where  F_BLH='" + blh + "' and F_BC_BGZT='已审核' and F_BC_BGXH='" + bgxh + "'";
                    dt_bc   = aa.GetDataTable(sql_str, "bcbg");
                    if (dt_bc.Rows.Count <= 0)
                    {
                        log.WriteMyLog("未查询到此补充报告" + blbh, logname);
                        return("0");
                    }
                }
                //小冰冻审核
                if (bglx == "bd")
                {
                    sql_str = "select * from T_BDBG where  F_BLH='" + blh + "' and  F_BD_BGZT='已审核' and F_BD_BGXH='" + bgxh + "'";
                    dt_bd   = aa.GetDataTable(sql_str, "bdbg");
                    if (dt_bd.Rows.Count <= 0)
                    {
                        log.WriteMyLog("未查询到此冰冻报告" + blbh, logname);
                        return("0");
                    }
                }

                string TimeSign_XML = "";
                //时间戳服务地址
                string yztime = f.ReadString("CA", "yztime", "0");
                if (yztime == "1")
                {
                    string timeip = f.ReadString("CA", "timeip_web", "http://172.20.89.23:8080/xjcaTimestamp/services/sign");
                    string hash   = blbh + "^" + dt_cg.Rows[0]["F_XM"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_NL"].ToString().Trim() + "^"
                                    + dt_cg.Rows[0]["F_XM"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_BRBH"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_SQXH"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_ZYH"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_MZH"].ToString().Trim() + "^" + dt_cg.Rows[0]["F_SFZH"].ToString().Trim();
                    if (debug == "1")
                    {
                        log.WriteMyLog("验证时间戳:" + blbh + "\n" + hash, logname);
                    }
                    //返回值时间戳xml(TimeSign_XML)需要写人数据库
                    StringBuilder md5 = new StringBuilder(Getmd5(hash));
                    try
                    {
                        TimeSign_XML = XJCA_TimeSign(timeip, blbh, md5);
                    }
                    catch (Exception ee2)
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("CA签名:时间戳验证失败:" + ee2.Message);
                        }
                        ZgqClass.BGHJ(blh, yhmc, "数字签名", "时间戳验证失败:" + ee2.Message, "ZGQJK", "CA签名");
                        log.WriteMyLog("CA签名:时间戳验证失败:" + ee2.Message, logname);
                        return("0");
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("CA签名:TimeSign_XML:" + TimeSign_XML, logname);
                    }

                    if (debug == "1")
                    {
                        log.WriteMyLog("CA签名:时间戳完成", logname);
                    }
                }


                //签章----------------------------------
                if (debug == "1")
                {
                    log.WriteMyLog("CA签名:开始签章。。。", logname);
                }


                //签章原文
                string xmlstr = "";
                string bgwy   = "";

                if (bglx == "cg" || bglx == "")
                {
                    xmlstr = xmlstr + "<F_BLZD><![CDATA[" + dt_cg.Rows[0]["F_BLZD"].ToString() + "]]></F_BLZD>";
                    xmlstr = xmlstr + "<F_BGYS>" + dt_cg.Rows[0]["F_BGYS"].ToString() + "</F_BGYS>";
                    xmlstr = xmlstr + "<F_SHYS>" + dt_cg.Rows[0]["F_SHYS"].ToString() + "</F_SHYS>";
                    xmlstr = xmlstr + "<F_BGRQ>" + dt_cg.Rows[0]["F_BGRQ"].ToString() + "</F_BGRQ>";
                    xmlstr = xmlstr + "<F_SPARE5>" + dt_cg.Rows[0]["F_spare5"].ToString() + "</F_SPARE5>";
                    xmlstr = xmlstr + "<F_BGLX>" + "cg1" + "</F_BGLX>";
                }
                if (bglx == "bc" && dt_bc.Rows.Count > 0)
                {
                    xmlstr = xmlstr + "<F_BLZD><![CDATA[" + dt_bc.Rows[0]["F_BCZD"].ToString() + "]]></F_BLZD>";
                    xmlstr = xmlstr + "<F_BGYS>" + dt_bc.Rows[0]["F_BC_BGYS"].ToString() + "</F_BGYS>";
                    xmlstr = xmlstr + "<F_SHYS>" + dt_bc.Rows[0]["F_BC_SHYS"].ToString() + "</F_SHYS>";
                    xmlstr = xmlstr + "<F_BGRQ>" + dt_bc.Rows[0]["F_BC_BGRQ"].ToString() + "</F_BGRQ>";
                    xmlstr = xmlstr + "<F_SPARE5>" + dt_bc.Rows[0]["F_BC_spare5"].ToString() + "</F_SPARE5>";
                    xmlstr = xmlstr + "<F_BGLX>" + "bc" + bgxh + "</F_BGLX>";
                }
                if (bglx == "bd")
                {
                    xmlstr = xmlstr + "<F_BLZD><![CDATA[" + dt_bd.Rows[0]["F_BDZD"].ToString() + "]]></F_BLZD>";
                    xmlstr = xmlstr + "<F_BGYS>" + dt_bd.Rows[0]["F_BD_BGYS"].ToString() + "</F_BGYS>";
                    xmlstr = xmlstr + "<F_SHYS>" + dt_bd.Rows[0]["F_BD_SHYS"].ToString() + "</F_SHYS>";
                    xmlstr = xmlstr + "<F_BGRQ>" + dt_bd.Rows[0]["F_BD_BGRQ"].ToString() + "</F_BGRQ>";
                    xmlstr = xmlstr + "<F_SPARE5>" + dt_bd.Rows[0]["F_BD_BGRQ"].ToString() + "</F_SPARE5>";
                    xmlstr = xmlstr + "<F_BGLX>" + "bd" + dt_bd.Rows[0]["F_BD_BGXH"].ToString() + "</F_BGLX>";
                }
                if (xmlstr == "")
                {
                    log.WriteMyLog("CA签名:签章数据内容为空,请重新审核", logname);
                    if (msg == "1")
                    {
                        MessageBox.Show("CA签名失败:签章数据内容为空");
                    }
                    ZgqClass.BGHJ(blh, yhmc, "数字签名", "签章数据内容为空", "ZGQJK", "CA签名");
                    return("0");
                }
                string bgyw = "";
                bgyw = "<BL>";
                bgyw = bgyw + "<F_BLBH>" + blbh + "</F_BLBH>";
                bgyw = bgyw + "<F_BLH>" + blh + "</F_BLH>";
                bgyw = bgyw + "<F_XM>" + blh + "</F_XM>";
                bgyw = bgyw + "<F_XB>" + blh + "</F_XB>";
                bgyw = bgyw + "<F_NL>" + blh + "</F_NL>";
                bgyw = bgyw + "<F_ZYH>" + blh + "</F_ZYH>";
                bgyw = bgyw + "<F_MZH>" + blh + "</F_MZH>";
                bgyw = bgyw + "<F_SQXH>" + blh + "</F_SQXH>";
                bgyw = bgyw + "<F_YZID>" + blh + "</F_YZID>";
                bgyw = bgyw + "<F_BRBH>" + blh + "</F_BRBH>";
                bgyw = bgyw + "<F_SFZH>" + blh + "</F_SFZH>";
                bgyw = bgyw + "<F_SDRQ>" + blh + "</F_SDRQ>";
                bgyw = bgyw + "<F_CH>" + blh + "</F_CH>";
                bgyw = bgyw + xmlstr + "</BL>";

                if (debug == "1")
                {
                    log.WriteMyLog("CA签名:签章内容:" + bgyw, logname);
                }


                try
                {
                    int           len     = 0;
                    StringBuilder signxml = new StringBuilder(100000);

                    bool qzrtn = XJCA_SignSeal(Getmd5(bgyw), signxml, ref len);

                    if (debug == "1")
                    {
                        log.WriteMyLog("CA签名:" + signxml.ToString(), logname);
                    }
                    if (!qzrtn)
                    {
                        log.WriteMyLog("CA签名:数字签名失败,请重新审核" + qzrtn, logname);

                        if (msg == "1")
                        {
                            MessageBox.Show("CA签名:数字签名失败,请重新审核" + qzrtn);
                        }
                        ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:数字签名失败" + qzrtn, "ZGQJK", "CA签名");
                        return("0");
                    }
                    else
                    {
                        string sign = signxml.ToString().Trim();
                        if (sign == "")
                        {
                            log.WriteMyLog("CA签名:KEY密码验证失败:签名失败", logname);
                            if (msg == "1")
                            {
                                MessageBox.Show("CA签名:KEY密码验证失败:签名失败");
                            }
                            ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:KEY密码验证失败:签名失败", "ZGQJK", "CA签名");
                            return("0");
                        }

                        if (sign.Split(',')[0].Trim() == "")
                        {
                            log.WriteMyLog("CA签名:KEY密码验证失败:签名失败", logname);
                            if (msg == "1")
                            {
                                MessageBox.Show("CA签名失败:KEY密码验证失败:签名失败");
                            }
                            ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:KEY密码验证失败:签名失败", "ZGQJK", "CA签名");

                            return("0");
                        }

                        if (debug == "1")
                        {
                            log.WriteMyLog("CA签名:签字通过,解析返回值", logname);
                        }
                        try
                        {
                            // 签章返回的信息signxml 包含签章数据,证书内容,证书id,以“,”隔开,保存签章数据和证书id
                            string[] getsignxml = signxml.ToString().Split(',');
                            //签章数据
                            string signxml_str = getsignxml[0];
                            //证书内容
                            string cert = getsignxml[1];
                            //证书id
                            string certID = getsignxml[2];
                            //将signxml,,TimeSign_XML等返回值 存入数据库-------------
                            try
                            {
                                string sqlstr = "insert into T_CAXX(F_blbh,blh,RQ,KeyName,bgnr,TimeSign_XML,signxml,cert,certID) values ('" + blbh + "','" + blh + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + yhmc + "','" + bgyw + "','" + TimeSign_XML + "','" + signxml.ToString() + "','" + cert + "','" + certID + "') ";

                                int x = SQL_ExecuteNonQuery(sqlstr);

                                if (x <= 0)
                                {
                                    log.WriteMyLog("CA签名:写入数据库T_SZQM失败", logname);
                                    if (msg == "1")
                                    {
                                        MessageBox.Show("CA签名:写入数据库T_SZQM失败");
                                    }
                                    ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:写入数据库T_SZQM失败", "ZGQJK", "CA签名");

                                    return("0");
                                }
                                else
                                {
                                    if (debug == "1")
                                    {
                                        log.WriteMyLog("CA签名:插入T_SZQM完成", logname);
                                    }
                                    if (bglx == "cg")
                                    {
                                        aa.ExecuteSQL("update T_JCXX  set F_SZQZ='1' where F_BLH='" + blh + "'");
                                    }
                                    if (bglx == "bc")
                                    {
                                        aa.ExecuteSQL("update T_BCBG  set F_SZQZ='1' where F_BLH='" + blh + "' and F_bc_bgxh='" + bgxh + "'");
                                    }
                                    if (bglx == "bd")
                                    {
                                        aa.ExecuteSQL("update T_BDBG  set F_SZQZ='1' where F_BLH='" + blh + "' and F_bd_bgxh='" + bgxh + "'");
                                    }
                                    ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:签名成功", "ZGQJK", "CA签名");
                                }
                            }
                            catch (Exception ee7)
                            {
                                log.WriteMyLog("CA签名:写入数据库异常:" + ee7.Message, logname);
                                if (msg == "1")
                                {
                                    MessageBox.Show("CA签名:写入数据库异常:" + ee7.Message);
                                }
                                ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:写入数据库异常:" + ee7.Message, "ZGQJK", "CA签名");

                                return("0");
                            }
                        }
                        catch (Exception ee8)
                        {
                            log.WriteMyLog("CA签名:解析签名数据异常:" + ee8.Message, logname);
                            if (msg == "1")
                            {
                                MessageBox.Show("CA签名:解析签名数据异常:" + ee8.Message);
                            }
                            ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:解析签名数据异常:" + ee8.Message, "ZGQJK", "CA签名");

                            return("0");
                        }
                    }

                    log.WriteMyLog("CA签名:签名完成", logname);
                }
                catch (Exception ee9)
                {
                    log.WriteMyLog("CA签名:签名异常:" + ee9.Message, logname);
                    if (msg == "1")
                    {
                        MessageBox.Show("CA签名:签名异常:" + ee9.Message);
                    }
                    ZgqClass.BGHJ(blh, yhmc, "数字签名", "CA签名:签名异常:" + ee9.Message, "ZGQJK", "CA签名");

                    return("0");
                }

                //----------------------------------------------
                //----------------获取签章图片----------------------
                //----------------------------------------------
                string getbmpfs = f.ReadString("CA", "getbmpfs", "2").Replace("\0", "").Trim();
                string upbmpfs  = f.ReadString("CA", "upbmpfs", "0").Replace("\0", "").Trim();
                string bmppath  = ZgqClass.GetSz("view", "szqmlj", Application.StartupPath.ToString() + "\\rpt-szqm\\ysbmp").Replace("\0", "");



                if (getbmpfs == "0")
                {
                    goto GetEwm;
                }
                if (getbmpfs == "2")
                {
                    if (File.Exists(bmppath + "\\" + yhmc + ".bmp"))
                    {
                        goto GetEwm;
                    }
                }
                if (!Directory.Exists(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\"))
                {
                    Directory.CreateDirectory(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\");
                }
                if (debug == "1")
                {
                    log.WriteMyLog("获取签章图片开始。。。", logname);
                }
                bool ss = XJCA_GetSealBMPB(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp", 1);
                // XJCA_ResetDevice();
                if (ss)
                {
                    if (!File.Exists(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp"))
                    {
                        log.WriteMyLog("获取签章图片失败" + Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp", logname);
                    }

                    if (debug == "1")
                    {
                        log.WriteMyLog("获取签章图片成功,开始上传。。", logname);
                    }

                    if (upbmpfs == "1")
                    {
                        if (debug == "1")
                        {
                            log.WriteMyLog("上传签名图片:" + Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp --->" + bmppath + yhmc + ".bmp", logname);
                        }

                        File.Copy(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp", bmppath + yhmc + ".bmp", true);
                        if (!File.Exists(bmppath + yhmc + ".bmp"))
                        {
                            log.WriteMyLog("签章图片上传失败" + bmppath + yhmc + ".bmp", logname);
                            return("0");
                        }
                        if (debug == "1")
                        {
                            log.WriteMyLog("签章图片上传成功", logname);
                        }

                        return("1");
                    }
                    if (upbmpfs == "2")
                    {
                        ///////上传签章图片至ftp---------------------
                        string ftpServerIP = f.ReadString("ftp", "ftpip", "");
                        string ftpUserID   = f.ReadString("ftp", "user", "");
                        string ftpPassword = f.ReadString("ftp", "pwd", "");
                        string ftpszqmpath = f.ReadString("ca", "ftpszqmpath", "/pathsetup/pathqc/rpt-szqm/YSBMP/");
                        string ftpURI      = "ftp://" + ftpServerIP + "/" + ftpszqmpath + "/";
                        string status      = "";
                        FtpWeb fw          = new FtpWeb(ftpServerIP, ftpszqmpath, ftpUserID, ftpPassword);

                        fw.Upload(Application.StartupPath.ToString() + "\\rpt-szqm\\YSBMP\\" + yhmc + ".bmp", "", out status);
                        if (status == "Error")
                        {
                            log.WriteMyLog("CA签名:签章图片上传失败,请重新审核", logname);
                            return("0");
                        }
                        if (debug == "1")
                        {
                            log.WriteMyLog("签章图片上传成功", logname);
                        }
                    }
                }
                else
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("签章图片获取失败,请重新审核", logname);
                    }
                    return("1");
                }


                /////验章
                // XJCAverify.(M_signxml, M_signxml.Length, Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP", 7, 3, 3, 0);

GetEwm:
                # region 获取二维码图片
                string get2wm = f.ReadString("ca", "get2wm", "0").Replace("\0", "");

                if (get2wm == "1")
                {
                    if (!Directory.Exists(Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\"))
                    {
                        Directory.CreateDirectory(Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\");
                    }
                    else
                    {
                        DirectoryInfo dir = new DirectoryInfo(Application.StartupPath.ToString() + @"\rpt-szqm\MakePdfFile\");
                        foreach (FileInfo ff in dir.GetFiles("*.*"))
                        {
                            ff.Delete();
                        }
                    }

                    StringBuilder M_signxml = new StringBuilder(blbh, 10000);
                    XJCA_MakePdf417ToFile(M_signxml, M_signxml.Length, Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP", 7, 3, 3, 0);
                    //XJCA_ResetDevice();
                    if (!File.Exists(Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP"))
                    {
                        log.WriteMyLog("二维码不存在" + Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP", logname);
                        return("1");
                    }
                    string up2wmfs = f.ReadString("ca", "up2wmfs", "1").Replace("\0", "");
                    if (up2wmfs == "1")
                    {
                        string ewmpath = f.ReadString("ca", "ewmpath", Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile").Replace("\0", "");
                        if (debug == "1")
                        {
                            log.WriteMyLog("上传二维码图片:" + Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP --->" + ewmpath + "\\" + blbh + "EWM.BMP", logname);
                        }
                        File.Copy(Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP", ewmpath + "\\" + blbh + "EWM.BMP", true);
                        if (!File.Exists(ewmpath + "\\" + blbh + "EWM.BMP"))
                        {
                            log.WriteMyLog("二维码图片上传失败" + ewmpath + "\\" + blbh + "EWM.BMP", logname);
                            return("0");
                        }
                        if (debug == "1")
                        {
                            log.WriteMyLog("二维码图片上传成功", logname);
                        }
                        return("1");
                    }
                    if (upbmpfs == "2")
                    {
                        ///////上传签章图片至ftp---------------------
                        string ftpServerIP = f.ReadString("ftp", "ftpip", "");
                        string ftpUserID   = f.ReadString("ftp", "user", "");
                        string ftpPassword = f.ReadString("ftp", "pwd", "");
                        string ftpewmpath  = f.ReadString("ca", "ftpewmpath", "/pathimages/szqm/MakePdfFile/");

                        string ftpURI = "ftp://" + ftpServerIP + "/" + ftpewmpath + "/";
                        string status = "";
                        FtpWeb fw     = new FtpWeb(ftpServerIP, ftpewmpath, ftpUserID, ftpPassword);
                        fw.Upload(Application.StartupPath.ToString() + "\\rpt-szqm\\MakePdfFile\\" + blbh + "EWM.BMP", "", out status);
                        if (status == "Error")
                        {
                            log.WriteMyLog("二维码图片上传失败,请重新审核!", logname);
                            return("0");
                        }
                        if (debug == "1")
                        {
                            log.WriteMyLog("二维码图片上传成功", logname);
                        }
                    }
                }
                return("1");
            }
            catch (Exception ee1)
            {
                log.WriteMyLog(ee1.Message, logname);
                return("0");
            }
            #endregion
        }
Exemplo n.º 3
0
        public void pathtohis(string blh, string bglx, string bgxh, string msg1, string debug1, string[] cslb)
        {
            if (bglx == "")
            {
                bglx = "cg";
            }
            if (bgxh == "")
            {
                bgxh = "0";
            }

            string blbh  = blh + bglx + bgxh;
            string CZY   = f.ReadString("yh", "yhmc", "").Replace("\0", "").Trim();
            string CZYGH = f.ReadString("yh", "yhbh", "").Replace("\0", "").Trim();

            debug = f.ReadString("savetohis", "debug", "").Replace("\0", "").Trim();
            string isbghj = f.ReadString("zgqjk", "isbghj", "1").Replace("\0", "").Trim();

            string xtdm = f.ReadString("savetohis", "xtdm", "2060000");

            string certificate = f.ReadString("savetohis", "certificate", "ZmmJ9RMCKAUxFsiwl/08iiA3J17G0OpI");

            msg = msg1;

            string IP        = f.ReadString("savetohis", "IP", "223.220.200.7");
            string toPDFPath = f.ReadString("savetohis", "toPDFPath", "");
            string useName   = f.ReadString("savetohis", "useName", "");
            string pwd       = f.ReadString("savetohis", "pwd", "");
            string tjtxpath  = toPDFPath;

            string qxsh = "";
            string xdj  = "";

            bglx = bglx.ToLower();

            if (cslb.Length == 5)
            {
                if (cslb[4].ToLower() == "qxsh")
                {
                    qxsh = "1"; //取消审核动作
                }
                if (cslb[3].ToLower() == "new")
                {
                    xdj = "1";
                }
            }

            dbbase.odbcdb aa   = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", "");
            DataTable     jcxx = new DataTable();

            try
            {
                jcxx = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "jcxx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return;
            }
            if (jcxx == null)
            {
                MessageBox.Show("病理数据库设置有问题!");
                return;
            }
            if (jcxx.Rows.Count < 1)
            {
                MessageBox.Show("病理号有错误!");
                return;
            }
            if (jcxx.Rows[0]["F_SQXH"].ToString().Trim() == "")
            {
                log.WriteMyLog("无申请序号,不处理");
                ZgqClass.BGHJ(blh, CZY, "保存", "无申请序号,不处理", "ZGQJK", "");
                aa.ExecuteSQL("update T_JCXX_FS set F_bz='无申请序号,不处理',F_FSZT='已处理'  where F_blbh='" + blbh + "' ");
                return;
            }

            string bgzt = jcxx.Rows[0]["F_BGZT"].ToString().Trim();

            if (qxsh == "1")
            {
                bgzt = "取消审核";
            }



            string brbh = jcxx.Rows[0]["F_BRBH"].ToString().Trim();
            string brlb = jcxx.Rows[0]["F_brlb"].ToString().Trim();
            string sqxh = jcxx.Rows[0]["F_SQXH"].ToString().Trim();

            if (brlb == "住院")
            {
                brlb = "I";
            }
            else if (brlb == "体检")
            {
                brlb = "T";
            }
            else
            {
                brlb = "O";
            }

            string ZYH = jcxx.Rows[0]["F_MZH"].ToString().Trim();

            if (brlb == "I")
            {
                ZYH = jcxx.Rows[0]["F_ZYH"].ToString().Trim();
            }

            string SFZH = jcxx.Rows[0]["F_SFZH"].ToString().Trim();
            string XM   = jcxx.Rows[0]["F_XM"].ToString().Trim();
            string SJKS = jcxx.Rows[0]["F_BQ"].ToString().Trim();
            string CH   = jcxx.Rows[0]["F_CH"].ToString().Trim();
            string YZXM = jcxx.Rows[0]["F_YZXM"].ToString().Trim();

            //回写状态   客户端用
            int hczt = f.ReadInteger("savetohis", "hczt", 1);
            int hcbg = f.ReadInteger("savetohis", "hcbg", 1);

            if (hczt == 1)
            {
                if (bglx != "bc" && bglx != "bd")
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传状态");
                    }
                    #region  回状态(不包括审核)
                    if (bgzt == "已登记" || bgzt == "已取材" || bgzt == "已写报告" || bgzt == "报告延期" || bgzt == "取消审核")
                    {
                        string bgzt_1 = "";
                        if (bgzt == "已登记" || bgzt == "已取材")
                        {
                            bgzt_1 = "S";
                        }

                        if (bgzt == "已写报告" || bgzt == "报告延期")
                        {
                            bgzt_1 = "R";
                        }

                        if (bgzt == "已审核")
                        {
                            bgzt_1 = "F";
                        }

                        if (bgzt == "已写报告" && jcxx.Rows[0]["F_HXBJ"].ToString().Trim() == "1")
                        {
                            bgzt_1 = "C";
                        }

                        if (bgzt == "取消审核")
                        {
                            bgzt_1 = "C";
                        }


                        if (bgzt_1 == "")
                        {
                            log.WriteMyLog("bgzt_1状态为空,不回写!");
                            return;
                        }

                        string ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                          + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"
                                                          //+ "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||||||||||||\r"
                                                          + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                          + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                          + "OBR||" + sqxh + "|" + "BL_" + blbh + "|" + YZXM + "|||||||||||||||||||||" + bgzt_1;
                        if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                        {
                            ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                       //+ "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"
                                                       + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||||||||||||\r"
                                                       + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                       + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                       + "OBR||" + sqxh + "|" + blh + "|" + YZXM + "|||||||||||||||||||||" + bgzt_1;
                        }

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告状态入参:" + ChangeGmsApplyStatus_Hl7);
                        }

                        string rtn_msg2 = rtn_CallInterface("HL7v2", "ChangeGmsApplyStatus", ChangeGmsApplyStatus_Hl7, "", certificate);


                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告状态平台返回:" + rtn_msg2);
                        }

                        if (rtn_msg2.Trim() == "-1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-回写报告状态失败:" + rtn_msg2);
                            if (isbghj == "1")
                            {
                                ZgqClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:-1", "ZGQJK", "回写报告状态:" + bgzt);
                            }
                            return;
                        }
                        else
                        {
                            readhl7_fjfy r7 = new readhl7_fjfy();
                            int          xy = 0;
                            r7.Adt01(rtn_msg2, ref xy);
                            if (r7.MSA[1].Trim() == "AA")
                            {
                                if (debug == "1")
                                {
                                    log.WriteMyLog(r7.MSA[3].Trim());
                                }
                                if (isbghj == "1")
                                {
                                    ZgqClass.BGHJ(blh, CZY, "保存", "回写报告状态成功:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:" + bgzt);
                                }
                            }
                            else
                            {
                                log.WriteMyLog("回写报告状态失败:" + r7.MSA[3].Trim());
                                if (isbghj == "1")
                                {
                                    ZgqClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:" + bgzt);
                                }
                            }
                        }
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传状态结束");
                    }
                    #endregion
                }
            }



            DataTable dt_bc = new DataTable();
            DataTable dt_bd = new DataTable();
            string    bgzt2 = "";
            if (bglx.ToLower().Trim() == "bd")
            {
                dt_bd = aa.GetDataTable("select * from T_BDBG where F_BLH='" + blh + "' and  F_BD_BGXH='" + bgxh + "'", "bd");
                bgzt2 = dt_bd.Rows[0]["F_BD_BGZT"].ToString();
            }
            if (bglx.ToLower().Trim() == "bc")
            {
                dt_bc = aa.GetDataTable("select * from T_BCBG where F_BLH='" + blh + "' and  F_BC_BGXH='" + bgxh + "'", "bc");
                bgzt2 = dt_bc.Rows[0]["F_BC_BGZT"].ToString();
            }
            if (bgzt != "取消审核" && bglx.ToLower().Trim() != "cg")
            {
                bgzt = bgzt2;
            }

            string pdfname  = "";
            string pdfpath  = "";
            string filepath = "";
            string ispdf    = f.ReadString("savetohis", "ispdf", "1").Replace("\0", "").Trim();

            if (ispdf == "1")
            {
                #region  生成pdf
                if (bgzt.Trim() == "已审核")
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("生成pdf开始");
                    }
                    string ML      = DateTime.Parse(jcxx.Rows[0]["F_SDRQ"].ToString()).ToString("yyyyMM");
                    string err_msg = "";



                    //生成jpg
                    bool isrtn = false;
                    if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                    {
                        isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZgqPDFJPG.Type.JPG, ref err_msg, ref pdfname, ref pdfpath, ref filepath, IP, useName, pwd);
                    }
                    else
                    {
                        isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZgqPDFJPG.Type.PDF, ref err_msg, ref pdfname, ref pdfpath, ref filepath, IP, useName, pwd);
                    }

                    if (isrtn)
                    {
                        pdfname = pdfname.Substring(pdfname.LastIndexOf('\\') + 1);
                        ZgqClass.BGHJ(blh, "his接口", "报告审核", "生成PDF成功:" + pdfpath, "ZGQJK", "pdf");
                        aa.ExecuteSQL("delete T_BG_PDF  where F_BLBH='" + blbh + "' ");
                        aa.ExecuteSQL("insert  into T_BG_PDF(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_PDFPATH,F_PDFNAME) values('" + blbh + "','" + blh + "','" + bglx + "','" + bgxh + "','" + pdfpath + "','" + pdfname + "')");
                    }
                    else
                    {
                        log.WriteMyLog(blh + "-" + err_msg);
                        ZgqClass.BGHJ(blh, "his接口", "审核PDF", "生成PDF失败" + err_msg, "ZGQJK", "pdf");
                        if (msg == "1")
                        {
                            MessageBox.Show("病理号:" + blh + "  生成PDF失败,请重新审核!\r\n" + err_msg);
                        }
                        return;
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("生成pdf或jpg结束");
                    }
                }
                else
                {
                }


                # endregion
            }

            //回写报告

            if (hcbg == 1)
            {
                if (bgzt == "已审核")
                {
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传审核状态");
                    }
                    string txwebpath = ZgqClass.GetSz("savetohis", "txwebpath", @"http://223.220.200.111/pathwebrpt/images").Replace("\0", "").Trim();

                    ////回写报告审核状态
                    if (bglx != "bc" && bglx != "bd")
                    {
                        #region 回写审核状态
                        string ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                          + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"
                                                          //+ "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||||||||||||\r"
                                                          + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                          + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                          + "OBR||" + sqxh + "|" + "BL_" + blbh + "|" + YZXM + "|||||||||||||||||||||F";

                        if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                        {
                            ChangeGmsApplyStatus_Hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORM^O01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                                       //+ "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI~" + ZYH + "^^^^||" + XM + "^||||||||||||\r"
                                                       + "PID|||" + jcxx.Rows[0]["F_YZID"].ToString().Trim() + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||||||||||||\r"
                                                       + "PV1||" + brlb + "|||||||||||||||||" + ZYH + "\r"
                                                       + "ORC|SC|" + sqxh + "|||RC|||||" + CZYGH + "^" + CZY + "\r"
                                                       + "OBR||" + sqxh + "|" + blh + "|" + YZXM + "|||||||||||||||||||||F";
                        }

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告审核状态入参:" + ChangeGmsApplyStatus_Hl7);
                        }

                        string rtn_msg_zt = rtn_CallInterface("HL7v2", "ChangeGmsApplyStatus", ChangeGmsApplyStatus_Hl7, "", certificate);

                        if (debug == "1")
                        {
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-修改报告审核状态平台返回:" + rtn_msg_zt);
                        }

                        if (rtn_msg_zt.Trim() == "-1")
                        {
                            if (isbghj == "1")
                            {
                                ZgqClass.BGHJ(blh, CZY, "保存", "回写报告审核状态失败:-1", "ZGQJK", "回写报告状态:已审核");
                            }
                            log.WriteMyLog(blh + "^" + bglx + "^" + bgxh + "-回写报告状态失败:" + rtn_msg_zt);
                            return;
                        }
                        else
                        {
                            readhl7_fjfy r7 = new readhl7_fjfy();
                            int          xy = 0;
                            r7.Adt01(rtn_msg_zt, ref xy);
                            if (r7.MSA[1].Trim() == "AA")
                            {
                                if (debug == "1")
                                {
                                    log.WriteMyLog(r7.MSA[3].Trim());
                                }
                                if (isbghj == "1")
                                {
                                    ZgqClass.BGHJ(blh, CZY, "保存", "回写报告状态成功:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:已审核");
                                }
                            }
                            else
                            {
                                if (isbghj == "1")
                                {
                                    ZgqClass.BGHJ(blh, CZY, "保存", "回写报告状态失败:" + r7.MSA[3].Trim(), "ZGQJK", "回写报告状态:已审核");
                                }
                                log.WriteMyLog("回写报告状态失败:" + r7.MSA[3].Trim());
                            }
                        }
                        #endregion
                    }
                    DataTable dt_pdf = new DataTable();
                    dt_pdf = aa.GetDataTable("select *  from T_BG_PDF  where F_BLBH='" + blbh + "'", "pdf");
                    if (dt_pdf == null || dt_pdf.Rows.Count <= 0)
                    {
                        if (ispdf == "1")
                        {
                            #region  生成pdf
                            if (bgzt.Trim() == "已审核")
                            {
                                string ML      = DateTime.Parse(jcxx.Rows[0]["F_SDRQ"].ToString()).ToString("yyyyMM");
                                string err_msg = "";


                                //生成jpg
                                bool isrtn = false;
                                if (jcxx.Rows[0]["F_BRLB"].ToString().Trim() == "体检")
                                {
                                    isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZgqPDFJPG.Type.JPG, ref err_msg, ref pdfname, ref pdfpath, ref filepath, IP, useName, pwd);
                                }
                                else
                                {
                                    isrtn = MD_PDF_JPG(blh, bglx, bgxh, ML, ZgqPDFJPG.Type.PDF, ref err_msg, ref pdfname, ref pdfpath, ref filepath, IP, useName, pwd);
                                }

                                if (isrtn)
                                {
                                    pdfname = pdfname.Substring(pdfname.LastIndexOf('\\') + 1);
                                    ZgqClass.BGHJ(blh, "his接口", "报告审核", "生成PDF成功:" + pdfpath, "ZGQJK", "pdf");
                                    aa.ExecuteSQL("delete T_BG_PDF  where F_BLBH='" + blbh + "' ");
                                    aa.ExecuteSQL("insert  into T_BG_PDF(F_BLBH,F_BLH,F_BGLX,F_BGXH,F_PDFPATH,F_PDFNAME) values('" + blbh + "','" + blh + "','" + bglx + "','" + bgxh + "','" + pdfpath + "','" + pdfname + "')");
                                }
                                else
                                {
                                    log.WriteMyLog(blh + "-" + err_msg);
                                    ZgqClass.BGHJ(blh, "his接口", "审核PDF", "生成PDF失败" + err_msg, "ZGQJK", "pdf");
                                    if (msg == "1")
                                    {
                                        MessageBox.Show("病理号:" + blh + "  生成PDF失败,请重新审核!\r\n" + err_msg);
                                    }
                                    return;
                                }
                            }
                            else
                            {
                            }

                            if (debug == "1")
                            {
                                log.WriteMyLog("生成pdf或jpg结束");
                            }
                            # endregion
                        }
                    }
                    else
                    {
                        pdfpath = dt_pdf.Rows[0]["F_PDFPATH"].ToString().Trim();
                        pdfname = dt_pdf.Rows[0]["F_PDFNAME"].ToString().Trim();
                    }
                    #region 回传报告

                    if (debug == "1")
                    {
                        log.WriteMyLog("回传结果开始");
                    }

                    string bgys = jcxx.Rows[0]["F_BGYS"].ToString().Trim();
                    string shys = jcxx.Rows[0]["F_SHYS"].ToString().Trim();

                    string qcys   = jcxx.Rows[0]["F_QCYS"].ToString().Trim();
                    string qcysgh = getyhgh(qcys);
                    string qcrq   = jcxx.Rows[0]["F_QCrq"].ToString().Trim();
                    string bgrq   = DateTime.Parse(jcxx.Rows[0]["F_BGRQ"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                    string shrq   = DateTime.Parse(jcxx.Rows[0]["F_SPARE5"].ToString().Trim()).ToString("yyyyMMddHHmmss");

                    // 诊断描述
                    string Res_char = (jcxx.Rows[0]["F_RYSJ"].ToString().Trim() + "\r\n" + jcxx.Rows[0]["F_JXSJ"].ToString().Trim());
                    //诊断结论	Res_con
                    string Res_con = (jcxx.Rows[0]["F_BLZD"].ToString().Trim() + "\r\n" + jcxx.Rows[0]["F_TSJC"].ToString().Trim());
                    try
                    {
                        qcrq = DateTime.Parse(qcrq).ToString("yyyyMMddHHmmss");
                    }
                    catch
                    {
                    }
                    if (bglx == "bc")
                    {
                        bgys     = dt_bc.Rows[0]["F_BC_BGYS"].ToString().Trim();
                        shys     = dt_bc.Rows[0]["F_BC_SHYS"].ToString().Trim();
                        Res_char = (dt_bc.Rows[0]["F_BC_JXSJ"].ToString().Trim());
                        Res_con  = (dt_bc.Rows[0]["F_BCZD"].ToString().Trim() + "\r\n" + dt_bc.Rows[0]["F_BC_TSJC"].ToString().Trim());
                        bgrq     = DateTime.Parse(dt_bc.Rows[0]["F_bc_bgrq"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                        shrq     = DateTime.Parse(dt_bc.Rows[0]["F_bc_SPARE5"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                    }
                    if (bglx == "bd")
                    {
                        bgys     = dt_bd.Rows[0]["F_BD_BGYS"].ToString().Trim();
                        shys     = dt_bd.Rows[0]["F_BD_SHYS"].ToString().Trim();
                        Res_char = "";
                        Res_con  = (dt_bd.Rows[0]["F_BDZD"].ToString().Trim());
                        bgrq     = DateTime.Parse(dt_bc.Rows[0]["F_bd_bgrq"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                        shrq     = DateTime.Parse(dt_bc.Rows[0]["F_bd_bgrq"].ToString().Trim()).ToString("yyyyMMddHHmmss");
                    }
                    string bgysgh = getyhgh(bgys);
                    string shysgh = getyhgh(shys);

                    string hxbj = jcxx.Rows[0]["F_HXBJ"].ToString().Trim();

                    string zt2 = "F";
                    if (hxbj == "1")
                    {
                        zt2 = "C";
                    }

                    string xb = jcxx.Rows[0]["F_XB"].ToString().Trim();
                    if (xb == "女")
                    {
                        xb = "F";
                    }
                    else if (xb.Trim() == "男")
                    {
                        xb = "M";
                    }
                    else
                    {
                        xb = "U";
                    }
                    ////就诊科室,检查方法,检查部位,异常标记,申请科室,登记时间,登记人,检查时间,检查人,性别
                    string blk = jcxx.Rows[0]["F_BLK"].ToString().Trim();
                    if (blk.Contains("TCT") || blk == "LCT" || blk == "液基细胞")
                    {
                        DataTable TJ_bljc = new DataTable();
                        TJ_bljc = aa.GetDataTable(" select top 1  *  from T_TBS_BG where  F_blh='" + blh + "'", "blxx");
                        if (TJ_bljc.Rows.Count > 0)
                        {
                            Res_char = Res_char + "标本满意度:" + TJ_bljc.Rows[0]["F_TBS_BBMYD"].ToString().Trim() + "\r\n" + "\r\n";
                            Res_char = Res_char + "     " + "\r\n" + TJ_bljc.Rows[0]["F_TBS_XBL"].ToString().Trim() + "\r\n" + TJ_bljc.Rows[0]["F_TBS_XBXM1"].ToString().Trim()
                                       + "\r\n" + TJ_bljc.Rows[0]["F_TBS_XBXM2"].ToString().Trim() + "\r\n" + "\r\n";
                            Res_char = Res_char + "病原微生物:" + "\r\n" + TJ_bljc.Rows[0]["F_TBS_WSW2"].ToString().Trim() + "\r\n" + TJ_bljc.Rows[0]["F_TBS_WSW1"].ToString().Trim()
                                       + "\r\n" + TJ_bljc.Rows[0]["F_TBS_WSW3"].ToString().Trim() + "\r\n" + TJ_bljc.Rows[0]["F_TBS_BDXM1"].ToString().Trim() + "\r\n" + "\r\n";
                            Res_char = Res_char + "炎症程度:" + TJ_bljc.Rows[0]["F_TBS_YZCD"].ToString().Trim() + "\r\n" + "\r\n";

                            ///////////诊断/////////////////////////
                            Res_con = "TBS诊断:" + TJ_bljc.Rows[0]["F_TBSZD"].ToString().Trim() + "\r\n" + "\r\n";
                            if (TJ_bljc.Rows[0]["F_TBS_BCYJ1"].ToString().Trim() != "")
                            {
                                Res_con = Res_con + "补充意见:" + TJ_bljc.Rows[0]["F_TBS_BCYJ1"].ToString().Trim() + "\r\n";
                            }
                        }
                    }
                    string SendGmsReport_hl7 = "MSH|^~\\&|GMS||HIS||" + DateTime.Now.ToString("yyyyMMddHHmmss") + "||ORU^R01|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|P|2.4" + "\r"
                                               + "PID|||" + brbh + "^^^^PI||" + jcxx.Rows[0]["F_XM"].ToString().Trim() + "^||^" + jcxx.Rows[0]["F_nl"].ToString().Trim() + "|" + xb + "|||||||" + "\r"
                                               + "PV1||" + brlb + "|" + SJKS + "^^" + CH + "||||^" + jcxx.Rows[0]["F_SJYS"].ToString().Trim() + "||||||||||||" + ZYH + "|||||||||||||||||||||||||" + "\r"
                                               + "OBR||" + sqxh + "|" + "BL_" + blbh + "|" + YZXM + "||" + DateTime.Parse(jcxx.Rows[0]["F_sdrq"].ToString().Trim()).ToString("yyyyMMddHHmmss") + "|" + qcrq + "|||" + qcysgh + "^" + qcys + "||||" + DateTime.Parse(jcxx.Rows[0]["F_sdrq"].ToString().Trim()).ToString("yyyyMMddHHmmss") + "|" + jcxx.Rows[0]["F_BBMC"].ToString().Trim() + "|^" + jcxx.Rows[0]["F_SJYS"].ToString().Trim() + "||||||" + bgrq + "||||||||||" + bgysgh + "&" + bgys + "^^" + "\r"
                                               + "NTE|1||" + filepath + "|Z-RP" + "\r"
                                               + "OBX|1|FT|^肉眼所见||" + Res_char.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\\.br\\.") + "|||N|||" + zt2 + "|||" + shrq + "||" + shysgh + "^" + shys + "|^" + jcxx.Rows[0]["F_BLK"].ToString().Trim() + "|" + "\r"
                                               + "OBX|2|FT| ^病理诊断||" + Res_con.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\\.br\\.") + "|||N|||" + zt2 + "|||" + shrq + "||" + shysgh + "^" + shys + "|^" + jcxx.Rows[0]["F_BLK"].ToString().Trim() + "|" + "\r";


                    if (jcxx.Rows[0]["F_brlb"].ToString().Trim() == "体检")
                    {
                        SendGmsReport_hl7 = SendGmsReport_hl7 + "ZIM|1|pdfname|" + "BL_" + blbh + "|" + pdfpath.Replace("ftp", "http").Trim() + "||" + "\r";
                    }
                    else
                    {
                        DataTable dt_tx = aa.GetDataTable("select * from V_DYTX where F_blh='" + blh + "'", "tx");
                        if (dt_tx.Rows.Count > 0)
                        {
                            for (int x = 0; x < dt_tx.Rows.Count; x++)
                            {
                                string txlj = txwebpath + "/" + jcxx.Rows[0]["F_TXML"].ToString().Trim() + "/" + dt_tx.Rows[x]["F_TXM"].ToString();
                                SendGmsReport_hl7 = SendGmsReport_hl7 + "ZIM|" + (x + 1).ToString() + "|" + dt_tx.Rows[x]["F_ID"].ToString() + "|" + "BL_" + blbh + "|" + txlj + "||1" + "\r";
                            }
                        }
                        else
                        {
                            SendGmsReport_hl7 = SendGmsReport_hl7 + "ZIM|1|1|" + "BL_" + blbh + "|||" + "\r";
                        }
                    }

                    if (debug == "1")
                    {
                        log.WriteMyLog("报告审核回写结果:" + SendGmsReport_hl7);
                    }
                    string rtn_msg2 = rtn_CallInterface("HL7v2", "SendGmsReport", SendGmsReport_hl7, "", certificate);

                    string iscfsc = ZgqClass.GetSz("zgqjk", "iscfsc", "0").Replace("\0", "").Trim();
                    if (rtn_msg2.Contains("error"))
                    {
                        if (msg == "1")
                        {
                            MessageBox.Show("报告审核回写结果错误:" + rtn_msg2);
                        }
                        log.WriteMyLog("报告审核回写结果错误:" + rtn_msg2);
                        if (isbghj == "1")
                        {
                            ZgqClass.BGHJ(blh, "上传平台", "审核", "报告审核回写结果错误:" + rtn_msg2, "ZGQJK", "报告审核回写结果");
                        }

                        if (iscfsc == "1")
                        {
                            aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='" + rtn_msg2 + "'  where F_blbh='" + blbh + "' ");
                        }
                        else
                        {
                            aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='" + rtn_msg2 + "',F_FSZT='已处理'  where F_blbh='" + blbh + "' ");
                        }

                        return;
                    }
                    else
                    {
                        readhl7_fjfy r7 = new readhl7_fjfy();
                        int          xy = 0;
                        r7.Adt01(rtn_msg2, ref xy);
                        if (r7.MSA[1].Trim() == "AA")
                        {
                            if (debug == "1")
                            {
                                log.WriteMyLog(r7.MSA[3].Trim());
                            }
                            if (isbghj == "1")
                            {
                                ZgqClass.BGHJ(blh, "上传平台", "审核", "报告审核回写结果成功:" + r7.MSA[3].Trim(), "ZGQJK", "报告审核回写结果");
                            }
                        }
                        else
                        {
                            if (msg == "1")
                            {
                                MessageBox.Show(r7.MSA[3].Trim());
                            }
                            log.WriteMyLog("报告审核回写结果失败:" + r7.MSA[3].Trim());
                            if (isbghj == "1")
                            {
                                ZgqClass.BGHJ(blh, "上传平台", "审核", "报告审核回写结果失败:" + r7.MSA[3].Trim(), "ZGQJK", "报告审核回写结果");
                            }

                            if (iscfsc == "1")
                            {
                                aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='报告审核回写结果失败:" + r7.MSA[3].Trim() + "'  where F_blbh='" + blbh + "' ");
                            }
                            else
                            {
                                aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='报告审核回写结果失败:" + r7.MSA[3].Trim() + "',,F_FSZT='已处理'  where F_blbh='" + blbh + "' ");
                            }

                            return;
                        }
                    }
                    if (debug == "1")
                    {
                        log.WriteMyLog("回传结果结束");
                    }

                    #endregion

                    aa.ExecuteSQL("update T_JCXX_FS set F_errmsg='',F_FSZT='已处理'  where F_blbh='" + blbh + "'");
                    aa.ExecuteSQL("update T_JCXX set F_HXBJ='1' where F_blh='" + blh + "'");
                    return;
                }
                //取消审核,删除pdf
                #region
                if (bgzt == "取消审核")
                {
                    DataTable dt2 = aa.GetDataTable("select top 1 * from T_BG_PDF where F_blbh='" + blbh + "' ", "dt2");
                    if (dt2.Rows.Count > 0)
                    {
                        //开共享

                        if (useName.Trim() != "")
                        {
                            Process pro = new Process();
                            try
                            {
                                pro.StartInfo.FileName               = "cmd.exe";
                                pro.StartInfo.UseShellExecute        = false;
                                pro.StartInfo.RedirectStandardInput  = true;
                                pro.StartInfo.RedirectStandardOutput = true;
                                pro.StartInfo.RedirectStandardError  = true;
                                pro.StartInfo.CreateNoWindow         = true;
                                pro.Start();
                                pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ " + pwd + " /user:"******"");
                                Thread.Sleep(500);

                                if (File.Exists(dt2.Rows[0]["F_PDFPATH"].ToString()))
                                {
                                    File.Delete(dt2.Rows[0]["F_PDFPATH"].ToString());
                                }
                            }
                            catch (Exception ee)
                            {
                            }
                            finally
                            {
                                pro.StandardInput.WriteLine("net use  \\\\" + IP + "\\ipc$ /del");
                            }
                        }
                        else
                        {
                            if (File.Exists(dt2.Rows[0]["F_PDFPATH"].ToString()))
                            {
                                File.Delete(dt2.Rows[0]["F_PDFPATH"].ToString());
                            }
                        }
                        //判断共享上是否存在该pdf文件
                        aa.ExecuteSQL("delete T_BG_PDF  where F_BLbH='" + blbh + "' ");
                    }
                }
                #endregion
            }

            return;
        }