XUSNPIX5 ;OAK_BP/CMW - NPI EXTRACT REPORT ;01-OCT-06
 ;;8.0;KERNEL;**453**; Jul 10, 1995;Build 36
 ;;Per VHA Directive 10-93-142, this routine should not be modified.
 ;
 ; NPI Extract Report Mailer routine
 ;
 ; Input parameter: XUSRTN
 ;
 ; Other relevant variables:
 ;   XUSRTN="XUSNPIX1" (current routine name, used for ^XTMP and ^TMP
 ;                         storage subscript)
 ; Storage Global:
 ;   ^XTMP("XUSNPIX1",0) = Piece 1^Piece 2^Piece 3^Piece 4^Piece 5^Piece 6
 ;      where:
 ;      Piece 1 => Purge Date - 1 year in future
 ;      Piece 2 => Create Date - Today
 ;      Piece 3 => Description
 ;      Piece 4 => Last Date Compiled
 ;      Piece 5 => $H last run start time
 ;      Piece 6 => $H last run completion time
 ;
 ;   ^XTMP("XUSNPIX1",1) = DATA
 ;               
 ;          XUSNPI => Unique NPI of entry
 ;          LDT => Last Date Run, VA Fileman Format
 ;
 Q
 ;
EMAIL(XUSRTN) ; EMAIL THE MESSAGE
 ; Add domain name if it does not exist
 N XUSFOC,DLAYGO,DA,DIC,DIE,DR,X,Y
 I '$$FIND1^DIC(4.2,,"QX","Q-NPS.VA.GOV","B") D
 . S XUSFOC=$O(^DIC(4.2,"B","FOC-AUSTIN.VA.GOV",0)) I 'XUSFOC Q
 . I XUSFOC=$O(^DIC(4.2,"B","FOC-AUSTIN.VA.GOV",""),-1) D
 . . S DIC="^DIC(4.2,",X="Q-NPS.VA.GOV",DIC(0)="L",DLAYGO=4.2 D ^DIC K DLAYGO
 . . S DIE=DIC,DA=+Y
 . . S DR="1///NS;2///^S X=XUSFOC;1.7///YES;6.2///NPS;"
 . . D ^DIE
 ;
 N XMY
 ; Send email to designated recipient for live release
 S XMY("XXX@Q-NPS.VA.GOV")=""
 ;S XMY(DUZ)="" ;use for testing - remove before live
 D ESEND
 Q
 ;
VMAIL(XUSRTN) ; Verification email
 N TMP
 S TMP=^TMP(XUSRTN,$J,1)
 K ^TMP(XUSRTN,$J)
 S ^TMP(XUSRTN,$J,1)=$P(TMP,U,1,4)
 S ^TMP(XUSRTN,$J,2)=""
 S ^TMP(XUSRTN,$J,3)="TYPE 1 : NEW PERSON FILE (#200)"
 S ^TMP(XUSRTN,$J,4)=""
 S ^TMP(XUSRTN,$J,5)="Date/Time of Extract:   "_$P(TMP,U,9)
 S ^TMP(XUSRTN,$J,6)=""
 S ^TMP(XUSRTN,$J,7)="Message number: "_MSGCNT_"  Total NPI records: "_(COUNT-2)
 S ^TMP(XUSRTN,$J,8)=""
 S ^TMP(XUSRTN,$J,9)="Programmer Notes:   "_XUSVER_" - "_$P(TMP,U,10)
 ;
 ; Send verification email to local mail group and VA Outlook mail group.
 S XMY("G.NPI EXTRACT VERIFICATION")=""
 D ESEND
 K ^TMP(XUSRTN)
 Q
 ;
SMAIL(XUSRTN) ; Summary email
 N TMP,T1,T2,T1NV,T2NV
 K ^TMP(XUSRTN,$J)
 S T1=$G(^XTMP(XUSRTN,1))
 S T2=$G(^XTMP(XUSRTN,2))
 S T1NV=$G(^XTMP(XUSRTN,"1NV"))
 S T2NV=$G(^XTMP(XUSRTN,"2NV"))
 S ^TMP(XUSRTN,$J,1)=^XTMP(XUSRTN,"H")_" - SUMMARY for "_DTTM
 S ^TMP(XUSRTN,$J,2)=""
 S ^TMP(XUSRTN,$J,3)="NEW PERSON FILE (#200)  "_+$P(T1,U)_" Message(s) Totaling "_+$P(T1,U,2)_" NPI records."
 S ^TMP(XUSRTN,$J,4)=""
 S ^TMP(XUSRTN,$J,5)="INSITUTION FILE (#4)  "_+$P(T2,U)_" Message(s) Totaling "_+$P(T2,U,2)_" NPI records."
 S ^TMP(XUSRTN,$J,6)=""
 S ^TMP(XUSRTN,$J,7)="NON VA Individual (#355.93)  "_+$P(T1NV,U)_" Message(s) Totaling "_+$P(T1NV,U,2)_" NPI records."
 S ^TMP(XUSRTN,$J,8)=""
 S ^TMP(XUSRTN,$J,9)="NON VA Facility/Group (#355.93)  "_+$P(T2NV,U)_" Message(s) Totaling "_+$P(T2NV,U,2)_" NPI records."
 S ^TMP(XUSRTN,$J,10)=""
 S ^TMP(XUSRTN,$J,11)="Programmer Notes:   "_XUSVER_" - "_$G(XUSPROD)
 ;
 ; Send verification email to local mail group and VA Outlook mail group
 S XMY("G.NPI EXTRACT VERIFICATION")=""
 N XMTEXT,XMSUB,XMDUN,XMDUZ,XMZ
 S XMTEXT="^TMP("""_XUSRTN_""","_$J_","
 S XMSUB=$TR($P($G(^TMP(XUSRTN,$J,1)),U),":")_"("_$G(XUSPROD)_") NPI EXTRACT SUMMARY "
 D ^XMD
 Q
 K ^TMP(XUSRTN)
 Q
 ;
ESEND N XMTEXT,XMSUB,XMDUN,XMDUZ,XMZ
 S XMTEXT="^TMP("""_XUSRTN_""","_$J_","
 S XMSUB=$TR($P($G(^TMP(XUSRTN,$J,1)),U),":")_"("_$G(XUSPROD)_") NPI EXTRACT TYPE 1 "
 D ^XMD
 Q
