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

BARDYSV5.m

Go to the documentation of this file.
BARDYSV5 ; 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 IBARTMP("BARDYSVZ",I modifications
 ; IHS/SD/TMM  01/29/2010  M3  Tag TRANS moved from ^BARDYSV3 to ^BARDYSV5 due to 
 ;                             routine size of ^BARDYSV3 and SAC checker requirement
 ; IHS/SD/TMM  02/11/2010  M4  Use correct VISIT variable for BARMRG
 ; FEB 2013 P.OTT CHANGED PTR TO INSURER TYPE
 ; SEP 2013 P.OTT FIXED <UNDEF> IN INS TYPE (INSTYPX)
 Q
 ;
VISITS(BARBEG,BAREND) ;EP - GET VISIT DATA
 I $E(BAREND,6,7)="00" S $E(BAREND,6,7)="31"
 S BAREND=BAREND_".24"
 S BAROMY=$E(BARBEG,2,5)
 S BARYR=$E(DT,1,3)
 D NOW^%DTC
 N CNT
 S BEGIN=BARBEG-.01
 S END=$P(BAREND,".",1)_".999999"
 S VISIT=0 F CNT=1:1 S VISIT=$O(^AUPNVSIT(VISIT)) Q:'VISIT  D             ;M2
 .S TMPBILL=""
 .S TPBIEN="" F TMP=1:1 S TPBIEN=$O(^ABMDBILL(DUZ(2),"AV",VISIT,TPBIEN)) Q:'TPBIEN  D
 ..S $P(TMPBILL,"|",TMP)=TPBIEN
 .;M2 20091021 S BILLIEN=TMPBILL               ;Not sure how to handle multiple bills for 3PBIEN field  M2 20091025
 .S BILLIEN=$P($G(TMPBILL),"|",1)              ;Not sure how to handle multiple bills for 3PBIEN field  M2 20091025
 .;S MULTBILL=$S(TMPBILL["|":TMPBILL,1:"")     ;This for extra field at end of Visit Record
 .S MULTBILL=TMPBILL                           ;This for extra field at end of Visit Record
 .W:'$D(ZTQUEUED)&'(CNT#1000) "V"
 .S VISCRDT=$P($$GET1^DIQ(9000010,VISIT,.02,"I"),".")  ;DATE VISIT CREATED          ;M2 20091008
 .Q:VISCRDT<BARBEG                  ;M2 20091008
 .Q:VISCRDT>END                     ;filter visits created after selection period
 .S BARMY=($E(VISCRDT,1,3)+1700)_"-"_$E(VISCRDT,4,5)
 .D VDATA                          ;M2
 .I 'BARVDA S BARVDA=0
 .D VREC                            ;Build Visit Record in ^BAROMB($J,
 Q
 ;
GETV(VISIT) ;EP - Get Visit Variables
 N BARVDA,VISITIEN
VDATA ;EP - Visit Data
 S VISITIEN=VISIT
 S IENS=VISITIEN_","
 S BARSCAT=$$SC^APCLV(VISITIEN,"I")                      ;API SERVICE CATEGORY
 S BARSCAT=$$SC^APCLV(VISITIEN,"E")                      ;API SERVICE CATEGORY
 S TMP=$G(^AUPNVSIT(VISITIEN,0))
 S BARMRG=$P(TMP,"^",37)                                 ;M2 20091008
 S VSITCRET=$P($$GET1^DIQ(9000010,IENS,.02,"I"),".")  ;DATE VISIT CREATED
 S BARVADMT=$P($$GET1^DIQ(9000010,IENS,.01,"I"),".")  ;VISIT/ADMIT DATE&TIME
 ;DETERMINE REVIEW DATE
 S VPCCREV=$P($$GET1^DIQ(9000010,IENS,.13,"I"),".")   ;DATE LAST MODIFIED
 S PCCREV=$$GEREV(VISITIEN,VPCCREV)  ;CHECK ALGORYTHM                            ;
 ;END REVIEW DATE
 S BARVTYP=$$GET1^DIQ(9000010,IENS,.03,"E")          ;TYPE (OF VISIT)
 S BARVLOC=$$LOCENC^APCLV(VISITIEN,"C")              ;API LOC. OF ENCOUNTER ASUFAC
 S BARLOCN=$$GET1^DIQ(9000010,IENS,.06,"E")       ;'LOC. OF ENCOUNTER' NAME
 S:BARVLOC="" BARVLOC="UNDEF"
 S BARVDEL=$$GET1^DIQ(9000010,IENS,.11,"I")      ;DELETE FLAG = 1 IF DELETED
 S BARDEP=$$GET1^DIQ(9000010,IENS,.09)           ;DEPENDENT ENTRY COUNT - IF 0 THE VISIT SHOULD HAVE BEEN DELETED
 S BARTPBF=$$GET1^DIQ(9000010,IENS,.04,"E")      ;THIRD PARTY BILLED (Visit has been billed)
 S BARCS=$$CLINIC^APCLV(VISITIEN,"C")            ;CLINIC STOP (FOR
 S BARVDA=VISITIEN
 I BARVDA="" S BARVDA=0                          ;M2
 Q
 ;
GEREV(BARVDA,VPCCREV) ;EP - GET LAST DATE 'REVIEWED'
 ;PER DAVID BATTESE GET REVIEW DATE FROM V CHART AUDIT IF TURNED ON
 N TMP,QUEAUDIT,EARLIEST
 S QUEAUDIT=$$GET1^DIQ(9001000,DUZ(2)_",",.12,"I")  ;FIELD 'EHR/CHART AUDIT START DATE' FROM 'PCC MASTER CONTROL'
 Q:BARVADMT<QUEAUDIT VPCCREV  ;IF ADMIT DATE IS BEFORE AUDIT WAS TURNED ON GET REVIEW DATE FROM 'DATE LAST MODIFIED'
 D  ;OTHERWISE SEE IF YOU CAN GET IT IN THE 'V CHART AUDIT' FILE
 .S (PCCREV,TMP)=""  ;^AUPNVCA = V CHART AUDIT
 .F  S TMP=$O(^AUPNVCA("AD",BARVDA,TMP)) Q:'TMP  D
 ..I $$GET1^DIQ(9000010.45,TMP_",",.04)="R" D      ;CHART AUDIT STATUS, R=REVIEWED/COMPLETE I=INCOMPLETE
 ...S PCCREV=$$GET1^DIQ(9000010.45,BARVDA_",",.01)  ;DATE OF AUDIT
 I PCCREV S PCCREV=PCCREV_"A"  ;IF A "R" DATE OF AUDIT WAS FOUND THEN USE IT
 E  S PCCREV=VPCCREV_"V"       ;OTHERWISE STAY WITH THE 'DATE LAST MODIFIED'
 Q PCCREV
 ;
VREC ;EP - SET THE VISIT AND BILL RECORDS SORTED BY VISIT
 N VISITREC,BILLREC,RECHDR,TRANREC
 S (BILLREC,VISITREC)=""
 S RECHDR=BARVLOC_U_BILLIEN_U_$S($G(BARMY)'="":BARMY,1:0)
 ;
 I '$D(^BAROMB($J,BARVLOC,BARVDA,"A VISITREC")) D
 .S VISITREC=RECHDR_U_BARVDA              ;VISIT IEN                 ;M2 20090930
 .S VISITREC=VISITREC_U_BARSCAT           ;'SERVICE CATEGORY'        ;M2 20090930
 .S VISITREC=VISITREC_U_BARVTYP           ;'VISIT TYPE'              
 .S VISITREC=VISITREC_U_$G(VSITCRET)      ;'DATE VISIT CREATED'
 .S VISITREC=VISITREC_U_$G(BARVADMT)      ;'VISIT/ADMIT DATE&TIME'
 .S VISITREC=VISITREC_U_$G(PCCREV)        ;"VISIT REVIEWED DATE" SEE $$GETREV
 .S VISITREC=VISITREC_U_BARLOCN           ;'LOC. OF ENCOUNTER' - NAME
 .S VISITREC=VISITREC_U_BARMRG            ;'MERGED TO'
 .S VISITREC=VISITREC_U_BARVDEL           ;'DELETE FLAG'             ;M2 20090930
 .S VISITREC=VISITREC_U_BARDEP            ;'DEPENDENT ENTRY COUNT'   ;M2 20090930
 .S VISITREC=VISITREC_U_BARCS             ;CLINIC STOP               ;M2 20091008
 .;Verify IHS AFFILIATION
 .N REC                                                              ;M2 20091008
 .S REC=$O(^AUTTLOC(DUZ(2),11,""),-1)                                ;M2 20091008
 .S AFFIL=$$GET1^DIQ(9999999.0611,REC_","_DUZ(2)_",",.03,"I")        ;M2 20091008
 .S VISITREC=VISITREC_U_AFFIL             ;ADD AFFIL AND IHS CODES TO VISIT REC  ;M2 20091008
 .S VISITREC=VISITREC_U_MULTBILL          ;Multiple 3PBills per Visit ;M2 20091015
 .;
 .S ^BAROMB($J,BARVLOC,BARVDA,"A VISITREC")="V"_U_VISITREC
 .S TEMP=$G(^BARTMP("BARDYSV3",$J,"A_VISITREC"))+1
 .S ^BARTMP("BARDYSV3",$J,"A_VISITREC")=TMP
 .S ^BARTMP("BARDYSV3",$J,"A_VISITREC",TMP)="V"_U_VISITREC
 .S ^BARTMP("BARDYSV3",0,20,BARVLOC,"V")=$G(^BARTMP("BARDYSV3",0,20,BARVLOC,"V"))+1
 I BARCS="" D  Q                         ;IF NO CLINIC, NO BILL SO DO NOT INCLUDE. INCLUDE PER MARSHA
 .S BARVDA=0
 .S TMP=$G(^BARTMP("BARDYSV3",1,"VISITS SCREENED FOR CLINIC STOP"))+1     ;M2 20091006
 .S ^BARTMP("BARDYSV3",1,"VISITS SCREENED FOR CLINIC STOP")=TMP           ;M2 20091006
 .S TMPREC=$G(VISITIEN)_"^"_$G(BARVTYP)_"^"_BARLOCN_"^"_$G(BARCS)         ;M2 20091006 20091008
 .S TMPREC=TMPREC_"^"_$G(BARVLOC)_U_$G(VISCRDT)_U_$G(END)_U_$G(BEGIN)     ;M2 20091008
 .S TMPREC=TMPREC_"^"_$G(VISITREC)                                        ;M2 20091008
 .S ^BARTMP("BARDYSV3",1,"VISITS SCREENED FOR CLINIC STOP",TMP,0)=TMPREC    ;M2 20091006
 Q
 ;
TRANS(BARBEG,BAREND) ;EP - Find the A/R Transactions for this period   ;M3*ADD*TMM
 S BEGIN=BARBEG-.01
 S END=BAREND_".999999"
 N CNT
 S BARTRIEN=BEGIN F CNT=1:1 S BARTRIEN=$O(^BARTR(DUZ(2),BARTRIEN)) Q:('BARTRIEN)!(BARTRIEN>END)  D     ;A/R TRANS DT/TM
 . I DUZ=902 W !,CNT,". ",BARTRIEN
 .W:'$D(ZTQUEUED)&'(CNT#1000) "T"
 .S BARTR0=$G(^BARTR(DUZ(2),BARTRIEN,0))
 .S BARTR1=$G(^BARTR(DUZ(2),BARTRIEN,1))
 .S BARVLOC=$P(BARTR0,U,11)         ;Visit Location
 .S BARBL=$P(BARTR0,U,4)            ;A/R Bill IEN
 .I BARBL="" D  Q
 ..S ^BARTMP("BARDYSVZ","TRANS MISSING ARBILL")=DUZ(2)_U_$G(BARTRIEN)_"---"_$G(BARTR0)
 .S BARBL0=$G(^BARBL(DUZ(2),BARBL,0))
 .S BILLIEN=$P(BARBL0,U,17)
 .S TPBDUZ2=$P(BARBL0,U,22)
 .;get the Visit data for record header
 .I TPBDUZ2="" S TPBDUZ2=0   ;just in case... send data anyway for testing
 .I BILLIEN="" S BILLIEN=0   ;just in case... send data anyway for testing
 .S VISIT=0,VISIT=$O(^ABMDBILL(TPBDUZ2,BILLIEN,11,VISIT))     ;PCC VISIT IEN
 .Q:'VISIT
 .S BARVLOC=$$LOCENC^APCLV(VISIT,"C")        ;API LOC. OF ENCOUNTER ASUFAC ;M2
 .S:BARVLOC="" BARVLOC="UNDEF"                                             ;M2
 .S BARVDA=VISIT                             ;Get visit data
 .S:BARVDA="" BARVDA=0                                                     ;M2
 .S VISCRDT=$P($$GET1^DIQ(9000010,VISIT,.02,"I"),".")  ;DATE VISIT CREATED        ;M2 20091008
 .Q:VISCRDT<3081001               ;filter Visits created prior to 10/1/08
 .S BARMY=($E(VISCRDT,1,3)+1700)_"-"_$E(VISCRDT,4,5)
 .S IENS=VISIT_","
 .;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
 .S RECHDR=BARVLOC_U_BILLIEN_U_$S($G(BARMY)'="":BARMY,1:0)
 .;
 .;Get A/R transaction data
 .S TRANDATE=BARTRIEN
 .S IENS=BARTRIEN_","
 .I $$GET1^DIQ(90050.03,IENS,7,"I")="Y" Q      ;'MESSAGE' IF YES SCREEN OUT PER MEETING 4/7/2009
 .S INSURER=$$GET1^DIQ(90050.03,IENS,6,"E")    ;'A/R ACCOUNT'
 .S INSPTR=$$GET1^DIQ(90050.03,IENS,6,"I")     ;'A/R ACCOUNT' PTR
 .S TRANTYP=$$GET1^DIQ(90050.03,IENS,101,"E")  ;'TRANSACTION TYPE'
 .S CREDDEB=$$GET1^DIQ(90050.03,IENS,3.5,"I")  ;'CREDIT / DEBIT'
 .S ADJCAT=$$GET1^DIQ(90050.03,IENS,102,"E")   ;'ADJUSTMENT CATEGORY'
 .S ADJTYP=$$GET1^DIQ(90050.03,IENS,103,"E")   ;'ADJUSTMENT TYPE'
 .S ARBILL=$$GET1^DIQ(90050.03,IENS,4,"I")     ;'PTR TO A/R BILL'
 .S CURAMT=$$GET1^DIQ(90050.01,ARBILL_",",15,"I")  ;'CURRENT BILL' AMOUNT IN 'A/R BILL'
 .I CURAMT="" S CURAMT="null"
 .S D0=INSPTR,INSTYP=$$VALI^BARVPM(8) ;AR ACCNR NUMBER-->^P
 .I INSTYP="I" S ^BARTMP("BARDYSV3",1,"TXS SCREENED FOR INSTYP=I")=$G(^BARTMP("BARDYSV3",1,"TXS SCREENED FOR INSTYP=I"))+1
 .S IENS=VISIT_","                                              ;M2 20090930
 .S SAVEDUZ=DUZ(2)                                              ;M4*ADD*TMM
 .S BILLSTA=$$GET1^DIQ(9002274.4,IENS,.04,"E")   ;BILL STATUS   ;M2 20090930
 .S DUZ(2)=SAVEDUZ                                              ;M4*ADD*TMM
 .;Write Transaction record
 .I '$D(^BAROMB($J,BARVLOC,BARVDA,"TRANS REC",TRANDATE)) D
 ..S RECHDR=BARVLOC_U_BILLIEN_U_$S($G(BARMY)'="":BARMY,1:0)          ;Transaction Record Header
 ..S TRANREC="T"_U_RECHDR_U_TRANDATE
 ..S TRANREC=TRANREC_U_INSURER
 ..S TRANREC=TRANREC_U_TRANTYP
 ..S TRANREC=TRANREC_U_$P(TRANDATE,".")
 ..S TRANREC=TRANREC_U_CREDDEB
 ..S TRANREC=TRANREC_U_ADJCAT
 ..S TRANREC=TRANREC_U_ADJTYP
 ..S TRANREC=TRANREC_U_CURAMT
 ..S TRANREC=TRANREC_U_INSTYP                ;M2 20090930
 ..S TRANREC=TRANREC_U_BARMRG                ;M2 20090930
 ..S TRANREC=TRANREC_U_BARVDEL               ;M2 20090930
 ..S TRANREC=TRANREC_U_BARDEP                ;M2 20090930
 ..S ^BAROMB($J,BARVLOC,BILLIEN,"TRANS REC",TRANDATE)=TRANREC
 ..S TMP=$G(^BARTMP("BARDYSV3",$J,"TRANS_REC"))+1
 ..S ^BARTMP("BARDYSV3",$J,"TRANS_REC")=TMP
 ..S ^BARTMP("BARDYSV3",$J,"TRANS_REC",TMP)=TRANREC
 ..S ^BARTMP("BARDYSV3",0,20,BARVLOC,"T")=$G(^BARTMP("BARDYSV3",0,20,BARVLOC,"T"))+1
 Q