create or replace procedure SP_YF_CFZSMX_EDIT ( POPFLAG in number , --0:扫码增加 1:删除 PMZZYBZ in varchar2 , --0:门诊 1:住院 PYZLB00 in varchar2 , --0(来自YF_MZCFMX),1(来自YF_YZYPSQ表),2(来自YF_ZYCFMX,只有5.0存在此值),3(来自YJ_YWJJ00),4(病区摆药扫码),5(住院药房入库扫码) PCFLSH0 in varchar2 , --单号 门诊:YF_MZCF00.CFLSH0 住院:YF_YPCKD0.CKDH00 PYPQLPC in number , --处方流水号YF_MZCFMX.CFLSH0或YF_YZYPSQ.CKDH00或YJ_YWJJ00.ID0000 PYPNM00 in number , --药品内码 PZSM000 in varchar2 , --追溯码 PZYID00 in number , --住院ID PCZY000 in number , --操作员 PCZYKS0 in number default 0 , --操作员科室 Pcommit in varchar2 default 'N' , --是否提交 Pzxcgbz out number , --执行成功标志 1成功 0失败 Ptsxx00 out varchar2 , --执行结果提示信息,成功的情况下也可能有警告信息 POTHER0 in varchar2 default null --输入(可空):备用参数 ) as Ecustom exception; Vcounter number; LS_SFCLBZ YF_CFZSMX.SFCLBZ%type; LS_YSMZSL YF_CFZSMX.YPZSL0%type; --已扫码数量 LS_WSMZSL YF_CFZSMX.YPZSL0%type; --未扫码数量 --LS_YSSL00 YF_CFZSMX.YPZSL0%type; --余数数量 LS_BCSMSL YF_CFZSMX.YPZSL0%type; --本次扫码数量 LS_ZSMZHL BM_YD0000.ZSMZHL%type; --追溯码转换率 LS_SYJLSL YF_RKZSM0.SYJLSL%type; --拆零库剩于数量 LS_ZSID00 YF_YZZSMX.ZSID00%type; LS_YBJKID YF_YBZSRZ.YBJKID%type; LS_CFLSH0 YF_MZCF00.CFLSH0%type; LS_YFBMBH BM_BMBM00.BMBH00%type; LS_YSYSL0 YF_CFZSMX.YPZSL0%type; ls_CFXX00 varchar2(200); LS_MZYBZSMCLCLFS varchar2(40); -- modification history -- Person Date Comments -- dsm 2025.04.18 create 处方追溯码明细操作; YF-20250418-010 -- dsm 2025.04.21 PCFLSH0赋值ls_CFLSH0 YF-20250421-002 -- linshu 2025.05.07 增加入参POTHER0; for YF-20250507-001 -- dsm 2025.05.09 增加SF_YF_GetZSMGGYF处理 for YF-20250509-001 -- dsm 2025.05.20 增加重复使用判断 for for YF-20250520-004 -- dsm 2025.05.21 FYTYBZ住院时写入1 for YF-20250521-003 -- huangjy 2025.07.08 修正医嘱补刷 for YF-20250704-002 -- dsm 2025.07.10 上传记录作废或者删除的,允许删除 for YF-20250710-001 begin Pzxcgbz := 0; LS_CFLSH0:=trim(PCFLSH0); select max(trim(MC0000)) into LS_MZYBZSMCLCLFS from BM_TYZD00 where BH0000='YF_MZYBZSMCLCLFS' and ZDMC00='医保追溯码配置'; if POPFLAG = 0 then --扫码BEGIN select nvl(A.ZSMZHL,0) into LS_ZSMZHL from BM_YD0000 A where A.YPNM00 = PYPNM00; if LS_ZSMZHL = 0 then Ptsxx00 := '该药品追溯码转换率未维护,不能进行扫码'; raise Ecustom; end if; LS_SFCLBZ := '0'; begin select sum(nvl(YPZSL0,0)-nvl(TYZSL0,0)) into LS_YSYSL0 from YF_CFZSMX where ZSM000=PZSM000 and YPNM00=PYPNM00; exception when others then LS_YSYSL0:=0; end; if LS_YSYSL0>=LS_ZSMZHL then begin select '('||decode(MZZYBZ,'0','门诊','住院')||'处方号:'||CFLSH0||', 日期:'||CZRQ00||')' into ls_CFXX00 from ( select * from YF_CFZSMX A where ZSM000=PZSM000 and YPNM00=PYPNM00 and nvl(YPZSL0,0)-nvl(TYZSL0,0)>0 order by ID0000 desc) where rownum=1; exception when others then ls_CFXX00:=''; end; Ptsxx00 := '该药品追溯码数量已经使用完!'||chr(13)||ls_CFXX00; raise Ecustom; end if; if PMZZYBZ = '0' then --获取已扫码数量 select nvl(sum(A.YPZSL0),0) into LS_YSMZSL from YF_CFZSMX A where A.YZLB00 = '0' and A.MZZYBZ = '0' and A.CFLSH0 = LS_CFLSH0 and A.YPQLPC = PYPQLPC and A.YPNM00 = PYPNM00; --获取未扫码数量 select ( A.YPZSL0*A.ZHL000 - LS_YSMZSL ) into LS_WSMZSL from YF_MZCFMX A where A.CFLSH0 = LS_CFLSH0 and A.CFID00 = PYPQLPC and A.YPNM00 = PYPNM00; --select decode(mod(LS_WSMZSL,LS_ZSMZHL),0,LS_ZSMZHL,mod(LS_WSMZSL,LS_ZSMZHL)) into LS_BCSMSL from dual; else select nvl(sum(A.YPZSL0),0) into LS_YSMZSL from YF_CFZSMX A where A.YZLB00 = '2' and A.MZZYBZ = '1' and A.CFLSH0 = LS_CFLSH0 and A.YPQLPC = PYPQLPC and A.YPNM00 = PYPNM00; --获取未扫码数量 if PYZLB00='1' then select ( A.YPZSL0*A.ZHL000 - LS_YSMZSL ) into LS_WSMZSL from YF_YZYPSQ A where A.CKDH00 = LS_CFLSH0 and A.YPQLPC = PYPQLPC and A.YPNM00 = PYPNM00; else select ( A.YPZSL0*A.ZHL000 - LS_YSMZSL ) into LS_WSMZSL from YF_ZYCFMX A where A.CFLSH0 = LS_CFLSH0 and A.CFID00 = PYPQLPC and A.YPNM00 = PYPNM00; end if; end if; select SF_YF_GetZSMGGYF(PYPNM00,PCZYKS0) into ls_YFBMBH from dual; --判断一下是否追溯码在拆零库 select count(1) into Vcounter from YF_RKZSM0 A where A.ZSM000 = PZSM000 ; LS_SYJLSL:=0; if Vcounter>0 then select A.SYJLSL into LS_SYJLSL from YF_RKZSM0 A where A.ZSM000 = PZSM000 ; if LS_SYJLSL<=0 then Ptsxx00:='此码在拆零库中已经使用完了'; raise Ecustom; end if; end if; if Vcounter > 0 then --判断一下数量是否够 --select A.SYJLSL into LS_SYJLSL from YF_RKZSM0 A where A.ZSM000 = PZSM000 and A.SYJLSL > 0; if LS_WSMZSL >= LS_SYJLSL then LS_BCSMSL := LS_SYJLSL; update YF_RKZSM0 A set A.SYJLSL = A.SYJLSL - LS_SYJLSL where A.ZSM000 = PZSM000 ; else LS_BCSMSL := LS_WSMZSL; update YF_RKZSM0 set SYJLSL = SYJLSL - LS_BCSMSL where ZSM000 = PZSM000 ; end if; else --判断一下是不是余数 if LS_WSMZSL >= LS_ZSMZHL then LS_BCSMSL := LS_ZSMZHL; else select mod(LS_WSMZSL,LS_ZSMZHL) into LS_BCSMSL from dual; --剩余数量进拆零库 insert into YF_RKZSM0(CLLSH0,YFBMBH,PYCKBH,YFRKPC,KCLSH0,YPNM00,ZSM000,ZSMLY0,JLZSL0,SYJLSL,ZT0000,CZY000) Values(SQ_YF_RKZSM0_CLLSH0.NEXTVAL,ls_YFBMBH,0,0,0,PYPNM00,PZSM000,'2',LS_ZSMZHL,LS_ZSMZHL-LS_BCSMSL,0,PCZY000); LS_SFCLBZ := '1'; end if; end if; insert into YF_CFZSMX(ID0000,MZZYBZ,YZLB00,CFLSH0,YPQLPC,YPNM00,ZSM000,FYTYBZ,CZY000,SFLB00,YPZSL0,SFCLBZ,ZYID00) Values(SQ_YF_CFZSMX_ID0000.NEXTVAL,PMZZYBZ,PYZLB00,PCFLSH0,PYPQLPC,PYPNM00,PZSM000,decode(PMZZYBZ,'0','0','1'),PCZY000,'3',LS_BCSMSL,LS_SFCLBZ,PZYID00); --扫码BEGIN elsif POPFLAG = '1' then select nvl(MAX(A.ZSID00),0) into LS_ZSID00 from YF_YZZSMX A where A.MZZYBZ = PMZZYBZ and A.YZLB00 = PYZLB00 and A.CFLSH0 = LS_CFLSH0 and A.YPQLPC = PYPQLPC and A.ZSM000 = PZSM000; if LS_ZSID00 > 0 then --判断是否已做退药上传 select nvl(max(A.YBJKID),0) into LS_YBJKID from YF_YBZSRZ A where A.CFLSH0 = LS_CFLSH0 and A.ZSID00 = LS_ZSID00 and A.LB0000 = '0' and ZT0000 not in('2','4'); if LS_YBJKID > 0 then Ptsxx00 := '发药追溯码已上传,不能实行删除!'; raise Ecustom; else --删除医保追溯日志 delete YF_YZZSMX A where A.MZZYBZ = PMZZYBZ and A.YZLB00 = PYZLB00 and A.CFLSH0 = LS_CFLSH0 and A.YPQLPC = PYPQLPC and ZSM000 = PZSM000 and ZT0000 in('0'); select count(1) into Vcounter from YF_YZZSMX A where A.MZZYBZ = PMZZYBZ and A.YZLB00 = PYZLB00 and A.ZSID00 = LS_ZSID00; if Vcounter = 0 then delete from YF_YBZSRZ A where A.CFLSH0 = LS_CFLSH0 and A.ZSID00 = LS_ZSID00 and A.LB0000 = '0'; end if; end if; end if; select nvl(SFCLBZ,'0'),YPZSL0 into LS_SFCLBZ,LS_SYJLSL from YF_CFZSMX where CFLSH0 = LS_CFLSH0 and YZLB00 = PYZLB00 and YPQLPC = PYPQLPC and ( FYTYBZ = '1' or FYTYBZ = '0') and ZSM000 = PZSM000; if LS_SFCLBZ = '1' or (LS_SFCLBZ = '0' and substr(LS_MZYBZSMCLCLFS,1,2) in('-1','1')) then --库存加回去 update YF_RKZSM0 SET SYJLSL = SYJLSL + LS_SYJLSL where ZSM000 = PZSM000 ; end if; delete from YF_CFZSMX where CFLSH0 = LS_CFLSH0 and YZLB00 = PYZLB00 and YPQLPC = PYPQLPC and ( FYTYBZ = '1' or FYTYBZ = '0') and ZSM000 = PZSM000; end if; Pzxcgbz:=1; if pcommit='Y' then commit; end if; exception when no_data_found then raise_application_error(-20001,substrb('没有找到数据!*'||sqlerrm,1,240)); when Ecustom then raise_application_error(-20010,substrb(Ptsxx00||'!*',1,240)); when others then raise_application_error(-20002,substrb(nvl(sqlerrm, '原因不明出错')||'!*',1,240)); end; /