source: WorldVistAEHR/trunk/r/SCHEDULING-SD-SC/SDAMA200.m@ 1582

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

initial load of WorldVistAEHR

File size: 7.4 KB
RevLine 
[613]1SDAMA200 ;BPOIFO/ACS-Scheduling Replacement API Errors and Validation ; 12/13/04 3:13pm
2 ;;5.3;Scheduling;**253,275,310,283,347**;13 Aug 1993
3 ;
4 ;*******************************************************************
5 ; CHANGE LOG
6 ;
7 ; DATE PATCH DESCRIPTION
8 ;-------- ---------- -------------------------------------
9 ;09/20/02 SD*5.3*253 ROUTINE COMPLETED
10 ;12/10/02 SD*5.3*275 ADDED PATIENT STATUS FILTER AND VALIDATION
11 ;08/15/03 SD*5.3*310 ADD ERROR 114
12 ;08/19/03 SD*5.3*283 ADDED 'NT' APPT STATUS MULTIPLE APPT STATUS
13 ; VALUES ALLOWED, NULL FIELD LIST ALLOWED.
14 ; REMOVED ERROR CODE 107.
15 ;07/26/04 SD*5.3*347 NEW VARIABLES USED IN ^%DTC CALL.
16 ; ALLOW FOR APPOINTMENT STATUSES R,NT OR
17 ; R AND NT TO BE PASSED IF THE PATIENT STATUS
18 ; IS SET TO O.
19 ;
20 ;*******************************************************************
21 ;-------------------------------------------------------------------
22 ; *** VALIDATE INPUT PARAMETERS ***
23 ;INPUT
24 ; SDIEN Patient, clinic, or facility IEN (required)
25 ; SDFIELDS Fields requested (optional)
26 ; SDAPSTAT Appointment status (optional)
27 ; SDSTART Start date (optional)
28 ; SDEND End date (optional)
29 ; SDAPINAM The API that is calling this routine (required)
30 ; SDRTNNAM The routine that is calling this routine (required)
31 ; SDIOSTAT Patient status filter
32 ;-------------------------------------------------------------------
33 ;
34VALIDATE(SDIEN,SDFIELDS,SDAPSTAT,SDSTART,SDEND,SDAPINAM,SDRTNNAM,SDIOSTAT) ;
35 ;
36 N SDERRFLG
37 S SDERRFLG=0
38 ;Validate IEN
39 I $G(SDIEN)="" D ERROR($S(SDAPINAM="GETPLIST":104,1:102),SDAPINAM,.SDERRFLG,SDRTNNAM)
40 I $G(SDIEN)'="",+$G(SDIEN)'=$G(SDIEN) D ERROR(110,SDAPINAM,.SDERRFLG,SDRTNNAM)
41 ;
42 ;Validate Appointment Status Filter
43 I $L($G(SDAPSTAT))>0 D
44 . ;validate each status, build new status list if necessary
45 . N SDNUM,SDPIECE,SDQUIT,SDAPVAL,SDNEWAP
46 . S SDQUIT=0
47 . ;get count of values passed in
48 . S SDNUM=$L(SDAPSTAT,";")
49 . S SDNEWAP=";"
50 . ;check each value passed in
51 . F SDPIECE=1:1:SDNUM S SDAPVAL=$P(SDAPSTAT,";",SDPIECE) D Q:SDQUIT=1
52 .. I $G(SDAPVAL)="" D ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDQUIT=1 Q
53 .. I ";R;C;N;NT;"'[(";"_SDAPVAL_";") D ERROR(109,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDQUIT=1 Q
54 .. ;build status string
55 .. S SDNEWAP=SDNEWAP_SDAPVAL_";"
56 .S SDAPSTAT=SDNEWAP
57 ;set appointment status filter to 'all' if null or undefined
58 I $G(SDAPSTAT)="" S SDAPSTAT=";R;C;N;NT;"
59 ;
60 ;Validate start and end date/time variables if they are passed in
61 N SDSTVAL,SDENDVAL,%H,%T,%Y,X
62 S (SDSTVAL,SDENDVAL)=0
63 I $G(SDSTART)'="" D
64 . I +SDSTART'=SDSTART D ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
65 . S X=SDSTART D H^%DTC I %H=0 D ERROR(105,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
66 . S SDSTVAL=1
67 I $G(SDEND)'="" D
68 . I +SDEND'=SDEND D ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
69 . S X=SDEND D H^%DTC I %H=0 D ERROR(106,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
70 . S SDENDVAL=1
71 ;If start and end dates are valid, make sure start date not > end date
72 I SDSTVAL,SDENDVAL D
73 . I SDSTART>SDEND D ERROR(111,SDAPINAM,.SDERRFLG,SDRTNNAM)
74 ;
75 ;Remove beginning and ending semi-colons from SDFIELDS list if present
76 I $L($G(SDFIELDS))>0 D
77 . I $E($G(SDFIELDS),1,1)=";" D
78 .. S SDFIELDS=$E(SDFIELDS,2,$L(SDFIELDS))
79 .. I $G(SDFIELDS)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
80 .I $L($G(SDFIELDS))>0 D
81 .. I $E($G(SDFIELDS),$L($G(SDFIELDS)),$L($G(SDFIELDS)))=";" D
82 ... S SDFIELDS=$E(SDFIELDS,1,$L(SDFIELDS)-1)
83 ... I $G(SDFIELDS)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM)
84 ;
85 ;Validate SDFIELDS list
86 N SDI,SDFIELD,SDNUM,SDEND
87 S (SDI,SDFIELD,SDNUM,SDEND)=0
88 ;Check field list for valid numbers requested
89 I $G(SDFIELDS)]"" D
90 . ;get number of pieces
91 . S SDNUM=$L(SDFIELDS,";")
92 . ;validate each piece
93 . F SDI=1:1:SDNUM S SDFIELD=$P(SDFIELDS,";",SDI) D Q:SDEND
94 .. I $G(SDFIELD)="" D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDEND=1 Q
95 .. I '$D(^SDAM(44.3,SDFIELD)) D ERROR(103,SDAPINAM,.SDERRFLG,SDRTNNAM) S SDEND=1 Q
96 ;If field list is null and API is not NEXTAPPT, set up to include all
97 I ($G(SDFIELDS)="")&(SDAPINAM'="NEXTAPPT") S SDI=0 D
98 . F S SDI=$O(^SDAM(44.3,SDI)) Q:+$G(SDI)=0 D
99 .. S SDFIELDS=$G(SDFIELDS)_SDI_";"
100 . ;remove ending semi-colon
101 . S SDFIELDS=$E(SDFIELDS,1,$L(SDFIELDS)-1)
102 ;
103 ;Validate Patient Status Filter
104 I $L($G(SDIOSTAT))>0 D
105 . I $L(SDIOSTAT)>1 D ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
106 . I "IO"'[SDIOSTAT D ERROR(112,SDAPINAM,.SDERRFLG,SDRTNNAM) Q
107 ;set patient status filter to 'both' if null or undefined
108 I $G(SDIOSTAT)="" S SDIOSTAT="IO"
109 ;
110 ;Validate Appt Status and Patient Status Filter Combination
111 ;if they specify a patient status, they must specify scheduled/kept appt type "R"
112 I $G(SDIOSTAT)="I",$G(SDAPSTAT)'=";R;" D ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
113 I $G(SDIOSTAT)="O",$S($G(SDAPSTAT)=";R;":0,$G(SDAPSTAT)=";NT;":0,$G(SDAPSTAT)=";R;NT;":0,$G(SDAPSTAT)=";NT;R;":0,1:1) D ERROR(113,SDAPINAM,.SDERRFLG,SDRTNNAM)
114 ;
115 I SDERRFLG>0 Q -1
116 Q 1
117 ;
118ERROR(SDERRNUM,SDAPINAM,SDERRFLG,SDRTNNAM) ;
119 ;Put error message in ^TMP global
120 S SDERRFLG=1
121 S $P(^TMP($J,SDRTNNAM,SDAPINAM,"ERROR",SDERRNUM),"^",1)=$P($T(@SDERRNUM),";;",2)
122 Q
123 ;
124 ;***************************************************************
125 ; ERROR CODES AND MESSAGES USED FOR PARAMETER VALIDATION
126 ;***************************************************************
127 ;
128101 ;;DATABASE IS UNAVAILABLE
129102 ;;PATIENT ID IS REQUIRED
130103 ;;INVALID FIELD LIST
131104 ;;CLINIC ID IS REQUIRED
132105 ;;INVALID START DATE
133106 ;;INVALID END DATE
134108 ;;FACILITY ID IS REQUIRED
135109 ;;INVALID APPOINTMENT STATUS FILTER
136110 ;;ID MUST BE NUMERIC
137111 ;;START DATE CAN'T BE AFTER END DATE
138112 ;;INVALID PATIENT STATUS FILTER
139113 ;;APPT STATUS AND PATIENT STATUS FILTER COMBINATION UNSUPPORTED IN VISTA
140114 ;;INVALID PATIENT ID
141116 ;;DATA MISMATCH
142117 ;;SDAPI ERROR
143 ;
144 ;------------------------------------------------------------------
145 ;Additional APIs called from GETAPPT, GETPLIST, NEXTAPPT, GETALLCL
146 ;------------------------------------------------------------------
147 ;
148PATAPPT(SDPATIEN) ;For a patient IEN, return Boolean value for existence of appointments on ^DPT
149 I $D(^DPT(SDPATIEN,"S")) Q 1
150 Q 0
151 ;
152CLNAPPT(SDCLIEN) ;For a clinic IEN, return Boolean value for existence of appointments on ^SC
153 I $D(^SC($G(SDCLIEN),"S")) Q 1
154 Q 0
155GETCLIEN(SDPATIEN,SDAPPTDT) ; For a patient and appt date, return the clinic IEN on ^DPT
156 Q $P($G(^DPT($G(SDPATIEN),"S",$G(SDAPPTDT),0)),"^",1)
157 ;
158GETPTIEN(SDCLIEN,SDAPPTDT,SDPATCNT) ; For a clinic, appt date, and node, return the patient IEN on ^SC
159 Q $P($G(^SC($G(SDCLIEN),"S",$G(SDAPPTDT),1,$G(SDPATCNT),0)),"^",1)
160 ;
161GETSDDA(SDCLIEN,SDAPPTDT,SDPATIEN) ; For a clinic, appt date, and patient, return the SDDA node number on ^SC
162 N SDPATCNT,SDMATCH
163 S SDPATCNT=0,SDMATCH=0
164 F S SDPATCNT=$O(^SC($G(SDCLIEN),"S",$G(SDAPPTDT),1,SDPATCNT)) D Q:('SDPATCNT!SDMATCH)
165 . I 'SDPATCNT Q
166 . I $P($G(^SC(SDCLIEN,"S",SDAPPTDT,1,SDPATCNT,0)),"^",1)=SDPATIEN S SDMATCH=1
167 Q $G(SDPATCNT)
168 ;
169GETASTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Appointment Status (N, C, R, or NT)
170 N SDSTAT
171 S SDSTAT=$P($G(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
172 S SDSTAT=$S($G(SDSTAT)="NT":"NT",$G(SDSTAT)="I":"R",$G(SDSTAT)["N":"N",$G(SDSTAT)["C":"C",1:"R")
173 Q SDSTAT
174 ;
175GETPSTAT(SDPATIEN,SDAPPTDT) ;For a patient and appt date, return Patient Status (I or O)
176 N SDSTAT
177 S SDSTAT=$P($G(^DPT(SDPATIEN,"S",SDAPPTDT,0)),"^",2)
178 S SDSTAT=$S($G(SDSTAT)="I":"I",1:"O")
179 Q SDSTAT
180 ;
Note: See TracBrowser for help on using the repository browser.