123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- using ADODB;
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Security.Cryptography;
- using System.Windows.Forms;
- using ZLPlugin_LisPacs_MR.Domain.Units;
- using ZLPlugin_LisPacs_MR.Model;
- namespace ZLPlugin_LisPacs_MR
- {
- //工具类
- public class Tools
- {
- //生成 uuid
- public static string Generate16CharUUID()
- {
- byte[] buffer = new byte[8];
- using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
- {
- rng.GetBytes(buffer);
- }
- long longValue = BitConverter.ToInt64(buffer, 0);
- Log.Info("longValue" + longValue);
- return longValue.ToString("X").Substring(0, 16);
- }
- public static string Generate16CharGUID()
- {
- // 生成Guid
- Guid guid = Guid.NewGuid();
- // 将Guid转换为字符串并截取前16位
- string randomString = guid.ToString().Substring(0, 16);
- Log.Info("Generate16CharGUID=" + randomString);
- return randomString;
- }
- //获取ip地址
- public static string GetHostIp()
- {
- string hostName = Dns.GetHostName();
- IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName);
- IPAddress[] ipAddresses = ipHostInfo.AddressList;
- foreach (IPAddress ip in ipAddresses)
- {
- if (ip.AddressFamily == AddressFamily.InterNetwork)
- {
- Console.WriteLine("本机 IP 地址:" + ip);
- return ip.ToString();
- }
- }
- return hostName;
- }
- public static string FormatStr(string str)
- {
- return str.Replace("\n", "").Replace("\t", "").Replace("\r", "");
- }
- public static string ReplaceString(string str)
- {
- return str.Replace("\\", "\\\\").Replace("\"", "\\\"");
- }
- public static Connection Connection;
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="sql"></param>
- /// <param name="rs"></param>
- public static void QueryTable(string sql, out Recordset rs)
- {
- rs = new Recordset();
- try
- {
- rs.Open(sql, Connection, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockOptimistic, (int)CommandTypeEnum.adCmdText);
- }
- catch (Exception ex)
- {
- Log.Info(ex.Message, true);
- Log.Info("出错sql为:" + sql, true);
- }
- }
- public static int ExecuteSql(string sql)
- {
- int result = 1;
- try
- {
- object missing = System.Reflection.Missing.Value;
- Command Command = new Command();
- Command.ActiveConnection = Connection;
- Command.CommandText = sql;
- Command.Execute(out missing, ref missing, (int)CommandTypeEnum.adCmdText);
- }
- catch (Exception ex)
- {
- result = 0;
- Log.Info("ex.Message=" + ex.Message);
- Log.Info("ex.StackTrace=" + ex.StackTrace);
- Connection.Close();
- }
- return result;
- }
- public static int ExecuteStoredProc(long 病人id, long 主医嘱id, string json, int lis, int pacs)
- {
- int result = 1;
- try
- {
- int? isNull = null;
- object missing = System.Reflection.Missing.Value;
- Command Command = new Command();
- Command.ActiveConnection = Connection;
- Command.CommandText = "Zl_医嘱作废_一张纸互认";
- Command.CommandType = CommandTypeEnum.adCmdStoredProc;
- Parameter par_br = Command.CreateParameter("病人id_In", DataTypeEnum.adBigInt, ParameterDirectionEnum.adParamInput, 18, 病人id);
- Command.Parameters.Append(par_br);
- Parameter par_yz = Command.CreateParameter("主医嘱id_In", DataTypeEnum.adBigInt, ParameterDirectionEnum.adParamInput, 18, 主医嘱id);
- Command.Parameters.Append(par_yz);
- Parameter par_json = Command.CreateParameter("Json_In", DataTypeEnum.adVarWChar, ParameterDirectionEnum.adParamInput, 2000, json);
- Command.Parameters.Append(par_json);
- Parameter par_pacs = Command.CreateParameter("检查消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, pacs == 1 ? 1 : isNull);
- Command.Parameters.Append(par_pacs);
- Parameter par_lis = Command.CreateParameter("检验消息_In", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 1, lis == 1 ? 1 : isNull);
- Command.Parameters.Append(par_lis);
- Parameter par_state = Command.CreateParameter("state", DataTypeEnum.adInteger, ParameterDirectionEnum.adParamOutput, 1);
- Command.Parameters.Append(par_state);
- Command.Execute(out missing, ref missing, (int)CommandTypeEnum.adCmdStoredProc);
- }
- catch (Exception ex)
- {
- result = 0;
- Connection.Close();
- Log.Info(ex.Message, true);
- Log.Info(ex.StackTrace, true);
- }
- return result;
- }
- /// <summary>
- /// 得到json,无子数组
- /// </summary>
- /// <param name="rd"></param>
- /// <returns></returns>
- public static string GetJsonData(Recordset rd)
- {
- string value = "{";
- for (var i = 0; i < rd.RecordCount; i++)
- {
- for (var j = 0; j < rd.Fields.Count; j++)
- {
- object obj = rd.Fields[j].Value;
- string val = obj.ToString().Trim();
- if (val == "")
- {
- value += "\"" + rd.Fields[j].Name + "\":null,";
- }
- else
- {
- //value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
- if (rd.Fields[j].Name == "附项")
- {
- value += "\"" + rd.Fields[j].Name + "\":null,";
- }
- else
- {
- value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
- }
- }
- }
- rd.MoveNext();
- }
- value = value.Substring(0, value.Length - 1);
- value += "}";
- return value;
- }
- /// <summary>
- /// 得到保存前的医嘱json
- /// </summary>
- /// <param name="rd"></param>
- /// <returns></returns>
- public static string GetAdviceSaveData(Recordset rd)
- {
- string value = "";
- if (rd.RecordCount > 0)
- {
- value = "[";
- for (var i = 0; i < rd.RecordCount; i++)
- {
- value += "{";
- for (var j = 0; j < rd.Fields.Count; j++)
- {
- object obj = rd.Fields[j].Value;
- string val = obj.ToString().Trim();
- if (val == "")
- {
- value += "\"" + rd.Fields[j].Name + "\":null,";
- }
- else
- {
- if (rd.Fields[j].Name == "医嘱内容")
- {
- value += "\"" + rd.Fields[j].Name + "\":\"" + val.Replace("\"", " ") + "\",";
- }else if (rd.Fields[j].Name == "附项")
- {
- value += "\"" + rd.Fields[j].Name + "\":null,";
- }
- else
- {
- value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
- }
- }
- }
- value = value.Substring(0, value.Length - 1);
- value += "},";
- rd.MoveNext();
- }
- value = value.Substring(0, value.Length - 1);
- value += "]";
- }
- return value;
- }
- public static string RecordsetToJson(Recordset rd)
- {
- string value = "";
- if (rd.RecordCount > 0)
- {
- //value = "[";
- for (var i = 0; i < rd.RecordCount; i++)
- {
- value += "{";
- for (var j = 0; j < rd.Fields.Count; j++)
- {
- Log.Info("\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",");
- value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
- //object obj = rd.Fields[j].Value;
- //string val = obj.ToString().Trim();
- //if (val == "")
- //{
- // value += "\"" + rd.Fields[j].Name + "\":null,";
- //}
- //else
- //{
- // value += "\"" + rd.Fields[j].Name + "\":\"" + rd.Fields[j].Value + "\",";
- //}
- }
- value = value.Substring(0, value.Length - 1);
- value += "},";
- //rd.MoveNext();
- }
- value = value.Substring(0, value.Length - 1);
- //value += "]";
- }
- return value;
- }
- /// <summary>
- /// 防止卡顿,程序等待
- /// </summary>
- /// <param name="mm"></param>
- public static void Delay(int mm, int sate = 1)
- {
- DateTime current = DateTime.Now;
- while (current.AddMilliseconds(mm) > DateTime.Now)
- {
- if (!string.IsNullOrWhiteSpace(SocketClient.Message))
- {
- return;
- }
- if (sate == 1)
- {
- Application.DoEvents();
- }
- }
- }
- public static bool MutualRecognition(Results result, out string message)
- {
- message = "";
- if (result.ResultText[0].State == "0")
- {
- return true;
- }
- else//互认
- {
- var LIS = result.ResultText[0].LIS;
- var PACS = result.ResultText[0].PACS;
- if (LIS != null && PACS == null)
- {
- message = "已互认检验结果[";
- for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
- {
- message += result.ResultText[0].LIS[i].ReportName + ",";
- }
- message = message.Substring(0, message.Length - 1);
- message += "],不允许重复检验,请删除或调整相关项目后再保存!";
- }
- else if (PACS != null && LIS == null)
- {
- message = "已互认检查结果[";
- for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
- {
- message += result.ResultText[0].PACS[i].ItemName + ",";
- }
- message = message.Substring(0, message.Length - 1);
- message += "],不允许重复检查,请删除或调整相关项目后再保存!";
- }
- else if (PACS != null && LIS != null)
- {
- message = "已互认检验结果[";
- for (int i = 0; i < result.ResultText[0].LIS.Count; i++)
- {
- message += result.ResultText[0].LIS[i].ReportName + ",";
- }
- message = message.Substring(0, message.Length - 1);
- message += "],检查结果[";
- for (int i = 0; i < result.ResultText[0].PACS.Count; i++)
- {
- message += result.ResultText[0].PACS[i].ItemName + ",";
- }
- message = message.Substring(0, message.Length - 1);
- message += "],不允许重复检验检查,请删除或调整相关项目后再保存!";
- }
- return false;
- }
- }
- }
- }
|