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