1.个检

  1. create or replace procedure SP_ESI_HMZXDD_RECE00
  2. -- When Who What
  3. -- 2017.12.15 JXQ Create
  4. (
  5. POPFLAG in number, --操作标志 0:按订单号
  6. PDDH000 in varchar2, --订单号
  7. PYYBH00 in varchar2, --医院编号
  8. PTJH000 out number --体检号
  9. )
  10. as
  11. VCOUNT0 number;
  12. VZXCGBZ number;
  13. VDATE00 varchar2(8);
  14. VTIME00 varchar2(8);
  15. VID0000 varchar2(50);
  16. VTTMC00 varchar2(50);
  17. VTSXX00 varchar2(200);
  18. VSQLSTR varchar2(500);
  19. VERRMSG varchar2(200);
  20. VSYWID0 varchar2(1000);
  21. VTMMS00 PT_SYSCS0.VALUE0%type; --条码模式
  22. VROW HM_TMP_TJZ000%rowtype;
  23. VTTID00 HM_YW_TJZ000.TTID00%type;
  24. VJKTTID HM_YW_TJTT00.JKTTID%type;
  25. VRWID00 HM_YW_TJZ000.RWID00%type;
  26. VFZID00 HM_YW_TJZ000.FZID00%type;
  27. VYYBH00 HM_YW_TJZ000.YYBH00%type;
  28. VKL0000 HM_YW_TJZ000.KL0000%type;
  29. VKDYSID HM_YW_TJZ000.KDYSID%type;
  30. VSFZH00 HM_YW_TJZ000.SFZH00%type;
  31. VTJH000 HM_YW_TJZFB0.TJH000%type;
  32. VJKTJH0 HM_YW_TJZFB0.TJH000%type;
  33. VSFYWID HM_YW_TJYW00.SFYWID%type;
  34. VDDH000 HM_YW_TJZFB0.DDH000%type;
  35. VDDYJE0 HM_YW_TJZFB0.DDYJE0%type;
  36. VDDSJE0 HM_YW_TJZFB0.DDSJE0%type;
  37. VJYXMID HM_TMP_TJZFB0.JYXMID%type;
  38. VSQXMID HM_ZD_TJSQXM.SQXMID%type;
  39. ECUSTOM exception;
  40. type T_CUR_TJZ is ref cursor; --
  41. CUR_TJZ T_CUR_TJZ;
  42. type T_CUR_YW is ref cursor; --
  43. CUR_YW T_CUR_YW;
  44. type T_CUR_YW_TMP is ref cursor; --
  45. CUR_YW_TMP T_CUR_YW_TMP;
  46. type T_CUR_JYXM is ref cursor; --
  47. CUR_JYXM T_CUR_JYXM;
  48. begin
  49. VDATE00 := to_char(sysdate, 'YYYYMMDD');
  50. VTIME00 := to_char(sysdate, 'HH24:MI:SS');
  51. --SP_ESI_HMZXDD_TJTT00(0);
  52. --处理条码生成
  53. select SF_PT_GetXTCS('HM_LISTMMS', '0', VYYBH00) into VTMMS00 from dual;
  54. select count(*) into VCOUNT0 from HM_YW_TJZFB0 where 1=1 and DDH000 = PDDH000;
  55. if VCOUNT0 > 0 then
  56. VERRMSG := '已生成订单号'; raise ECUSTOM;
  57. end if;
  58. select count(*) into VCOUNT0 from hm_yw_tjz000_qzj where 1=1 and code = PDDH000;
  59. if VCOUNT0 = 0 then
  60. VERRMSG := '未找到订单号'; raise ECUSTOM;
  61. end if;
  62. select tjh000, tjh000, code, TSXE00, TSXE00, SFZH00, rwid00
  63. into VID0000, VJKTJH0, VDDH000, VDDYJE0, VDDSJE0, VSFZH00, VTTID00
  64. from hm_yw_tjz000_qzj where code = PDDH000;
  65. select nvl(max(a.TTID00), null), nvl(max(JKTTID), null) into VTTID00, VJKTTID from HM_YW_TJTT00 a inner join Hm_Yw_Ttrw00 b on a.ttid00 = b.ttid00
  66. where b.rwid00 = VTTID00;
  67. if VTTID00 is null then
  68. SP_HM_OPER_DDTTRW(1, VTTID00, VRWID00, VFZID00);
  69. else
  70. select nvl(max(RWID00), null) into VRWID00 from HM_YW_TTRW00 where TTID00 = VTTID00 and RWYDRQ like to_char(sysdate, 'YYYY')||'%' and rownum = 1;
  71. if VRWID00 is null then
  72. select SQ_HM_YW_TTRW00_RWID00.nextval into VRWID00 from dual;
  73. insert into HM_YW_TTRW00 (RWID00, TTID00, DJR000, RWYDRQ)
  74. select VRWID00, VTTID00, 0, to_char(sysdate, 'YYYYMMDD') from dual;
  75. insert into HM_YW_TTRWFB (RWID00, TTID00)
  76. select VRWID00, VTTID00 from dual;
  77. end if;
  78. select nvl(max(RWFZID), null) into VFZID00 from HM_YW_TTRWFZ where RWID00 = VRWID00 and BZ0000 = '订单' and rownum = 1;
  79. if VFZID00 is null then
  80. select SQ_HM_YW_TTRWFZ_RWFZID.nextval into VFZID00 from dual;
  81. insert into HM_YW_TTRWFZ(RWFZID, RWID00, FZMC00, PYSM00, BZ0000, TJLXID, FBBH00)
  82. select VFZID00, VRWID00, '通用', 'ty', '订单', 1, 4 from dual;
  83. end if;
  84. end if;
  85. select nvl(max(TJH000),null) into VTJH000 from HM_TMP_TJZFB0 where DDH000 = VDDH000;
  86. if VTJH000 is null then
  87. select SF_HM_GetTJH(PYYBH00) into VTJH000 from dual;
  88. end if;
  89. --体检者表
  90. insert into HM_TMP_TJZ000 (
  91. TJH000, DH0000, CSRQ00, NL0000, DDTJH0, DDH000, XM0000, XB0000,
  92. HYZKID, LXID00, TJLXID, SFHY00, KDYSID, KL0000, TSXE00, DAID00)
  93. select
  94. VTJH000, DH0000, CSRQ00, NL0000, VDDH000, VDDH000, XM0000, XB0000,
  95. 6 HYZKID, 1 LXID00, 1 TJLXID, '0' SFHY00, '0', null, TOTAL_FEE, null
  96. from hm_yw_tjz000_qzj A where code = PDDH000 and not exists (select 1 from HM_TMP_TJZ000 where DDH000 = VDDH000);
  97. --体检者附表
  98. insert into HM_TMP_TJZFB0 (
  99. TJH000, DDH000, DDYJE0, DDSJE0)
  100. select
  101. VTJH000, code, TSXE00, TSXE00
  102. from hm_yw_tjz000_qzj where code = PDDH000 and not exists (select 1 from HM_TMP_TJZFB0 where DDH000 = VDDH000);
  103. --业务表
  104. delete from HM_TMP_TJYW00 where TJH000 = VTJH000;
  105. insert into HM_TMP_TJYW00 (
  106. SFYWID, DJYWID, TJH000, TTID00, RWID00, SQXMID, SFXMMC,
  107. ZYFLID, DJ0000, SL0000, YSJE00, TSJE00, GWYJE0, ZFJE00, YDJ000,
  108. DJR000, DJRQ00, DJSJ00, TXM000, CJRQ00, CJSJ00, CJR000, YBCJKS,
  109. JYYLJG, JYYLRQ, JYYLSJ, QJ0000, JCBZ00, JCKSID, FKKSRQ, FKKSSJ,
  110. FKJSRQ, FKJSSJ, TFNTBZ, KDRQ00, KDSJ00, KDYS00, SFSF00, SFJZ00,
  111. SFRQ00, SFSJ00, KSCZY0, JCYSID, JCYSXM, JCRQ00, JCSJ00, ZHXMID,
  112. FYWID0, KHQRBZ, TOPACS, FKJCID, YYRQ00, SGYWID, JPKSID, DDTJH0)
  113. select
  114. SQ_HM_YW_TJYW00_SFYWID.nextval, null, VTJH000, VTTID00, VRWID00, B.SQXMID, B.SFXMMC,
  115. null, A.DJ0000, 1, A.DJ0000, ZFJE00, 0, 0, '0',
  116. null, null, null, null, null, null, null, (select YBCJKS from HM_ZD_JYYBLX where YBLXID = B.BBLXID),
  117. '0', null, null, '0', '0', (select SFKSID from HM_ZD_TJSQXM where SQXMID = to_number(A.SQXMID)), '00000000', null,
  118. null, null, '0', VDATE00, VTIME00, null, '0', '0',
  119. null, null, null, null, null, null, null, null,
  120. -1, '0', '0', null, '00000000', null, null, VJKTJH0
  121. from hm_yw_tjyw00_qzj A, HM_ZD_TJSQXM B where A.SQXMID = to_number(B.SQXMID) and A.tjh000 = VJKTJH0
  122. and not exists (select 1 from HM_TMP_TJYW00 where DDTJH0 = VJKTJH0 and to_number(SQXMID) = A.SQXMID);
  123. --更新DJYWID
  124. declare cursor CUR_YW_TMP is
  125. select TJH000, SFYWID from HM_TMP_TJYW00 where TJH000 = VTJH000 and DJYWID is null;
  126. begin
  127. for ROW in CUR_YW_TMP loop
  128. select SQ_HM_YW_TJYW00_SFYWID.nextval into VSFYWID from dual;
  129. update HM_TMP_TJYW00 set DJYWID = VSFYWID where TJH000 = ROW.TJH000 and SFYWID = ROW.SFYWID;
  130. end loop;
  131. end;
  132. --========================= 插入正式库 =============================
  133. VYYBH00 := PYYBH00;
  134. VERRMSG := '***** 001 *****';
  135. select count(*) into VCOUNT0 from HM_YW_TJZ000 where TJH000 = VTJH000;
  136. if VCOUNT0 = 0 then
  137. select * into VROW from HM_TMP_TJZ000 where TJH000 = VTJH000;
  138. VKDYSID := vROW.KDYSID;
  139. SP_HM_EDIT_TJZ000(
  140. 0, VTJH000, 0, VROW.DAID00, VSFZH00, VROW.XM0000, VFZID00, VRWID00, VTTID00, null,
  141. VROW.KL0000, VDDSJE0, VROW.XB0000, VROW.CSRQ00, VROW.NL0000, '1', null, VROW.HYZKID, null, null, VROW.KDYSID,
  142. null, VROW.DH0000, '0', VROW.LXID00, null, null, null, null, null, -1, VROW.TJLXID,
  143. null, null, '0', 0, null, null, '4', null, null, null,
  144. '0', null, '0', '0', VYYBH00, -1, 'N', VZXCGBZ, VTSXX00);
  145. update HM_YW_TJZ000 set TSXE00 = VROW.TSXE00, KL0000 = VROW.KL0000 where TJH000 = VTJH000;
  146. end if;
  147. VERRMSG := '***** 002 *****';
  148. update HM_YW_TJZFB0 A set
  149. (DDH000, DDYJE0, DDSJE0) = (select DDH000, DDYJE0, DDSJE0 from HM_TMP_TJZFB0 where TJH000 = A.TJH000)
  150. where TJH000 = VTJH000;
  151. --update TBL_ORDER@TODD set status = 1, his_bm = VTJH000 where ORDER_NUM = PDDH000;
  152. VERRMSG := '***** 003 *****';
  153. select count(*) into VCOUNT0 from HM_YW_TJYW00 where TJH000 = VTJH000;
  154. if VCOUNT0 = 0 then
  155. insert into HM_YW_TJYW00 (
  156. SFYWID, TJH000, TTID00, RWID00, SQXMID, SFXMMC, ZYFLID, DJ0000, SL0000, YSJE00,
  157. TSJE00, GWYJE0, ZFJE00, YDJ000, DJR000, DJRQ00, DJSJ00, TXM000, CJRQ00, CJSJ00,
  158. CJR000, YBCJKS, JYYLJG, JYYLRQ, JYYLSJ, QJ0000, JCBZ00, JCKSID, FKKSRQ, FKKSSJ,
  159. FKJSRQ, FKJSSJ, TFNTBZ, KDRQ00, KDSJ00, KDYS00, SFSF00, SFJZ00, SFRQ00, SFSJ00,
  160. KSCZY0, JCYSID, JCYSXM, JCRQ00, JCSJ00, ZHXMID, FYWID0, KHQRBZ, TOPACS, FKJCID,
  161. YYRQ00, SGYWID, JPKSID, DJYWID)
  162. select
  163. SFYWID, VTJH000, TTID00, RWID00, SQXMID, SFXMMC, ZYFLID, DJ0000, SL0000, YSJE00,
  164. TSJE00, GWYJE0, ZFJE00, '0', '', '', '', null, CJRQ00, CJSJ00,
  165. CJR000, YBCJKS, JYYLJG, JYYLRQ, JYYLSJ, QJ0000, JCBZ00, JCKSID, FKKSRQ, FKKSSJ,
  166. FKJSRQ, FKJSSJ, TFNTBZ, KDRQ00, KDSJ00, KDYS00, SFSF00, SFJZ00, SFRQ00, SFSJ00,
  167. KSCZY0, JCYSID, JCYSXM, JCRQ00, JCSJ00, ZHXMID, FYWID0, KHQRBZ, TOPACS, FKJCID,
  168. YYRQ00, SGYWID, JPKSID, DJYWID
  169. from HM_TMP_TJYW00 A where TJH000 = VTJH000
  170. and not exists (select 1 from HM_YW_TJYW00 where TJH000 = A.TJH000 and DJYWID = A.DJYWID)
  171. order by SFYWID;
  172. VERRMSG := '***** 004 *****';
  173. if VTMMS00 = '0' then --自打印,更新条码
  174. VSYWID0 := '';
  175. open CUR_YW for
  176. select SFYWID from HM_YW_TJYW00 A,HM_ZD_TJSQXM B where A.SQXMID = B.SQXMID AND A.TJH000 = VTJH000 and B.TMQZ00 is not null and A.TXM000 is null
  177. and A.TFNTBZ = '0';
  178. loop
  179. fetch CUR_YW into VSFYWID;
  180. exit when CUR_YW%NOTFOUND;
  181. if VSYWID0 is null then
  182. VSYWID0 := VSFYWID;
  183. else
  184. VSYWID0 := VSYWID0||','||VSFYWID;
  185. end if;
  186. end loop;
  187. close CUR_YW;
  188. if VSYWID0 is not null then
  189. SP_HM_OPER_JYTM00(0, VTJH000, VSYWID0, 0, 'N', VZXCGBZ, VERRMSG);
  190. end if;
  191. end if;
  192. end if;
  193. --*/
  194. SP_HM_REJSYWJE(VTJH000, 1);
  195. PTJH000 := VTJH000;
  196. exception
  197. when No_Data_Found then
  198. raise_application_error(-20001, substrb('没有找到数据!'||sqlerrm||VERRMSG||'--'||VTJH000, 1, 240));
  199. when ECUSTOM then
  200. raise_application_error(-20010, substrb(VERRMSG||'!*', 1, 240));
  201. when others then
  202. raise_application_error(-20002, substrb(nvl(sqlerrm, '原因不明出错'), 1, 240));
  203. end;
文档更新时间: 2024-02-22 16:14