IBCEP82 ;ALB/CLT, Special cross references and data entry for fields in file 355.93 ; 14 Apr 2006  9:41 AM
 ;;2.0;INTEGRATED BILLING;**343,374**;21-MAR-94;Build 16
 ;
 ; Call at tags only
 Q
 ;This routine will ask for the NPI, check for duplicate entries, and check for proper
 ;format using the double-add-double formula.  If the NPI is being deleted it will ask
 ;the user why it is being deleted.
 ;If it is being deleted because of an erroneous entry it will be completely deleted.
 ;If it is a valid NPI being deleted because of possible inappropriate usage it will be
 ;maintained in the history cross reference to preclude anyone from using this NPI again.
 ;
EN ;Routine primary entry point
 N DTOUT,DUOUT,DIR,DIE,DIC,DR,X,Y
 N IBIEN,IBNPI,IBCHECK,IBOLDNPI,IBRBNPI,IBRB
 S IBIEN=DA,IBOLDNPI=""
EN1 ;
 K DIR
 S DIR(0)="FO^10:10",DIR("A")="NPI",DIR("?")="Enter a 10 digit National Provider Identifier"
 I $G(DA) S:$P($G(^IBA(355.93,DA,0)),U,14)'="" (DIR("B"),IBOLDNPI)=$P($G(^IBA(355.93,DA,0)),U,14)
 D ^DIR S IBCHECK=0
 I X="^" W *7,!,"   EXIT NOT ALLOWED ??" G EN1
 I $E(X)="^" W *7,!,"   JUMPING NOT ALLOWED ??" G EN1
 I X="@" G:IBOLDNPI'="" DEL W *7,"??" G EN1
 I $G(DUOUT)!$G(DTOUT)!(X="")!(Y=IBOLDNPI) G XIT
 S IBNPI=Y
 I '$$CHKDGT^XUSNPI(IBNPI) W !,*7,"Not a valid NPI.  Please try again.",! G EN1
 I $$NPIUSED^IBCEP81(IBNPI) G EN1
 S IBCHECK=1
 I IBOLDNPI="" D ACTI
 I IBOLDNPI'="" D:IBNPI'=IBOLDNPI INACT
 S $P(^IBA(355.93,IBIEN,0),U,14)=IBNPI,^IBA(355.93,"NPI",IBNPI,IBIEN)="",^IBA(355.93,"NPIHISTORY",IBNPI,IBIEN)=""
 G XIT
 ;
ACTI ;CREATE AN ACTIVATED ENTRY IN MULTIPLE NPISTATUS FIELD
 S DA(1)=IBIEN,DIC="^IBA(355.93,"_DA(1)_",""NPISTATUS"",",DIC(0)="L",X=$$NOW^XLFDT()
 S DIC("DR")=".02////^S X=1;.03////^S X=IBNPI;.04////^S X=DUZ"
 D FILE^DICN
 S $P(^IBA(355.93,IBIEN,0),U,14)=IBNPI
 Q
 ;
DEL ;NPI HAS BEEN DELETED
 ;If the user deletes the NPI this subroutine will determine why it was deleted and if it was because it was found
 ;in a false identity situation will mark it in history to never be used again.
 S IBNPI=DIR("B")
 K DIR
 S DIR(0)="Y"
 S DIR("A")="Are you sure you wish to delete this NPI"
 S DIR("?")="You have indicated you wish to delete the NPI.  This is a second chance check."
 D ^DIR
 G:Y(0)="NO" XIT
 S DIR(0)="S^E:ERROR;V:VALID",DIR("A")="Was this a Valid NPI or an NPI entered in Error"
 S DIR("?",1)="An example of an NPI entered in error is if the entry person transposed numbers,"
 S DIR("?",2)="or if the NPI for one provider is accidentally assigned to a different provider."
 S DIR("?")="Enter an 'E' for Error or a 'V' for Valid."
 D ^DIR
 I Y="E" D COMP W !,"The NPI has been deleted.",!
 I Y="V" S IBCHECK=2 D INACT W !,"The NPI is now inactive.",!
 Q
 ;
COMP ;COMPLETELY DELETE THE NPI
 ;This subroutine will delete the NPI from the file 355.93.
 S OIEN=$O(^IBA(355.93,IBIEN,"NPISTATUS","C",IBOLDNPI,"A"),-1)
 D DELNPI(IBIEN,OIEN)
 K ^IBA(355.93,"NPI",IBOLDNPI,DA),^IBA(355.93,"NPIHISTORY",IBOLDNPI,DA)
 S IBRB=0
 D  ; Find the most recent status '0' (inactive) NPI entry in the list.
 . N IBRBLST,IBRBTMP
 . ; Don't want to roll back to the same number you are deleting.
 . S IBRBLST(IBOLDNPI)=""
 . S IBRBTMP="A"
 . ; Go through each entry in reverse order
 . F  S IBRBTMP=$O(^IBA(355.93,IBIEN,"NPISTATUS",IBRBTMP),-1) Q:'IBRBTMP  D  Q:IBRB'=0
 .. S IBRBLST=^IBA(355.93,IBIEN,"NPISTATUS",IBRBTMP,0)
 .. ; If this is an 'active' entry then ignore it.
 .. I $P(IBRBLST,U,2)=1 Q
 .. ; If this entry does not have an NPI then ignore it.
 .. I $P(IBRBLST,U,3)="" Q
 .. ;If this is an inactive entry then report it.
 .. I $P(IBRBLST,U,2)=0 S IBRB=IBRBTMP Q
 .. Q
 . Q
 I IBRB>0 D ROLLBACK
 Q
 ;
DELNPI(IEN,OIEN) ;DELETE-INVALID removes NPI from file.
 NEW DIE,DIK,DIC,DA,DR,D,D0,DI,DIC,DQ,X
 NEW DP,DM,DK,DL,DIEL
 S DIE="^IBA(355.93,",DA=IEN,DR="41.01////@"
 D ^DIE
 S DA(1)=IEN,DIK="^IBA(355.93,"_DA(1)_",""NPISTATUS"",",DA=OIEN
 D ^DIK
 Q
 ;
INACT ;INACTIVATE AN ENTRY
 ;This subroutine makes two entries in the NPI multiple field.
 ;One for the deactivation of the old NPI and the second
 ;for the activation of a new NPI.
 S DA(1)=IBIEN,DIC="^IBA(355.93,"_DA(1)_",""NPISTATUS"",",DIC(0)="L",X=$$NOW^XLFDT()
 S DIC("DR")=".02////^S X=0;.03////^S X=IBOLDNPI;.04////^S X=DUZ"
 D FILE^DICN
 S ^IBA(355.93,"NPIHISTORY",IBOLDNPI,DA(1))=""
 K ^IBA(355.93,"NPI",IBOLDNPI,DA(1))
 S $P(^IBA(355.93,IBIEN,0),U,14)=""
 I $G(IBCHECK)<2 D ACTI
 S ^IBA(355.93,"NPIHISTORY",IBNPI,DA(1))=""
 Q
 ;
ROLLBACK ;Rollback or delete NPI
 S IBRBNPI=$P(^IBA(355.93,IBIEN,"NPISTATUS",IBRB,0),U,3)
 NEW DIE,DIK,DIC,DA,DR,D,D0,DI,DIC,DQ,X
 NEW DP,DM,DK,DL,DIEL
 S DA(1)=IBIEN,DIK="^IBA(355.93,"_DA(1)_",""NPISTATUS"",",DA=IBRB
 D ^DIK
 S $P(^IBA(355.93,IBIEN,0),U,14)=IBRBNPI,^IBA(355.93,"NPI",IBRBNPI,IBIEN)=""
 Q
 ;
XIT ;CLEAN AND EXIT
 Q
 ;
XR ;Set the primary taxonomy code cross reference for field 42
 N ATAX S ATAX=""
 I $D(^IBA(355.93,DA(1),"TAXONOMY","D")) D:X=1
 . F  S ATAX=$O(^IBA(355.93,DA(1),"TAXONOMY","D",1,ATAX)) Q:ATAX=""  D
 .. K ^IBA(355.93,DA(1),"TAXONOMY","D",1,ATAX)
 .. I ATAX'=DA S $P(^IBA(355.93,DA(1),"TAXONOMY",ATAX,0),U,2)=0,^IBA(355.93,DA(1),"TAXONOMY","D",0,ATAX)=""
 S ^IBA(355.93,DA(1),"TAXONOMY","D",X,DA)=""
 Q
 ;
KXR ;Kill primary taxonomy code cross reference for field 42
 N K
 F K=0,1 K ^IBA(355.93,DA(1),"TAXONOMY","D",K,DA)
 Q
