LisPacs_MR_Bll.cs 44 KB

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