Procházet zdrojové kódy

开单互认新加金额字段

zackhua před 7 měsíci
rodič
revize
e684052ccd
7 změnil soubory, kde provedl 321 přidání a 70 odebrání
  1. 54 0
      Domain/Units/HttpUtils.cs
  2. 129 16
      LisPacs_MR_Bll.cs
  3. 3 1
      Model/Codes.cs
  4. 17 0
      Model/YZZCancelDTO.cs
  5. 5 4
      SocketClient.cs
  6. 6 5
      Tools.cs
  7. 107 44
      clsPlugin.cs

+ 54 - 0
Domain/Units/HttpUtils.cs

@@ -0,0 +1,54 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Text;
+
+namespace ZLPlugin_MR.Domain.Units
+{
+    public class HttpUtils
+    {
+        public static string WSCenterData(string url, string data)
+        {
+            string srcString = string.Empty;
+            try
+            {
+                Encoding myEncoding = Encoding.GetEncoding("UTF-8");
+                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; //将提交的字符串数据转换成字节数组 //注意提交的编码,这里默认的是Default:系统当前编码
+                byte[] postData = myEncoding.GetBytes(data); //设置提交的相关参数
+                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
+                request.Method = "POST";
+                request.KeepAlive = false;
+                request.ProtocolVersion = HttpVersion.Version10;
+                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
+                //request.ContentType = "text/xml;charset=utf-8";
+                request.ContentType = "application/json;charset=utf-8";
+                request.Headers.Add("code", "ZHONGLIAN");
+
+                request.ContentLength = postData.Length;
+
+                using (System.IO.Stream writer = request.GetRequestStream())
+                {
+                    writer.Write(postData, 0, postData.Length);
+                }
+
+                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
+                using (System.IO.Stream sr = response.GetResponseStream())
+                {
+                    using (StreamReader reader = new StreamReader(sr, myEncoding))
+                    {
+                        srcString = reader.ReadToEnd();
+                    }
+                }
+                //result = JSON.JsonToObject<Result>(Tools.FormatStr(srcString), Encoding.UTF8);
+            }
+            catch (Exception ex)
+            {
+                Log.Info("请求入参:" + data);
+                Log.Info("请求出参:" + srcString);
+                Log.Info(ex.Message);
+            }
+            return srcString;
+        }
+
+    }
+}

+ 129 - 16
LisPacs_MR_Bll.cs

@@ -1,6 +1,7 @@
 using ADODB;
 using System;
 using System.Collections.Generic;
+using System.Text;
 using ZLPlugin_MR.Domain.Units;
 using ZLPlugin_MR.Model;
 
@@ -42,11 +43,11 @@ namespace ZLPlugin_MR.ServerImpl
             total = 0;
             type = "";
             string sql = @"Select Count(1) As total,b.代码 code From 诊疗项目目录 a,ZLLPMR.字典对码表 b
-                                  Where b.名称 = a.操作类型 and 分类 ='检查' 
-                                  and a.类别 = 'D' And a.Id  = {0} --And 操作类型 In('DR','CT','MRI','X线')
+                                  Where 分类 ='检查互认项目' 
+                                  and a.类别 = 'D' And b.编码  = '{0}'
                                   group by b.代码";
             sql = string.Format(sql, zlid);
-            //Log.Info("sql2:" + sql);
+            Log.Info("sql2:" + sql);
             Recordset rd = new Recordset();
             Tools.QueryTable(sql, out rd);
             if (!rd.EOF)
@@ -83,6 +84,8 @@ namespace ZLPlugin_MR.ServerImpl
                         Codes codes = new Codes();
                         codes.id = list[i].相关ID;  //原先是 取id 不行 
                         codes.code = code;
+                        codes.yzid = list[i].ID;
+                        codes.zlxmid = list[i].诊疗项目ID;
                         listlis.Add(codes);
                         //lis += list[i].诊疗项目ID + ",";
                         //lis_id += list[i].ID + ",";
@@ -90,7 +93,7 @@ namespace ZLPlugin_MR.ServerImpl
                     }
 
                 }
-                else if (list[i].诊疗类别 == "D" && list[i].相关ID == "0.0")
+                else if (list[i].诊疗类别 == "D" && list[i].相关ID != "0.0")
                 {
                     //pacs = list[i].诊疗项目ID + ",";
                     //pacs_id = list[i].ID + ",";
@@ -98,13 +101,17 @@ namespace ZLPlugin_MR.ServerImpl
                     string type = "";
                     //IsPacsProject(list[i].诊疗项目ID, out total, out  type);
                     String param = list[i].诊疗项目ID + "_" + list[i].标本部位 + "_" + list[i].检查方法;
+                    Log.Info("param==" + param);
                     IsPacsProject(param, out total, out type);
                     if (total > 0)
                     {
                         Codes codes = new Codes();
-                        codes.id = list[i].ID;
+                        codes.id = list[i].相关ID;
                         codes.type = type;
+                        codes.yzid = list[i].ID;
+                        codes.zlxmid = list[i].诊疗项目ID;
                         listPacs.Add(codes);
+                        codeNo += type + "#";
                     }
                 }
             }
@@ -121,7 +128,7 @@ namespace ZLPlugin_MR.ServerImpl
         /// <param name="ZYID"></param>
         /// <param name="standardItemId"></param>
         /// <returns></returns>
-        public static Recordset GetZYPostJson(long lngPatientID, long ZYID, string no, int type)
+        public static Recordset GetZYPostJson(long lngPatientID, long ZYID, string no, int type,string totalPrice,string xgid)
         {
             string sql = @"Select distinct  a.姓名 ""PatientName"",
                                     b.身份证号 ""PatientIdCard"",
@@ -135,25 +142,61 @@ namespace ZLPlugin_MR.ServerImpl
                                     '{2}' ""standardItemId"",
                                     '' ""reportStartTime"",
                                     '' ""reportEndTime"",
-                                    '{3}' ""hrType""
+                                    '{3}' ""hrType"",
+                                    sysdate ""applyTime"",
+                                    '{4}' ""hisApplyCode"",
+                                    '2' ""patientType"",
+                                    '{5}' ""totalAmount""
                                     From 病案主页 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e
                                     Where b.病人id = a.病人id
                                     And c.姓名 = a.住院医师
                                     And d.Id = a.入院科室id
                                     And a.病人id = {0} And a.主页id = {1}";
-            sql = string.Format(sql, lngPatientID, ZYID, no, type);
+            sql = string.Format(sql, lngPatientID, ZYID, no, type, xgid, totalPrice);
             Recordset rd = new Recordset();
             Tools.QueryTable(sql, out rd);
             return rd;
         }
+
+
+        public static string GetZYTotalPrice(string zlxmid)
+        {
+            string sql = @"Select sum(现价) 金额 from 收费价目 where 收费细目id in (select 收费项目id from 诊疗收费关系 where 诊疗项目id = {0} )";
+            sql = string.Format(sql, zlxmid);
+            Recordset rd = new Recordset();
+            Tools.QueryTable(sql, out rd);
+            if (!rd.EOF)
+            {
+                rd.MoveFirst();
+                return rd.Fields["金额"].Value.ToString();
+            }
+            return "";
+        }
+
+        public static string GetMZTotalPrice(long lngPatientID, string YZID)
+        {
+            string sql = @"Select sum(a.实收金额) 金额 from 门诊费用记录 a,病人医嘱记录 b where a.医嘱序号 = b.id and b.病人id ={0} and b.id = {1}";
+            sql = string.Format(sql, lngPatientID, YZID);
+            Recordset rd = new Recordset();
+            Tools.QueryTable(sql, out rd);
+            if (!rd.EOF)
+            {
+                rd.MoveFirst();
+                return rd.Fields["金额"].Value.ToString();
+            }
+            return "";
+        }
+
         /// <summary>
         /// 门诊
         /// </summary>
         /// <param name="lngPatientID"></param>
         /// <param name="ZYID"></param>
         /// <param name="standardItemId"></param>
+        /// <param name="totalAmount"> 金额</param>
+        /// <param name="xgid">相关</param>
         /// <returns></returns>
-        public static Recordset GetMZPostJson(long ZYID, string no, int type)
+        public static Recordset GetMZPostJson(long ZYID, string code, int type,string totalAmount, string xgid)
         {
             string sql = @"Select distinct a.姓名 ""PatientName"",
                                     b.身份证号 ""PatientIdCard"",
@@ -167,13 +210,17 @@ namespace ZLPlugin_MR.ServerImpl
                                     '{1}' ""standardItemId"",
                                     '' ""reportStartTime"",
                                     '' ""reportEndTime"",
-                                    '{2}' ""hrType""
+                                    '{2}' ""hrType"",
+                                    sysdate ""applyTime"",
+                                    '{3}' ""hisApplyCode"",
+                                    '1' ""patientType"",
+                                    '{4}' ""totalAmount""
                                     From 病人挂号记录 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e
                                     Where b.病人id = a.病人id
                                     And c.姓名 = a.执行人
                                     And d.Id = a.执行部门id
                                     And a.id = {0}";
-            sql = string.Format(sql, ZYID, no, type);
+            sql = string.Format(sql, ZYID, code, type, xgid,totalAmount);
             Recordset rd = new Recordset();
             Tools.QueryTable(sql, out rd);
             return rd;
@@ -253,7 +300,7 @@ namespace ZLPlugin_MR.ServerImpl
                                 //Log.Info("items.id:" + items.id);
                                 string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                 //Log.Info("items.code:" + items.code);
-                                //Log.Info("items.id:" + items.id);
+                                Log.Info("items.id:" + items.id);
                                 int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, items.id);
                                 //Log.Info("res:" + res);
                                 if (res > 0)
@@ -314,13 +361,14 @@ namespace ZLPlugin_MR.ServerImpl
         /// 是否互认
         /// </summary>
         /// <returns></returns>
-        public static void IsAgree(out int res, out int date)
+        public static void IsAgree(out int res, out int date, out int yzzState)
         {
             res = 1;
             date = 20000;
+            yzzState = 0;
             try
             {
-                string sql = @"Select 互认 As AGREE,WAITINGDATE From zllpmr.互认配置表";
+                string sql = @"Select 互认 As AGREE,WAITINGDATE ,一张纸 From zllpmr.互认配置表";
                 Recordset rd = new Recordset();
                 Tools.QueryTable(sql, out rd);
                 if (!rd.EOF)
@@ -328,6 +376,28 @@ namespace ZLPlugin_MR.ServerImpl
                     rd.MoveFirst();
                     res = int.Parse(rd.Fields["AGREE"].Value.ToString());
                     date = int.Parse(rd.Fields["WAITINGDATE"].Value.ToString());
+                    yzzState = int.Parse(rd.Fields["一张纸"].Value.ToString());
+                }
+            }
+            catch (Exception ex)
+            {
+                Log.Info(ex.Message);
+                Log.Info(ex.StackTrace);
+            }
+        }
+
+        public static void getUrlYzzCancelMedical(out string url)
+        {
+            url = "";
+            try
+            {
+                string sql = @"Select 一张纸URL  From zllpmr.互认配置表";
+                Recordset rd = new Recordset();
+                Tools.QueryTable(sql, out rd);
+                if (!rd.EOF)
+                {
+                    rd.MoveFirst();
+                    url = rd.Fields["一张纸URL"].Value.ToString();
                 }
             }
             catch (Exception ex)
@@ -391,8 +461,10 @@ namespace ZLPlugin_MR.ServerImpl
                                 to_char(b.摘要) as 摘要
                          from 病人医嘱发送 a,病人医嘱记录 b 
                          where b.id = a.医嘱id and  发送号 = {0} and 诊疗类别 in('D','C')
-                         and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is not null)";
+                         ";
+            //and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is not null)
             sql = string.Format(sql, fsh);
+            Log.Info("医嘱记录=》》"+sql);
             Recordset recordset = new Recordset();
             Tools.QueryTable(sql, out recordset);
             List<YZData> list = new List<YZData>();
@@ -453,7 +525,48 @@ namespace ZLPlugin_MR.ServerImpl
             }
             json = json.Substring(0, json.Length - 1);
             json += "]}}";
-            Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs);
+            //原始调用过程没有作用 改用数据处理平台中转
+            //Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs);
+            int lisMessage = 0;
+            int pacsMessage = 0;
+            //调有 http 
+           /* Dictionary<string, string> body = new Dictionary<string, string>();
+            body.Add("patientId", 病人id.ToString());
+            body.Add("medicalOrderId", 主医嘱id.ToString());
+            body.Add("jsonIn", json);
+            if (lis > 0)
+            {
+                lisMessage = 1;
+            }
+            if (pacs > 0)
+            {
+                pacsMessage = 1;
+            }
+            body.Add("lisMessage", lisMessage.ToString());
+            body.Add("pacsMessage", pacsMessage.ToString());*/
+
+            if (lis > 0)
+            {
+                lisMessage = 1;
+            }
+            if (pacs > 0)
+            {
+                pacsMessage = 1;
+            }
+            YZZCancelDTO zZCancelDTO = new YZZCancelDTO();
+            zZCancelDTO.patientId = 病人id.ToString();
+            zZCancelDTO.medicalOrderId = 主医嘱id.ToString();
+            zZCancelDTO.jsonIn = json;
+            zZCancelDTO.lisMessage = lisMessage.ToString();
+            zZCancelDTO.pacsMessage = pacsMessage.ToString();
+
+            string url = "http://172.30.0.66:7000/cancelMedicalForYzz";
+            getUrlYzzCancelMedical(out url);
+            Log.Info("url=" + url);
+            string body = JSON.ObjectToJson<YZZCancelDTO>(zZCancelDTO, Encoding.UTF8);
+            Log.Info("body==" + body);
+            string resultString = HttpUtils.WSCenterData(url, body);
+            Log.Info("resultString==" + resultString);
         }
     }
 }

+ 3 - 1
Model/Codes.cs

@@ -4,8 +4,10 @@ namespace ZLPlugin_MR.Model
 {
     public class Codes
     {
-        public string id { get; set; }
+        public string id { get; set; } // 相关id
         public string code { get; set; }
         public string type { get; set; }
+        public string yzid { get; set; } // 医嘱id 
+        public string zlxmid { get; set; } //诊疗项目id
     }
 }

+ 17 - 0
Model/YZZCancelDTO.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ZLPlugin_MR.Model
+{
+    public class YZZCancelDTO
+    {
+        public string patientId { get; set; }
+        public string medicalOrderId { get; set; }// public string 3767642public string ,
+        public string jsonIn { get; set; }// public string 0.0public string ,
+        public string lisMessage { get; set; }// public string 2public string ,
+        public string pacsMessage { get; set; }// public string 2public string ,
+
+    }
+}

+ 5 - 4
SocketClient.cs

@@ -48,6 +48,7 @@ namespace ZLPlugin_MR.Domain.Units
         public SocketClient(string ip, int Port)
         {
             _ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+            _ClientSocket.ReceiveTimeout = 2000;
             this.ipAddress = ip;
             this.Port = Port;
             Start();
@@ -63,10 +64,10 @@ namespace ZLPlugin_MR.Domain.Units
                                                                                                   //客户端网络结点号  
                 remoteEndPoint = _ClientSocket.RemoteEndPoint.ToString();
                 LocalEndPoint = _ClientSocket.LocalEndPoint.ToString();
-                //Console.WriteLine($"远端地址:{remoteEndPoint} 本端地址:{LocalEndPoint}");
-                threadReceive = new Thread(Receive);
-                threadReceive.IsBackground = true;
-                threadReceive.Start();
+                Log.Info($"远端地址:{remoteEndPoint} 本端地址:{LocalEndPoint}");
+                /* threadReceive = new Thread(Receive);
+                 threadReceive.IsBackground = true;
+                 threadReceive.Start();*/
                 IsRun = true;
             }
             catch (Exception ex)

+ 6 - 5
Domain/Units/Tools.cs → Tools.cs

@@ -69,13 +69,14 @@ namespace ZLPlugin_MR.Domain.Units
                 object missing = System.Reflection.Missing.Value;
                
                 Command command = new Command();
-                command.CommandTimeout = 20000;
-                Connection.Open();
+                //command.CommandTimeout = 200;
+                //Connection.Open();
+               // Connection.ConnectionString();
                 command.ActiveConnection = Connection;
-
                 Log.Info("111  Connection  111" + Connection.State);
+                Log.Info("111  Connection  111" + command.State);
                 command.CommandText = "Zl_医嘱作废_一张纸互认";
-
+                
                 command.CommandType = CommandTypeEnum.adCmdStoredProc;
                 Log.Info("ExecuteStoredProc   qq");
                 Parameter par_br = command.CreateParameter("病人id_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 18, 病人id);
@@ -99,7 +100,7 @@ namespace ZLPlugin_MR.Domain.Units
                 command.Parameters.Append(par_state);
                 Log.Info("ExecuteStoredProc   r");
                 Log.Info("ExecuteStoredProc   11");
-                Recordset recordset = command.Execute(out missing, ref missing, (int)CommandTypeEnum.adCmdStoredProc);
+                Recordset recordset = command.Execute(out missing, ref missing);// , (int)CommandTypeEnum.adCmdStoredProc
                 Log.Info("ExecuteStoredProc");
                 Log.Info((string)missing);
             }

+ 107 - 44
clsPlugin.cs

@@ -86,18 +86,21 @@ namespace ZLPlugin_MR
             Log.Info("AdviceSend   lngModual == " + lngModual );
             Log.Info("AdviceSend   lngSys == " + lngSys);
             
-            /*if (lngSys !=0 || lngModual == 1252)
+            //住院的时候发送 不需要  20241015
+            if (lngModual == 1254)
             {
                 return true;
-            }*/
-            Log.Info("AdviceSend  enter==");
-            SocketClient clientSend = new SocketClient("127.0.0.1", 6061);
+            }
+            //--------------  20241015
+            Log.Info("AdviceSend  enter=="+ lngSendID);
+            
             try
             {
                 Log.Info("AdviceSend  enter==");
                 int res = 1;
                 int waittingdate = 0;
-                LisPacs_MR_Bll.IsAgree(out res, out waittingdate);
+                int yzzState = 0;
+                LisPacs_MR_Bll.IsAgree(out res, out waittingdate, out yzzState);
                 if (res == 0)//互认关闭
                 {
                     return true;
@@ -110,6 +113,7 @@ namespace ZLPlugin_MR
                 int hrType = 0;
                 if (listlis.Count == 0 && listpacs.Count == 0)
                 {
+                    Log.Info("listlis.Count == 0");
                     return true;
                 }
                 else if (listlis.Count > 0 && listpacs.Count == 0)//只有检验
@@ -120,10 +124,43 @@ namespace ZLPlugin_MR
                 {
                     hrType = 2;
                 }
-                Recordset rd = LisPacs_MR_Bll.GetMZPostJson(lngClinicID, code, hrType);
+                string yzid = listlis[0].yzid;
+                string xgid = listlis[0].id;
+
+                string totalPrice= LisPacs_MR_Bll.GetMZTotalPrice(lngPatientID, yzid);
+                Recordset rd = LisPacs_MR_Bll.GetMZPostJson(lngClinicID, code, hrType, totalPrice, xgid);
                 string json = Tools.RecordsetToJson(rd);
+                Log.Info(json);
+                SocketClient clientSend = new SocketClient("127.0.0.1", 6061);
                 clientSend.Send(json);
-                Tools.Delay(10000, 0);
+                //Tools.Delay(10000, 0);
+
+                bool status = true; int i = 0;
+                var begintime = DateTime.Now.Ticks;
+                TimeSpan timeSpan = new TimeSpan();
+                Log.Info("初始化完成!");
+                while (status)
+                {
+                    timeSpan = new TimeSpan(DateTime.Now.Ticks - begintime);
+                    //Thread.Sleep(3000);
+                    try
+                    {
+                        clientSend.Receive();
+                    }
+                    catch (Exception e)
+                    {
+                        Log.Info("接收失败!" + e.Message);
+                    }
+                    if (timeSpan.TotalSeconds > 10 || !string.IsNullOrWhiteSpace(SocketClient.Message))
+                    {
+                        status = false;
+                    }
+                    Log.Info("timeSpan.TotalSeconds:" + timeSpan.TotalSeconds);
+                    i++;
+
+                }
+                Log.Info("22222" + SocketClient.Message);
+
                 if (!string.IsNullOrWhiteSpace(SocketClient.Message))
                 {
                     Log.Info(SocketClient.Message);
@@ -131,20 +168,26 @@ namespace ZLPlugin_MR
                     rex = JSON.JsonToObject<ResultsEx>(Tools.FormatStr(SocketClient.Message), Encoding.UTF8);
                     if (rex.ResultCode == 2)//有互认
                     {
-                        SocketClient.Message = null;
-                        return SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, 1);
+                        MessageBox.Show("回传数据至his!");
+                        clientSend.Receive();
+                       // SocketClient.Message = null;
+                        SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, 1);
+                        clientSend.Close();
+                        return true;
                     }
                     else if (rex.ResultCode == -1)//互认引用失败
                     {
                         MessageBox.Show(rex.ResultText.ToString(), "中联软件", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
+                        clientSend.Close();
                         return true;
                     }
                     else
                     {
+                        clientSend.Close();
                         return true;//此病人不存在互认信息
                     }
-
                 }
+                clientSend.Close();
             }
             catch (Exception ex)
             {
@@ -170,26 +213,26 @@ namespace ZLPlugin_MR
             //'      int场合=0-医生站调用,1-护士站调用,2-医技站调用(PACS/LIS)
             Log.Info("AdviceSave  lngModual==" + lngModual);
             Log.Info("AdviceSave   lngSys == " + lngSys);
-            #region 仅印江人民医院使用,仅支持住院,因为一张纸发送医嘱后也会触发此方法
-            if (lngModual == 1252)
-            {
-                
-                return true;
-            }
-            Log.Info("AdviceSave  enter==");
-            #endregion
             rsAdvice.Filter = "";
             try
             {
-
-                SocketClient socketClient = new SocketClient("127.0.0.1", 6061);
                 int res = 1;
                 int waittingdate = 0;
-                LisPacs_MR_Bll.IsAgree(out res, out waittingdate);
+                int yzzState = 0;
+                LisPacs_MR_Bll.IsAgree(out res, out waittingdate, out yzzState);
                 if (res == 0)//互认关闭
                 {
                     return true;
                 }
+                if (yzzState == 1)
+                {
+                    #region 仅印江人民医院使用,仅支持住院,因为一张纸发送医嘱后也会触发此方法
+                    if (lngModual == 1252)
+                    {
+                        return true;
+                    }
+                    #endregion
+                }
                 string str = Tools.GetAdviceSaveData(rsAdvice);
                 Log.Info("保存前医嘱:" + str);
                 if (str == "")
@@ -216,41 +259,54 @@ namespace ZLPlugin_MR
                 {
                     hrType = 2;
                 }
+
+                string yzid = listlis[0].yzid;
+                string xgid = listlis[0].id;
                 if (lngModual == 1253)//住院
                 {
-                    rd = LisPacs_MR_Bll.GetZYPostJson(lngPatientID, lngClinicID, code, hrType);
+                    string zlxmid = listlis[0].zlxmid;
+                    string totalPrice = LisPacs_MR_Bll.GetZYTotalPrice(zlxmid);
+                    rd = LisPacs_MR_Bll.GetZYPostJson(lngPatientID, lngClinicID, code, hrType, totalPrice, xgid);
                 }
                 else
                 {
-                    rd = LisPacs_MR_Bll.GetMZPostJson(lngClinicID, code, hrType);
+                    string totalPrice = LisPacs_MR_Bll.GetMZTotalPrice(lngPatientID, yzid);
+                    
+                    rd = LisPacs_MR_Bll.GetMZPostJson(lngClinicID, code, hrType, totalPrice,xgid);
                 }
+                SocketClient socketClient = new SocketClient("127.0.0.1", 6061);
                 //Results result = new Results();
                 string json = Tools.RecordsetToJson(rd);
+                Log.Info(json);
                 socketClient.Send(json);
-                Tools.Delay(10000, 0);
-                bool flag = true;
-                int num2 = 0;
-                long ticks = DateTime.Now.Ticks;
+                //Tools.Delay(10000, 0);
+
+                bool status = true; int i = 0;
+                var begintime = DateTime.Now.Ticks;
                 TimeSpan timeSpan = new TimeSpan();
                 Log.Info("初始化完成!");
-                
-                while (flag)
+                while (status)
                 {
-                    Log.Info("num==" + num2);
-                    timeSpan = new TimeSpan(DateTime.Now.Ticks - ticks);
-                   // socketClient.Receive();
-                    Log.Info("SocketClient.Message==:" + SocketClient.Message);
-                    if (timeSpan.TotalSeconds > 20.0 || !string.IsNullOrWhiteSpace(SocketClient.Message))
+                    timeSpan = new TimeSpan(DateTime.Now.Ticks - begintime);
+                    //Thread.Sleep(3000);
+                    try
+                    {
+                        socketClient.Receive();
+                    }
+                    catch (Exception e)
                     {
-                        flag = false;
+                        Log.Info("接收失败!" + e.Message);
                     }
-                       
-                    Log.Info("timeSpan.TotalSeconds:" + timeSpan.TotalSeconds.ToString());
-                    ++num2;
-                    Log.Info("num2==" + num2);
+                    if (timeSpan.TotalSeconds > 10 || !string.IsNullOrWhiteSpace(SocketClient.Message))
+                    {
+                        status = false;
+                    }
+                    Log.Info("timeSpan.TotalSeconds:" + timeSpan.TotalSeconds);
+                    i++;
+
                 }
-                Log.Info("SocketClient.Message  22==:" + SocketClient.Message);
-               
+                Log.Info("22222" + SocketClient.Message);
+
                 if (!string.IsNullOrWhiteSpace(SocketClient.Message))
                 {
                     Log.Info(SocketClient.Message);
@@ -258,20 +314,27 @@ namespace ZLPlugin_MR
                     rex = JSON.JsonToObject<ResultsEx>(Tools.FormatStr(SocketClient.Message), Encoding.UTF8);
                     if (rex.ResultCode == 2)//有互认
                     {
-                        SocketClient.Message = null;
-                        return SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, -1);
+                        MessageBox.Show("回传数据至his!");
+                        socketClient.Receive();
+                        //SocketClient.Message = null;
+                        SaveData(waittingdate, lngPatientID, lngClinicID, listlis, listpacs, -1);
+                        socketClient.Close();
+                        return true;
                     }
                     else if (rex.ResultCode == -1)//互认引用失败
                     {
                         MessageBox.Show(rex.ResultText.ToString(), "中联软件", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
+                        socketClient.Close();
                         return true;
                     }
                     else
                     {
+                        socketClient.Close();
                         return true;//此病人不存在互认信息
                     }
 
                 }
+                socketClient.Close();
             }
             catch (Exception ex)
             {
@@ -316,7 +379,7 @@ namespace ZLPlugin_MR
             long pacsId;
             Log.Info("Domain.Infos.UserInfo.编号 = " + Domain.Infos.UserInfo.编号);
             LisPacs_MR_Bll.SaveData(result, lngPatientID, lngClinicID, Domain.Infos.UserInfo.编号, listlis, listpacs, out lisId, out pacsId);
-            Log.Info("state:"+ state + "lisId"+ lisId);
+            Log.Info("state:"+ state + "  lisId"+ lisId);
             if (state < 1)
             {
                 return true;