PrescriptionCirculation.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PTMedicalInsurance.Common;
  11. using PTMedicalInsurance.Helper;
  12. using PTMedicalInsurance.FormSetter;
  13. using PTMedicalInsurance.Business;
  14. using PTMedicalInsurance.Variables;
  15. using System.IO;
  16. using Newtonsoft.Json.Linq;
  17. namespace PTMedicalInsurance.Forms
  18. {
  19. public partial class PrescriptionCirculation : Form
  20. {
  21. //设置业务实例
  22. CenterBusiness cBus = new CenterBusiness();
  23. HisMainBusiness hBus = new HisMainBusiness();
  24. HisIrisServices hIS = new HisIrisServices();
  25. MIIrisServices mIS = new MIIrisServices();
  26. InvokeHelper invoker = new InvokeHelper();
  27. InsuServices iris = new InsuServices();
  28. public string patInfo = "", ReadCardOutParam = "", CertNo = "";
  29. public string AdmID = "", AdmLoc = "", AdmDoc = "";
  30. //1.声明自适应类实例
  31. AutoResizeForm asc = new AutoResizeForm();
  32. public PrescriptionCirculation()
  33. {
  34. InitializeComponent();
  35. asc.controllInitializeSize(this);
  36. asc.controlAutoSize(this);
  37. GridViewSetter grdSetter = new GridViewSetter();
  38. grdSetter.SetHeaderTextOfHISRegister(dgv_HISRegInfo);
  39. grdSetter.SetHeaderTextOfHISPrescFee(dgv_PrescriptionInfo);
  40. grdSetter.DatagridviewColumnWidthAdaptation(dgv_HISRegInfo);
  41. grdSetter.DatagridviewColumnWidthAdaptation(dgv_PrescriptionInfo);
  42. dtST.Text = DateTime.Now.ToString("yyyy-MM-01 00:00:00");
  43. dtED.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  44. if (CertNo != "")
  45. {
  46. string outParam = "";
  47. DataTable dt = null;
  48. if (GetHISRegInfo("2023-06-14 00:00:00", "2023-06-14 23:59:59", "45050219890708002X", ref outParam, ref dt) != 0)
  49. {
  50. MessageBox.Show(outParam);
  51. return;
  52. }
  53. dgv_HISRegInfo.DataSource = dt;
  54. }
  55. }
  56. public PrescriptionCirculation(string PatInfo)
  57. {
  58. InitializeComponent();
  59. asc.controllInitializeSize(this);
  60. asc.controlAutoSize(this);
  61. GridViewSetter grdSetter = new GridViewSetter();
  62. grdSetter.SetHeaderTextOfHISRegister(dgv_HISRegInfo);
  63. grdSetter.SetHeaderTextOfHISPrescFee(dgv_PrescriptionInfo);
  64. grdSetter.DatagridviewColumnWidthAdaptation(dgv_HISRegInfo);
  65. grdSetter.DatagridviewColumnWidthAdaptation(dgv_PrescriptionInfo);
  66. dtST.Text = DateTime.Now.ToString("yyyy-MM-01 00:00:00");
  67. dtED.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  68. if (PatInfo != "")
  69. {
  70. string outParam = "";
  71. DataTable dt = null;
  72. if (GetHISRegInfo(dtST.Text, dtED.Text, PatInfo, ref outParam, ref dt) != 0)
  73. {
  74. MessageBox.Show(outParam);
  75. return;
  76. }
  77. dgv_HISRegInfo.DataSource = dt;
  78. tb_CertNo.Text = PatInfo;
  79. }
  80. }
  81. /// <summary>
  82. /// 获取HIS就诊信息
  83. /// </summary>
  84. /// <param name="dtST"></param>
  85. /// <param name="dtED"></param>
  86. /// <param name="PatInfo"></param>
  87. /// <param name="errMsg"></param>
  88. /// <param name="DT"></param>
  89. /// <returns></returns>
  90. private int GetHISRegInfo(string dtST,string dtED,string PatInfo,ref string errMsg,ref DataTable DT)
  91. {
  92. dynamic joTmp = new JObject();
  93. joTmp.Add("stDate", dtST);
  94. joTmp.Add("endDate", dtED);
  95. joTmp.Add("patInfo", PatInfo);
  96. JObject joRtnHISRegInfo = hIS.GetHISRegInfo(joTmp);
  97. if (JsonHelper.parseIrisRtnValue(joRtnHISRegInfo, out errMsg) != 0)
  98. {
  99. errMsg = "获取HIS患者就诊信息失败,请联系管理员!" + errMsg;
  100. return -1;
  101. }
  102. else
  103. {
  104. if ((joRtnHISRegInfo["result"]["rows"].ToString() == "[]"))
  105. {
  106. errMsg = "查询HIS就诊信息结果为空!";
  107. return -1;
  108. }
  109. else
  110. {
  111. DT = (DataTable)joRtnHISRegInfo["result"]["rows"].ToObject(typeof(DataTable));
  112. return 0;
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 获取HIS费用明细信息
  118. /// </summary>
  119. /// <param name="PrescNo"></param>
  120. /// <param name="errMsg"></param>
  121. /// <param name="DT"></param>
  122. /// <returns></returns>
  123. private int GetHISPrescFeeInfo(string PrescNo, ref string errMsg, ref DataTable DT)
  124. {
  125. dynamic joTmp = new JObject();
  126. joTmp.Add("prescNo", PrescNo);
  127. JObject joRtnHISPrescFeeInfo = hIS.GetHISPrescFeeInfo(joTmp);
  128. if (JsonHelper.parseIrisRtnValue(joRtnHISPrescFeeInfo, out errMsg) != 0)
  129. {
  130. errMsg = "获取HIS患者处方信息失败,请联系管理员!" + errMsg;
  131. return -1;
  132. }
  133. else
  134. {
  135. if ((joRtnHISPrescFeeInfo["result"]["rows"].ToString() == "[]"))
  136. {
  137. errMsg = "查询HIS处方信息结果为空!";
  138. return -1;
  139. }
  140. else
  141. {
  142. DT = (DataTable)joRtnHISPrescFeeInfo["result"]["rows"].ToObject(typeof(DataTable));
  143. return 0;
  144. }
  145. }
  146. }
  147. /// <summary>
  148. /// 获取医保挂号信息-医保平台
  149. /// </summary>
  150. /// <returns></returns>
  151. private int GetInsuRegInfo(ref string errMsg)
  152. {
  153. AdmID = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["admID"].Value.ToString();
  154. AdmDoc = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["doc"].Value.ToString();
  155. AdmLoc = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["loc"].Value.ToString();
  156. string sqlStr = " SELECT top 1 * FROM BS_MedInsuRegisterInfo " //DateDiff(dd,OccurTime,getdate())=0
  157. + " WHERE Type=3 And RegState=1 "
  158. + " and OccurTime> '" + dtST.Text + "' And OccurTime<'" + dtED.Text + "'"
  159. + " and Hospital_Dr='" + Global.inf.hospitalDr + "'" //and PersonalNO='" + Global.pat.psn_no + "'
  160. + " and Adm_Dr='" + AdmID + "'"
  161. + " And AdmInDepName='" + AdmLoc + "'"
  162. + " And ChiefPhyDocName='" + AdmDoc + "'"
  163. + " ORDER BY ID DESC ";
  164. JObject joSqlstr = new JObject();
  165. joSqlstr.Add("sqlStr", sqlStr);
  166. JArray jaParam = new JArray();
  167. jaParam.Add(joSqlstr);
  168. JObject joSettlQuery = new JObject();
  169. joSettlQuery.Add("params", jaParam);
  170. joSettlQuery.Add("code", "09010062");
  171. InvokeHelper invoker = new InvokeHelper();
  172. JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询门诊挂号");
  173. try
  174. {
  175. if (joRtn["result"]["data"].ToString() == "[]")
  176. {
  177. errMsg = "医保挂号查询结果为空!";
  178. return -1;
  179. }
  180. else
  181. {
  182. DataTable dtInsu = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
  183. if (dtInsu.Rows.Count > 1)
  184. {
  185. //gb_InsuReg.Visible = true;
  186. errMsg="注意:该患者存在多条医保挂号记录!";
  187. Global.pat.mdtrtID = dtInsu.Rows[0]["InsuRegID"].ToString();
  188. }
  189. else
  190. {
  191. Global.pat.mdtrtID = dtInsu.Rows[0]["InsuRegID"].ToString();
  192. }
  193. }
  194. return 0;
  195. }
  196. catch (Exception eX)
  197. {
  198. MessageBox.Show(eX.Message);
  199. return -1;
  200. }
  201. }
  202. private int GetPreVerificationInput(string AdmID,string prescNo,ref string outParam)
  203. {
  204. dynamic joTmp = new JObject();
  205. joTmp.Add("prescNo", prescNo);
  206. joTmp.Add("admID", AdmID);
  207. JObject joRtnPreVerificationData = hIS.GetPreVerificationData(joTmp);
  208. if (JsonHelper.parseIrisRtnValue(joRtnPreVerificationData, out outParam) != 0)
  209. {
  210. outParam = "获取处方流传预核验数据失败,请联系管理员!" + outParam;
  211. return -1;
  212. }
  213. else
  214. {
  215. if (joRtnPreVerificationData["dllinput"]["params"].ToString() == "[]")
  216. {
  217. outParam = "获取处方流传预核验数据结果为空!";
  218. return -1;
  219. }
  220. else
  221. {
  222. outParam = joRtnPreVerificationData["dllinput"]["params"].ToString();
  223. }
  224. return 0;
  225. }
  226. }
  227. private void btnClose_Click(object sender, EventArgs e)
  228. {
  229. Close();
  230. }
  231. private void btnPresUpload_Click(object sender, EventArgs e)
  232. {
  233. }
  234. private void dgv_HISRegInfo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  235. {
  236. string outParam = "";
  237. DataTable dt = null;
  238. string prescNo = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["prescNo"].Value.ToString();
  239. string admID = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["admID"].Value.ToString();
  240. if (prescNo == "") return;
  241. //获取HIS处方明细信息
  242. if (GetHISPrescFeeInfo(prescNo, ref outParam, ref dt) != 0)
  243. {
  244. MessageBox.Show(outParam);
  245. return;
  246. }
  247. dgv_PrescriptionInfo.DataSource = dt;
  248. }
  249. private void btnUpload_Pre_Click(object sender, EventArgs e)
  250. {
  251. if ((dgv_HISRegInfo.Rows.Count == 0) || (dgv_PrescriptionInfo.Rows.Count == 0))
  252. {
  253. MessageBox.Show("请先查询该患者HIS就诊信息和处方信息!");
  254. return;
  255. }
  256. string OutMsg = "";
  257. string prescNo = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["prescNo"].Value.ToString();
  258. string admID = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["admID"].Value.ToString();
  259. //获取医保挂号信息
  260. if (GetInsuRegInfo(ref OutMsg) == 0)
  261. {
  262. MessageBox.Show(Global.pat.mdtrtID);
  263. }
  264. JObject joPreInput = new JObject();
  265. if (GetPreVerificationInput(admID, prescNo, ref OutMsg) != 0)
  266. {
  267. MessageBox.Show(OutMsg);
  268. return;
  269. }
  270. return;
  271. #region【电子处方预核验流程】
  272. ///【查询当前病人是否已门诊挂号】 比对HIS就诊记录与医保登记记录表信息
  273. if (Global.pat.mdtrtID == "")
  274. {
  275. #region【读卡】
  276. string errMsg, outParam;
  277. if (ReadCardOutParam == "")
  278. {
  279. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  280. if (hBus.readCard(out ReadCardOutParam) != 0)
  281. {
  282. MessageBox.Show(JsonHelper.setExceptionJson(-100, "读卡失败!", ReadCardOutParam).ToString());
  283. return;
  284. }
  285. else
  286. {
  287. //展示患者信息界面
  288. if (hBus.showPatInfo(ReadCardOutParam, out patInfo) != 0)
  289. {
  290. MessageBox.Show("读卡成功,展示患者信息界面失败:" + patInfo);
  291. return;
  292. }
  293. if (hBus.setGlobalPatAfaterShowPatInfo(ReadCardOutParam, out errMsg) != 0)
  294. {
  295. MessageBox.Show(JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString());
  296. return;
  297. }
  298. }
  299. }
  300. #endregion
  301. #region【医保挂号-就诊信息上传】
  302. patInfo = ReadCardOutParam;
  303. if (hBus.setGlobalPatAfaterShowPatInfo(patInfo, out errMsg) != 0)
  304. {
  305. MessageBox.Show(JsonHelper.setExceptionJson(-1, "setGlobalPatAfaterShowPatInfo", errMsg).ToString());
  306. return;
  307. }
  308. //显示登记面板
  309. if (hBus.showOutPatRegisterForm(out outParam) != 0)
  310. {
  311. MessageBox.Show(JsonHelper.setExceptionJson(-1, "显示登记面板", outParam).ToString());
  312. return;
  313. }
  314. JObject joReg = JObject.Parse(outParam);
  315. //医保挂号
  316. JObject jo2201Inpar = JObject.Parse(JsonHelper.getDestProperty(joReg, "data"));
  317. JObject jo2201Inpar_plain = JObject.Parse(JsonHelper.getDestProperty(joReg, "data"));
  318. jo2201Inpar = JObject.Parse(JsonHelper.setCenterInpar("2201", jo2201Inpar));
  319. jo2201Inpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2201", jo2201Inpar_plain));
  320. //此处先取到就诊信息上传的入参,只要挂号成功就保存到云HIS后台(保存后台需要用到2203入参)
  321. JObject jo2203AInpar = new JObject();
  322. JObject jo2203AInpar_plain = new JObject();
  323. jo2203AInpar.Add("mdtrtinfo", JObject.Parse(JsonHelper.getDestValue(joReg, "mdtrtinfo")));
  324. jo2203AInpar.Add("diseinfo", JArray.Parse(JsonHelper.getDestValue(joReg, "diseinfo")));
  325. JObject jo2201Rtn = invoker.invokeCenterService("2201", jo2201Inpar);
  326. if (JsonHelper.parseCenterRtnValue(jo2201Rtn, out errMsg) != 0)
  327. {
  328. MessageBox.Show(JsonHelper.setExceptionJson(-1, "医保挂号", errMsg).ToString());
  329. return;
  330. }
  331. else
  332. {
  333. Global.pat.mdtrtID = JsonHelper.getDestValue(jo2201Rtn, "output.data.mdtrt_id");
  334. //插入患者本次就诊用的参保信息
  335. if (hBus.insertPatCurInsuInfo(patInfo, out outParam) != 0)
  336. {
  337. if (DialogResult.Yes != MessageBox.Show(outParam, " 是否继续? ", MessageBoxButtons.YesNo))
  338. {
  339. MessageBox.Show(JsonHelper.setExceptionJson(-1, "插入患者本次就诊用的参保信息,请联系管理员!是否继续?", outParam).ToString());
  340. return;
  341. }
  342. }
  343. jo2203AInpar["mdtrtinfo"]["mdtrt_id"] = Global.pat.mdtrtID;
  344. jo2203AInpar_plain = JObject.Parse(JsonHelper.setCenterInpar_plain("2203A", jo2203AInpar));
  345. jo2203AInpar = JObject.Parse(JsonHelper.setCenterInpar("2203A", jo2203AInpar));
  346. //门诊登记信息,插入云医保平台
  347. jo2201Rtn.Add("validflag", 1);
  348. jo2201Rtn.Add("regstate", 1);
  349. jo2201Rtn.Add("type", 3);
  350. Global.writeLog(jo2201Inpar_plain.ToString());
  351. if (mIS.saveOutpatRegisterInfo(jo2201Inpar_plain, jo2201Rtn, jo2203AInpar_plain, out errMsg) != 0)
  352. {
  353. MessageBox.Show(JsonHelper.setExceptionJson(-1, "中心登记成功但医保平台保存失败,请联系管理员!", errMsg).ToString());
  354. return;
  355. }
  356. }
  357. #endregion
  358. }
  359. else
  360. {
  361. }
  362. #endregion
  363. }
  364. private void btnReadCard_Click(object sender, EventArgs e)
  365. {
  366. CertNo = tb_CertNo.Text;
  367. if (tb_CertNo.Text != "")
  368. {
  369. CertNo = tb_CertNo.Text;
  370. Global.pat.certNO = tb_CertNo.Text;
  371. }
  372. #region【读卡】
  373. string OutParam, errMsg;
  374. //打开读卡窗口,操作员选择读卡类型后进行读卡器读卡,再进行1101获取参保信息
  375. if (tb_CertNo.Text == "")
  376. {
  377. if (hBus.readCard(out OutParam) != 0)
  378. {
  379. MessageBox.Show(JsonHelper.setExceptionJson(-100, "读卡失败!", OutParam).ToString());
  380. return;
  381. }
  382. else
  383. {
  384. //展示患者信息界面
  385. ReadCardOutParam = OutParam;
  386. if (hBus.showPatInfo(OutParam, out patInfo) != 0)
  387. {
  388. MessageBox.Show("读卡成功,展示患者信息界面失败:" + patInfo);
  389. return;
  390. }
  391. }
  392. }
  393. #endregion
  394. #region【查询HIS就诊信息-用身份证号查询患者当日的就诊记录】
  395. tb_CertNo.Text = Global.pat.certNO;
  396. string outParam = "";
  397. DataTable dt = null;
  398. if (GetHISRegInfo(dtST.Text, dtED.Text, Global.pat.certNO, ref outParam,ref dt) != 0)
  399. {
  400. MessageBox.Show(outParam);
  401. return;
  402. }
  403. dgv_HISRegInfo.DataSource = dt;
  404. #endregion
  405. #region【调用医保平台获取医保登记信息-根据HIS就诊信息查找医保登记信息 (接诊医生、接诊科室)】
  406. /*
  407. AdmID = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["admID"].Value.ToString();
  408. AdmDoc = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["doc"].Value.ToString();
  409. AdmLoc = dgv_HISRegInfo.Rows[dgv_HISRegInfo.CurrentRow.Index].Cells["loc"].Value.ToString();
  410. gb_InsuReg.Visible = true;
  411. string sqlStr = " SELECT * FROM BS_MedInsuRegisterInfo " //DateDiff(dd,OccurTime,getdate())=0
  412. + " WHERE Type=3 And RegState=1 and OccurTime> '" + dtST.Text + "' And OccurTime<'" + dtED.Text+"'"
  413. + " and PersonalNO='" + Global.pat.psn_no + "' and Hospital_Dr='" + Global.inf.hospitalDr + "'"
  414. + " and Adm_Dr='" + AdmID + "'"
  415. + " And AdmInDepName='" + AdmLoc +"'"
  416. + " And ChiefPhyDocName='"+ AdmDoc+"'";
  417. JObject joSqlstr = new JObject();
  418. joSqlstr.Add("sqlStr", sqlStr);
  419. JArray jaParam = new JArray();
  420. jaParam.Add(joSqlstr);
  421. JObject joSettlQuery = new JObject();
  422. joSettlQuery.Add("params", jaParam);
  423. joSettlQuery.Add("code", "09010062");
  424. InvokeHelper invoker = new InvokeHelper();
  425. JObject joRtn = invoker.invokeInsuService(joSettlQuery.ToString(), "查询门诊挂号");
  426. try
  427. {
  428. if (joRtn["result"]["data"].ToString() == "[]")
  429. {
  430. MessageBox.Show("查询结果为空!");
  431. return;
  432. }
  433. else
  434. {
  435. DataTable dtInsu = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
  436. if (dtInsu.Rows.Count > 1)
  437. {
  438. //gb_InsuReg.Visible = true;
  439. dgv_MdtrtInfo.DataSource = dtInsu;
  440. MessageBox.Show("注意:该患者今日存在多条医保挂号记录,请选择!");
  441. }
  442. else
  443. {
  444. bReg = true;
  445. Global.pat.mdtrtID = dtInsu.Rows[0]["InsuRegID"].ToString();
  446. }
  447. }
  448. }
  449. catch (Exception eX)
  450. {
  451. MessageBox.Show(eX.Message);
  452. }
  453. */
  454. #endregion
  455. }
  456. }
  457. }