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

AGINSUPD.m

Go to the documentation of this file.
AGINSUPD ; IHS/ITSC/TPF - UPDATE SELECTION VARIABLE AFTER SCREEN FIELD IS EDITED ;   
 ;;7.1;PATIENT REGISTRATION;;AUG 25,2005
 ;THESE TAGS ARE CALLED FROM SCREEN EDIT ROUTINES WHICH NEED TO
 ;UPDATE THE 'SELECTION' VARIABLE FOR THE ITEM BEING EDITED
 ;
FINDMCR(AGSELECT) ;EP
 N TEMPDFN,MCRDATA,SUBSCRIP,SUF,POL,POLNUM,AGD1,MCRELIG,EFF,END,INS,COV,PHPTR,PH
 S SUBSCRIP=$P(AGSELECT,U,11)
 S TEMPDFN=$P(SUBSCRIP,",")
 Q:$G(TEMPDFN)=""  ;IF NO DFN NO ENTRY CAN BE FOUND AT ALL
 S AGD1=$P(SUBSCRIP,",",3)
 S:AGD1="" AGD1=$O(^AUPNMCR(TEMPDFN,11,0))
 S RECPTR=TEMPDFN_",11,"_AGD1_","_0
 S MCRDATA=$G(^AUPNMCR(TEMPDFN,0))
 S PCP=$P(MCRDATA,U,14)
 S (INSPTR,INS)=""
 S INSPTR=$P(MCRDATA,U,2)
 S:INSPTR'="" INS=$P($G(^AUTNINS(INSPTR,0)),U)
 S TYPE="R"
 S SUFPTR=$P(MCRDATA,U,4)
 S SUF=$S($G(SUFPTR)="":"",1:$P(^AUTTMCS(SUFPTR,0),U))
 S POL=$P(MCRDATA,U,3)
 S:POL'="" POLNUM=POL_SUF
 S PHPTR="M"_TEMPDFN
 S PH=$P($G(^AUPNMCR(TEMPDFN,21)),U)
 S MCRELIG=$S($G(AGD1)="":"",1:$G(^AUPNMCR(TEMPDFN,11,AGD1,0)))
 S EFF=$S(MCRELIG="":"",1:$P(MCRELIG,U))
 S END=$S(MCRELIG="":"",1:$P(MCRELIG,U,2))
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S COVPTR=""
 S COV=$S(MCRELIG="":"",1:$P(MCRELIG,U,3))
 D LOAD
 Q AGSELECT
FINDMCD(AGSELECT) ;EP
 N MCDPTR,MCDSTR,INSPTR,INS,COVPTR,COV,POL,PHPTR,PHSTR,PH,AGD1,MCDELIG,EFF,END,PLANPTR
 N PCP,GRPNAME,PLANNAME,MCDRATE,POLNUM
 S SUBSCRIP=$P(AGSELECT,U,11)
 S MCDPTR=$P(SUBSCRIP,",")
 S AGD1=$P(SUBSCRIP,",",3)
 S:AGD1="" AGD1=$O(^AUPNMCD(MCDPTR,11,0))
 S MCDSTR=$G(^AUPNMCD(MCDPTR,0))
 S PLANPTR=$P(MCDSTR,U,10)
 S PLANNAME=PLANPTR
 S INSPTR=$P(MCDSTR,U,2)
 S MCDRATE=$P(MCDSTR,U,11)
 S PCP=$P(MCDSTR,U,14)
 S GRPNAME=$P(MCDSTR,U,17)
 S:GRPNAME'="" GRPNUMB=$P($G(^AUTNEGRP(GRPNAME,0)),U,2)
 I $P(MCDSTR,U,10)'="" D
 . S INS=$P(^AUTNINS(INSPTR,0),U)
 . S TYPE="D"
 I $P(MCDSTR,U,10)="" S INS="MEDICAID",INSPTR=$P(MCDSTR,U,2),TYPE="D"
 I $P(MCDSTR,U,3)="" S POLNUM=""
 I $P(MCDSTR,U,3)'="" S POLNUM=$P(MCDSTR,U,3)
 I $D(^AUPNMCD(MCDPTR,21))  D
 . I $P(^AUPNMCD(MCDPTR,21),U)'="" S PH=$P(^AUPNMCD(MCDPTR,21),U)
 . I $P(^AUPNMCD(MCDPTR,21),U)="" S PH=""
 I '$D(^AUPNMCD(MCDPTR,21)) S PH=""
 S PHPTR="D"_MCDPTR
 S MCDELIG=$S($G(AGD1)'="":$G(^AUPNMCD(MCDPTR,11,AGD1,0)),1:"")
 S RECPTR=MCDPTR_",11,"_AGD1_","_0
 S EFF=$P(MCDELIG,U)
 S END=$P(MCDELIG,U,2)
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S COVPTR=""
 I $P(MCDELIG,U,3)'="" S COV=$P(MCDELIG,U,3)
 I $P(MCDELIG,U,3)="" S COV=""
 D LOAD
 Q AGSELECT
FINDRRE(AGSELECT) ;EP
 N TEMPDFN,SUBSCRIP,RREDATA,PRE,POL,POLNUM,AGD1,RREELIG,EFF,END,PHPTR,PH,POLNUM,COV,PCP,PLANNAME
 S SUBSCRIP=$P(AGSELECT,U,11)
 S TEMPDFN=$P(SUBSCRIP,",")
 Q:$G(TEMPDFN)=""  ;IF NO DFN NO ENTRY CAN BE FOUND AT ALL
 S RREDATA=$G(^AUPNRRE(TEMPDFN,0))
 S AGD1=$P(SUBSCRIP,",",3)
 S:AGD1="" AGD1=$O(^AUPNRRE(TEMPDFN,11,0))
 S PCP=$P(RREDATA,U,14)
 S (INSPTR,INS)=""
 S INSPTR=$P(RREDATA,U,2)
 S:INSPTR'="" INS=$P($G(^AUTNINS(INSPTR,0)),U)
 S TYPE="R"
 S PRE=""
 S PREPTR=$P(RREDATA,U,3)
 S:PREPTR'="" PRE=$P(^AUTTRRP(PREPTR,0),U)
 S POL=$P(RREDATA,U,4)
 S:POL'="" POLNUM=PRE_POL
 S PHPTR="R"_TEMPDFN
 S PH=$P($G(^AUPNRRE(TEMPDFN,21)),U)
 S RREELIG=$S($G(AGD1)'="":$G(^AUPNRRE(TEMPDFN,11,AGD1,0)),1:"")
 S RECPTR=TEMPDFN_",11,"_AGD1_","_0
 S EFF=$P(RREELIG,U)
 S END=$P(RREELIG,U,2)
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S PLANNAME=$P(RREELIG,U,4)
 S COVPTR=""
 S COV=$P(RREELIG,U,3)
 D LOAD
 Q AGSELECT
FINDPVT(AGSELECT) ;EP
 N PHPTR,PH,COVPTR,COV,POLNUM,PLANPTR,GRPNUMB,GRPNAME,PLANNAME,AGD1,PVTSTR,INS,PHREC,PHPAT,EFF,END
 S SUBSCRIP=$P(AGSELECT,U,11)
 S AGD1=$P(SUBSCRIP,",",3)
 S TEMPDFN=$P(SUBSCRIP,",")
 Q:$G(TEMPDFN)=""  ;IF NO DFN NO ENTRY CAN BE FOUND AT ALL
 S:AGD1="" AGD1=$O(^AUPNPRVT(TEMPDFN,11,0))
 S PVTSTR=$G(^AUPNPRVT(TEMPDFN,11,AGD1,0))
 S RECPTR=TEMPDFN_",11,"_AGD1_","_0
 S INSPTR=$P(PVTSTR,U)
 S RELPOLHO=$P(PVTSTR,U,5)
 S INS=$S($G(INSPTR)'="":$P($G(^AUTNINS(INSPTR,0)),U),1:"")
 S TYPE="P"
 S PHPTR=TYPE_$S($G(AGD1)'="":$P($G(^AUPNPRVT(TEMPDFN,11,AGD1,0)),U,8),1:"")
 I $E($G(PHPTR),2,10)'="" D
 . S PHREC=$G(^AUPN3PPH($E(PHPTR,2,10),0))
 . S GRPNUMB=$P($G(^AUPN3PPH($E(PHPTR,2,9),0)),U,6)
 . S GRPNAME=$S(GRPNUMB="":"",1:$P($G(^AUTNEGRP(GRPNUMB,0)),U))
 . S INSGEND=$P(PHREC,U,8)
 . S PH=$P(PHREC,U)
 . S (COVPTR,COV)=$P(PHREC,U,5)
 . I COVPTR'="" D
 .. S COV=$P(^AUTTPIC(COVPTR,0),U)
 .. ;GET THE MOST CURRENT DATE IN AFFECT BY TAKING TODAYS DATE AND GOING BACK ONE
 .. S DATEINEF=DT+.01,DATEINEF=$O(^AUTTPIC(COVPTR,19,"B",DATEINEF),-1)
 .. I DATEINEF="" S (OPCOPAY,COINS,FAMDEDUC,INDDEDUC)="" Q
 .. S DATEINEF=$O(^AUTTPIC(COVPTR,19,"B",DATEINEF,""))
 .. S OPCOPAY=$P($G(^AUTTPIC(COVPTR,19,DATEINEF,0)),U,2)
 .. S OPCOINS=$P($G(^AUTTPIC(COVPTR,19,DATEINEF,0)),U,3)
 .. S FAMDEDUC=$P($G(^AUTTPIC(COVPTR,19,DATEINEF,0)),U,11)
 .. S INDDEDUC=$P($G(^AUTTPIC(COVPTR,19,DATEINEF,0)),U,12)
 . S POLNUM=$P(PHREC,U,4)
 E  D
 .S (PHREC,GRPNUMB,GRPNAME,PH,COVPTR,COV,POLNUM)=""
 I $G(PVTSTR)'="" S EFF=$P(PVTSTR,U,6),END=$P(PVTSTR,U,7)
 E  S (EFF,END)=""
 S ISACTIVE=$$ISACTIVE(EFF,END)
 D LOAD
 Q AGSELECT
FINDTPL(AGSELECT) ;EP
 N TEMPDFN
 S (PHPTR,PH,COVPTR,COV,POLNUM,INS,INSPTR,EFF,END,RECPTR,PLANPTR,GRPNAME,GRPNUMB)=""
 S SUBSCRIP=$P(AGSELECT,U,11)
 S TEMPDFN=$P(SUBSCRIP,",")
 Q:$G(TEMPDFN)=""  ;IF NO DFN NO ENTRY CAN BE FOUND AT ALL
 S AGTPLDT=$P(SUBSCRIP,",",2)
 S:AGTPLDT="" AGTPLDT=$O(^AUPNTPL(TEMPDFN,1,0))
 S AGDATA0=$S(AGTPLDT="":"",1:$G(^AUPNTPL(TEMPDFN,1,AGTPLDT,0)))
 S AGDATA1=$S(AGTPLDT="":"",1:$G(^AUPNTPL(TEMPDFN,1,AGTPLDT,1)))
 S GRPNAME=$P(AGDATA0,U,6)
 S GRPNUMB=$S(GRPNAME="":"",1:$P($G(^AUTNEGRP(GRPNAME,0)),U,2))
 S RECPTR=TEMPDFN_","_AGTPLDT
 S INSPTR=$P(AGDATA0,U,2)
 S EFF=$P(AGDATA0,U,4)
 S END=$P(AGDATA0,U,5)
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S POLNUM=$P(AGDATA0,U,3)
 S PH=$P(AGDATA1,U)
 S INS=$S(INSPTR'="":$P($G(^AUTNINS(INSPTR,0)),U),1:"UNDEFINED")
 S (COV,TYPE)="T"
 D LOAD
 K AGTPLDT,AGDATA0,AGDATA1,PHPTR,PH,COVPTR,COV,POLNUM,INS,INSPTR,EFF,END,RECPTR,PLANPTR,GRPNAME,GRPNUMB
 Q AGSELECT
FINDWC(AGSELECT) ;EP
 N PHPTR,PH,COVPTR,COV,POLNUM,INS,INSPTR,EFF,END,RECPTR,PLANPTR,GRPNAME,GRPNUMB,SUBSCRIP
 S SUBSCRIP=$P(AGSELECT,U,11)
 S TEMPDFN=$P(SUBSCRIP,",")
 Q:$G(TEMPDFN)=""  ;IF NO DFN NO ENTRY CAN BE FOUND AT ALL
 S AGWCDT=$P(SUBSCRIP,",",2)
 S:AGWCDT="" AGWCDT=$O(^AUPNWC(TEMPDFN,11,0))
 I '$D(^AUPNWC(TEMPDFN,11,AGWCDT)) S AGWCDT=$O(^AUPNWC(TEMPDFN,11,AGWCDT,0))
 S AGDATA0=$S($G(AGWCDT)="":"",1:$G(^AUPNWC(TEMPDFN,11,AGWCDT,0)))
 S AGDATA1=$S($G(AGWCDT)="":"",1:$G(^AUPNWC(TEMPDFN,11,AGWCDT,1)))
 S RECPTR=TEMPDFN_","_AGWCDT
 S GRPNAME=$P(AGDATA0,U,11)
 S GRPNUMB=$S(GRPNAME="":"",1:$P($G(^AUTNEGRP(GRPNAME,0)),U,2))
 S ENTITY=$P(AGDATA0,U,10),INSPTR=ENTITY
 S EFF=$P(AGDATA0,U,12)
 S END=$P(AGDATA0,U,13)
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S POLNUM=$P(AGDATA0,U,4)
 S PH=$P(AGDATA0,U,6)
 S INS=$S(ENTITY'="":$P($G(^AUTNINS(ENTITY,0)),U),1:"UNDEFINED")
 S (COV,TYPE)="W"
 D LOAD
 Q AGSELECT
FINDGUAR(AGSELECT) ;EP
 N PHPTR,PH,COVPTR,COV,POLNUM,INS,INSPTR,EFF,END,RECPTR,PLANPTR,INSGLORF,TEMPDFN
 S SUBSCRIP=$P(AGSELECT,U,11)
 S TEMPDFN=$P(SUBSCRIP,",")
 S AGGUAR=$P(SUBSCRIP,",",2)
 S AGGUARDT=$P(SUBSCRIP,",",3)
 S:AGGUARDT="" AGGUARDT=$O(^AUPNGUAR(TEMPDFN,1,AGGUAR,11,0))
 I '$D(^AUPNGUAR(TEMPDFN,1,AGGUAR,11,AGGUARDT)) S AGGUARDT=$O(^AUPNGUAR(TEMPDFN,1,AGGUAR,11,0))
 S POLNUM=$S($G(AGGUAR)="":"",1:$P($G(^AUPNGUAR(TEMPDFN,1,AGGUAR,0)),U,3))
 S RECPTR=TEMPDFN_","_AGGUAR_","_AGGUARDT
 S INSPTR=$S($G(AGGUAR)="":"",1:$P($P($G(^AUPNGUAR(TEMPDFN,1,AGGUAR,0)),U),";")_",0)")
 S INSGLO=$S($G(AGGUAR)="":"",1:U_$P($P($G(^AUPNGUAR(TEMPDFN,1,AGGUAR,0)),U),";",2))
 S INSGLORF=INSGLO_INSPTR
 S INS=$P(@INSGLORF,U)
 I INSGLORF[("AUPNPAT") D
 .S GSTREET=$S($G(INS)="":"",1:$P($G(^DPT(INS,.11)),U))
 .S GCITY=$S($G(INS)="":"",1:$P($G(^DPT(INS,.11)),U,4))
 .S GSTATE=$S($G(INS)="":"",1:$P($G(^DPT(INS,.11)),U,5))
 .S GZIP=$S($G(INS)="":"",1:$P($G(^DPT(INS,.11)),U,6))
 .S INS=$S($G(INS)="":"",1:$P($G(^DPT(INS,0)),U))
 E  D
 .S GSTREET=$P($G(@INSGLORF),U,2)
 .S GCITY=$P($G(@INSGLORF),U,3)
 .S GSTATE=$P($G(@INSGLORF),U,4)
 .S GZIP=$P($G(@INSGLORF),U,5)
 S INSGLORF=$TR(INSGLORF,U)
 I $G(AGGUAR)'="",($G(AGGUARDT)'="") S EFF=$P($G(^AUPNGUAR(TEMPDFN,1,AGGUAR,11,AGGUARDT,0)),U),END=$P($G(^AUPNGUAR(TEMPDFN,1,AGGUAR,11,AGGUARDT,0)),U,2)
 E  S (EFF,END)=""
 S ISACTIVE=$$ISACTIVE(EFF,END)
 S (COV,TYPE)="G"
 D LOAD
 Q AGSELECT
ISACTIVE(EFFDT,ENDDT) ;EP - IS THE POLICY ACTIVE AS OF TODAY
 NEW OPENEND
 I EFFDT="",(ENDDT="") Q 0  ;NO DATES CONSIDERED INACTIVE
 S ENDDT=ENDDT  ;TRUE IF ENDING DATE IS AT COB OF ENDING DATE - ANSWER FROM ADRIAN IS IT IS
 ;               IN FORCE FOR ALL OF TODAY
 S OPENEND=ENDDT=""
 I OPENEND I DT=EFFDT!(DT>EFFDT) Q 1
 I DT=EFFDT!(DT=ENDDT) Q 1
 I DT>EFFDT&(DT<ENDDT) Q 1
 Q 0
LOAD ;LOAD SELECTION VARIABLE WITH CURRENT ELIGIBILITY DATA
 S AGSELECT=$G(INS)_U_$G(INSPTR)_U_$G(COVPTR)_U_$G(COV)_U_$G(EFF)_U_$G(END)_U_$G(PHPTR)_U_$G(PH)_U_$G(POLNUM)_U_$G(TYPE)_U_$G(RECPTR)_U_$G(PLANPTR)_U_$G(ISACTIVE)_U_$G(INSGLORF)_U_$G(MCDRATE)_U_$G(RELPOLHO)
 S AGSELECT=AGSELECT_U_$G(PCP)_U_$G(PLANNAME)_U_$G(GRPNAME)_U_$G(GRPNUMB)_U_$G(GSTREET)_U_$G(GCITY)_U_$G(GSTATE)_U_$G(GZIP)_U_$G(INSGEND)_U_$G(OPCOPAY)_U_$G(OPCOINS)_U_$G(FAMDEDUC)_U_$G(INDDEDUC)
 Q