SCAPMC28 ;ALB/REW - Patients with an Appointment ; 1/10/05 2:49pm
;;5.3;Scheduling;**41,140,346,1015**;AUG 13, 1993;Build 21
;IHS/ANMC/LJF 12/06/2000 changed SSN to HRCN as Long Patient ID
;
;;1.0
PTAP(SCCL,SCDATES,SCMAXCNT,SCLIST,SCERR,MORE) ; -- list of patients with an appointment in a given clinic
;
; input:
; SCCL = Pointer to File #44
; SCDATES("BEGIN") = begin date to search (inclusive)
; [default: TODAY]
; ("END") = end date to search (inclusive)
; [default: TODAY]
; ("INCL") = 1: only use patients who were assigned to
; team for entire date range
; 0: anytime in date range
; [default: 1]
; SCMAXCNT - Maximum # of patients to return, default=99
; SCLIST -array name to store list
; [ex. ^TMP("SCPT",$J)]
;
; SCERR = array NAME to store error messages.
; [ex. ^TMP("ORXX",$J)]
; MORE - This is a flag that says that this list exists and has been
; aborted because it reached the maxcount. If this =1 it means
; 'kill the old list & start where you finished'
; Note: Don't Return DFNs where $D(^TMP("SCMC",$J,"EXCLUDE PT","SCPTA",+DFN)) is true
; Output:
; SCLIST() = array of patients
; Format:
; Subscript: Sequential # from 1 to n
; Piece Description
; 1 IEN of PATIENT file entry
; 2 Name of patient
; 3 ien to 40.7 - Not Stop Code!! stp=$$intstp
; 4 AMIS reporting stop code
; 5 Patient's Long ID (SSN)
;
; SCEFFDT - negative of effective date
; SCN - current subscript (counter) 1->n
; SCPTA0 is 0 node of Patient Team Assignment file 1st piece is DFN
; SCERR() = Array of DIALOG file messages(errors) .
; @SCERR@(0)=number of errors, undefined if none
; Foramt:
; Subscript: Sequential # from 1 to n
; Piece Description
; 1 IEN of DIALOG file
;
; Returned: 1 if ok, 0 if error^More?
;
;
ST N SCEND,SCVSDT,SCSTART
N SCLSEQ,SCN,SCESEQ,SCPARM,SCP,SCBEGIN,SCEND,SCINCL,SCDTS
G:'$$OKDATA APQ ;check/setup variables
; -- loop through visit file
LP S SCDT=SCBEGIN
S:'$P(SCEND,".",2) SCEND=$$FMADD^XLFDT(SCEND,1) ;ending is end of day
IF $G(MORE) D
.S SCSTART=$P($G(@SCLIST@(0)),U,2)
.S SCBEGIN=$P($G(@SCLIST@(0)),U,3)
.K @SCLIST
APQ Q $$PTAPX(.SCCL,.SCBEGIN,.SCEND,.SCMAXCNT,.SCLIST,.SCERR,.SCSTART)
;
PTAPX(SCCL,SCBEGIN,SCEND,MAXCNT,SCLIST,SCERR,SCSTART) ;return appointments in dt range
; Input: (As above plus:)
; SCSTART - Continue with list at this point
; output: SCN - COUNT OF PTS
; returns: dfn^ptname^clinic^apptdt^long id
;
;initialize variables
N SCDT,SCARRAY,DFN,SDAPTCNT,SDARRAY,SDERR,SDX,SDY
K ^TMP($J,"SDAMA301")
;setup call to SDAPI
S SDARRAY(1)=$G(SCBEGIN)_";"_$G(SCEND),SDARRAY(2)=$G(SCCL),SDARRAY("FLDS")=4
S SDARRAY("SORT")="P"
;call SDAPI to retrieve appointments
S SDAPTCNT=$$SDAPI^SDAMA301(.SDARRAY)
;handle errors if any returned from SDAPI and QUIT
I SDAPTCNT<0 D Q ($G(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
.;call existing error handler
.D ERR^SCAPMCU1(.SCESEQ,,,"",.SCERR)
.K ^TMP($J,"SDAMA301")
;if appointments returned
I SDAPTCNT>0 D
.;retrieve patient ID to start at if continuing list (was appt ifn)
.; * no code could be found to utilize continuation of a list
.; * if this changes this code should be revisited to ensure only 1
.; call to SDAPI is made.
.S DFN=+$G(SCSTART)
.S SCSTART=0
.S SCDT=0
.;resort appts to ensure same data is returned to user
.;only 1st appt date/time is needed for each patient
.;as patient can only be added to the list once.
.K ^TMP($J,"RE-SORT","SDAMA301")
.S (SDY,SDX)=0
.F S SDX=$O(^TMP($J,"SDAMA301",SDX)) Q:'SDX D
..S SDY=$O(^TMP($J,"SDAMA301",SDX,""))
..S ^TMP($J,"RE-SORT","SDAMA301",SDY,SDX)=""
.K ^TMP($J,"SDAMA301")
.;loop through re-sorted appts returned from SDAPI until
.; 1. no more patients with appointments exist
.; 2. number of patients found that match criteria is not less than max
.F S SCDT=$O(^TMP($J,"RE-SORT","SDAMA301",SCDT)) Q:'SCDT!(SCN'<SCMAXCNT) D
..;get patient for the kept appointment in the re-sorted list
..F S DFN=$O(^TMP($J,"RE-SORT","SDAMA301",SCDT,DFN)) Q:'DFN!(SCN'<SCMAXCNT) D
...;quit if patient is found in either of the following lists
...;this list may be used elsewhere, left in for compatibility
...Q:$D(@SCLIST@("SCPTAP",+DFN))
...Q:$D(^TMP("SCMC",$J,"EXCLUDE PT","SCPTA",+DFN))
...;increment the patient counter and store in SCLIST
...S SCN=$G(@SCLIST@(0))+1
...S @SCLIST@(0)=SCN
...;get the patient's long ID (SSN) and Name
...D GETS^DIQ(2,+DFN,".01;.363","","SCARRAY")
...;add the following appt info to SCLIST at the current Patient Counter
...;1. Patient DFN 2. Patient Name 3. Clinic IEN 4. Appt DTM 5. Patients Long ID
...;S @SCLIST@(SCN)=DFN_U_$P($G(^DPT(+DFN,0)),U,1)_U_SCCL_U_SCDT_U_$P($G(^DPT(+DFN,.36)),U,3) ;IHS/ANMC/LJF 12/06/2000
...S @SCLIST@(SCN)=DFN_U_$P($G(^DPT(+DFN,0)),U,1)_U_SCCL_U_SCDT_U_$$HRCN^BDGF2(DFN,+$G(DUZ(2))) ;IHS/ANMC/LJF 12/06/2000
...;add the patient's DFN to the exclusion list
...S @SCLIST@("SCPTAP",+DFN,+SCN)=""
;kill the re-sorted appt global reference generated
K ^TMP($J,"RE-SORT","SDAMA301")
;if # of patients found that match criteria is NOT LESS than the requested Max then
;set SCLIST at the 0 Node to:
;1.Current Patient Count 2. Current Patient Processing 3. Appt DTM 4. Clinic IEN
S:(SCN'<SCMAXCNT) @SCLIST@(0)=SCN_U_+$G(DFN)_U_+$G(SCDT)_U_+$G(SCCL)
Q ($G(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
;
OKDATA() ;check/setup variables
N SCOK
S SCOK=1
S SCMAXCNT=$G(SCMAXCNT,99)
D INIT^SCAPMCU1(.SCOK) ; set default dates & error array (if undefined)
IF '$D(^SC(+$G(SCCL),0)) D S SCOK=0
. S SCPARM("CLINIC")=$G(SCCL,"Undefined")
. D ERR^SCAPMCU1(.SCESEQ,4045101,.SCPARM,"",.SCERR)
; -- is it a valid TEAM ien passed (Error # 4045101 in DIALOG file)
Q SCOK
SCAPMC28 ;ALB/REW - Patients with an Appointment ; 1/10/05 2:49pm
+1 ;;5.3;Scheduling;**41,140,346,1015**;AUG 13, 1993;Build 21
+2 ;IHS/ANMC/LJF 12/06/2000 changed SSN to HRCN as Long Patient ID
+3 ;
+4 ;;1.0
PTAP(SCCL,SCDATES,SCMAXCNT,SCLIST,SCERR,MORE) ; -- list of patients with an appointment in a given clinic
+1 ;
+2 ; input:
+3 ; SCCL = Pointer to File #44
+4 ; SCDATES("BEGIN") = begin date to search (inclusive)
+5 ; [default: TODAY]
+6 ; ("END") = end date to search (inclusive)
+7 ; [default: TODAY]
+8 ; ("INCL") = 1: only use patients who were assigned to
+9 ; team for entire date range
+10 ; 0: anytime in date range
+11 ; [default: 1]
+12 ; SCMAXCNT - Maximum # of patients to return, default=99
+13 ; SCLIST -array name to store list
+14 ; [ex. ^TMP("SCPT",$J)]
+15 ;
+16 ; SCERR = array NAME to store error messages.
+17 ; [ex. ^TMP("ORXX",$J)]
+18 ; MORE - This is a flag that says that this list exists and has been
+19 ; aborted because it reached the maxcount. If this =1 it means
+20 ; 'kill the old list & start where you finished'
+21 ; Note: Don't Return DFNs where $D(^TMP("SCMC",$J,"EXCLUDE PT","SCPTA",+DFN)) is true
+22 ; Output:
+23 ; SCLIST() = array of patients
+24 ; Format:
+25 ; Subscript: Sequential # from 1 to n
+26 ; Piece Description
+27 ; 1 IEN of PATIENT file entry
+28 ; 2 Name of patient
+29 ; 3 ien to 40.7 - Not Stop Code!! stp=$$intstp
+30 ; 4 AMIS reporting stop code
+31 ; 5 Patient's Long ID (SSN)
+32 ;
+33 ; SCEFFDT - negative of effective date
+34 ; SCN - current subscript (counter) 1->n
+35 ; SCPTA0 is 0 node of Patient Team Assignment file 1st piece is DFN
+36 ; SCERR() = Array of DIALOG file messages(errors) .
+37 ; @SCERR@(0)=number of errors, undefined if none
+38 ; Foramt:
+39 ; Subscript: Sequential # from 1 to n
+40 ; Piece Description
+41 ; 1 IEN of DIALOG file
+42 ;
+43 ; Returned: 1 if ok, 0 if error^More?
+44 ;
+45 ;
ST NEW SCEND,SCVSDT,SCSTART
+1 NEW SCLSEQ,SCN,SCESEQ,SCPARM,SCP,SCBEGIN,SCEND,SCINCL,SCDTS
+2 ;check/setup variables
IF '$$OKDATA
GOTO APQ
+3 ; -- loop through visit file
LP SET SCDT=SCBEGIN
+1 ;ending is end of day
IF '$PIECE(SCEND,".",2)
SET SCEND=$$FMADD^XLFDT(SCEND,1)
+2 IF $GET(MORE)
Begin DoDot:1
+3 SET SCSTART=$PIECE($GET(@SCLIST@(0)),U,2)
+4 SET SCBEGIN=$PIECE($GET(@SCLIST@(0)),U,3)
+5 KILL @SCLIST
End DoDot:1
APQ QUIT $$PTAPX(.SCCL,.SCBEGIN,.SCEND,.SCMAXCNT,.SCLIST,.SCERR,.SCSTART)
+1 ;
PTAPX(SCCL,SCBEGIN,SCEND,MAXCNT,SCLIST,SCERR,SCSTART) ;return appointments in dt range
+1 ; Input: (As above plus:)
+2 ; SCSTART - Continue with list at this point
+3 ; output: SCN - COUNT OF PTS
+4 ; returns: dfn^ptname^clinic^apptdt^long id
+5 ;
+6 ;initialize variables
+7 NEW SCDT,SCARRAY,DFN,SDAPTCNT,SDARRAY,SDERR,SDX,SDY
+8 KILL ^TMP($JOB,"SDAMA301")
+9 ;setup call to SDAPI
+10 SET SDARRAY(1)=$GET(SCBEGIN)_";"_$GET(SCEND)
SET SDARRAY(2)=$GET(SCCL)
SET SDARRAY("FLDS")=4
+11 SET SDARRAY("SORT")="P"
+12 ;call SDAPI to retrieve appointments
+13 SET SDAPTCNT=$$SDAPI^SDAMA301(.SDARRAY)
+14 ;handle errors if any returned from SDAPI and QUIT
+15 IF SDAPTCNT<0
Begin DoDot:1
+16 ;call existing error handler
+17 DO ERR^SCAPMCU1(.SCESEQ,,,"",.SCERR)
+18 KILL ^TMP($JOB,"SDAMA301")
End DoDot:1
QUIT ($GET(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
+19 ;if appointments returned
+20 IF SDAPTCNT>0
Begin DoDot:1
+21 ;retrieve patient ID to start at if continuing list (was appt ifn)
+22 ; * no code could be found to utilize continuation of a list
+23 ; * if this changes this code should be revisited to ensure only 1
+24 ; call to SDAPI is made.
+25 SET DFN=+$GET(SCSTART)
+26 SET SCSTART=0
+27 SET SCDT=0
+28 ;resort appts to ensure same data is returned to user
+29 ;only 1st appt date/time is needed for each patient
+30 ;as patient can only be added to the list once.
+31 KILL ^TMP($JOB,"RE-SORT","SDAMA301")
+32 SET (SDY,SDX)=0
+33 FOR
SET SDX=$ORDER(^TMP($JOB,"SDAMA301",SDX))
IF 'SDX
QUIT
Begin DoDot:2
+34 SET SDY=$ORDER(^TMP($JOB,"SDAMA301",SDX,""))
+35 SET ^TMP($JOB,"RE-SORT","SDAMA301",SDY,SDX)=""
End DoDot:2
+36 KILL ^TMP($JOB,"SDAMA301")
+37 ;loop through re-sorted appts returned from SDAPI until
+38 ; 1. no more patients with appointments exist
+39 ; 2. number of patients found that match criteria is not less than max
+40 FOR
SET SCDT=$ORDER(^TMP($JOB,"RE-SORT","SDAMA301",SCDT))
IF 'SCDT!(SCN'<SCMAXCNT)
QUIT
Begin DoDot:2
+41 ;get patient for the kept appointment in the re-sorted list
+42 FOR
SET DFN=$ORDER(^TMP($JOB,"RE-SORT","SDAMA301",SCDT,DFN))
IF 'DFN!(SCN'<SCMAXCNT)
QUIT
Begin DoDot:3
+43 ;quit if patient is found in either of the following lists
+44 ;this list may be used elsewhere, left in for compatibility
+45 IF $DATA(@SCLIST@("SCPTAP",+DFN))
QUIT
+46 IF $DATA(^TMP("SCMC",$JOB,"EXCLUDE PT","SCPTA",+DFN))
QUIT
+47 ;increment the patient counter and store in SCLIST
+48 SET SCN=$GET(@SCLIST@(0))+1
+49 SET @SCLIST@(0)=SCN
+50 ;get the patient's long ID (SSN) and Name
+51 DO GETS^DIQ(2,+DFN,".01;.363","","SCARRAY")
+52 ;add the following appt info to SCLIST at the current Patient Counter
+53 ;1. Patient DFN 2. Patient Name 3. Clinic IEN 4. Appt DTM 5. Patients Long ID
+54 ;S @SCLIST@(SCN)=DFN_U_$P($G(^DPT(+DFN,0)),U,1)_U_SCCL_U_SCDT_U_$P($G(^DPT(+DFN,.36)),U,3) ;IHS/ANMC/LJF 12/06/2000
+55 ;IHS/ANMC/LJF 12/06/2000
SET @SCLIST@(SCN)=DFN_U_$PIECE($GET(^DPT(+DFN,0)),U,1)_U_SCCL_U_SCDT_U_$$HRCN^BDGF2(DFN,+$GET(DUZ(2)))
+56 ;add the patient's DFN to the exclusion list
+57 SET @SCLIST@("SCPTAP",+DFN,+SCN)=""
End DoDot:3
End DoDot:2
End DoDot:1
+58 ;kill the re-sorted appt global reference generated
+59 KILL ^TMP($JOB,"RE-SORT","SDAMA301")
+60 ;if # of patients found that match criteria is NOT LESS than the requested Max then
+61 ;set SCLIST at the 0 Node to:
+62 ;1.Current Patient Count 2. Current Patient Processing 3. Appt DTM 4. Clinic IEN
+63 IF (SCN'<SCMAXCNT)
SET @SCLIST@(0)=SCN_U_+$GET(DFN)_U_+$GET(SCDT)_U_+$GET(SCCL)
+64 QUIT ($GET(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
+65 ;
OKDATA() ;check/setup variables
+1 NEW SCOK
+2 SET SCOK=1
+3 SET SCMAXCNT=$GET(SCMAXCNT,99)
+4 ; set default dates & error array (if undefined)
DO INIT^SCAPMCU1(.SCOK)
+5 IF '$DATA(^SC(+$GET(SCCL),0))
Begin DoDot:1
+6 SET SCPARM("CLINIC")=$GET(SCCL,"Undefined")
+7 DO ERR^SCAPMCU1(.SCESEQ,4045101,.SCPARM,"",.SCERR)
End DoDot:1
SET SCOK=0
+8 ; -- is it a valid TEAM ien passed (Error # 4045101 in DIALOG file)
+9 QUIT SCOK