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

SDES2QRYAPREQSA.m

Go to the documentation of this file.
SDES2QRYAPREQSA ;ALB/BWF - QUERY APPOINTMENT REQUESTS; JAN 4,2023
 ;;5.3;Scheduling;**869,875,885**;Aug 13, 1993;Build 5
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
FINDBYREQ(ERRORS,SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT) ;
 N REQCNT,DFN,PRIORITYGROUP,CURRENTENR,PATSVCCONN,PATSCPERCENT,COUNT,REQCNT,CLINIEN,REQIEN,REQDATE,STOPDATE
 N PGROUP,CLINIC,FLTRPRIOGROUP,SERVICELIST,STAT,STOPCDATE,CONSIEN,GMRSERVICE,INVSTART,RECALLIEN,SERVICE
 S COUNT=0
 ;
 ; appointment requests
 ;
 I $D(SDINPUT("FILTER","REQUEST TYPE","APPT"))!($D(SDINPUT("FILTER","REQUEST TYPE","ALL"))) D
 .S REQCNT=0
 .; by clinic
 .I $D(SDINPUT("FILTER","CLINIC")) D
 ..S CLINIEN=0 F  S CLINIEN=$O(SDINPUT("FILTER","CLINIC",CLINIEN)) Q:'CLINIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...; use GCC when filtering by PID DATE
 ...I FLTRPIDDATE'="" D  Q
 ....S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"ECC","O",CLINIEN,FLTRPIDDATE,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .....S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 .....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
 .....D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 ...; use EC when not filtering by PID DATE
 ...S REQDATE=$S(FLTRORIGDATE:FLTRORIGDATE-.01,1:STARTDT-.01)
 ...S STOPDATE=$S(FLTRORIGDATE:FLTRORIGDATE_.9999,1:ENDDT)
 ...F  S REQDATE=$O(^SDEC(409.85,"EC","O",CLINIEN,REQDATE)) Q:'REQDATE!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ....S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"EC","O",CLINIEN,REQDATE,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .....S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 .....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
 .....D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 .;
 .; by service
 .I $D(SDINPUT("FILTER","SERVICE")) D
 ..S SERVICE=0 F  S SERVICE=$O(SDINPUT("FILTER","SERVICE",SERVICE)) Q:'SERVICE!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...;
 ...; filter by PID date (aka desired date)
 ...I FLTRPIDDATE D  Q
 ....S REQDATE=FLTRPIDDATE-.01
 ....S STOPDATE=FLTRPIDDATE_.9999
 ....F  S REQDATE=$O(^SDEC(409.85,"ESC","O",SERVICE,REQDATE)) Q:'REQDATE!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .....S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"ESC","O",SERVICE,REQDATE,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ......S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 ......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
 ......D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 ...;
 ...; filter by enrollment priority
 ...I $D(SDINPUT("FILTER","PRIORITY GROUP")) D  Q
 ....S REQDATE=STARTDT-.01
 ....S STOPDATE=ENDDT_.9999
 ....; all groups
 ....I $D(SDINPUT("FILTER","PRIORITY GROUP","ALL")) D  Q
 .....S PGROUP="" F  S PGROUP=$O(^SDEC(409.85,"ESP","O",SERVICE,PGROUP)) Q:PGROUP=""!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ......F  S REQDATE=$O(^SDEC(409.85,"ESP","O",SERVICE,PGROUP,REQDATE)) Q:'REQDATE!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .......S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"ESP","O",SERVICE,PGROUP,REQDATE,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ........S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 ........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
 ........D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 ....; filter by specific groups - start at A to only pick up "GROUP n"
 ....S FLTRPRIOGROUP="A" F  S FLTRPRIOGROUP=$O(SDINPUT("FILTER","PRIORITY GROUP",FLTRPRIOGROUP)) Q:FLTRPRIOGROUP=""  D
 .....S PGROUP=$P(FLTRPRIOGROUP," ",2)
 .....F  S REQDATE=$O(^SDEC(409.85,"ESP","O",SERVICE,PGROUP,REQDATE)) Q:'REQDATE!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ......S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"ESP","O",SERVICE,PGROUP,REQDATE,REQIEN)) Q:'REQIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .......S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 .......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
 .......D FLTRAPPTREQ^SDES2QRYAPREQSB(REQIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 ...;
 ...S REQDATE=STARTDT-.01
 ...S STOPDATE=ENDDT_.9999
 ...F  S REQDATE=$O(^SDEC(409.85,"ES","O",SERVICE,REQDATE)) Q:'REQDATE!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ....S REQIEN=0 F  S REQIEN=$O(^SDEC(409.85,"ES","O",SERVICE,REQDATE,REQIEN)) Q:'REQIEN!(REQDATE>STOPDATE)!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 .....S DFN=$$GET1^DIQ(409.85,REQIEN,.01,"I") Q:'DFN
 .....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
 .....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 clinic
 .I $D(SDINPUT("FILTER","CLINIC")) D  Q
 ..S CLINIC=0 F  S CLINIC=$O(SDINPUT("FILTER","CLINIC",CLINIC)) Q:'CLINIC!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...S CONSIEN=0 F  S CONSIEN=$O(^GMR(123,"H",CLINIC,CONSIEN)) Q:'CONSIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ....Q:$$REQCHK(CONSIEN)
 ....S DFN=$$GET1^DIQ(123,CONSIEN,.02,"I") Q:'DFN
 ....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
 ....D FLTRCONSULT^SDES2QRYAPREQSB(CONSIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 .; 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 GMRSERVICE=0 F  S GMRSERVICE=$O(GMRSVC(GMRSERVICE)) Q:'GMRSERVICE  D
 ...S OSACT=$O(^ORD(100.01,"B","ACTIVE",0))
 ...S OSPEND=$O(^ORD(100.01,"B","PENDING",0))
 ...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:$$REQCHK(CONSIEN)
 ......S DFN=$$GET1^DIQ(123,CONSIEN,.02,"I") Q:'DFN
 ......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
 ......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
 .S REQCNT=0
 .I $D(SDINPUT("FILTER","CLINIC")) D  Q
 ..S CLINIC=0 F  S CLINIC=$O(SDINPUT("FILTER","CLINIC",CLINIC)) Q:'CLINIC!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ...S RECALLIEN=0 F  S RECALLIEN=$O(^SD(403.5,"E",CLINIC,RECALLIEN)) Q:'RECALLIEN!(REQCNT>SDINPUT("MAX NUMBER OF RECORDS"))  D
 ....S DFN=$$GET1^DIQ(403.5,RECALLIEN,.01,"I") Q:'DFN
 ....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
 ....D FLTRRECALL^SDES2QRYAPREQSB(RECALLIEN,.SDINPUT,FLTRORIGDATE,FLTRPIDDATE,STARTDT,ENDDT,PRIORITYGROUP,PATSVCCONN,PATSCPERCENT,.COUNT,.REQCNT)
 Q
 ;
REQCHK(SDGMR,DFN) ;alb/sat 658 - new rules for consult check
 N CPRSTAT,IFC,OSACT,OSPEND
 Q:'$D(^GMR(123,+$G(SDGMR),0)) 1
 S OSACT=$O(^ORD(100.01,"B","ACTIVE",0))
 S OSPEND=$O(^ORD(100.01,"B","PENDING",0))
 S CPRSTAT=$$GET1^DIQ(123,SDGMR_",",8,"I")
 Q:'((CPRSTAT=OSACT)!(CPRSTAT=OSPEND)) 1
 S IFC=$$GET1^DIQ(123,SDGMR,.125,"I")
 Q:IFC="P" 1
 Q 0
 ;
CHECKSERVICES(SDINPUT,SERVICEIEN) ;
 N STOPCODES,FOUND,SFIENS,STOPCODE
 S FOUND=0
 D GETS^DIQ(123.5,SERVICEIEN_",","688*","IE","STOPCODES")
 S SFIENS="" F  S SFIENS=$O(STOPCODES(123.5688,SFIENS)) Q:SFIENS=""  D
 .S STOPCODE=$G(STOPCODES(123.5688,SFIENS,.01,"I")) Q:'STOPCODE
 .I $D(SDINPUT("FILTER","SERVICE",STOPCODE)) S FOUND=1
 Q FOUND
 ;
STOP(GMRSTOP,SDGMR)  ;get stop codes from field 688 of REQUEST SERVICES file 123.5
 ; .GMRSTOP - returned array of STOP CODE pointers to CLINIC STOP file 40.7
 ;            GMRSTOP(<clinic stop id>)=<clinic stop name>
 ;  SDGMR   - (required) pointer to REQUEST/CONSULTATION file 123
 N RS,SDDATA,SDI,SDIEN,SDNM
 K GMRSTOP
 S RS=$$GET1^DIQ(123,SDGMR_",",1,"I")  ;get TO SERVICE
 D GETS^DIQ(123.5,RS_",","688*","IE","SDDATA")
 S SDI=0 F  S SDI=$O(SDDATA(123.5688,SDI)) Q:SDI=""  D
 .S SDIEN=$G(SDDATA(123.5688,SDI,.01,"I"))
 .S SDNM=$G(SDDATA(123.5688,SDI,.01,"E"))
 .S:+SDIEN GMRSTOP(SDIEN)=SDNM
 Q
 ;
GETSVC(GMRSVC,SVC)  ;get REQUEST SERVICES entries for given stop codes
 ; .GMRSVC - returned array of REQUEST SERVICES entries
 ; .SVC    - input array of clinic stop codes SVC(NAME)=ID pointer to CLINIC STOP file 40.7
 N AB1,ID,SDN,STOP
 K GMRSVC
 S SDN="" F  S SDN=$O(SVC(SDN)) Q:SDN=""  D
 .I SVC(SDN)="" Q
 .S STOP=SVC(SDN) I '$D(^DIC(40.7,STOP,0)) Q
 .S ID=0 F  S ID=$O(^GMR(123.5,"AB1",STOP,ID)) Q:ID=""  D
 ..S AB1=0 F  S AB1=$O(^GMR(123.5,"AB1",STOP,ID,AB1)) Q:AB1=""  D
 ...Q:STOP'=$P($G(^GMR(123.5,ID,688,AB1,0)),U,1)
 ...S GMRSVC(ID)=""
 Q
 ;
PRIO(SDGMR) ;
 N CNT,F81,FED,PRIO,PRIO1,RET,SDED,SDI   ;alb/sat 658 added CNT, F81 and SDI
 ;alb/sat 658 start modification - if GMRC*3.0*81 has been installed/loaded at or before the file entry date/time, then always use the Earliest Date (Clinically Indicated Date)
 S F81=9999999
 S CNT=$$INSTALDT^XPDUTL("GMRC*3.0*81",.RET)
 I CNT>0 S F81=$O(RET(0))
 S SDED=$P($$GET1^DIQ(123,SDGMR_",",17,"I"),".",1)   ;earliest date  ;ICR 6185  ;alb/sat 658 moved this and next line up from under 'S PRIO=""'
 S FED=$P($$GET1^DIQ(123,SDGMR_",",.01,"I"),".",1)   ;file entry date  ;ICR 4837
 S PRIO=""
 I F81'>FED S PRIO=SDED Q PRIO
 ;alb/sat 658 end modification
 S PRIO1=$$GET1^DIQ(123,SDGMR_",",5)                 ;urgency text  ;ICR 4837
 I SDED="" S PRIO=PRIO1               ;2.6.17.2 - use URGENCY text if EARLIEST DATE is null
 I (PRIO=""),(FED="")!(SDED'=FED) S PRIO=SDED  ;2.6.17.1 - use EARLIEST DATE if not = FILE ENTRY DATE
 I (PRIO=""),((PRIO1["STAT")!(PRIO1["NEXT AVAILABLE")!(PRIO1["EMERGENCY")!(PRIO1["TODAY")) S PRIO=SDED  ;2.6.17.3
 S:PRIO="" PRIO=PRIO1  ;2.6.17.3
 Q PRIO   ;alb/sat 658 added PRIOX tag