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

KMPUTLW2.m

Go to the documentation of this file.
KMPUTLW2 ;SP/JML - Manage REST interfaces for VSM Monitors ;11/1/2023
 ;;4.0;CAPACITY MANAGEMENT;**1,4**;3/1/2018;Build 36
  ;
  ; Reference to ^%ZTER(1 supported by ICR #7138
  ; Reference to ^%ZTER(3.077 supported by ICR #7139
  ;
EVTPKG(KMPOPT) ;
 ; calculate eventname, parenteventname, eventtype, eventsource
 N KMPENAME,KMPESTR,KMPPSTR
 S KMPESTR="|||",KMPPSTR="|"
 S KMPESTR=$$CALCEVT(KMPOPT)
 S KMPENAME=$P(KMPESTR,"|")
 ;
 S KMPPSTR=$G(^KMPVPKG(KMPENAME))
 I KMPPSTR="" D
 .S KMPPSTR=$$CALCPKG(KMPENAME)
 Q KMPESTR_"|"_KMPPSTR
 ;
CALCEVT(KMPOPT) ;
 N KMPENAM,KMPETYP,KMPP1,KMPP2,KMPPENAM,KMPRUMD
 S (KMPENAM,KMPPENAM,KMPETYP,KMPRUMD)=""
 S KMPP1=$P(KMPOPT,"***"),KMPP2=$P(KMPOPT,"***",2)
 ; Event Type - RPC, Protocol, Option
 S KMPETYP=$S($E(KMPP1)="`":"RPC",KMPP2'="":"PROTOCOL",1:"OPTION")
 ; RUM Designation -> EventSource - 1:TaskMan, 2: Menu, 3:RPC Broker, 4:Users, 5:Unknown
 I $E(KMPP1)="!"!(KMPP1="$AFTR ZTMS$")!(KMPP1="$STRT ZTMS$") S KMPRUMD="TASKMAN"
 I KMPRUMD="" S KMPRUMD=$S($E(KMPP1)="`":"RPC BROKER",$E(KMPP1)="#":"USERS",1:"MENU")
 I KMPRUMD="" S KMPRUMD="UNKNOWN"
  ; EventName
 I $$RESERVED(KMPP1) S KMPENAM=KMPP1 ; handle system events
 I KMPENAM="","`!#"[$E(KMPP1) S KMPENAM=$E(KMPP1,2,$L(KMPP1)) ; handle non menu events
 I KMPENAM="" S KMPENAM=KMPP1 ; remaining need no editing
 I KMPP2'="" S KMPPENAM=KMPENAM,KMPENAM=KMPP2 ; IF PROTOCOL SET OPTION AS PARENT EVENT
 I (KMPENAM'="")&($E(KMPENAM,1)="`") S KMPENAM=$E(KMPENAM,2,$L(KMPENAM))
 S KMPRET=KMPENAM_"|"_KMPPENAM_"|"_KMPETYP_"|"_KMPRUMD
 S ^KMPVEVT(KMPOPT)=KMPRET
 Q KMPRET
 ;
CALCPKG(KMPENAME) ;
 N KMPIEN,KMPPKGID,KMPPNAM,KMPPRE,KMPRET
 ; CODE FROM SERVER TO SET KMPPKGID
 I $$RESERVED(KMPENAME) Q $$RESPACK(KMPENAME)
 S KMPPKGID="",KMPRET="UNKNOWN^UNKNOWN"
 S KMPPRE=$E(KMPENAME,1,4) D
 .I $D(^DIC(9.4,"C",KMPPRE)) S KMPPKGID=$O(^DIC(9.4,"C",KMPPRE,""))
 I KMPPKGID="" S KMPPRE=$E(KMPENAME,1,3) D
 .I $D(^DIC(9.4,"C",KMPPRE)) S KMPPKGID=$O(^DIC(9.4,"C",KMPPRE,""))
 I KMPPKGID="" S KMPPRE=$E(KMPENAME,1,2) D
 .I $D(^DIC(9.4,"C",KMPPRE)) S KMPPKGID=$O(^DIC(9.4,"C",KMPPRE,""))
 I KMPPKGID="" Q KMPRET
 S KMPIEN=""
 ; IF 2 ENTRIES NO WAY TO DECIDE WHICH IS CORRECT SO TAKE FIRST - DON'T LOOP - RARE OCCURRENCE
 S KMPIEN=$O(^DIC(9.4,"C",KMPPRE,KMPIEN)) Q:KMPIEN=""  D
 .S KMPPNAM=$P($G(^DIC(9.4,KMPIEN,0)),"^")
 .S KMPRET=KMPPRE_"|"_KMPPNAM
 .S ^KMPVPKG(KMPENAME)=KMPRET
 Q KMPRET
 ;
RESERVED(KMPENAME) ; Return 1 if system event
 I "#USER#^$AFTR ZTMS$^$STRT ZTMS$^$BROKER HANDLER$^$LOGIN$^$VISTALINK HANDLER$^$XQ MENU DRIVER$^EVE^"[KMPENAME Q 1
 I "#USER#^$AFTR ZTMS$^$STRT ZTMS$^$BROKER HANDLER$^$LOGIN$^$VISTALINK HANDLER$^$XQ MENU DRIVER$"[$E(KMPENAME,2,$L(KMPENAME)) Q 1
 Q 0
 ;
RESPACK(KMPENAME) ; Return PREFIX^PACKAGE
 I "^$AFTR ZTMS$^$STRT ZTMS$^$XQ MENU DRIVER$^$LOGIN$^#USER#^EVE^"[KMPENAME Q "XU|KERNEL"
 I "^$BROKER HANDLER$^"[KMPENAME Q "XWB|RPC BROKER"
 I "^$VISTALINK HANDLER$^"[KMPENAME Q "XOBV|VISTALINK"
 ; The following code is to fix null vsmpackage in KMPVBusinessEvent 2-14-2018 SCL
 I "^$BROKER HANDLER$^"[$E(KMPENAME,2,$L(KMPENAME)) Q "XWB|RPC BROKER"
 I "^$AFTR ZTMS$^$STRT ZTMS$^$XQ MENU DRIVER$^$LOGIN$^#USER#^EVE^"[$E(KMPENAME,2,$L(KMPENAME)) Q "XU|KERNEL"
 I "^$VISTALINK HANDLER$^"[$E(KMPENAME,2,$L(KMPENAME)) Q "XOBV|VISTALINK"
 Q ""
 ;
SETCFG(KMPCFG) ; Change VSM configuration via national server change request
 N KMPDATA,KMPEARR,KMPENUM,KMPFNAM,KMPFNUM,KMPFUNC,KMPFVAL,KMPI,KMPIEN,KMPMKEY,KMPMSG,KMPMSG2,KMPON,KMPRESP,KMPRT
 N KMPRTN,KMPRTO,KMPTEXT,KMPTNUM,KMPVER,FDA
 ;
 S KMPFUNC="SETCFG"
 S KMPMKEY=KMPCFG.Monitor
 S (KMPMSG,KMPMSG2)=""
 ;
 D STOPMON^KMPVCBG(KMPMKEY,1,1)
 ;
 S KMPVER=$$GETVAL^KMPVCCFG(KMPMKEY,"VERSION",8969)
 I KMPCFG.Function'="SetConfig" Q "Incorrect Function Type"
 S KMPFVAL("ALLOW TEST SYSTEM")=KMPCFG.AllowTestSystem
 S KMPFVAL("APIKEY")=KMPCFG.ApiKey
 S KMPFVAL("COLLECTION INTERVAL")=KMPCFG.CollectionInterval
 S KMPFVAL("DAYS TO KEEP DATA")=KMPCFG.DaysToKeepData
 S KMPFVAL("ENCRYPT")=KMPCFG.Encrypt
 S KMPFVAL("HTTP REQUEST MAX LENGTH")=KMPCFG.HttpRequestMaxLength
 S KMPFVAL("MONITOR START DELAY")=KMPCFG.MonitorStartDelay
 S KMPFVAL("NATIONAL DATA EMAIL ADDRESS")=KMPCFG.NationalDataEmailAddress
 S KMPFVAL("NATIONAL FQDN")=KMPCFG.NationalFqdn
 S KMPFVAL("NATIONAL IP ADDRESS")=KMPCFG.NationalIpAddress
 S KMPFVAL("NATIONAL PORT")=KMPCFG.NationalPort
 S KMPFVAL("NATIONAL SUPPORT EMAIL ADDRESS")=KMPCFG.NationalSupportEmailAddress
 S KMPFVAL("ONOFF")=KMPCFG.OnOff
 S KMPFVAL("TASKMAN OPTION")=KMPCFG.TaskmanOption
 S KMPFVAL("VSM CFG EMAIL ADDRESS")=KMPCFG.VsmCfgEmailAddress
 ;
 ; verify Monitor Type is valid
 I $D(^KMPV(8969,"B",KMPMKEY)) S KMPIEN=$O(^KMPV(8969,"B",KMPMKEY,""))
 I $G(KMPIEN)="" Q "Monitor "_KMPMKEY_" not defined. No changes made."
 ;  get field numbers and set FDA array
 S KMPFNAM=""
 F  S KMPFNAM=$O(KMPFVAL(KMPFNAM)) Q:KMPFNAM=""  D
 .S KMPFNUM=$$FLDNUM^DILFD(8969,KMPFNAM)
 .I KMPFNUM>0 S FDA($J,8969,KMPIEN_",",KMPFNUM)=KMPFVAL(KMPFNAM)
 .E  S KMPEARR(KMPFNAM)=""
 ;
 ; If field name does not exist send message and quit
 I $D(KMPEARR) D  Q "Configuration Update field(s) do not exist in the VSM CONFIGURATION file"
 .S KMPTEXT("SUBJECT")="VSM ALERT:  Configuration Update field(s) do not exist in the VSM CONFIGURATION file "
 .S KMPI=1
 .S KMPFNAM="",KMPTEXT(KMPI)=KMPMKEY_" Missing Fields",KMPI=KMPI+1
 .F  S KMPFNAM=$O(KMPEARR(KMPFNAM)) Q:KMPFNAM=""  D
 ..S KMPTEXT(KMPI)=KMPFNAM,KMPI=KMPI+1
 ;
 ; If still good get old values for logging changes
 S KMPFNAM=""
 F  S KMPFNAM=$O(KMPFVAL(KMPFNAM)) Q:KMPFNAM=""  D
 .S $P(KMPFVAL(KMPFNAM),"^",2)=$$GETVAL^KMPVCCFG(KMPMKEY,KMPFNAM,8969,"I")
 ;
 ; ATTEMPT TO MAKE CHANGES
 K KMPEARR
 D FILE^DIE("ET","FDA($J)","KMPEARR")
 ; IF ERRORS SEND MESSAGE WITH ERRORS
 S KMPRESP="OK"
 S KMPI=1
 I $D(KMPEARR) D  ; Add filing errors to support message
 .S KMPRESP="UPDATE FAILED"
 .S KMPTEXT("SUBJECT")="VSM ALERT:"_KMPMKEY_" Configuration Update: WITH ERRORS. "
 .S KMPTEXT(KMPI)="Changes NOT applied to VSM CONFIGURATION file. ",KMPI=KMPI+1
 .S KMPTEXT(KMPI)="Number of errors: "_+KMPEARR("DIERR"),KMPI=KMPI+1
 .S KMPENUM=""
 .F  S KMPENUM=$O(KMPEARR("DIERR",KMPENUM)) Q:+KMPENUM=0  D
 ..S KMPTNUM=""
 ..F  S KMPTNUM=$O(KMPEARR("DIERR",KMPENUM,"TEXT",KMPTNUM)) Q:+KMPTNUM=0  D
 ...S KMPTEXT(KMPI)=KMPEARR("DIERR",KMPENUM,"TEXT",KMPTNUM),KMPI=KMPI+1
 .D INFOMSG^KMPUTLW(.KMPTEXT)
 ; If no FILING errors then list changes in Support Message and Log Changes
 I '$D(KMPEARR) D
 .S KMPI=1
 .S KMPTEXT("SUBJECT")="VSM CONFIGURATION: "_KMPMKEY_" Configuration Update: No Errors. "
 .S KMPTEXT(KMPI)="Changes applied to VSM CONFIGURATION file. ",KMPI=KMPI+1
 .; list changes in Support Message
 .S KMPFNAM="",KMPTEXT(KMPI)="Changed Fields",KMPI=KMPI+1
 .F  S KMPFNAM=$O(KMPFVAL(KMPFNAM)) Q:KMPFNAM=""  D
 ..S KMPDATA=KMPFVAL(KMPFNAM)
 ..S KMPTEXT(KMPI)=KMPFNAM_"-"_$P(KMPDATA,"^",2)_" TO "_$P(KMPDATA,"^"),KMPI=KMPI+1
 .D INFOMSG^KMPUTLW(.KMPTEXT)
 ; if end state is 'ON' then start monitor
 I $$GETVAL^KMPVCCFG(KMPMKEY,"ONOFF",8969)="ON" D STARTMON^KMPVCBG(KMPMKEY,1,1)
 ;
 Q KMPRESP
 ;
GETERR(KMPRET,KMPREQ) ; Return run history recorded in the VSM CACHE TASK LOG file
 N KMPD,KMPDAT,KMPENUM,KMPINODE,KMPJNODE,KMPUVNB,KMPVAL,KMPVAR,KMPVNUM,KMPVOBJ
 ;
 S KMPDAT=KMPREQ.ErrorDate
 I KMPDAT="" S KMPRET.Status="No Date Provided" Q
 S KMPDAT=$ZDATEH(KMPDAT,3)
 S KMPENUM=KMPREQ.ErrorNumber
 I KMPENUM="" S KMPRET.Status="No Error Number Provided" Q
 S KMPD=##class(%DynamicObject).%New()
 I '$D(^%ZTER(1,KMPDAT,1,KMPENUM)) S KMPRET.Status="Error Not Found" Q
 S KMPD.ErrorNumber=+$G(^%ZTER(1,KMPDAT,1,KMPENUM,0))
 S KMPD.LastGlobalReference=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"GR"))
 S KMPINODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"I"))
 S KMPD.CurrentIo=$P(KMPINODE,"^",1)
 S KMPD.ZaValue=$P(KMPINODE,"^",2)
 S KMPD.ZbValue=$P(KMPINODE,"^",3)
 S KMPD.CurrentZio=$P(KMPINODE,"^",4)
 S KMPD.HValue=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"H"))
 S KMPJNODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"J"))
 S KMPD.JobNumber=$P(KMPJNODE,"^",1)
 S KMPD.ProcessName=$P(KMPJNODE,"^",2)
 S KMPD.UserName=$P(KMPJNODE,"^",3)
 S KMPUVNB=$P(KMPJNODE,"^",4)
 S KMPD.Uci=$P(KMPUVNB,"~",1)
 S KMPD.Vol=$P(KMPUVNB,"~",1)
 S KMPD.Node=$P(KMPUVNB,"~",1)
 S KMPD.Box=$P(KMPUVNB,"~",1)
 S KMPD.AlternateJobNumber=$P(KMPJNODE,"^",5)
 S KMPD.Line=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"LINE"))
 S KMPD.ZE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"ZE"))
 S KMPVNUM=0,KMPVOBJ=##class(%DynamicObject).%New()
 F  S KMPVNUM=$O(^%ZTER(1,KMPDAT,1,KMPENUM,"ZV",KMPVNUM)) Q:+KMPVNUM=0  D
 .S KMPVAR=^%ZTER(1,KMPDAT,1,KMPENUM,"ZV",KMPVNUM,0)
 .S KMPVAL=^%ZTER(1,KMPDAT,1,KMPENUM,"ZV",KMPVNUM,"D")
 .D KMPVOBJ.%Set(KMPVAR,KMPVAL)
 S KMPD.Variables=KMPVOBJ
 S KMPRET.Status="Error Found"
 S KMPRET.Error=KMPD
 Q