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

BPMXFX2.m

Go to the documentation of this file.
BPMXFX2 ;IHS/OIT/NKD - CLEANUP UTILITY - SPLIT INTO MULTIPLE ROUTINES - 6/26/12 ;
 ;;1.0;IHS PATIENT MERGE;**2**;MAR 01, 2010;Build 1
 ;
 Q
WP ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX WORD PROCESSING FIELD ENTRIES
 ;
 N BPMTO,BPMCNT,BPMCNT2,BPMCNT3,I,J,X,D1,XIEN,XFLD,XGLFR,XDFR,XGLTO,XGL0,XDTO,XCNT
 N ABSPE,AMHPINTK,AUPNPAT,BATREG,BIP,BWP,PS,SCPT
 ;
 S XIEN="FROM"
 F  S XIEN=$O(^TMP("BPM",$J,XIEN),-1) Q:+XIEN'=XIEN  D
 . N BPMFR,BPMTO,XIENS,ABSPE,AMHPINTK,AUPNPAT,BATREG,BIP,BWP,PS,SCPT
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),BPMTO=$O(^TMP("BPM",$J,XIEN,BPMFR,"")),XIENS=$G(^TMP("BPM",$J,XIEN,BPMFR,BPMTO)),BPMCNT=0
 . D GETXWP
 . ; ITERATE THROUGH WP FIELDS
 . F I=1:1 S X=$P($T(WPFLDS+I),";;",2) Q:X["$$END"  D
 . . ; ITERATE THROUGH WP SUBSCRIPTS
 . . F J=1:1 S XFLD=$P($P(X,";",3),"^",J) Q:$L(XFLD)<1  D
 . . . S XGLFR=$P(X,";",2)_BPMFR_","_XFLD,XGL0="^"_$P(X,";",2),XGLTO=XGL0_$$LAST^BPMXFIX(BPMFR)_","_XFLD
 . . . ; QUIT IF FROM PATIENT DID NOT HAVE DATA
 . . . Q:'$D(@(XGLFR_")"))
 . . . ; CONCAT WP ARRAYS INTO A STRING
 . . . S XCNT=0,XDFR=""
 . . . F  S XCNT=$O(@(XGLFR_")")@(XCNT)) Q:'XCNT  S XDFR=XDFR_" "_@(XGLFR_","_XCNT_",0)")
 . . . S XCNT=0,XDTO=""
 . . . F  S XCNT=$O(@(XGLTO_")")@(XCNT)) Q:'XCNT  S XDTO=XDTO_" "_@(XGLTO_","_XCNT_",0)")
 . . . ; CHECK IF THE FROM WP FIELD WAS ALREADY MERGED
 . . . Q:XDTO[XDFR
 . . . S D1=+$P($G(@(XGLTO_",0)")),U,3)
 . . . ;D RSLT^BPMXFIX($J("",2)_"Appending to: "_XGLTO)
 . . . ; APPEND TO THE TO PATIENT
 . . . S XCNT=0
 . . . F  S XCNT=$O(@(XGLFR_")")@(XCNT)) Q:'XCNT  D
 . . . . S D1=D1+1
 . . . . S @(XGLTO_","_D1_",0)")=@(XGLFR_","_XCNT_",0)")
 . . . . S $P(@(XGLTO_",0)"),U,3,5)=D1_U_D1_U_$$DT^XLFDT()
 . . . S BPMCNT=BPMCNT+1
 . I BPMCNT D HDR^BPMXFIX($$LAST^BPMXFIX(BPMFR),DUZ(2)),RSLT^BPMXFIX("  *** FROM Patient IEN: "_BPMFR_" Total Found: "_BPMCNT_" ***")
 ;
 S BPMTO=0
 F  S BPMTO=$O(^TMP("BPM",$J,"TO",BPMTO)) Q:+BPMTO'=BPMTO  D
 . Q:$$LAST^BPMXFIX(BPMTO)'=BPMTO
 . S (BPMCNT2,BPMCNT3)=0
 . ; ITERATE THROUGH WP FIELDS
 . F I=1:1 S X=$P($T(WPFLDS+I),";;",2) Q:X["$$END"  D
 . . ; ITERATE THROUGH WP SUBSCRIPTS
 . . F J=1:1 S XFLD=$P($P(X,";",3),"^",J) Q:$L(XFLD)<1  D
 . . . S XGL0="^"_$P(X,";",2),XGLTO=XGL0_BPMTO_","_XFLD
 . . . Q:'$D(@(XGLTO_",0)"))
 . . . ; CREATE ENTRY IN PARENT FILE IF IT DOESN'T EXIST
 . . . I '$D(@(XGL0_BPMTO_",0)")) D  Q
 . . . . ;D RSLT^BPMXFIX($J("",2)_"Creating parent ("_$P(X,";",1)_") entry")
 . . . . N ORIEN,FDA,ERR
 . . . . S ORIEN(1)=BPMTO
 . . . . S FDA($P(X,";",4),"+1,",.01)=BPMTO
 . . . . D UPDATE^DIE(,"FDA","ORIEN","ERR")
 . . . . I $D(ERR) D RSLT^BPMXFIX($J("",4)_"ADD FAILED!") Q
 . . . . S BPMCNT2=BPMCNT2+1
 . . . ; CORRECT .01 FIELD IN PARENT FILE ENTRY
 . . . I $P(@(XGL0_BPMTO_",0)"),"^",1)'=BPMTO D
 . . . . ;D RSLT^BPMXFIX($J("",2)_"Correcting parent ("_$P(X,";",1)_") entry: "_$G(@(XGL0_BPMTO_",0)")))
 . . . . N FDA
 . . . . S FDA($P(X,";",4),BPMTO_",",.01)=BPMTO
 . . . . D UPDATE^DIE(,"FDA",)
 . . . . S BPMCNT3=BPMCNT3+1
 . I BPMCNT2+BPMCNT3>0 D RSLT^BPMXFIX(""),HDR^BPMXFIX($$LAST^BPMXFIX(BPMTO),DUZ(2))
 . I BPMCNT2 D RSLT^BPMXFIX("  *** Missing Parent Entry Total Found: "_BPMCNT2_" ***")
 . I BPMCNT3 D RSLT^BPMXFIX("  *** Incorrect Parent Entry Total Found: "_BPMCNT3_" ***")
 ;
 Q
 ;
I1 ;EP
 ;----- REPOINT 'ACCOUNT' FIELD #.01 OF THE 'A/R ACCOUNTS/IHS' 
 ;      FILE #90050.02
 ;
 N BPMD0,BPMDUZ2,BPMPTR,DA,X,XIEN,BPMFR,BPMCNT,BPMHDR
 ;
 S BPMDUZ2=$G(DUZ(2)),(XIEN,BPMCNT)=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),X=BPMFR_";AUPNPAT(",DUZ(2)=0
 . F  S DUZ(2)=$O(^BARAC(DUZ(2))) Q:'DUZ(2)  D
 . . S BPMD0=0,BPMHDR=1
 . . F  S BPMD0=$O(^BARAC(DUZ(2),"B",X,BPMD0)) Q:'BPMD0  D
 . . . N X
 . . . S BPMPTR=$P($G(^BARAC(DUZ(2),BPMD0,0)),U)
 . . . Q:+BPMPTR'=BPMFR
 . . . Q:$P(BPMPTR,";",2)'="AUPNPAT("
 . . . D HDR^BPMXFIX($$LAST^BPMXFIX(BPMFR),DUZ(2),BPMD0,BPMHDR)
 . . . S BPMHDR=0
 . . . S $P(^BARAC(DUZ(2),BPMD0,0),U)=$$LAST^BPMXFIX(BPMFR)_";AUPNPAT("
 . . . S DA=BPMD0,X=BPMFR_";AUPNPAT("
 . . . X ^DD(90050.02,.01,1,1,2),^DD(90050.02,.01,1,2,2)
 . . . S X=$$LAST^BPMXFIX(BPMFR)_";AUPNPAT("
 . . . X ^DD(90050.02,.01,1,1,1),^DD(90050.02,.01,1,2,1)
 . . . S BPMCNT=BPMCNT+1
 I BPMDUZ2 S DUZ(2)=BPMDUZ2    ;resetting DUZ(2) back to original value
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 Q
 ;
I2 ;EP
 ; ----- REPOINT "GUARANTOR" FIELD (#.01) UNDER GUARANTOR SUBFIELD (#101)
 ;         IN GUARANTOR FILE (#9000043)
 ;
 N BPMD0,BPMD1,BPMPTR,DA,X,XIEN,BPMFR,BPMCNT,BPMHDR
 ;
 S (XIEN,BPMCNT)=0
 F  S XIEN=$O(^TMP("BPM",$J,XIEN)) Q:+XIEN'=XIEN  D
 . S BPMFR=$O(^TMP("BPM",$J,XIEN,"")),X=BPMFR_";AUPNPAT(",BPMD0=0,BPMHDR=1
 . F  S BPMD0=$O(^AUPNGUAR("C",X,BPMD0)) Q:'BPMD0  D
 . . S BPMD1=0
 . . F  S BPMD1=$O(^AUPNGUAR("C",X,BPMD0,BPMD1)) Q:'BPMD1  D
 . . . N X
 . . . S BPMPTR=$P($G(^AUPNGUAR(BPMD0,1,BPMD1,0)),U)
 . . . Q:+BPMPTR'=BPMFR
 . . . Q:$P(BPMPTR,";",2)'="AUPNPAT("
 . . . D HDR^BPMXFIX($$LAST^BPMXFIX(BPMFR),DUZ(2),BPMD0_","_BPMD1,BPMHDR)
 . . . S BPMHDR=0
 . . . S $P(^AUPNGUAR(BPMD0,1,BPMD1,0),U)=$$LAST^BPMXFIX(BPMFR)_";AUPNPAT("
 . . . S DA(1)=BPMD0,DA=BPMD1,X=BPMFR_";AUPNPAT("
 . . . X ^DD(9000043.0101,.01,1,1,2),^DD(9000043.0101,.01,1,2,2)
 . . . S X=$$LAST^BPMXFIX(BPMFR)_";AUPNPAT("
 . . . X ^DD(9000043.0101,.01,1,1,1),^DD(9000043.0101,.01,1,2,1)
 . . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 Q
 ;
I3 ;EP
 ; ----- REPOINT DESTINATION FIELD (#.127) IN 3P CLAIM DATA FILE
 ;
 N BPMD0,BPMDUZ2,BPMPTR,BPMCNT
 ;
 S (BPMDUZ2,BPMCNT)=0
 F  S BPMDUZ2=$O(^ABMDCLM(BPMDUZ2)) Q:'BPMDUZ2  D
 . S BPMD0=0
 . F  S BPMD0=$O(^ABMDCLM(BPMDUZ2,BPMD0)) Q:'BPMD0  D
 . . S BPMPTR=$P($G(^ABMDCLM(BPMDUZ2,BPMD0,12)),U,7)
 . . Q:'$D(^TMP("BPM",$J,"FROM",+BPMPTR))
 . . Q:$P(BPMPTR,";",2)'="AUPNPAT("
 . . D HDR^BPMXFIX($$LAST^BPMXFIX(+BPMPTR),BPMDUZ2,BPMD0)
 . . S $P(^ABMDCLM(BPMDUZ2,BPMD0,12),U,7)=$$LAST^BPMXFIX(+BPMPTR)_";AUPNPAT("
 . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 Q
 ;
I4 ;EP
 ; ----- REPOINT DESTINATION FIELD (#.127) IN 3P BILL FILE
 ;
 N BPMD0,BPMDUZ2,BPMPTR,BPMCNT
 ;
 S (BPMDUZ2,BPMCNT)=0
 F  S BPMDUZ2=$O(^ABMDBILL(BPMDUZ2)) Q:'BPMDUZ2  D
 . S BPMD0=0
 . F  S BPMD0=$O(^ABMDBILL(BPMDUZ2,BPMD0)) Q:'BPMD0  D
 . . S BPMPTR=$P($G(^ABMDBILL(BPMDUZ2,BPMD0,12)),U,7)
 . . Q:'$D(^TMP("BPM",$J,"FROM",+BPMPTR))
 . . Q:$P(BPMPTR,";",2)'="AUPNPAT("
 . . D HDR^BPMXFIX($$LAST^BPMXFIX(+BPMPTR),BPMDUZ2,BPMD0)
 . . S $P(^ABMDBILL(BPMDUZ2,BPMD0,12),U,7)=$$LAST^BPMXFIX(+BPMPTR)_";AUPNPAT("
 . . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 Q
 ;
V3 ;EP
 ;----- IHS/OIT/NKD BPM*1.0*2 FIX ORDER FILE VARIABLE POINTER ENTRIES
 ;
 N BPMD0,BPMPTR,DA,DIK,BPMCNT,I
 ;
 S (BPMD0,BPMCNT)=0
 F  S BPMD0=$O(^OR(100,BPMD0)) Q:'BPMD0  D
 . S BPMPTR=$P($G(^OR(100,BPMD0,0)),U,2)
 . Q:'$D(^TMP("BPM",$J,"TO",+BPMPTR))
 . Q:$P(BPMPTR,";",2)'="DPT("
 . ;
 . F I=1:1:$L(^TMP("BPM",$J,"TO",+BPMPTR),"^")  D
 . . ;----- RESET VARIABLE POINTER -> FROM PATIENT FOR KILL LOGIC
 . . S $P(^OR(100,BPMD0,0),U,2)=$P(^TMP("BPM",$J,"TO",+BPMPTR),"^",I)_";DPT("
 . . ;
 . . ;----- EXECUTE KILL LOGIC FOR XREFS
 . . S DIK="^OR(100,",DA=BPMD0
 . . D IX2^DIK
 . ;
 . ;----- RESET VARIABLE POINTER -> TO PATIENT FOR SET LOGIC
 . S $P(^OR(100,BPMD0,0),U,2)=$$LAST^BPMXFIX(+BPMPTR)_";DPT("
 . ;
 . ;----- EXECUTE SET LOGIC FOR XREFS
 . S DIK="^OR(100,",DA=BPMD0
 . D IX1^DIK
 . S BPMCNT=BPMCNT+1
 D RSLT^BPMXFIX("  *** Total Found: "_BPMCNT_" ***")
 Q
 ;
GETXWP ;
 N XCNT,XDIEN,I,J,X,XFIL,XNOD,XFLD
 F XCNT=1:1:$L(XIENS,"^") D
 . S XDIEN=$P(XIENS,"^",XCNT)
 . ; ITERATE THROUGH WP FIELDS
 . F I=1:1 S X=$P($T(WPFLDS+I),";;",2) Q:X["$$END"  D
 . . 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)'=$P(X,";",1)
 . . . S XNOD=0
 . . . ; ITERATE THROUGH MERGE IMAGE NODES
 . . . F  S XNOD=$O(^XDRM(XDIEN,1,XFIL,1,XNOD)) Q:+XNOD'=XNOD  D
 . . . . ; ITERATE THROUGH WP SUBSCRIPTS
 . . . . F J=1:1 S XFLD=$P($P(X,";",3),"^",J) Q:$L(XFLD)<1  D
 . . . . . I $NA(@(^XDRM(XDIEN,1,XFIL,1,XNOD,0)),$S($P(X,";",2)[",":3,1:2))=($P(X,";",2)_BPMFR_","_XFLD_")") S @(^XDRM(XDIEN,1,XFIL,1,XNOD,0))=$G(^XDRM(XDIEN,1,XFIL,1,XNOD,1))
 Q
WPFLDS ;----- LIST OF WORD PROCESSING FIELDS TO BE MERGED - FILENAME;GBLROOT;SUBSCRPT^
 ;;PATIENT;AUPNPAT(;12^13^14^15^16;9000001;
 ;;ASTHMA REGISTER;BATREG(;11;90181.01;
 ;;MHSS INTAKE;AMHPINTK(;10^11^12^13^14^15^16^17^18^19^21^22^23^24^25^26^27^28^41;9002011.07;
 ;;BI PATIENT;BIP(;1;9002084;
 ;;BW PATIENT;BWP(;1;9002086;
 ;;PHARMACY PATIENT;PS(55,;5.2;55;
 ;;OUTPATIENT PROFILE;SCPT(404.41,;"C";404.41;
 ;;ABSP ELIGIBILITY;ABSPE(;"TRANS"^"RESP";9002313.7;
 ;;$$END
 ;;GMRY PATIENT I/O FILE;GMR(126,;"IN"^"IV"^"OUT";