source: WorldVistAEHR/trunk/r/SCHEDULING-SD-SC/SDAMA201.m@ 623

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

initial load of WorldVistAEHR

File size: 7.0 KB
Line 
1SDAMA201 ;BPOIFO/ACS-Scheduling Replacement APIs ; 12/13/04 3:14pm
2 ;;5.3;Scheduling;**253,275,283,316,347**;13 Aug 1993
3 ;
4 ;GETAPPT - Returns appointment information for a patient
5 ;NEXTAPPT - Returns next appointment information for a patient
6 ;
7 ;** BEFORE USING THE APIS IN THIS ROUTINE, PLEASE SUBSCRIBE **
8 ;** TO DBIA #3859 **
9 ;
10 ;*****************************************************************
11 ; CHANGE LOG
12 ;
13 ; DATE PATCH DESCRIPTION
14 ;-------- ---------- -----------------------------------------
15 ;09/20/02 SD*5.3*253 ROUTINE COMPLETED
16 ;12/10/02 SD*5.3*275 ADDED PATIENT STATUS FILTER
17 ;07/03/03 SD*5.3*283 REMOVED 'NO ACTION TAKEN' EDIT
18 ;09/16/03 SD*5.3*316 CHANGED 'NEXTAPPT' TO START LOOKING 'NOW'
19 ;07/26/04 SD*5.3*347 NEW VARIABLES USED IN ^%DTC CALL.
20 ; NEXTAPPT TO GET DATA FROM SDAPI NOT VISTA.
21 ; GETAPPT WILL RETRIEVE APPT DATA THROUGH
22 ; SDAPI API. PATIENT STATUS TO OVERWRITE
23 ; APPOINTMENT STATUS OF "R" OR "R;I".
24 ; GETAPPT CALLS GETAPPT^SDAMA205.
25 ;
26 ;*****************************************************************
27GETAPPT(SDPATIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,SDRESULT,SDIOSTAT) ;
28 ;*****************************************************************
29 ;
30 ; GET APPOINTMENTS FOR PATIENT
31 ;
32 ;INPUT
33 ; SDPATIEN Patient IEN (required)
34 ; SDFIELDS Fields requested (optional)
35 ; SDAPSTAT Appointment Status Filter (optional)
36 ; SDSTART Start date/time (optional)
37 ; SDEND End date/time (optional)
38 ; SDRESULT Record count returned here (optional)
39 ; SDIOSTAT Patient Status filter (optional)
40 ;
41 ;OUTPUT
42 ; ^TMP($J,"SDAMA201","GETAPPT",X,Y)=FieldYdata
43 ; where "X" is an incremental appointment counter and
44 ; "Y" is the field number requested
45 ;
46 ;*****************************************************************
47 ; Call API to Get Appointment(s) for Patient.
48 D GETAPPT^SDAMA205(.SDPATIEN,.SDFIELDS,.SDAPSTAT,.SDSTART,.SDEND,.SDRESULT,.SDIOSTAT)
49 Q
50 ;
51NEXTAPPT(SDPATIEN,SDFIELDS,SDAPSTAT,SDIOSTAT) ;
52 ;*****************************************************************
53 ;
54 ; GET NEXT APPOINTMENT FOR PATIENT
55 ;
56 ; This API should be called with an EXTRINISIC call. It will
57 ; return "-1" if an error occurs, "1" if a future appointment
58 ; exists, or "0" if no future appointment exists. If the user
59 ; enters field numbers into the optional SDFIELDS parameter and a
60 ; next appointment is found, the requested fields for that next
61 ; appointment will be retrieved and put into:
62 ; ^TMP($J,"SDAMA201","NEXTAPPT")
63 ;
64 ;INPUT
65 ; SDPATIEN Patient IEN (required)
66 ; SDFIELDS Fields requested (optional)
67 ; SDAPSTAT Appointment status filter (optional)
68 ; SDIOSTAT Patient status filter (optional)
69 ;
70 ;OUTPUT
71 ; -1: error
72 ; 0: no future appointment
73 ; 1: future appointment exists
74 ;
75 ; If "1" is returned and the user has requested fields in the
76 ; SDFIELDS parameter, the following global is populated:
77 ; ^TMP($J,"SDAMA201","NEXTAPPT",Y)=FieldYdata
78 ; where "Y" is the field number requested
79 ;
80 ;*****************************************************************
81 N SDAPINAM,SDRTNNAM,SDSTART,SDRESULT,%,%H,%I,X
82 S SDAPINAM="NEXTAPPT",SDRTNNAM="SDAMA201",SDRESULT=0
83 K ^TMP($J,SDRTNNAM,SDAPINAM)
84 ;
85 ;Validate input parameters
86 S SDRESULT=$$VALIDATE^SDAMA200(.SDPATIEN,.SDFIELDS,.SDAPSTAT,,,SDAPINAM,SDRTNNAM,.SDIOSTAT)
87 I SDRESULT=-1 Q -1
88 ;
89 ;Get current date/time
90 D NOW^%DTC
91 S SDSTART=$E(%,1,12)
92 ;GET NEXT APPOINTMENT DATA
93 ;If an appt was found and the user wants data returned, get fields requested
94 N SDICN,SDARRAY,SDCOUNT,SDAPLST,SDI,SDTMP,SDNUM,SDERR,SDFLDCNT,SDR,SDFLD,SD310
95 N SDAPT,SDCLN,SDFFLD,SDFS
96 S SDAPLST=""
97 ;
98 S SDARRAY(1)=SDSTART ; set searchpoint to current date/time
99 ; Translate and set up Appointment Status List
100 I $L($G(SDAPSTAT))>0 D
101 . ;Remove a leading and a trailing semicolon
102 . I $E(SDAPSTAT,$L(SDAPSTAT))=";" S SDAPSTAT=$E(SDAPSTAT,1,($L(SDAPSTAT)-1))
103 . I $E(SDAPSTAT)=";" S SDAPSTAT=$E(SDAPSTAT,2,$L(SDAPSTAT))
104 . ;IO/Appt Statuses have been validated by SDAMA200 to be I or O/R NT
105 . I $L($G(SDIOSTAT))=1 S SDAPLST=$S(SDIOSTAT="I":"I;",SDIOSTAT="O":SDAPSTAT_";")
106 . I $L($G(SDIOSTAT))'=1 D
107 .. ;Reset appointment status R=R;I C=CC;CP;CCR;CPR N=NS,NSR
108 .. S SDNUM=$L(SDAPSTAT,";") F SDI=1:1:SDNUM D
109 ... S SDTMP=$P(SDAPSTAT,";",SDI)
110 ... S SDTMP=$S(SDTMP="R":"R;I",SDTMP="C":"CC;CP;CCR;CPR",SDTMP="N":"NS;NSR",1:SDTMP)
111 ... S SDAPLST=SDAPLST_SDTMP_";"
112 . S SDARRAY(3)=$E(SDAPLST,1,($L(SDAPLST)-1)) ; Axe trailing semicolon
113 S SDARRAY(4)=SDPATIEN
114 S SDARRAY("MAX")=1
115 ; Must request at least 1 field, will ask for date/time which is field 1
116 S SDFIELDS=$G(SDFIELDS),(SDFFLD,SDFIELDS)=$S(SDFIELDS'="":SDFIELDS,1:1)
117 ; Strip out field 12 if it exists, replace with 3 if 3 is not already there
118 ; If we have both 3 and 12 in the field list, remove the 12 and a semicolon
119 I (";"_SDFIELDS_";")[";12;",((";"_SDFIELDS_";")[";3;") D
120 . S SDNUM=$L(SDFFLD,";"),SDI=$F(SDFFLD,12)
121 . I SDI=3 S SDFFLD=$E(SDFFLD,4,$L(SDFFLD)) Q
122 . S SDFFLD=$E(SDFFLD,1,(SDI-4))_$E(SDFFLD,SDI,$L(SDFFLD))
123 I ((";"_SDFIELDS_";")[";12;")&((";"_SDFIELDS_";")'[";3;") S SDNUM=$L(SDFFLD,";") D
124 . F SDI=1:1:SDNUM S SDR=$P(SDFFLD,";",SDI) I SDR=12 S $P(SDFFLD,";",SDI)=3 Q
125 ;
126 S SDARRAY("FLDS")=$S(SDFFLD'="":SDFFLD,1:1)
127 F SDI=1:1 S SDTMP=$P(SDFIELDS,";",SDI) Q:SDTMP="" S SDFS(SDTMP)=SDI
128 ; Setup done, call SDAPI, quit if no appointment (SDCOUNT=0) and return 0
129 S SDCOUNT=$$SDAPI^SDAMA301(.SDARRAY) Q:SDCOUNT=0 0
130 ;If we have an appointment, process it
131 I SDCOUNT=1,SDFIELDS'="" S SDFLDCNT=$L(SDFIELDS,";") D:SDPATIEN'=""
132 . ;If malformed appointment data, set SDCOUNT to 0, quit
133 . S SDCLN=$O(^TMP($J,"SDAMA301",SDPATIEN,"")) I SDCLN="" S SDCOUNT=0 Q
134 . S SDAPT=$O(^TMP($J,"SDAMA301",SDPATIEN,SDCLN,"")) I SDAPT="" S SDCOUNT=0 Q
135 . S SD310=$G(^TMP($J,"SDAMA301",SDPATIEN,SDCLN,SDAPT)) I SD310="" S SDCOUNT=0 Q
136 . S SDTMP="" F SDI=1:1:SDFLDCNT S SDTMP=$O(SDFS(SDTMP)) Q:SDTMP="" D
137 .. I "^1^5^9^11^"[(U_SDTMP_U) S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=$P(SD310,U,SDTMP) Q
138 .. I "^2^4^8^10^"[(U_SDTMP_U) S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=$TR($P(SD310,U,SDTMP),";","^") Q
139 .. I SDTMP=7 S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=$S($P(SD310,"^",SDTMP)="":"N",1:$P(SD310,"^",SDTMP)) Q
140 .. S SDFLD="FLD"_SDTMP
141 .. I "^3^6^12^"[(U_SDTMP_U) D @(SDFLD)
142 ;If err, set up err node
143 I SDCOUNT=-1 D
144 . S SDERR=$O(^TMP($J,"SDAMA301",""))
145 . S SDERR=$S(SDERR=101:101,SDERR=115:114,SDERR=116:114,1:117)
146 . D ERROR^SDAMA200(SDERR,"NEXTAPPT",0,"SDAMA201")
147 K ^TMP($J,"SDAMA301")
148 Q SDCOUNT
149 ;Xlate output from SDAPI as required
150FLD3 S SDR=$P($P(SD310,U,SDTMP),";",1)
151 S SDR=$S(SDR="I":"R",SDR?1(1"CC",1"CP",1"CPR"):"C",SDR?1(1"NS",1"NSR"):"N",1:SDR)
152 S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=SDR Q
153FLD6 S SDR=$G(^TMP($J,"SDAMA301",SDPATIEN,SDCLN,SDAPT,"C"))
154 S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=SDR Q
155FLD12 S SDR=$P($P(SD310,U,3),";",1)
156 S SDR=$S(SDR="I":"I",SDR="R":"O",SDR="NT":"O",1:"")
157 S ^TMP($J,"SDAMA201","NEXTAPPT",SDTMP)=SDR Q
Note: See TracBrowser for help on using the repository browser.