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

IBCESRV.m

Go to the documentation of this file.
  1. IBCESRV ;ALB/TMP - Server interface to IB from Austin ;8/6/03 10:04am
  1. ;;2.0;INTEGRATED BILLING;**137,181,196,232,296,320,407,623,641**;21-MAR-94;Build 61
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. SERVER ; Entry point for server option to process EDI msgs received from Austin
  1. ;
  1. N IBEFLG,IBERR,IBTDA,XMER,IBXMZ,IBHOLDCT
  1. K ^TMP("IBERR",$J),^TMP("IBMSG",$J),^TMP("IBMSGH",$J),^TMP("IB-HOLD",$J),^TMP("IBMSG-H",$J)
  1. S IBXMZ=$G(XMZ)
  1. S IBEFLG=$$MSG(.XMER,.IBTDA,IBXMZ)
  1. D:$G(IBEFLG) PERROR^IBCESRV1(.IBERR,.IBTDA,"G.IB EDI",IBXMZ)
  1. N ZTREQ
  1. D DKILL^IBCESRV1(IBXMZ) S ZTREQ="@"
  1. K ^TMP("IBERR",$J),^TMP("IBMSG",$J),^TMP("IBMSGH",$J),^TMP("IB-HOLD",$J),^TMP("IBMSG-H",$J)
  1. Q
  1. ;
  1. MSG(XMER,IBTDA,IBXMZ) ; Read/Store message lines
  1. ;
  1. I '$D(XMER) S XMER="" ;JWS IB*2.0*623
  1. ; Return message formats:
  1. ; Ref: Your <queue name> message #<msg#> with Austin ID #<id #>,
  1. ; is assigned confirmation number <confirmation #>.
  1. ; Generates an 837REC0 message
  1. ; 277STAT - claim status messages - Generates one or more 837REC1
  1. ; 837REC2 or 837REJ1 messages
  1. ; 837DEL - bill entry # from File 364
  1. ; 835EOB - Explanation of Benefits messages
  1. ; REPORT - Free text Envoy report file - may contain one or more
  1. ; reports that are turned into bulletins
  1. ;
  1. ; OUTPUT:
  1. ; Function returns flag ... 0 = no errors 1 = errors
  1. ; IBTDA - array subscripted by ien of message file entries created
  1. ; If array entry = 1, the message was only partially stored
  1. ;
  1. N IBLAST,IBTYP,IBTYP1,IB0,IBBTCH,IBDATE,IBHD,IBMG,IBRTN,IBTXN,IBTXND,XMDUZ,IBGBL,IBD,IBEFLG,IBHOLDCT,IBWANT,X,Y,Z
  1. K ^TMP("IBERR",$J),^TMP("IBMSG",$J),^TMP("IBMSGH",$J),^TMP("IB-HOLD",$J)
  1. ;
  1. S (IBEFLG,IBERR,IBTXN)="",IBGBL="IBTXN",IBLAST=0
  1. S IBD("MSG#")=IBXMZ
  1. S IBHD=$$NET^XMRENT(IBXMZ)
  1. S IBD("SUBJ")=$P(IBHD,U,6)
  1. S (X,IBDATE)=$P(IBHD,U)
  1. I X'="" D ;Reformat date, if needed
  1. . I X'["@" S X=$P(X," ",1,3)_"@"_$P(X," ",4)
  1. . N %DT
  1. . S %DT="XTS" D ^%DT S:Y>0 IBDATE=Y\.0001*.0001
  1. ;
  1. K ^TMP("IB-HOLD",$J) N IBHOLDCT S IBHOLDCT=0
  1. S IBD("Q")=$E(IBD("SUBJ"),1,3)
  1. I $G(IBD("SUBJ"))?.E1(1" MCR",1" MCT",1" MCH")1" Confirmation" D G MSGQ:$G(IBERR),MSG1
  1. . S IBD("Q")="MC"_$E($P(IBD("SUBJ")," MC",2))
  1. . ;Austin confirmation
  1. . X XMREC ; Line 1 of message
  1. . S:XMER'<0 IBHOLDCT=IBHOLDCT+1,^TMP("IB-HOLD",$J,IBHOLDCT)=XMRG
  1. . I XMER<0 D Q
  1. .. S IBERR=3
  1. .. S ^TMP("IBERR",$J,"MSG",1)=IBHD
  1. .. S ^TMP("IBERR",$J,"MSG",2)=$G(XMRG)
  1. . ;JWS;IB*2.0*641;initialize IBBTCH=0
  1. . S IBTXN=XMRG,IBBTCH=0
  1. . ;JWS;IB*2.0*641v15;don't want to take chance if value matches in FHIR, check if FHIR is off
  1. . I '$$GET1^DIQ(350.9,"1,",8.21,"I") S IBBTCH=+$O(^IBA(364.1,"MSG",+$P(IBTXN,"#",2)\1,""),-1)
  1. . ;;JWS;IB*2.0*623 - looking for original message #, but there won't be one
  1. . ;;JWS;IB*2.0*641v14;wrong value was being passed as Batch number pointer
  1. . ;; old 623 I 'IBBTCH S IBBTCH=$P($P(IBTXN,"#",2),")")
  1. . ;;JWS;IB*2.0*641v15;clean up getting IBBTCH internal pointer value, check for 837 FHIR on
  1. . I $$GET1^DIQ(350.9,"1,",8.21,"I") S IBBTCH=+$P(IBTXN,"(",3) I IBBTCH S IBBTCH=$O(^IBA(364.1,"B",IBBTCH,0))
  1. . ;I 'IBBTCH S IBBTCH=$P($P($P(IBTXN,"#",2),"(",2),")") I IBBTCH S IBBTCH=$O(^IBA(364.1,"B",IBBTCH,0))
  1. . I 'IBBTCH S IBERR=6 D REST(.IBTXN,IBGBL) Q ;No msgs match conf recpt
  1. . S IBTXN("BATCH",IBBTCH,0)="837REC0^"_IBD("MSG#")_U_+$E($P(IBD("SUBJ")," "),4,14)_"^^"_IBBTCH_U_IBDATE
  1. . X XMREC ;Get second line of the message
  1. . I XMER<0 S IBERR=2 Q
  1. . S IBTXN("BATCH",IBBTCH,1)=IBTXN_" "_XMRG_"$",IBTXN=IBTXN("BATCH",IBBTCH,0)
  1. . S IBHOLDCT=IBHOLDCT+1,^TMP("IB-HOLD",$J,IBHOLDCT)=XMRG
  1. . S IBLAST=1
  1. . Q
  1. ; Read header line of non-confirmation message (line 1)
  1. F X XMREC Q:$S(XMER<0:1,1:$E(XMRG,1,13)'="RACUBOTH RUCH")
  1. S:XMER'<0 IBHOLDCT=IBHOLDCT+1,^TMP("IB-HOLD",$J,IBHOLDCT)=XMRG
  1. I XMER<0 D G MSGQ
  1. . S IBERR=3
  1. . S ^TMP("IBERR",$J,"MSG",1)=IBHD
  1. . S ^TMP("IBERR",$J,"MSG",2)=$G(XMRG)
  1. ;
  1. S IBTXN=XMRG
  1. MSG1 I $E(IBTXN,$L(IBTXN)-3,$L(IBTXN))?3A1"."!(IBTXN="NNNN"),IBHOLDCT>1 S XMER=-1,IBLAST=1 G MSGQ
  1. ;
  1. S IBTYP1=$S($P(IBTXN,U)="277STAT":"837REC1",1:$P(IBTXN,U))
  1. S IBTYP=$S(IBTYP1="":"",1:$O(^IBE(364.3,"B",IBTYP1,"")))
  1. I IBTYP="" S IBERR=1 D REST(.IBTXN,IBGBL) G MSGQ ;Bad msg type
  1. ;
  1. S IB0=$G(^IBE(364.3,IBTYP,0)),IBRTN=$P(IB0,U,3,4),IBMG=$P(IB0,U,2)
  1. I $TR(IBRTN,U)="" S IBERR=5 D REST(.IBTXN,IBGBL) G MSGQ ;No routine defined
  1. ;
  1. S IBWANT=1
  1. I 'IBLAST,XMER'<0 D G:IBLAST&(XMER<0) MSGQ ;Message is other than Austin confirmation
  1. . S IBGBL="^TMP(""IBMSG"","_$J_")"
  1. . S @IBGBL=$P(IBTXN,U),^TMP("IBMSGH",$J,0)=IBTXN
  1. . ;
  1. . I $P(IBTXN,U)="277STAT" D Q ;Claim status message
  1. .. F X XMREC Q:XMER<0 D Q:IBLAST ;Extract rest of message
  1. ... S IBHOLDCT=IBHOLDCT+1,^TMP("IB-HOLD",$J,IBHOLDCT)=XMRG
  1. ... I +XMRG=99,$P(XMRG,U,2)="$" S IBLAST=1 Q
  1. ... S IBD=XMRG,Z=+XMRG_"^IBCE277(.IBD)"
  1. ... S IBTXN=XMRG
  1. ... I '$$CKLABEL(Z,.IBTXN,IBGBL) S IBLAST=1,IBWANT=0,XMER=-1,IBERR=7 Q
  1. ... D @Z
  1. . ;
  1. . I $P(IBTXN,U)="835EOB" D Q ;Explanation of Benefits message
  1. .. F X XMREC Q:XMER<0 D Q:IBLAST ;Extract rest of message
  1. ... S IBHOLDCT=IBHOLDCT+1,^TMP("IB-HOLD",$J,IBHOLDCT)=XMRG
  1. ... I +XMRG=99,$P(XMRG,U,2)="$" S IBLAST=1 Q
  1. ... S IBD=XMRG,Z=+XMRG_"^IBCE835(.IBD)"
  1. ... S IBTXN=XMRG
  1. ... I '$$CKLABEL(Z,.IBTXN,IBGBL) S IBLAST=1,IBWANT=0,XMER=-1,IBERR=7 Q
  1. ... D @Z
  1. . ;
  1. . I $P(IBTXN,U)="REPORT" D Q ; Report file
  1. .. D REPORT^IBCERPT(IBHD,IBDATE,.IBD,IBTXN)
  1. .. I '$O(^TMP("IBMSG",$J,"REPORT",0,"D",0,0)) S IBWANT=0
  1. . ;
  1. . ; ****** Insert code for additional message types here and in ^IBCEM
  1. ;
  1. I IBLAST,IBWANT D ADD(IBGBL,.IBTDA,.IBERR)
  1. ;
  1. I 'IBLAST,'$G(IBERR) K @IBGBL S IBERR=2 ;No $ as last character of message
  1. MSGQ I $G(IBERR) D ERRUPD^IBCESRV1(IBGBL,.IBERR) S IBEFLG=1
  1. Q IBEFLG
  1. ;
  1. REST(IBTXN,IBGBL) ;Extract raw message data if not id-ed or can't process
  1. N CT,Z
  1. S CT=0
  1. S Z=0 F S Z=$O(^TMP("IB-HOLD",$J,Z)) Q:'Z S CT=CT+1,@IBGBL@("BATCH",0,"D",0,CT)="##RAW DATA: "_$G(^TMP("IB-HOLD",$J,Z))
  1. F X XMREC Q:XMER<0 S:XMRG'="" CT=CT+1,@IBGBL@("BATCH",0,"D",0,CT)="##RAW DATA: "_XMRG
  1. Q
  1. ;
  1. ADD(IBGBL,IBTDA,IBERR) ; Add message(s) in @IBGBL to file #364.2
  1. ; Errors returned in IBERR
  1. ; Message entry #'s are returned in IBTDA(ien)=""
  1. ;
  1. N IB,IBA,IBB,IBC,IBDATA,IBHDR,IBLINE,IBTYP,IBRTN
  1. S IBA="" F S IBA=$O(@IBGBL@(IBA)) Q:IBA=""!(IBERR=3) S IBB="" F S IBB=$O(@IBGBL@(IBA,IBB)) Q:IBB=""!(IBERR=3) D
  1. . S IBHDR=$G(@IBGBL@(IBA,IBB,0))
  1. . Q:IBHDR=""
  1. . S IBTYP=$S($P(IBHDR,U)="":"",1:$O(^IBE(364.3,"B",$P(IBHDR,U),""))),IBRTN=$P($G(^IBE(364.3,IBTYP,0)),U,3,4)
  1. . S IBTDA=$$ADDTXN(IBHDR) ;File message hdr data
  1. . I IBTDA'>0 S IBERR=3 Q ;msg hdr can't be filed
  1. . S IBTDA(IBTDA)=""
  1. . D LOADDET(IBA,IBB,.IBTDA,IBGBL,.IBERR,$P(IBHDR,U,1))
  1. . Q:$G(IBERR) ;Message not completely filed
  1. . D TRTN^IBCESRV1(IBTDA):$TR(IBRTN,U)'="" ;Task update to run
  1. Q
  1. ;
  1. ADDTXN(IBDATA,REPORT) ; Add a trxn for msg in IBDATA to file 364.2
  1. ; REPORT = 1 if storing a report format message
  1. ;Function returns ien of the new entry in file 364.2 or "" if an error
  1. ;
  1. N A,IBDA,IBBTCH,IBBILL,IBDT,IBTEST,DLAYGO,DIC,DD,DO,X,Y,Z,IBIFN
  1. ;
  1. S IBDA="",IBBTCH=$P(IBDATA,U,5),IBBILL=$P(IBDATA,U,4),IBIFN=0
  1. I IBBILL S IBIFN=+$G(^IBA(364,IBBILL,0))
  1. S IBDT=$P(IBDATA,U,6)
  1. S IBTEST=0
  1. I $E($G(IBD("Q")),1,3)="MCT" D
  1. . I IBBILL,'$P($G(^IBA(364,IBBILL,0)),U,7),$D(^IBM(361.4,IBIFN,0)) S IBTEST=1 Q ; Resubmit live claim for test (make sure 361.4 exists)
  1. . I IBBTCH,$O(^IBM(361.4,"C",IBBTCH,0)) S IBTEST=1 Q ; Resubmit live claim as test batch
  1. ;
  1. S (X,A)=$G(IBD("MSG#")) ; Use msg ID for .01 field
  1. F Z=1:1 Q:'$D(^IBA(364.2,"B",A)) S A=X_"."_Z
  1. S X=A
  1. S DIC(0)="L",DIC="^IBA(364.2,",DLAYGO=364.2
  1. S DIC("DR")=".02///"_$P(IBDATA,U)_";.03///^S X=""NOW"";.08////"_($P(IBDATA,U,7)="Y")_";.13////"_$P(IBDATA,U,8)_$S(IBBILL="":"",1:";.05////"_IBBILL)_";.06////P;.1////"_IBDT_$S(IBBTCH="":"",1:";.04////"_IBBTCH)_";.14////"_IBTEST
  1. D FILE^DICN
  1. S:Y>0 IBDA=+Y
  1. ;
  1. Q IBDA
  1. ;
  1. LOADDET(IB1,IB2,IBTDA,IBGBL,IBERR,IBTNM) ; Load the rest of the message text into the message
  1. ; IB1 = "BATCH" or "CLAIM" or "REPORT"
  1. ; IB2 = batch # or claim # or 0
  1. ; IBTDA = ien in file 364.2 being updated
  1. ; IBGBL = name of the array holding the detail message text to be loaded
  1. ; IBTNM = message name (i.e. "835EOB","837REC0","REPORT",etc.)
  1. ;
  1. ; OUTPUT: IBERR if any errors found, pass by reference
  1. ; IBTDA(IBTDA)=1 if errors - pass by reference
  1. ;
  1. S IBTDA=+$G(IBTDA)
  1. N CT,IB3,IBE,IBZ,Q
  1. ;
  1. K ^TMP("IBTEXT",$J)
  1. ;
  1. S (CT,IB3)=0 ;Put formatted data into msg
  1. F S IB3=$O(@IBGBL@(IB1,IB2,IB3)) Q:'IB3 S CT=CT+1,^TMP("IBTEXT",$J,CT)=@IBGBL@(IB1,IB2,IB3)
  1. ; Add identifying data from hdr record
  1. S IB3=0 F S IB3=$O(^TMP("IBMSG-H",$J,IB1,IB2,IB3)) Q:'IB3 S CT=CT+1,^TMP("IBTEXT",$J,CT)=^TMP("IBMSG-H",$J,IB1,IB2,IB3)
  1. ;
  1. ; Put raw data into msg
  1. I $G(IBTNM)'="835EOB" D
  1. . S IBZ="" F S IBZ=$O(@IBGBL@(IB1,IB2,"D",IBZ)) Q:IBZ="" S IB3=0 F S IB3=$O(@IBGBL@(IB1,IB2,"D",IBZ,IB3)) Q:'IB3 S CT=CT+1,^TMP("IBTEXT",$J,CT)=@IBGBL@(IB1,IB2,"D",IBZ,IB3)
  1. I $G(IBTNM)="835EOB" D
  1. . S IB3=0 F S IB3=$O(@IBGBL@(IB1,IB2,"D1",IB3)) Q:'IB3 S IBZ="" F S IBZ=$O(@IBGBL@(IB1,IB2,"D1",IB3,IBZ)) Q:IBZ="" S CT=CT+1,^TMP("IBTEXT",$J,CT)=@IBGBL@(IB1,IB2,"D1",IB3,IBZ)
  1. ;
  1. D STOREM^IBCESRV2(IBTDA,"^TMP(""IBTEXT"",$J)",.IBE)
  1. ;
  1. I $D(IBE("DIERR")) D S:$L($G(IBE)) IBERR(IBTDA,IB1,IB2)=IBE ; Extract error
  1. . D EXTERR^IBCESRV1(.IBERR,.IBTDA,.IBE)
  1. K ^TMP("IBTEXT",$J)
  1. Q
  1. ;
  1. CKLABEL(Z,IBTXN,IBGBL) ; Checks to be sure label in Z exists.
  1. ; If it doesn't exist, files an error and returns 0
  1. ; OR returns 1 if it does exist
  1. N X,LAB
  1. S X=1,LAB=$P(Z,"(")
  1. I $S('LAB!($L($P(LAB,U))>8):1,1:$T(@LAB)="") S X=0 D REST(.IBTXN,IBGBL)
  1. Q X
  1. ;
  1. ERROR ; Error condition messages
  1. ;;Message code does not exist in IB MESSAGE ROUTER file (364.3).
  1. ;;This message has no ending $.
  1. ;;Message file problem - no message stored.
  1. ;;Message file problem - message partially stored.
  1. ;;Routine to process this message type does not exist.
  1. ;;Batch does not exist for this confirmation message.
  1. ;;Bad message format found - cannot store message.
  1. ;