VBECLU0 ;HOIFO/BNT - VBECS Patient Lookup Utility ;
;;2.0;VBEC;**1**;Jun 05, 2015;Build 13
;
; Note: This routine supports data exchange with an FDA registered
; medical device. As such, it may not be changed in any way without
; prior written approval from the medical device manufacturer.
;
; Integration Agreements:
;
SET X="You Can't Enter VBECLU0 at top of routine!"
QUIT
;
BYFILTER(FILTER,FILTERV,BDATE,EDATE,SEARCH,VALUE,DELIM) ; -- search type by clinic, provider, or ward.
NEW PCNT,OKAY,VAL
K ^TMP("PTLKUP",$J)
SET (OKAY,PCNT)=0
;W:$D(ALAN(1)) !,"In ByFilter"
;
DO ADD^VBECLU("<record count='0'>")
SET LINENO=VBECLINE
FOR I=1:1 S VAL=$P(FILTERV,DELIM,I) QUIT:VAL="" DO Q:$$STOP^XOBVLIB()
. IF FILTER="WARD" DO WARDPTS(VAL) S OKAY=1 Q
. IF FILTER="CLINIC" DO CLINPTS(VAL,BDATE,EDATE) S OKAY=2 Q
. IF FILTER="PROVIDER" D PROVPTS(VAL) S OKAY=3 Q
;
IF OKAY<1 DO ADD^VBECLU("<error message='Filter not correctly specified'></error>")
;
; -- update the record count
DO ADDPTS()
SET @VBECRSLT@(LINENO)="<record count='"_PCNT_"'>"
IF ($G(MAXSIZRE)<1) DO ADD^VBECLU("<maximum message=''></maximum>")
DO ADD^VBECLU("<error message=''></error>")
QUIT
;
FILTCHK(DFN,TYPE,VALUE) ; -- Filter search -
; -- check patients to match search type and search value for filter searchs
; -- returns 1 if matchs, 0 if no match
;
;W:$D(ALAN(1)) !,"In FilterCheck"
SET VALUE=$$UP^XLFSTR(VALUE)
Q:($G(VALUE)="")!($G(VALUE)="*") 1
Q:($G(TYPE)="") 1
Q:($G(DFN)<1) 0
;
NEW I,J,OKAY
SET OKAY=0
IF TYPE="NAME" DO
. SET CHKVAL=$P($G(^DPT(DFN,0)),"^",1)
. IF $E(CHKVAL,1,$LENGTH(VALUE))=VALUE SET OKAY=1
IF TYPE="SSN" DO
. SET CHKVAL=$P($G(^DPT(DFN,0)),"^",9)
. IF $E(CHKVAL,1,$LENGTH(VALUE))=VALUE SET OKAY=1
IF TYPE="ICN" DO
. SET CHKVAL=$P($G(^DPT(DFN,"MPI")),"^",1)
. IF $E(CHKVAL,1,$LENGTH(VALUE))=VALUE SET OKAY=1
IF TYPE="SSN4" DO
. SET CHKVAL=$E($P($G(^DPT(DFN,0)),"^",1),1)_$E($P($G(^DPT(DFN,0)),"^",9),6,9)
. IF $E(CHKVAL,1,$LENGTH(VALUE))=VALUE SET OKAY=1
QUIT OKAY
;
WARDPTS(WARD) ; RETURN LIST OF PATIENTS IN A WARD
; Based on ORQPTQ2
Q:+$G(WARD)<1
N DFN
S DFN=0
S WARD=$P(^DIC(42,WARD,0),"^") ;GET WARD NAME FOR "CN" LOOKUP
Q:WARD=""
F D Q:DFN'>0 Q:$$STOP^XOBVLIB()
. S DFN=$O(^DPT("CN",WARD,DFN)) Q:DFN'>0
. Q:'$$FILTCHK(DFN,SEARCH,VALUE)
. S ^TMP("PTLKUP",$J,$P($G(^DPT(DFN,0)),"^",1),DFN)=""
Q
;
PROVPTS(PROV) ; RETURN LIST OF PATIENTS LINKED TO A PRIMARY PROVIDER
; Based on ORQPTQ2
; "APR" xref is on field PROVIDER in file 2 (2;.104)
; "AAP" xref is on field ATTENDING PHYSICIAN in file 2 (2;.1041)
;
Q:+$G(PROV)<1
;
N DFN,XREF
S DFN=0
F XREF="AAP","APR" DO
. F S DFN=$O(^DPT(XREF,PROV,DFN)) Q:DFN'>0 D Q:$$STOP^XOBVLIB()
.. Q:'$$FILTCHK(DFN,SEARCH,VALUE)
.. S ^TMP("PTLKUP",$J,$P($G(^DPT(DFN,0)),"^",1),DFN)=""
Q
;
CLINPTS(CLIN,BDATE,EDATE) ; RETURN LIST OF PTS W/CLINIC APPT W/IN BEGINNING AND END DATES
Q:+$G(CLIN)<1
;
N DFN,NAME,I,J,X,ORJ,ORSRV,ORNOWDT,CHKX,CHKIN,MAXAPPTS,ORC,CLNAM
S MAXAPPTS=200
S NOWDT=$$NOW^XLFDT
;
S DFN=0,I=1
IF $G(BDATE)="" S BDATE="T"
IF $G(EDATE)="" S EDATE="T+1"
;CONVERT BDATE AND EDATE INTO FILEMAN DATE/TIME
D DT^DILF("T",BDATE,.BDATE,"","")
D DT^DILF("T",EDATE,.EDATE,"","")
I (BDATE=-1)!(EDATE=-1) S Y(1)="^Error in date range." Q
S EDATE=$P(EDATE,".")_.5 ;ADD 1/2 DAY TO END DATE
;
D CLINPT2(+CLIN,BDATE,EDATE)
QUIT
;
CLINPT2(CLIN,BEGIN,END) ; -- Use scheduling rehosting API from patches SD*5.3*253 and SD*5.3*275
; -- GETPLIST^SDAMA202(SDIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,.SDRESULT,SDIOSTAT)
;
K ^TMP($J,"SDAMA202","GETPLIST")
NEW I,X,APPTS SET APPTS=""
;
; -- get appointment date/time, patient status, patient ien & name,
; only get appointment status = "R" for scheduled or kept appointments.
DO GETPLIST^SDAMA202(+CLIN,"1;3;4","R",BEGIN,END,.APPTS)
;
; -- check number of appointments
Q:APPTS<1
;
; -- check for an error, may need to pass message up.
I $D(^TMP($J,"SDAMA202","GETPTLIST","ERROR")) QUIT
;
; -- move list of appointments to list of patients, ordered by name, dfn
S (I,X)=""
F SET I=$O(^TMP($J,"SDAMA202","GETPLIST",I)) Q:I<1 S X=^(I,4) DO
. Q:'$$FILTCHK(+X,SEARCH,VALUE) ;check if meets search criteria
. S ^TMP("PTLKUP",$J,$P(X,"^",2),+X)=""
QUIT
;
ADDPTS() ;
N NAME,DFN
S NAME=""
FOR SET NAME=$O(^TMP("PTLKUP",$J,NAME)) Q:NAME="" DO
. S DFN="" FOR SET DFN=$O(^TMP("PTLKUP",$J,NAME,DFN)) Q:DFN<1 DO
.. DO PTDATA^VBECLU(DFN,.PCNT)
;IF ($G(MAXSIZRE)<1) DO ADD^VBECLU("<maximum message=''></maximum>")
Q
;
NAMECOMP(DFN) ; ENTRY IS +$P($G(^DPT(DFN,"NAME")),"^",1)
N A,LN,FN,MI,PR,SU,DE
S A=$G(^VA(20,+$P($G(^DPT(DFN,"NAME")),"^",1),1))
S LN=$$CHARCHK^XOBVLIB($P(A,"^",1))
S FN=$$CHARCHK^XOBVLIB($P(A,"^",2))
S MI=$$CHARCHK^XOBVLIB($P(A,"^",3))
S PR=$$CHARCHK^XOBVLIB($P(A,"^",4))
S SU=$$CHARCHK^XOBVLIB($P(A,"^",5))
S DE=$$CHARCHK^XOBVLIB($P(A,"^",6))
DO ADD^VBECLU("<CmpntLastName>"_LN_"</CmpntLastName><CmpntFirstName>"_FN_"</CmpntFirstName><CmpntMiddleName>"_MI_"</CmpntMiddleName><CmpntPrefx>"_PR_"</CmpntPrefx><PatientNameSuffix>"_SU_"</PatientNameSuffix><CmpntDgr>"_DE_"</CmpntDgr>")
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVBECLU0 5266 printed Nov 22, 2024@17:54:13 Page 2
VBECLU0 ;HOIFO/BNT - VBECS Patient Lookup Utility ;
+1 ;;2.0;VBEC;**1**;Jun 05, 2015;Build 13
+2 ;
+3 ; Note: This routine supports data exchange with an FDA registered
+4 ; medical device. As such, it may not be changed in any way without
+5 ; prior written approval from the medical device manufacturer.
+6 ;
+7 ; Integration Agreements:
+8 ;
+9 SET X="You Can't Enter VBECLU0 at top of routine!"
+10 QUIT
+11 ;
BYFILTER(FILTER,FILTERV,BDATE,EDATE,SEARCH,VALUE,DELIM) ; -- search type by clinic, provider, or ward.
+1 NEW PCNT,OKAY,VAL
+2 KILL ^TMP("PTLKUP",$JOB)
+3 SET (OKAY,PCNT)=0
+4 ;W:$D(ALAN(1)) !,"In ByFilter"
+5 ;
+6 DO ADD^VBECLU("<record count='0'>")
+7 SET LINENO=VBECLINE
+8 FOR I=1:1
SET VAL=$PIECE(FILTERV,DELIM,I)
if VAL=""
QUIT
Begin DoDot:1
+9 IF FILTER="WARD"
DO WARDPTS(VAL)
SET OKAY=1
QUIT
+10 IF FILTER="CLINIC"
DO CLINPTS(VAL,BDATE,EDATE)
SET OKAY=2
QUIT
+11 IF FILTER="PROVIDER"
DO PROVPTS(VAL)
SET OKAY=3
QUIT
End DoDot:1
if $$STOP^XOBVLIB()
QUIT
+12 ;
+13 IF OKAY<1
DO ADD^VBECLU("<error message='Filter not correctly specified'></error>")
+14 ;
+15 ; -- update the record count
+16 DO ADDPTS()
+17 SET @VBECRSLT@(LINENO)="<record count='"_PCNT_"'>"
+18 IF ($GET(MAXSIZRE)<1)
DO ADD^VBECLU("<maximum message=''></maximum>")
+19 DO ADD^VBECLU("<error message=''></error>")
+20 QUIT
+21 ;
FILTCHK(DFN,TYPE,VALUE) ; -- Filter search -
+1 ; -- check patients to match search type and search value for filter searchs
+2 ; -- returns 1 if matchs, 0 if no match
+3 ;
+4 ;W:$D(ALAN(1)) !,"In FilterCheck"
+5 SET VALUE=$$UP^XLFSTR(VALUE)
+6 if ($GET(VALUE)="")!($GET(VALUE)="*")
QUIT 1
+7 if ($GET(TYPE)="")
QUIT 1
+8 if ($GET(DFN)<1)
QUIT 0
+9 ;
+10 NEW I,J,OKAY
+11 SET OKAY=0
+12 IF TYPE="NAME"
Begin DoDot:1
+13 SET CHKVAL=$PIECE($GET(^DPT(DFN,0)),"^",1)
+14 IF $EXTRACT(CHKVAL,1,$LENGTH(VALUE))=VALUE
SET OKAY=1
End DoDot:1
+15 IF TYPE="SSN"
Begin DoDot:1
+16 SET CHKVAL=$PIECE($GET(^DPT(DFN,0)),"^",9)
+17 IF $EXTRACT(CHKVAL,1,$LENGTH(VALUE))=VALUE
SET OKAY=1
End DoDot:1
+18 IF TYPE="ICN"
Begin DoDot:1
+19 SET CHKVAL=$PIECE($GET(^DPT(DFN,"MPI")),"^",1)
+20 IF $EXTRACT(CHKVAL,1,$LENGTH(VALUE))=VALUE
SET OKAY=1
End DoDot:1
+21 IF TYPE="SSN4"
Begin DoDot:1
+22 SET CHKVAL=$EXTRACT($PIECE($GET(^DPT(DFN,0)),"^",1),1)_$EXTRACT($PIECE($GET(^DPT(DFN,0)),"^",9),6,9)
+23 IF $EXTRACT(CHKVAL,1,$LENGTH(VALUE))=VALUE
SET OKAY=1
End DoDot:1
+24 QUIT OKAY
+25 ;
WARDPTS(WARD) ; RETURN LIST OF PATIENTS IN A WARD
+1 ; Based on ORQPTQ2
+2 if +$GET(WARD)<1
QUIT
+3 NEW DFN
+4 SET DFN=0
+5 ;GET WARD NAME FOR "CN" LOOKUP
SET WARD=$PIECE(^DIC(42,WARD,0),"^")
+6 if WARD=""
QUIT
+7 FOR
Begin DoDot:1
+8 SET DFN=$ORDER(^DPT("CN",WARD,DFN))
if DFN'>0
QUIT
+9 if '$$FILTCHK(DFN,SEARCH,VALUE)
QUIT
+10 SET ^TMP("PTLKUP",$JOB,$PIECE($GET(^DPT(DFN,0)),"^",1),DFN)=""
End DoDot:1
if DFN'>0
QUIT
if $$STOP^XOBVLIB()
QUIT
+11 QUIT
+12 ;
PROVPTS(PROV) ; RETURN LIST OF PATIENTS LINKED TO A PRIMARY PROVIDER
+1 ; Based on ORQPTQ2
+2 ; "APR" xref is on field PROVIDER in file 2 (2;.104)
+3 ; "AAP" xref is on field ATTENDING PHYSICIAN in file 2 (2;.1041)
+4 ;
+5 if +$GET(PROV)<1
QUIT
+6 ;
+7 NEW DFN,XREF
+8 SET DFN=0
+9 FOR XREF="AAP","APR"
Begin DoDot:1
+10 FOR
SET DFN=$ORDER(^DPT(XREF,PROV,DFN))
if DFN'>0
QUIT
Begin DoDot:2
+11 if '$$FILTCHK(DFN,SEARCH,VALUE)
QUIT
+12 SET ^TMP("PTLKUP",$JOB,$PIECE($GET(^DPT(DFN,0)),"^",1),DFN)=""
End DoDot:2
if $$STOP^XOBVLIB()
QUIT
End DoDot:1
+13 QUIT
+14 ;
CLINPTS(CLIN,BDATE,EDATE) ; RETURN LIST OF PTS W/CLINIC APPT W/IN BEGINNING AND END DATES
+1 if +$GET(CLIN)<1
QUIT
+2 ;
+3 NEW DFN,NAME,I,J,X,ORJ,ORSRV,ORNOWDT,CHKX,CHKIN,MAXAPPTS,ORC,CLNAM
+4 SET MAXAPPTS=200
+5 SET NOWDT=$$NOW^XLFDT
+6 ;
+7 SET DFN=0
SET I=1
+8 IF $GET(BDATE)=""
SET BDATE="T"
+9 IF $GET(EDATE)=""
SET EDATE="T+1"
+10 ;CONVERT BDATE AND EDATE INTO FILEMAN DATE/TIME
+11 DO DT^DILF("T",BDATE,.BDATE,"","")
+12 DO DT^DILF("T",EDATE,.EDATE,"","")
+13 IF (BDATE=-1)!(EDATE=-1)
SET Y(1)="^Error in date range."
QUIT
+14 ;ADD 1/2 DAY TO END DATE
SET EDATE=$PIECE(EDATE,".")_.5
+15 ;
+16 DO CLINPT2(+CLIN,BDATE,EDATE)
+17 QUIT
+18 ;
CLINPT2(CLIN,BEGIN,END) ; -- Use scheduling rehosting API from patches SD*5.3*253 and SD*5.3*275
+1 ; -- GETPLIST^SDAMA202(SDIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,.SDRESULT,SDIOSTAT)
+2 ;
+3 KILL ^TMP($JOB,"SDAMA202","GETPLIST")
+4 NEW I,X,APPTS
SET APPTS=""
+5 ;
+6 ; -- get appointment date/time, patient status, patient ien & name,
+7 ; only get appointment status = "R" for scheduled or kept appointments.
+8 DO GETPLIST^SDAMA202(+CLIN,"1;3;4","R",BEGIN,END,.APPTS)
+9 ;
+10 ; -- check number of appointments
+11 if APPTS<1
QUIT
+12 ;
+13 ; -- check for an error, may need to pass message up.
+14 IF $DATA(^TMP($JOB,"SDAMA202","GETPTLIST","ERROR"))
QUIT
+15 ;
+16 ; -- move list of appointments to list of patients, ordered by name, dfn
+17 SET (I,X)=""
+18 FOR
SET I=$ORDER(^TMP($JOB,"SDAMA202","GETPLIST",I))
if I<1
QUIT
SET X=^(I,4)
Begin DoDot:1
+19 ;check if meets search criteria
if '$$FILTCHK(+X,SEARCH,VALUE)
QUIT
+20 SET ^TMP("PTLKUP",$JOB,$PIECE(X,"^",2),+X)=""
End DoDot:1
+21 QUIT
+22 ;
ADDPTS() ;
+1 NEW NAME,DFN
+2 SET NAME=""
+3 FOR
SET NAME=$ORDER(^TMP("PTLKUP",$JOB,NAME))
if NAME=""
QUIT
Begin DoDot:1
+4 SET DFN=""
FOR
SET DFN=$ORDER(^TMP("PTLKUP",$JOB,NAME,DFN))
if DFN<1
QUIT
Begin DoDot:2
+5 DO PTDATA^VBECLU(DFN,.PCNT)
End DoDot:2
End DoDot:1
+6 ;IF ($G(MAXSIZRE)<1) DO ADD^VBECLU("<maximum message=''></maximum>")
+7 QUIT
+8 ;
NAMECOMP(DFN) ; ENTRY IS +$P($G(^DPT(DFN,"NAME")),"^",1)
+1 NEW A,LN,FN,MI,PR,SU,DE
+2 SET A=$GET(^VA(20,+$PIECE($GET(^DPT(DFN,"NAME")),"^",1),1))
+3 SET LN=$$CHARCHK^XOBVLIB($PIECE(A,"^",1))
+4 SET FN=$$CHARCHK^XOBVLIB($PIECE(A,"^",2))
+5 SET MI=$$CHARCHK^XOBVLIB($PIECE(A,"^",3))
+6 SET PR=$$CHARCHK^XOBVLIB($PIECE(A,"^",4))
+7 SET SU=$$CHARCHK^XOBVLIB($PIECE(A,"^",5))
+8 SET DE=$$CHARCHK^XOBVLIB($PIECE(A,"^",6))
+9 DO ADD^VBECLU("<CmpntLastName>"_LN_"</CmpntLastName><CmpntFirstName>"_FN_"</CmpntFirstName><CmpntMiddleName>"_MI_"</CmpntMiddleName><CmpntPrefx>"_PR_"</CmpntPrefx><PatientNameSuffix>"_SU_"</PatientNameSuffix><CmpntDgr>"_DE_"</CmpntDgr>")
+10 ;