LisPacs_MR_Bll.cs 41 KB

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