IBCIST ;DSI/SLM - ENTRY POINTS FOR CLAIMSMANAGER INTERFACE ;7-MAR-2001
 ;;2.0;INTEGRATED BILLING;**161**;21-MAR-94
 ;;Per VHA Directive 10-93-142, this routine should not be modified.
 ;
ST1 ;add or update in 351.9
 Q:'$D(IBIFN)
 Q:$$CK1^IBCIUT1(IBIFN)     ; Exit if the bill is not a HCFA-1500
 K IBCIREDT     ; remove the re-edit flag upon start of bill edit
 ;
 ; If the bill is not editable, then just quit.
 ; This can happen in the IB PRINT BILL option when the user wants to
 ; review the IB screens on a bill that has already been authorized.
 ; esg - 5/22/01
 ;
 I '$F(".1.","."_$P($G(^DGCR(399,IBIFN,0)),U,13)_".") Q  ;DSI/DJW 3/21/02
 ;
 I '$D(^IBA(351.9,IBIFN)) D ADD^IBCIADD1 Q
 D UPDT1,OVRDN,UPDT^IBCIADD1
ST1Q Q
 ;
ST2 ;send to claimsmanager
 ;  When calling ST2 the following 4 variables will always be returned:
 ;    IBCISNT  - identifies where it was sent from
 ;    IBCIERR  - error code if error condition
 ;    IBCISTAT - claim status in 351.9
 ;    IBCIREDT - re-edit flag
 ;
 I '$D(IBIFN) Q                        ; check for ibifn
 I '$D(IBCISNT) Q                      ; check for this variable
 I IBCISNT'=7 D CKFT^IBCIUT1(IBIFN)    ; check for form type change
 I IBCISNT'=7,$$CK1^IBCIUT1(IBIFN) Q   ; check for hcfa 1500
 I '$D(^IBA(351.9,IBIFN)) Q            ; check for existence in 351.9
 ;
 NEW IBCIMT
 S IBCIERR="",IBCIREDT=0,IBCIMT=$$ENV^IBCIUT5
 ;
 ;if claimsmanager not working okay update status and quit
 I '$$CK2^IBCIUT1() D  G ST2Q
 .I IBCISNT=1 S (IBCIST,IBCISTAT)=7 D ST^IBCIUT1(IBCIST) Q
 .I IBCISNT=2 S (IBCIST,IBCISTAT)=7 D ST^IBCIUT1(IBCIST) Q
 .I IBCISNT=3 Q
 .I IBCISNT=4 S (IBCIST,IBCISTAT)=10 D ST^IBCIUT1(IBCIST) Q
 .I IBCISNT=5 S (IBCIST,IBCISTAT)=11 D ST^IBCIUT1(IBCIST) Q
 .I IBCISNT=6 S (IBCIST,IBCISTAT)=7 D ST^IBCIUT1(IBCIST) Q
 ;
 ;normal send
 I IBCISNT=1 D MSG1,SEND D  G ST2Q
 .D UPDT1,UPDT2
 .I IBCISTAT=6 D MSG3
 .I IBCISTAT=3 D MSG2
 .I IBCISTAT=4 D EN^IBCIWK(1)
 ;
 ;multiple send option - not authorized
 I IBCISNT=2 D  G ST2Q
 .I '$$CKLI^IBCIUT1(IBIFN) Q       ; check for line items
 .D SEND
 .D UPDT1,UPDT2
 .I IBCISTAT=4 D
 ..N IBCIETP
 ..S IBCIETP=""
 ..F  S IBCIETP=$O(^IBA(351.9,IBIFN,1,"B",IBCIETP)) Q:IBCIETP=""  D GENERR^IBCIUT4(IBIFN,IBCIETP)
 ..Q
 ;
 ;test send
 I IBCISNT=3 D  G ST2Q
 .D MSG1,SEND
 .I IBCISTAT=3 D MSG2
 ;
 ;cancelled
 I IBCISNT=4 D  G ST2Q
 .D COMMENT^IBCIUT7(IBIFN,3)
 .; if the bill has never been sent to CM or if there are currently
 .; no line items on the bill, then just change the status and quit
 .I '$P(^IBA(351.9,IBIFN,0),U,15)!('$$CKLI^IBCIUT1(IBIFN)) D  Q
 ..S IBCIST=9 D ST^IBCIUT1(IBCIST)
 ..D DELTI^IBCIUT4   ;delete temp nodes on a cancel even when not sending to claimsmanager
 .D UPDT1,UPDT2,SEND
 ;
 ;overridden
 I IBCISNT=5 D  G ST2Q
 .D UPDT1,UPDT2,OVRDN1,SEND
 ;
 ;multiple send option - authorized
 I IBCISNT=6 D  G ST2Q
 .I '$$CKLI^IBCIUT1(IBIFN) Q       ; check for line items
 .D UPDT1,UPDT2,SEND
 ;
 ;
 ; Notes about IBCISNT=7 - esg - 1/3/2002
 ; User changed the form type from a HCFA into a UB and this bill
 ; has been previously sent to ClaimsManager as a HCFA.  So this
 ; bill is currently a UB bill, but we need to send it to
 ; ClaimsManager in order to delete the line items over there.
 ; Ultimately, this bill will get deleted from 351.9, but we have
 ; to send it over there first.
 ;
 I IBCISNT=7 D  G ST2Q
 . I '$$CKLI^IBCIUT1(IBIFN) Q      ; check for line items
 . D SEND
 . Q
 ;
 ;
ST2Q D CLEAN1^IBCIUT2 K PROBLEM
 Q
 ;
SEND ; send the bill to claimsmanager
 I $$ASND^IBCIUT2(IBIFN) G SENDX    ; no tcp/ip problems
 D COMERR^IBCIUT4                   ; communications error mail message
 I PROBLEM'=99 D CLRCMQ^IBCIUT6(0)  ; clear CM queue (silent mode)
SENDX ;
 Q
 ;
UPDT1 ; update certain fields when editing
 ; update the Date/Time Last Edited field (.08)
 ; update the User Last Edited field (.09)
 ;
 N IENS,FDA
 S IENS=IBIFN_",",FDA(351.9,IENS,.08)=$$NOW^XLFDT,FDA(351.9,IENS,.09)=DUZ
 D FILE^DIE("K","FDA")
 Q
 ;
UPDT2 ; update certain fields when sending
 ; update the Entered By User field if not there (.07)
 ; update the Date/Time Entered field if not there (.06)
 ; update the number of times sent to ClaimsManager (.04)
 ; update the Date/Time last sent to ClaimsManager (.03)
 ; update the Last Sent By User field (.05)
 ;
 N IENS,FDA,IBCIEB,IBCIDE
 S IENS=IBIFN_","
 I $P(^IBA(351.9,IBIFN,0),U,7)="" S FDA(351.9,IENS,.07)=DUZ
 I $P(^IBA(351.9,IBIFN,0),U,6)="" S FDA(351.9,IENS,.06)=$$NOW^XLFDT
 S IBCILSI=$$NOW^XLFDT,CTR=$S($P(^IBA(351.9,IBIFN,0),U,4)]"":$P(^(0),U,4),1:0)
 S IBCITSI=CTR+1,FDA(351.9,IENS,.04)=IBCITSI
 S FDA(351.9,IENS,.03)=IBCILSI,FDA(351.9,IENS,.05)=DUZ
 D FILE^DIE("K","FDA")
 Q
 ;
OVRDN ;clear if overridden
 N IENS,FDA
 I $P(^IBA(351.9,IBIFN,0),U,10)]"" D
 .S IENS=IBIFN_","
 .S FDA(351.9,IENS,.1)="",FDA(351.9,IENS,.11)=""
 .D FILE^DIE("K","FDA")
 Q
OVRDN1 ;set if overridden
 N IENS,FDA
 S IENS=IBIFN_","
 S FDA(351.9,IENS,.1)=1,FDA(351.9,IENS,.11)=DUZ
 D FILE^DIE("K","FDA")
 Q
MSG1 ;display 'sending to ClaimsManager' message
 W !!,"... ",$S(IBCIMT="T":"TEST-",1:""),"Sending ",$P(^DGCR(399,IBIFN,0),U)," to ClaimsManager"
 Q
MSG2 ;display 'no errors found' message
 W !!,"No Errors found by ClaimsManager"
 Q
MSG3 ;display 'comm error' messsage
 W !!,"Communications Error - Not Sent to ClaimsManager"
 W !?3,$P(IBCIERR,U,2)
 I $P(IBCIERR,U,3)'="" D
 . W !?3,$P($P(IBCIERR,U,3)," - ",1)
 . W !?3,$P($P(IBCIERR,U,3,99)," - ",2,99)
 . Q
 Q
MSG4 ;display 'no line items' message
 W !!,"There are no line items associated with this claim."
 W !!,"ClaimsManager cannot process without line items. Please"
 W !,"enter the line item data and resend."
 Q
MSG5 ;display 'cancelled' message
 W !!,"... Claim has been CANCELLED in ClaimsManager."
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HIBCIST   5897     printed  Sep 23, 2025@19:49:38                                                                                                                                                                                                      Page 2
IBCIST    ;DSI/SLM - ENTRY POINTS FOR CLAIMSMANAGER INTERFACE ;7-MAR-2001
 +1       ;;2.0;INTEGRATED BILLING;**161**;21-MAR-94
 +2       ;;Per VHA Directive 10-93-142, this routine should not be modified.
 +3       ;
ST1       ;add or update in 351.9
 +1        if '$DATA(IBIFN)
               QUIT 
 +2       ; Exit if the bill is not a HCFA-1500
           if $$CK1^IBCIUT1(IBIFN)
               QUIT 
 +3       ; remove the re-edit flag upon start of bill edit
           KILL IBCIREDT
 +4       ;
 +5       ; If the bill is not editable, then just quit.
 +6       ; This can happen in the IB PRINT BILL option when the user wants to
 +7       ; review the IB screens on a bill that has already been authorized.
 +8       ; esg - 5/22/01
 +9       ;
 +10      ;DSI/DJW 3/21/02
           IF '$FIND(".1.","."_$PIECE($GET(^DGCR(399,IBIFN,0)),U,13)_".")
               QUIT 
 +11      ;
 +12       IF '$DATA(^IBA(351.9,IBIFN))
               DO ADD^IBCIADD1
               QUIT 
 +13       DO UPDT1
           DO OVRDN
           DO UPDT^IBCIADD1
ST1Q       QUIT 
 +1       ;
ST2       ;send to claimsmanager
 +1       ;  When calling ST2 the following 4 variables will always be returned:
 +2       ;    IBCISNT  - identifies where it was sent from
 +3       ;    IBCIERR  - error code if error condition
 +4       ;    IBCISTAT - claim status in 351.9
 +5       ;    IBCIREDT - re-edit flag
 +6       ;
 +7       ; check for ibifn
           IF '$DATA(IBIFN)
               QUIT 
 +8       ; check for this variable
           IF '$DATA(IBCISNT)
               QUIT 
 +9       ; check for form type change
           IF IBCISNT'=7
               DO CKFT^IBCIUT1(IBIFN)
 +10      ; check for hcfa 1500
           IF IBCISNT'=7
               IF $$CK1^IBCIUT1(IBIFN)
                   QUIT 
 +11      ; check for existence in 351.9
           IF '$DATA(^IBA(351.9,IBIFN))
               QUIT 
 +12      ;
 +13       NEW IBCIMT
 +14       SET IBCIERR=""
           SET IBCIREDT=0
           SET IBCIMT=$$ENV^IBCIUT5
 +15      ;
 +16      ;if claimsmanager not working okay update status and quit
 +17       IF '$$CK2^IBCIUT1()
               Begin DoDot:1
 +18               IF IBCISNT=1
                       SET (IBCIST,IBCISTAT)=7
                       DO ST^IBCIUT1(IBCIST)
                       QUIT 
 +19               IF IBCISNT=2
                       SET (IBCIST,IBCISTAT)=7
                       DO ST^IBCIUT1(IBCIST)
                       QUIT 
 +20               IF IBCISNT=3
                       QUIT 
 +21               IF IBCISNT=4
                       SET (IBCIST,IBCISTAT)=10
                       DO ST^IBCIUT1(IBCIST)
                       QUIT 
 +22               IF IBCISNT=5
                       SET (IBCIST,IBCISTAT)=11
                       DO ST^IBCIUT1(IBCIST)
                       QUIT 
 +23               IF IBCISNT=6
                       SET (IBCIST,IBCISTAT)=7
                       DO ST^IBCIUT1(IBCIST)
                       QUIT 
               End DoDot:1
               GOTO ST2Q
 +24      ;
 +25      ;normal send
 +26       IF IBCISNT=1
               DO MSG1
               DO SEND
               Begin DoDot:1
 +27               DO UPDT1
                   DO UPDT2
 +28               IF IBCISTAT=6
                       DO MSG3
 +29               IF IBCISTAT=3
                       DO MSG2
 +30               IF IBCISTAT=4
                       DO EN^IBCIWK(1)
               End DoDot:1
               GOTO ST2Q
 +31      ;
 +32      ;multiple send option - not authorized
 +33       IF IBCISNT=2
               Begin DoDot:1
 +34      ; check for line items
                   IF '$$CKLI^IBCIUT1(IBIFN)
                       QUIT 
 +35               DO SEND
 +36               DO UPDT1
                   DO UPDT2
 +37               IF IBCISTAT=4
                       Begin DoDot:2
 +38                       NEW IBCIETP
 +39                       SET IBCIETP=""
 +40                       FOR 
                               SET IBCIETP=$ORDER(^IBA(351.9,IBIFN,1,"B",IBCIETP))
                               if IBCIETP=""
                                   QUIT 
                               DO GENERR^IBCIUT4(IBIFN,IBCIETP)
 +41                       QUIT 
                       End DoDot:2
               End DoDot:1
               GOTO ST2Q
 +42      ;
 +43      ;test send
 +44       IF IBCISNT=3
               Begin DoDot:1
 +45               DO MSG1
                   DO SEND
 +46               IF IBCISTAT=3
                       DO MSG2
               End DoDot:1
               GOTO ST2Q
 +47      ;
 +48      ;cancelled
 +49       IF IBCISNT=4
               Begin DoDot:1
 +50               DO COMMENT^IBCIUT7(IBIFN,3)
 +51      ; if the bill has never been sent to CM or if there are currently
 +52      ; no line items on the bill, then just change the status and quit
 +53               IF '$PIECE(^IBA(351.9,IBIFN,0),U,15)!('$$CKLI^IBCIUT1(IBIFN))
                       Begin DoDot:2
 +54                       SET IBCIST=9
                           DO ST^IBCIUT1(IBCIST)
 +55      ;delete temp nodes on a cancel even when not sending to claimsmanager
                           DO DELTI^IBCIUT4
                       End DoDot:2
                       QUIT 
 +56               DO UPDT1
                   DO UPDT2
                   DO SEND
               End DoDot:1
               GOTO ST2Q
 +57      ;
 +58      ;overridden
 +59       IF IBCISNT=5
               Begin DoDot:1
 +60               DO UPDT1
                   DO UPDT2
                   DO OVRDN1
                   DO SEND
               End DoDot:1
               GOTO ST2Q
 +61      ;
 +62      ;multiple send option - authorized
 +63       IF IBCISNT=6
               Begin DoDot:1
 +64      ; check for line items
                   IF '$$CKLI^IBCIUT1(IBIFN)
                       QUIT 
 +65               DO UPDT1
                   DO UPDT2
                   DO SEND
               End DoDot:1
               GOTO ST2Q
 +66      ;
 +67      ;
 +68      ; Notes about IBCISNT=7 - esg - 1/3/2002
 +69      ; User changed the form type from a HCFA into a UB and this bill
 +70      ; has been previously sent to ClaimsManager as a HCFA.  So this
 +71      ; bill is currently a UB bill, but we need to send it to
 +72      ; ClaimsManager in order to delete the line items over there.
 +73      ; Ultimately, this bill will get deleted from 351.9, but we have
 +74      ; to send it over there first.
 +75      ;
 +76       IF IBCISNT=7
               Begin DoDot:1
 +77      ; check for line items
                   IF '$$CKLI^IBCIUT1(IBIFN)
                       QUIT 
 +78               DO SEND
 +79               QUIT 
               End DoDot:1
               GOTO ST2Q
 +80      ;
 +81      ;
ST2Q       DO CLEAN1^IBCIUT2
           KILL PROBLEM
 +1        QUIT 
 +2       ;
SEND      ; send the bill to claimsmanager
 +1       ; no tcp/ip problems
           IF $$ASND^IBCIUT2(IBIFN)
               GOTO SENDX
 +2       ; communications error mail message
           DO COMERR^IBCIUT4
 +3       ; clear CM queue (silent mode)
           IF PROBLEM'=99
               DO CLRCMQ^IBCIUT6(0)
SENDX     ;
 +1        QUIT 
 +2       ;
UPDT1     ; update certain fields when editing
 +1       ; update the Date/Time Last Edited field (.08)
 +2       ; update the User Last Edited field (.09)
 +3       ;
 +4        NEW IENS,FDA
 +5        SET IENS=IBIFN_","
           SET FDA(351.9,IENS,.08)=$$NOW^XLFDT
           SET FDA(351.9,IENS,.09)=DUZ
 +6        DO FILE^DIE("K","FDA")
 +7        QUIT 
 +8       ;
UPDT2     ; update certain fields when sending
 +1       ; update the Entered By User field if not there (.07)
 +2       ; update the Date/Time Entered field if not there (.06)
 +3       ; update the number of times sent to ClaimsManager (.04)
 +4       ; update the Date/Time last sent to ClaimsManager (.03)
 +5       ; update the Last Sent By User field (.05)
 +6       ;
 +7        NEW IENS,FDA,IBCIEB,IBCIDE
 +8        SET IENS=IBIFN_","
 +9        IF $PIECE(^IBA(351.9,IBIFN,0),U,7)=""
               SET FDA(351.9,IENS,.07)=DUZ
 +10       IF $PIECE(^IBA(351.9,IBIFN,0),U,6)=""
               SET FDA(351.9,IENS,.06)=$$NOW^XLFDT
 +11       SET IBCILSI=$$NOW^XLFDT
           SET CTR=$SELECT($PIECE(^IBA(351.9,IBIFN,0),U,4)]"":$PIECE(^(0),U,4),1:0)
 +12       SET IBCITSI=CTR+1
           SET FDA(351.9,IENS,.04)=IBCITSI
 +13       SET FDA(351.9,IENS,.03)=IBCILSI
           SET FDA(351.9,IENS,.05)=DUZ
 +14       DO FILE^DIE("K","FDA")
 +15       QUIT 
 +16      ;
OVRDN     ;clear if overridden
 +1        NEW IENS,FDA
 +2        IF $PIECE(^IBA(351.9,IBIFN,0),U,10)]""
               Begin DoDot:1
 +3                SET IENS=IBIFN_","
 +4                SET FDA(351.9,IENS,.1)=""
                   SET FDA(351.9,IENS,.11)=""
 +5                DO FILE^DIE("K","FDA")
               End DoDot:1
 +6        QUIT 
OVRDN1    ;set if overridden
 +1        NEW IENS,FDA
 +2        SET IENS=IBIFN_","
 +3        SET FDA(351.9,IENS,.1)=1
           SET FDA(351.9,IENS,.11)=DUZ
 +4        DO FILE^DIE("K","FDA")
 +5        QUIT 
MSG1      ;display 'sending to ClaimsManager' message
 +1        WRITE !!,"... ",$SELECT(IBCIMT="T":"TEST-",1:""),"Sending ",$PIECE(^DGCR(399,IBIFN,0),U)," to ClaimsManager"
 +2        QUIT 
MSG2      ;display 'no errors found' message
 +1        WRITE !!,"No Errors found by ClaimsManager"
 +2        QUIT 
MSG3      ;display 'comm error' messsage
 +1        WRITE !!,"Communications Error - Not Sent to ClaimsManager"
 +2        WRITE !?3,$PIECE(IBCIERR,U,2)
 +3        IF $PIECE(IBCIERR,U,3)'=""
               Begin DoDot:1
 +4                WRITE !?3,$PIECE($PIECE(IBCIERR,U,3)," - ",1)
 +5                WRITE !?3,$PIECE($PIECE(IBCIERR,U,3,99)," - ",2,99)
 +6                QUIT 
               End DoDot:1
 +7        QUIT 
MSG4      ;display 'no line items' message
 +1        WRITE !!,"There are no line items associated with this claim."
 +2        WRITE !!,"ClaimsManager cannot process without line items. Please"
 +3        WRITE !,"enter the line item data and resend."
 +4        QUIT 
MSG5      ;display 'cancelled' message
 +1        WRITE !!,"... Claim has been CANCELLED in ClaimsManager."
 +2        QUIT