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

BARDYSV3.m

Go to the documentation of this file.
BARDYSV3 ; IHS/SD/MAS,TPF - OMB - DAYS TO COLLECTION ; 02/09/2009
 ;;1.8;IHS ACCOUNTS RECEIVABLE;**12,13,14,16,23**;OCT 26, 2005
 ;
 ; IHS/SD/TMM  07/02/2009  M1  Routine too large.  Create 2nd routine ^BARDYSV2
 ; IHS/SD/TMM  09/17/2009  M2  Copy BARDYSVZ to BARDYSV3 for OMB Phase II modifications
 ; IHS/SD/TMM  01/07/2010  M3  Record XBFLG value returned from ^XBGSAVE
 ; IHS/SD/TMM  01/26/2010  M4  Use 3PB DUZ2 for ^DIQ calls TO 3PB files
 ; IHS/SD/TMM  01/27/2010  M5  Update BATCH routine with current logic (to match INSTALL^BARDYSV4 and INTERACT)
 ; IHS/SD/TMM  01/29/2010  M6  Tag TRANS moved from ^BARDYSV3 to ^BARDYSV5 due to
 ;                             routine size of ^BARDYSV3 and SAC checker requirement
 ; MAR 2012 HEAT# 80021 P.OTTIS (=""1M" changed to ["1M") 
 ; MAR 2012 HEAT# 55217 P.OTTIS Parker - <UNDEFINED>BATCH+36^BARDYSV3
 ; FEB 2013 P.OTT CHANGED PTR TO INSURER TYPE
 Q
 ;
 ;IT IS EXPECTED THAT IF NO DATES ARE PASSED VIA TASKMAN THAT THE TASK WILL BE SCHEDULED
 ;FOR THE FIRST DAY OF THE MONTH AND THE RANGE WILL BE FROM THE 1ST TO THA LAST DAY OF THE
 ;MONTH BEFORE
 ;
 ;ASK DATE RANGE FIND VISITS FOR THAT RANGE IN THE VISIT FILE
INTERACT ;EP - INTERACTIVE EP
 I '$$IHS(DUZ(2)) W !,"THIS REPORT IS NOT INTENDED FOR NON-IHS FACILITIES!!" W ! K DIR S DIR(0)="E" D ^DIR Q
 S ZTQUEUED=$G(ZTQUEUED)
 D INIT
 ;
ASKBEG ;EP - ASK BEGIN DATE
 N BEGDATE,ENDDATE
 K DIR
 S DIR(0)="DO^::EX"
 S DIR("A")="Enter Beginning Visit Date"
 D ^DIR
 Q:$D(DIRUT)!$D(DTOUT)!($D(DUOUT))!(Y="")
 S BEGDATE=Y
 ;
ASKEND ;EP - ASK END DATE
 K DIR
 S DIR(0)="DO^::EX"
 S DIR("A")="Enter Ending Visit Date"
 D ^DIR
 G:$D(DIRUT)!$D(DTOUT)!($D(DUOUT))!(Y="") ASKBEG
 S ENDDATE=Y
 I BEGDATE>ENDDATE W !,"BEGIN DATE CAN NOT BE GREATER THAN ENDING DATE!" K DIR S DIR(0)="E" D ^DIR G ASKEND
 D NOW^%DTC
 S ^BARTMP("BARDYSV3",0,"INTERACT STARTED",DUZ(2),%)=BEGDATE_U_ENDDATE
 W !!
 D VISITS^BARDYSV5(BEGDATE,ENDDATE)
 D BILLS(BEGDATE,ENDDATE)                             ;M2
 ;D TRANS(BEGDATE,ENDDATE)                            ;M2   ;M6*DEL*TMM
 D TRANS^BARDYSV5(BEGDATE,ENDDATE)                    ;M2   ;M6*ADD*TMM
 I '$D(^BAROMB($J)) D  G ASKBEG
 . S BARTMP="NO DATA FOUND FOR OMB REPORT!"
 . W !,BARTMP
 . K DIR
 . S DIR(0)="E"
 . D ^DIR
 . S ^BARTMP("BARDYSV3",0,"INTERACT COMPLETED",DUZ(2),%)=BARTMP
 S RC=$$ASKFNAME^BARDYSV4(.BARFILE,BEGDATE,ENDDATE)
 W !,"DESTINATION FILE: ",BARFILE
 D SENDFILE^BARDYSV4("BAROMB(",BARFILE)               ;M1 BAR*1.8*13 TMM 
 D NOW^%DTC
 S ^BARTMP("BARDYSV3",0,"INTERACT COMPLETED",DUZ(2),%)=""                                                      ;M2
 ; Global copy to flat file successful when XBFLG=0
 ;   XBFLG=0 (zero)    Save was successful. No errors detected
 ;   XBFLG=-1          Save was unsuccessful, If errors detected XBFLG is 
 ;                     set to "-1", error info stored in XBFLG(1) and 
 ;                     XBGSAVE returns to the calling program WITHOUT SAVING THE 
 ;                     FILE.
 ; HEAT# 0055217 P.OTT
 ;
 I $G(XBFLG)'=0 S ^BARTMP("BARDYSV3",0,"INTERACT COMPLETED",DUZ(2),%,1)="Global copy of ^BAROMB Failed"_"^"_$G(XBFLG)_"^"_$G(XBFLG(1))   ;M2  ;M3*ADD*TMM
 I $G(XBFLG)=-1 S ^BARTMP("BARDYSV3",0,"INTERACT COMPLETED",DUZ(2),%,2)=XBFLG_"^"_$G(XBFLG(1))                                       ;M2  ;M3*ADD*TMM
 I $G(XBFLG)=0 S ^BARTMP("BARDYSV3",0,"INTERACT COMPLETE",DUZ(2),%,3)="Global copy ^BAROMB successful"                               ;M2  ;M3*ADD*TMM
 Q
 ;
 ;IT IS EXPECTED THAT IF NO DATES ARE PASSED VIA TASKMAN THAT THE TASK WILL BE SCHEDULED
 ;FOR THE FIRST DAY OF THE MONTH AND THE RANGE WILL BE FROM THE 1ST TO THA LAST DAY OF THE
 ;MONTH BEFORE
BATCH(BARBEG,BAREND) ;EP - ENTER FOR TASKED JOB
 D INIT
 N RANGE,BARBEG,BAREND
 S ^BARTMP("BARDYSV3",0,"JOB")=$J
 I $P(D,U,6)["1M" S RANGE=$$LSTMNTH(DT) S BARBEG=$P(RANGE,U),BAREND=$P(RANGE,U,2) ;P.OTT
 E  I $P(D,U,6)[("D") S %DT="" S X="T-"_+$P(D,U,6) D ^%DT S BARBEG=Y,BAREND=DT
 D NOW^%DTC
 S ^BARTMP("BARDYSV3",0,"BATCH STARTED",%)=BARBEG_U_BAREND
 D VISITS^BARDYSV5(BARBEG,BAREND)
 D BILLS(BARBEG,BAREND)                            ;M2
 ;D TRANS(BARBEG,BAREND)                           ;M2   ;M6*DEL*TMM
 D TRANS^BARDYSV5(BARBEG,BAREND)                   ;M2   ;M6*ADD*TMM
 S ^BARTMP("BARDYSV3",0,"BATCH COMPLETED",DUZ(2),%)="OMB PHASE II - Data Extracted, Ready to send"
 S RC=$$ASKFNAME^BARDYSV4(.BARFILE,BARBEG,BAREND)
 D SENDFILE^BARDYSV4("BAROMB(",BARFILE)               ;M1 BAR*1.8*13 TMM 
 D NOW^%DTC
 ;
 ; HEAT# 0055217 P.OTT
 ;
 I $G(XBFLG)'=0 S ^BARTMP("BARDYSV3",0,"BATCH COMPLETED",DUZ(2),%,1)="Global copy of ^BAROMB Failed"_"^"_$G(XBFLG)_"^"_$G(XBFLG(1))   ;M2  ;M3*ADD*TMM
 I $G(XBFLG)=-1 S ^BARTMP("BARDYSV3",0,"BATCH COMPLETED",DUZ(2),%,2)=$G(XBFLG)_"^"_$G(XBFLG(1))                                   ;M2  ;M3*ADD*TMM
 I $G(XBFLG)=0 S ^BARTMP("BARDYSV3",0,"BATCH COMPLETED",DUZ(2),%,3)="Global copy ^BAROMB successful"                              ;M2  ;M3*ADD*TMM
 ;*** M5*END ADD*TMM ***
 Q
 ;
 ;COMPUTE LAST MONTH'S DAYS IN A MONTH, PASS DT. USE THIS TO GET DATE RANGE
LSTMNTH(TODAY) ;EP - COMPY
 N DAYS,LSTMNTH,FMYR,STARTDAY,ENDDAY
 S FMYR=$E(TODAY,1,3)
 S THISMNTH=$E(TODAY,4,5)
 S LSTMNTH=$E(TODAY,4,5)-1
 I LSTMNTH=0 S LSTMNTH=12
 S X=LSTMNTH
 S X1=X,X=$S("^1^3^5^7^8^10^12^"[(U_X_U):31,X'=2:30,$E(X1,1,3)#4:28,1:29)
 S STARTDAY="01"
 S ENDDAY=X
 S:THISMNTH="01" FMYR=FMYR-1,LSTMNTH=12
 S:$L(LSTMNTH)=1 LSTMNTH="0"_LSTMNTH
 S BEGIN=FMYR_LSTMNTH_STARTDAY
 S END=FMYR_LSTMNTH_ENDDAY
 Q BEGIN_U_END
 ;
IHS(DUZ2) ;EP - RETURN TRUE IF IHS AFFILIATION
 N REC
 S REC=$O(^AUTTLOC(DUZ2,11,""),-1)
 S AFFIL=$$GET1^DIQ(9999999.0611,REC_","_DUZ2_",",.03,"I")
 Q AFFIL=1  ;1 MEANS IHS
 ;
BILLS(BARBEG,BAREND) ;EP - Find 3P Bills for this period
 ;Create sort file for all 3PB's and A/R Bills, then create bill record
 N CNT                                           ;M2
 S BEGIN=BARBEG-.01
 S END=BAREND_".999999"
 ;
 ;Find 3P Bills for this period for all 3PB DUZ(2)
 S TPBDUZ2=0 F  S TPBDUZ2=$O(^ABMDBILL(TPBDUZ2)) Q:'TPBDUZ2  D
 .S TPAPRVDT=BEGIN F CNT=1:1 S TPAPRVDT=$O(^ABMDBILL(TPBDUZ2,"AP",TPAPRVDT)) Q:('TPAPRVDT)!(TPAPRVDT>END)  D     ;3P BILL APPROVE DT/TM
 ..S TPBIEN="" F  S TPBIEN=$O(^ABMDBILL(TPBDUZ2,"AP",TPAPRVDT,TPBIEN)) Q:'TPBIEN  D    ;3P BILL IEN
 ...S ^BARTMP("BARDYSV3",10,"BILLS",TPBIEN,0)=TPAPRVDT_U_U_TPBDUZ2          ;3PB IEN noted
 ;
 ;Now find A/R Bills for this period
 N CNT                                           ;M2
 S TPAPRVDT=BEGIN F CNT=1:1 S TPAPRVDT=$O(^BARBL(DUZ(2),"AG",TPAPRVDT)) Q:('TPAPRVDT)!(TPAPRVDT>END)  D
 .W:'$D(ZTQUEUED)&'(CNT#1000) "."
 .S BARBLIEN=$O(^BARBL(DUZ(2),"AG",TPAPRVDT,"")) Q:'BARBLIEN  D
 ..S TPBIEN=$P($G(^BARBL(DUZ(2),BARBLIEN,0)),U,17)
 ..S:TPBIEN="" TPBIEN=0
 ..;Update ^BARTMP if doesn't exist from the 3P Bill
 ..S ^BARTMP("BARDYSV3",10,"BILLS",TPBIEN,BARBLIEN)=TPAPRVDT
 ..I $D(^BARTMP("BARDYSV3",10,"BILLS",TPBIEN,0)) S $P(^BARTMP("BARDYSV3",10,"BILLS",TPBIEN,0),U,2)="DUP"
 ;
 ;$O thru ^BARTMP and create bill records
 K TMP
 S BILLIEN="" F  S BILLIEN=$O(^BARTMP("BARDYSV3",10,"BILLS",BILLIEN)) Q:BILLIEN=""  D
 .S BARBLIEN="" F  S BARBLIEN=$O(^BARTMP("BARDYSV3",10,"BILLS",BILLIEN,BARBLIEN)) Q:BARBLIEN=""  D
 ..K TMP
 ..I BARBLIEN=0 D
 ...S TMP=$G(^BARTMP("BARDYSV3",10,"BILLS",BILLIEN,BARBLIEN))
 ...S TMP=$P(TMP,U,2)
 ..I $G(TMP)="DUP" Q    ;skip this one, there will be another entry with same 3PBIEN and a real BARBLIEN 
 ..;Get the 3PB IEN DUZ2
 ..S TPBDUZ2=$P($G(^BARBL(DUZ(2),BARBLIEN,0)),"^",22)           ;TPB DUZ(2)
 ..;
 ..;Get multiple visits for 3P Bill   ;M2 20091015
 ..S MULTVIS=""        ;M2 20091015
 ..I TPBDUZ2'="" S VISIT=0 F TMP=1:1 S VISIT=$O(^ABMDBILL(TPBDUZ2,BILLIEN,11,VISIT)) Q:'VISIT  D     ;PCC VISIT IEN  ;M2 20091015
 ...S $P(MULTVIS,"|",TMP)=VISIT            ;send all visits for this 3PB
 ..;M2 20091021 S MULTVIS=$S(MULTVIS["|":MULTVIS,1:"")
 ..;
 ..I TPBDUZ2'="" S VISIT=0 F  S VISIT=$O(^ABMDBILL(TPBDUZ2,BILLIEN,11,VISIT)) Q:'VISIT  D     ;PCC VISIT IEN  ;M2 20091015-moved down here from above
 ...S BARVLOC=$$LOCENC^APCLV(VISIT,"C")  ;API LOC. OF ENCOUNTER ASUFAC  ;M2
 ...S:BARVLOC="" BARVLOC="UNDEF"                                        ;M2
 ...;*** loc testing
 ...;I BARVLOC="UNDEF" D
 ...;look at all scenarios initially
 ...S IENS=BILLIEN
 ...S SAVEDUZ=DUZ(2)                                                   ;M4*ADD*TMM
 ...S DUZ(2)=TPBDUZ2                                                   ;M4*ADD*TMM
 ...S TPBVLOC=$$GET1^DIQ(9002274.4,IENS,.03,"E")      ;VISIT LOCATION  ;M2 20091015
 ...S DUZ(2)=SAVEDUZ                                                   ;M4*ADD*TMM
 ...I TPBVLOC'=BARVLOC D
 ....;S TMPREC=TPBVLOC_U_BARVLOC_U_BILLIEN_U_VISIT                      ;M4*DEL*TMM
 ....;S TMP=$G(^BARTMP("BARDYSV3",1,"VISIT LOC NO MATCH"))+1            ;M4*DEL*TMM
 ....;S ^BARTMP("BARDYSV3",1,"VISIT LOC NO MATCH",TMP,0)=TMPREC    ;M2 20091015  ;M4*DEL*TMM
 ....S TMPREC=TPBVLOC_U_BARVLOC_U_BILLIEN_U_VISIT                      ;M4*ADD*TMM
 ....S TMP=$G(^BARTMP("BARDYSV3",1,"VISIT LOC NO MATCH"))+1            ;M4*ADD*TMM
 ....S ^BARTMP("BARDYSV3",1,"VISIT LOC NO MATCH",TMP,0)=TMPREC   ;M2 20091015   ;M4*ADD*TMM
 ...;*** End loc testing
 ...S IENS=VISIT_","
 ...S BARVDA=VISIT                                                      ;M2
 ...I BARVDA="" S BARVDA=0                                              ;M2
 ...S VISCRDT=$P($$GET1^DIQ(9000010,IENS,.02,"I"),".")  ;DATE VISIT CREATED        ;M2 20091008
 ...S BARMY=($E(VISCRDT,1,3)+1700)_"-"_$E(VISCRDT,4,5)
 ...;S TMP=$G(^AUPNVSIT(VISITIEN,0))                        ;M2 20091015 ;M4*DEL*TMM
 ...S TMP=$G(^AUPNVSIT(VISIT,0))                            ;M2 20091015 ;M4*ADD*TMM
 ...S BARMRG=$P(TMP,"^",37)                                 ;M2 20091015
 ...S BARVDEL=$$GET1^DIQ(9000010,IENS,.11,"I")      ;DELETE FLAG = 1 IF DELETED   ;M2 20090930
 ...S BARDEP=$$GET1^DIQ(9000010,IENS,.09)           ;DEPENDENT ENTRY COUNT - IF 0 THE VISIT SHOULD HAVE BEEN DELETED  ;M2 20090930
 ...D BDATA      ;get Bill variables    ;M2
 ...D BREC       ;Write Bill record     ;M2
 Q
 ;
BDATA ;EP - Set 3P Bill data
 S IENS=BILLIEN
 I TPBDUZ2'="" S BILL3P=$P($G(^ABMDBILL(TPBDUZ2,BILLIEN,0)),U)_" "  ;3P BILL NUMBER
 I BILL3P'="" S BILLAR=$O(^BARBL(DUZ(2),"B",BILL3P))                ;A/R BILL NUMBER
 S BLLARIEN=$G(BARBLIEN)
 N D0
 S D0=$$GET1^DIQ(90050.01,BLLARIEN_",",3,"I")                 ;'A/R ACCOUNT' PTR  ;M4*DEL*TMM
 ;S INSTYP=$$GET1^DIQ(9999999.18,INSPTR,.211,"I")  ;RETURNS NUM PTR (I.E. 21) P.OTT GET INS TYP
 S INSTYP=$$VALI^BARVPM(8) ;$P($G(^AUTTINTY(INSTYP,0)),U,2)  ;NUMBER-->"INDIAN PATIENT^I" P.OTT
 I INSTYP="I" S ^BARTMP("BARDYSV3",1,"BILLS SCREENED FOR INSTYP=I")=$G(^BARTMP("BARDYSV3",1,"BILLS SCREENED FOR INSTYP=I"))+1
 ;Use 3PB DUZ2 for 3PB look up
 S SAVEDUZ=DUZ(2)                                  ;M4*ADD*TMM
 S DUZ(2)=TPBDUZ2                                  ;M4*ADD*TMM
 S BILLSTA=$$GET1^DIQ(9002274.4,IENS,.04,"E")                     ;BILL STATUS
 S BILLNUM=$P($$GET1^DIQ(9002274.4,IENS,.01),"-")                 ;3P BILL NUMBER
 S BILLAPP=$$GET1^DIQ(9002274.4,IENS,.15,"I")                     ;3P DATE/TIME APPROVED
 S BILLAMT=$$GET1^DIQ(9002274.4,IENS,.21)                         ;3P BILLED AMOUNT
 S BILLEXP=$$GET1^DIQ(9002274.4,IENS,.17,"I")                     ;3P EXPORT NUMBER (DATE EXPORTED TO A/R)
 S:BILLEXP'="" BILLEXP=$P($G(^ABMDTXST(DUZ(2),BILLEXP,0)),U)      ;INTERNAL FM DATE
 S ACTINS=$$GET1^DIQ(9002274.4,IENS,.08,"E")                      ;ACTIVE INSURER
 S DUZ(2)=SAVEDUZ                                  ;M4*ADD*TMM
 Q
 ;
BREC ;EP - BUILD BILL REC
 I '$D(^BAROMB($J,BARVLOC,BILLIEN,"BILLREC")) D
 .S RECHDR=BARVLOC_U_BILLIEN_U_$S($G(BARMY)'="":BARMY,1:0)
 .S BILLREC=RECHDR_U_BILLIEN
 .S BILLREC=BILLREC_U_BILLNUM
 .S BILLREC=BILLREC_U_BILLAPP
 .S BILLREC=BILLREC_U_BILLAMT
 .S BILLREC=BILLREC_U_BILLEXP
 .S BILLREC=BILLREC_U_ACTINS
 .S BILLREC=BILLREC_U_BILLSTA          ;M2 20090930
 .S BILLREC=BILLREC_U_BARMRG           ;M2 20090930
 .S BILLREC=BILLREC_U_BARVDEL          ;M2 20090930
 .S BILLREC=BILLREC_U_BARDEP           ;M2 20090930
 .S BILLREC=BILLREC_U_MULTVIS          ;M2 20091015
 .S ^BAROMB($J,BARVLOC,BILLIEN,"BILLREC",BARVDA)="B"_U_BILLREC
 .S TMP=$G(^BARTMP("BARDYSV3",$J,"BILLREC"))+1
 .S ^BARTMP("BARDYSV3",$J,"BILLREC")=TMP
 .S ^BARTMP("BARDYSV3",$J,"BILLREC",TMP)="B"_U_BILLREC
 .S ^BARTMP("BARDYSV3",0,20,BARVLOC,"B")=$G(^BARTMP("BARDYSV3",0,20,BARVLOC,"B"))+1
 Q
 ;
INIT ;EP - Initialize
 K ^BAROMB($J)
 ;Kill prior run data
 S TMP=$G(^BARTMP("BARDYSV3",0,"JOB"))
 I TMP'="" K ^BAROMB(TMP)                 ;Kill prior run
 K ^BARTMP("BARDYSV3")
 ;Set for this run
 S ^BARTMP("BARDYSV3",0,"JOB")=$J
 Q  ;EOR