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

AUM15DU.m

Go to the documentation of this file.
AUM15DU ;IHS/OIT/NKD - DUPLICATE ICD9 UTILITY 09/09/14 ; 
 ;;15.0;TABLE MAINTENANCE;;SEP 09,2014;Build 1
 ;
 Q
MAIN ; EP - FIND DUPLICATE ICD9 ENTRIES AND MERGE AS AN ARRAY
 N ID
 S ID=$NA(^XTMP("AUM",$$NOW^XLFDT))
 D SEARCH(ID)
 I $G(@ID@("COUNT")) D STAGE1(ID),STAGE2(ID),STAGE3(ID)
 Q
 N CNT,CNT2,RES
 K @ID S @ID@("COUNT")=0
 ; CREATE LIST
 S CNT=" " F  S CNT=$O(^ICD9("AB",CNT)) Q:CNT']""  D
 . S RES="",CNT2=0 F  S CNT2=$O(^ICD9("AB",CNT,CNT2)) Q:'CNT2  S RES=RES_CNT2_U  ; HIGH -> LOW
 . I CNT["." S CNT2=0 F  S CNT2=$O(^ICD9("AB",$TR(CNT,"."),CNT2)) Q:'CNT2  S RES=RES_CNT2_U  ; ADD ANY MATCHES W/O . FORMAT
 . S:$E(RES,$L(RES))=U RES=$E(RES,1,$L(RES)-1)
 . Q:$L(RES,U)'>1
 . S @ID@("COUNT")=+$G(@ID@("COUNT"))+1
 . Q:ID["SCAN"
 . S @ID@("DUP",$P(RES,U,2),$P(RES,U,1),$P(RES,U,2)_";ICD9(",$P(RES,U,1)_";ICD9(")=""
 . S:CNT["." ^TMP("AUM",$J,"DUP",CNT)=$P(RES,U)
 Q:ID["SCAN"
 I '$G(@ID@("COUNT")) D RSLT^AUM15("  Searching for duplicates..."_$J("",3)_"No duplicates found!") Q
 D RSLT^AUM15("  Searching for duplicates..."_$J("",3)_$G(@ID@("COUNT"))_" found: XDR REPOINTED ENTRY (#15.3)")
 Q
STAGE1(ID) ; PRE-MERGE
 N CNT
 S @ID@("BPM")=$$GET^XPAR("PKG","BPM USE IHS LOGIC")
 I $G(@ID@("BPM")) D CHG^XPAR("PKG","BPM USE IHS LOGIC",,0)
 S @ID@("XDRM-BEFORE")=+$O(^XDRM("@"),-1)
 S CNT=0 F  S CNT=$O(^PXD(811.3,CNT)) Q:'CNT  D
 . Q:'$D(^PXD(811.3,CNT,80))
 . Q:$G(^PXD(811.3,CNT,80,0))]""
 . S ^PXD(811.3,CNT,80,0)="^811.31PA^^"
 D RSLT^AUM15("  Pre-Merge Stage..."_$J("",12)_"Complete")
 Q
STAGE2(ID) ; MERGE
 N XDRTIME
 S (@ID@("START"),XDRTIME)=$H
 D RSLT^AUM15("  Merge started: "_$J("",15)_$$HTE^XLFDT($G(@ID@("START"))),1)
 I $$VERSION^XPDUTL("ABM")=2.6 D MRGD2D($NA(@ID@("DUP")),9002274.3,"^ABMDCLM(","^ABMDCLM(")
 I $$VERSION^XPDUTL("ABM")=2.6 D MRGD2D($NA(@ID@("DUP")),9002274.4,"^ABMDBILL(","^ABMDBILL(")
 D EN^XDRMERG(80,$NA(@ID@("DUP")))
 S @ID@("STOP")=$H
 D RSLT^AUM15("  Merge completed: "_$J("",13)_$$HTE^XLFDT($G(@ID@("STOP"))))
 D RSLT^AUM15("  Elapsed time: "_$J("",16)_$$HDIFF^XLFDT($G(@ID@("STOP")),$G(@ID@("START")),3))
 Q
STAGE3(ID) ; POST-MERGE
 N CNT,CNT2
 I $G(@ID@("BPM")) D CHG^XPAR("PKG","BPM USE IHS LOGIC",,$G(@ID@("BPM")))
 S @ID@("XDRM-AFTER")=+$O(^XDRM("@"),-1)
 D RSLT^AUM15("  Post-Merge Stage..."_$J("",11)_"Complete",1)
 S CNT=$G(@ID@("XDRM-BEFORE")),CNT2=$G(@ID@("XDRM-AFTER"))
 I CNT2>CNT D RSLT^AUM15("  Details stored in MERGE IMAGES (#15.4): IEN "_(CNT+1)_"-"_CNT2)
 Q
MRGD2D(FROM,FILEI,XVAL,XR) ; MERGE 3PB DUZ(2) AND DINUM ENTRIES - CODE BASE FROM DINUM^XDRMERG2
 N IENOLD,IENNEW,XDUZO,XDUZ,XDA,XDA2,XVAL1,XPC
 S XDUZO=DUZ(2)
 S XDUZ=0 F  S XDUZ=$O(@(XVAL_XDUZ_")")) Q:'XDUZ  D  ; LOOP THROUGH DUZ2 (XDUZ)
 . S DUZ(2)=XDUZ,XDA=0 F  S XDA=$O(@(XVAL_XDUZ_","_XDA_")")) Q:'XDA  D  ; LOOP THROUGH ENTRIES (XDA)
 . . S XVAL1=XVAL_XDUZ_","_XDA_",5)" I $D(@XVAL1) D  ;ADMITTING DIAGNOSIS (#.59)
 . . . S IENOLD=$P($G(@XVAL1),U,9),IENNEW=$S(+IENOLD:$O(@FROM@(IENOLD,0)),1:0)
 . . . I IENNEW S $P(@XVAL1,U,9)=IENNEW I FILEI=9002274.3 K @(XVAL_XDUZ_",""AINP"","_IENOLD_","_XDA_")") S @(XVAL_XDUZ_",""AINP"","_IENNEW_","_XDA_")")=""
 . . S XVAL1=XVAL_XDUZ_","_XDA_",8)" I $D(@XVAL1) F XPC=12,19,20 D  ;E-CODE (#.857-#.859)
 . . . S IENOLD=$P($G(@XVAL1),U,XPC),IENNEW=$S(+IENOLD:$O(@FROM@(IENOLD,0)),1:0)
 . . . S:IENNEW $P(@XVAL1,U,XPC)=IENNEW
 . . S XVAL1=XVAL_XDUZ_","_XDA_",17,",XDA2=0 F  S XDA2=$O(@(XVAL1_XDA2_")")) Q:'XDA2  D
 . . . S IENOLD=$P($G(@(XVAL1_XDA2_",0)")),U,4),IENNEW=$S(+IENOLD:$O(@FROM@(IENOLD,0)),1:0)  ;E-CODE (#.04)
 . . . S:IENNEW $P(@(XVAL1_XDA2_",0)"),U,4)=IENNEW
 . . . S IENOLD=XDA2,IENNEW=$O(@FROM@(XDA2,0)) Q:'IENNEW  ;DINUM-ED SUBFILES
 . . . I '$D(@(XVAL1_IENNEW_",0)")) D ^XBFMK S DIC=XVAL1,DIC(0)="L",X=IENNEW,DINUM=IENNEW D FILE^DICN
 . . . D MERGEIT(XVAL1,IENOLD,IENNEW,FILEI+.0017,XDA_",")
 S DUZ(2)=XDUZO
 Q
MERGEIT(XDRDIC,IENFROM,IENTO,FILEI,XDRIENS) ; MERGE TWO ENTRIES IN FILE - CODE BASE FROM MERGEIT^XDRMERGB
 N NODE,NODE1,NODE2,XDRXX,DIK,DA,I,Y,XFILNO,IENTOSTR,XDRZZ
 N XDRAA ; DEBUG STATEMENT
 ;
 S:+$G(FILEI)&(+$P(@(XDRDIC_"0)"),U,2)'=$G(FILEI)) $P(@(XDRDIC_"0)"),U,2)=$G(FILEI)_"P"
 S XFILNO=+$P(@(XDRDIC_"0)"),U,2)
 S IENTOSTR=IENTO_","_XDRIENS
 ;
 S NODE=""
 F  D  Q:NODE=""
 . S NODE1=$O(@(XDRDIC_IENFROM_","""_NODE_""")"))
 . I NODE1="" S NODE="" Q  ; NOTHING MORE TO MOVE OVER
 . S NODE2=$O(@(XDRDIC_IENTO_","""_NODE_""")"))
 . I NODE2'="",NODE1]NODE2 S NODE=NODE2 Q  ; NODE ON TO, BUT NOT ON FROM - GO TO NEXT
 . S NODE=NODE1
 . I $D(@(XDRDIC_IENFROM_","""_NODE_""")"))=1 D  Q  ; SINGLE NODE, MERGE DATA
 . . I NODE2]NODE1!(NODE2="") D  Q  ;  MISSING NODE, JUST MOVE IT OVER
 . . . N XDRXX,FLD,N,J
 . . . F N=0:0 S N=$O(^DD(XFILNO,"GL",NODE,N)) Q:N'>0  S FLD=$O(^(N,0)) I $O(^DD(XFILNO,FLD,1,0))>0 D
 . . . . S X=0 F J=0:0 S J=$O(^DD(XFILNO,FLD,1,J)) Q:J'>0  I $O(^(J,0))>0 S X=1 Q
 . . . . I X>0 D
 . . . . . S XDRXX(XFILNO,IENTOSTR,FLD)=$P(@(XDRDIC_IENFROM_","""_NODE_""")"),U,N)
 . . . K XDRAA I $D(XDRTESTK),$D(XDRXX) M XDRAA=XDRXX ; DEBUG STATEMENT
 . . . K XDRZZ
 . . . I $D(XDRXX) D FILE^DIE("","XDRXX","XDRZZ")
 . . . I $D(XDRTESTK),$D(XDRZZ) S XDRTESTK=XDRTESTK+1 M ^XTMP("XDRTESTK",$$NOW^XLFDT(),XDRTESTK,"XX")=XDRAA,^("ZZ")=XDRZZ ; DEBUG STATMENT
 . . . M @(XDRDIC_IENTO_","""_NODE_""")")=@(XDRDIC_IENFROM_","""_NODE_""")")
 . . I $D(@(XDRDIC_IENTO_","""_NODE_""")"))>1 Q  ; MISMATCH SO QUIT
 . . N XDRXX,FLD
 . . S X1=@(XDRDIC_IENFROM_","""_NODE_""")")
 . . S (X2,X3)=@(XDRDIC_IENTO_","""_NODE_""")")
 . . F I=1:1 Q:X1=""  S X=$P(X1,U),X1=$P(X1,U,2,999) I X'="" D
 . . . S Y=$P(X2,U,I)
 . . . I Y=""  D
 . . . . S $P(X2,U,I)=X
 . . . . S FLD=$O(^DD(XFILNO,"GL",NODE,I,0)) S JXFLD=FLD
 . . . . I FLD>0,$O(^DD(XFILNO,FLD,1,0))>0 S XDRXX(XFILNO,IENTOSTR,FLD)=X
 . . I X2'=X3 D
 . . . I $D(XDRXX) D
 . . . . K XDRAA I $D(XDRTESTK) M XDRAA=XDRXX ; DEBUG STATEMENT
 . . . . K XDRZZ
 . . . . N X2 D FILE^DIE("","XDRXX","XDRZZ")
 . . . . I $D(XDRTESTK),$D(XDRZZ) S XDRTESTK=XDRTESTK+1 M ^XTMP("XDRTESTK",$$NOW^XLFDT(),XDRTESTK,"XX")=XDRAA,^("ZZ")=XDRZZ ; DEBUG STATMENT
 . . . S @(XDRDIC_IENTO_","""_NODE_""")")=X2 ; SET MERGED DATA ON NODE
 S XDRXX=$P(@(XDRDIC_IENFROM_",0)"),U)
 K DA N DIU S DIU(0)=1 S DIK=XDRDIC,DA=IENFROM,DA(1)=$P(XDRIENS,",") D ^DIK ; KILL OFF MERGED FROM ENTRY
 Q