LisPacs_MR_Bll.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. using ADODB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using ZLPlugin_MR.Domain.Units;
  6. using ZLPlugin_MR.Model;
  7. using static System.Windows.Forms.AxHost;
  8. namespace ZLPlugin_MR.ServerImpl
  9. {
  10. public class LisPacs_MR_Bll
  11. {
  12. /// <summary>
  13. /// lis是否有互认项目
  14. /// </summary>
  15. /// <returns></returns>
  16. public static void IsLisProject(string zlid, out string code, out int total)
  17. {
  18. code = "";
  19. total = 0;
  20. string sql = @"Select to_char(Replace(wm_concat(distinct(l.医保编码)),',','#')) Code,Count(1) total
  21. From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,ZLLPMR.互认项目清单 l
  22. Where y.诊疗项目id = x.Id
  23. And z.Id = y.收费项目id
  24. And m.收费细目id = z.Id
  25. And l.医保通用编码 = m.项目编码
  26. And m.险类 = 111
  27. and x.类别 = 'C'
  28. And x.Id = {0}";
  29. sql = string.Format(sql, zlid);
  30. Log.Info("sql1:" + sql);
  31. Recordset rd = new Recordset();
  32. Tools.QueryTable(sql, out rd);
  33. if (!rd.EOF)
  34. {
  35. rd.MoveFirst();
  36. code = rd.Fields["CODE"].Value.ToString();
  37. total = int.Parse(rd.Fields["TOTAL"].Value.ToString());
  38. }
  39. }
  40. public static void IsPacsProject(string zlid, out int total, out string type)
  41. {
  42. total = 0;
  43. type = "";
  44. string sql = @"Select Count(1) As total,b.代码 code From 诊疗项目目录 a,ZLLPMR.字典对码表 b
  45. Where 分类 ='检查互认项目'
  46. and a.类别 = 'D' And b.编码 = '{0}'
  47. group by b.代码";
  48. sql = string.Format(sql, zlid);
  49. Log.Info("sql2:" + sql);
  50. Recordset rd = new Recordset();
  51. Tools.QueryTable(sql, out rd);
  52. if (!rd.EOF)
  53. {
  54. rd.MoveFirst();
  55. total = int.Parse(rd.Fields["TOTAL"].Value.ToString());
  56. type = rd.Fields["CODE"].Value.ToString();
  57. }
  58. }
  59. /// <summary>
  60. /// 返回诊疗项目ID
  61. /// </summary>
  62. /// <param name="rsAdvice"></param>
  63. /// <returns></returns>
  64. public static void GetTreatmentId(List<YZData> list, out string codeNo, out List<Codes> listlis, out List<Codes> listPacs, out string billProjectNames)
  65. {
  66. //lis = "";
  67. //lis_id = "";
  68. //pacs = "";
  69. //pacs_id = "";
  70. codeNo = "";
  71. billProjectNames = "";
  72. listlis = new List<Codes>();
  73. listPacs = new List<Codes>();
  74. for (var i = 0; i < list.Count; i++)
  75. {
  76. Log.Info("list.Count " + i);
  77. if (list[i].诊疗类别 == "C" && list[i].相关ID != "0.0")
  78. {
  79. string code = "";
  80. int total = 0;
  81. IsLisProject(list[i].诊疗项目ID, out code, out total);
  82. Log.Info("IsLisProject " + total);
  83. if (total > 0)
  84. {
  85. Codes codes = new Codes();
  86. codes.id = list[i].相关ID; //原先是 取id 不行
  87. codes.code = code;
  88. codes.yzid = list[i].ID;
  89. codes.zlxmid = list[i].诊疗项目ID;
  90. listlis.Add(codes);
  91. //lis += list[i].诊疗项目ID + ",";
  92. //lis_id += list[i].ID + ",";
  93. codeNo += code + "#";
  94. Log.Info("codeNo " + codeNo);
  95. billProjectNames += list[i].医嘱内容 + "、";
  96. }
  97. }
  98. else if (list[i].诊疗类别 == "D" && list[i].相关ID != "0.0")
  99. {
  100. //pacs = list[i].诊疗项目ID + ",";
  101. //pacs_id = list[i].ID + ",";
  102. int total = 0;
  103. string type = "";
  104. //IsPacsProject(list[i].诊疗项目ID, out total, out type);
  105. String param = list[i].诊疗项目ID + "_" + list[i].标本部位 + "_" + list[i].检查方法;
  106. Log.Info("param==" + param);
  107. IsPacsProject(param, out total, out type);
  108. if (total > 0)
  109. {
  110. Codes codes = new Codes();
  111. codes.id = list[i].相关ID;
  112. codes.type = type;
  113. codes.code = type;
  114. codes.yzid = list[i].ID;
  115. codes.zlxmid = list[i].诊疗项目ID;
  116. codes.zxksid = list[i].执行科室ID;
  117. codes.part = list[i].标本部位;
  118. codes.method = list[i].检查方法;
  119. listPacs.Add(codes);
  120. codeNo += type + "#";
  121. Log.Info("codeNo " + codeNo);
  122. billProjectNames += list[i].医嘱内容 + "_" + list[i].标本部位 + "_" + list[i].检查方法 + "、";
  123. }
  124. }
  125. }
  126. //lis = lis.Length > 0 ? lis.Substring(0, lis.Length - 1) : lis;
  127. codeNo = codeNo.Length > 0 ? codeNo.Substring(0, codeNo.Length - 1) : codeNo;
  128. billProjectNames = billProjectNames.Length > 0 ? billProjectNames.Substring(0, billProjectNames.Length - 1) : billProjectNames;
  129. //pacs = pacs.Length > 0 ? pacs.Substring(0, pacs.Length - 1) : pacs;
  130. //lis_id = lis_id.Length > 0 ? lis_id.Substring(0, lis_id.Length - 1) : lis_id;
  131. //pacs_id = pacs_id.Length > 0 ? pacs_id.Substring(0, pacs_id.Length - 1) : pacs_id;
  132. }
  133. /// <summary>
  134. /// 住院
  135. /// </summary>
  136. /// <param name="lngPatientID"></param>
  137. /// <param name="ZYID"></param>
  138. /// <param name="standardItemId"></param>
  139. /// <returns></returns>
  140. public static Recordset GetZYPostJson(long lngPatientID, long ZYID, string no, int type,string totalPrice,string xgid)
  141. {
  142. string sql = @"Select distinct a.姓名 ""PatientName"",
  143. b.身份证号 ""PatientIdCard"",
  144. e.机构编码 ""jzOrgCode"",
  145. e.机构名称 ""jzOrgName"",
  146. c.编号 ""jzDoctorCode"",
  147. c.姓名 ""jzDoctorName"",
  148. d.编码 ""jzDeptCode"",
  149. d.名称 ""jzDeptName"",
  150. a.住院号 ""businessNumber"",
  151. '{2}' ""standardItemId"",
  152. TO_CHAR(SYSDATE-30, 'YYYY-MM-DD HH24:MI:SS') ""reportStartTime"",
  153. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""reportEndTime"",
  154. '{3}' ""hrType"",
  155. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""applyTime"",
  156. '{4}' ""hisApplyCode"",
  157. '2' ""patientType"",
  158. '{5}' ""totalAmount""
  159. From 病案主页 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e
  160. Where b.病人id = a.病人id
  161. And c.姓名 = a.住院医师
  162. And d.Id = a.入院科室id
  163. And a.病人id = {0} And a.主页id = {1}";
  164. sql = string.Format(sql, lngPatientID, ZYID, no, type, xgid, totalPrice);
  165. Recordset rd = new Recordset();
  166. Tools.QueryTable(sql, out rd);
  167. return rd;
  168. }
  169. /// <summary>
  170. /// 插入互认开单项目数据
  171. /// </summary>
  172. /// <param name="computerName"></param>
  173. /// <param name="lngPatientID"></param>
  174. /// <param name="billName"></param>
  175. /// <param name="lngSendID"></param>
  176. /// <param name="ip"></param>
  177. /// <param name="no"></param>
  178. /// <param name="yzID"></param>
  179. /// <param name="type"></param>
  180. /// <param name="operatorName"></param>
  181. /// <returns></returns>
  182. public static int InsertHuRenBillProject(string computerName, long lngPatientID, string billName, long lngSendID, string ip, string no, string yzXgID, string type, string operatorName, string patientSource)
  183. {
  184. string sql = @"Insert Into 互认开单项目(计算机名,患者id,开单项目,开单时间,发送号,计算机IP,单据号,相关id,类别,开单人,病人来源)
  185. Values('{0}','{1}','{2}',to_date('{3}','yyyy-mm-dd hh24:mi:ss'),{4},'{5}','{6}','{7}','{8}','{9}','{10}')";
  186. sql = string.Format(sql, computerName, lngPatientID, billName, DateTime.Now, lngSendID, ip, no, yzXgID, type, operatorName, patientSource);
  187. Log.Info("InsertLis:" + sql);
  188. int res = Tools.ExecuteSql(sql);
  189. return res;
  190. }
  191. public static string GetZYTotalPrice(string zlxmid)
  192. {
  193. string sql = @"Select sum(现价) 金额 from 收费价目 where 收费细目id in (select 收费项目id from 诊疗收费关系 where 诊疗项目id = {0} )";
  194. sql = string.Format(sql, zlxmid);
  195. Recordset rd = new Recordset();
  196. Tools.QueryTable(sql, out rd);
  197. if (!rd.EOF)
  198. {
  199. rd.MoveFirst();
  200. return rd.Fields["金额"].Value.ToString();
  201. }
  202. return "";
  203. }
  204. public static string GetMZTotalPrice(long lngPatientID, string YZID)
  205. {
  206. string sql = @"Select nvl(sum(a.实收金额),'0') 金额 from 门诊费用记录 a,病人医嘱记录 b where a.医嘱序号 = b.id and b.病人id ={0} and b.id = {1}";
  207. sql = string.Format(sql, lngPatientID, YZID);
  208. Recordset rd = new Recordset();
  209. Tools.QueryTable(sql, out rd);
  210. if (!rd.EOF)
  211. {
  212. rd.MoveFirst();
  213. return rd.Fields["金额"].Value.ToString();
  214. }
  215. return "";
  216. }
  217. public static string GetTotalPriceForLisByZLXM(string zlxmid)
  218. {
  219. string sql = @"Select nvl(sum(现价),'0') 金额 from 收费价目 where 终止日期 > sysdate and 收费细目id in (select 收费项目id from 诊疗收费关系 where 诊疗项目id = {0} )";
  220. sql = string.Format(sql, zlxmid);
  221. Log.Info("GetTotalPriceForLisByZLXM==" + sql);
  222. Recordset rd = new Recordset();
  223. Tools.QueryTable(sql, out rd);
  224. if (!rd.EOF)
  225. {
  226. rd.MoveFirst();
  227. return rd.Fields["金额"].Value.ToString();
  228. }
  229. return "0";
  230. }
  231. public static decimal GetTotalPriceForLisByZlxmIds(string zlxmids)
  232. {
  233. string sql = @"Select nvl(sum(现价),'0') 金额 from 收费价目 where 终止日期 > sysdate and 收费细目id in (select 收费项目id from 诊疗收费关系 where 诊疗项目id in ({0}) )";
  234. sql = string.Format(sql, zlxmids);
  235. Log.Info("GetTotalPriceForLisByZLXM==" + sql);
  236. Recordset rd = new Recordset();
  237. Tools.QueryTable(sql, out rd);
  238. if (!rd.EOF)
  239. {
  240. rd.MoveFirst();
  241. decimal amount = Convert.ToDecimal(rd.Fields["金额"].Value.ToString());
  242. return amount;
  243. }
  244. return 0;
  245. }
  246. //获取诊疗项目ids
  247. public static string GetZlxmIdFromList(List<Codes> list)
  248. {
  249. string zlxmids = "";
  250. for (var i = 0; i < list.Count; i++)
  251. {
  252. zlxmids += list[i].zlxmid + ",";
  253. }
  254. zlxmids = zlxmids.Length > 0 ? zlxmids.Substring(0, zlxmids.Length - 1) : zlxmids;
  255. return zlxmids;
  256. }
  257. /// <summary>
  258. ///
  259. /// </summary>
  260. /// <param name="zlxmid"> 诊疗项目id</param>
  261. /// <param name="zlksid"> 执行科室id</param>
  262. /// <param name="part"> 部位</param>
  263. /// <param name="method"> 方法</param>
  264. /// <param name="patientResource"> 病人来源 门诊 1 还是住院 2 0 所有</param>
  265. /// <returns></returns>
  266. public static decimal GetTotalPriceForPacsByZLXM(string zlxmid, string zlksid, string part, string method, int patientResource)
  267. {
  268. string sql = @"select nvl(sum(a.现价* b.收费数量),'0') 金额 from 收费价目 a,(
  269. select * from 诊疗收费关系 where 诊疗项目id = {0} and ( 适用科室id is null or 适用科室id = {1} )and 检查部位 = '{2}' and 检查方法 = '{3}' and 病人来源 <> {4}
  270. union all
  271. select * from 诊疗收费关系 where 诊疗项目id = {0} and 固有对照 = 1 and 适用科室id = {1} and 病人来源 <> {4}
  272. ) b where a.收费细目id = b.收费项目id and a.终止日期 > sysdate ";
  273. sql = string.Format(sql, zlxmid, zlksid, part, method, patientResource);
  274. Log.Info("GetTotalPriceForPacsByZLXM==" + sql);
  275. Recordset rd = new Recordset();
  276. Tools.QueryTable(sql, out rd);
  277. if (!rd.EOF)
  278. {
  279. rd.MoveFirst();
  280. decimal amount = Convert.ToDecimal(rd.Fields["金额"].Value.ToString());
  281. return amount;
  282. }
  283. return 0;
  284. }
  285. /// <summary>
  286. /// 门诊
  287. /// </summary>
  288. /// <param name="lngPatientID"></param>
  289. /// <param name="ZYID"></param>
  290. /// <param name="standardItemId"></param>
  291. /// <param name="totalAmount"> 金额</param>
  292. /// <param name="xgid">相关</param>
  293. /// <returns></returns>
  294. public static Recordset GetMZPostJson(long ZYID, string code, int type,string totalAmount, string xgid)
  295. {
  296. string sql = @"Select distinct a.姓名 ""PatientName"",
  297. b.身份证号 ""PatientIdCard"",
  298. e.机构编码 ""jzOrgCode"",
  299. e.机构名称 ""jzOrgName"",
  300. c.编号 ""jzDoctorCode"",
  301. c.姓名 ""jzDoctorName"",
  302. d.编码 ""jzDeptCode"",
  303. d.名称 ""jzDeptName"",
  304. a.门诊号 ""businessNumber"",
  305. '{1}' ""standardItemId"",
  306. TO_CHAR(SYSDATE-30, 'YYYY-MM-DD HH24:MI:SS') ""reportStartTime"",
  307. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""reportEndTime"",
  308. '{2}' ""hrType"",
  309. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""applyTime"",
  310. '{3}' ""hisApplyCode"",
  311. '1' ""patientType"",
  312. '{4}' ""totalAmount""
  313. From 病人挂号记录 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e
  314. Where b.病人id = a.病人id
  315. And c.姓名 = a.执行人
  316. And d.Id = a.执行部门id
  317. And a.id = {0}";
  318. sql = string.Format(sql, ZYID, code, type, xgid,totalAmount);
  319. Recordset rd = new Recordset();
  320. Tools.QueryTable(sql, out rd);
  321. return rd;
  322. }
  323. public static int InsertLis(LISItem lis, long lngPatientID, long lngClinicID, string date, string no, string yzid)
  324. {
  325. string sql = @"Insert Into ZLLPMR.互认_LIS(LISCHECKREPORTID,REPORTNAME,ORGNAME,REPORTTIME,病人ID,主页ID,TIME,OPERATORNO,医嘱id)
  326. Values('{0}','{1}','{2}',to_date('{3}','yyyy/mm/dd hh24:mi:ss'),{4},{5},to_date('{6}','yyyy/mm/dd hh24:mi:ss'),'{7}','{8}')";
  327. sql = string.Format(sql, lis.LisCheckReportId, lis.ReportName, lis.OrgName, lis.ReportTime, lngPatientID, lngClinicID, date, no, yzid);
  328. Log.Info("InsertLis:" + sql);
  329. int res = Tools.ExecuteSql(sql);
  330. return res;
  331. }
  332. public static void InsertLisItem(ItemListItem item, string id, long lngPatientID, long lngClinicID, string date)
  333. {
  334. string sql = @"Insert Into ZLLPMR.互认_LISITEMS(LISCHECKREPORTID,ITEMCODE,ITEMNAME,RESULT,UNIT,HINT,RANGE,STANDARDITEMID,TIME)
  335. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',to_date('{8}','yyyy/mm/dd hh24:mi:ss'))";
  336. sql = string.Format(sql, id, item.ItemCode, item.ItemName, item.Result, item.Unit, item.Hint, item.Range, item.StandardItemId, date);
  337. Log.Info("InsertLisItem:" + sql);
  338. Tools.ExecuteSql(sql);
  339. }
  340. public static int InsertPacs(PACSItem item, long lngPatientID, long lngClinicID, string no, long yzid)
  341. {
  342. string sql = @"Insert Into ZLLPMR.互认_PACS(PACSCHECKREPORTID,ITEMNAME,REPORTTIME,CHECKTYPENAME,POSITIONNAME,STANDARDITEMID,DIAGNOSRESULT,ORGNAME,病人ID,主页ID,TIME,OPERATORNO,医嘱id,REPORTTYPECODE)
  343. Values('{0}','{1}',to_date('{2}','yyyy/mm/dd hh24:mi:ss'),'{3}','{4}','{5}','{6}','{7}',{8},{9},sysdate,'{10}','{11}','{12}')";
  344. //var lis = result.ResultText[0].LIS[0];
  345. sql = string.Format(sql, item.PacsCheckReportId, item.ItemName, item.ReportTime, item.CheckTypeName, item.PositionName, item.StandardItemId, Tools.FormatStr(item.DiagnosResult), item.OrgName, lngPatientID, lngClinicID, no, yzid, item.reportTypeCode);
  346. return Tools.ExecuteSql(sql);
  347. }
  348. public static int GetLis(string id)
  349. {
  350. int total = 0;
  351. string sql = @"Select Count(1) as TOTAL From ZLLPMR.互认_LIS Where LISCHECKREPORTID = '{0}'";
  352. sql = string.Format(sql, id);
  353. Recordset rd = new Recordset();
  354. Tools.QueryTable(sql, out rd);
  355. if (!rd.EOF)
  356. {
  357. rd.MoveFirst();
  358. total = int.Parse(rd.Fields["TOTAL"].Value.ToString());
  359. }
  360. return total;
  361. }
  362. public static void SaveData(Results result, long lngPatientID, long lngClinicID, string no, List<Codes> listlis, List<Codes> listpacs, out long lis_id, out long pacs_id)
  363. {
  364. Log.Info("entered SaveData");
  365. lis_id = -1;
  366. pacs_id = -1;
  367. //Log.Info("666");
  368. var lis = result.ResultText[0].LIS;
  369. var pacs = result.ResultText[0].PACS;
  370. bool state = true;
  371. if (lis != null)
  372. {
  373. //Log.Info("777");
  374. for (int i = 0; i < lis.Count; i++)
  375. {
  376. //long yzid = null;
  377. //string code = lis[i].ItemList[0].StandardItemId;
  378. for (int j = 0; j < lis[i].ItemList.Count; j++)
  379. {
  380. //Log.Info("state:" + state);
  381. if (!state)
  382. {
  383. break;
  384. }
  385. foreach (var items in listlis)
  386. {
  387. //Log.Info("state666");
  388. if (items.code.Contains(lis[i].ItemList[j].StandardItemId))
  389. {
  390. // Log.Info("items.code:" + items.code);
  391. //Log.Info("items.id:" + items.id);
  392. string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  393. //Log.Info("items.code:" + items.code);
  394. Log.Info("items.id:" + items.id);
  395. int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, items.id);
  396. //Log.Info("res:" + res);
  397. if (res > 0)
  398. {
  399. if (lis_id == -1)
  400. {
  401. lis_id = long.Parse(items.id);
  402. }
  403. //Log.Info("res1");
  404. for (int k = 0; k < lis[i].ItemList.Count; k++)
  405. {
  406. //Log.Info("8888");
  407. InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date);
  408. }
  409. }
  410. state = false;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. if (pacs != null)
  417. {
  418. long id = long.Parse(listpacs[0].id);
  419. for (int i = 0; i < pacs.Count; i++)
  420. {
  421. foreach (var items in listpacs)
  422. {
  423. if (pacs[i].reportTypeCode == items.type)
  424. {
  425. id = long.Parse(items.id);
  426. break;
  427. }
  428. }
  429. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, id);
  430. if (res > 0)
  431. {
  432. if (pacs_id == -1)
  433. {
  434. pacs_id = id;
  435. }
  436. }
  437. }
  438. }
  439. Log.Info("end SaveData");
  440. }
  441. public static void SaveDataNew2(Results result, long lngPatientID, long lngClinicID, string no, List<Codes> listlis, List<Codes> listpacs, out List<long> lis_ids, out List<long> pacs_ids)
  442. {
  443. lis_ids = new List<long>();
  444. pacs_ids = new List<long>();
  445. var lis = result.ResultText[0].LIS;
  446. var pacs = result.ResultText[0].PACS;
  447. if (lis != null)
  448. {
  449. Log.Info("lis.Count=" + lis.Count);
  450. foreach (var items in listlis)
  451. {
  452. Log.Info("items.id="+ items.id);
  453. bool state = true;
  454. for (int i = 0; i < lis.Count; i++)
  455. {
  456. Log.Info("state=" + state);
  457. if (!state)
  458. {
  459. break;
  460. }
  461. bool flag = true;
  462. for (int j = 0; j < lis[i].ItemList.Count; j++)
  463. {
  464. Log.Info("flag=" + flag);
  465. //这里判断指标不能循环多次
  466. if (!flag)
  467. {
  468. break;
  469. }
  470. if (items.code.Contains(lis[i].ItemList[j].StandardItemId))
  471. {
  472. string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  473. string xgid = items.id;
  474. int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, xgid);
  475. if (res > 0)
  476. {
  477. lis_ids.Add(long.Parse(xgid));
  478. for (int k = 0; k < lis[i].ItemList.Count; k++)
  479. {
  480. InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date);
  481. }
  482. }
  483. flag = false;
  484. state = false;
  485. }
  486. }
  487. }
  488. }
  489. }
  490. if (pacs != null)
  491. {
  492. Log.Info("pacs.Count=" + pacs.Count);
  493. foreach (var items in listpacs)
  494. {
  495. for (int i = 0; i < pacs.Count; i++)
  496. {
  497. long id = long.Parse(items.id);
  498. if (pacs[i].StandardItemId.Contains(items.code))
  499. {
  500. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, id);
  501. if (res > 0)
  502. {
  503. pacs_ids.Add(id);
  504. }
  505. break;
  506. }
  507. }
  508. }
  509. }
  510. }
  511. /// <summary>
  512. /// 保存互认数据 原来只支持一单
  513. /// </summary>
  514. /// <param name="result"></param>
  515. /// <param name="lngPatientID"></param>
  516. /// <param name="lngClinicID"></param>
  517. /// <param name="no"></param>
  518. /// <param name="listlis"></param>
  519. /// <param name="listpacs"></param>
  520. /// <param name="lis_id"></param>
  521. /// <param name="pacs_id"></param>
  522. public static void SaveDataNew(Results result, long lngPatientID, long lngClinicID, string no, List<Codes> listlis, List<Codes> listpacs, out List<long> lis_ids, out List<long> pacs_ids)
  523. {
  524. lis_ids = new List<long>();
  525. pacs_ids = new List<long>();
  526. var lis = result.ResultText[0].LIS;
  527. var pacs = result.ResultText[0].PACS;
  528. if (lis != null)
  529. {
  530. for (int i = 0; i < lis.Count; i++)
  531. {
  532. bool state = true;
  533. for (int j = 0; j < lis[i].ItemList.Count; j++)
  534. {
  535. if (!state)
  536. {
  537. break;
  538. }
  539. foreach (var items in listlis)
  540. {
  541. if (items.code.Contains(lis[i].ItemList[j].StandardItemId))
  542. {
  543. //insert 互认_lis
  544. string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  545. string xgid = items.id;
  546. int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, xgid);
  547. if (res > 0)
  548. {
  549. lis_ids.Add(long.Parse(xgid));
  550. for (int k = 0; k < lis[i].ItemList.Count; k++)
  551. {
  552. InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date);
  553. }
  554. }
  555. state = false;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. if (pacs != null)
  562. {
  563. long id = long.Parse(listpacs[0].id);
  564. for (int i = 0; i < pacs.Count; i++)
  565. {
  566. id = long.Parse(listpacs[i].id);
  567. foreach (var items in listpacs)
  568. {
  569. if (pacs[i].reportTypeCode == items.type)
  570. {
  571. id = long.Parse(items.id);
  572. break;
  573. }
  574. }
  575. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, id);
  576. if (res > 0)
  577. {
  578. pacs_ids.Add(id);
  579. }
  580. }
  581. }
  582. }
  583. /// <summary>
  584. /// 是否互认
  585. /// </summary>
  586. /// <returns></returns>
  587. public static void IsAgree(out int res, out int date, out int yzzState)
  588. {
  589. res = 1;
  590. date = 20000;
  591. yzzState = 0;
  592. try
  593. {
  594. string sql = @"Select 互认 As AGREE,WAITINGDATE ,一张纸 From zllpmr.互认配置表";
  595. Recordset rd = new Recordset();
  596. Tools.QueryTable(sql, out rd);
  597. if (!rd.EOF)
  598. {
  599. rd.MoveFirst();
  600. res = int.Parse(rd.Fields["AGREE"].Value.ToString());
  601. date = int.Parse(rd.Fields["WAITINGDATE"].Value.ToString());
  602. yzzState = int.Parse(rd.Fields["一张纸"].Value.ToString());
  603. }
  604. }
  605. catch (Exception ex)
  606. {
  607. Log.Info(ex.Message);
  608. Log.Info(ex.StackTrace);
  609. }
  610. }
  611. public static void getUrlYzzCancelMedical(out string url)
  612. {
  613. url = "";
  614. try
  615. {
  616. string sql = @"Select 一张纸URL From zllpmr.互认配置表";
  617. Recordset rd = new Recordset();
  618. Tools.QueryTable(sql, out rd);
  619. if (!rd.EOF)
  620. {
  621. rd.MoveFirst();
  622. url = rd.Fields["一张纸URL"].Value.ToString();
  623. }
  624. }
  625. catch (Exception ex)
  626. {
  627. Log.Info(ex.Message);
  628. Log.Info(ex.StackTrace);
  629. }
  630. }
  631. /// <summary>
  632. /// 仅一张纸使用,查询发送的医嘱
  633. /// </summary>
  634. /// <param name="ZYID"></param>
  635. /// <param name="no"></param>
  636. /// <param name="type"></param>
  637. /// <returns></returns>
  638. public static List<YZData> GetYZList(long fsh)
  639. {
  640. string sql = @"select
  641. to_char(b.ID) as id ,
  642. decode(b.相关id,null,'0.0',to_char(b.相关id)) as 相关id,
  643. to_char(b.前提id ) as 前提id,
  644. to_char(b.病人来源 ) as 病人来源,
  645. to_char(b.病人id )as 病人id,
  646. to_char(b.主页id )as 主页id,
  647. to_char(b.挂号单 )as 挂号单,
  648. to_char(b.婴儿 )as 婴儿,
  649. to_char(b.姓名 )as 姓名,
  650. to_char(b.性别 )as 性别,
  651. to_char(b.年龄 )as 年龄,
  652. to_char(b.病人科室id )as 病人科室id,
  653. to_char(b.序号 )as 序号,
  654. to_char(b.医嘱状态 )as 医嘱状态,
  655. to_char(b.医嘱期效 )as 医嘱期效,
  656. to_char(b.诊疗类别 )as 诊疗类别,
  657. to_char(b.诊疗项目ID )as 诊疗项目ID,
  658. to_char(b.标本部位 )as 标本部位,
  659. to_char(b.检查方法 )as 检查方法,
  660. to_char(b.收费细目id )as 收费细目id,
  661. to_char(b.天数 )as 天数,
  662. to_char(b.单次用量 )as 单次用量,
  663. to_char(b.总给予量 )as 总给予量,
  664. to_char(b.医嘱内容 )as 医嘱内容,
  665. to_char(b.医生嘱托 )as 医生嘱托,
  666. to_char(b.执行科室ID )as 执行科室ID,
  667. to_char(b.执行频次 )as 执行频次,
  668. to_char(b.频率次数 )as 频率次数,
  669. to_char(b.频率间隔 )as 频率间隔,
  670. to_char(b.间隔单位 )as 间隔单位,
  671. to_char(b.执行时间方案 )as 执行时间方案,
  672. to_char(b.计价特性 )as 计价特性,
  673. to_char(b.执行性质 )as 执行性质,
  674. to_char(b.执行标记 )as 执行标记,
  675. to_char(b.可否分零 )as 可否分零,
  676. to_char(b.紧急标志 )as 紧急标志,
  677. to_char(b.开始执行时间,'yyyy-mm-dd hh24:mi:ss' )as 开始执行时间,
  678. to_char(b.执行终止时间 ,'yyyy-mm-dd hh24:mi:ss' )as 执行终止时间,
  679. to_char(b.开嘱科室ID )as 开嘱科室ID,
  680. to_char(b.开嘱医生 )as 开嘱医生,
  681. to_char(b.开嘱时间 ,'yyyy-mm-dd hh24:mi:ss' )as 开嘱时间,
  682. to_char(b.摘要) as 摘要
  683. from 病人医嘱发送 a,病人医嘱记录 b
  684. where b.id = a.医嘱id and 发送号 = {0} and 诊疗类别 in('D','C')
  685. ";
  686. //and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is not null)
  687. sql = string.Format(sql, fsh);
  688. Log.Info("医嘱记录=》》"+sql);
  689. Recordset recordset = new Recordset();
  690. Tools.QueryTable(sql, out recordset);
  691. List<YZData> list = new List<YZData>();
  692. while (!recordset.EOF)
  693. {
  694. YZData yz = new YZData();
  695. yz.ID = recordset.Fields["ID"].Value.ToString();
  696. yz.相关ID = recordset.Fields["相关ID"].Value.ToString();// yz.3767642yz.,
  697. yz.前提ID = recordset.Fields["前提ID"].Value.ToString();// yz.0.0yz.,
  698. yz.病人来源 = recordset.Fields["病人来源"].Value.ToString();// yz.2yz.,
  699. yz.病人ID = recordset.Fields["病人ID"].Value.ToString();// yz.46688yz.,
  700. yz.主页ID = recordset.Fields["主页ID"].Value.ToString();// yz.1yz.,
  701. yz.挂号单 = recordset.Fields["挂号单"].Value.ToString();// yz.yz.,
  702. yz.婴儿 = recordset.Fields["婴儿"].Value.ToString();// yz.0.0yz.,
  703. yz.姓名 = recordset.Fields["姓名"].Value.ToString();// yz.王少清yz.,
  704. yz.性别 = recordset.Fields["性别"].Value.ToString();// yz.男yz.,
  705. yz.年龄 = recordset.Fields["年龄"].Value.ToString();// yz.86yz.,
  706. yz.病人科室ID = recordset.Fields["病人科室ID"].Value.ToString();// yz.232yz.,
  707. yz.序号 = recordset.Fields["序号"].Value.ToString();// yz.87yz.,
  708. yz.医嘱状态 = recordset.Fields["医嘱状态"].Value.ToString();// yz.-1yz.,
  709. yz.医嘱期效 = recordset.Fields["医嘱期效"].Value.ToString();// yz.1yz.,
  710. yz.诊疗类别 = recordset.Fields["诊疗类别"].Value.ToString();// yz.Cyz.,
  711. yz.诊疗项目ID = recordset.Fields["诊疗项目ID"].Value.ToString();// yz.1890yz.,
  712. yz.标本部位 = recordset.Fields["标本部位"].Value.ToString();// yz.静脉血yz.,
  713. yz.检查方法 = recordset.Fields["检查方法"].Value.ToString();// yz.yz.,
  714. yz.收费细目ID = recordset.Fields["收费细目ID"].Value.ToString();// yz.0.0yz.,
  715. yz.天数 = recordset.Fields["天数"].Value.ToString();// yz.0.0yz.,
  716. yz.单次用量 = recordset.Fields["单次用量"].Value.ToString();// yz.0.0yz.,
  717. yz.总给予量 = recordset.Fields["总给予量"].Value.ToString();// yz.1yz.,
  718. yz.医嘱内容 = recordset.Fields["医嘱内容"].Value.ToString();// yz.肝功能yz.,
  719. yz.医生嘱托 = recordset.Fields["医生嘱托"].Value.ToString();// yz.yz.,
  720. yz.执行科室ID = recordset.Fields["执行科室ID"].Value.ToString();// yz.167yz.,
  721. list.Add(yz);
  722. recordset.MoveNext();
  723. }
  724. return list;
  725. }
  726. public static void CancelYzzNew(long 病人id, long 主医嘱id, int lis, int pacs)
  727. {
  728. string sql = @"select c.no ,wm_concat(c.id) FEE_IDS
  729. from 病人医嘱记录 a, 病人医嘱发送 b, 门诊费用记录 c
  730. where b.医嘱id = a.id
  731. and c.医嘱序号 = b.医嘱id
  732. and a.病人id = {0}
  733. and (a.id = {1} or a.相关id = {1})
  734. group by c.no
  735. ";
  736. sql = string.Format(sql, 病人id, 主医嘱id);
  737. Recordset recordset = new Recordset();
  738. Tools.QueryTable(sql, out recordset);
  739. string json = "{\"input\":{\"operator_name\":\"\",\"operator_code\":\"\",\"operator_time\":\"\",\"del_list\":[";
  740. while (!recordset.EOF)
  741. {
  742. string no = recordset.Fields["NO"].Value.ToString();
  743. string fee_ids = recordset.Fields["FEE_IDS"].Value.ToString();
  744. json += "{\"fee_source\":1,\"fee_bill_type\":1,\"fee_no\":\"" + no + "\",\"del_type\":1,\"serial_num\":\"\",\"exe_sta_nums\":\"\",\"fee_ids\":\""+ fee_ids +"\"},";
  745. recordset.MoveNext();
  746. }
  747. json = json.Substring(0, json.Length - 1);
  748. json += "]}}";
  749. //原始调用过程没有作用 改用数据处理平台中转
  750. //Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs);
  751. int lisMessage = 0;
  752. int pacsMessage = 0;
  753. if (lis > 0)
  754. {
  755. lisMessage = 1;
  756. }
  757. if (pacs > 0)
  758. {
  759. pacsMessage = 1;
  760. }
  761. YZZCancelDTO zZCancelDTO = new YZZCancelDTO();
  762. zZCancelDTO.patientId = 病人id.ToString();
  763. zZCancelDTO.medicalOrderId = 主医嘱id.ToString();
  764. zZCancelDTO.jsonIn = json;
  765. zZCancelDTO.lisMessage = lisMessage.ToString();
  766. zZCancelDTO.pacsMessage = pacsMessage.ToString();
  767. string url = "http://172.30.0.66:7000/cancelMedicalForYzz";
  768. getUrlYzzCancelMedical(out url);
  769. Log.Info("url=" + url);
  770. string body = JSON.ObjectToJson<YZZCancelDTO>(zZCancelDTO, Encoding.UTF8);
  771. Log.Info("body==" + body);
  772. string resultString = HttpUtils.WSCenterData(url, body);
  773. Log.Info("resultString==" + resultString);
  774. }
  775. /// <summary>
  776. /// 作废医嘱
  777. /// </summary>
  778. public static void CancelYz(long 病人id, long 主医嘱id, int lis, int pacs)
  779. {
  780. string sql = @"select distinct c.no
  781. from 病人医嘱记录 a, 病人医嘱发送 b, 门诊费用记录 c
  782. where b.医嘱id = a.id
  783. and c.医嘱序号 = b.医嘱id
  784. and a.病人id = {0}
  785. and (a.id = {1} or a.相关id = {1})";
  786. sql = string.Format(sql, 病人id, 主医嘱id);
  787. Recordset recordset = new Recordset();
  788. Tools.QueryTable(sql, out recordset);
  789. string json = "{\"input\":{\"operator_name\":\"\",\"operator_code\":\"\",\"operator_time\":\"\",\"del_list\":[";
  790. while (!recordset.EOF)
  791. {
  792. string no = recordset.Fields["NO"].Value.ToString();
  793. json += "{\"fee_source\":1,\"fee_bill_type\":1,\"fee_no\":\"" + no + "\",\"del_type\":2,\"serial_num\":\"\",\"exe_sta_nums\":\"\",\"fee_ids\":\"\"},";
  794. recordset.MoveNext();
  795. }
  796. json = json.Substring(0, json.Length - 1);
  797. json += "]}}";
  798. //原始调用过程没有作用 改用数据处理平台中转
  799. //Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs);
  800. int lisMessage = 0;
  801. int pacsMessage = 0;
  802. //调有 http
  803. /* Dictionary<string, string> body = new Dictionary<string, string>();
  804. body.Add("patientId", 病人id.ToString());
  805. body.Add("medicalOrderId", 主医嘱id.ToString());
  806. body.Add("jsonIn", json);
  807. if (lis > 0)
  808. {
  809. lisMessage = 1;
  810. }
  811. if (pacs > 0)
  812. {
  813. pacsMessage = 1;
  814. }
  815. body.Add("lisMessage", lisMessage.ToString());
  816. body.Add("pacsMessage", pacsMessage.ToString());*/
  817. if (lis > 0)
  818. {
  819. lisMessage = 1;
  820. }
  821. if (pacs > 0)
  822. {
  823. pacsMessage = 1;
  824. }
  825. YZZCancelDTO zZCancelDTO = new YZZCancelDTO();
  826. zZCancelDTO.patientId = 病人id.ToString();
  827. zZCancelDTO.medicalOrderId = 主医嘱id.ToString();
  828. zZCancelDTO.jsonIn = json;
  829. zZCancelDTO.lisMessage = lisMessage.ToString();
  830. zZCancelDTO.pacsMessage = pacsMessage.ToString();
  831. string url = "http://172.30.0.66:7000/cancelMedicalForYzz";
  832. getUrlYzzCancelMedical(out url);
  833. Log.Info("url=" + url);
  834. string body = JSON.ObjectToJson<YZZCancelDTO>(zZCancelDTO, Encoding.UTF8);
  835. Log.Info("body==" + body);
  836. string resultString = HttpUtils.WSCenterData(url, body);
  837. Log.Info("resultString==" + resultString);
  838. }
  839. }
  840. }