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

KMPVCSRV.m

Go to the documentation of this file.
KMPVCSRV ;SP/JML - VSM Server routine for VistA functions ;5/1/2017
 ;;4.0;CAPACITY MANAGEMENT;;3/1/2018;Build 38;
 ;
 ;
EN ;  Server routine entry point
 ;
 Q:'$G(XQMSG)
 N XMZ,XMRG,XMER
 S XMZ=XQMSG
 S XQSUB=$G(XQSUB)
 N KMPVCHKF,KMPVFNUM,KMPVFUNC,KMPVRQNAM,KMPVSITE,KMPVSNAME,KMPVTEXT
 ;
 S KMPVFUNC=$P(XQSUB,"^"),KMPVSNAME=$P(XQSUB,"^",2),KMPVFNUM=$P(XQSUB,"^",3),KMPVRQNAM=$P(XQSUB,"^",4)
 S KMPVSITE=$$SITE^VASITE ;  IA 10112
 I KMPVSNAME'=$P(KMPVSITE,"^",2)!(KMPVFNUM'=$P(KMPVSITE,"^",3)) D  Q
 .S KMPVTEXT="WARN^CLIENT REQUEST LOCATION MISMATCH^"
 .S KMPVTEXT(1)="SITE DATA IN EMAIL: "_KMPVSNAME_"^"_KMPVFNUM
 .S KMPVTEXT(2)="SITE DATA AT SITE: "_KMPVSITE
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ; verify request is for valid function
 S KMPVCHKF="^"_KMPVFUNC_"^"
 I "^ACK^GETSTAT^RESEND^SETCFG^KMPUPDEF^CTMLOG^PACKUPDT^"'[KMPVCHKF D  Q
 .S KMPVTEXT="WARN^CLIENT REQUEST INVALID FUNCTION^"
 .S KMPVTEXT(1)="FUNCTION REQUEST="_KMPVFUNC
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 D @KMPVFUNC
 Q
 ; -- Tasks Via Email Requests --
 ;
ACK ; Receive acknowledge VSM receipt of VTCM data - delete from local node
 N KMPVCDATE,KMPVTSTAT,KMPVMT,KMPPAR1
 N XMER,XMRG
 ; IA #10073
 F  D REC^XMS3 Q:XMER=-1  D
 .I $P(XMRG,"=")="TRANSMISSION STATUS" S KMPVTSTAT=$P(XMRG,"=",2)
 .I $P(XMRG,"=")="COLLECTION DATE" S KMPVCDATE=$P(XMRG,"=",2)
 .I $P(XMRG,"=")="COLLECTION TYPE" S KMPVMKEY=$P(XMRG,"=",2)
 .I $P(XMRG,"=")="PARAM 1" S KMPPAR1=$P(XMRG,"=",2)
 Q:KMPVCDATE=""
 I KMPVTSTAT="TRANSMISSION RECEIVED" D
 .I KMPVMKEY="VTCM" K ^KMPTMP("KMPV","VTCM","DLY",KMPVCDATE)
 .I KMPVMKEY="VSTM" K ^KMPTMP("KMPV","VSTM","DLY",KMPVCDATE)
 .I KMPVMKEY="VMCM" K ^KMPTMP("KMPV","VMCM","DLY",KMPVCDATE)
 .I KMPVMKEY="VBEM" K ^KMPTMP("KMPV","VBEM","COMPRESS",KMPVCDATE)
 .I KMPVMKEY="VHLM" K ^KMPTMP("KMPV","VHLM","DLY",KMPVCDATE,KMPPAR1)
 Q
 ;
GETSTAT ; Returns current status of VSM
 N KMPVFLD,KMPVFNAM,KMPVLN,KMPVMKEY,KMPVSTAT,KMPVTEXT,KMPVTFLD,KMPVTNUM
 D CFGMSG^KMPVCBG("SERVER-VSMSTAT")
 Q
 ;
RESEND ;  Resend data for one or more monitors
 N KMPVMKEY,KMPVML
 N XMER,XMRG
 ; IA #10073
 F  D REC^XMS3 Q:XMER=-1  D
 .I $P(XMRG,"=")="CollectionType" D
 ..S KMPVMKEY=$P(XMRG,"=",2)
 ..I KMPVMKEY'="" S KMPVML(KMPVMKEY)=""
 S KMPVMKEY=""
 F  S KMPVMKEY=$O(KMPVML(KMPVMKEY)) Q:KMPVMKEY=""  D
 .I KMPVMKEY="VBEM" D EN^KMPVBETR
 .I KMPVMKEY="VTCM" D SEND^KMPVVTCM
 .I KMPVMKEY="VSTM" D SEND^KMPVVSTM
 .I KMPVMKEY="VMCM" D SEND^KMPVVMCM
 .I KMPVMKEY="VHLM" D PREPARE^KMPVVHLM
 Q
 ;
SETCFG() ; Change VSM configuration via national server change request
 N KMPVCALL,KMPVCFG,KMPVCFGAR,KMPVFVAL,KMPVDATA,KMPVERR,KMPVFNAM,KMPVI,KMPVLN
 N KMPVMKEY,KMPVSET,KMPVSTAT,KMPVTEXT,KMPVVAL,KMPVVALID,KMPVEARR
 N FDA,XMER,XMRG
 ;
 S KMPVMKEY="NONE"
 ; Read message text and attempt to update VSM configuration
 ; IA #10073
 F  D REC^XMS3 Q:XMER=-1  D
 .I $P(XMRG,"=")="MONITOR KEY" S KMPVMKEY=$P(XMRG,"=",2) Q
 .Q:$P(XMRG,"=")'="UPDATE KMPCFG"
 .S KMPVDATA=$P(XMRG,"=",2)
 .S KMPVFNAM=$P(KMPVDATA,"^"),KMPVVAL=$P(KMPVDATA,"^",2)
 .S KMPVFVAL(KMPVFNAM)=KMPVVAL
 ;
 ; verify Monitor Type is valid
 I $D(^KMPV(8969,"B",KMPVMKEY)) S KMPVIEN=$O(^KMPV(8969,"B",KMPVMKEY,""))
 I $G(KMPVIEN)="" D  Q
 .S KMPVTEXT="Monitor "_KMPVMKEY_" not defined"
 .S KMPVTEXT(1)="Monitor "_KMPVMKEY_"not defined. No changes made."
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ;  get field numbers and set FDA array
 S KMPVFNAM=""
 F  S KMPVFNAM=$O(KMPVFVAL(KMPVFNAM)) Q:KMPVFNAM=""  D
 .S KMPVFNUM=$$FLDNUM^DILFD(8969,KMPVFNAM)
 .I KMPVFNUM>0 S FDA($J,8969,KMPVIEN_",",KMPVFNUM)=KMPVFVAL(KMPVFNAM)
 .E  S KMPVEARR(KMPVFNAM)=""
 ;
 ; If field name does not exist send message and quit
 I $D(KMPVEARR) D  Q
 .S KMPVTEXT=KMPVMKEY_" Configuration Update: field(s) do not exist"
 .S KMPVTEXT(1)="The following field(s) do not exist in the VSM CONFIGURATION file"
 .S KMPVFNAM="",KMPVLN=2
 .F  S KMPVFNAM=$O(KMPVEARR(KMPVFNAM)) Q:KMPVFNAM=""  D
 ..S KMPVTEXT(KMPVLN)=KMPVFNAM,KMPVLN=KMPVLN+1
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ; If still good get old values for logging changes
 S KMPVFNAM=""
 F  S KMPVFNAM=$O(KMPVFVAL(KMPVFNAM)) Q:KMPVFNAM=""  D
 .S $P(KMPVFVAL(KMPVFNAM),"^",2)=$$GETVAL^KMPVCCFG(KMPVMKEY,KMPVFNAM,8969,"I")
 ;
 S KMPVLN=1
 I $D(KMPVEARR) D  Q 
 .S KMPVTEXT=KMPVMKEY_" Configuration Update: FILING ERRORS - NO CHANGES MADE"
 .S KMPVTEXT(KMPVLN)="CONFIGURATION CHANGES NOT APPLIED!",KMPVLN=KMPVLN+1
 .S KMPVTEXT(KMPVLN)="ERROR DETAILS: ",KMPVLN=KMPVLN+1
 .S KMPVI=""
 .F  S KMPVI=$O(KMPVEARR(KMPVI)) Q:KMPVI=""  D
 ..S KMPVTEXT(KMPVLN)=KMPVEARR(KMPVI),KMPVLN=KMPVLN+1
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ; ATTEMPT TO MAKE CHANGES
 K KMPVEARR
 D FILE^DIE("ET","FDA($J)","KMPVEARR")
 ; IF ERRORS SEND MESSAGE WITH ERRORS
 I $D(KMPVEARR) D  ; Add filing errors to support message
 .S KMPVTEXT=KMPVMKEY_" Configuration Update: WITH ERRORS"
 .S KMPVTEXT(KMPVLN)="Changes NOT applied to VSM CONFIGURATION file",KMPVLN=KMPVLN+1
 .S KMPVTEXT(KMPVLN)="Number of errors: "_+KMPVEARR("DIERR"),KMPVLN=KMPVLN+1
 .S KMPVENUM=""
 .F  S KMPVENUM=$O(KMPVEARR("DIERR",KMPVENUM)) Q:+KMPVENUM=0  D
 ..S KMPVTNUM=""
 ..F  S KMPVTNUM=$O(KMPVEARR("DIERR",KMPVENUM,"TEXT",KMPVTNUM)) Q:+KMPVTNUM=0  D
 ...S KMPVTEXT(KMPVLN)=KMPVEARR("DIERR",KMPVENUM,"TEXT",KMPVTNUM),KMPVLN=KMPVLN+1
 ; If no FILING errors then list changes in Support Message and Log Changes
 I '$D(KMPVEARR) D
 .S KMPVTEXT=KMPVMKEY_" Configuration Update: No Errors"
 .S KMPVTEXT(KMPVLN)="Changes applied to VSM CONFIGURATION file",KMPVLN=KMPVLN+1
 .S KMPVTEXT(KMPVLN)="CHANGED FIELDS:",KMPVLN=KMPVLN+1
 .; list changes in Support Message
 .S KMPVFNAM=""
 .F  S KMPVFNAM=$O(KMPVFVAL(KMPVFNAM)) Q:KMPVFNAM=""  D
 ..S KMPVDATA=KMPVFVAL(KMPVFNAM)
 ..S KMPVTEXT(KMPVLN)=KMPVFNAM_"  :  "_$P(KMPVDATA,"^",2)_" --> "_$P(KMPVDATA,"^"),KMPVLN=KMPVLN+1
 ;
 ; if end state is 'ON' then re-schedule -- if 'OFF' then de-schedule
 S KMPVON=$$GETVAL^KMPVCCFG(KMPVMKEY,"ONOFF",8969)
 I KMPVON="ON" D STARTMON^KMPVCBG(KMPVMKEY,1)
 I KMPVON="OFF" D STOPMON^KMPVCBG(KMPVMKEY,1)
 ;
 ; Mail config back to National Server
 D CFGMSG^KMPVCBG("SERVER-VSMCFG")
 ; Mail results back to SUPPORT mail groups
 D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 Q
 ;
KMPUPDEF ; Update VSM MONITOR DEFAULTS file.  Optionally apply defaults to VSM CONFIGURATION file.
 N KMPVADEF,KMPVDATA,KMPVEARR,KMPVENUM,KMPVFNAM,KMPVFVAL,KMPVI,KMPVIEN,KMPVIEN,KMPVLN,KMPVMKEY
 N KMPVON,KMPVREST,KMPVTEXT,KMPVTNUM,KMPVVAL
 N FDA,XMER,XMRG
 ;
 S KMPVMKEY="NONE"
 ; Read message text to get data to change
 ; IA #10073
 F  D REC^XMS3 Q:XMER=-1  D
 .I $P(XMRG,"=")="MONITOR KEY" S KMPVMKEY=$P(XMRG,"=",2) Q
 .I $P(XMRG,"=")="APPLY DEFAULTS" S KMPVADEF=$P(XMRG,"=",2) Q
 .Q:$P(XMRG,"=")'="UPDATE KMPDEF"
 .S KMPVDATA=$P(XMRG,"=",2)
 .S KMPVFNAM=$P(KMPVDATA,"^"),KMPVVAL=$P(KMPVDATA,"^",2)
 .S KMPVFVAL(KMPVFNAM)=KMPVVAL
 ;
 ; verify Monitor Type is valid
 I $D(^KMPV(8969.02,"B",KMPVMKEY)) S KMPVIEN=$O(^KMPV(8969.02,"B",KMPVMKEY,""))
 I $G(KMPVIEN)="" D  Q
 .S KMPVTEXT="Monitor "_KMPVMKEY_" not defined"
 .S KMPVTEXT(1)="Monitor "_KMPVMKEY_"not defined. No changes made."
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ;  get field numbers and set FDA array
 S KMPVFNAM=""
 F  S KMPVFNAM=$O(KMPVFVAL(KMPVFNAM)) Q:KMPVFNAM=""  D
 .S KMPVFNUM=$$FLDNUM^DILFD(8969.02,KMPVFNAM)
 .I KMPVFNUM>0 S FDA($J,8969.02,KMPVIEN_",",KMPVFNUM)=KMPVFVAL(KMPVFNAM)
 .E  S KMPVEARR(KMPVFNAM)=""
 ; If field name does not exist send message and quit
 I $D(KMPVEARR) D  Q
 .S KMPVTEXT=KMPVMKEY_" Default Value Update: field(s) do not exist"
 .S KMPVTEXT(1)="The following field(s) do not exist in the VSM MONITOR DEFAULTS file"
 .S KMPVFNAM="",KMPVLN=2
 .F  S KMPVFNAM=$O(KMPVEARR(KMPVFNAM)) Q:KMPVFNAM=""  D
 ..S KMPVTEXT(KMPVLN)=KMPVFNAM,KMPVLN=KMPVLN+1
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ; If still good get old values for logging changes
 S KMPVFNAM=""
 F  S KMPVFNAM=$O(KMPVFVAL(KMPVFNAM)) Q:KMPVFNAM=""  D
 .S $P(KMPVFVAL(KMPVFNAM),"^",2)=$$GETVAL^KMPVCCFG(KMPVMKEY,KMPVFNAM,8969.02,"I")
 ;
 ; Update VSM MONITOR DEFAULTS file
 D FILE^DIE("ET","FDA($J)","KMPVEARR")
 ;
 ; If filing errors send message and quit
 I $D(KMPVEARR) D  Q
 .S KMPVTEXT=KMPVMKEY_" Default Value Update: Filing Errors",KMPVLN=1
 .S KMPVI=0
 .F  S KMPVI=$O(KMPVEARR("DIERR",KMPVI)) Q:KMPVI=""  D
 ..S KMPVTNUM=""
 ..F  S KMPVTNUM=$O(KMPVEARR("DIERR",KMPVI,"TEXT",KMPVTNUM)) Q:KMPVTNUM=""  D
 ...S KMPVTEXT(KMPVLN)=KMPVEARR("DIERR",KMPVI,"TEXT",KMPVTNUM),KMPVLN=KMPVLN+1
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 ;
 ; If not applying defaults send SUPMSG and quit
 I +$G(KMPVADEF)=0 D  Q
 .S KMPVTEXT=KMPVMKEY_" Default Value Update: Successful"
 .S KMPVTEXT(1)="Changes made to VSM MONITOR DEFAULTS file"
 .S KMPVTEXT(2)="Changes not applied to VSM CONFIGURATION file"
 .D CFGMSG^KMPVCBG("SERVER-VSMUPDEF")
 .D SUPMSG^KMPVCBG(.KMPVTEXT)
 .
 ;
 ; if applying defaults set defaults into VSM CONFIGURATION file
 S KMPVLN=1
 S KMPVTEXT(KMPVLN)="Changes successfully made to VSM MONITOR DEFAULTS file",KMPVLN=KMPVLN+1
 S KMPVSTAT=$$RESTCFG^KMPVCCFG(KMPVMKEY)
 I KMPVSTAT=0 D
 .S KMPVTEXT=KMPVMKEY_" Default Value Update: No Errors"
 .S KMPVTEXT(KMPVLN)="Changes applied to VSM CONFIGURATION file",KMPVLN=KMPVLN+1
 I KMPVSTAT>0 D
 .S KMPVTEXT=KMPVMKEY_" Default Value Update:  WITH ERRORS"
 .S KMPVTEXT(KMPVLN)="Changes NOT applied to VSM CONFIGURATION file",KMPVLN=KMPVLN+1
 ;
 ; if end state is 'ON' then reschedule
 S KMPVON=$$GETVAL^KMPVCCFG(KMPVMKEY,"ONOFF",8969)
 I KMPVON="ON" D
 .D RESCH^KMPVCBG(KMPVMKEY,.KMPVERR)
 .I '$D(KMPVERR) S KMPVTEXT(KMPVLN)="Data Transmission task successfully rescheduled",KMPVLN=KMPVLN+1
 .I $D(KMPVERR)>0 D
 ..S KMPVTEXT=KMPVMKEY_" Default Value Update: WITH ERRORS"
 ..S KMPVTEXT(KMPVLN)="Data Transmission NOT successfully rescheduled",KMPVLN=KMPVLN+1
 ..S KMPVI=""
 ..F  S KMPVI=$O(KMPVERR(KMPVI)) Q:KMPVI=""  D
 ...S KMPVTEXT(KMPVLN)=KMPVERR(KMPVI),KMPVLN=KMPVLN+1
 I KMPVON="OFF" D
 .D DESCH^KMPVCBG(KMPVMKEY,.KMPVERR)
 .S KMPVTEXT(KMPVLN)="Data Transmission task successfully unscheduled",KMPVLN=KMPVLN+1
 .I $D(KMPVERR)>0 D
 ..S KMPVTEXT=KMPVMKEY_" Configuration Update: WITH ERRORS"
 ..S KMPVTEXT(KMPVLN-1)="Data Transmission NOT successfully unscheduled",KMPVLN=KMPVLN+1
 ..S KMPVI=""
 ..F  S KMPVI=$O(KMPVERR(KMPVI)) Q:KMPVI=""  D
 ...S KMPVTEXT(KMPVLN)=KMPVERR(KMPVI),KMPVLN=KMPVLN+1
 ;
 D SUPMSG^KMPVCBG(.KMPVTEXT)
 Q
 ;
CTMLOG ; Return run history recorded in the VSM CACHE TASK LOG file
 N KMPVMKEY,KMPVML,KMPVTEXT
 N XMER
 ;
 S KMPVIEN=0,KMPVLN=1
 S KMPVTEXT(KMPVLN)="Raw data from VSM CACHE TASK LOG file",KMPVLN=KMPVLN+1
 F  S KMPVIEN=$O(^KMPV(8969.03,KMPVIEN)) Q:+KMPVIEN=0  D
 .S KMPVDATA=$G(^KMPV(8969.03,KMPVIEN,0))
 .S KMPVTEXT(KMPVLN)=KMPVDATA,KMPVLN=KMPVLN+1
 S KMPVTEXT="Task Manager Run History for "_KMPVSITE
 D DBAMSG^KMPVCBG(.KMPVTEXT)
 Q
 ;
PACKUPDT ; Get data from PACKAGE file
 N KMPVCNAM,KMPVCNS,KMPVDOM,KMPVEMAIL,KMPVIEN,KMPVIEN2,KMPVLN,KMPVPDATA,KMPVPNAM,KMPVPNS,KMPVPRE,KMPVPROD,KMPVSCD,KMPVSINF
 N X,XMSUB,XMTEXT,XMY,XMZ,Y
 S KMPVPROD=$$PROD^KMPVCCFG()
 S KMPVDOM=$P($$NETNAME^XMXUTIL(.5),"@",2) ;IA 2734
 S KMPVSITE=$$SITE^VASITE ;  IA 10112
 D GETENV^%ZOSV S KMPVSCD=$P(Y,U,1) ;  IA 10097
 S KMPVSINF=$$SITEINFO^KMPVCCFG()
 S XMSUB="VBEMPACK"
 S KMPVPRE="",KMPVLN=1
 S KMPVTEXT(KMPVLN)="SYSTEM ID="_KMPVSINF,KMPVLN=KMPVLN+1
 F  S KMPVPRE=$O(^DIC(9.4,"C",KMPVPRE)) Q:KMPVPRE=""  D
 .S KMPVIEN=""
 .; NO WAY TO DECIDE WHICH IS CORRECT SO TAKE FIRST - DON'T LOOP
 .S KMPVIEN=$O(^DIC(9.4,"C",KMPVPRE,KMPVIEN)) Q:KMPVIEN=""  D
 ..S KMPVPNAM=$P($G(^DIC(9.4,KMPVIEN,0)),"^") ;,KMPVCNAM=KMPVPNAM
 ..S KMPVTEXT(KMPVLN)="PACKINFO="_KMPVPRE_"^"_KMPVPNAM,KMPVLN=KMPVLN+1
 S XMTEXT=$S($D(KMPVTEXT):"KMPVTEXT(",1:"No package data collected")
 S KMPVEMAIL=$$GETVAL^KMPVCCFG("VBEM","VSM CFG EMAIL ADDRESS",8969) I KMPVEMAIL'="" S XMY(KMPVEMAIL)=""
 D ^XMD
 Q