source: WorldVistAEHR/trunk/r/SCHEDULING-SD-SC/SCAPMC28.m@ 1150

Last change on this file since 1150 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.7 KB
RevLine 
[613]1SCAPMC28 ;ALB/REW - Patients with an Appointment ; 1/10/05 2:49pm
2 ;;5.3;Scheduling;**41,140,346**;AUG 13, 1993
3 ;;1.0
4PTAP(SCCL,SCDATES,SCMAXCNT,SCLIST,SCERR,MORE) ; -- list of patients with an appointment in a given clinic
5 ;
6 ; input:
7 ; SCCL = Pointer to File #44
8 ; SCDATES("BEGIN") = begin date to search (inclusive)
9 ; [default: TODAY]
10 ; ("END") = end date to search (inclusive)
11 ; [default: TODAY]
12 ; ("INCL") = 1: only use patients who were assigned to
13 ; team for entire date range
14 ; 0: anytime in date range
15 ; [default: 1]
16 ; SCMAXCNT - Maximum # of patients to return, default=99
17 ; SCLIST -array name to store list
18 ; [ex. ^TMP("SCPT",$J)]
19 ;
20 ; SCERR = array NAME to store error messages.
21 ; [ex. ^TMP("ORXX",$J)]
22 ; MORE - This is a flag that says that this list exists and has been
23 ; aborted because it reached the maxcount. If this =1 it means
24 ; 'kill the old list & start where you finished'
25 ; Note: Don't Return DFNs where $D(^TMP("SCMC",$J,"EXCLUDE PT","SCPTA",+DFN)) is true
26 ; Output:
27 ; SCLIST() = array of patients
28 ; Format:
29 ; Subscript: Sequential # from 1 to n
30 ; Piece Description
31 ; 1 IEN of PATIENT file entry
32 ; 2 Name of patient
33 ; 3 ien to 40.7 - Not Stop Code!! stp=$$intstp
34 ; 4 AMIS reporting stop code
35 ; 5 Patient's Long ID (SSN)
36 ;
37 ; SCEFFDT - negative of effective date
38 ; SCN - current subscript (counter) 1->n
39 ; SCPTA0 is 0 node of Patient Team Assignment file 1st piece is DFN
40 ; SCERR() = Array of DIALOG file messages(errors) .
41 ; @SCERR@(0)=number of errors, undefined if none
42 ; Foramt:
43 ; Subscript: Sequential # from 1 to n
44 ; Piece Description
45 ; 1 IEN of DIALOG file
46 ;
47 ; Returned: 1 if ok, 0 if error^More?
48 ;
49 ;
50ST N SCEND,SCVSDT,SCSTART
51 N SCLSEQ,SCN,SCESEQ,SCPARM,SCP,SCBEGIN,SCEND,SCINCL,SCDTS
52 G:'$$OKDATA APQ ;check/setup variables
53 ; -- loop through visit file
54LP S SCDT=SCBEGIN
55 S:'$P(SCEND,".",2) SCEND=$$FMADD^XLFDT(SCEND,1) ;ending is end of day
56 IF $G(MORE) D
57 .S SCSTART=$P($G(@SCLIST@(0)),U,2)
58 .S SCBEGIN=$P($G(@SCLIST@(0)),U,3)
59 .K @SCLIST
60APQ Q $$PTAPX(.SCCL,.SCBEGIN,.SCEND,.SCMAXCNT,.SCLIST,.SCERR,.SCSTART)
61 ;
62PTAPX(SCCL,SCBEGIN,SCEND,MAXCNT,SCLIST,SCERR,SCSTART) ;return appointments in dt range
63 ; Input: (As above plus:)
64 ; SCSTART - Continue with list at this point
65 ; output: SCN - COUNT OF PTS
66 ; returns: dfn^ptname^clinic^apptdt^long id
67 ;
68 ;initialize variables
69 N SCDT,SCARRAY,DFN,SDAPTCNT,SDARRAY,SDERR,SDX,SDY
70 K ^TMP($J,"SDAMA301")
71 ;setup call to SDAPI
72 S SDARRAY(1)=$G(SCBEGIN)_";"_$G(SCEND),SDARRAY(2)=$G(SCCL),SDARRAY("FLDS")=4
73 S SDARRAY("SORT")="P"
74 ;call SDAPI to retrieve appointments
75 S SDAPTCNT=$$SDAPI^SDAMA301(.SDARRAY)
76 ;handle errors if any returned from SDAPI and QUIT
77 I SDAPTCNT<0 D Q ($G(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
78 .;call existing error handler
79 .D ERR^SCAPMCU1(.SCESEQ,,,"",.SCERR)
80 .K ^TMP($J,"SDAMA301")
81 ;if appointments returned
82 I SDAPTCNT>0 D
83 .;retrieve patient ID to start at if continuing list (was appt ifn)
84 .; * no code could be found to utilize continuation of a list
85 .; * if this changes this code should be revisited to ensure only 1
86 .; call to SDAPI is made.
87 .S DFN=+$G(SCSTART)
88 .S SCSTART=0
89 .S SCDT=0
90 .;resort appts to ensure same data is returned to user
91 .;only 1st appt date/time is needed for each patient
92 .;as patient can only be added to the list once.
93 .K ^TMP($J,"RE-SORT","SDAMA301")
94 .S (SDY,SDX)=0
95 .F S SDX=$O(^TMP($J,"SDAMA301",SDX)) Q:'SDX D
96 ..S SDY=$O(^TMP($J,"SDAMA301",SDX,""))
97 ..S ^TMP($J,"RE-SORT","SDAMA301",SDY,SDX)=""
98 .K ^TMP($J,"SDAMA301")
99 .;loop through re-sorted appts returned from SDAPI until
100 .; 1. no more patients with appointments exist
101 .; 2. number of patients found that match criteria is not less than max
102 .F S SCDT=$O(^TMP($J,"RE-SORT","SDAMA301",SCDT)) Q:'SCDT!(SCN'<SCMAXCNT) D
103 ..;get patient for the kept appointment in the re-sorted list
104 ..F S DFN=$O(^TMP($J,"RE-SORT","SDAMA301",SCDT,DFN)) Q:'DFN!(SCN'<SCMAXCNT) D
105 ...;quit if patient is found in either of the following lists
106 ...;this list may be used elsewhere, left in for compatibility
107 ...Q:$D(@SCLIST@("SCPTAP",+DFN))
108 ...Q:$D(^TMP("SCMC",$J,"EXCLUDE PT","SCPTA",+DFN))
109 ...;increment the patient counter and store in SCLIST
110 ...S SCN=$G(@SCLIST@(0))+1
111 ...S @SCLIST@(0)=SCN
112 ...;get the patient's long ID (SSN) and Name
113 ...D GETS^DIQ(2,+DFN,".01;.363","","SCARRAY")
114 ...;add the following appt info to SCLIST at the current Patient Counter
115 ...;1. Patient DFN 2. Patient Name 3. Clinic IEN 4. Appt DTM 5. Patients Long ID
116 ...S @SCLIST@(SCN)=DFN_U_$G(SCARRAY(2,+DFN_",",.01))_U_SCCL_U_SCDT_U_$G(SCARRAY(2,+DFN_",",.363))
117 ...;add the patient's DFN to the exclusion list
118 ...S @SCLIST@("SCPTAP",+DFN,+SCN)=""
119 ;kill the re-sorted appt global reference generated
120 K ^TMP($J,"RE-SORT","SDAMA301")
121 ;if # of patients found that match criteria is NOT LESS than the requested Max then
122 ;set SCLIST at the 0 Node to:
123 ;1.Current Patient Count 2. Current Patient Processing 3. Appt DTM 4. Clinic IEN
124 S:(SCN'<SCMAXCNT) @SCLIST@(0)=SCN_U_+$G(DFN)_U_+$G(SCDT)_U_+$G(SCCL)
125 Q ($G(@SCERR@(0))<1)_U_(SCN'<SCMAXCNT)
126 ;
127OKDATA() ;check/setup variables
128 N SCOK
129 S SCOK=1
130 S SCMAXCNT=$G(SCMAXCNT,99)
131 D INIT^SCAPMCU1(.SCOK) ; set default dates & error array (if undefined)
132 IF '$D(^SC(+$G(SCCL),0)) D S SCOK=0
133 . S SCPARM("CLINIC")=$G(SCCL,"Undefined")
134 . D ERR^SCAPMCU1(.SCESEQ,4045101,.SCPARM,"",.SCERR)
135 ; -- is it a valid TEAM ien passed (Error # 4045101 in DIALOG file)
136 Q SCOK
Note: See TracBrowser for help on using the repository browser.