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

AGDATA.m

Go to the documentation of this file.
AGDATA ;IHS/SD/EFG - Patient Registration 7.1 BAD DATA FIXER;   
 ;;7.1;PATIENT REGISTRATION;**1,2**;JAN 31, 2007
 ;
 ;PATPTR IS AN ARRAY OF PATIENTS THAT NEED TO BE FIXED
QUEFIX ;EP - QUEUE DATA FIX TO TASKMAN
 S ZTRTN="FIXALL^AGDATA(PATPTRS,NOMSG)",ZTDESC="Clean up all known data problems in eligibility records"
 S ZTIO=""
 S PATPTRS="",NOMSG=1
 S ZTSAVE("PATPTRS")=""
 S ZTSAVE("NOMSG")=""
 D ^%ZTLOAD
 I $D(ZTSK)[0 W !!,"Cleanup canceled!"
 E  W !!?5,"Full patient audit queued as Task # ",ZTSK,"!"
 H 2
 D HOME^%ZIS
 Q
FIXALL(PATPTRS,NOMSG) ;EP - FIX ALL ELIGIBLITY KNOWN BAD DATA ISSUES
 ;Q:'$D(PATPTRS)
 ;AG*7.1*2
 I '$D(PATPTRS) D  Q
 .D PRVT()
 .D RRE()
 .D MCD()
 .D MCR()
 .D GUAR()
 .D INSURER
 .D POLHCREF()
 .D KILL
 .I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Data fix is complete."),TS
 D PRVT(.PATPTRS)
 D RRE(.PATPTRS)
 D MCD(.PATPTRS)
 D MCR(.PATPTRS)
 D GUAR(.PATPTRS)
 D POLHCREF(.PATPTRS)
 ;I '$D(PATPTRS) D INSURER
 ;I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Data fix is complete."),TS
 D KILL
 Q
TS D MES^XPDUTL($$HTE^XLFDT($H))
 Q
GUAR(PATPTRS) ;EP - CLEAR ANY GUARANTOR ENTRIES WITH NO GUARANTORS ORDATES
 I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Fixing Guarantor entries with no guarantors or dates."),TS
 I $D(PATPTRS) D  Q
 .S PTR=""
 .F  S PTR=$O(PATPTRS(PTR)) Q:PTR=""  D:$D(^AUPNGUAR(PTR)) GUAR1(PTR)
 ;IF NO ARRAY PASSED DO THEM ALL
 S PATPTR=0
 F  S PATPTR=$O(^AUPNGUAR(PATPTR)) Q:'PATPTR  D GUAR1(PATPTR)
  Q
GUAR1(PATPTR) ;EP - DELETE GUARANTOR ENTRIES WITH MISSING GUARANTORS OR DATES
 N SUB1,SUB11,REDO
REDO ;
 S SUB1=$O(^AUPNGUAR(PATPTR,1,0))
 I 'SUB1 D  Q  ;NO GUARANTORS FOUND AT ALL
 .K DIE,DIK,DA,DIC S DIK="^AUPNGUAR(",DA=PATPTR D ^DIK
 ;FOR EACH GUARANTOR ARE THERE EFFECTIVE DATES
 S (SUB1,REDO)=0
 F  S SUB1=$O(^AUPNGUAR(PATPTR,1,SUB1)) Q:'SUB1  D  G REDO:REDO
 .S SUB11=$O(^AUPNGUAR(PATPTR,1,SUB1,11,0))
 .I 'SUB11 D  Q
 ..S REDO=1 K DIE,DIK,DA,DIC S DA(1)=PATPTR,DA=SUB1,DIK="^AUPNGUAR("_DA(1)_",1," D ^DIK
 Q
PRVT(PATPTRS) ;EP - CLEAR ANY PRIVATE ELIG RECORDS MISSING INSURER POINTER
 ;MUST DO DIRECT KILL BECAUSE X-REF NOT THERE. BOMBS ON USE OF ^DIK
 I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Fixing private eligibility with missing .01 field."),TS
 I $D(PATPTRS) D  Q
 .S PTR=""
 .F  S PTR=$O(PATPTRS(PTR)) Q:PTR=""  D:$D(^AUPNPRVT(PTR)) PRVT1(PTR)
 ;IF NO ARRAY PASSED DO THEM ALL
 S PATPTR=0
 F  S PATPTR=$O(^AUPNPRVT(PATPTR)) Q:'PATPTR  D PRVT1(PATPTR)
 S PATPTR=0
 F  S PATPTR=$O(^AUPNPRVT("B",PATPTR)) Q:PATPTR=""  D PRVT1(PATPTR)
 ;AG*7.1*2 IM21986 DANGLING C X-REF. ONLY DONE IF PATPTR NOT DEFINED
 ;THIS DOES THEM ALL. INDIVIDUAL PATIENT ENTRIES ARE DONE IN ^AGEDPRV
 Q:'$D(PATPTRS)
 S POLHPTR=0
 F  S POLHPTR=$O(^AUPNPRVT("C",POLHPTR)) Q:POLHPTR=""  D
 .S PATPTR=""
 .F  S PATPTR=$O(^AUPNPRVT("C",POLHPTR,PATPTR)) Q:PATPTR=""  D
 ..S RECNO=""
 ..F  S RECNO=$O(^AUPNPRVT("C",POLHPTR,PATPTR,RECNO)) Q:RECNO=""  D
 ...I '$D(^AUPNPRVT(PATPTR,11,RECNO,0))  K ^AUPNPRVT("C",POLHPTR,PATPTR,RECNO)
  Q
PRVT1(PATPTR) ;EP - DELETE PRVT ENTRIES MISSING .01 FIELD
 I $P($G(^AUPNPRVT(PATPTR,0)),U)="" K ^AUPNPRVT(PATPTR),^AUPNPRVT("B",PATPTR)
 S INSREC=0
 F  S INSREC=$O(^AUPNPRVT(PATPTR,11,INSREC)) Q:'INSREC  D
 .I $P($G(^AUPNPRVT(PATPTR,11,INSREC,0)),U)="" K ^AUPNPRVT(PATPTR,11,INSREC) Q
 .;I $P($G(^AUPNPRVT(PATPTR,11,INSREC,0)),U,8)="" K DIC,DIK,DIE,DA,DR S DA=INSREC,DA(1)=PATPTR,DIK="^AUPNPRVT("_DA(1)_",11," D ^DIK K DIC,DIK,DIE,DA,DR Q  ;ALLOW ADDING OF POLICY HOLDER
 .I $O(^AUPNPRVT(PATPTR,11,0)) Q
 .K DIC,DIK,DIE,DA,DR S DA=PATPTR,DIK="^AUPNPRVT(" D ^DIK K DIC,DIK,DIE,DA,DR
 Q
MCD(PATPTRS) ;EP - DELETE MCD RECORDS MISSING .01 FIELD
  N HRN,DFN,ST,MCDNUM,PTR,RECNO
  I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Optimizing Medicaid eligibility entries."),TS
 ;MUST DO DIRECT KILL BECAUSE X-REF NOT THERE. BOMBS ON USE OF ^DIK
 I $D(PATPTRS) D  Q
 .S PTR=""
 .F  S PTR=$O(PATPTRS(PTR)) Q:PTR=""  D  Q
 ..S RECNO=$O(^AUPNMCD("B",PTR,""))
 ..Q:RECNO=""
 ..D MCD1(RECNO)
 ..D MCD2(RECNO)
 ;IF NO ARRAY PASSED DO ALL ENTRIES
 S RECNO=0
 F  S RECNO=$O(^AUPNMCD(RECNO)) Q:'RECNO  D MCD1(RECNO)
 S PATPTR=0
 F  S PATPTR=$O(^AUPNMCD("AB",PATPTR)) Q:'PATPTR  D MCD2(PATPTR)
 Q
MCD1(RECNO) ;EP
 I $P($G(^AUPNMCD(RECNO,0)),U)="" K ^AUPNMCD(RECNO) Q  ;GET RID OF WHOLE THING INCLUDING SUBFILE
 ;IF THE INS. PTR IS MISSING LETS FIX IT SO TPB CLAIMS GENERATOR DOESN'T BLOW UP
 I $P($G(^AUPNMCD(RECNO,0)),U,2)="" D
 .K DIC,DIK,DIE,DA,DR
 .S MCDPTR=$O(^AUTNINS("B","MEDICAID",""))
 .S DA=RECNO,DIE="^AUPNMCD(",DR=".02///^S X=MCDPTR"
 .D ^DIE
 .K DIC,DIK,DIE,DA,DR
 S ELIGREC=0
 F  S ELIGREC=$O(^AUPNMCD(RECNO,11,ELIGREC)) Q:'ELIGREC  D
 .I $P($G(^AUPNMCD(RECNO,11,ELIGREC,0)),U)="" K ^AUPNMCD(RECNO,11,ELIGREC)
 Q
 ;
MCD2(PTR) ;EP
 S ST="" F  S ST=$O(^AUPNMCD("AB",PTR,ST)) Q:ST=""  D
 .S MCDNUM="" F  S MCDNUM=$O(^AUPNMCD("AB",PTR,ST,MCDNUM)) Q:MCDNUM=""  D
 ..S RECNO="" F  S RECNO=$O(^AUPNMCD("AB",PTR,ST,MCDNUM,RECNO)) Q:RECNO=""  D
 ...I $P($G(^AUPNMCD(RECNO,0)),U)="" K ^AUPNMCD(RECNO),^AUPNMCD("AB",PTR,ST,MCDNUM,RECNO)
 Q
RRE(PATPTRS) ;FIX "B" X-REF ENTRIES WITH NO ZERO RECORD
 ;MUST DO DIRECT KILL BECAUSE RECORD NOT THERE. BOMBS ON USE OF ^DIK DOESN'T WORK
 I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Optimizing Railroad eligibility entries."),TS
 I $D(PATPTRS) D  Q
 .S PATPTR=0
 .F  S PATPTR=$O(PATPTRS(PATPTR)) Q:'PTR  D:$D(^AUPNRRE(PATPTR)) RRE1(PATPTR)
 ;IF NO ARRAY PASSED DO THEM ALL
 S PATPTR=""
 F  S PATPTR=$O(^AUPNRRE("B",PATPTR)) Q:'PATPTR  D RRE1(PATPTR)
 S PATPTR=0
 F  S PATPTR=$O(^AUPNRRE(PATPTR)) Q:'PATPTR  D RRE1(PATPTR)
 Q
RRE1(PATPTR) ;EP
 I $P($G(^AUPNRRE(PATPTR,0)),U)="" K ^AUPNRRE(PATPTR),^AUPNRRE("B",PATPTR)
 Q
MCR(PATPTRS) ;EP - FIX MEDICARE WITH MISSING .01 FIELDS
 I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Optimizing Medicare eligibility entries."),TS
 I $D(PATPTRS) D  Q
 .S PTR="" F  S PTR=$O(PATPTRS(PTR)) Q:'PTR  D:$D(^AUPNMCR(PATPTR)) MCR1(PTR),MCR2(PTR)
 ;IF NO ARRAY PASSED DO THEM ALL
 S PATPTR=0
 F  S PATPTR=$O(^AUPNMCR(PATPTR)) Q:'PATPTR  D MCR1(PATPTR),MCR2(PATPTR)
 S PATPTR=0
 F  S PATPTR=$O(^AUPNMCR("B",PATPTR)) Q:'PATPTR  D MCR1(PATPTR)
 Q
MCR1(PATPTR) ;EP
 I $P($G(^AUPNMCR(PATPTR,0)),U)="" K ^AUPNMCR(PATPTR),^AUPNMCR("B",PATPTR)
 Q
MCR2(PATPTR) ;EP
 I $P($G(^AUPNMCR(PATPTR,0)),U)="" Q
 I '$O(^AUPNMCR(PATPTR,11,0)) D  Q
 .K DIR,DIE,DIC,DA
 .S DA=PATPTR
 .S DIK="^AUPNMCR("
 .D ^DIK
 .K DIR,DIE,DIC,DA
 Q
INSURER ;EP - DELETE DECIMAL IENS FROM INSURER FILE
  I '$D(ZTQUEUED),('NOMSG) D BMES^XPDUTL("Deleting Insurer records with decimal in IEN"),TS
 S INSPTR=0
 F  S INSPTR=$O(^AUTNINS(INSPTR)) Q:'INSPTR  D
 .I INSPTR[(".") K ^AUTNINS(INSPTR),^AUTNINS("B",INSPTR)
 Q
KILL ;EP - KILL VARS
 K PATPTR,INSPTR,PTR,RECNO,ELIGREC,INSREC
 Q
 ;POLM=ARRAY OF PAT. DFN
POLHCREF(POLM,INFOONLY) ;EP
 ;FOR FIXING DOUBLE POLICY HOLDER "C" X-REFS
 ;THIS IS A LOUSY FIX,VERY INEFFICIENT
 I '$D(ZTQUEUED),('$G(NOMSG)) D BMES^XPDUTL("Fixing double ""C"" x-refs entries pointing to the wrong records"),TS
 S:$G(INFOONLY)="" INFOONLY=0  ;MUST SEND INFOONLY AS 1 TO JUST SEE BAD X-REFS
 Q:$D(POLM)'=10
 S POLM=$O(POLM(""))
 Q:POLM=""
 S POLH=""
 F  S POLH=$O(^AUPNPRVT("C",POLH)) Q:POLH=""  D
 .Q:'$D(^AUPNPRVT("C",POLH,POLM))
 .D POLHCRE1(POLH,POLM,INFOONLY)
 Q
 ;POLH = POLICY HOLDER PTR
 ;POLM = ARRAY OF PT DFN
POLHCRE1(POLH,POLM,INFOONLY) ;EP
 W:INFOONLY !,"POLH: ",POLH,?15,"POLM: ",POLM
 ;W !,"POLH: ",POLH,?15,"POLM: ",POLM
 S REC=""
 F  S REC=$O(^AUPNPRVT("C",POLH,POLM,REC)) Q:REC=""  D
 .S TRUEPOLH=$P($G(^AUPNPRVT(POLM,11,REC,0)),U,8)
 .Q:TRUEPOLH=POLH
 .I INFOONLY D  Q
 ..W !?5,"BAD X-REF"
 ..W !?10,POLH,"***",POLM,"***",REC
 ..W !?15,TRUEPOLH
 ..W !
 .K ^AUPNPRVT("C",POLH,POLM,REC)
 Q