GMVGETD ;HOIFO/YH,FT-EXTRACTS WARD/ROOM-BED/PT AND PT VITALS ;5/10/07
;;5.0;GEN. MED. REC. - VITALS;**3,22,23**;Oct 31, 2002;Build 25
;
; This routine uses the following IAs:
; #1380 - ^DG(405.4 references (controlled)
; #1377 - ^DIC(42 references (controlled)
; #4290 - ^PXRMINDX global (controlled)
; #10035 - FILE 2 references (supported)
; #10039 - FILE 42 references (supported)
; #10103 - ^XLFDT calls (supported)
; #10104 - ^XLFSTR calls (supported)
;
; This routine supports the following IAs:
; #4416 - GMV EXTRACT REC RPC is called at GETVM (private)
; #4358 - GMV LATEST VM RPC is called at GETLAT (private)
;
GETVM(RESULT,GMRVDATA) ;GMV EXTRACT REC [RPC entry point]
; Returns data particular patient and date/time range in RESULT
; GMRVDATA = DFN^END DATE VITAL TAKEN^VITAL TYPE (OPTIONAL)^START DATE VITAL TAKEN
N DFN,GMVEND,GMVSTART,GMVTYPE
S DFN=+$P(GMRVDATA,U,1),GMVEND=+$P(GMRVDATA,U,2),GMVSTART=$P(GMRVDATA,U,4),GMVTYPE=$P(GMRVDATA,U,3)
K ^TMP($J,"GRPC")
S:GMVEND="" GMVEND=$$NOW^XLFDT()
I $P(GMVEND,".",2)'>0 S GMVEND=$P(GMVEND,".",1)_".235959"
I GMVSTART="" S GMVSTART=0
S:GMVTYPE'="" GMVTYPE(1)=$P(^GMRD(120.51,$O(^GMRD(120.51,"C",GMVTYPE,0)),0),"^")
D EN1^GMVGETD1
I '$D(^TMP($J,"GRPC")) S ^TMP($J,"GRPC",1)="0^NO "_$S(GMVTYPE'="":GMVTYPE(1),1:"VITALS/MEASUREMENTS ")_" ENTERED WITHIN THIS PERIOD"
S RESULT=$NA(^TMP($J,"GRPC"))
K GMRDT,GMRVARY,GMRVITY,GMRVX,GMRZZ
Q
GETLAT(RESULT,GMRDFN) ;GMV LATEST VM [RPC entry point]
; RETURNS THE LATEST VITALS/MEASUREMENTS FOR A GIVEN PATIENT(GMRDFN)
; IN RESULT ARRAY.
K ^TMP($J,"GRPC") D EN1^GMVLAT0(GMRDFN)
S RESULT=$NA(^TMP($J,"GRPC"))
Q
WARDLOC(RESULT,DUMMY) ;GMV WARD LOCATION [RPC entry point]
;RETURNS MAS WARD LOCATIONS IN RESULT ARRAY
K ^TMP($J,"GWARD"),^TMP($J,"GMRV") N GMRWARD,GINDEX,GN,GMR
S DUMMY=$G(DUMMY)
S DUMMY=$$UP^XLFSTR(DUMMY)
S DUMMY=$S(DUMMY="P":"P",1:"A")
D LIST^DIC(42,"","","","*","","","","I '$$INACT42^GMVUT2(+Y)",,"^TMP($J,""GMRV"")")
S GINDEX=+$P($G(^TMP($J,"GMRV","DILIST",0)),"^")
I GINDEX>0 D
. S (GMR,GN)=0 F S GN=$O(^TMP($J,"GMRV","DILIST",1,GN)) Q:GN'>0 D
. . S GMRWARD(1)=^TMP($J,"GMRV","DILIST",1,GN),GMRWARD=+^TMP($J,"GMRV","DILIST",2,GN)
. . I DUMMY="P" D Q
. . . I $O(^DPT("CN",GMRWARD(1),0))>0 S GMR=GMR+1,^TMP($J,"GWARD",GMR)=GMRWARD_"^"_GMRWARD(1)_U_^DIC(42,GMRWARD,44)
. . I DUMMY="A" D
. . . S GMR=GMR+1,^TMP($J,"GWARD",GMR)=GMRWARD_"^"_GMRWARD(1)_U_^DIC(42,GMRWARD,44)
K ^TMP($J,"GMRV") S RESULT=$NA(^TMP($J,"GWARD"))
Q
WARDPT(RESULT,GMRWARD) ;GMV WARD PT [RPC entry point]
;RETURNS A LIST OF PATIENTS ADMITTED TO A GIVEN MAS WARD(GMRWARD) IN RESULT ARRAY.
Q:'$D(^DPT("CN",GMRWARD))
N OUT,GN,DFN,DFN1,GMVPAT
K ^TMP($J,"GMRPT")
S (GN,DFN)=0 F S DFN=$O(^DPT("CN",GMRWARD,DFN)) Q:DFN'>0 D
. I $D(^DPT(DFN,0)) D
. . S GMVPAT=""
. . D PTINFO^GMVUTL3(.GMVPAT,DFN)
. . S OUT($P(^DPT(DFN,0),"^"),DFN)=DFN_"^"_$P(^DPT(DFN,0),"^")_"^"_GMVPAT
I '$D(OUT) Q
S DFN=""
F S DFN=$O(OUT(DFN)) Q:DFN="" D
.S DFN1=0
.F S DFN1=$O(OUT(DFN,DFN1)) Q:'DFN1 D
..S GN=GN+1,^TMP($J,"GMRPT",GN)=OUT(DFN,DFN1)
..Q
.Q
S RESULT=$NA(^TMP($J,"GMRPT"))
Q
ROOMBED(RESULT,GMRWARD) ;GMV ROOM/BED [RPC entry point]
;RETURNS A LIST OF ROOMS/BEDS FOR A GIVEN MAS WARD(GMRWARD) IN RESULT ARRAY.
Q:'$D(^DIC(42,"B",GMRWARD))
N GN,GROOM,GWARD,GMVTMP K ^TMP($J,"GROOM")
S (GN,GROOM)=0,GWARD=$O(^DIC(42,"B",GMRWARD,0)) I GWARD'>0 S ^TMP($J,"GROOM",1)="NO ROOM" G QUIT
F S GROOM=$O(^DG(405.4,"W",GWARD,GROOM)) Q:GROOM'>0 I $D(^DG(405.4,GROOM)) D
. S GMVTMP($P($P(^DG(405.4,GROOM,0),"^"),"-",1))=GROOM
. ;S GN=GN+1,^TMP($J,"GROOM",GN)=GROOM_"^"_$P(^DG(405.4,GROOM,0),"^")
. Q
S GROOM="",GN=0
F S GROOM=$O(GMVTMP(GROOM)) Q:GROOM="" D
. S GN=GN+1,^TMP($J,"GROOM",GN)=GMVTMP(GROOM)_"^"_GROOM
. Q
QUIT S RESULT=$NA(^TMP($J,"GROOM"))
Q
CLOSEST(RESULT,GMVDFN,GMVDT,GMVT,GMVFLAG) ; GMV CLOSEST READING [RPC entry point]
; Get nearest reading to date(/time) provided
; Input: GMVDFN - DFN (required)
; GMVDT - FileMan date/time (optional)
; Default is NOW
; GMVT - Vital Type abbreviation, FILE 120.51, Field 1 (required)
; GMVFLAG - Where to look (optional)
; 0 = either before or after GMVDT (default)
; 1 = before GMVDT
; 2 = after GMVDT
; Output: RESULT - piece1^piece2
; where piece1 = date/time of reading (FileMan internal format)
; piece2 = reading
; If no records found piece 1 = -2
; and piece 2 = message text
; If an error was encountered piece1 = -1
; and piece2 = error message
;
N GMVADIFF,GMVADT,GMVAVAL,GMVBDIFF,GMVBDT,GMVBVAL,GMVDATA,GMVTI
S GMVDFN=+$G(GMVDFN),GMVDT=+$G(GMVDT),GMVT=$G(GMVT),GMVFLAG=+$G(GMVFLAG)
S GMVFLAG=$S(GMVFLAG=2:2,GMVFLAG=1:1,1:0)
I 'GMVDFN S RESULT="-1^DFN not defined" Q
I '$D(^PXRMINDX(120.5,"PI",GMVDFN)) S RESULT="-2^Patient has no Vitals data on file" Q
I 'GMVDT S GMVDT=$$NOW^XLFDT()
I GMVT="" S RESULT="-1^Vital Type not defined" Q
S GMVTI=$$GETIEN^GMVGETVT(GMVT,2)
I 'GMVTI S RESULT="-1^Vital Type not found" Q
I '$D(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI)) S RESULT="-2^Patient has no data on file for this type" Q
S (GMVADT,GMVAVAL,GMVBDT,GMVBVAL,GMVDATA)=""
I GMVFLAG=0!(GMVFLAG=1) D
.S GMVDATA=$$FIND(GMVDFN,GMVTI,GMVDT,0,-1)
.S GMVBDT=$P(GMVDATA,U,1),GMVBVAL=$P(GMVDATA,U,2)
S GMVDATA=""
I GMVFLAG=0!(GMVFLAG=2) D
.S GMVDATA=$$FIND(GMVDFN,GMVTI,GMVDT,0,1)
.S GMVADT=$P(GMVDATA,U,1),GMVAVAL=$P(GMVDATA,U,2)
I GMVFLAG=1 D
.I GMVBDT'>0 S RESULT="-2^Before date not found" Q
.I GMVBVAL="" S RESULT="-2^Before value not found" Q
.S RESULT=GMVBDT_U_GMVBVAL
I GMVFLAG=2 D
.I GMVADT'>0 S RESULT="-2^After date not found" Q
.I GMVAVAL="" S RESULT="-2^After value not found" Q
.S RESULT=GMVADT_U_GMVAVAL
I GMVFLAG=0 D
.I GMVADT'>0,GMVBDT'>0 D Q
..S RESULT="-2^No records found"
.I GMVADT'>0,GMVBDT>0 D Q
..S:GMVBVAL]"" RESULT=GMVBDT_U_GMVBVAL
..S:GMVBVAL="" RESULT="-2^No records found"
.I GMVADT>0,GMVBDT'>0 D Q
..S:GMVAVAL]"" RESULT=GMVADT_U_GMVAVAL
..S:GMVAVAL="" RESULT="-2^No records found"
.I GMVADT>0,GMVBDT>0 D
..S GMVBDIFF=+$$FMDIFF^XLFDT(GMVDT,GMVBDT,2)
..S GMVADIFF=+$$FMDIFF^XLFDT(GMVADT,GMVDT,2)
..I GMVBDIFF<GMVADIFF S RESULT=GMVBDT_U_GMVBVAL
..I GMVADIFF<GMVBDIFF S RESULT=GMVADT_U_GMVAVAL
..I GMVADIFF=GMVBDIFF S RESULT=GMVADT_U_GMVAVAL
Q
FIND(GMVDFN,GMVTI,GMVSDT,GMVX,GMVDIR) ; Get nearest record from GMVSDT date/time
; Input: GMVDFN - DFN (required)
; GMVTI - Vital Type (120.51) IEN (required)
; GMVSDT - FileMan date/time (optional)
; Default is NOW
; GMVX - Return numeric values only or all values including
; text (optional)
; 0 = numeric values only (default)
; 1 = all values including text
; GMVDIR - direction of search (required)
; -1 = look before GMVSDT
; 1 = look after GMVSDT
; Output: GMVY - piece1^piece2
; where piece1 = date/time of reading (FileMan internal format)
; piece2 = reading
; If an error was encountered piece1 = -1
; and piece2 = error message
;
N GMVARR,GMVFLAG,GMVIEN,GMVY
S GMVDFN=+$G(GMVDFN),GMVTI=+$G(GMVTI),GMVSDT=+$G(GMVSDT),GMVX=+$G(GMVX),GMVDIR=$G(GMVDIR)
S GMVDIR=$S(GMVDIR=-1:-1,GMVDIR=1:1,1:"")
I GMVDIR="" Q "-1^Direction of search not defined"
I 'GMVTI Q "-1^Vital Type not defined"
S GMVX=$S(GMVX=1:1,1:0)
I 'GMVDFN Q "-1^Patient not defined"
I '$D(^PXRMINDX(120.5,"PI",GMVDFN)) Q "-1^Patient has no Vitals data on file"
I 'GMVSDT S GMVSDT=$$NOW^XLFDT()
S (GMVFLAG,GMVIEN)=0,GMVY=""
F S GMVSDT=$O(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI,GMVSDT),GMVDIR) Q:'GMVSDT!(GMVFLAG) D
.S GMVIEN=0
.F S GMVIEN=$O(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI,GMVSDT,GMVIEN)) Q:$L(GMVIEN)'>0!(GMVFLAG) D
..I GMVIEN=+GMVIEN D
...D F1205^GMVUTL(.GMVARR,GMVIEN,0)
..I GMVIEN'=+GMVIEN D
...D CLIO^GMVUTL(.GMVARR,GMVIEN)
..S GMVARR(0)=$G(GMVARR(0))
..Q:$P(GMVARR(0),U,8)=""
..Q:$P(GMVARR(0),U,1)'>0
..I GMVX=1 D
...S GMVY=$P(GMVARR(0),U,1)_U_$P(GMVARR(0),U,8),GMVFLAG=1
..I 'GMVX D
...I "UNAVAILABLEPASSREFUSED"[$$UP^XLFSTR($P(GMVARR(0),U,8)) Q
...S GMVY=$P(GMVARR(0),U,1)_U_$P(GMVARR(0),U,8),GMVFLAG=1
I GMVY="" S GMVY="-1^No record found"
Q GMVY
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HGMVGETD 8619 printed Dec 13, 2024@01:58:48 Page 2
GMVGETD ;HOIFO/YH,FT-EXTRACTS WARD/ROOM-BED/PT AND PT VITALS ;5/10/07
+1 ;;5.0;GEN. MED. REC. - VITALS;**3,22,23**;Oct 31, 2002;Build 25
+2 ;
+3 ; This routine uses the following IAs:
+4 ; #1380 - ^DG(405.4 references (controlled)
+5 ; #1377 - ^DIC(42 references (controlled)
+6 ; #4290 - ^PXRMINDX global (controlled)
+7 ; #10035 - FILE 2 references (supported)
+8 ; #10039 - FILE 42 references (supported)
+9 ; #10103 - ^XLFDT calls (supported)
+10 ; #10104 - ^XLFSTR calls (supported)
+11 ;
+12 ; This routine supports the following IAs:
+13 ; #4416 - GMV EXTRACT REC RPC is called at GETVM (private)
+14 ; #4358 - GMV LATEST VM RPC is called at GETLAT (private)
+15 ;
GETVM(RESULT,GMRVDATA) ;GMV EXTRACT REC [RPC entry point]
+1 ; Returns data particular patient and date/time range in RESULT
+2 ; GMRVDATA = DFN^END DATE VITAL TAKEN^VITAL TYPE (OPTIONAL)^START DATE VITAL TAKEN
+3 NEW DFN,GMVEND,GMVSTART,GMVTYPE
+4 SET DFN=+$PIECE(GMRVDATA,U,1)
SET GMVEND=+$PIECE(GMRVDATA,U,2)
SET GMVSTART=$PIECE(GMRVDATA,U,4)
SET GMVTYPE=$PIECE(GMRVDATA,U,3)
+5 KILL ^TMP($JOB,"GRPC")
+6 if GMVEND=""
SET GMVEND=$$NOW^XLFDT()
+7 IF $PIECE(GMVEND,".",2)'>0
SET GMVEND=$PIECE(GMVEND,".",1)_".235959"
+8 IF GMVSTART=""
SET GMVSTART=0
+9 if GMVTYPE'=""
SET GMVTYPE(1)=$PIECE(^GMRD(120.51,$ORDER(^GMRD(120.51,"C",GMVTYPE,0)),0),"^")
+10 DO EN1^GMVGETD1
+11 IF '$DATA(^TMP($JOB,"GRPC"))
SET ^TMP($JOB,"GRPC",1)="0^NO "_$SELECT(GMVTYPE'="":GMVTYPE(1),1:"VITALS/MEASUREMENTS ")_" ENTERED WITHIN THIS PERIOD"
+12 SET RESULT=$NAME(^TMP($JOB,"GRPC"))
+13 KILL GMRDT,GMRVARY,GMRVITY,GMRVX,GMRZZ
+14 QUIT
GETLAT(RESULT,GMRDFN) ;GMV LATEST VM [RPC entry point]
+1 ; RETURNS THE LATEST VITALS/MEASUREMENTS FOR A GIVEN PATIENT(GMRDFN)
+2 ; IN RESULT ARRAY.
+3 KILL ^TMP($JOB,"GRPC")
DO EN1^GMVLAT0(GMRDFN)
+4 SET RESULT=$NAME(^TMP($JOB,"GRPC"))
+5 QUIT
WARDLOC(RESULT,DUMMY) ;GMV WARD LOCATION [RPC entry point]
+1 ;RETURNS MAS WARD LOCATIONS IN RESULT ARRAY
+2 KILL ^TMP($JOB,"GWARD"),^TMP($JOB,"GMRV")
NEW GMRWARD,GINDEX,GN,GMR
+3 SET DUMMY=$GET(DUMMY)
+4 SET DUMMY=$$UP^XLFSTR(DUMMY)
+5 SET DUMMY=$SELECT(DUMMY="P":"P",1:"A")
+6 DO LIST^DIC(42,"","","","*","","","","I '$$INACT42^GMVUT2(+Y)",,"^TMP($J,""GMRV"")")
+7 SET GINDEX=+$PIECE($GET(^TMP($JOB,"GMRV","DILIST",0)),"^")
+8 IF GINDEX>0
Begin DoDot:1
+9 SET (GMR,GN)=0
FOR
SET GN=$ORDER(^TMP($JOB,"GMRV","DILIST",1,GN))
if GN'>0
QUIT
Begin DoDot:2
+10 SET GMRWARD(1)=^TMP($JOB,"GMRV","DILIST",1,GN)
SET GMRWARD=+^TMP($JOB,"GMRV","DILIST",2,GN)
+11 IF DUMMY="P"
Begin DoDot:3
+12 IF $ORDER(^DPT("CN",GMRWARD(1),0))>0
SET GMR=GMR+1
SET ^TMP($JOB,"GWARD",GMR)=GMRWARD_"^"_GMRWARD(1)_U_^DIC(42,GMRWARD,44)
End DoDot:3
QUIT
+13 IF DUMMY="A"
Begin DoDot:3
+14 SET GMR=GMR+1
SET ^TMP($JOB,"GWARD",GMR)=GMRWARD_"^"_GMRWARD(1)_U_^DIC(42,GMRWARD,44)
End DoDot:3
End DoDot:2
End DoDot:1
+15 KILL ^TMP($JOB,"GMRV")
SET RESULT=$NAME(^TMP($JOB,"GWARD"))
+16 QUIT
WARDPT(RESULT,GMRWARD) ;GMV WARD PT [RPC entry point]
+1 ;RETURNS A LIST OF PATIENTS ADMITTED TO A GIVEN MAS WARD(GMRWARD) IN RESULT ARRAY.
+2 if '$DATA(^DPT("CN",GMRWARD))
QUIT
+3 NEW OUT,GN,DFN,DFN1,GMVPAT
+4 KILL ^TMP($JOB,"GMRPT")
+5 SET (GN,DFN)=0
FOR
SET DFN=$ORDER(^DPT("CN",GMRWARD,DFN))
if DFN'>0
QUIT
Begin DoDot:1
+6 IF $DATA(^DPT(DFN,0))
Begin DoDot:2
+7 SET GMVPAT=""
+8 DO PTINFO^GMVUTL3(.GMVPAT,DFN)
+9 SET OUT($PIECE(^DPT(DFN,0),"^"),DFN)=DFN_"^"_$PIECE(^DPT(DFN,0),"^")_"^"_GMVPAT
End DoDot:2
End DoDot:1
+10 IF '$DATA(OUT)
QUIT
+11 SET DFN=""
+12 FOR
SET DFN=$ORDER(OUT(DFN))
if DFN=""
QUIT
Begin DoDot:1
+13 SET DFN1=0
+14 FOR
SET DFN1=$ORDER(OUT(DFN,DFN1))
if 'DFN1
QUIT
Begin DoDot:2
+15 SET GN=GN+1
SET ^TMP($JOB,"GMRPT",GN)=OUT(DFN,DFN1)
+16 QUIT
End DoDot:2
+17 QUIT
End DoDot:1
+18 SET RESULT=$NAME(^TMP($JOB,"GMRPT"))
+19 QUIT
ROOMBED(RESULT,GMRWARD) ;GMV ROOM/BED [RPC entry point]
+1 ;RETURNS A LIST OF ROOMS/BEDS FOR A GIVEN MAS WARD(GMRWARD) IN RESULT ARRAY.
+2 if '$DATA(^DIC(42,"B",GMRWARD))
QUIT
+3 NEW GN,GROOM,GWARD,GMVTMP
KILL ^TMP($JOB,"GROOM")
+4 SET (GN,GROOM)=0
SET GWARD=$ORDER(^DIC(42,"B",GMRWARD,0))
IF GWARD'>0
SET ^TMP($JOB,"GROOM",1)="NO ROOM"
GOTO QUIT
+5 FOR
SET GROOM=$ORDER(^DG(405.4,"W",GWARD,GROOM))
if GROOM'>0
QUIT
IF $DATA(^DG(405.4,GROOM))
Begin DoDot:1
+6 SET GMVTMP($PIECE($PIECE(^DG(405.4,GROOM,0),"^"),"-",1))=GROOM
+7 ;S GN=GN+1,^TMP($J,"GROOM",GN)=GROOM_"^"_$P(^DG(405.4,GROOM,0),"^")
+8 QUIT
End DoDot:1
+9 SET GROOM=""
SET GN=0
+10 FOR
SET GROOM=$ORDER(GMVTMP(GROOM))
if GROOM=""
QUIT
Begin DoDot:1
+11 SET GN=GN+1
SET ^TMP($JOB,"GROOM",GN)=GMVTMP(GROOM)_"^"_GROOM
+12 QUIT
End DoDot:1
QUIT SET RESULT=$NAME(^TMP($JOB,"GROOM"))
+1 QUIT
CLOSEST(RESULT,GMVDFN,GMVDT,GMVT,GMVFLAG) ; GMV CLOSEST READING [RPC entry point]
+1 ; Get nearest reading to date(/time) provided
+2 ; Input: GMVDFN - DFN (required)
+3 ; GMVDT - FileMan date/time (optional)
+4 ; Default is NOW
+5 ; GMVT - Vital Type abbreviation, FILE 120.51, Field 1 (required)
+6 ; GMVFLAG - Where to look (optional)
+7 ; 0 = either before or after GMVDT (default)
+8 ; 1 = before GMVDT
+9 ; 2 = after GMVDT
+10 ; Output: RESULT - piece1^piece2
+11 ; where piece1 = date/time of reading (FileMan internal format)
+12 ; piece2 = reading
+13 ; If no records found piece 1 = -2
+14 ; and piece 2 = message text
+15 ; If an error was encountered piece1 = -1
+16 ; and piece2 = error message
+17 ;
+18 NEW GMVADIFF,GMVADT,GMVAVAL,GMVBDIFF,GMVBDT,GMVBVAL,GMVDATA,GMVTI
+19 SET GMVDFN=+$GET(GMVDFN)
SET GMVDT=+$GET(GMVDT)
SET GMVT=$GET(GMVT)
SET GMVFLAG=+$GET(GMVFLAG)
+20 SET GMVFLAG=$SELECT(GMVFLAG=2:2,GMVFLAG=1:1,1:0)
+21 IF 'GMVDFN
SET RESULT="-1^DFN not defined"
QUIT
+22 IF '$DATA(^PXRMINDX(120.5,"PI",GMVDFN))
SET RESULT="-2^Patient has no Vitals data on file"
QUIT
+23 IF 'GMVDT
SET GMVDT=$$NOW^XLFDT()
+24 IF GMVT=""
SET RESULT="-1^Vital Type not defined"
QUIT
+25 SET GMVTI=$$GETIEN^GMVGETVT(GMVT,2)
+26 IF 'GMVTI
SET RESULT="-1^Vital Type not found"
QUIT
+27 IF '$DATA(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI))
SET RESULT="-2^Patient has no data on file for this type"
QUIT
+28 SET (GMVADT,GMVAVAL,GMVBDT,GMVBVAL,GMVDATA)=""
+29 IF GMVFLAG=0!(GMVFLAG=1)
Begin DoDot:1
+30 SET GMVDATA=$$FIND(GMVDFN,GMVTI,GMVDT,0,-1)
+31 SET GMVBDT=$PIECE(GMVDATA,U,1)
SET GMVBVAL=$PIECE(GMVDATA,U,2)
End DoDot:1
+32 SET GMVDATA=""
+33 IF GMVFLAG=0!(GMVFLAG=2)
Begin DoDot:1
+34 SET GMVDATA=$$FIND(GMVDFN,GMVTI,GMVDT,0,1)
+35 SET GMVADT=$PIECE(GMVDATA,U,1)
SET GMVAVAL=$PIECE(GMVDATA,U,2)
End DoDot:1
+36 IF GMVFLAG=1
Begin DoDot:1
+37 IF GMVBDT'>0
SET RESULT="-2^Before date not found"
QUIT
+38 IF GMVBVAL=""
SET RESULT="-2^Before value not found"
QUIT
+39 SET RESULT=GMVBDT_U_GMVBVAL
End DoDot:1
+40 IF GMVFLAG=2
Begin DoDot:1
+41 IF GMVADT'>0
SET RESULT="-2^After date not found"
QUIT
+42 IF GMVAVAL=""
SET RESULT="-2^After value not found"
QUIT
+43 SET RESULT=GMVADT_U_GMVAVAL
End DoDot:1
+44 IF GMVFLAG=0
Begin DoDot:1
+45 IF GMVADT'>0
IF GMVBDT'>0
Begin DoDot:2
+46 SET RESULT="-2^No records found"
End DoDot:2
QUIT
+47 IF GMVADT'>0
IF GMVBDT>0
Begin DoDot:2
+48 if GMVBVAL]""
SET RESULT=GMVBDT_U_GMVBVAL
+49 if GMVBVAL=""
SET RESULT="-2^No records found"
End DoDot:2
QUIT
+50 IF GMVADT>0
IF GMVBDT'>0
Begin DoDot:2
+51 if GMVAVAL]""
SET RESULT=GMVADT_U_GMVAVAL
+52 if GMVAVAL=""
SET RESULT="-2^No records found"
End DoDot:2
QUIT
+53 IF GMVADT>0
IF GMVBDT>0
Begin DoDot:2
+54 SET GMVBDIFF=+$$FMDIFF^XLFDT(GMVDT,GMVBDT,2)
+55 SET GMVADIFF=+$$FMDIFF^XLFDT(GMVADT,GMVDT,2)
+56 IF GMVBDIFF<GMVADIFF
SET RESULT=GMVBDT_U_GMVBVAL
+57 IF GMVADIFF<GMVBDIFF
SET RESULT=GMVADT_U_GMVAVAL
+58 IF GMVADIFF=GMVBDIFF
SET RESULT=GMVADT_U_GMVAVAL
End DoDot:2
End DoDot:1
+59 QUIT
FIND(GMVDFN,GMVTI,GMVSDT,GMVX,GMVDIR) ; Get nearest record from GMVSDT date/time
+1 ; Input: GMVDFN - DFN (required)
+2 ; GMVTI - Vital Type (120.51) IEN (required)
+3 ; GMVSDT - FileMan date/time (optional)
+4 ; Default is NOW
+5 ; GMVX - Return numeric values only or all values including
+6 ; text (optional)
+7 ; 0 = numeric values only (default)
+8 ; 1 = all values including text
+9 ; GMVDIR - direction of search (required)
+10 ; -1 = look before GMVSDT
+11 ; 1 = look after GMVSDT
+12 ; Output: GMVY - piece1^piece2
+13 ; where piece1 = date/time of reading (FileMan internal format)
+14 ; piece2 = reading
+15 ; If an error was encountered piece1 = -1
+16 ; and piece2 = error message
+17 ;
+18 NEW GMVARR,GMVFLAG,GMVIEN,GMVY
+19 SET GMVDFN=+$GET(GMVDFN)
SET GMVTI=+$GET(GMVTI)
SET GMVSDT=+$GET(GMVSDT)
SET GMVX=+$GET(GMVX)
SET GMVDIR=$GET(GMVDIR)
+20 SET GMVDIR=$SELECT(GMVDIR=-1:-1,GMVDIR=1:1,1:"")
+21 IF GMVDIR=""
QUIT "-1^Direction of search not defined"
+22 IF 'GMVTI
QUIT "-1^Vital Type not defined"
+23 SET GMVX=$SELECT(GMVX=1:1,1:0)
+24 IF 'GMVDFN
QUIT "-1^Patient not defined"
+25 IF '$DATA(^PXRMINDX(120.5,"PI",GMVDFN))
QUIT "-1^Patient has no Vitals data on file"
+26 IF 'GMVSDT
SET GMVSDT=$$NOW^XLFDT()
+27 SET (GMVFLAG,GMVIEN)=0
SET GMVY=""
+28 FOR
SET GMVSDT=$ORDER(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI,GMVSDT),GMVDIR)
if 'GMVSDT!(GMVFLAG)
QUIT
Begin DoDot:1
+29 SET GMVIEN=0
+30 FOR
SET GMVIEN=$ORDER(^PXRMINDX(120.5,"PI",GMVDFN,GMVTI,GMVSDT,GMVIEN))
if $LENGTH(GMVIEN)'>0!(GMVFLAG)
QUIT
Begin DoDot:2
+31 IF GMVIEN=+GMVIEN
Begin DoDot:3
+32 DO F1205^GMVUTL(.GMVARR,GMVIEN,0)
End DoDot:3
+33 IF GMVIEN'=+GMVIEN
Begin DoDot:3
+34 DO CLIO^GMVUTL(.GMVARR,GMVIEN)
End DoDot:3
+35 SET GMVARR(0)=$GET(GMVARR(0))
+36 if $PIECE(GMVARR(0),U,8)=""
QUIT
+37 if $PIECE(GMVARR(0),U,1)'>0
QUIT
+38 IF GMVX=1
Begin DoDot:3
+39 SET GMVY=$PIECE(GMVARR(0),U,1)_U_$PIECE(GMVARR(0),U,8)
SET GMVFLAG=1
End DoDot:3
+40 IF 'GMVX
Begin DoDot:3
+41 IF "UNAVAILABLEPASSREFUSED"[$$UP^XLFSTR($PIECE(GMVARR(0),U,8))
QUIT
+42 SET GMVY=$PIECE(GMVARR(0),U,1)_U_$PIECE(GMVARR(0),U,8)
SET GMVFLAG=1
End DoDot:3
End DoDot:2
End DoDot:1
+43 IF GMVY=""
SET GMVY="-1^No record found"
+44 QUIT GMVY
+45 ;