MHV1P22 ;LB - My HealtheVet Install Utility Routine ; [1/15/13 15:01pm]
 ;;1.0;My HealtheVet;**22**;Oct 16, 2015;Build 19
 ;;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ;  Integration Agreements:
 ;        10141 : BMES^XPDUTL
 ;              : MES^XPDUTL
 ;              : $$INSTALDT^XPDUTL(): Return All Install Dates/Times
 ;        10018 : UPDATE^DIE
 ;        10103 : $$FMTH^XLFDT
 ;              : $$HTFM^XLFDT
 ;              : $$NOW^XLFDT
 ;        2067  : $$PKGPAT^XPDIP(): Update Patch History
 ;
ENV ;
 Q
 ;
PRE ; Pre-init routine
 ; Turn on MHV Application Logging, add a log entry for the start
 ; of the patch install.
 ;----------------------------------------------------------------------------
 ; Check if any SM Clinics are missing the Institution
 D LOGON
 D LOG^MHVUL2(XPDNM,"PRE-INIT","S","TRACE")
 S ERR=""
 S MHVC=0
 D LOG^MHVUL2("CHECK","INSTITUTION","S","TRACE")
 D CHKHLOC(.ERR)
 I ERR'="" D
 . D LOG^MHVUL2("CHECK INSTITUTION",ERR,"S","ERROR")
 . D BMES^XPDUTL("     *** An Error occurred during installation.")
 . D MES^XPDUTL("     Please log a remedy ticket to check INSTITUTION and DIVISION in Hospital Location File.")
 . D BMES^XPDUTL("     This install will now abort.  Only attempt to re-install when ")
 . D MES^XPDUTL("     corrective action has been taken.")
 . S XPDABORT=2
 . Q
 ;----------------------------------------------------------------------------
 ; Defect 218690 -Fix for Patch MHV*1.0*11 Install
 ; Check if Patch MHV*1.0*11 has been installed in the PATCH INSTALL File
 D LOG^MHVUL2("CHECK","MHV*1.0*11 INSTALL","S","TRACE")
 N MHVP,RSLT,P11SEQ,P11DT,P11VER,P11USR,P11COM,P11IIEN,P11CDT,RET,MHVC,MHVPINST,MHVPKIEN
 S MHVP=0,ERR=""
 ;Check if Patch MHV*1.0*11 is in Patch History File
 S MHVPINST=$$PATCH^XPDUTL("MHV*1.0*11")
 I MHVPINST=1 D
 . D BMES^XPDUTL("    Patch MHV*1.0*11 SEQ#14 currently exists in MHV PATCH APPLICATION HISTORY.")
 . D MES^XPDUTL("     No update of Patch MHV*1.0*11 is necessary.")
 . D BMES^XPDUTL("    This install will now continue with the next steps.")
 ;
 I MHVPINST<1 D  ;Patch was not found in MHV PATCH APPLICATION HISTORY
 . S MHVP=$$INSTALDT^XPDUTL("MHV*1.0*11",.RSLT)     ;check the INSTALL history
 . I MHVP<1 S ERR="Patch MHV*1.0*11 SEQ #14 has never been installed" Q
 . S ERR=""
 . S MHVPKIEN=$$FIND1^DIC(9.4,"","BX","My HealtheVet","","","ERR")  ;get local MHV Package IEN
 . S ERR=$G(ERR("DIERR",1,"TEXT",1)) Q:$G(ERR)'=""
 . S P11VER="1.0"                                   ;patch version -fixed
 . S P11DT=$O(RSLT("@"),-1)                         ;get last install date
 . S RET="11 SEQ#14^"_P11DT             ;patch^date installed
 . S MHVP=$$PKGPAT^XPDIP(MHVPKIEN,P11VER,.RET)      ;Update Patch History File
 . I +$P($G(MHVP),"^",2)>0 D  Q
 . . D BMES^XPDUTL("     Patch MHV*1.0*11 SEQ#14 Install History Succesfully Updated")
 . ;This should never hapen? but just in case-err handling below:
 . I +$P($G(MHVP),"^",2)'>0 D  
 . . S ERR="Patch MHV*1.0*11 SEQ #14 Install History could not be updated"
 . . D BMES^XPDUTL("     "_ERR)
 . . D MES^XPDUTL("     Please log a Help Desk Incident ticket for this issue.")
 ;
 I ERR'="" D ERRSTAT(ERR)
 D LOG^MHVUL2(XPDNM,"PRE-INIT END","S","TRACE")
 Q
 ;
ERRSTAT(ERRCOM) ;
 D LOG^MHVUL2("CHECK MHV*1.0*11 SEQ#14 INSTALL",ERRCOM,"S","ERROR")
 D BMES^XPDUTL("     *** An Error occurred during installation.")
 D MES^XPDUTL("     Please Install the Released Patch MHV*1.0*11 SEQ#14 first.")
 D BMES^XPDUTL("    This install will now abort. Only attempt to re-install when ")
 D MES^XPDUTL("     corrective action has been taken.")
 S XPDABORT=2
 Q
 ;
POST ; Post-init routine
 N ERR
 D LOG^MHVUL2(XPDNM,"POST-INIT BEGIN","S","TRACE")
 D LOG^MHVUL2(XPDNM,"POST-INIT END","S","TRACE")
 D LOGOFF
 D RESET^MHVUL2
 Q
 ;
LOGON ; Turn on MHV application logging
 N UPDATE,SUCCESS
 D BMES^XPDUTL("     Turning on MHV Application Logging")
 S UPDATE("STATE")=1
 S UPDATE("DELETE")=$$HTFM^XLFDT($H+60)
 S UPDATE("LEVEL")="DEBUG"
 D LOGSET^MHVUL1(.SUCCESS,.UPDATE)
 Q
 ;
LOGOFF ; Turn off MHV application logging
 N SUCCESS
 D BMES^XPDUTL("     Turning off MHV Application Logging")
 D LOGOFF^MHVUL1(.SUCCESS)
 Q
 ;
CHKHLOC(ERR) ; Check Institution in Hospital Location File (#44)
 N MHVCSIEN,MHVCLIEN,MHVINST,MHVDIVN
 S MHVCSIEN=$$SCIEN(719)
 I $G(MHVCSIEN)="" S ERR="MHV SECURE MESSAGING Stop Code is not found in STOP CODE File" Q
 S MHVCLIEN=0
 F  S MHVCLIEN=$O(^SC("ACST",MHVCSIEN,MHVCLIEN)) Q:'MHVCLIEN  D
 .S MHVCLNM=$$GET1^DIQ(44,+MHVCLIEN,.01,"I")
 .I ($G(MHVCLNM)'="")&($$UP^XLFSTR($E(MHVCLNM,1,2))'="ZZ")  D
 ..S MHVINST=$$GET1^DIQ(44,+MHVCLIEN,3,"E")
 ..S MHVDIVN=$$GET1^DIQ(44,+MHVCLIEN,3.5,"E")
 ..I ($G(MHVINST)="")!($G(MHVDIVN)="")  D
 ...D CHKLERR(.MHVCLNM)
 ...S ERR="Missing Institution/Division field in Hospital Location File (#44)"
 ...Q
 Q
 ;
CHKLERR(MHVCLNM) ; Print messages in case of Institution or Division missing
 D LOG^MHVUL2("INSTITUTION-DIVISION MISSING",$G(MHVCLNM),"S","ERROR")
 I MHVC=0  D
 .D BMES^XPDUTL("     *** Please check the following Secure Messaging Clinics that the")
 .D MES^XPDUTL("     *** Institution field and Division field have valid values")
 S MHVC=MHVC+1
 D MES^XPDUTL("     "_$G(MHVCLNM))
 Q
 ;
SCIEN(SCN) ;Get stop code IEN
 N SCIEN
 I SCN="" Q ""
 S SCIEN=$O(^DIC(40.7,"C",SCN,0))
 I $G(SCIEN)="" Q ""
 Q SCIEN
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMHV1P22   5463     printed  Sep 23, 2025@19:51:30                                                                                                                                                                                                     Page 2
MHV1P22   ;LB - My HealtheVet Install Utility Routine ; [1/15/13 15:01pm]
 +1       ;;1.0;My HealtheVet;**22**;Oct 16, 2015;Build 19
 +2       ;;Per VHA Directive 2004-038, this routine should not be modified.
 +3       ;
 +4       ;  Integration Agreements:
 +5       ;        10141 : BMES^XPDUTL
 +6       ;              : MES^XPDUTL
 +7       ;              : $$INSTALDT^XPDUTL(): Return All Install Dates/Times
 +8       ;        10018 : UPDATE^DIE
 +9       ;        10103 : $$FMTH^XLFDT
 +10      ;              : $$HTFM^XLFDT
 +11      ;              : $$NOW^XLFDT
 +12      ;        2067  : $$PKGPAT^XPDIP(): Update Patch History
 +13      ;
ENV       ;
 +1        QUIT 
 +2       ;
PRE       ; Pre-init routine
 +1       ; Turn on MHV Application Logging, add a log entry for the start
 +2       ; of the patch install.
 +3       ;----------------------------------------------------------------------------
 +4       ; Check if any SM Clinics are missing the Institution
 +5        DO LOGON
 +6        DO LOG^MHVUL2(XPDNM,"PRE-INIT","S","TRACE")
 +7        SET ERR=""
 +8        SET MHVC=0
 +9        DO LOG^MHVUL2("CHECK","INSTITUTION","S","TRACE")
 +10       DO CHKHLOC(.ERR)
 +11       IF ERR'=""
               Begin DoDot:1
 +12               DO LOG^MHVUL2("CHECK INSTITUTION",ERR,"S","ERROR")
 +13               DO BMES^XPDUTL("     *** An Error occurred during installation.")
 +14               DO MES^XPDUTL("     Please log a remedy ticket to check INSTITUTION and DIVISION in Hospital Location File.")
 +15               DO BMES^XPDUTL("     This install will now abort.  Only attempt to re-install when ")
 +16               DO MES^XPDUTL("     corrective action has been taken.")
 +17               SET XPDABORT=2
 +18               QUIT 
               End DoDot:1
 +19      ;----------------------------------------------------------------------------
 +20      ; Defect 218690 -Fix for Patch MHV*1.0*11 Install
 +21      ; Check if Patch MHV*1.0*11 has been installed in the PATCH INSTALL File
 +22       DO LOG^MHVUL2("CHECK","MHV*1.0*11 INSTALL","S","TRACE")
 +23       NEW MHVP,RSLT,P11SEQ,P11DT,P11VER,P11USR,P11COM,P11IIEN,P11CDT,RET,MHVC,MHVPINST,MHVPKIEN
 +24       SET MHVP=0
           SET ERR=""
 +25      ;Check if Patch MHV*1.0*11 is in Patch History File
 +26       SET MHVPINST=$$PATCH^XPDUTL("MHV*1.0*11")
 +27       IF MHVPINST=1
               Begin DoDot:1
 +28               DO BMES^XPDUTL("    Patch MHV*1.0*11 SEQ#14 currently exists in MHV PATCH APPLICATION HISTORY.")
 +29               DO MES^XPDUTL("     No update of Patch MHV*1.0*11 is necessary.")
 +30               DO BMES^XPDUTL("    This install will now continue with the next steps.")
               End DoDot:1
 +31      ;
 +32      ;Patch was not found in MHV PATCH APPLICATION HISTORY
           IF MHVPINST<1
               Begin DoDot:1
 +33      ;check the INSTALL history
                   SET MHVP=$$INSTALDT^XPDUTL("MHV*1.0*11",.RSLT)
 +34               IF MHVP<1
                       SET ERR="Patch MHV*1.0*11 SEQ #14 has never been installed"
                       QUIT 
 +35               SET ERR=""
 +36      ;get local MHV Package IEN
                   SET MHVPKIEN=$$FIND1^DIC(9.4,"","BX","My HealtheVet","","","ERR")
 +37               SET ERR=$GET(ERR("DIERR",1,"TEXT",1))
                   if $GET(ERR)'=""
                       QUIT 
 +38      ;patch version -fixed
                   SET P11VER="1.0"
 +39      ;get last install date
                   SET P11DT=$ORDER(RSLT("@"),-1)
 +40      ;patch^date installed
                   SET RET="11 SEQ#14^"_P11DT
 +41      ;Update Patch History File
                   SET MHVP=$$PKGPAT^XPDIP(MHVPKIEN,P11VER,.RET)
 +42               IF +$PIECE($GET(MHVP),"^",2)>0
                       Begin DoDot:2
 +43                       DO BMES^XPDUTL("     Patch MHV*1.0*11 SEQ#14 Install History Succesfully Updated")
                       End DoDot:2
                       QUIT 
 +44      ;This should never hapen? but just in case-err handling below:
 +45               IF +$PIECE($GET(MHVP),"^",2)'>0
                       Begin DoDot:2
 +46                       SET ERR="Patch MHV*1.0*11 SEQ #14 Install History could not be updated"
 +47                       DO BMES^XPDUTL("     "_ERR)
 +48                       DO MES^XPDUTL("     Please log a Help Desk Incident ticket for this issue.")
                       End DoDot:2
               End DoDot:1
 +49      ;
 +50       IF ERR'=""
               DO ERRSTAT(ERR)
 +51       DO LOG^MHVUL2(XPDNM,"PRE-INIT END","S","TRACE")
 +52       QUIT 
 +53      ;
ERRSTAT(ERRCOM) ;
 +1        DO LOG^MHVUL2("CHECK MHV*1.0*11 SEQ#14 INSTALL",ERRCOM,"S","ERROR")
 +2        DO BMES^XPDUTL("     *** An Error occurred during installation.")
 +3        DO MES^XPDUTL("     Please Install the Released Patch MHV*1.0*11 SEQ#14 first.")
 +4        DO BMES^XPDUTL("    This install will now abort. Only attempt to re-install when ")
 +5        DO MES^XPDUTL("     corrective action has been taken.")
 +6        SET XPDABORT=2
 +7        QUIT 
 +8       ;
POST      ; Post-init routine
 +1        NEW ERR
 +2        DO LOG^MHVUL2(XPDNM,"POST-INIT BEGIN","S","TRACE")
 +3        DO LOG^MHVUL2(XPDNM,"POST-INIT END","S","TRACE")
 +4        DO LOGOFF
 +5        DO RESET^MHVUL2
 +6        QUIT 
 +7       ;
LOGON     ; Turn on MHV application logging
 +1        NEW UPDATE,SUCCESS
 +2        DO BMES^XPDUTL("     Turning on MHV Application Logging")
 +3        SET UPDATE("STATE")=1
 +4        SET UPDATE("DELETE")=$$HTFM^XLFDT($HOROLOG+60)
 +5        SET UPDATE("LEVEL")="DEBUG"
 +6        DO LOGSET^MHVUL1(.SUCCESS,.UPDATE)
 +7        QUIT 
 +8       ;
LOGOFF    ; Turn off MHV application logging
 +1        NEW SUCCESS
 +2        DO BMES^XPDUTL("     Turning off MHV Application Logging")
 +3        DO LOGOFF^MHVUL1(.SUCCESS)
 +4        QUIT 
 +5       ;
CHKHLOC(ERR) ; Check Institution in Hospital Location File (#44)
 +1        NEW MHVCSIEN,MHVCLIEN,MHVINST,MHVDIVN
 +2        SET MHVCSIEN=$$SCIEN(719)
 +3        IF $GET(MHVCSIEN)=""
               SET ERR="MHV SECURE MESSAGING Stop Code is not found in STOP CODE File"
               QUIT 
 +4        SET MHVCLIEN=0
 +5        FOR 
               SET MHVCLIEN=$ORDER(^SC("ACST",MHVCSIEN,MHVCLIEN))
               if 'MHVCLIEN
                   QUIT 
               Begin DoDot:1
 +6                SET MHVCLNM=$$GET1^DIQ(44,+MHVCLIEN,.01,"I")
 +7                IF ($GET(MHVCLNM)'="")&($$UP^XLFSTR($EXTRACT(MHVCLNM,1,2))'="ZZ")
                       Begin DoDot:2
 +8                        SET MHVINST=$$GET1^DIQ(44,+MHVCLIEN,3,"E")
 +9                        SET MHVDIVN=$$GET1^DIQ(44,+MHVCLIEN,3.5,"E")
 +10                       IF ($GET(MHVINST)="")!($GET(MHVDIVN)="")
                               Begin DoDot:3
 +11                               DO CHKLERR(.MHVCLNM)
 +12                               SET ERR="Missing Institution/Division field in Hospital Location File (#44)"
 +13                               QUIT 
                               End DoDot:3
                       End DoDot:2
               End DoDot:1
 +14       QUIT 
 +15      ;
CHKLERR(MHVCLNM) ; Print messages in case of Institution or Division missing
 +1        DO LOG^MHVUL2("INSTITUTION-DIVISION MISSING",$GET(MHVCLNM),"S","ERROR")
 +2        IF MHVC=0
               Begin DoDot:1
 +3                DO BMES^XPDUTL("     *** Please check the following Secure Messaging Clinics that the")
 +4                DO MES^XPDUTL("     *** Institution field and Division field have valid values")
               End DoDot:1
 +5        SET MHVC=MHVC+1
 +6        DO MES^XPDUTL("     "_$GET(MHVCLNM))
 +7        QUIT 
 +8       ;
SCIEN(SCN) ;Get stop code IEN
 +1        NEW SCIEN
 +2        IF SCN=""
               QUIT ""
 +3        SET SCIEN=$ORDER(^DIC(40.7,"C",SCN,0))
 +4        IF $GET(SCIEN)=""
               QUIT ""
 +5        QUIT SCIEN
 +6       ;