prompt 病区医嘱自动审核发药SP_YF_BQYZZDSHFY create or replace procedure SP_YF_BQYZZDSHFY( PCKDH00 in char, --出库单号 PCZY000 in number, --操作员 PCOMMIT in char, PINXML0 in char --其他入参 ) as --电子病历评级数据 LS_CKDH00 YF_YZYPSQ.CKDH00%type; YF_SFZDSHZDFY varchar2(20); LS_FYRQSJ varchar2(20); LS_SJFYR0 BM_YGBM00.YGBH00%type; LS_YFBMBH YF_YZYPSQ.YFBMBH%type; ls_FYR000 BM_YGBM00.YGBH00%type; -- MODIFICATION HISTORY 3.1 -- Person Date Comments -- dsm 2025.07.08 create for YF-20250626-004 -- dsm 2025.07.22 整个单的审核时间要一样,否则领药单查询会出现重复记录 for YF-20250721-001 -- dsm 2025.10.11 (蔡佳源)修改归档 for YF-20251010-002 begin --0不自动,1自动(第1位自动审核,第2位自动发药)默认00 select nvl(max(trim(VALUE0)),'00') into YF_SFZDSHZDFY from XT_XTCS00 where name00='YF_SFZDSHZDFY'; if YF_SFZDSHZDFY='00' then return; end if; LS_CKDH00:=trim(PCKDH00); --审核日期、审核人 select YFBMBH,FYR000 into LS_YFBMBH,ls_FYR000 from YF_YZYPSQ where CKDH00=LS_CKDH00 and rownum=1; if substr(YF_SFZDSHZDFY,1,1)='1' then begin --select to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')-round(DBMS_RANDOM.value(1,5))/1440,'YYYYMMDDHH24:MI:SS') into LS_FYRQSJ from YF_YZYPSQ where CKDH00=LS_CKDH00 and (SHRQ00 is null or SHRQ00='20991231') and rownum=1; select to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')-round(DBMS_RANDOM.value(1,5),2)/1440,'YYYYMMDDHH24:MI:SS') into LS_FYRQSJ from YF_YZYPSQ where CKDH00=LS_CKDH00 and (SHRQ00 is null or SHRQ00='20991231') and rownum=1; exception when others then LS_FYRQSJ:=' '; end; --update YF_YZYPSQ set ZLFWMC=to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')-round(DBMS_RANDOM.value(1,5))/1440,'YYYYMMDDHH24:MI:SS') where CKDH00=LS_CKDH00 and (SHRQ00 is null or SHRQ00='20991231'); if LS_FYRQSJ<>' ' then Update YF_YZYPSQ set SHRQ00=substr(LS_FYRQSJ,1,8), SHSJ00=substr(LS_FYRQSJ,9,8), SHR000=FYR000,SHBZ00='1' ,ZLFWMC='' where CKDH00=LS_CKDH00 and (SHRQ00 is null or SHRQ00='20991231'); end if; end if; --摆药日期、摆药人 -- update YF_YZYPSQ set BYRQ00=FYRQ00,BYSJ00=to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')+round(DBMS_RANDOM.value(1,7))/1440,'HH24:MI:SS'), -- BYR000=decode(nvl(FHR000,-1),-1,FYR000) where CKDH00=LS_CKDH00 and CKDH00 is not null and BYRQ00 is null; --离柜发药日期、发药人 if substr(YF_SFZDSHZDFY,2,1)='1' then LS_FYRQSJ:=' '; begin --select to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')+round(DBMS_RANDOM.value(1,10))/1440,'YYYYMMDDHH24:MI:SS') into LS_FYRQSJ from YF_YZYPSQ where CKDH00=LS_CKDH00 and CKDH00 is not null and SJFYRQ is null and rownum=1; select to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')+round(DBMS_RANDOM.value(20,40),2)/1440,'YYYYMMDDHH24:MI:SS') into LS_FYRQSJ from YF_YZYPSQ where CKDH00=LS_CKDH00 and CKDH00 is not null and SJFYRQ is null and rownum=1; exception when others then LS_FYRQSJ:=' '; end; --update YF_YZYPSQ set ZLFWMC=to_char(to_date(FYRQ00||FYSJ00,'YYYYMMDDHH24:MI:SS')+round(DBMS_RANDOM.value(1,10))/1440,'YYYYMMDDHH24:MI:SS') where CKDH00=LS_CKDH00 and CKDH00 is not null and SJFYRQ is null; begin if (to_char(sysdate,'HH24:MI')>'00:00' and to_char(sysdate,'HH24:MI')<='07:30') then select SJFYR0 into ls_SJFYR0 from YF_YZYPSQ where YFBMBH=ls_YFBMBH and FYRQ00=to_char(sysdate,'YYYYMMDD') and (substr(FYSJ00,1,5) between '00:00' and '07:30') and SJFYR0 is not null and rownum=1; elsif to_char(sysdate,'HH24:MI')>'07:30' and to_char(sysdate,'HH24:MI')<='17:30' then select SJFYR0 into ls_SJFYR0 from YF_YZYPSQ where YFBMBH=ls_YFBMBH and FYRQ00=to_char(sysdate,'YYYYMMDD') and (substr(FYSJ00,1,5) between '07:30' and '17:30') and SJFYR0 is not null and rownum=1; elsif to_char(sysdate,'HH24:MI')>'17:30' and to_char(sysdate,'HH24:MI')<='23:59' then select SJFYR0 into ls_SJFYR0 from YF_YZYPSQ where YFBMBH=ls_YFBMBH and FYRQ00=to_char(sysdate,'YYYYMMDD') and (substr(FYSJ00,1,5) between '17:30' and '23:59') and SJFYR0 is not null and rownum=1; end if; exception when others then ls_SJFYR0:=0; end; if ls_SJFYR0=0 then select ygbh00 into LS_SJFYR0 from ( select YGBH00 from BM_YGBM00 where BMBH00=LS_YFBMBH and YGBH00<>ls_FYR000 order by dbms_random.value ) where rownum = 1; end if; if LS_FYRQSJ<>' ' then update YF_YZYPSQ set SJFYRQ=substr(LS_FYRQSJ,1,8), SJFYSJ=substr(LS_FYRQSJ,9,8), SJFYR0=nvl(FHR000,LS_SJFYR0),ZLFWMC='' where CKDH00=LS_CKDH00 and CKDH00 is not null and SJFYRQ is null; end if; end if; if PCOMMIT='Y' then commit; end if; exception when others then raise_application_error(-20002,substrb(nvl(sqlerrm, '原因不明出错')||'!*',1,240)); end; / --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%