SDES2QRYAPREQSB ;ALB/BWF - QUERY APPOINTMENT REQUESTS; JAN 4,2023
;;5.3;Scheduling;**869,873,875,877,878**;Aug 13, 1993;Build 11
;;Per VHA Directive 6402, this routine should not be modified
;
; Reference to DGENA in ICR#3812
;
Q
FLTRAPPTREQ(REQIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
N REQIENS,CLINICIEN,APPTREQ,WAITDAYS,DATEENTERED,PATNAME,REQSUBTYPE
Q:'REQIEN
S REQIENS=REQIEN_","
D GETS^DIQ(409.85,REQIENS,".01;1;2;4;8;8.5;10.5;15;22;23","IE","APPTREQ")
Q:$G(APPTREQ(409.85,REQIENS,23,"I"))="C"
; filter appointment sub-type
S REQSUBTYPE=$G(APPTREQ(409.85,REQIENS,4,"I"))
I REQSUBTYPE="" S REQSUBTYPE="UNKNOWN"
I '$D(SDINPUT("FILTER","REQUEST SUBTYPE",REQSUBTYPE)),('$D(SDINPUT("FILTER","REQUEST SUBTYPE","ALL"))) Q
; check clinics
S CLINICIEN=$G(APPTREQ(409.85,REQIENS,8,"I"))
I $D(SDINPUT("FILTER","CLINIC")),CLINICIEN="" Q
I CLINICIEN'="",$D(SDINPUT("FILTER","CLINIC")),'$D(SDINPUT("FILTER","CLINIC",CLINICIEN)) Q
; check services
S STOPIEN=$G(APPTREQ(409.85,REQIENS,8.5,"I"))
I $D(SDINPUT("FILTER","SERVICE")),STOPIEN="" Q
I STOPIEN'="",$D(SDINPUT("FILTER","SERVICE")),'$D(SDINPUT("FILTER","SERVICE",STOPIEN)) Q
; wait time
S DATEENTERED=$G(APPTREQ(409.85,REQIENS,1,"I"))
I DATEENTERED<STARTDT!(DATEENTERED>ENDDT) Q
; origination date
I $D(SDINPUT("FILTER","ORIGINATION DATE")),$G(APPTREQ(409.85,REQIENS,1,"I"))'=FLTRORIGDATE Q
; pid (desired) date
S PIDDATE=$G(APPTREQ(409.85,REQIENS,22,"I"))
I PIDDATE="" S PIDDATE="UNKNOWN"
I $D(SDINPUT("FILTER","PID")),PIDDATE'=FLTRPIDDATE Q
S WAITDAYS=$$FMDIFF^XLFDT(DT,$G(APPTREQ(409.85,REQIENS,1,"I")))
;
S PATNAME=$G(APPTREQ(409.85,REQIENS,.01,"E"))
S CLINICNAME=$G(APPTREQ(409.85,REQIENS,8,"E"))
I CLINICNAME="" S CLINICNAME="UNKNOWN"
; get service related from the request itself, set to 0 if null
S SERVICEREL=$G(APPTREQ(409.85,REQIENS,15,"I"))
I SERVICEREL="" S SERVICEREL=0
; SCPERCENT IS CONVERTED TO THE INVERSE IN THE ORIGINAL FOR SORTING
S SCPERCENT=100-$G(PATSCPERCENT)
S COUNT=$G(COUNT)+1,REQCNT=$G(REQCNT)+1
D SETDATA($G(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,PIDDATE,DATEENTERED,"A",REQIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
Q
;
FLTRCONSULT(CONSIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
N CONSIENS,CONSULT,CLINICIEN,SERVICEIEN,WAITDAYS,DATEENTERED,PATNAME,CLINICNAME,SERVICEREL,PIDDATE
Q:'CONSIEN
S CONSIENS=CONSIEN_","
D GETS^DIQ(123,CONSIENS,".01;.02;.05;.07;1;2","IE","CONSULT")
; clinics
S CLINICIEN=$G(CONSULT(123,CONSIENS,2,"I"))
I CLINICIEN'="",$D(SDINPUT("FILTER","CLINIC")),'$D(SDINPUT("FILTER","CLINIC",CLINICIEN)) Q
; services
S SERVICEIEN=$G(CONSULT(123,CONSIENS,1,"I"))
I SERVICEIEN,$D(SDINPUT("FILTER","SERVICE")) Q:'$$CHECKSERVICES^SDES2QRYAPREQSA(.SDINPUT,SERVICEIEN)
; wait time
S DATEENTERED=$P($G(CONSULT(123,CONSIENS,.01,"I")),".")
I DATEENTERED<STARTDT!(DATEENTERED>ENDDT) Q
; origination date
I $D(SDINPUT("FILTER","ORIGINATION DATE")),$P($G(CONSULT(123,CONSIENS,.01,"I")),".")'=FLTRORIGDATE Q
; pid (desired) date - uses $$PRIO^SDES2QRYAPREQSA to determine PID date for consults
S PIDDATE=$$PRIO^SDES2QRYAPREQSA(CONSIEN)
I PIDDATE="" S PIDDATE=DATEENTERED
I $D(SDINPUT("FILTER","PID")),PIDDATE'=FLTRPIDDATE Q
; urgency
I $D(SDINPUT("FILTER","URGENCY")),$$GET1^DIQ(123,CONSIEN,5,"I")'=$G(SDINPUT("FILTER","URGENCY")) Q
;
S WAITDAYS=$$FMDIFF^XLFDT(DT,DATEENTERED)
S PATNAME=$G(CONSULT(123,CONSIENS,.02,"E"))
I PATNAME="" S PATNAME="UNKNOWN"
S CLINICNAME=$G(CONSULT(123,CONSIENS,2,"E"))
I CLINICNAME="" S CLINICNAME="UNKNOWN"
S SERVICEREL=$S(PRIORITYGROUP="GROUP 1":1,1:0)
; SCPERCENT IS CONVERTED TO THE INVERSE IN THE ORIGINAL FOR SORTING
S SCPERCENT=100-$G(PATSCPERCENT)
S COUNT=$G(COUNT)+1,REQCNT=$G(REQCNT)+1
D SETDATA($G(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,PIDDATE,DATEENTERED,"C",CONSIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
Q
;
FLTRRECALL(RECALLIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
N RECALLIENS,RECALL,CLINICIEN,STOPIEN,DATEENTERED,RECALLDATE,WAITDAYS,PATNAME,CLINICNAME,SERVICEREL,SCPERCENT
S RECALLIENS=RECALLIEN_","
D GETS^DIQ(403.5,RECALLIENS,".01;4.5;5;5.5;7.5","IE","RECALL")
; clinics
S CLINICIEN=$G(RECALL(403.5,RECALLIENS,4.5,"I"))
I CLINICIEN'="",$D(SDINPUT("FILTER","CLINIC")),'$D(SDINPUT("FILTER","CLINIC",CLINICIEN)) Q
I $$GET1^DIQ(44,CLINICIEN,50.01,"I")=1 Q ;do not return if OOS? is yes
; services
S STOPIEN=$$GET1^DIQ(44,CLINICIEN,8,"I")
I STOPIEN,$D(SDINPUT("FILTER","SERVICE")),'$D(SDINPUT("FILTER","SERVICE",STOPIEN)) Q
S DATEENTERED=$P($G(RECALL(403.5,RECALLIENS,7.5,"I")),".")
I DATEENTERED="" S DATEENTERED=$G(RECALL(403.5,RECALLIENS,5,"I"))
; origination date
I $D(SDINPUT("FILTER","ORIGINATION DATE")),DATEENTERED'=FLTRORIGDATE Q
; wait time
S RECALLDATE=$G(RECALL(403.5,RECALLIENS,5.5,"I"))
I 'RECALLDATE S RECALLDATE=$G(RECALL(403.5,RECALLIENS,5,"I"))
I RECALLDATE<STARTDT!(RECALLDATE>ENDDT) Q
; pid (desired) date
I $D(SDINPUT("FILTER","PID")),RECALLDATE'=FLTRPIDDATE Q
S WAITDAYS=$$FMDIFF^XLFDT(DT,RECALLDATE)
S PATNAME=$G(RECALL(403.5,RECALLIENS,.01,"E"))
I PATNAME="" S PATNAME="UNKNOWN"
S CLINICNAME=$G(RECALL(403.5,RECALLIENS,4.5,"E"))
I CLINICNAME="" S CLINICNAME="UNKNOWN"
S SERVICEREL=PATSVCCONN
; SCPERCENT IS CONVERTED TO THE INVERSE OF THE ORIGINAL FOR SORTING
S SCPERCENT=100-PATSCPERCENT
S COUNT=$G(COUNT)+1,REQCNT=$G(REQCNT)+1
D SETDATA($G(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,RECALLDATE,DATEENTERED,"R",RECALLIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
Q
; set data into ^TMP for final processing
SETDATA(SORT,PATNAME,CLINICNAME,PRIOGROUP,DESIREDDATE,ORIGDATE,REQTYPE,REQIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT) ;
;
I $G(SORT)="DEFAULT" D
.S ^TMP("SDES2QUERY",$J,"DATA",PRIOGROUP,'SERVICEREL,DESIREDDATE,ORIGDATE,REQIEN)=REQTYPE
I $G(SORT)="PRIORITY GROUP" D
.S ^TMP("SDES2QUERY",$J,"DATA",PRIOGROUP,'SERVICEREL,DESIREDDATE,ORIGDATE,REQIEN)=REQTYPE
I $G(SORT)="PATIENT NAME" D
.I PATNAME="" S PATNAME="**MISSING PATIENT NAME**"
.S ^TMP("SDES2QUERY",$J,"DATA",PATNAME,REQIEN)=REQTYPE
I $G(SORT)="CLINIC" D
.I CLINICNAME="" S CLINICNAME="**MISSING CLINIC NAME**"
.S ^TMP("SDES2QUERY",$J,"DATA",CLINICNAME,REQIEN)=REQTYPE
I $G(SORT)="REQUEST" D
.S ^TMP("SDES2QUERY",$J,"DATA",REQTYPE,REQIEN)=REQTYPE
I $G(SORT)="WAIT TIME" D
.S ^TMP("SDES2QUERY",$J,"DATA",WAITDAYS,REQIEN)=REQTYPE
I $G(SORT)="ORIGINATION DATE" D
.S ^TMP("SDES2QUERY",$J,"DATA",ORIGDATE,REQIEN)=REQTYPE
I $G(SORT)="PID DATE" D
.S ^TMP("SDES2QUERY",$J,"DATA",DESIREDDATE,REQIEN)=REQTYPE
I $G(SORT)="SERVICE RELATED" D
.S ^TMP("SDES2QUERY",$J,"DATA",SERVICEREL,REQIEN)=REQTYPE
I $G(SORT)="SCVISIT" D
.S ^TMP("SDES2QUERY",$J,"DATA",SCPERCENT,REQIEN)=REQTYPE
S ^TMP("SDES2QUERY",$J,"COUNT")=COUNT
Q
;
GETPATENR(DFN,PRIORITYGROUP,CURRENTENR,PATSVCCONN,PATSCPERCENT) ;
N ENRRET
Q:'DFN
S PRIORITYGROUP=$$PRIORITY^DGENA(DFN)
; default group to 0 if undefined
I PRIORITYGROUP="" S PRIORITYGROUP=0
; Set service connected and service connected percent to 0
S (PATSVCCONN,PATSCPERCENT)=0
S CURRENTENR=$$FINDCUR^DGENA(DFN)
I CURRENTENR'="" D
.D GET^DGENA(CURRENTENR,.ENRRET)
.S PATSVCCONN=$G(ENRRET("ELIG","SC"))
.S PATSVCCONN=$S(PATSVCCONN="Y":1,1:0)
.S PATSCPERCENT=$G(ENRRET("ELIG","SCPER"))
.S PATSCPERCENT=$S(PATSCPERCENT'="":PATSCPERCENT,1:0)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2QRYAPREQSB 7582 printed Nov 22, 2024@18:04:26 Page 2
SDES2QRYAPREQSB ;ALB/BWF - QUERY APPOINTMENT REQUESTS; JAN 4,2023
+1 ;;5.3;Scheduling;**869,873,875,877,878**;Aug 13, 1993;Build 11
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; Reference to DGENA in ICR#3812
+5 ;
+6 QUIT
FLTRAPPTREQ(REQIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
+1 NEW REQIENS,CLINICIEN,APPTREQ,WAITDAYS,DATEENTERED,PATNAME,REQSUBTYPE
+2 if 'REQIEN
QUIT
+3 SET REQIENS=REQIEN_","
+4 DO GETS^DIQ(409.85,REQIENS,".01;1;2;4;8;8.5;10.5;15;22;23","IE","APPTREQ")
+5 if $GET(APPTREQ(409.85,REQIENS,23,"I"))="C"
QUIT
+6 ; filter appointment sub-type
+7 SET REQSUBTYPE=$GET(APPTREQ(409.85,REQIENS,4,"I"))
+8 IF REQSUBTYPE=""
SET REQSUBTYPE="UNKNOWN"
+9 IF '$DATA(SDINPUT("FILTER","REQUEST SUBTYPE",REQSUBTYPE))
IF ('$DATA(SDINPUT("FILTER","REQUEST SUBTYPE","ALL")))
QUIT
+10 ; check clinics
+11 SET CLINICIEN=$GET(APPTREQ(409.85,REQIENS,8,"I"))
+12 IF $DATA(SDINPUT("FILTER","CLINIC"))
IF CLINICIEN=""
QUIT
+13 IF CLINICIEN'=""
IF $DATA(SDINPUT("FILTER","CLINIC"))
IF '$DATA(SDINPUT("FILTER","CLINIC",CLINICIEN))
QUIT
+14 ; check services
+15 SET STOPIEN=$GET(APPTREQ(409.85,REQIENS,8.5,"I"))
+16 IF $DATA(SDINPUT("FILTER","SERVICE"))
IF STOPIEN=""
QUIT
+17 IF STOPIEN'=""
IF $DATA(SDINPUT("FILTER","SERVICE"))
IF '$DATA(SDINPUT("FILTER","SERVICE",STOPIEN))
QUIT
+18 ; wait time
+19 SET DATEENTERED=$GET(APPTREQ(409.85,REQIENS,1,"I"))
+20 IF DATEENTERED<STARTDT!(DATEENTERED>ENDDT)
QUIT
+21 ; origination date
+22 IF $DATA(SDINPUT("FILTER","ORIGINATION DATE"))
IF $GET(APPTREQ(409.85,REQIENS,1,"I"))'=FLTRORIGDATE
QUIT
+23 ; pid (desired) date
+24 SET PIDDATE=$GET(APPTREQ(409.85,REQIENS,22,"I"))
+25 IF PIDDATE=""
SET PIDDATE="UNKNOWN"
+26 IF $DATA(SDINPUT("FILTER","PID"))
IF PIDDATE'=FLTRPIDDATE
QUIT
+27 SET WAITDAYS=$$FMDIFF^XLFDT(DT,$GET(APPTREQ(409.85,REQIENS,1,"I")))
+28 ;
+29 SET PATNAME=$GET(APPTREQ(409.85,REQIENS,.01,"E"))
+30 SET CLINICNAME=$GET(APPTREQ(409.85,REQIENS,8,"E"))
+31 IF CLINICNAME=""
SET CLINICNAME="UNKNOWN"
+32 ; get service related from the request itself, set to 0 if null
+33 SET SERVICEREL=$GET(APPTREQ(409.85,REQIENS,15,"I"))
+34 IF SERVICEREL=""
SET SERVICEREL=0
+35 ; SCPERCENT IS CONVERTED TO THE INVERSE IN THE ORIGINAL FOR SORTING
+36 SET SCPERCENT=100-$GET(PATSCPERCENT)
+37 SET COUNT=$GET(COUNT)+1
SET REQCNT=$GET(REQCNT)+1
+38 DO SETDATA($GET(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,PIDDATE,DATEENTERED,"A",REQIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
+39 QUIT
+40 ;
FLTRCONSULT(CONSIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
+1 NEW CONSIENS,CONSULT,CLINICIEN,SERVICEIEN,WAITDAYS,DATEENTERED,PATNAME,CLINICNAME,SERVICEREL,PIDDATE
+2 if 'CONSIEN
QUIT
+3 SET CONSIENS=CONSIEN_","
+4 DO GETS^DIQ(123,CONSIENS,".01;.02;.05;.07;1;2","IE","CONSULT")
+5 ; clinics
+6 SET CLINICIEN=$GET(CONSULT(123,CONSIENS,2,"I"))
+7 IF CLINICIEN'=""
IF $DATA(SDINPUT("FILTER","CLINIC"))
IF '$DATA(SDINPUT("FILTER","CLINIC",CLINICIEN))
QUIT
+8 ; services
+9 SET SERVICEIEN=$GET(CONSULT(123,CONSIENS,1,"I"))
+10 IF SERVICEIEN
IF $DATA(SDINPUT("FILTER","SERVICE"))
if '$$CHECKSERVICES^SDES2QRYAPREQSA(.SDINPUT,SERVICEIEN)
QUIT
+11 ; wait time
+12 SET DATEENTERED=$PIECE($GET(CONSULT(123,CONSIENS,.01,"I")),".")
+13 IF DATEENTERED<STARTDT!(DATEENTERED>ENDDT)
QUIT
+14 ; origination date
+15 IF $DATA(SDINPUT("FILTER","ORIGINATION DATE"))
IF $PIECE($GET(CONSULT(123,CONSIENS,.01,"I")),".")'=FLTRORIGDATE
QUIT
+16 ; pid (desired) date - uses $$PRIO^SDES2QRYAPREQSA to determine PID date for consults
+17 SET PIDDATE=$$PRIO^SDES2QRYAPREQSA(CONSIEN)
+18 IF PIDDATE=""
SET PIDDATE=DATEENTERED
+19 IF $DATA(SDINPUT("FILTER","PID"))
IF PIDDATE'=FLTRPIDDATE
QUIT
+20 ; urgency
+21 IF $DATA(SDINPUT("FILTER","URGENCY"))
IF $$GET1^DIQ(123,CONSIEN,5,"I")'=$GET(SDINPUT("FILTER","URGENCY"))
QUIT
+22 ;
+23 SET WAITDAYS=$$FMDIFF^XLFDT(DT,DATEENTERED)
+24 SET PATNAME=$GET(CONSULT(123,CONSIENS,.02,"E"))
+25 IF PATNAME=""
SET PATNAME="UNKNOWN"
+26 SET CLINICNAME=$GET(CONSULT(123,CONSIENS,2,"E"))
+27 IF CLINICNAME=""
SET CLINICNAME="UNKNOWN"
+28 SET SERVICEREL=$SELECT(PRIORITYGROUP="GROUP 1":1,1:0)
+29 ; SCPERCENT IS CONVERTED TO THE INVERSE IN THE ORIGINAL FOR SORTING
+30 SET SCPERCENT=100-$GET(PATSCPERCENT)
+31 SET COUNT=$GET(COUNT)+1
SET REQCNT=$GET(REQCNT)+1
+32 DO SETDATA($GET(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,PIDDATE,DATEENTERED,"C",CONSIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
+33 QUIT
+34 ;
FLTRRECALL(RECALLIEN,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT) ;
+1 NEW RECALLIENS,RECALL,CLINICIEN,STOPIEN,DATEENTERED,RECALLDATE,WAITDAYS,PATNAME,CLINICNAME,SERVICEREL,SCPERCENT
+2 SET RECALLIENS=RECALLIEN_","
+3 DO GETS^DIQ(403.5,RECALLIENS,".01;4.5;5;5.5;7.5","IE","RECALL")
+4 ; clinics
+5 SET CLINICIEN=$GET(RECALL(403.5,RECALLIENS,4.5,"I"))
+6 IF CLINICIEN'=""
IF $DATA(SDINPUT("FILTER","CLINIC"))
IF '$DATA(SDINPUT("FILTER","CLINIC",CLINICIEN))
QUIT
+7 ;do not return if OOS? is yes
IF $$GET1^DIQ(44,CLINICIEN,50.01,"I")=1
QUIT
+8 ; services
+9 SET STOPIEN=$$GET1^DIQ(44,CLINICIEN,8,"I")
+10 IF STOPIEN
IF $DATA(SDINPUT("FILTER","SERVICE"))
IF '$DATA(SDINPUT("FILTER","SERVICE",STOPIEN))
QUIT
+11 SET DATEENTERED=$PIECE($GET(RECALL(403.5,RECALLIENS,7.5,"I")),".")
+12 IF DATEENTERED=""
SET DATEENTERED=$GET(RECALL(403.5,RECALLIENS,5,"I"))
+13 ; origination date
+14 IF $DATA(SDINPUT("FILTER","ORIGINATION DATE"))
IF DATEENTERED'=FLTRORIGDATE
QUIT
+15 ; wait time
+16 SET RECALLDATE=$GET(RECALL(403.5,RECALLIENS,5.5,"I"))
+17 IF 'RECALLDATE
SET RECALLDATE=$GET(RECALL(403.5,RECALLIENS,5,"I"))
+18 IF RECALLDATE<STARTDT!(RECALLDATE>ENDDT)
QUIT
+19 ; pid (desired) date
+20 IF $DATA(SDINPUT("FILTER","PID"))
IF RECALLDATE'=FLTRPIDDATE
QUIT
+21 SET WAITDAYS=$$FMDIFF^XLFDT(DT,RECALLDATE)
+22 SET PATNAME=$GET(RECALL(403.5,RECALLIENS,.01,"E"))
+23 IF PATNAME=""
SET PATNAME="UNKNOWN"
+24 SET CLINICNAME=$GET(RECALL(403.5,RECALLIENS,4.5,"E"))
+25 IF CLINICNAME=""
SET CLINICNAME="UNKNOWN"
+26 SET SERVICEREL=PATSVCCONN
+27 ; SCPERCENT IS CONVERTED TO THE INVERSE OF THE ORIGINAL FOR SORTING
+28 SET SCPERCENT=100-PATSCPERCENT
+29 SET COUNT=$GET(COUNT)+1
SET REQCNT=$GET(REQCNT)+1
+30 DO SETDATA($GET(SDINPUT("SORT")),PATNAME,CLINICNAME,PRIORITYGROUP,RECALLDATE,DATEENTERED,"R",RECALLIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT)
+31 QUIT
+32 ; set data into ^TMP for final processing
SETDATA(SORT,PATNAME,CLINICNAME,PRIOGROUP,DESIREDDATE,ORIGDATE,REQTYPE,REQIEN,SERVICEREL,SCPERCENT,WAITDAYS,COUNT) ;
+1 ;
+2 IF $GET(SORT)="DEFAULT"
Begin DoDot:1
+3 SET ^TMP("SDES2QUERY",$JOB,"DATA",PRIOGROUP,'SERVICEREL,DESIREDDATE,ORIGDATE,REQIEN)=REQTYPE
End DoDot:1
+4 IF $GET(SORT)="PRIORITY GROUP"
Begin DoDot:1
+5 SET ^TMP("SDES2QUERY",$JOB,"DATA",PRIOGROUP,'SERVICEREL,DESIREDDATE,ORIGDATE,REQIEN)=REQTYPE
End DoDot:1
+6 IF $GET(SORT)="PATIENT NAME"
Begin DoDot:1
+7 IF PATNAME=""
SET PATNAME="**MISSING PATIENT NAME**"
+8 SET ^TMP("SDES2QUERY",$JOB,"DATA",PATNAME,REQIEN)=REQTYPE
End DoDot:1
+9 IF $GET(SORT)="CLINIC"
Begin DoDot:1
+10 IF CLINICNAME=""
SET CLINICNAME="**MISSING CLINIC NAME**"
+11 SET ^TMP("SDES2QUERY",$JOB,"DATA",CLINICNAME,REQIEN)=REQTYPE
End DoDot:1
+12 IF $GET(SORT)="REQUEST"
Begin DoDot:1
+13 SET ^TMP("SDES2QUERY",$JOB,"DATA",REQTYPE,REQIEN)=REQTYPE
End DoDot:1
+14 IF $GET(SORT)="WAIT TIME"
Begin DoDot:1
+15 SET ^TMP("SDES2QUERY",$JOB,"DATA",WAITDAYS,REQIEN)=REQTYPE
End DoDot:1
+16 IF $GET(SORT)="ORIGINATION DATE"
Begin DoDot:1
+17 SET ^TMP("SDES2QUERY",$JOB,"DATA",ORIGDATE,REQIEN)=REQTYPE
End DoDot:1
+18 IF $GET(SORT)="PID DATE"
Begin DoDot:1
+19 SET ^TMP("SDES2QUERY",$JOB,"DATA",DESIREDDATE,REQIEN)=REQTYPE
End DoDot:1
+20 IF $GET(SORT)="SERVICE RELATED"
Begin DoDot:1
+21 SET ^TMP("SDES2QUERY",$JOB,"DATA",SERVICEREL,REQIEN)=REQTYPE
End DoDot:1
+22 IF $GET(SORT)="SCVISIT"
Begin DoDot:1
+23 SET ^TMP("SDES2QUERY",$JOB,"DATA",SCPERCENT,REQIEN)=REQTYPE
End DoDot:1
+24 SET ^TMP("SDES2QUERY",$JOB,"COUNT")=COUNT
+25 QUIT
+26 ;
GETPATENR(DFN,PRIORITYGROUP,CURRENTENR,PATSVCCONN,PATSCPERCENT) ;
+1 NEW ENRRET
+2 if 'DFN
QUIT
+3 SET PRIORITYGROUP=$$PRIORITY^DGENA(DFN)
+4 ; default group to 0 if undefined
+5 IF PRIORITYGROUP=""
SET PRIORITYGROUP=0
+6 ; Set service connected and service connected percent to 0
+7 SET (PATSVCCONN,PATSCPERCENT)=0
+8 SET CURRENTENR=$$FINDCUR^DGENA(DFN)
+9 IF CURRENTENR'=""
Begin DoDot:1
+10 DO GET^DGENA(CURRENTENR,.ENRRET)
+11 SET PATSVCCONN=$GET(ENRRET("ELIG","SC"))
+12 SET PATSVCCONN=$SELECT(PATSVCCONN="Y":1,1:0)
+13 SET PATSCPERCENT=$GET(ENRRET("ELIG","SCPER"))
+14 SET PATSCPERCENT=$SELECT(PATSCPERCENT'="":PATSCPERCENT,1:0)
End DoDot:1
+15 QUIT