- BARSYNC ; IHS/SD/LSL - File Synchronization ;
- ;;1.8;IHS ACCOUNTS RECEIVABLE;;OCT 26, 2005
- ;
- ; IHS/SD/LSL - 05/21/02 - V1.6 Patch 2
- ; Called by A/R V1.6 Patch 2 post init (BARPOST2)
- ; Routine created
- ;
- ; IHS/SD/LSL - 01/13/03 - V1.7
- ; Called by A/R V1.7 post init routine (BARPT17) since V1.7
- ; includes a modification that should resolve the issue of the
- ; Transaction History being out of sync with the balance on the
- ; bill. Routine modified to restructure global by date AUTO SYNC
- ; was run in order to contain historical data.
- ;
- ; *********************************************************************
- ;
- ; This routine will compare the Current Bill Amount of the A/R Bill
- ; File to the A/R Transaction history balance. If they are not
- ; equal, it will create a transaction (AUTO SYNC) that will make
- ; them equal. This transaction will not be reflected on the
- ; A/R Current Bill amount. Nor will it be reflected on the current
- ; Period Summary Report. The bills that were touched will be
- ; stored in
- ;
- ; ^BARSYNC(BARSTART,DUZ(2),BARVISOU,BARAC,BARDOS,BARBILL)=BARBAMT^BARTAMT
- ;
- ; Where: BARSTART = Date AUTO SYNC was run
- ; DUZ(2) = Billing location
- ; BARVIS = Visit type on A/R Bill
- ; BARAC = A/R Account on A/R Bill
- ; BARDOS = DOS Begin on A/R Bill
- ; BARBILL = A/R Bill
- ; BARBAMT = Current Bill Amount from A/R Bill File
- ; BARTAMT = Transaction History Balance
- ;
- ; This global will be used when printing the Auto Sync Report
- ; from the Manager Reports Menu.
- ;
- ; *********************************************************************
- Q
- ; *********************************************************************
- ENPOST ; EP - Entry point for Post init process to allow tasking.
- D START
- Q
- ; *********************************************************************
- ;
- EN ; EP - Entry point for processing other than post init.
- S BARAGAIN=1 ; Default, run auto sync
- I $D(^BARSYNC) D ASKAGAIN ; Already run, ask again?
- Q:'+BARAGAIN ; No, don't run again.
- W !,"Auto Sync in Progress...",!
- D START
- W !,"Auto Sync Complete.",!!
- Q
- ; *********************************************************************
- ;
- ASKAGAIN ;
- S BARLASTB=$O(^BARSYNC(9999999),-1)
- S BARLASTE=$G(^BARSYNC(BARLASTB,"STOP"))
- S Y=BARLASTB
- D DD^%DT
- S BARLASTB=Y
- I +$G(BARLASTE) D
- . S Y=BARLASTE
- . D DD^%DT
- . S BARLASTE=Y
- W !!,$$CJ^XLFSTR("Auto Sync was last run on "_BARLASTB,IOM)
- I $G(BARLASTE)="" W !,$$CJ^XLFSTR(" and did NOT complete.",IOM),!
- E W !,$$CJ^XLFSTR(" and completed on "_BARLASTE_".",IOM),!
- K DIR
- S DIR(0)="Y"
- S DIR("A")="Do you wish to execute Auto Sync again"
- S DIR("B")="N"
- D ^DIR
- I Y'=1 S BARAGAIN=0 Q
- S BARAGAIN=1
- Q
- ; *********************************************************************
- ;
- START ;
- I $O(^BARSYNC(""))'["." D MERGE
- D NOW^%DTC
- S BARSTART=%
- S ^BARSYNC(BARSTART,"START")=BARSTART
- S BARJOURN=$$NOJOURN^ZIBGCHAR("BARSYNC")
- S BARDUZ=DUZ(2)
- S DUZ(2)=0
- F S DUZ(2)=$O(^BARBL(DUZ(2))) Q:'+DUZ(2) D
- . S BARBILL=0
- . F S BARBILL=$O(^BARBL(DUZ(2),BARBILL)) Q:'+BARBILL D
- . . Q:'$D(^BARBL(DUZ(2),BARBILL,0)) ; No data on bill
- . . D BILLDATA
- . . D TRDATA
- . . Q:+BARBAMT=BARTAMT ; Files are in sync
- . . S BARDIF=BARBAMT-BARTAMT
- . . D TRANS
- . . Q:BARTRIEN<1 ; Trans not created
- . . D SETSYNC
- S DUZ(2)=BARDUZ
- D NOW^%DTC
- S ^BARSYNC(BARSTART,"STOP")=%
- Q
- ; *********************************************************************
- ;
- MERGE ;
- ; Convert GLOBAL to accomodate multiple executions of Auto Sync
- N BARDATE
- S BARDATE=+$G(^BARSYNC("START"))
- Q:'+BARDATE
- M ^BARTMP($J,BARDATE)=^BARSYNC
- S BARX=""
- F S BARX=$O(^BARSYNC(BARX)) Q:BARX="" D
- . K ^BARSYNC(BARX)
- M ^BARSYNC=^BARTMP($J)
- K ^BARTMP($J)
- Q
- ; *********************************************************************
- ;
- BILLDATA ;
- ; Gather data from A/R Bill file.
- F I=0:1:1 S BARBL(I)=$G(^BARBL(DUZ(2),BARBILL,I))
- S BARBAMT=$P(BARBL(0),U,15) ; Current bill amount
- S BARAC=$$GET1^DIQ(90050.01,BARBILL,3) ; A/R Account (external)
- S:BARAC="" BARAC="NO A/R ACCOUNT"
- S BARDOS=$P(BARBL(1),U,2) ; DOS Begin
- I BARDOS="" S BARDOS=99
- S BARVIS=$P(BARBL(1),U,8) ; Visit location
- I +BARVIS S BARVISOU=$$GET1^DIQ(4,BARVIS,.01)
- E S BARVISOU="NO VISIT LOCATION"
- Q
- ; *********************************************************************
- TRDATA ;
- ; Gather data for A/R Bill from A/R Transaction File via "AC" x-ref
- ; Find PSR transactions and do math to find balance
- S (BARTR,BARTAMT)=0
- F S BARTR=$O(^BARTR(DUZ(2),"AC",BARBILL,BARTR)) Q:'+BARTR D
- . Q:'$D(^BARTR(DUZ(2),BARTR,0)) ; No transaction data
- . F I=0:1:1 S BARTR(I)=$G(^BARTR(DUZ(2),BARTR,I))
- . S BARTRTYP=$P(BARTR(1),U) ; Trans type (pointer)
- . S BARADCAT=$P(BARTR(1),U,2) ; Adjust cat (pointer)
- . S BARCDT=$P(BARTR(0),U,2)
- . S BARDBT=$P(BARTR(0),U,3)
- . I ",3,4,13,14,15,16,19,20,"'[(","_BARADCAT_",")&(",40,49,39,108,503,504,"'[(","_BARTRTYP_",")) Q
- . S BARTAMT=BARTAMT+BARDBT-BARCDT
- Q
- ; *********************************************************************
- ;
- TRANS ;
- ; Create Auto Sync Transaction
- ;
- S BARTRIEN=$$NEW^BARTR
- Q:BARTRIEN<1
- ;
- I BARDIF>0 S DR="3////^S X=$FN(BARDIF,""-"")" ; Debit
- E S DR="2////^S X=$FN(BARDIF,""-"")" ; Credit
- S DR=DR_";4////^S X=BARBILL" ; A/R bill
- S DR=DR_";5////^S X=$P(BARBL(1),U)" ; Patient
- S DR=DR_";6////^S X=$P(BARBL(0),U,3)" ; A/R acct
- S DR=DR_";8////^S X=$P(BARBL(0),U,8)" ; Parent location
- S DR=DR_";9////^S X=DUZ(2)" ; Parent ASUFAC
- S DR=DR_";10////8" ; Service/section
- S DR=DR_";11////^S X=BARVIS" ; visit location
- S DR=DR_";12////^S X=DT" ; Date
- S DR=DR_";13////^S X=DUZ" ; Entry By
- S DR=DR_";101////504" ; Transaction type
- ;
- S DA=BARTRIEN
- S DIE=90050.03
- S DIDEL=90050
- D ^DIE
- K DIDEL,DIE,DA,DR
- Q
- ; *********************************************************************
- SETSYNC ;
- ; Set data into ^BARSYNC
- S ^BARSYNC(BARSTART,DUZ(2),BARVISOU,BARAC,BARDOS,BARBILL)=BARBAMT_U_BARTAMT
- Q
- BARSYNC ; IHS/SD/LSL - File Synchronization ;
- +1 ;;1.8;IHS ACCOUNTS RECEIVABLE;;OCT 26, 2005
- +2 ;
- +3 ; IHS/SD/LSL - 05/21/02 - V1.6 Patch 2
- +4 ; Called by A/R V1.6 Patch 2 post init (BARPOST2)
- +5 ; Routine created
- +6 ;
- +7 ; IHS/SD/LSL - 01/13/03 - V1.7
- +8 ; Called by A/R V1.7 post init routine (BARPT17) since V1.7
- +9 ; includes a modification that should resolve the issue of the
- +10 ; Transaction History being out of sync with the balance on the
- +11 ; bill. Routine modified to restructure global by date AUTO SYNC
- +12 ; was run in order to contain historical data.
- +13 ;
- +14 ; *********************************************************************
- +15 ;
- +16 ; This routine will compare the Current Bill Amount of the A/R Bill
- +17 ; File to the A/R Transaction history balance. If they are not
- +18 ; equal, it will create a transaction (AUTO SYNC) that will make
- +19 ; them equal. This transaction will not be reflected on the
- +20 ; A/R Current Bill amount. Nor will it be reflected on the current
- +21 ; Period Summary Report. The bills that were touched will be
- +22 ; stored in
- +23 ;
- +24 ; ^BARSYNC(BARSTART,DUZ(2),BARVISOU,BARAC,BARDOS,BARBILL)=BARBAMT^BARTAMT
- +25 ;
- +26 ; Where: BARSTART = Date AUTO SYNC was run
- +27 ; DUZ(2) = Billing location
- +28 ; BARVIS = Visit type on A/R Bill
- +29 ; BARAC = A/R Account on A/R Bill
- +30 ; BARDOS = DOS Begin on A/R Bill
- +31 ; BARBILL = A/R Bill
- +32 ; BARBAMT = Current Bill Amount from A/R Bill File
- +33 ; BARTAMT = Transaction History Balance
- +34 ;
- +35 ; This global will be used when printing the Auto Sync Report
- +36 ; from the Manager Reports Menu.
- +37 ;
- +38 ; *********************************************************************
- +39 QUIT
- +40 ; *********************************************************************
- ENPOST ; EP - Entry point for Post init process to allow tasking.
- +1 DO START
- +2 QUIT
- +3 ; *********************************************************************
- +4 ;
- EN ; EP - Entry point for processing other than post init.
- +1 ; Default, run auto sync
- SET BARAGAIN=1
- +2 ; Already run, ask again?
- IF $DATA(^BARSYNC)
- DO ASKAGAIN
- +3 ; No, don't run again.
- IF '+BARAGAIN
- QUIT
- +4 WRITE !,"Auto Sync in Progress...",!
- +5 DO START
- +6 WRITE !,"Auto Sync Complete.",!!
- +7 QUIT
- +8 ; *********************************************************************
- +9 ;
- ASKAGAIN ;
- +1 SET BARLASTB=$ORDER(^BARSYNC(9999999),-1)
- +2 SET BARLASTE=$GET(^BARSYNC(BARLASTB,"STOP"))
- +3 SET Y=BARLASTB
- +4 DO DD^%DT
- +5 SET BARLASTB=Y
- +6 IF +$GET(BARLASTE)
- Begin DoDot:1
- +7 SET Y=BARLASTE
- +8 DO DD^%DT
- +9 SET BARLASTE=Y
- End DoDot:1
- +10 WRITE !!,$$CJ^XLFSTR("Auto Sync was last run on "_BARLASTB,IOM)
- +11 IF $GET(BARLASTE)=""
- WRITE !,$$CJ^XLFSTR(" and did NOT complete.",IOM),!
- +12 IF '$TEST
- WRITE !,$$CJ^XLFSTR(" and completed on "_BARLASTE_".",IOM),!
- +13 KILL DIR
- +14 SET DIR(0)="Y"
- +15 SET DIR("A")="Do you wish to execute Auto Sync again"
- +16 SET DIR("B")="N"
- +17 DO ^DIR
- +18 IF Y'=1
- SET BARAGAIN=0
- QUIT
- +19 SET BARAGAIN=1
- +20 QUIT
- +21 ; *********************************************************************
- +22 ;
- START ;
- +1 IF $ORDER(^BARSYNC(""))'["."
- DO MERGE
- +2 DO NOW^%DTC
- +3 SET BARSTART=%
- +4 SET ^BARSYNC(BARSTART,"START")=BARSTART
- +5 SET BARJOURN=$$NOJOURN^ZIBGCHAR("BARSYNC")
- +6 SET BARDUZ=DUZ(2)
- +7 SET DUZ(2)=0
- +8 FOR
- SET DUZ(2)=$ORDER(^BARBL(DUZ(2)))
- IF '+DUZ(2)
- QUIT
- Begin DoDot:1
- +9 SET BARBILL=0
- +10 FOR
- SET BARBILL=$ORDER(^BARBL(DUZ(2),BARBILL))
- IF '+BARBILL
- QUIT
- Begin DoDot:2
- +11 ; No data on bill
- IF '$DATA(^BARBL(DUZ(2),BARBILL,0))
- QUIT
- +12 DO BILLDATA
- +13 DO TRDATA
- +14 ; Files are in sync
- IF +BARBAMT=BARTAMT
- QUIT
- +15 SET BARDIF=BARBAMT-BARTAMT
- +16 DO TRANS
- +17 ; Trans not created
- IF BARTRIEN<1
- QUIT
- +18 DO SETSYNC
- End DoDot:2
- End DoDot:1
- +19 SET DUZ(2)=BARDUZ
- +20 DO NOW^%DTC
- +21 SET ^BARSYNC(BARSTART,"STOP")=%
- +22 QUIT
- +23 ; *********************************************************************
- +24 ;
- MERGE ;
- +1 ; Convert GLOBAL to accomodate multiple executions of Auto Sync
- +2 NEW BARDATE
- +3 SET BARDATE=+$GET(^BARSYNC("START"))
- +4 IF '+BARDATE
- QUIT
- +5 MERGE ^BARTMP($JOB,BARDATE)=^BARSYNC
- +6 SET BARX=""
- +7 FOR
- SET BARX=$ORDER(^BARSYNC(BARX))
- IF BARX=""
- QUIT
- Begin DoDot:1
- +8 KILL ^BARSYNC(BARX)
- End DoDot:1
- +9 MERGE ^BARSYNC=^BARTMP($JOB)
- +10 KILL ^BARTMP($JOB)
- +11 QUIT
- +12 ; *********************************************************************
- +13 ;
- BILLDATA ;
- +1 ; Gather data from A/R Bill file.
- +2 FOR I=0:1:1
- SET BARBL(I)=$GET(^BARBL(DUZ(2),BARBILL,I))
- +3 ; Current bill amount
- SET BARBAMT=$PIECE(BARBL(0),U,15)
- +4 ; A/R Account (external)
- SET BARAC=$$GET1^DIQ(90050.01,BARBILL,3)
- +5 IF BARAC=""
- SET BARAC="NO A/R ACCOUNT"
- +6 ; DOS Begin
- SET BARDOS=$PIECE(BARBL(1),U,2)
- +7 IF BARDOS=""
- SET BARDOS=99
- +8 ; Visit location
- SET BARVIS=$PIECE(BARBL(1),U,8)
- +9 IF +BARVIS
- SET BARVISOU=$$GET1^DIQ(4,BARVIS,.01)
- +10 IF '$TEST
- SET BARVISOU="NO VISIT LOCATION"
- +11 QUIT
- +12 ; *********************************************************************
- TRDATA ;
- +1 ; Gather data for A/R Bill from A/R Transaction File via "AC" x-ref
- +2 ; Find PSR transactions and do math to find balance
- +3 SET (BARTR,BARTAMT)=0
- +4 FOR
- SET BARTR=$ORDER(^BARTR(DUZ(2),"AC",BARBILL,BARTR))
- IF '+BARTR
- QUIT
- Begin DoDot:1
- +5 ; No transaction data
- IF '$DATA(^BARTR(DUZ(2),BARTR,0))
- QUIT
- +6 FOR I=0:1:1
- SET BARTR(I)=$GET(^BARTR(DUZ(2),BARTR,I))
- +7 ; Trans type (pointer)
- SET BARTRTYP=$PIECE(BARTR(1),U)
- +8 ; Adjust cat (pointer)
- SET BARADCAT=$PIECE(BARTR(1),U,2)
- +9 SET BARCDT=$PIECE(BARTR(0),U,2)
- +10 SET BARDBT=$PIECE(BARTR(0),U,3)
- +11 IF ",3,4,13,14,15,16,19,20,"'[(","_BARADCAT_",")&(",40,49,39,108,503,504,"'[(","_BARTRTYP_","))
- QUIT
- +12 SET BARTAMT=BARTAMT+BARDBT-BARCDT
- End DoDot:1
- +13 QUIT
- +14 ; *********************************************************************
- +15 ;
- TRANS ;
- +1 ; Create Auto Sync Transaction
- +2 ;
- +3 SET BARTRIEN=$$NEW^BARTR
- +4 IF BARTRIEN<1
- QUIT
- +5 ;
- +6 ; Debit
- IF BARDIF>0
- SET DR="3////^S X=$FN(BARDIF,""-"")"
- +7 ; Credit
- IF '$TEST
- SET DR="2////^S X=$FN(BARDIF,""-"")"
- +8 ; A/R bill
- SET DR=DR_";4////^S X=BARBILL"
- +9 ; Patient
- SET DR=DR_";5////^S X=$P(BARBL(1),U)"
- +10 ; A/R acct
- SET DR=DR_";6////^S X=$P(BARBL(0),U,3)"
- +11 ; Parent location
- SET DR=DR_";8////^S X=$P(BARBL(0),U,8)"
- +12 ; Parent ASUFAC
- SET DR=DR_";9////^S X=DUZ(2)"
- +13 ; Service/section
- SET DR=DR_";10////8"
- +14 ; visit location
- SET DR=DR_";11////^S X=BARVIS"
- +15 ; Date
- SET DR=DR_";12////^S X=DT"
- +16 ; Entry By
- SET DR=DR_";13////^S X=DUZ"
- +17 ; Transaction type
- SET DR=DR_";101////504"
- +18 ;
- +19 SET DA=BARTRIEN
- +20 SET DIE=90050.03
- +21 SET DIDEL=90050
- +22 DO ^DIE
- +23 KILL DIDEL,DIE,DA,DR
- +24 QUIT
- +25 ; *********************************************************************
- SETSYNC ;
- +1 ; Set data into ^BARSYNC
- +2 SET ^BARSYNC(BARSTART,DUZ(2),BARVISOU,BARAC,BARDOS,BARBILL)=BARBAMT_U_BARTAMT
- +3 QUIT