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

SDES2GREQSINST.m

Go to the documentation of this file.
SDES2GREQSINST ;ALB/BWF - SDES2 get all appointment requests by institution ;JUL 18, 2023
 ;;5.3;Scheduling;**853,877**;Aug 13, 1993;Build 14
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ;
 ; INPUT
 ;
 ; SDCONTEXT Array
 ;
 ; SDAPPTREQS("STATION NUMBER") - (optional) - Institution Station Number
 ; SDAPPTREQS("NUMBER")         - (optional) - the number of records to find for each appointment request type
 ;                                             consult/procedure, appointment request, and recall.
 ;
GETREQUESTS(RESULTS,SDCONTEXT,SDAPPTREQS) ;
 N CONSIEN,CPRSSTAT,CONSTATACTIVE,CONSCNT,CONSDTTM,NUMRECORDS,CONSTATPENDING,APPTREQIEN,RECALLDTTM,RECALLIEN,REQUEST,RECALLCNT
 N DFN,RECALLUSER,RECALLIEN,RECALLPTR,CONSPTR,APPTREQCNT,APPTREQDTTM,APPTREQIEN,APPTREQPTR,DATELOOP,IENLOOP
 N RECORDIEN,RECORDPTR,GMRCNT,ERRORS,APPTREQENTERED,STAT,INST,CONSINST,RECALLCLIN,RECALLDIV,RECALLINST,STATION,VALSTAT,SDDUZ
 K ^TMP("SDES2GREQSINST",$J)
 ; validate context array
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.RESULTS,.ERRORS) Q
 S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
 ; validate input array
 S STATION=$G(SDAPPTREQS("STATION NUMBER"))
 S INST=$$IEN^XUAF4(STATION)
 I STATION]"",'INST D ERRLOG^SDES2JSON(.ERRORS,197)
 S NUMRECORDS=$G(SDAPPTREQS("NUMBER"))
 I NUMRECORDS D VALNUMBERRNG^SDES2VALUTIL(.VALSTAT,.ERRORS,NUMRECORDS,1,200,,,504)
 I $D(ERRORS) S ERRORS("Request",1)="" D BUILDJSON^SDES2JSON(.RESULTS,.ERRORS) Q
 I 'NUMRECORDS S NUMRECORDS=200
 ; get the consults
 S CONSTATACTIVE=$O(^ORD(100.01,"B","ACTIVE",0))
 S CONSTATPENDING=$O(^ORD(100.01,"B","PENDING",0))
 F STAT=CONSTATACTIVE,CONSTATPENDING D
 .; set CONSCNT here so we get at least NUMRECORDS for each status, allowing us to get a mixture from both pending and active status
 .S (CONSIEN,CONSCNT)=0
 .F  S CONSIEN=$O(^GMR(123,"D",STAT,CONSIEN)) Q:'CONSIEN!(CONSCNT>NUMRECORDS)  D
 ..S CONSDTTM=$$GET1^DIQ(123,CONSIEN,.01,"I")
 ..S CONSINST=$$GET1^DIQ(123,CONSIEN,.05,"I")
 ..I INST,CONSINST,(CONSINST'=INST) Q
 ..S CONSCNT=CONSCNT+1
 ..S CONSPTR=CONSIEN_";GMR(123,"
 ..S ^TMP("SDES2GREQSINST",$J,CONSDTTM,CONSPTR)=""
 ; get recalls
 S RECALLCNT=0
 S RECALLDTTM=0 F  S RECALLDTTM=$O(^SD(403.5,"AC",RECALLDTTM)) Q:'RECALLDTTM!(RECALLCNT=NUMRECORDS)!(RECALLCNT>NUMRECORDS)  D
 .S RECALLUSER=0 F  S RECALLUSER=$O(^SD(403.5,"AC",RECALLDTTM,RECALLUSER)) Q:'RECALLUSER!(RECALLCNT=NUMRECORDS)!(RECALLCNT>NUMRECORDS)  D
 ..S RECALLIEN=0 F  S RECALLIEN=$O(^SD(403.5,"AC",RECALLDTTM,RECALLUSER,RECALLIEN)) Q:'RECALLIEN!(RECALLCNT>NUMRECORDS)  D
 ...S RECALLCLIN=$$GET1^DIQ(403.5,RECALLIEN,4.5,"I")
 ...S RECALLDIV=$$GET1^DIQ(44,RECALLCLIN,3.5,"I")
 ...S RECALLINST=$$GET1^DIQ(40.8,RECALLDIV,.07,"I")
 ...I INST,INST'=RECALLINST Q
 ...S RECALLCNT=RECALLCNT+1
 ...S RECALLPTR=RECALLIEN_";SD(403.5,"
 ...S ^TMP("SDES2GREQSINST",$J,RECALLDTTM,RECALLPTR)=""
 ; get appointment requests
 S APPTREQCNT=0
 S APPTREQDTTM=0 F  S APPTREQDTTM=$O(^SDEC(409.85,"E","O",APPTREQDTTM)) Q:'APPTREQDTTM!(APPTREQCNT=NUMRECORDS)!(APPTREQCNT>NUMRECORDS)  D
 .S APPTREQIEN=0 F  S APPTREQIEN=$O(^SDEC(409.85,"E","O",APPTREQDTTM,APPTREQIEN)) Q:'APPTREQIEN!(APPTREQCNT=NUMRECORDS)!(APPTREQCNT>NUMRECORDS)  D
 ..S APPTREQENTERED=$$GET1^DIQ(409.85,APPTREQIEN,9.5,"I")
 ..I INST,INST'=$$GET1^DIQ(409.85,APPTREQIEN,2,"I") Q
 ..S APPTREQCNT=APPTREQCNT+1
 ..S APPTREQPTR=APPTREQIEN_";SDEC(409.85,"
 ..S ^TMP("SDES2GREQSINST",$J,APPTREQENTERED,APPTREQPTR)=""
 ; process results in ^TMP
 S GMRCNT=0
 S DATELOOP=0 F  S DATELOOP=$O(^TMP("SDES2GREQSINST",$J,DATELOOP)) Q:'DATELOOP  D
 .S IENLOOP="" F  S IENLOOP=$O(^TMP("SDES2GREQSINST",$J,DATELOOP,IENLOOP)) Q:IENLOOP=""  D
 ..S RECORDIEN=$P(IENLOOP,";")
 ..S RECORDPTR=$P(IENLOOP,";",2)
 ..I RECORDPTR["GMR(123" D  Q
 ...Q:GMRCNT=NUMRECORDS!(GMRCNT>NUMRECORDS)
 ...S GMRCNT=GMRCNT+1
 ...D GETCONSULT^SDES2GETCONSULTS(.REQUEST,RECORDIEN,SDDUZ)
 ..I RECORDPTR["SD(403.5" D  Q
 ...D GETRECALL^SDES2GETRECALL(.REQUEST,RECORDIEN,$$GET1^DIQ(403.5,RECORDIEN,.01,"I"),SDDUZ)
 ..I RECORDPTR["SDEC(409.85" D  Q
 ...D GETREQUEST^SDES2GETAPPTREQ(.REQUEST,RECORDIEN,SDDUZ)
 I '$D(REQUEST) S REQUEST("Request",1)="" D BUILDJSON^SDES2JSON(.RESULTS,.REQUEST) K ^TMP("SDES2GREQSINST",$J) Q
 D BUILDJSON^SDES2JSON(.RESULTS,.REQUEST)
 K ^TMP("SDES2GREQSINST",$J)
 Q