LisPacs_MR_Bll.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. nvl(a.住院号,b.留观号) ""businessNumber"",
  175. '{2}' ""standardItemId"",
  176. TO_CHAR(SYSDATE-30, 'YYYY-MM-DD HH24:MI:SS') ""reportStartTime"",
  177. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""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. TO_CHAR(SYSDATE-30, 'YYYY-MM-DD HH24:MI:SS') ""reportStartTime"",
  213. TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') ""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, long yzID)
  380. {
  381. string sql = @"Insert Into ZLLPMR.互认_LIS(LISCHECKREPORTID,REPORTNAME,ORGNAME,REPORTTIME,病人ID,主页ID,TIME,OPERATORNO,医嘱id,相关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},{9})";
  383. sql = string.Format(sql, lis.LisCheckReportId, lis.ReportName, lis.OrgName, lis.ReportTime, lngPatientID, lngClinicID, date, no, yzXgID,yzID);
  384. Log.Info("InsertLis:" + sql);
  385. int res = Tools.ExecuteSql(sql);
  386. return res;
  387. }
  388. public static int 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. return Tools.ExecuteSql(sql);
  395. }
  396. public static int InsertPacs(PACSItem item, long lngPatientID, long lngClinicID, string no,long yzxgid,long yzid)
  397. {
  398. string sql = @"Insert Into ZLLPMR.互认_PACS(PACSCHECKREPORTID,ITEMNAME,REPORTTIME,CHECKTYPENAME,POSITIONNAME,STANDARDITEMID,DIAGNOSRESULT,ORGNAME,病人ID,主页ID,TIME,OPERATORNO,医嘱id,REPORTTYPECODE,相关id)
  399. Values('{0}','{1}',to_date('{2}','yyyy/mm/dd hh24:mi:ss'),'{3}','{4}','{5}','{6}','{7}',{8},{9},sysdate,'{10}','{11}','{12}','{13}')";
  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, yzxgid, item.reportTypeCode,yzid);
  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), long.Parse(items.yzid));
  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 xgid =long.Parse(listpacs[0].id);
  470. long yzid =long.Parse(listpacs[0].yzid);
  471. for (int i = 0; i < pacs.Count; i++)
  472. {
  473. foreach (var items in listpacs)
  474. {
  475. if (pacs[i].reportTypeCode == items.type)
  476. {
  477. xgid = long.Parse(items.id);
  478. yzid = long.Parse(items.yzid);
  479. break;
  480. }
  481. }
  482. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, xgid, yzid);
  483. if (res > 0)
  484. {
  485. if (pacs_id == -1)
  486. {
  487. pacs_id = xgid;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. /// <summary>
  494. /// 保存互认数据 原来只支持一单
  495. /// </summary>
  496. /// <param name="result"></param>
  497. /// <param name="lngPatientID"></param>
  498. /// <param name="lngClinicID"></param>
  499. /// <param name="no"></param>
  500. /// <param name="listlis"></param>
  501. /// <param name="listpacs"></param>
  502. /// <param name="lis_id"></param>
  503. /// <param name="pacs_id"></param>
  504. 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)
  505. {
  506. lis_id = -1;
  507. pacs_id = -1;
  508. var lis = result.ResultText[0].LIS;
  509. var pacs = result.ResultText[0].PACS;
  510. if (lis != null)
  511. {
  512. for (int i = 0; i < lis.Count; i++)
  513. {
  514. bool state = true;
  515. for (int j = 0; j < lis[i].ItemList.Count; j++)
  516. {
  517. if (!state)
  518. {
  519. break;
  520. }
  521. foreach (var items in listlis)
  522. {
  523. if (items.code.Contains(lis[i].ItemList[j].StandardItemId))
  524. {
  525. //insert 互认_lis
  526. string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  527. string xgid = items.id;
  528. string yzid = items.yzid;
  529. int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, long.Parse(xgid), long.Parse(yzid));
  530. if (res > 0)
  531. {
  532. if (lis_id == -1)
  533. {
  534. lis_id = long.Parse(xgid);
  535. }
  536. for (int k = 0; k < lis[i].ItemList.Count; k++)
  537. {
  538. InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date);
  539. }
  540. }
  541. state = false;
  542. }
  543. }
  544. }
  545. }
  546. }
  547. if (pacs != null)
  548. {
  549. // long id = long.Parse(listpacs[0].id);
  550. long xgid = long.Parse(listpacs[0].id);
  551. long yzid = long.Parse(listpacs[0].yzid);
  552. for (int i = 0; i < pacs.Count; i++)
  553. {
  554. foreach (var items in listpacs)
  555. {
  556. if (pacs[i].reportTypeCode == items.type)
  557. {
  558. xgid = long.Parse(items.id);
  559. yzid = long.Parse(items.yzid);
  560. break;
  561. }
  562. }
  563. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, xgid, yzid);
  564. if (res > 0)
  565. {
  566. if (pacs_id == -1)
  567. {
  568. pacs_id = xgid;
  569. }
  570. }
  571. }
  572. }
  573. }
  574. 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)
  575. {
  576. lis_id = -1;
  577. pacs_id = -1;
  578. var lis = result.ResultText[0].LIS;
  579. var pacs = result.ResultText[0].PACS;
  580. if (lis != null)
  581. {
  582. Log.Info("lis.Count=" + lis.Count);
  583. foreach (var items in listlis)
  584. {
  585. Log.Info("items.id=" + items.id);
  586. bool state = true;
  587. for (int i = 0; i < lis.Count; i++)
  588. {
  589. Log.Info("state=" + state);
  590. if (!state)
  591. {
  592. break;
  593. }
  594. bool flag = true;
  595. for (int j = 0; j < lis[i].ItemList.Count; j++)
  596. {
  597. Log.Info("flag=" + flag);
  598. //这里判断指标不能循环多次
  599. if (!flag)
  600. {
  601. break;
  602. }
  603. if (items.code.Contains(lis[i].ItemList[j].StandardItemId))
  604. {
  605. string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  606. long xgid = long.Parse(items.id);
  607. long yzid = long.Parse(items.yzid);
  608. int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, xgid, yzid);
  609. if (res > 0)
  610. {
  611. lis_id= xgid;
  612. for (int k = 0; k < lis[i].ItemList.Count; k++)
  613. {
  614. InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date);
  615. }
  616. }
  617. flag = false;
  618. state = false;
  619. }
  620. }
  621. }
  622. }
  623. }
  624. if (pacs != null)
  625. {
  626. Log.Info("pacs.Count=" + pacs.Count);
  627. foreach (var items in listpacs)
  628. {
  629. for (int i = 0; i < pacs.Count; i++)
  630. {
  631. long yzxgid = long.Parse(items.id);
  632. long yzid = long.Parse(items.yzid);
  633. if (pacs[i].StandardItemId.Contains(items.code))
  634. {
  635. int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, yzxgid, yzid);
  636. if (res > 0)
  637. {
  638. pacs_id= yzxgid;
  639. }
  640. break;
  641. }
  642. }
  643. }
  644. }
  645. }
  646. /// <summary>
  647. /// 是否互认
  648. /// </summary>
  649. /// <returns></returns>
  650. public static void IsAgree(out int res,out int date,out int yzzState,out bool isForceSace)
  651. {
  652. res = 1;
  653. date = 20000;
  654. yzzState = 0;
  655. isForceSace = false;
  656. try
  657. {
  658. string sql = @"Select 互认 As AGREE,WAITINGDATE,isForceSace From zllpmr.互认配置表";
  659. Recordset rd = new Recordset();
  660. Tools.QueryTable(sql, out rd);
  661. if (!rd.EOF)
  662. {
  663. rd.MoveFirst();
  664. res = int.Parse(rd.Fields["AGREE"].Value.ToString());
  665. date = int.Parse(rd.Fields["WAITINGDATE"].Value.ToString());
  666. isForceSace = bool.Parse(rd.Fields["isForceSace"].Value.ToString());
  667. //yzzState = int.Parse(rd.Fields["一张纸"].Value.ToString());
  668. }
  669. }
  670. catch (Exception ex)
  671. {
  672. Log.Info(ex.Message);
  673. Log.Info(ex.StackTrace);
  674. }
  675. }
  676. public static void getUrlYzzCancelMedical(out string url)
  677. {
  678. url = "";
  679. try
  680. {
  681. string sql = @"Select 一张纸URL From zllpmr.互认配置表";
  682. Recordset rd = new Recordset();
  683. Tools.QueryTable(sql, out rd);
  684. if (!rd.EOF)
  685. {
  686. rd.MoveFirst();
  687. url = int.Parse(rd.Fields["一张纸URL"].Value.ToString());
  688. }
  689. }
  690. catch (Exception ex)
  691. {
  692. Log.Info(ex.Message);
  693. Log.Info(ex.StackTrace);
  694. }
  695. }
  696. /// <summary>
  697. /// 是否互认
  698. /// </summary>
  699. /// <returns></returns>
  700. public static void ExistHuRemYz(out long limit_day)
  701. {
  702. limit_day = 1;
  703. try
  704. {
  705. string sql = @"Select limit_day From zllpmr.互认配置表";
  706. Recordset rd = new Recordset();
  707. Tools.QueryTable(sql, out rd);
  708. if (!rd.EOF)
  709. {
  710. rd.MoveFirst();
  711. limit_day = long.Parse(rd.Fields["limit_day"].Value.ToString());
  712. }
  713. }
  714. catch (Exception ex)
  715. {
  716. Log.Info(ex.Message);
  717. Log.Info(ex.StackTrace);
  718. }
  719. }
  720. /// <summary>
  721. /// 仅一张纸使用,查询发送的医嘱
  722. /// </summary>
  723. /// <param name="ZYID"></param>
  724. /// <param name="no"></param>
  725. /// <param name="type"></param>
  726. /// <returns></returns>
  727. public static List<YZData> GetYZList(long fsh)
  728. {
  729. string sql = @"select
  730. to_char(b.ID) as id ,
  731. decode(b.相关id,null,'0.0',to_char(b.相关id)) as 相关id,
  732. to_char(b.前提id ) as 前提id,
  733. to_char(b.病人来源 ) as 病人来源,
  734. to_char(b.病人id )as 病人id,
  735. to_char(b.主页id )as 主页id,
  736. to_char(b.挂号单 )as 挂号单,
  737. to_char(b.婴儿 )as 婴儿,
  738. to_char(b.姓名 )as 姓名,
  739. to_char(b.性别 )as 性别,
  740. to_char(b.年龄 )as 年龄,
  741. to_char(b.病人科室id )as 病人科室id,
  742. to_char(b.序号 )as 序号,
  743. to_char(b.医嘱状态 )as 医嘱状态,
  744. to_char(b.医嘱期效 )as 医嘱期效,
  745. to_char(b.诊疗类别 )as 诊疗类别,
  746. to_char(b.诊疗项目ID )as 诊疗项目ID,
  747. to_char(b.标本部位 )as 标本部位,
  748. to_char(b.检查方法 )as 检查方法,
  749. to_char(b.收费细目id )as 收费细目id,
  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.执行科室ID )as 执行科室ID,
  756. to_char(b.执行频次 )as 执行频次,
  757. to_char(b.频率次数 )as 频率次数,
  758. to_char(b.频率间隔 )as 频率间隔,
  759. to_char(b.间隔单位 )as 间隔单位,
  760. to_char(b.执行时间方案 )as 执行时间方案,
  761. to_char(b.计价特性 )as 计价特性,
  762. to_char(b.执行性质 )as 执行性质,
  763. to_char(b.执行标记 )as 执行标记,
  764. to_char(b.可否分零 )as 可否分零,
  765. to_char(b.紧急标志 )as 紧急标志,
  766. to_char(b.开始执行时间,'yyyy-mm-dd hh24:mi:ss' )as 开始执行时间,
  767. to_char(b.执行终止时间 ,'yyyy-mm-dd hh24:mi:ss' )as 执行终止时间,
  768. to_char(b.开嘱科室ID )as 开嘱科室ID,
  769. to_char(b.开嘱医生 )as 开嘱医生,
  770. to_char(b.开嘱时间 ,'yyyy-mm-dd hh24:mi:ss' )as 开嘱时间,
  771. to_char(b.摘要) as 摘要
  772. from 病人医嘱发送 a,病人医嘱记录 b
  773. where b.id = a.医嘱id and 发送号 = {0} and 诊疗类别 in('D','C')
  774. and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is null)";
  775. // and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is not null)
  776. sql = string.Format(sql, fsh);
  777. Recordset recordset = new Recordset();
  778. Tools.QueryTable(sql, out recordset);
  779. List<YZData> list = new List<YZData>();
  780. while (!recordset.EOF)
  781. {
  782. YZData yz = new YZData();
  783. yz.ID = recordset.Fields["ID"].Value.ToString();
  784. yz.相关ID = recordset.Fields["相关ID"].Value.ToString();// yz.3767642yz.,
  785. yz.前提ID = recordset.Fields["前提ID"].Value.ToString();// yz.0.0yz.,
  786. yz.病人来源 = recordset.Fields["病人来源"].Value.ToString();// yz.2yz.,
  787. yz.病人ID = recordset.Fields["病人ID"].Value.ToString();// yz.46688yz.,
  788. yz.主页ID = recordset.Fields["主页ID"].Value.ToString();// yz.1yz.,
  789. yz.挂号单 = recordset.Fields["挂号单"].Value.ToString();// yz.yz.,
  790. yz.婴儿 = recordset.Fields["婴儿"].Value.ToString();// yz.0.0yz.,
  791. yz.姓名 = recordset.Fields["姓名"].Value.ToString();// yz.王少清yz.,
  792. yz.性别 = recordset.Fields["性别"].Value.ToString();// yz.男yz.,
  793. yz.年龄 = recordset.Fields["年龄"].Value.ToString();// yz.86yz.,
  794. yz.病人科室ID = recordset.Fields["病人科室ID"].Value.ToString();// yz.232yz.,
  795. yz.序号 = recordset.Fields["序号"].Value.ToString();// yz.87yz.,
  796. yz.医嘱状态 = recordset.Fields["医嘱状态"].Value.ToString();// yz.-1yz.,
  797. yz.医嘱期效 = recordset.Fields["医嘱期效"].Value.ToString();// yz.1yz.,
  798. yz.诊疗类别 = recordset.Fields["诊疗类别"].Value.ToString();// yz.Cyz.,
  799. yz.诊疗项目ID = recordset.Fields["诊疗项目ID"].Value.ToString();// yz.1890yz.,
  800. yz.标本部位 = recordset.Fields["标本部位"].Value.ToString();// yz.静脉血yz.,
  801. yz.检查方法 = recordset.Fields["检查方法"].Value.ToString();// yz.yz.,
  802. yz.收费细目ID = recordset.Fields["收费细目ID"].Value.ToString();// yz.0.0yz.,
  803. yz.天数 = recordset.Fields["天数"].Value.ToString();// yz.0.0yz.,
  804. yz.单次用量 = recordset.Fields["单次用量"].Value.ToString();// yz.0.0yz.,
  805. yz.总给予量 = recordset.Fields["总给予量"].Value.ToString();// yz.1yz.,
  806. yz.医嘱内容 = recordset.Fields["医嘱内容"].Value.ToString();// yz.肝功能yz.,
  807. yz.医生嘱托 = recordset.Fields["医生嘱托"].Value.ToString();// yz.yz.,
  808. yz.执行科室ID = recordset.Fields["执行科室ID"].Value.ToString();// yz.167yz.,
  809. list.Add(yz);
  810. recordset.MoveNext();
  811. }
  812. return list;
  813. }
  814. /// <summary>
  815. /// 作废医嘱
  816. /// </summary>
  817. public static void CancelYz(long 病人id, long 主医嘱id, int lis, int pacs)
  818. {
  819. string sql = @"select distinct c.no
  820. from 病人医嘱记录 a, 病人医嘱发送 b, 门诊费用记录 c
  821. where b.医嘱id = a.id
  822. and c.医嘱序号 = b.医嘱id
  823. and a.病人id = {0}
  824. and (a.id = {1} or a.相关id = {1})";
  825. sql = string.Format(sql, 病人id, 主医嘱id);
  826. Recordset recordset = new Recordset();
  827. Tools.QueryTable(sql, out recordset);
  828. string json = "{\"input\":{\"operator_name\":\"\",\"operator_code\":\"\",\"operator_time\":\"\",\"del_list\":[";
  829. while (!recordset.EOF)
  830. {
  831. string no = recordset.Fields["NO"].Value.ToString();
  832. json += "{\"fee_source\":1,\"fee_bill_type\":1,\"fee_no\":\""+ no + "\",\"del_type\":2,\"serial_num\":\"\",\"exe_sta_nums\":\"\",\"fee_ids\":\"\"},";
  833. recordset.MoveNext();
  834. }
  835. json = json.Substring(0,json.Length - 1);
  836. json += "]}}";
  837. //原始调用过程没有作用 改用数据处理平台中转
  838. //Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs);
  839. int lisMessage = 0;
  840. int pacsMessage = 0;
  841. //调有 http
  842. Dictionary<string, string> body = new Dictionary<string, string>();
  843. body.Add("patientId", 病人id.ToString());
  844. body.Add("medicalOrderId", 主医嘱id.ToString());
  845. body.Add("jsonIn", json);
  846. if (lis>0)
  847. {
  848. lisMessage = 1;
  849. }
  850. if (pacs>0)
  851. {
  852. pacsMessage = 1;
  853. }
  854. body.Add("lisMessage", lisMessage.ToString());
  855. body.Add("pacsMessage", pacsMessage.ToString());
  856. string url = "http://172.30.0.66:7000/cancelMedicalForYzz";
  857. getUrlYzzCancelMedical(out url);
  858. Log.Info("url="+ url);
  859. string resultString = HttpUtils.WSCenterData(url, body.ToString());
  860. Log.Info("resultString==" + resultString);
  861. }
  862. /*public List<BillProjectUpload> GetBillProjects(long lngSendID,string hostName,string patientId)
  863. {
  864. List<BillProjectUpload> billList = new List<BillProjectUpload>();
  865. List<YZData> list = GetYZList(lngSendID);
  866. for (var i = 0; i < list.Count; i++)
  867. {
  868. if (list[i].诊疗类别 == "C" && list[i].相关ID != "0.0")
  869. {
  870. string code = "";
  871. int total = 0;
  872. IsLisProject(list[i].诊疗项目ID, out code, out total);
  873. if (total > 0)
  874. {
  875. //进来才说明是互认项目
  876. BillProjectUpload billProject = new BillProjectUpload();
  877. billProject.billProjectName = list[i].医嘱内容;
  878. billProject.billName = list[i].开嘱医生;
  879. billProject.billTime = DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss");
  880. billProject.billType = "C";
  881. billProject.computerName = hostName;
  882. billProject.patientId = patientId;
  883. billProject.medicId = list[i].ID;
  884. billList.Add(billProject);
  885. }
  886. }
  887. else if (list[i].诊疗类别 == "D" && list[i].相关ID != "0.0")
  888. {
  889. int total = 0;
  890. string type = "";
  891. String param = list[i].诊疗项目ID + "_" + list[i].标本部位 + "_" + list[i].检查方法;
  892. IsPacsProject(param, out total, out type);
  893. if (total > 0)
  894. {
  895. //进来才说明是互认项目
  896. BillProjectUpload billProject = new BillProjectUpload();
  897. billProject.billProjectName = list[i].医嘱内容;
  898. billProject.billName = Infos.UserInfo.编号;
  899. billProject.billTime = DateTime.Now.ToString("yyyy-MM-DD HH:mm:ss");
  900. billProject.billType = "D";
  901. billProject.computerName = hostName;
  902. billProject.patientId = patientId;
  903. billProject.medicId = list[i].ID;
  904. billList.Add(billProject);
  905. }
  906. }
  907. }
  908. if(billList.Count>0)
  909. {
  910. //保存开单数据
  911. }
  912. return billList;
  913. }*/
  914. }
  915. }