HMPTOOLS ;ASMR/JD - More HMP utilities ; 9/25/15 10:59am
;;2.0;ENTERPRISE HEALTH MANAGEMENT PLATFORM;**2**;Sep 01, 2011;Build 28
;Per VA Directive 6402, this routine should not be modified.
CHKXTMP(RSLT) ; RPC(HMP CHKXTMP) to return the state of ^XTMP data
; RSLT - Return array:
; "There are a total of xxx patients in queue. yyy Complete zzz Staging"
; Where xxx,yyy, and zzz are zero or greater.
; NOTE: If xxx is zero, then the sentence after "queue." will NOT be displayed
; Goes through ^XTMP and figures out the total number of patients, how many
; have completed data staging, and how many are still staging.
; There is code to allow a bit more information than requested to be stored
; in a global (^TMP("FINDSTATUS",$J)) for future needs (e.g. Complete/staging
; is broken down by domain). *** This currently commented out ***.
; ^XTMP("HMPFX~<server id>~DFN",0,"status",<domain>)=STATUS, where STATUS=1 means
; data is completely staged and 0 means data is being staged but not complete yet.
; GLB = ^TMP("FINDSTATUS",$J) (FUTURE USE)
; HMPBAT = "HMPFX~<sever id>~DFN"
; HMPCM = Number of patients who have completed staging
; HMPCMP = Number of domains that have completed staging for a patient
; HMPCNT = Domain status (1 = complete; 0 = staging)
; HMPDFN = Patient IEN
; HMPDOM = Patient domain (e.g. lab, med, allergy, etc.)
; HMPST = Number of patients who are still in the staging state
; HMPSTG = Number of domains that are still staging for a patient
; HMPT = HMPCM+HMPST
F S HMPBAT=$O(^XTMP(HMPBAT)) Q:$E(HMPBAT,1,5)'="HMPFX" D
.I HMPDFN'=+HMPDFN Q ; Patients ONLY!
.F S HMPDOM=$O(^XTMP(HMPBAT,0,"status",HMPDOM)) Q:HMPDOM']"" D
..I HMPCNT=1 D
..I HMPCNT'=1 D
.I HMPSTG>0 D
.I HMPSTG'>0 D
S RSLT(1)="There are a total of "_HMPT_" patient"_$S(HMPT=1:"",1:"s")_" in queue."
I HMPCM>0 S RSLT(1)=RSLT(1)_" "_HMPCM_" Complete"
I HMPST>0 S RSLT(1)=RSLT(1)_" "_HMPST_" Staging"
MON ; Monitor the progress of ^XTMP growth. JD - 6/11/15
F Q:DONE'=-1 D
.W @IOF,"eHMP usage of ^XTMP = "_SIZE_" kilo byte(s)"
.W !!,"Hit any key to exit the monitor"
.X "R *DONE:2"
SIZE(RSLT) ; calculate the size of XTMP global
GETSIZE(HMPMODE,HMPSRVN) ; -- return current aggregate extract size for extracts waiting to be sent to HMP servers
; input: HMPMODE := [ estimate - use estimated domain average sizes (default) |
; actual - walk though object nodes to calculate using $LENGTH ]
; HMPSRVN := name of HMP server [optional - defaults to all HMP servers]
; returns: total size in bytes ^ object count
; -- loop thru extracts for server(s)
F S BATCH=$O(^XTMP(BATCH)) Q:$E(BATCH,1,$L(ROOT))'=ROOT D
. S TASK=0 F S TASK=$O(^XTMP(BATCH,TASK)) Q:'TASK D
. . S DOMAIN="" F S DOMAIN=$O(^XTMP(BATCH,TASK,DOMAIN)) Q:DOMAIN="" D
. . . S OBJS=+$O(^XTMP(BATCH,TASK,DOMAIN," "),-1)
. . . S OBJCNT=OBJCNT+OBJS
. . . S TOTAL=TOTAL+$$WALK(BATCH,TASK,DOMAIN) Q
. . . S TOTAL=TOTAL+(OBJS*$G(OBJSIZES($P(DOMAIN,"#")),1000))
WALK(BATCH,TASK,DOMAIN) ; -- walk through domain objectS in task to get actual size
F S OBJ=$O(^XTMP(BATCH,TASK,DOMAIN,OBJ)) Q:'OBJ D
. S NODE=0 F S NODE=$O(^XTMP(BATCH,TASK,DOMAIN,OBJ,NODE)) Q:'NODE S SIZE=SIZE+$L($G(^(NODE)))
;Create a message (M) in JSON format with a qualifier (Q)
; M - Message text - The paramater is message being reported for instance "DFN" could the message
; Q - Qualifier: - The quailifier is reporting where the JSON message is Required or Invalid.
; 1 - Required
; 2 - Invalid
; V - If Q=1, then V is ignored (or not passed in)
; If Q=2, then V=<the invalid value>
I Q=1 S TEXT=M_" is required"
I Q=2 S TEXT="Invalid "_M_": "_V
S ERRMSG("Message")=TEXT D ENCODE^HMPJSON("ERRMSG","RSLT","JSONERR")
I $G(JSONERR) S RSLT(1)=JSONERR