Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: SDES2QRYAPREQS

SDES2QRYAPREQS.m

Go to the documentation of this file.
SDES2QRYAPREQS ;ALB/BWF - QUERY APPOINTMENT REQUESTS; JAN 4,2023
 ;;5.3;Scheduling;**869,873,875,877**;Aug 13, 1993;Build 14
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ; SDCONTEXT
 ;
 ;S SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37 (required)
 ;S SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
 ;S SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
 ;S SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
 ;S SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
 ;
 ; SDINPUT
 ;S SDINPUT("FILTER","PATIENT",PATIENT IEN)=""       <- for searching by patient
 ;S SDINPUT("FILTER","REQUEST TYPE","APPT")=""       <- for APPT
 ;S SDINPUT("FILTER","REQUEST TYPE","CONSULT")=""    <- for CONSULT
 ;S SDINPUT("FILTER","REQUEST TYPE","RECALL")=""     <- for RECALL
 ;S SDINPUT("FILTER","REQUEST TYPE","ALL")=""        <- for ALL request types
 ;S SDINPUT("FILTER","REQUEST SUBTYPE","APPT")=""    <- for APPT requests
 ;S SDINPUT("FILTER","REQUEST SUBTYPE","RTC")=""     <- for RTC requests
 ;S SDINPUT("FILTER","REQUEST SUBTYPE","VETERAN")="" <- for VETERAN requests
 ;S SDINPUT("FILTER","REQUEST SUBTYPE","ALL")=""     <- for ALL request sub-types (default)
 ;S SDINPUT("FILTER","CLINIC",CLINIC IEN)=""
 ;S SDINPUT("FILTER","SERVICE",AMIS STOP CODE)=""
 ;S SDINPUT("FILTER","PRIORITY GROUP","GROUP 0")="" <- for group 0
 ;                                   ,"GROUP 1")="" <- for group 1
 ;                                   ,"GROUP 2")="" <- for group 2
 ;                                   ,"GROUP 3")="" <- for group 3
 ;                                   ,"GROUP 4")="" <- for group 4
 ;                                   ,"GROUP 5")="" <- for group 5
 ;                                   ,"GROUP 6")="" <- for group 6
 ;                                   ,"GROUP 7")="" <- for group 7
 ;                                   ,"GROUP 8")="" <- for group 8
 ;                                   ,"ALL")=""     <- for ALL groups
 ;S SDINPUT("FILTER","WAIT TIME")=WAIT TIME
 ;                                           ALL - for all days
 ;                                           <30 - less than 30 days
 ;                                           30-60 - 30 to 60 days
 ;                                           60-90 - 60 to 90 days
 ;                                           >=90 - greater than/equal to 90 days
 ;S SDINPUT("FILTER","ORIGINATION DATE")=ORIGINATION DATE
 ;S SDINPUT("FILTER","PID")=PATIENT INDICATED DATE - ALSO DESIRED DATE
 ;S SDINPUT("FILTER","URGENCY")=URGENCY IEN (POINTER TO THE PROTOCOL FILE #101) - only applies to consults
 ;
 ;S SDINPUT("SORT")=SORT TYPE
 ;                   DEFAULT, PATIENT NAME, CLINIC, REQUEST, WAIT TIME, PRIORITY GROUP, ORIGINATION DATE
 ;                   PID DATE, SERVICE RELATED, SCVISIT
 ;
 ;S SDINPUT("MAX NUMBER OF RECORDS")=MAX NUMBER OF TOTAL RECORDS to accumulate for each request type (optional - max/default 200)
 ;S SDINPUT("RETURN NUMBER OF RECORDS")=NUMBER OF RECORDS RETURNED WITH EACH CALL (optional - max 200/default 50)
 ;S SDINPUT("LAST RECORD")=LAST RECORD IEN RETURNED ON THE PREVIOUS CALL (optional)
 ;                         - This is used to get the next batch of records up to the value of 'RETURN NUMBER OF RECORDS'
 ;
QUERY(JSONRETURN,SDCONTEXT,SDINPUT) ;
 N ERRORS,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDDT,REQUESTS,NEWLASTREC,TOTALRECORDS,LASTREC,SDDUZ,AMISLIST
 ; only kill off the data set if we are not retrieving more from the dataset previously acquired
 I '$D(SDINPUT("LAST RECORD")) K ^TMP("SDES2QUERY",$J)
 ; validate context
 S JSONRETURN=$NA(^TMP("SDES2QUERY",$J,"JSON")) K @JSONRETURN
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("QueryResults",1)="" D ENCODE^XLFJSON("ERRORS",.JSONRETURN) Q
 ;
 S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 D VALIDATE(.ERRORS,.SDINPUT,.FLTRORIGDATE,.FLTRPIDDATE,.STARTDT,.ENDDT,.AMISLIST)
 I $D(ERRORS) S ERRORS("QueryResults",1)="" D ENCODE^XLFJSON("ERRORS",.JSONRETURN) Q
 ;
 ; get the next set of records
 I $D(SDINPUT("LAST RECORD")) D  Q
 .I $G(SDINPUT("LAST RECORD"))>($G(^TMP("SDES2QUERY",$J,"COUNT"))-1) D  Q
 ..D ERRLOG^SDES2JSON(.ERRORS,52,"No more records in list.")
 ..S ERRORS("QueryResults",1)=""
 ..D ENCODE^XLFJSON("ERRORS",.JSONRETURN)
 .S NEWLASTREC=$$BUILDBYLASTREC($G(SDINPUT("LAST RECORD")),$G(SDINPUT("RETURN NUMBER OF RECORDS")),.REQUESTS,SDDUZ)
 .I '$D(REQUESTS) D  Q
 ..S REQUESTS("QueryResults",1)="" D ENCODE^XLFJSON("REQUESTS",.JSONRETURN) Q
 .S REQUESTS("QueryResults","LastRecord")=$G(NEWLASTREC)
 .S REQUESTS("QueryResults","TotalRecords")=$G(^TMP("SDES2QUERY",$J,"COUNT"))
 .D ENCODE^XLFJSON("REQUESTS",.JSONRETURN)
 ;
 ; find by patient
 I $D(SDINPUT("FILTER","PATIENT")) D  Q
 .D FINDBYPAT(.ERRORS,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT)
 .S TOTALRECORDS=$$BUILDXREF($G(SDINPUT("SORT")))
 .S LASTREC=$$BUILDRESULTS($G(SDINPUT("RETURN NUMBER OF RECORDS")),.REQUESTS,SDDUZ)
 .I '$D(REQUESTS) D
 ..S REQUESTS("QueryResults","TotalRecords")=""
 ..S REQUESTS("QueryResults","LastRecord")=""
 .S REQUESTS("QueryResults","TotalRecords")=$G(TOTALRECORDS)
 .S REQUESTS("QueryResults","LastRecord")=$G(LASTREC)
 .D ENCODE^XLFJSON("REQUESTS",.JSONRETURN)
 ;
 ; find by request type
 I $D(SDINPUT("FILTER","REQUEST TYPE")) D  Q
 .D FINDBYREQ^SDES2QRYAPREQSA(.ERRORS,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT)
 .S TOTALRECORDS=$$BUILDXREF($G(SDINPUT("SORT")))
 .S LASTREC=$$BUILDRESULTS($G(SDINPUT("RETURN NUMBER OF RECORDS")),.REQUESTS,SDDUZ)
 .I '$D(REQUESTS) D
 ..S REQUESTS("QueryResults","TotalRecords")=""
 ..S REQUESTS("QueryResults","LastRecord")=""
 .S REQUESTS("QueryResults","TotalRecords")=$G(TOTALRECORDS)
 .S REQUESTS("QueryResults","LastRecord")=$G(LASTREC)
 .D ENCODE^XLFJSON("REQUESTS",.JSONRETURN)
 Q
VALIDATE(ERRORS,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,AMISLIST) ;
 N NUMRECORDS,VPAT,VRET,VCLIN,VAMIS,STRTENDDATES,NUMRECORDS,RETURNRECORDCNT,VALSTAT,STOPCODEIEN,STOPCODETYPE,STOPCODELIST
 S (FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT)=""
 S VPAT=0 F  S VPAT=$O(SDINPUT("FILTER","PATIENT",VPAT)) Q:'VPAT  D
 .D VALFILEIEN^SDES2VALUTIL(.VRET,.ERRORS,2,VPAT,1,,1,2)
 ; validate request type
 D VALREQTYPE(.ERRORS,.SDINPUT)
 ; validate request sub-type
 D VALREQSUBTYPE(.ERRORS,.SDINPUT)
 ; validate clinic/clinic list
 S VCLIN=0 F  S VCLIN=$O(SDINPUT("FILTER","CLINIC",VCLIN)) Q:'VCLIN  D
 .D VALFILEIEN^SDES2VALUTIL(.VRET,.ERRORS,44,VCLIN,1,,18,19)
 ; validate services/AMIS stop codes
 S VAMIS=0 F  S VAMIS=$O(SDINPUT("FILTER","SERVICE",VAMIS)) Q:'VAMIS  D
 .S STOPCODEIEN=$$AMISTOSTOPCODE^SDES2UTIL(VAMIS)
 .D VALFILEIEN^SDES2VALUTIL(.VRET,.ERRORS,40.7,STOPCODEIEN,1,,92,93) Q:'VRET
 .S STOPCODELIST(STOPCODEIEN)=""
 I $D(STOPCODELIST) D
 .M AMISLIST=SDINPUT("FILTER","SERVICE")
 .K SDINPUT("FILTER","SERVICE")
 .M SDINPUT("FILTER","SERVICE")=STOPCODELIST
 ; validate wait time
 I '$D(SDINPUT("FILTER","WAIT TIME")) S SDINPUT("FILTER","WAIT TIME")="ALL"
 S STRTENDDATES=$$VALWAITTIME(.ERRORS,$G(SDINPUT("FILTER","WAIT TIME")))
 S STARTDT=$P(STRTENDDATES,U)
 S ENDDT=$P(STRTENDDATES,U,2)
 ; priority group
 D VALPRIOGROUP(.ERRORS,.SDINPUT)
 ; origination date
 I $D(SDINPUT("FILTER","ORIGINATION DATE")) D
 .S FLTRORIGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(SDINPUT("FILTER","ORIGINATION DATE")),,,48,49)
 ; PID date
 I $D(SDINPUT("FILTER","PID")) D
 .S FLTRPIDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(SDINPUT("FILTER","PID")),,,,548)
 ; urgency
 I $D(SDINPUT("FILTER","URGENCY")) D VALFILEIEN^SDES2VALUTIL(.VRET,.ERRORS,101,$G(SDINPUT("FILTER","URGENCY")))
 ; validate sort - default if needed
 I $G(SDINPUT("SORT"))="" S SDINPUT("SORT")="DEFAULT"
 D VALSORT(.ERRORS,$G(SDINPUT("SORT")))
 ; validate number of records
 S NUMRECORDS=$G(SDINPUT("MAX NUMBER OF RECORDS"))
 I NUMRECORDS D VALNUMBERRNG^SDES2VALUTIL(.VALSTAT,.ERRORS,NUMRECORDS,1,200,,,504)
 I NUMRECORDS,'$D(SDINPUT("LAST RECORD")) S SDINPUT("MAX NUMBER OF RECORDS")=NUMRECORDS-1
 ; default to 199 (will return 200)
 I 'NUMRECORDS S SDINPUT("MAX NUMBER OF RECORDS")=199
 ; number of records to return, default to 50
 S RETURNRECORDCNT=$G(SDINPUT("RETURN NUMBER OF RECORDS"))
 I RETURNRECORDCNT D VALNUMBERRNG^SDES2VALUTIL(.VALSTAT,.ERRORS,RETURNRECORDCNT,1,200,,,504)
 I 'RETURNRECORDCNT S SDINPUT("RETURN NUMBER OF RECORDS")=50
 Q
FINDBYPAT(ERRORS,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT) ;
 ; get consults for this patient
 N CONSIEN,PATIENT,CONSTAT,COUNT,DFN,PCE,PRIORITYGROUP,REQIEN,CONSTART,CONEND,INVDTTM,CURRENTENR,ENRRET,PATSCPERCENT,PATSVCCONN,REQCNT
 N GMRSERVICE,INVSTART,SERVICE,STAT,OSPEND,OSACT,RECALLIEN,SERVICELIST,GMRSVC
 S COUNT=0
 S DFN=0 F  S DFN=$O(SDINPUT("FILTER","PATIENT",DFN)) Q:'DFN  D
 .; this line replaces all of the above logic - request SCHEDULING be added to ICR 3812
 .D GETPATENR^SDES2QRYAPREQSB(DFN,.PRIORITYGROUP,.CURRENTENR,.PATSVCCONN,.PATSCPERCENT)
 .I $D(SDINPUT("FILTER","PRIORITY GROUP")),('$D(SDINPUT("FILTER","PRIORITY GROUP",PRIORITYGROUP))&'$D(SDINPUT("FILTER","PRIORITY GROUP","ALL"))) Q
 .;
 .; appointment requests
 .I $D(SDINPUT("FILTER","REQUEST TYPE","APPT"))!($D(SDINPUT("FILTER","REQUEST TYPE","ALL"))) D
 ..Q:$D(SDINPUT("FILTER","URGENCY"))
 ..S REQCNT=0
 ..S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"B",DFN,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...Q:$$GET1^DIQ(409.85,REQIEN,23,"I")="C"
 ...D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 .;
 .; consults
 .I $D(SDINPUT("FILTER","REQUEST TYPE","CONSULT"))!($D(SDINPUT("FILTER","REQUEST TYPE","ALL"))) D
 ..S REQCNT=0
 ..; by service
 ..I $D(SDINPUT("FILTER","SERVICE")) D  Q
 ...S SERVICE=0 F  S SERVICE=$O(SDINPUT("FILTER","SERVICE",SERVICE)) Q:'SERVICE  D
 ....S SERVICELIST(SERVICE)=SERVICE
 ...D GETSVC^SDES2QRYAPREQSA(.GMRSVC,.SERVICELIST)
 ...S OSACT=$O(^ORD(100.01,"B","ACTIVE",0))
 ...S OSPEND=$O(^ORD(100.01,"B","PENDING",0))
 ...S GMRSERVICE=0 F  S GMRSERVICE=$O(GMRSVC(GMRSERVICE)) Q:'GMRSERVICE  D
 ....F STAT=OSACT,OSPEND Q:REQCNT>SDINPUT("MAX NUMBER OF RECORDS")  D
 .....Q:STAT=""
 .....S INVSTART=9999999-ENDDT-1
 .....F  S INVSTART=$O(^GMR(123,"AE",GMRSERVICE,STAT,INVSTART)) Q:'INVSTART!($P(INVSTART,".")>(9999999-STARTDT))!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ......S CONSIEN=0 F  S CONSIEN=$O(^GMR(123,"AE",GMRSERVICE,STAT,INVSTART,CONSIEN)) Q:'CONSIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .......Q:$$GET1^DIQ(123,CONSIEN,.02,"I")'=DFN
 .......Q:$$REQCHK^SDES2QRYAPREQSA(CONSIEN)
 .......D GETPATENR^SDES2QRYAPREQSB(DFN,.PRIORITYGROUP,.CURRENTENR,.PATSVCCONN,.PATSCPERCENT)
 .......D FLTRCONSULT^SDES2QRYAPREQSB(CONSIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 ..; by date/time
 ..S CONSTART=9999999-STARTDT,CONEND=9999999-ENDDT
 ..S INVDTTM=CONEND
 ..F  S INVDTTM=$O(^GMR(123,"AD",DFN,INVDTTM)) Q:'INVDTTM!(INVDTTM>CONSTART)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...S CONSIEN=0
 ...F  S CONSIEN=$O(^GMR(123,"AD",DFN,INVDTTM,CONSIEN)) Q:'CONSIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ....Q:$$REQCHK^SDES2QRYAPREQSA(CONSIEN)
 ....D FLTRCONSULT^SDES2QRYAPREQSB(CONSIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 .;
 .; recalls
 .I $D(SDINPUT("FILTER","REQUEST TYPE","RECALL"))!($D(SDINPUT("FILTER","REQUEST TYPE","ALL"))) D
 ..Q:$D(SDINPUT("FILTER","URGENCY"))
 ..S REQCNT=0
 ..S RECALLIEN=0 F  S RECALLIEN=$O(^SD(403.5,"B",DFN,RECALLIEN)) Q:'RECALLIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...D FLTRRECALL^SDES2QRYAPREQSB(RECALLIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 Q
BUILDXREF(SORT) ;
 N SORTBY,REQIEN,DESDATE,ORIGDT,REQTYPE,COUNT,PRIOGRP,SERVICEREL
 S RECORDER=0
 I SORT="DEFAULT"!(SORT="PRIORITY GROUP") D  Q RECORDER
 .S PRIOGRP="" F  S PRIOGRP=$O(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP)) Q:PRIOGRP=""  D
 ..S SERVICEREL="" F  S SERVICEREL=$O(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP,SERVICEREL)) Q:SERVICEREL=""  D
 ...S DESDATE="" F  S DESDATE=$O(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP,SERVICEREL,DESDATE)) Q:DESDATE=""  D
 ....S ORIGDT="" F  S ORIGDT=$O(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP,SERVICEREL,DESDATE,ORIGDT)) Q:ORIGDT=""  D
 .....S REQIEN=0 F  S REQIEN=$O(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP,SERVICEREL,DESDATE,ORIGDT,REQIEN)) Q:'REQIEN  D
 ......S REQTYPE=$G(^TMP("SDES2QUERY",$J,"DATA",PRIOGRP,SERVICEREL,DESDATE,ORIGDT,REQIEN))
 ......S RECORDER=RECORDER+1
 ......S ^TMP("SDES2QUERY",$J,"XREF",RECORDER,REQIEN)=REQTYPE
 S SORTBY="" F  S SORTBY=$O(^TMP("SDES2QUERY",$J,"DATA",SORTBY)) Q:SORTBY=""  D
 .S REQIEN="" F  S REQIEN=$O(^TMP("SDES2QUERY",$J,"DATA",SORTBY,REQIEN)) Q:REQIEN=""  D
 ..S REQTYPE=$G(^TMP("SDES2QUERY",$J,"DATA",SORTBY,REQIEN))
 ..S RECORDER=RECORDER+1
 ..S ^TMP("SDES2QUERY",$J,"XREF",RECORDER,REQIEN)=REQTYPE
 Q RECORDER
 ;
BUILDRESULTS(RETURNNUMREC,REQUESTS,SDDUZ) ;
 N LASTREC,RECORDER,REQIEN,REQTYPE,DFN
 S LASTREC=""
 S RECORDER=0 F  S RECORDER=$O(^TMP("SDES2QUERY",$J,"XREF",RECORDER)) Q:'RECORDER!(RECORDER>RETURNNUMREC)  D
 .S REQIEN=0 F  S REQIEN=$O(^TMP("SDES2QUERY",$J,"XREF",RECORDER,REQIEN)) Q:'REQIEN!(RECORDER>RETURNNUMREC)  D
 ..S REQTYPE=$G(^TMP("SDES2QUERY",$J,"XREF",RECORDER,REQIEN)) Q:REQTYPE=""
 ..S LASTREC=RECORDER
 ..I REQTYPE="A" D GETREQUEST^SDES2GETAPPTREQ(.REQUESTS,REQIEN,SDDUZ)
 ..I REQTYPE="C" D GETCONSULT^SDES2GETCONSULTS(.REQUESTS,REQIEN,SDDUZ)
 ..I REQTYPE="R" S DFN=$$GET1^DIQ(403.5,REQIEN,.01,"I") D GETRECALL^SDES2GETRECALL(.REQUESTS,REQIEN,DFN,SDDUZ)
 Q LASTREC
 ;
BUILDBYLASTREC(LASTRECORD,NUMRECORDS,REQUESTS,SDDUZ) ;
 N RECORDER,COUNT,REQTYPE,REQIEN,NEWLASTRECORD,DFN
 S COUNT=0,NEWLASTRECORD=""
 S RECORDER=LASTRECORD
 F  S RECORDER=$O(^TMP("SDES2QUERY",$J,"XREF",RECORDER)) Q:'RECORDER!(COUNT>NUMRECORDS)  D
 .S REQIEN=$O(^TMP("SDES2QUERY",$J,"XREF",RECORDER,0)) Q:'REQIEN
 .S REQTYPE=$G(^TMP("SDES2QUERY",$J,"XREF",RECORDER,REQIEN))
 .I REQTYPE="A" D GETREQUEST^SDES2GETAPPTREQ(.REQUESTS,REQIEN,SDDUZ)
 .I REQTYPE="C" D GETCONSULT^SDES2GETCONSULTS(.REQUESTS,REQIEN,SDDUZ)
 .I REQTYPE="R" S DFN=$$GET1^DIQ(403.5,REQIEN,.01,"I") D GETRECALL^SDES2GETRECALL(.REQUESTS,REQIEN,DFN,SDDUZ)
 .S NEWLASTRECORD=RECORDER
 .S COUNT=COUNT+1
 Q NEWLASTRECORD
VALREQTYPE(ERRORS,SDINPUT) ;
 N TYPE
 ; default request type to all
 I '$D(SDINPUT("FILTER","REQUEST TYPE")) S SDINPUT("FILTER","REQUEST TYPE","ALL")="" Q
 ; check for invalid request types
 S TYPE="" F  S TYPE=$O(SDINPUT("FILTER","REQUEST TYPE",TYPE)) Q:TYPE=""  D
 .I "CONSULT^RECALL^APPT^ALL"'[TYPE D ERRLOG^SDES2JSON(.ERRORS,61)
 Q
VALREQSUBTYPE(ERRORS,SDINPUT)   ;
 N TYPE
 ; default request type to all
 I '$D(SDINPUT("FILTER","REQUEST SUBTYPE")) S SDINPUT("FILTER","REQUEST SUBTYPE","ALL")="" Q
 ; check for invalid request types
 S TYPE="" F  S TYPE=$O(SDINPUT("FILTER","REQUEST SUBTYPE",TYPE)) Q:TYPE=""  D
 .I "^APPT^RTC^VETERAN^ALL"'[TYPE D ERRLOG^SDES2JSON(.ERRORS,559)
 Q
VALWAITTIME(ERRORS,WAITTIME) ;
 N SDBEG,SDEND
 I WAITTIME'="","<30^30-60^60-90^>=90^ALL"'[WAITTIME D ERRLOG^SDES2JSON(.ERRORS,52,"Invalid wait time.") Q ""
 S SDBEG=$S(WAITTIME["ALL":"",WAITTIME="<30":"29",WAITTIME="30-60":"60",WAITTIME="60-90":"90",WAITTIME=">=90":"",1:"")
 S SDEND=$S(WAITTIME["ALL":"",WAITTIME="<30":"DT",WAITTIME="30-60":"30",WAITTIME="60-90":"60",WAITTIME=">=90":"90",1:"90")
 I SDBEG'="" S SDBEG=$$FMADD^XLFDT(DT,-SDBEG)
 I SDBEG="" S SDBEG=1410102
 I SDEND'="" S SDEND=$$FMADD^XLFDT(DT,-SDEND)
 I SDEND="" S SDEND=4141015
 Q SDBEG_U_SDEND
 ;
VALPRIOGROUP(ERRORS,SDINPUT) ;
 N PGROUP,GRP
 S PGROUP="" F  S PGROUP=$O(SDINPUT("FILTER","PRIORITY GROUP",PGROUP)) Q:PGROUP=""  D
 .I PGROUP="ALL" D  Q
 ..F GRP=0:1:8  S SDINPUT("FILTER","PRIORITY GROUP",GRP)=""
 .I PGROUP="GROUP 0" S SDINPUT("FILTER","PRIORITY GROUP",0)="" Q
 .D VALFIELD^SDES2VALUTIL(.VRET,.ERRORS,409.85,10.5,PGROUP) Q:'VRET
 .S SDINPUT("FILTER","PRIORITY GROUP",$G(VRET(409.85,10.5,"I")))=""
 Q
 ;
VALSORT(ERRORS,SORT) ;
 I "DEFAULT^PATIENT NAME^CLINIC^REQUEST^WAIT TIME^PRIORITY GROUP^ORIGINATION DATE^PID DATE^SERVICE RELATED^SCVISIT"'[$G(SORT) D ERRLOG^SDES2JSON(.ERRORS,52,"Invalid sort criteria.")
 Q