GMVRPCM ; HOIFO/DP - RPC for Vitals Manager ;07/25/05 9:10am
 ;;5.0;GEN. MED. REC. - VITALS;**1,8,13,3,22**;Oct 31, 2002;Build 22
 ; Integration Agreements:
 ; #10040 [Supported] File 44 references
 ; #10076 [Supported] XUSEC Calls
 ; #2263 [Supported] XPAR Calls
 ; #2541 [Supported] XUPARAM Calls
 ; #2692 [Controlled] ORQPTQ1
 ; #3227 [Private] NURAPI Calls
 ; #4084 [Private] File 44 AC x-ref
 ; #4360 [Private] GMV MANAGER RPC
ADDQUAL ; [P] Add qualifier to vital/category
 
GMVVIT=+$P(DATA,";",1),GMVCAT=+$P(DATA,";",2),GMVQUAL=+$P(DATA,";",3)
 
I $O(^GMRD(120.52,GMVQUAL,1,"B",GMVVIT,0)) D  Q
 
.@RESULTS@(0)="1^Qualifier already assigned."
 
GMVFDA(120.521,"+1,"_GMVQUAL_",",.01)=GMVVIT
 
GMVFDA(120.521,"+1,"_GMVQUAL_",",.02)=GMVCAT
 
UPDATE^DIE("","GMVFDA","GMVIEN","GMVERR")
 
I $G(GMVIEN(1)) @RESULTS@(0)=+GMVIEN(1)_"^Qualifier Assigned"
 
E  S @RESULTS@(0)="-1^Unable to assign qualifier"
 
Q
DELQUAL ; [P] Delete qualifier from vital/category
 
GMVVIT=+$P(DATA,";",1),GMVCAT=+$P(DATA,";",2),GMVQUAL=+$P(DATA,";",3)
 
X=$O(^GMRD(120.52,GMVQUAL,1,"B",GMVVIT,0))
 
GMVFDA(120.521,X_","_GMVQUAL_",",.01)="@"
 
FILE^DIE("","GMVFDA","GMVERR")
 
I $D(GMVERR@RESULTS@(0)="-1^Unable to remove qualifier."
 
E  S @RESULTS@(0)="1^Qualifier removed."
 
Q
DELTEMP ; [P] Delete Template
 
GMVENT=$P(DATA,U,1),GMVNAME=$P(DATA,U,2)
 
I $$GET^XPAR(GMVENT,"GMV TEMPLATE DEFAULT")=GMVNAME D
 
.DEL^XPAR(GMVENT,"GMV TEMPLATE DEFAULT",1)
 
DEL^XPAR(GMVENT,"GMV TEMPLATE",GMVNAME,.GMVERR)
 
'$G(GMVERR@RESULTS@(0)="1^Template Removed."
 
E  S @RESULTS@(0)="-1^"_GMVERR
 
Q
GETCATS ; [P] Return Listing of categories
 
GMVQI
 
GMVCAT=0:0 GMVCAT=$O(^GMRD(120.52,"AA",DATA,GMVCAT)) Q:'GMVCAT  D
 
.Q:$$ACTIVE^GMVUID(120.53,"",GMVCAT_",","")
 .
GMVQUAL="",X="" F  S X=$O(^GMRD(120.52,"AA",DATA,GMVCAT,X)) Q:X=""  D
 
..GMVQI=$O(^GMRD(120.52,"AA",DATA,GMVCAT,X,0))
 ..
Q:$$ACTIVE^GMVUID(120.52,"",GMVQI_",","")
 ..
GMVQUAL=GMVQUAL_$S(GMVQUAL]"":", ",1:"")_X
 
.Y=$O(@RESULTS@(""),-1)+1
 .
@RESULTS@(Y)=GMVCAT_U_$P(^GMRD(120.53,GMVCAT,0),U)_U_GMVQUAL
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)_U_$P(^GMRD(120.51,DATA,0),U)
 
Q
GETDATA ; [P] Generic fileman data call
 ; Variable DATA = File#^IENS^Field#
 
@RESULTS@(0)=$$GET1^DIQ($P(DATA,U,1),$P(DATA,U,2),$P(DATA,U,3))
 
Q
GETDEF ; [P] Get Default Template
 
I $G(DATA)]"" D  Q
 
.X=$$GET^XPAR($P(DATA,U),"GMV TEMPLATE DEFAULT")
 .
X="" @RESULTS@(0)="-1^No Default Template"
 
.E  S @RESULTS@(0)=X
 
ENVAL^XPAR(.GMV,"GMV TEMPLATE DEFAULT")
 
X="" F  S X=$O(GMV(X)) Q:X=""  D
 
.Y=$O(@RESULTS@(""),-1)+1
 .
@RESULTS@(Y)=X_U_GMV(X,1)
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
Q
GETHILO ; [P] Returns an abnormal value
 
@RESULTS@(0)=+$$GET1^DIQ(120.57,"1,",DATA)
 
Q
GETLIST ; [P] Return listing of file
 
GMVCNT,GMVLOOP,GMVRET,^TMP("DILIST",$J)
 
GMVSCRN=""
 
+DATA=44 DATA2=$P(DATA,U,2),DATA=+DATA
 
DATA=120.51 D  ; Set screen for vitals list
 
.GMVSCRN="I $$VITALIEN^GMVUTL8()[("",""_+Y_"","")"
 
DATA=42 D  ; Screen for ward location
 
.GMVSCRN="I '$$INACT42^GMVUT2(+Y)"
 
DATA=44 D  Q  ; Clinics
 
.CNT X=DATA2,CNT=0
 .
F  S X=$O(^SC("AC","C",X)) Q:'X!(CNT>100)  D
 
..Q:+$G(^SC(X,"OOS"))
 ..
Y=$G(^SC(X,"I"))
 ..
Q:DT>+Y&($P(Y,U,2)=""!(DT<$P(Y,U,2)))
 ..
@RESULTS@($O(@RESULTS@(""),-1)+1)=DATA_";"_X_U_$P(^SC(X,0),U),CNT=CNT+1
 .
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
DATA=100.21 D  Q  ; CPRS Teams
 
.TEAMS^ORQPTQ1(.GMVRET)
 .
X=0:0 X=$O(GMVRET(X)) Q:'X  @RESULTS@(X)=DATA_";"_GMVRET(X)
 .
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
DATA=211.4 D  Q  ; NURS Locations
 
.ACTLOCS^NURAPI(.GMVRET)
 .
X=0:0 X=$O(GMVRET(X)) Q:'X  @RESULTS@(X)=DATA_";"_GMVRET(X)
 .
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
DATA=120.52 D  S @RESULTS@(0)=GMVCNT_U_$$GET1^DID(DATA,"","","NAME"Q  ;qualifiers
 
.GMVCNT=0,GMVLOOP=""
 
.F  S GMVLOOP=$O(^GMRD(120.52,"B",GMVLOOP)) Q:GMVLOOP=""  D
 
..GMVIEN=0
 ..
F  S GMVIEN=$O(^GMRD(120.52,"B",GMVLOOP,GMVIEN)) Q:'GMVIEN  D
 
...GMVNAME=$P($G(^GMRD(120.52,GMVIEN,0)),U,1)
 ...
Q:GMVNAME=""
 
...Q:$$ACTIVE^GMVUID(120.52,.01,GMVIEN_",","")  ;inactive vuid
 
...GMVCNT=GMVCNT+1
 ...
@RESULTS@(GMVCNT)="120.52;"_GMVIEN_U_GMVNAME
 
LIST^DIC(DATA,"","@;.01","P","","","","",GMVSCRN)
 
X=0:0 X=$O(^TMP("DILIST",$J,X)) Q:'X  D
 
.@RESULTS@(X)=DATA_";"_^TMP("DILIST",$J,X,0)
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)_U_$$GET1^DID(DATA,"","","NAME")
 
^TMP("DILIST",$J)
 
Q
GETQUAL ; [P] Return qualifiers list
 ; DATA=VitalIEN;CatIEN
 ; Uses X-ref of ^GMRD(120.52,"AA",VitalIEN,CategoryIEN,QName,QIEN)
 
GMVIT=+$P(DATA,";",1),GMVCAT=+$P(DATA,";",2)
 
'$D(^GMRD(120.53,GMVCAT,0)) @RESULTS@(0)="-1^No such category" Q
 I $$
ACTIVE^GMVUID(120.53,"",GMVCAT_",",""@RESULTS@(0)="-1^Inactive category" Q
 I 
'$D(^GMRD(120.51,GMVIT,0)) @RESULTS@(0)="-1^No such vital" Q
 I $$
ACTIVE^GMVUID(120.51,"",GMVIT_",",""@RESULTS@(0)="-1^Inactive vital type" Q
 S 
GMVNAM=""
 
F  S GMVNAM=$O(^GMRD(120.52,"AA",GMVIT,GMVCAT,GMVNAM)) Q:GMVNAM=""  D
 
.GMVIEN=$O(^GMRD(120.52,"AA",GMVIT,GMVCAT,GMVNAM,0))  ; Assume only one of this name
 
.Q:$$ACTIVE^GMVUID(120.52,"",GMVIEN_",","")
 .
Y=$O(@RESULTS@(""),-1)+1
 .
@RESULTS@(Y)=GMVIEN_U_GMVNAM
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)_U_$P(^GMRD(120.53,GMVCAT,0),U)
 
Q
GETTEMP ; [P] Get Template List
 
I $G(DATA)]"" D
 
.GMVENT=$$ENTITY($P(DATA,U,1)),GMVNAME=$P(DATA,U,2)
 .
GMVNAME="" D
 
..GETLST^XPAR(.GMVTMP,GMVENT,"GMV TEMPLATE")
 ..
X=0:0 X=$O(GMVTMP(X)) Q:'X  D
 
...GMV(GMVENT,$P(GMVTMP(X),U,1))=$P(GMVTMP(X),U,2,10)
 .
GMVNAME]"" GMV(GMVENT,GMVNAME)=$$GET^XPAR(GMVENT,"GMV TEMPLATE",GMVNAME)
 
I $G(DATA)="" ENVAL^XPAR(.GMV,"GMV TEMPLATE")
 
GMVENT="",GMVNAME=""
 
F  S GMVENT=$O(GMV(GMVENT)) Q:GMVENT=""  D
 
.GMVROOT=$P(GMVENT,";",2),GMVTYPE=$$TYPE(GMVROOT),GMVIEN=+GMVENT
 
.Q:GMVTYPE=0  ;unknown template type
 
.Q:GMVROOT="VA(200,"&('$$GET^XPAR("SYS","GMV ALLOW USER TEMPLATES"))
 .
GMVROOT="VA(200,"&(GMVIEN'=DUZQ:'$D(^XUSEC("GMV MANAGER",DUZ))
 .
F  S GMVNAME=$O(GMV(GMVENT,GMVNAME)) Q:GMVNAME=""  D
 
..GMVOWNER=$P($G(@(U_GMVROOT_(+GMVIEN)_",0)"),"Unk"),U)
 ..
Y=$O(@RESULTS@(""),-1)+1
 ..
@RESULTS@(Y)=GMVTYPE_U_GMVENT_U_GMVOWNER_U_GMVNAME_U_GMV(GMVENT,GMVNAME)
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
Q
LOOKUP ; [P] Does a lookup on a file
 
GMVSCRN
 
GMVSCRN=$S(+DATA=44:"I "_"""^C^W^"""_"[$P(^(0),U,3)",1:"")
 
I $P(DATA,"^",3)="" GMVFLD="@;.01"
 
E  S GMVFLD="@;"_$P(DATA,"^",3)
 
GMVFLD=$P(GMVFLD,";",1,5) ; Limit lookup to 4 display fields
 
FIND^DIC(+DATA,"",GMVFLD,"P",$P(DATA,"^",2),61,,GMVSCRN)
 
^TMP("DILIST",$J,0)<1 D  Q
 
.@RESULTS@(0)="-1^No entries found matching '"_$P(DATA,U,2)_"'."
 
^TMP("DILIST",$J,0)>60 D  Q
 
.@RESULTS@(0)="-1^Too many matches found, please be more specific."
 
X=0:0 X=$O(^TMP("DILIST",$J,X)) Q:'X  D
 
.@RESULTS@(X)=+DATA_";"_^TMP("DILIST",$J,X,0)
 
@RESULTS@(0)=+$O(@RESULTS@(""),-1)
 
Q
NEWQUAL ; [P] Create New Qualifier
 
@RESULTS@(0)="-1^Use the New Term Rapid Turnaround (NTRT) process to add qualifiers"
 
Q
NEWTEMP ; [P] New Template
 
GMVENT=$P(DATA,"^",1),GMVNAME=$P(DATA,"^",2),GMVDESC=$P(DATA,"^",3)
 
GMVENT=$$ENTITY(GMVENT)
 
GMVTYPE=$$TYPE($P(GMVENT,";",2))
 
GMVOWN=$P($G(@(U_$P(GMVENT,";",2)_+GMVENT_",0)"),"Unk"),U)
 
S:GMVDESC="" GMVDESC="No Description"
 
ADD^XPAR(GMVENT,"GMV TEMPLATE",GMVNAME,GMVDESC,.GMVERR)
 
'GMVERR @RESULTS@(0)=GMVTYPE_U_GMVENT_U_GMVOWN_U_GMVNAME
 
E  S @RESULTS@(0)="-1^"_GMVERR
 
Q
RENTEMP ; [P] Rename a Template
 
GMVENT=$P(DATA,U,1),GMVOLD=$P(DATA,U,2),GMVNEW=$P(DATA,U,3)
 
REP^XPAR(GMVENT,"GMV TEMPLATE",GMVOLD,GMVNEW,.GMVERR)
 
'GMVERR @RESULTS@(0)="1^Renamed"
 
E  S @RESULTS@(0)="-1^"_GMVERR Q
 
; Reset default template if this was a default template
 
D:$$GET^XPAR(GMVENT,"GMV TEMPLATE DEFAULT")=GMVOLD
 
.EN^XPAR(GMVENT,"GMV TEMPLATE DEFAULT",1,GMVNEW)
 
Q
RPC(RESULTS,OPTION,DATA) ; [Procedure] Main RPC call tag
 ; RPC: [GMV MANAGER]
 ;
 ; Input parameters
 ;  1. RESULTS [Reference/Required] RPC Return array
 ;  2. OPTION [Literal/Required] RPC Option to execute
 ;  3. DATA [Literal/Required] Other data as required for call
 ;
 
GMV,GMVCAT,GMVDESC,GMVENT,GMVERR,GMVFDA,GMVFLD,GMVIEN,GMVIT,GMVNAM,GMVNAME,GMVNEW,GMVOLD,GMVOWN,GMVOWNER,GMVQUAL,GMVROOT,GMVTYPE,GMVVAL,GMVVIT,GMVSCRN
 
RESULTS=$NA(^TMP("GMVMGR",$J)) @RESULTS
 
D:$T(@OPTION)]"" @OPTION
 
S:'$D(@RESULTS) @RESULTS@(0)="-1^No results returned"
 
CLEAN^DILF
 
Q
SETDATA ; [P] Save New Qualifier Name/Abbv
 
@RESULTS@(0)="-1^Use the New Term Rapid Turnaround (NTRT) process to add qualifiers"
 
Q
SETDEF ; [P] Set Default Template
 
EN^XPAR($P(DATA,U),"GMV TEMPLATE DEFAULT",1,$P(DATA,U,2),.GMVERR)
 
'$G(GMVERR@RESULTS@(0)="1^Set As Default."
 
E  S @RESULTS@(0)="-1^"_GMVERR
 
Q
SETHILO ; [P] Set abnormal value
 
+(^GMRD(120.57,0)):5
 
E  S @RESULTS@(0)="-1^Site File In Use." Q
 S 
GMVFLD=$P(DATA,"^",1),GMVVAL=$P(DATA,"^",2)
 
GMVFDA(120.57,"1,",GMVFLD)=GMVVAL
 
FILE^DIE("","GMVFDA","GMVERR")
 
-(^GMRD(120.57,0))
 
@RESULTS@(0)="1^Update Complete."
 
Q
SETTEMP ; [P] Set Template data
 
EN^XPAR($P(DATA,U),"GMV TEMPLATE",$P(DATA,U,2),$P(DATA,U,3),.GMVERR)
 
'$G(GMVERR@RESULTS@(0)="1^Template Saved."
 
E  S @RESULTS@(0)="-1^"_GMVERR
 
Q
VALID ; [P] Verify data validity against fileman
 
VAL^DIE($P(DATA,U,1),$P(DATA,U,2),$P(DATA,U,3),"H",$P(DATA,U,4),.GMVRET)
 
GMVRET'="^" @RESULTS@(0)="1^Valid Data"
 
E  S @RESULTS@(0)="-1^"_^TMP("DIERR",$J,1,"TEXT",1)
 
Q
ENTITY(X) ; [Function] Convert USR, SYS, and DIV entities
 ; Input parameters
 ;  1. X [Literal/Required] XPAR generic entity to transform to variable pointer format
 ;
 
Q:X="USR" DUZ_";VA(200,"
 
Q:X="SYS" $$FIND1^DIC(4.2,"","QX",$$KSP^XUPARAM("WHERE"))_";DIC(4.2,"
 
Q:X="DIV" DUZ(2)_";DIC(4,"
 
X
 
;
TYPE(X) ; [F] Returns the type of template
 ; Input parameters
 ;  1. X [Literal/Required] Variable pointer to evaluate
 ;
 
Q:X="DIC(4.2," ;Domain
 
Q:X="DIC(4," ;  Institution
 
Q:X="SC(" ;     Hospital Location
 
Q:X="VA(200," ; New Person
 
;             Unknown
 ;
VT ;VitalTypeIENS
 
X,Y,Z
 
Y=0,@RESULTS@(0)="-1"
 
X="T","P","R","BP","HT","WT","PN","PO2","CVP","CG" D
 
.Z=$O(^GMRD(120.51,"C",X,0))
 .
Q:'Z
 
.Y=Y+1,@RESULTS@(Y)=Z
 
Q