Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSOPFSU1

PSOPFSU1.m

Go to the documentation of this file.
  1. PSOPFSU1 ;BIR/LE,AM - PFSS Charge Message & Utilities ;08/09/93
  1. ;;7.0;OUTPATIENT PHARMACY;**201,225**;DEC 1997;Build 29
  1. ;External reference CHARGE^IBBAPI and GETCHGID^IBBAPI supported by DBIA 4665
  1. Q
  1. ;
  1. CHRG(PSORXN,PSOREF,PSOCHTYP,PSOPFS) ;ENTRY POINT:
  1. ;Used to pass charge msg info to an external billing system via IBB API's
  1. ; Inputs: PSORXN = RX IEN, PSOREF = fill number, PSOCHTYP = "CG" for Charge or "CD" for Credit transaction,
  1. ; PSOPFS = switch status (0 or 1) ^ PFSS Account Reference for the fill ^ PFSS Charge ID for the fill
  1. ; Outputs: none
  1. ;
  1. N I,CLDIV,IFN,J,PSODG,PSOZCL,PSOCHID,PSOPFSA,PSODFN,PSORX,PSOFT1,PSODRG,PSODRUG,PSORXE,PSOCHG,PSOFD,PSOFT,PSOFLD
  1. ; quit if PFSS switch is off or not defined
  1. Q:'+$G(PSOPFS)
  1. ;
  1. ; check for CHARGE LOCATION before processing charge message.
  1. S CLDIV=$$CHLOC^PSOPFSU0()
  1. Q:CLDIV<1 ;if no CHARGE LOCATION, don't send charge message to either IB or external billing system.
  1. ;
  1. ; check for PFSS Acct Reference; if not one define, request one
  1. S PSOPFSA=$P(PSOPFS,"^",2)
  1. I PSOPFSA<1 D PFSI(PSORXN,PSOREF) S PSOPFSA=$P(PSOPFS,"^",2) I PSOPFSA<1 D ;because PSOCP is too large, need to check for/get them here
  1. .S PSOPFSA=$$GACT^PSOPFSU0(PSORXN,PSOREF)
  1. Q:PSOPFSA<1 ;Normally IB returns an acct ref or zero for unsuccessful if a problem is encountered.
  1. ; If IBB didn't return a value, don't send charge message because IBB will produce a hard error. Subsequent phase of PFSS will provide further error handling.
  1. ;
  1. ; check for PFSS Charge ID. If no charge ID, means Rx never sent to external bill sys or there was a problem retrieve one.
  1. S PSOCHID=$P(PSOPFS,"^",3)
  1. ;If no Charge ID is defined, request a Unique Charge ID and store it in file 52
  1. I PSOCHID<1 S PSOCHID=$$GETCHGID^IBBAPI() I PSOCHID>0 D
  1. . I PSOREF=0 S $P(^PSRX(PSORXN,"PFS"),"^",2)=PSOCHID ;set directly for speed (CMOPs, etc.)
  1. . I PSOREF>0 S $P(^PSRX(PSORXN,1,PSOREF,"PFS"),"^",2)=PSOCHID
  1. Q:PSOCHID<1 ;no charge message will be sent if can't get a PFSS CHARGE ID from IB. Subsequent phase of PFSS will provide error handling for this type problem.
  1. ;Retrieve all fields to pass for the charge message
  1. S PSOFT="4,10,21" I PSOREF=0 D CHRGOF
  1. I PSOREF>0 D CHRGRF
  1. ;Get general Rx data fields
  1. D GETS^DIQ(52,PSORXN,"2;3;6;105","I","PSORX")
  1. S PSOFT1(29)=$$NDC^PSOHDR(PSORXN,PSOREF,$S(PSOREF>0:"R",1:""))
  1. S PSODFN=$G(PSORX(52,PSORXN_",",2,"I")),PSODRG=$G(PSORX(52,PSORXN_",",6,"I")),PSOFT1(31)=$G(PSORX(52,PSORXN_",",105,"I"))
  1. D DATA^PSS50(PSODRG,,,,,"PSOSC")
  1. ;S PSOFT1(2)="PSO"_PSORXN_"F"_PSOREF ;12/6/05; DECISION MADE TO NOT SEND clinicial event indicator FOR OP
  1. S PSOFT1(7)=$G(^TMP($J,"PSOSC",PSODRG,400)),PSOFT1(6)=PSOCHTYP,PSOFT1(13)=160
  1. S PSOFT1(18)=$G(PSORX(52,PSORXN_",",3,"I")),PSOFT1(18)=$$GET1^DIQ(53,PSOFT1(18)_",",15,"I")
  1. S PSOFT1(22)=$FN($G(^TMP($J,"PSOSC",PSODRG,16)),"",2),PSOFT1(29)=PSOFT1(29)_";"_$G(^TMP($J,"PSOSC",PSODRG,.01))
  1. S PSORXE(31)=$G(^TMP($J,"PSOSC",PSODRG,3)),PSORXE(17)=PSOREF
  1. S:(PSORXE(18)="") PSORXE(18)=$G(RELDT) ;CMOP
  1. S PSORXE(15)=PSORXN
  1. S PSOCHG=$$CHARGE^IBBAPI(PSODFN,PSOPFSA,PSOCHTYP,PSOCHID,.PSOFT1,"",.PSODG,.PSOZCL,.PSORXE,"","")
  1. ;errors to be handled in subsequent phase
  1. K ^TMP($J,"PSOSC")
  1. Q
  1. ;
  1. CHRGOF ;Retrieve charge fields for orig fills
  1. D GETS^DIQ(52,PSORXN,"4;7;8;22;31;125","I","PSORX")
  1. S PSOFD="22,7,4"
  1. F I=1:1 S PSOFLD=$P(PSOFD,",",I) Q:PSOFLD="" S PSOFT1($P(PSOFT,",",I))=$G(PSORX(52,PSORXN_",",$P(PSOFD,",",I),"I"))
  1. S PSOPFSA=$G(PSORX(52,PSORXN_",",125,"I")),PSORXE(18)=$G(PSORX(52,PSORXN_",",31,"I"))
  1. S PSORXE(1)=PSOFT1(10)_";;"_$G(PSORX(52,PSORXN_",",8,"I"))
  1. D GOC
  1. Q
  1. ;
  1. CHRGRF ;Retrieve charge fields for refills
  1. D GETS^DIQ(52.1,PSOREF_","_PSORXN,".01;1;1.1;15;17;21","I","PSORX")
  1. S PSOFD=".01,1,15"
  1. F I=1:1 S PSOFLD=$P(PSOFD,",",I) Q:PSOFLD="" S PSOFT1($P(PSOFT,",",I))=$G(PSORX(52.1,PSOREF_","_PSORXN_",",$P(PSOFD,",",I),"I"))
  1. S PSOPFSA=$G(PSORX(52.1,PSOREF_","_PSORXN_",",21,"I")),PSORXE(18)=$G(PSORX(52.1,PSOREF_","_PSORXN_",",17,"I"))
  1. S PSORXE(1)=PSOFT1(10)_";;"_$G(PSORX(52.1,PSOREF_","_PSORXN_",",1.1,"I"))
  1. D GOC
  1. Q
  1. ;
  1. GOC ;Called from CHRGOF, CHRGRF. Parse OP classifications and ICD's. Don't send null values.
  1. D GETS^DIQ(52,PSORXN,"52311*","I","PSORX")
  1. F I=1:1 Q:'$D(PSORX(52.052311,I_","_PSORXN_",")) D
  1. . S:PSORX(52.052311,I_","_PSORXN_",",".01","I")'="" PSODG(I,3)=PSORX(52.052311,I_","_PSORXN_",",".01","I"),PSODG(I,6)="F"
  1. . I I=1 F J=1:1:8 Q:'$D(PSORX(52.052311,I_","_PSORXN_",",J,"I")) D
  1. . . S:PSORX(52.052311,I_","_PSORXN_",",J,"I")'="" PSOZCL(J,2)=J,PSOZCL(J,3)=PSORX(52.052311,I_","_PSORXN_",",J,"I")
  1. S:'$D(PSOZCL) PSOZCL="" S:'$D(PSODG) PSODG=""
  1. Q
  1. ;
  1. CG ;Called from PSOCPB; for the last fill, send chrg message if released; PSOCPB too large for more code.
  1. ; this is used for SC/EI changes when no charges are cancelled. Expects to have PSODA = RXIEN and PSOLFIL= fill#
  1. ;N REL,PFS
  1. ;I 'PSOLFIL S REL=$$GET1^DIQ(52,PSODA_",","31","I")
  1. ;I PSOLFIL>0 S REL=$$GET1^DIQ(52.1,PSOLFIL_","_PSODA_",","17","I") ;REFILL
  1. ;I REL'=""&(PSOPFS)&(+$G(PSOPFSA)) D CHRG(PSODA,PSOLFIL,"CG",PSOPFS)
  1. Q
  1. ;
  1. LF(PSODA) ;return last fill number;CALLED from PSOCPB
  1. N LF
  1. I $D(^PSRX(PSODA,1,0)) S LF="A",LF=$O(^PSRX(PSODA,1,LF),-1) Q LF
  1. Q 0 ;ORIG FILL
  1. ;
  1. PFSI(PSODA,PSOREF) ;get PFSS Acct Ref and Charge ID and store in PSOPFS; Called from multiple places in this routine
  1. I PSOREF=0&($D(^PSRX(PSODA,"PFS"))) S PSOPFS=PSOPFS_"^"_$P(^PSRX(PSODA,"PFS"),"^",1,2) Q
  1. I PSOREF>0&($D(^PSRX(PSODA,1,PSOREF,"PFS"))) S PSOPFS=PSOPFS_"^"_$P(^PSRX(PSODA,1,PSOREF,"PFS"),"^",1,2)
  1. Q
  1. ;
  1. PFSA(PSODA,PSOREF,WR) ;called from PSOCP (WR=2) and PSOCPB (WR=3)
  1. ;get switch status, acct ref, and charge ID, then validate switch vs availability of PFSS acct ref
  1. Q:'$G(WR)
  1. S PSOPFS=+$$SWSTAT^IBBAPI()
  1. D PFSI(PSODA,PSOREF)
  1. ; if switch is off, but have an PFSS Acct Ref for new orders, send charge to IDX
  1. ; if switch is off, but have a Charge ID, send cancel charge to IDX
  1. I '+PSOPFS,$P(PSOPFS,"^",WR)>0 S $P(PSOPFS,"^")=1
  1. Q
  1. ;
  1. PFS ;;Called from PSOCPB; PSOCPB is too large to hold more code. Processes copay cancels for PFS only.
  1. ;find any fills being cancelled for PFSS, cancel them, and remove them from PSOCAN, then return to PSOCP to process any IB cancels
  1. ;
  1. N X,I,PSOREF,PSOOLD,PREA,PSONW
  1. ;If it's a PFS fill, if released, and not previously cancelled, set the X array, then kill it out of PSOCAN array.
  1. ;Killed out of PSOCAN because don't want the IB processing to look at PFSS billed fills.
  1. ;Note that in PSOCPD, PFS entries are not stored in PSOCAN array if a charge ID is not defined. So, don't have to check for release date.
  1. ;If prev cancelled and PFS, kill it from PSOCAN array
  1. S I="" F S I=$O(PSOCAN(I)) Q:I="" S PSOREF=+PSOCAN(I) D
  1. . I PSOREF=PSODA&($P(PSOCAN(I),"^",10)="PFS") D Q
  1. . . I $P(PSOCAN(I),"^",5)["CANCEL" K PSOCAN(I) Q
  1. . . S X(0)=$P(PSOCAN(I),"^",2)_"^"_PSORSN K PSOCAN(I)
  1. . I PSOREF'=PSODA&($P(PSOCAN(I),"^",10)="PFS") D
  1. . . I $P(PSOCAN(I),"^",5)["CANCEL" K PSOCAN(I) Q
  1. . . S X(PSOREF)=$P(PSOCAN(I),"^",2)_"^"_PSORSN K PSOCAN(I)
  1. I $G(CANTYPE)&('$D(X)) D MSGNOCAN^PSOCPB Q ;CANTYPE=1 means trying cancelling all fills;can't cancel twice
  1. ;
  1. ;send charge messages, set activity log, display message
  1. S PREA="C",PSOREF=""
  1. F S PSOREF=$O(X(PSOREF)) Q:PSOREF="" S PSOPFS=1 D PFSI(PSODA,PSOREF) D CHRG(PSODA,PSOREF,"CD",PSOPFS) D ACTLOG^PSOCPA D:'$G(CANTYPE) MSG^PSOCPB
  1. I $G(CANTYPE)&('$D(PSOCAN)) D MSG^PSOCPB ;if cancelling all and no legacy IB bills to cancel, write msg
  1. S PSOPFSA=0 ;reset variable so charge isn't sent twice if SC/EI's were also changed.
  1. Q
  1. ;