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

APCLPYR2.m

Go to the documentation of this file.
APCLPYR2 ; IHS/CMI/LAB - Patients by Payer (Insurer) - Medicare ;
 ;;2.0;IHS PCC SUITE;**21**;MAY 14, 2009;Build 34
 Q
 ;
MRALOOP ;EP
 I $E(IOST)="C" W !!,"Please be patient.  This may take a few minutes.",!! H 6
 S APCLINAM="Medicare Part A"
 K ^TMP($J,"APCLPYR")
 S APCLPAGE=0
 ;
 D HEADING
 ;
 S APCLDFN=0
 F  S APCLDFN=$O(^AUPNMCR(APCLDFN)) Q:'APCLDFN  D  Q:$D(DUOUT)
 .;Check if Patient is registered here
 .S Y=$$HRN^AUPNPAT(APCLDFN,APCLFAC)
 .I Y="" Q
 .I Y<1 Q
 .;
 .I APCLSORT="NAME" S APCLSRT=$P(^DPT(APCLDFN,0),U)_U_APCLDFN
 .I APCLSORT="HRNO" S APCLSRT=Y
 .;
 .;-->  Check for Other Insurance if user picked this option
 .I APCLOTH=1 D  Q:APCLICTR>1
 ..S APCLICTR=0
 ..I +$O(^AUPNMCR("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNMCD("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNRRE("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..S X=0
 ..F  S X=$O(^AUPNPRVT("B",APCLDFN,11,X)) Q:'X  S APCLICTR=APCLICTR+1
 .;
 .S APCLCTR=0
 .S APCLIEN=0
 .S APCLFLAG=0
 .F  S APCLIEN=$O(^AUPNMCR(APCLDFN,11,APCLIEN)) Q:'APCLIEN  D
 ..S APCLCTR=APCLCTR+1
 ..I $P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="A" Q
 ..S APCLFLAG=APCLIEN
 ..S APCLBEG=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U)
 ..S APCLEND=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,2)
 ..;--> There is no Beg Date 
 ..I APCLACT,APCLBEG="" S APCLFLAG=0
 ..;-->  User wants to restrict to beg elig dates after beg date
 ..I APCLACT=2,APCLBEG<APCLBDAT S APCLFLAG=0
 ..;--> Beg Date is earlier than selected end date 
 ..I APCLACT,APCLEDAT>0,APCLBEG>APCLEDAT S APCLFLAG=0
 ..;--> End date is before selected begin date 
 ..I APCLACT,APCLEND>0,APCLEND<APCLBDAT S APCLFLAG=0
 .I APCLFLAG D
 ..;S APCLMRNO=$P(^AUPNMCR(APCLDFN,0),U,3)
 ..S APCLMRNO=$$GETMCR^AGUTL(APCLDFN)  ;IHS/CMI/LAB NMCI PATCH 21
 ..S APCLMRSF=""
 ..S X=$P(^AUPNMCR(APCLDFN,0),U,4)
 ..I X S APCLMRSF=$G(^AUTTMCS(X,0))
 ..I APCLOTH,APCLCTR=1 D STORE
 ..I APCLOTH=0 D STORE
 ;
 S APCLCTR=0
 S APCLSRT=""
 F  S APCLSRT=$O(^TMP($J,"APCLPYR",APCLSRT)) Q:APCLSRT=""  D  Q:$D(DUOUT)
 .S X=^TMP($J,"APCLPYR",APCLSRT)
 .S APCLDFN=$P(X,U)
 .S APCLBEG=$P(X,U,2)
 .S APCLEND=$P(X,U,3)
 .S APCLMRNO=$P(X,U,4)
 .S APCLMRSF=$P(X,U,5)
 .D WRT
 .S APCLCTR=APCLCTR+1
 .I $Y>(IOSL-5) D  I '$D(DUOUT) D HEADING
 ..I $E(IOST)="C" K DIR S DIR(0)="E" D ^DIR K DIR
 ;
 I '$D(DUOUT) W !!,"Total: ",APCLCTR
 Q
 ;
MRBLOOP ;EP
 I $E(IOST)="C" W !!,"Please be patient.  This may take a few minutes.",!! H 6
 S APCLINAM="Medicare Part B"
 K ^TMP($J,"APCLPYR")
 S APCLPAGE=0
 ;
 D HEADING
 ;
 S APCLDFN=0
 F  S APCLDFN=$O(^AUPNMCR(APCLDFN)) Q:'APCLDFN  D  Q:$D(DUOUT)
 .;Check if Patient is registered here
 .S Y=$$HRN^AUPNPAT(APCLDFN,APCLFAC)
 .I Y="" Q
 .I Y<1 Q
 .;
 .I APCLSORT="NAME" S APCLSRT=$P(^DPT(APCLDFN,0),U)_U_APCLDFN
 .I APCLSORT="HRNO" S APCLSRT=Y
 .;
 .;-->  Check for Other Insurance if user picked this option
 .I APCLOTH=1 D  Q:APCLICTR>1
 ..S APCLICTR=0
 ..I +$O(^AUPNMCR("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNMCD("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNRRE("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..S X=0
 ..F  S X=$O(^AUPNPRVT("B",APCLDFN,11,X)) Q:'X  S APCLICTR=APCLICTR+1
 .;
 .S APCLCTR=0
 .S APCLIEN=0
 .S APCLFLAG=0
 .F  S APCLIEN=$O(^AUPNMCR(APCLDFN,11,APCLIEN)) Q:'APCLIEN  D
 ..S APCLCTR=APCLCTR+1
 ..I $P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="B" Q
 ..S APCLFLAG=APCLIEN
 ..S APCLBEG=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U)
 ..S APCLEND=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,2)
 ..;--> There is no Beg Date 
 ..I APCLACT,APCLBEG="" S APCLFLAG=0
 ..;-->  User wants to restrict to beg elig dates after beg date
 ..I APCLACT=2,APCLBEG<APCLBDAT S APCLFLAG=0
 ..;--> Beg Date is earlier than selected end date 
 ..I APCLACT,APCLEDAT>0,APCLBEG>APCLEDAT S APCLFLAG=0
 ..;--> End date is before selected begin date 
 ..I APCLACT,APCLEND>0,APCLEND<APCLBDAT S APCLFLAG=0
 .I APCLFLAG D
 ..;S APCLMRNO=$P(^AUPNMCR(APCLDFN,0),U,3)
 ..S APCLMRNO=$$GETMCR^AGUTL(APCLDFN)  ;IHS/CMI/LAB NMCI PATCH 21
 ..S APCLMRSF=""
 ..S X=$P(^AUPNMCR(APCLDFN,0),U,4)
 ..I X S APCLMRSF=$G(^AUTTMCS(X,0))
 ..I APCLOTH,APCLCTR=1 D STORE
 ..I APCLOTH=0 D STORE
 ;
 S APCLCTR=0
 S APCLSRT=""
 F  S APCLSRT=$O(^TMP($J,"APCLPYR",APCLSRT)) Q:APCLSRT=""  D  Q:$D(DUOUT)
 .S X=^TMP($J,"APCLPYR",APCLSRT)
 .S APCLDFN=$P(X,U)
 .S APCLBEG=$P(X,U,2)
 .S APCLEND=$P(X,U,3)
 .S APCLMRNO=$P(X,U,4)
 .S APCLMRSF=$P(X,U,5)
 .D WRT
 .S APCLCTR=APCLCTR+1
 .I $Y>(IOSL-5) D  I '$D(DUOUT) D HEADING
 ..I $E(IOST)="C" K DIR S DIR(0)="E" D ^DIR K DIR
 ;
 I '$D(DUOUT) W !!,"Total: ",APCLCTR
 Q
 ;
MRDLOOP ;EP
 I $E(IOST)="C" W !!,"Please be patient.  This may take a few minutes.",!! H 6
 S APCLINAM="Medicare Part D"
 K ^TMP($J,"APCLPYR")
 S APCLPAGE=0
 ;
 D HEADING
 ;
 S APCLDFN=0
 F  S APCLDFN=$O(^AUPNMCR(APCLDFN)) Q:'APCLDFN  D  Q:$D(DUOUT)
 .;Check if Patient is registered here
 .S Y=$$HRN^AUPNPAT(APCLDFN,APCLFAC)
 .I Y="" Q
 .I Y<1 Q
 .;
 .I APCLSORT="NAME" S APCLSRT=$P(^DPT(APCLDFN,0),U)_U_APCLDFN
 .I APCLSORT="HRNO" S APCLSRT=Y
 .;
 .;-->  Check for Other Insurance if user picked this option
 .I APCLOTH=1 D  Q:APCLICTR>1
 ..S APCLICTR=0
 ..I +$O(^AUPNMCR("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNMCD("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..I +$O(^AUPNRRE("B",APCLDFN,0)) S APCLICTR=APCLICTR+1
 ..S X=0
 ..F  S X=$O(^AUPNPRVT("B",APCLDFN,11,X)) Q:'X  S APCLICTR=APCLICTR+1
 .;
 .S APCLCTR=0
 .S APCLIEN=0
 .S APCLFLAG=0
 .F  S APCLIEN=$O(^AUPNMCR(APCLDFN,11,APCLIEN)) Q:'APCLIEN  D
 ..S APCLCTR=APCLCTR+1
 ..I $P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="D" Q
 ..S APCLFLAG=APCLIEN
 ..S APCLBEG=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U)
 ..S APCLEND=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,2)
 ..;--> There is no Beg Date 
 ..I APCLACT,APCLBEG="" S APCLFLAG=0
 ..;-->  User wants to restrict to beg elig dates after beg date
 ..I APCLACT=2,APCLBEG<APCLBDAT S APCLFLAG=0
 ..;--> Beg Date is earlier than selected end date 
 ..I APCLACT,APCLEDAT>0,APCLBEG>APCLEDAT S APCLFLAG=0
 ..;--> End date is before selected begin date 
 ..I APCLACT,APCLEND>0,APCLEND<APCLBDAT S APCLFLAG=0
 .I APCLFLAG D
 ..;S APCLMRNO=$P(^AUPNMCR(APCLDFN,0),U,3)
 ..S APCLMRNO=$$GETMCR^AGUTL(APCLDFN)  ;IHS/CMI/LAB NMCI PATCH 21
 ..S APCLMRSF=""
 ..S X=$P(^AUPNMCR(APCLDFN,0),U,4)
 ..I X S APCLMRSF=$G(^AUTTMCS(X,0))
 ..I APCLOTH,APCLCTR=1 D STORE
 ..I APCLOTH=0 D STORE
 ;
 S APCLCTR=0
 S APCLSRT=""
 F  S APCLSRT=$O(^TMP($J,"APCLPYR",APCLSRT)) Q:APCLSRT=""  D  Q:$D(DUOUT)
 .S X=^TMP($J,"APCLPYR",APCLSRT)
 .S APCLDFN=$P(X,U)
 .S APCLBEG=$P(X,U,2)
 .S APCLEND=$P(X,U,3)
 .S APCLMRNO=$P(X,U,4)
 .S APCLMRSF=$P(X,U,5)
 .D WRT
 .S APCLCTR=APCLCTR+1
 .I $Y>(IOSL-5) D  I '$D(DUOUT) D HEADING
 ..I $E(IOST)="C" K DIR S DIR(0)="E" D ^DIR K DIR
 ;
 I '$D(DUOUT) W !!,"Total: ",APCLCTR
 Q
 ;
STORE ;
 S ^TMP($J,"APCLPYR",APCLSRT)=APCLDFN_U_APCLBEG_U_APCLEND_U_APCLMRNO_U_APCLMRSF
 Q
 ;
WRT ;
 W $P(^DPT(APCLDFN,0),U)
 W ?32,$J($$HRN^AUPNPAT(APCLDFN,APCLFAC),6)
 W ?41,APCLMRNO
 W ?53,APCLMRSF
 I APCLALL=0 D  Q
 .W ?57,$E(APCLBEG,4,5),"/",$E(APCLBEG,6,7),"/",$E(APCLBEG,2,3)
 .I APCLEND W ?67,$E(APCLEND,4,5),"/",$E(APCLEND,6,7),"/",$E(APCLEND,2,3)
 .W !
 S APCLIEN=0
 F  S APCLIEN=$O(^AUPNMCR(APCLDFN,11,APCLIEN)) Q:'APCLIEN  D
 .S APCLBEG=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U)
 .I APCLACT=2,APCLBEG<APCLBDAT Q
 .S APCLEND=$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,2)
 .I APCLTYP="MRA",$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="A" Q
 .I APCLTYP="MRB",$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="B" Q
 .I APCLTYP="MRD",$P(^AUPNMCR(APCLDFN,11,APCLIEN,0),U,3)'="D" Q
 .W ?57,$E(APCLBEG,4,5),"/",$E(APCLBEG,6,7),"/",$E(APCLBEG,2,3)
 .I APCLEND W ?67,$E(APCLEND,4,5),"/",$E(APCLEND,6,7),"/",$E(APCLEND,2,3)
 .W !
 Q
 ;
HEADING ;
 D ^XBCLS
 W !
 S X=DT
 W $E(X,4,5),"/",$E(X,6,7),"/",$E(X,2,3)
 S X=$P($G(^DIC(4,APCLFAC,0)),U)
 W ?((IOM-$L(X))/2),X
 S APCLPAGE=APCLPAGE+1
 W ?70,"Page ",APCLPAGE
 W !
 ;
 S X="Patient List for "_APCLINAM
 W ?((IOM-$L(X))/2),X,!
 ;
 S X=""
 I APCLOTH=1 S X=X_"Having only this insurance"
 I X]"" W ?((IOM-$L(X))/2),X,!
 ;
 S X=""
 I APCLACT=0 S X=X_"With any eligibility dates"
 I APCLACT D
 .S X=X_"With eligibility "
 .I $G(APCLEDAT)=$G(APCLBDAT) S X=X_"as of "
 .I $G(APCLEDAT)'=$G(APCLBDAT) S X=X_"from "
 .S X=X_$E(APCLBDAT,4,5)_"/"_$E(APCLBDAT,6,7)_"/"_$E(APCLBDAT,2,3)
 .I $G(APCLEDAT)=$G(APCLBDAT) Q
 .I $G(APCLEDAT)="" Q
 .S X=X_" to "
 .S X=X_$E(APCLEDAT,4,5)_"/"_$E(APCLEDAT,6,7)_"/"_$E(APCLEDAT,2,3)
 I X]"" W ?((IOM-$L(X))/2),X,!
 ;
 W !
 ;
 W "Patient Name",?33,"HRNO",?43,"MCR #",?52,"SUF",?59,"Begin",?69,"End"
 W !
 ;
 W "------------",?32,"------",?41,"---------",?52,"---",?57,"--------",?67,"--------"
 W !
 Q