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

BARSYNC.m

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