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

AGAGERP3.m

Go to the documentation of this file.
AGAGERP3 ; VNGT/IHS/DLS - Patient Age Specific Report ; April 29, 2010
 ;;7.1;PATIENT REGISTRATION;**8,9,12,14**;AUG 25, 2005;Build 1
 ;
 ;IHS/OIT/NKD AG*7.1*12 INSURER TYPE
 ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 ;
 Q
PRTMEDC ; Print Medicare Records
 N PAGENO,LINECT,ESCAPE,PATNAM,PATIEN,MCRNUM,AGTOTAL,X
 S PAGENO=0,ESCAPE=0
 D MRHDR^AGAGERP2
 S PATNAM=""
 F  S PATNAM=$O(^TMP("AGAGERP",$J,PATNAM)) Q:(PATNAM="")!(ESCAPE)  D
 . S PATIEN=""
 . F  S PATIEN=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN)) Q:PATIEN=""  D
 . . S MCRNUM=""
 . . F  S MCRNUM=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN,MCRNUM)) Q:MCRNUM=""  D
 . . . N CHRTNO,ADDR1,ADDR2,ADDR3,CITY,ST,ZIP,AGE,DOB,LASTUPD,COVERAGE,MCR,STABB
 . . . N MNUMB,MSUFF,RNUMB,RPREF,COVNO
 . . . S CHRTNO=$P($G(^AUPNPAT(PATIEN,41,DUZ(2),0)),U,2)
 . . . S ADDR1=$$GET1^DIQ(2,PATIEN,.111)
 . . . S ADDR2=$$GET1^DIQ(2,PATIEN,.112)
 . . . S ADDR3=$$GET1^DIQ(2,PATIEN,.113)
 . . . S CITY=$$GET1^DIQ(2,PATIEN,.114)
 . . . S STABB=$$GET1^DIQ(2,PATIEN,.115,"I")
 . . . S ST=$$GET1^DIQ(5,STABB,1)
 . . . S ZIP=$$GET1^DIQ(2,PATIEN,.116)
 . . . N Y S Y=$$GET1^DIQ(2,PATIEN,.03,"I") D DD^%DT S DOB=Y
 . . . S AGE=$$GET1^DIQ(9000001,PATIEN,1102.98)
 . . . S LASTUPD=$$GET1^DIQ(9000001,PATIEN,.03)
 . . . S MCR=$$GET1^DIQ(9000003,MCRNUM,.14)
 . . . S MNUMB=$$GET1^DIQ(9000003,MCRNUM,.03)
 . . . S RNUMB=$$GET1^DIQ(9000005,MCRNUM,.04)
 . . . S COVERAGE=""
 . . . S COVNO=1
 . . . I $G(MNUMB)'="" D MCOV^AGAGERP2
 . . . I $G(RNUMB)'="" D RCOV^AGAGERP2
 . . . I $$HASMBI^AGUTL(PATIEN),$$HASELIG^AGEDERR2(PATIEN)["MCR" D MCOV^AGAGERP2  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . I $$HASMBI^AGUTL(PATIEN),$$HASELIG^AGEDERR2(PATIEN)["RRE" D RCOV^AGAGERP2  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . S:$D(COVERAGE) COVERAGE=$P(COVERAGE,"/D",1),COVERAGE=$P(COVERAGE,"D",1)  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . S MSUFF=$$GET1^DIQ(9000003,MCRNUM,.04)
 . . . S RPREF=$$GET1^DIQ(9000005,MCRNUM,.03)
 . . . W !,PATNAM," (",CHRTNO,")("
 . . . I AGE["MOS" W AGE,")"
 . . . I AGE'["MOS" W +AGE,")"
 . . . ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2 - START OLD CODE
 . . . ;I MNUMB'="" W ?47,"M=",MNUMB I MSUFF'="" W "-",MSUFF
 . . . ;I RNUMB'="",MNUMB="" W ?47,"R=",RPREF,RNUMB
 . . . ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2 - END OLD CODE - START NEW CODE
 . . . I $$HASMBI^AGUTL(PATIEN) W ?47,$S($$HASELIG^AGEDERR2(PATIEN)["MCR":"M=",$$HASELIG^AGEDERR2(PATIEN)["RRE":"R=",1:"M="),$$GETMBI^AUPNMBI(PATIEN,$$DT^XLFDT)
 . . . E  I MNUMB'="" W ?47,"M=",MNUMB I MSUFF'="" W "-",MSUFF
 . . . E  I RNUMB'="",MNUMB="" W ?47,"R=",RPREF,RNUMB
 . . . ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2 - END NEW CODE
 . . . I $P(COVERAGE,"/",COVNO)'="" W ?69,"PART ",$P(COVERAGE,"/",COVNO) S COVNO=COVNO+1
 . . . W !,?10,ADDR1
 . . . ;I RNUMB'="",MNUMB'="" W ?47,"R=",RPREF,RNUMB  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . I $$HASMBI^AGUTL(PATIEN),$$HASELIG^AGEDERR2(PATIEN)["MCR",$$HASELIG^AGEDERR2(PATIEN)["RRE" W ?47,"R=",$$GETMBI^AUPNMBI(PATIEN,$$DT^XLFDT)  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . E  I RNUMB'="",MNUMB'="" W ?47,"R=",RPREF,RNUMB  ;IHS/OIT/NKD AG*7.1*14 MBI PHASE 2
 . . . I $P(COVERAGE,"/",COVNO)'="" W ?69,"PART ",$P(COVERAGE,"/",COVNO) S COVNO=COVNO+1
 . . . I $G(ADDR2)'="" W !,?10,ADDR2 I $P(COVERAGE,"/",COVNO)'="" W ?69,"PART ",$P(COVERAGE,"/",COVNO) S COVNO=COVNO+1
 . . . I $G(ADDR3)'="" W !,?10,ADDR3 I $P(COVERAGE,"/",COVNO)'="" W ?69,"PART ",$P(COVERAGE,"/",COVNO) S COVNO=COVNO+1
 . . . W !,?10,CITY," ",ST," ",ZIP I $P(COVERAGE,"/",COVNO)'="" W ?69,"PART ",$P(COVERAGE,"/",COVNO) S COVNO=COVNO+1
 . . . W !,"(MCR) ",MCR
 . . . W !,LASTUPD
 . . . W !,AGLINE("DASH") S LINECT=LINECT+7
 . . . I $E(IOST)="C",$Y>(IOSL-5) K DIR D RTRN^AG S ESCAPE=X=U D:'ESCAPE MRHDR^AGAGERP2
 . . . I $E(IOST)'="C",$Y>(IOSL-17) W !! D MRHDR^AGAGERP2
 . . . S AGTOTAL=$G(AGTOTAL)+1
 W !,"TOTAL RECORDS:",?20,$G(AGTOTAL),!!
 I $E(IOST)="C",PATNAM="" K DIR D RTRN^AG
 I $E(IOST)'="C" D CLOSE^%ZISH(IO)
 Q
 ;
PRTMEDD ; Print Medicaid Records
 N PAGENO,LINECT,ESCAPE,PATNAM,PATIEN,MCDNUM,AGTOTAL,X
 S PAGENO=0,ESCAPE=0
 D MDHDR^AGAGERP2
 S PATNAM=""
 F  S PATNAM=$O(^TMP("AGAGERP",$J,PATNAM)) Q:(PATNAM="")!(ESCAPE)  D
 . S PATIEN=""
 . F  S PATIEN=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN)) Q:(PATIEN="")!(ESCAPE)  D
 . . S MCDNUM=""
 . . F  S MCDNUM=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN,MCDNUM)) Q:(MCDNUM="")!(ESCAPE)  D
 . . . N CHRTNO,ADDR1,ADDR2,ADDR3,CITY,ST,ZIP,DOB,LASTUPD,COVERAGE,MCD,STABB
 . . . N MNUMB,MSTATE,PLAN,CHARCNT
 . . . S CHARCNT=0
 . . . S CHRTNO=$P($G(^AUPNPAT(PATIEN,41,DUZ(2),0)),U,2)
 . . . S ADDR1=$$GET1^DIQ(2,PATIEN,.111)
 . . . S ADDR2=$$GET1^DIQ(2,PATIEN,.112)
 . . . S ADDR3=$$GET1^DIQ(2,PATIEN,.113)
 . . . S CITY=$$GET1^DIQ(2,PATIEN,.114)
 . . . S STABB=$$GET1^DIQ(2,PATIEN,.115,"I")
 . . . S ST=$$GET1^DIQ(5,STABB,1)
 . . . S ZIP=$$GET1^DIQ(2,PATIEN,.116)
 . . . N Y S Y=$$GET1^DIQ(2,PATIEN,.03,"I") D DD^%DT S DOB=Y
 . . . S AGE=$$GET1^DIQ(9000001,PATIEN,1102.98)
 . . . S LASTUPD=$$GET1^DIQ(9000001,PATIEN,.03)
 . . . S MCD=$$GET1^DIQ(9000004,MCDNUM,.14)
 . . . S MNUMB=$$GET1^DIQ(9000004,MCDNUM,.03)
 . . . S COVERAGE=""
 . . . I MNUMB'="" D DCOV^AGAGERP2
 . . . S MSTATE=$$GET1^DIQ(5,$$GET1^DIQ(9000004,MCDNUM,.04,"I"),1)
 . . . S PLAN=$$GET1^DIQ(9000004,MCDNUM,.11)
 . . . W !,PATNAM," (",CHRTNO,")(" S CHARCNT=CHARCNT+$L(PATNAM)+$L(CHRTNO)+4
 . . . I AGE["MOS" W AGE,")" S CHARCNT=CHARCNT+$L(AGE)+1
 . . . I AGE'["MOS" W +AGE,")" S CHARCNT=CHARCNT+$L(+AGE)+1
 . . . I CHARCNT<35,$G(MNUMB)'="" W ?35,MNUMB,"(",$G(MSTATE),")"
 . . . W ?55,$G(PLAN)
 . . . W !,?10,ADDR1
 . . . I CHARCNT>34 W ?35,MNUMB,"(",$G(MSTATE),")"
 . . . W ?55,COVERAGE
 . . . I $G(ADDR2)'="" W !,?10,ADDR2
 . . . I $G(ADDR3)'="" W !,?10,ADDR3
 . . . W !,?10,CITY," ",ST," ",ZIP
 . . . W !,"(MCD) ",MCD
 . . . W !,LASTUPD
 . . . W !,AGLINE("DASH") S LINECT=LINECT+7
 . . . S AGTOTAL=$G(AGTOTAL)+1
 . . . I $E(IOST)="C",$Y>(IOSL-5) K DIR D RTRN^AG S ESCAPE=X=U D:'ESCAPE MDHDR^AGAGERP2
 . . . I $E(IOST)'="C",$Y>(IOSL-17) W !! D MDHDR^AGAGERP2
 W !,"TOTAL RECORDS:",?20,$G(AGTOTAL),!!
 I $E(IOST)="C",PATNAM="" K DIR D RTRN^AG
 I $E(IOST)'="C" D CLOSE^%ZISH(IO)
 Q
 ;
PRTPRVT ; Print Private Insurance Records
 N PAGENO,LINECT,ESCAPE,PATNAM,PATIEN,PRVTNO,PNODE,PNAME,I,AGTOTAL,FOUND,X,MSTATE
 S PAGENO=0,ESCAPE=0
 D PRVTHDR^AGAGERP2
 S PATNAM=""
 F  S PATNAM=$O(^TMP("AGAGERP",$J,PATNAM)) Q:(PATNAM="")!(ESCAPE)  D
 . S PATIEN=0
 . F  S PATIEN=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN)) Q:(+PATIEN=0)!(ESCAPE)  D
 . . S PRVTNO=""
 . . F  S PRVTNO=$O(^TMP("AGAGERP",$J,PATNAM,PATIEN,PRVTNO)) Q:(PRVTNO="")!(ESCAPE)  D
 . . . N CHRTNO,ADDR1,ADDR2,ADDR3,CITY,ST,ZIP,DOB,LASTUPD,COVERAGE,MCD,STABB,PNAME2,WFLG
 . . . N PNUMB,PNUMB2,CHARCNT,PHOLDER,START,END,PNODESV,MNUMB
 . . . S CHARCNT=0
 . . . S FOUND=0
 . . . S WFLG=$E(PRVTNO,1)
 . . . S CHRTNO=$P($G(^AUPNPAT(PATIEN,41,DUZ(2),0)),U,2)
 . . . S ADDR1=$$GET1^DIQ(2,PATIEN,.111)
 . . . S ADDR2=$$GET1^DIQ(2,PATIEN,.112)
 . . . S ADDR3=$$GET1^DIQ(2,PATIEN,.113)
 . . . S CITY=$$GET1^DIQ(2,PATIEN,.114)
 . . . S STABB=$$GET1^DIQ(2,PATIEN,.115,"I")
 . . . S ST=$$GET1^DIQ(5,STABB,1)
 . . . S ZIP=$$GET1^DIQ(2,PATIEN,.116)
 . . . N Y S Y=$$GET1^DIQ(2,PATIEN,.03,"I") D DD^%DT S DOB=Y
 . . . S AGE=$$GET1^DIQ(9000001,PATIEN,1102.98)
 . . . S LASTUPD=$$GET1^DIQ(9000001,PATIEN,.03)
 . . . I (WFLG'="M")!(WFLG'="W") D
 . . . . S PNODE=0
 . . . . F  S PNODE=$O(^AUPNPRVT(PATIEN,11,"B",PRVTNO,PNODE)) Q:(+PNODE=0)!(FOUND)  D
 . . . . . S START=$P($G(^AUPNPRVT(PATIEN,11,PNODE,0)),U,6)
 . . . . . S END=$P($G(^AUPNPRVT(PATIEN,11,PNODE,0)),U,7)
 . . . . . S FOUND=0
 . . . . . I $D(EXCL("Elig Date Range")) D ELGDTCH^AGAGERP1(START,END,.FOUND)
 . . . . . I '$D(EXCL("Elig Date Range")) D ELGDTCH2^AGAGERP1(START,END,.FOUND)
 . . . . . S PNODESV=+PNODE
 . . . . . Q:FOUND
 . . . . I $D(PNODESV) S PNODE=PNODESV
 . . . . S PNAME=$$GET1^DIQ(9999999.18,PRVTNO,.01)
 . . . . S PHOLDER=$P($G(^AUPNPRVT(PATIEN,11,+$G(PNODE),0)),U,8)
 . . . . S PNUMB2=$P($G(^AUPNPRVT(PATIEN,11,+$G(PNODE),0)),U,2)
 . . . . S PNUMB=$$GET1^DIQ(9000003.1,+$G(PHOLDER),.04)
 . . . . I PNUMB="" S PNUMB=$G(PNUMB2)
 . . . . S COVERAGE=$$GET1^DIQ(9000003.1,+$G(PHOLDER),.05)
 . . . . I COVERAGE="" D PCOV^AGAGERP2
 . . . I WFLG="W" D
 . . . . S PNAME=$$GET1^DIQ(9999999.18,$E(PRVTNO,3,99),.01)
 . . . . S COVERAGE="WORKMEN'S COMP"
 . . . I WFLG="M" D
 . . . . S MCDNUM=$E(PRVTNO,3,99)
 . . . . S PNUMB=$$GET1^DIQ(9000004,MCDNUM,.03)
 . . . . S PLAN=$$GET1^DIQ(9000004,MCDNUM,.11)
 . . . . S MSTATE=$$GET1^DIQ(9000004,MCDNUM,.04,"I")
 . . . . S MSTATE=$$GET1^DIQ(5,MSTATE,1)
 . . . . I MSTATE'="" S PNAME=MSTATE_" "_PLAN
 . . . . I MSTATE="" S PNAME=PLAN
 . . . . I PNUMB'="" D DCOV^AGAGERP2
 . . . W !,PATNAM," (",$G(CHRTNO),")(" S CHARCNT=CHARCNT+$L(PATNAM)+$L(CHRTNO)+4
 . . . I AGE["MOS" W AGE,")" S CHARCNT=CHARCNT+$L(AGE)+1
 . . . I AGE'["MOS" W +AGE,")" S CHARCNT=CHARCNT+$L(+AGE)+1
 . . . I CHARCNT<35 W ?35,$G(PNUMB)
 . . . W ?53,$E($G(PNAME),1,26)
 . . . W !,?10,$G(ADDR1)
 . . . I CHARCNT>34 W ?35,$G(PNUMB)
 . . . W ?53,$G(COVERAGE)
 . . . I $G(ADDR2)'="" W !,?10,$G(ADDR2)
 . . . W !,?10,$G(CITY)," ",$G(ST)," ",$G(ZIP)
 . . . W !,$G(LASTUPD)
 . . . W !,AGLINE("DASH") S LINECT=LINECT+7
 . . . S AGTOTAL=$G(AGTOTAL)+1
 . . . I $E(IOST)="C",$Y>(IOSL-5) K DIR D RTRN^AG S ESCAPE=X=U D:'ESCAPE PRVTHDR^AGAGERP2
 . . . I $E(IOST)'="C",$Y>(IOSL-17) W !! D PRVTHDR^AGAGERP2
 W !,"TOTAL RECORDS:",?20,$G(AGTOTAL),!!
 I $E(IOST)="C",PATNAM="" K DIR D RTRN^AG
 I $E(IOST)'="C" D CLOSE^%ZISH(IO)
 Q
 ;
GETPATN ; Get Specific Patient
 N PATNAM,PATNUM,PATNUM,SEL,AGINSLP,EFF,END,AGALTRES,PLAN,ARPLNTYP,ARNTYP,AGSEENLY,FOUND
 S PATNUM=+$G(EXCL("Specific Patient"))
 S PATNAM=$$GET1^DIQ(2,PATNUM,.01)
 Q:(+PATNUM=0)!(PATNAM="")
 S ^TMP("AGAGERP",$J)="",^TMP("AGAGERP",$J,PATNAM,PATNUM)=""
 K AGINS,AGINSN1,AGINSNN
 S SEL=0
 I $G(EXCL("Elig Date Range"))'="" S AGSEENLY=1
 S AGALTRES=$P($G(EXCL("Alternate Resource")),U,2)
 I (AGALTRES="MEDICARE")!(AGALTRES="") D FINDMCR^AGINS(PATNUM),FINDRRE^AGINS(PATNUM)
 I (AGALTRES="")!(AGALTRES="MEDICAID")!(AGALTRES="CHIP") D FINDMCD^AGINS(PATNUM)
 I (AGALTRES="")!(AGALTRES["PRIVATE") D FINDPVT^AGINS(PATNUM)
 K EFF,END,PLAN,ARNOTYP
 S AGINSLP=0
 F  S AGINSLP=$O(AGINS(AGINSLP)) Q:AGINSLP=""  D
 . S ARNOTYP=$P(AGINS(AGINSLP),U,10)
 . I AGALTRES="MEDICAID",ARNOTYP="D" D
 . . S PLAN=$P(AGINS(AGINSLP),U,12)
 . . I PLAN'="" D
 . . . ;S ARPLNTYP=$$GET1^DIQ(9999999.18,PLAN,.21,"I")
 . . . S ARPLNTYP=$$INSTYP^AGUTL(PLAN)  ;IHS/OIT/NKD AG*7.1*12
 . . . I ARPLNTYP="K",AGALTRES="MEDICAID" K AGINS(AGINSLP) Q
 . . . I ARPLNTYP'="K",AGALTRES="CHIP" K AGINS(AGINSLP) Q
 . I $D(AGINS(AGINSLP)) D
 . . S EFF=$P(AGINS(AGINSLP),U,5)
 . . S END=$P(AGINS(AGINSLP),U,6)
 . . S FOUND=0
 . . I $G(EXCL("Elig Date Range"))'="" D ELGDTCH^AGAGERP1(EFF,END,.FOUND)
 . . I $G(EXCL("Elig Date Range"))="" D ELGDTCH2^AGAGERP1(EFF,END,.FOUND)
 . . I 'FOUND K AGINS(AGINSLP)
 Q