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

BPMXFX1.m

Go to the documentation of this file.
BPMXFX1 ;IHS/OIT/NKD - CLEANUP UTILITY - SPLIT INTO MULTIPLE ROUTINES - 7/23/12 ;
 ;;1.0;IHS PATIENT MERGE;**2**;MAR 01, 2010;Build 1
 ;
 Q
TPB ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX 3PB ENTRIES
 ;
 N XIEN,BPMFR,BPMTO,BPMCNT,BPMCNT2,BPMHDR,BPMTMP
 ;
 D RSLT^BPMXFIX("Merging remaining 3PB Claims and Bills...")
 S (XIEN,BPMCNT,BPMCNT2)=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),BPMTO=$$LAST^BPMXFIX(BPMFR),BPMHDR=1
 . ; PROCESS CLAIMS
 . N BPMDUZ2,BPMD0
 . S BPMDUZ2=0 F  S BPMDUZ2=$O(^ABMDCLM(BPMDUZ2)) Q:BPMDUZ2'=+BPMDUZ2  D
 . . N BPMTMP
 . . S BPMD0=0 F  S BPMD0=$O(^ABMDCLM(BPMDUZ2,"B",BPMFR,BPMD0)) Q:BPMD0'=+BPMD0  D
 . . . Q:$P($G(^ABMDCLM(BPMDUZ2,BPMD0,0)),U)'=BPMFR
 . . . S BPMTMP(BPMD0)=""
 . . . D ONECLAIM^BPMX3PB(BPMDUZ2,BPMD0,BPMTO)
 . . . S BPMCNT=BPMCNT+1
 . . I $D(BPMTMP) D
 . . . I $O(BPMTMP($O(BPMTMP(0))))="" D HDR^BPMXFIX(BPMTO,BPMDUZ2,$O(BPMTMP(0)),,"Claim") Q
 . . . D RSLT^BPMXFIX(""),HDR^BPMXFIX(BPMTO,BPMDUZ2,,,"Claim"),ENTRIES^BPMXFIX(.BPMTMP)
 . ; PROCESS BILLS
 . N BPMDUZ2,BPMD0
 . S BPMDUZ2=0 F  S BPMDUZ2=$O(^ABMDBILL(BPMDUZ2)) Q:BPMDUZ2'=+BPMDUZ2  D
 . . N BPMTMP
 . . S BPMD0=0 F  S BPMD0=$O(^ABMDBILL(BPMDUZ2,"D",BPMFR,BPMD0)) Q:BPMD0'=+BPMD0  D
 . . . Q:$P($G(^ABMDBILL(BPMDUZ2,BPMD0,0)),U,5)'=BPMFR
 . . . N BPMB S BPMB=$P($G(^ABMDBILL(BPMDUZ2,BPMD0,0)),U,1)
 . . . S BPMTMP(BPMB)=""
 . . . D ONEBILL^BPMX3PB(BPMDUZ2,BPMD0,BPMTO)
 . . . S BPMCNT2=BPMCNT2+1
 . . I $D(BPMTMP) D
 . . . I $O(BPMTMP($O(BPMTMP(0))))="" D HDR^BPMXFIX(BPMTO,BPMDUZ2,$O(BPMTMP(0)),,"Bill") Q
 . . . D RSLT^BPMXFIX(""),HDR^BPMXFIX(BPMTO,BPMDUZ2,,,"Bill"),ENTRIES^BPMXFIX(.BPMTMP)
 D RSLT^BPMXFIX("  *** Total Claims Found: "_BPMCNT_" ***")
 D RSLT^BPMXFIX("  *** Total Bills  Found: "_BPMCNT2_" ***")
 ; RE-INDEX "ADR" X-REF ON ALL MERGED TO BILLS
 ; CORRECT CLAIM PATIENT IF DIFFERENT
 N BPMCNT,BPMD0,BPMDUZ2,BPMDUZ,BPMTO,DA,X,BPMCI,BPMCP
 D RSLT^BPMXFIX("Correcting improperly merged Claims...")
 S (BPMDUZ2,BPMCNT)=0
 F  S BPMDUZ2=$O(^ABMDBILL(BPMDUZ2)) Q:BPMDUZ2'=+BPMDUZ2  D
 . S BPMTO=0 F  S BPMTO=$O(^TMP("BPM",$J,"TO",BPMTO)) Q:BPMTO'=+BPMTO  D
 . . N BPMTMP
 . . S BPMHDR=1
 . . S BPMD0=0 F  S BPMD0=$O(^ABMDBILL(BPMDUZ2,"D",BPMTO,BPMD0)) Q:BPMD0'=+BPMD0  D
 . . . Q:$P($G(^ABMDBILL(BPMDUZ2,BPMD0,0)),U,5)'=BPMTO
 . . . S BPMDUZ(2)=DUZ(2),DUZ(2)=BPMDUZ2
 . . . S DA=BPMD0
 . . . S X=$$GET1^DIQ(9002274.4,BPMD0,.71,"I")
 . . . X ^DD(9002274.4,.71,1,2,2)
 . . . X ^DD(9002274.4,.71,1,2,1)
 . . . S DUZ(2)=BPMDUZ(2)
 . . . S BPMCI=+$P($G(^ABMDBILL(BPMDUZ2,BPMD0,0)),U,1)
 . . . Q:'BPMCI
 . . . S BPMCP=$P($G(^ABMDCLM(BPMDUZ2,BPMCI,0)),"^",1)
 . . . Q:BPMCP'=+BPMCP
 . . . I BPMCP'=BPMTO D
 . . . . S BPMTMP(BPMCI)=""
 . . . . D ONECLAIM^BPMX3PB(BPMDUZ2,BPMCI,BPMTO)
 . . . . S BPMCNT=BPMCNT+1
 . . I $D(BPMTMP) D
 . . . I $O(BPMTMP($O(BPMTMP(0))))="" D HDR^BPMXFIX(BPMTO,BPMDUZ2,$O(BPMTMP(0)),,"Claim") Q
 . . . D RSLT^BPMXFIX(""),HDR^BPMXFIX(BPMTO,BPMDUZ2,,,"Claim"),ENTRIES^BPMXFIX(.BPMTMP)
 D RSLT^BPMXFIX("  *** Total Claim Corrections Found: "_BPMCNT_" ***")
 N BPMDUZ2,BPMCP,BPMCH,BPMCI,BPMB,BPMBP,BPMBI,BPMV,BPMVP,BPMVI
 S BPMDUZ2=0 F  S BPMDUZ2=$O(^ABMDCLM(BPMDUZ2)) Q:BPMDUZ2'=+BPMDUZ2  D
 . S BPMCP=0 F  S BPMCP=$O(^ABMDCLM(BPMDUZ2,"B",BPMCP)) Q:BPMCP'=+BPMCP  D
 . . S BPMCH=$$HRN^BPMXFIX(BPMDUZ2,BPMCP)
 . . Q:'$$MRG^BPMXFIX(BPMCP,"TO")&'$$MRG^BPMXFIX(BPMCH,"TO")
 . . S BPMCI=0 F  S BPMCI=$O(^ABMDCLM(BPMDUZ2,"B",BPMCP,BPMCI)) Q:BPMCI'=+BPMCI  D
 . . . Q:$P($G(^ABMDCLM(BPMDUZ2,BPMCI,0)),U)'=BPMCP
 . . . ;
 . . . S BPMB=$$BILL^BPMXFIX(BPMDUZ2,BPMCI),BPMBP=$P(BPMB,"^",1),BPMBI=$P(BPMB,"^",2)
 . . . Q:BPMCP=BPMBP
 . . . Q:'$$MRG^BPMXFIX(BPMBP,"TO")
 . . . ;
 . . . S BPMV=$$VSIT^BPMXFIX(BPMDUZ2,BPMCI),BPMVP=$P(BPMV,"^",1),BPMVI=$P(BPMV,"^",2)
 . . . Q:(BPMCP=BPMVP)!(BPMCP=$$LAST^BPMXFIX(BPMVP))
 . . . Q:'$$MRG^BPMXFIX(BPMVP,"TO")&'$$MRG^BPMXFIX(BPMVP,"FROM")
 . . . I ($L(BPMBP_BPMVP)>0) D  Q
 . . . . N BPMTO
 . . . . S BPMTO=$$LAST^BPMXFIX($S($L(BPMBP)>0:BPMBP,$L(BPMVP)>0:BPMVP,1:0))
 . . . . D HDR^BPMXFIX(BPMTO,BPMDUZ2,BPMCI)
 . . . . D ONECLAIM^BPMX3PB(BPMDUZ2,BPMCI,BPMTO)
 . . . D RSLT^BPMXFIX("The following Claim does not have Bill/Visit data for Patient comparisons")
 . . . D HDR^BPMXFIX(BPMCP,BPMDUZ2,BPMCI)
 . . . I ($L(BPMCH)>0)&$$MRG^BPMXFIX(BPMCH,"TO") D HDR^BPMXFIX($$LAST^BPMXFIX(BPMCH),BPMDUZ2,,,,"Possible owner")
 Q
 ;
ATX ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX PT TAXONOMY ENTRIES
 ;
 N BPMCNT,BPMD0,BPMD1
 ;
 S (BPMCNT,BPMD0)=0
 F  S BPMD0=$O(^ATXPAT(BPMD0)) Q:'BPMD0  D
 . S BPMD1=0
 . F  S BPMD1=$O(^ATXPAT(BPMD0,11,BPMD1)) Q:'BPMD1  D
 . . Q:'$D(^TMP("BPM",$J,"FROM",BPMD1))
 . . D HDR^BPMXFIX($$LAST^BPMXFIX(BPMD1),DUZ(2),BPMD0_","_BPMD1)
 . . D ONE^BPMXTAX(BPMD0,BPMD1,BPMD1,$$LAST^BPMXFIX(BPMD1))
 . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 ;
 Q
 ;
BQI ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX ICARE ENTRIES
 ;
 ; REMOVE "AC" X-REF ON THE FROM PATIENT
 N BPMCNT,I,BPMFR
 S (BPMCNT,I)=0
 F  S I=$O(^BQIPAT("AC",I)) Q:$L(I)<1  D
 . S BPMFR=0
 . F  S BPMFR=$O(^TMP("BPM",$J,"FROM",BPMFR)) Q:+BPMFR'=BPMFR  D
 . . Q:'$D(^BQIPAT("AC",I,BPMFR))
 . . K ^BQIPAT("AC",I,BPMFR)
 . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** iCare Patient AC Index Total Found: "_BPMCNT_" ***")
 ;
 ; REPOINT ANY PANELS THE FROM PATIENT STILL EXISTS ON
 N OWNR,PLIEN,UID,BPMD1,BPMCNT
 S UID=$J,(OWNR,BPMCNT)=0
 F  S OWNR=$O(^BQICARE(OWNR)) Q:+OWNR'=OWNR  D
 . S PLIEN=0
 . F  S PLIEN=$O(^BQICARE(OWNR,1,PLIEN)) Q:+PLIEN'=PLIEN  D
 . . S BPMD1=0
 . . F  S BPMD1=$O(^BQICARE(OWNR,1,PLIEN,40,BPMD1)) Q:+BPMD1'=BPMD1  D
 . . . Q:'$D(^TMP("BPM",$J,"FROM",BPMD1))
 . . . N DIC,DIE,DA,IENS,X,DATA,DINUM,DLAYGO,DIK,DO,DD
 . . . S DATA=$G(^BQICARE(OWNR,1,PLIEN,40,BPMD1,0))
 . . . ;
 . . . S DA(2)=OWNR,DA(1)=PLIEN,DA=BPMD1
 . . . ; Delete old record
 . . . S DIK="^BQICARE("_DA(2)_",1,"_DA(1)_",40," D ^DIK
 . . . ; Add new record
 . . . S DA(2)=OWNR,DA(1)=PLIEN,(X,DINUM)=$$LAST^BPMXFIX(BPMD1)
 . . . S DIC="^BQICARE("_DA(2)_",1,"_DA(1)_",40,",DIE=DIC
 . . . S DLAYGO=90505.04,DIC(0)="L",DIC("P")=DLAYGO
 . . . I '$D(^BQICARE(DA(2),1,DA(1),40,0)) S ^BQICARE(DA(2),1,DA(1),40,0)="^90505.04P^^"
 . . . K DO,DD D FILE^DICN
 . . . S $P(^BQICARE(OWNR,1,PLIEN,40,$$LAST^BPMXFIX(BPMD1),0),U,2,99)=$P(DATA,U,2,99)
 . . . D STA^BQIPLRF(OWNR,PLIEN)
 . . . D ULK^BQIPLRF(OWNR,PLIEN)
 . . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** iCare User Total Found: "_BPMCNT_" ***")
 ;
 Q
 ;
EDR ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 RESEND A40 MESSAGES FOR BADE
 ;
 Q:'$$PATCH^XPDUTL("BPM*1.0*1")!'$$PATCH^XPDUTL("BADE*1.0*1")
 N XIEN
 ;
 S XIEN=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . N BPMFR,BPMTO,ERR
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),BPMTO=$O(^TMP("BPM",$J,XIEN,BPMFR,""))
 . D A40^BADEMRG(BPMFR,BPMTO)
 . I '$D(ERR) D HDR^BPMXFIX(BPMTO,DUZ(2),BPMFR,,"From Patient IEN")
 . E  D RSLT^BPMXFIX($J("",2)_"EDR A40 MESSAGE FAILED: "_BPMFR_" -> "_BPMTO)
 ;
 Q
 ;
LAB ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX LAB ENTRIES
 ;
 N XIEN,BPMCNT1,BPMCNT2
 ;
 S (XIEN,BPMCNT1,BPMCNT2)=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . N BPMFR,BPMTO,XIENS,BLRFM,BLRNEW,BLROLD,BLRTO,XDRMRG,DA,DIE,DR,X,Y,I,J
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),BPMTO=$O(^TMP("BPM",$J,XIEN,BPMFR,"")),XIENS=$G(^TMP("BPM",$J,XIEN,BPMFR,BPMTO))
 . D GETXLR
 . ; QUIT IF FROM PATIENT DID NOT HAVE LAB DATA
 . Q:'$D(BLROLD)
 . S BPMTO=$$LAST^BPMXFIX(BPMFR)
 . S (BLRFM,XDRMRG("FR"))=BPMFR,(BLRTO,XDRMRG("TO"))=BPMTO
 . S BLRNEW=+$G(^DPT(BLRTO,"LR"))
 . Q:'BLROLD&'BLRNEW
 . ; CORRECT FIELD IF TO PATIENT DID NOT HAVE LAB DATA
 . I BLROLD=BLRNEW D  Q
 . . Q:$P(^LR(BLROLD,0),"^",3)=BLRTO
 . . D HDR^BPMXFIX(BLRTO,DUZ(2),BLROLD,,"Lab Node")
 . . S DIE="^LR("
 . . S DA=BLROLD
 . . S DR=".03////"_BLRTO
 . . D ^DIE
 . . S BPMCNT1=BPMCNT1+1
 . Q:'$D(^LR(BLROLD,0))
 . ;IHS/OIT/NKD BPM*1.0*2 STORE VALUES OF "AC" X-REF
 . I $D(^LRO(68,"AC",BLROLD)) K ^TMP("BPM-LR",$J) M ^TMP("BPM-LR",$J,68,"AC",BLROLD)=^LRO(68,"AC",BLROLD)
 . ;
 . D HDR^BPMXFIX(BLRTO,DUZ(2),BLROLD,,"Lab Node")
 . D MERGE^BLRMERG
 . ;IHS/OIT/NKD BPM*1.0*2 RESTORE VALUES OF "AC" X-REF
 . I $D(^TMP("BPM-LR",$J))  D
 . . S I=0
 . . F  S I=$O(^LRO(68,"AC",BLRNEW,I)) Q:+I'=I  D
 . . . S J=0
 . . . F  S J=$O(^LRO(68,"AC",BLRNEW,I,J)) Q:+J'=J  D
 . . . . ; QUIT IF X-REF HAS A VALUE
 . . . . Q:$L(^LRO(68,"AC",BLRNEW,I,J))>0
 . . . . ; QUIT IF X-REF DID NOT COME FROM BLROLD
 . . . . Q:'$D(^TMP("BPM-LR",$J,68,"AC",BLROLD,I,J))
 . . . . S ^LRO(68,"AC",BLRNEW,I,J)=$G(^TMP("BPM-LR",$J,68,"AC",BLROLD,I,J))
 . . K ^TMP("BPM-LR",$J)
 . ;Repoint ^LR("BLRA") ESIG xref in Lab Data file #63
 . D EN^BPMXLR2(BLRFM,BLRTO)
 . S BPMCNT2=BPMCNT2+1
 D RSLT^BPMXFIX("  *** Repoint Total Found: "_BPMCNT1_" ***")
 D RSLT^BPMXFIX("  *** Merge Total Found: "_BPMCNT2_" ***")
 ;
 Q
 ;
MPI ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 RESEND A40 MESSAGES FOR MPI
 ;
 N X
 S X="AGMPIHLO" X ^%ZOSF("TEST") Q:'$T
 N XIEN
 ;
 S XIEN=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . N BPMFR,BPMTO,SUCCESS
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),BPMTO=$O(^TMP("BPM",$J,XIEN,BPMFR,""))
 . D CREATMSG^AGMPIHLO(BPMTO,"A40",BPMFR,.SUCCESS)
 . I SUCCESS D HDR^BPMXFIX(BPMTO,DUZ(2),BPMFR,,"From Patient IEN")
 . E  D RSLT^BPMXFIX($J("",2)_"MPI A40 MESSAGE FAILED: "_BPMFR_" -> "_BPMTO)
 Q
 ;
PRB ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX PROBLEM LIST ENTRIES
 ;
 N BPMTO,BPMFR,BPMF,BPMS,BPMI,BPMN,BPMNS,BPMCNT,BPMHDR
 S (BPMTO,BPMCNT)=0
 F  S BPMTO=$O(^TMP("BPM",$J,"TO",BPMTO)) Q:+BPMTO'=BPMTO  D
 . Q:BPMTO'=$$LAST^BPMXFIX(BPMTO)
 . Q:'$D(^AUPNPROB("AA",BPMTO))
 . S BPMF=0
 . F  S BPMF=$O(^AUPNPROB("AA",BPMTO,BPMF)) Q:+BPMF'=BPMF  D
 . . S BPMS="",BPMHDR=1
 . . F  S BPMS=$O(^AUPNPROB("AA",BPMTO,BPMF,BPMS)) Q:$L(BPMS)<1  D
 . . . S BPMI=$O(^AUPNPROB("AA",BPMTO,BPMF,BPMS,""))
 . . . F  S BPMN=$O(^AUPNPROB("AA",BPMTO,BPMF,BPMS,BPMI)) Q:$L(BPMN)<1  D
 . . . . N BPMOS
 . . . . S BPMNS=$$NEXT^BPMXPRB(BPMTO,$$GET1^DIQ(9000011,BPMN,.06,"I")),BPMOS=$$GET1^DIQ(9000011,BPMN,.07,"I")
 . . . . I BPMHDR D HDR^BPMXFIX(BPMTO,BPMF) S BPMHDR=0
 . . . . D RSLT^BPMXFIX($J("",4)_"Duplicate Sequence: "_BPMOS_$J("",6-$L(BPMOS))_" New Sequence: "_BPMNS)
 . . . . N FDA
 . . . . S FDA(9000011,BPMN_",",.07)=BPMNS ; NMBR (.07)
 . . . . D UPDATE^DIE(,"FDA",)
 . . . . ; UPDATE MODIFIED X-REF
 . . . . K ^AUPNPROB("MODIFIED",BPMTO)
 . . . . S ^AUPNPROB("MODIFIED",BPMTO,$$NOW^XLFDT())=""
 . . . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 ; REMOVE MODIFIED X-REF ON ALL FROM PATIENTS
 S BPMFR=0
 F  S BPMFR=$O(^TMP("BPM",$J,"FROM",BPMFR)) Q:+BPMFR'=BPMFR  D
 . K ^AUPNPROB("MODIFIED",BPMFR)
 Q
 ;
VST ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX DELETED VISIT ENTRIES
 ;
 Q:$$GET1^DIQ(15.1,2,99999.01)'="YES"
 ;
 N BPMD0,BPMCNT
 S (BPMCNT,BPMD0)=0
 F  S BPMD0=$O(^AUPNVSIT(BPMD0)) Q:'BPMD0  D
 . Q:$P(^AUPNVSIT(BPMD0,0),U,11)'=1            ;skip if not a deleted visit
 . Q:+$P($G(^AUPNVSIT(BPMD0,0)),U,5)'=$P($G(^AUPNVSIT(BPMD0,0)),U,5)
 . Q:'$D(^TMP("BPM",$J,"FROM",$P($G(^AUPNVSIT(BPMD0,0)),U,5)))
 . S $P(^AUPNVSIT(BPMD0,0),U,5)=$$LAST^BPMXFIX($P($G(^AUPNVSIT(BPMD0,0)),U,5))
 . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 ;
 Q
 ;
GETXLR ;
 N XCNT,XDIEN,I,J,X,XFIL,XNOD
 F XCNT=1:1:$L(XIENS,"^") D
 . S XDIEN=$P(XIENS,"^",XCNT)
 . S XFIL=0
 . ; FIND THE MERGE IMAGE FILE
 . F  S XFIL=$O(^XDRM(XDIEN,1,XFIL)) Q:+XFIL'=XFIL  D
 . . Q:$P(^XDRM(XDIEN,1,XFIL,0),"^",1)'="VA PATIENT"
 . . S XNOD=0
 . . ; ITERATE THROUGH MERGE IMAGE NODES
 . . F  S XNOD=$O(^XDRM(XDIEN,1,XFIL,1,XNOD)) Q:+XNOD'=XNOD  D
 . . . Q:$G(^XDRM(XDIEN,1,XFIL,1,XNOD,0))'=("DPT("_BPMFR_",""LR"")")
 . . . ; SET BLROLD
 . . . S BLROLD=+$G(^XDRM(XDIEN,1,XFIL,1,XNOD,1))
 Q