SDAMA205 ;BPOIFO/ACS-Scheduling Replacement APIs ; 12/13/04 3:17pm
;;5.3;Scheduling;**347,1015**;13 Aug 1993;Build 21
;
;*****************************************************************
; CHANGE LOG
;
; DATE PATCH DESCRIPTION
;-------- ---------- -----------------------------------------
;07/21/04 SD*5.3*347 CALLED FROM GETAPPT^SDAMA201.
;
;*****************************************************************
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
;
;*****************************************************************
N SDAPDT,SDAPINAM,SDARRAY,SDRTNNAM,SDAPNUM,SDCNVRT,SDDATA,SDX,SDY,SDZ
S SDAPINAM="GETAPPT",SDRTNNAM="SDAMA201",SDRESULT=0
K ^TMP($J,SDRTNNAM,SDAPINAM)
S SDRESULT=$$VALIDATE^SDAMA200(.SDPATIEN,.SDFIELDS,.SDAPSTAT,.SDSTART,.SDEND,SDAPINAM,SDRTNNAM,.SDIOSTAT)
I SDRESULT=-1 Q
;
;CONVERT INPUT VALUES TO SDAPI FILTER VALUES
S SDARRAY("SORT")="P"
S SDARRAY(4)=SDPATIEN
I $G(SDSTART)>0!($G(SDEND)>0) S SDARRAY(1)=$G(SDSTART)_";"_$G(SDEND)
;convert Field List
S SDARRAY("FLDS")=""
F SDX=1:1 S SDY=$P(SDFIELDS,";",SDX) Q:SDY="" D
.I SDY=12,SDFIELDS[3 Q ; Patient Status not needed if Appt. Stat. exists.
.I SDY=12 S SDY=3 ; Patient Status and Appointment Status are the same here.
.S SDARRAY("FLDS")=SDARRAY("FLDS")_SDY_";"
I '$L(SDFIELDS) S SDARRAY("FLDS")="1;2;3;4;5;6;7;8;9;10;11"
;convert Appt. List
S SDZ=""
;IO Status has been validated by SDAMA200 to be I or O
I $L($G(SDIOSTAT))=1 S SDZ=$S(SDIOSTAT="I":"I;",SDIOSTAT="O":SDAPSTAT_";")
I $L($G(SDIOSTAT))'=1,$L($G(SDAPSTAT)) D
.F SDX=1:1:$L(SDAPSTAT,";") S SDY=$P(SDAPSTAT,";",SDX) D
..S SDZ=SDZ_$S(SDY="R":"R;I;",SDY="N":"NS;NSR;",SDY="C":"CC;CP;CCR;CPR;",1:SDY_";")
E S SDZ="R;I;CC;CP;CCR;CPR;NS;NSR;NT;"
I $L(SDZ) S SDARRAY(3)=$E(SDZ,1,$L(SDZ)-1)
;
;CALL SDAPI TO RETRIEVE APPOINTMENT INFO
S SDRESULT=$$SDAPI^SDAMA301(.SDARRAY)
I SDRESULT=0 Q ; No Appointment info returned.
;
I SDRESULT=-1 D Q ; Error(s) Encountered.
.S SDX=$O(^TMP($J,"SDAMA301",""))
.S SDX=$S(SDX=101:101,SDX=115:114,SDX=116:114,1:117)
.D ERROR^SDAMA200(SDX,"GETAPPT",0,"SDAMA201")
.K ^TMP($J,"SDAMA301")
;
; Convert Appt. Info Returned from SDAPI to GETAPPT Format.
F SDX=1,5,7,9,11,12 S SDCNVRT(SDX)=""
F SDX=2,4,8,10 S SDCNVRT(SDX)="S SDDATA=$TR(SDDATA,"";"",""^"")"
S SDCNVRT(3)="S SDDATA=$P(SDDATA,"";""),SDDATA=$S(SDDATA=""R"":SDDATA,SDDATA=""I"":""R"",$E(SDDATA,1)=""C"":""C"",$E(SDDATA,1,2)=""NS"":""N"",1:""NT"")"
S SDCNVRT(6)="S SDDATA=$G(^TMP($J,""SDAMA301"",SDPATIEN,SDAPDT,""C""))"
;
S SDAPNUM=0,SDAPDT=""
;Loop through returned appointments from SDAPI
F S SDAPDT=$O(^TMP($J,"SDAMA301",SDPATIEN,SDAPDT)) Q:SDAPDT="" S SDX=^(SDAPDT) D
.S SDAPNUM=SDAPNUM+1
.;Loop through requested fields
.F SDY=1:1 S SDZ=$P($G(SDFIELDS),";",SDY) Q:SDZ="" D
..;Retrieve data for requested field
..S SDDATA=$P(SDX,"^",SDZ)
..;Convert Overbook to N if null value returned from SDAPI
..I SDZ=7,SDDATA="" S SDDATA="N"
..X SDCNVRT(SDZ) S ^TMP($J,"SDAMA201","GETAPPT",SDAPNUM,SDZ)=SDDATA
.;Set Patient Status Value in output based on Appt Status
.I $P($P(SDX,U,3),";")="I" S ^TMP($J,"SDAMA201","GETAPPT",SDAPNUM,12)="I"
.I $S($P($P(SDX,U,3),";")="R":1,$P($P(SDX,U,3),";")="NT":1,1:0) S ^TMP($J,"SDAMA201","GETAPPT",SDAPNUM,12)="O"
K ^TMP($J,"SDAMA301")
Q
;
SDAMA205 ;BPOIFO/ACS-Scheduling Replacement APIs ; 12/13/04 3:17pm
+1 ;;5.3;Scheduling;**347,1015**;13 Aug 1993;Build 21
+2 ;
+3 ;*****************************************************************
+4 ; CHANGE LOG
+5 ;
+6 ; DATE PATCH DESCRIPTION
+7 ;-------- ---------- -----------------------------------------
+8 ;07/21/04 SD*5.3*347 CALLED FROM GETAPPT^SDAMA201.
+9 ;
+10 ;*****************************************************************
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 NEW SDAPDT,SDAPINAM,SDARRAY,SDRTNNAM,SDAPNUM,SDCNVRT,SDDATA,SDX,SDY,SDZ
+21 SET SDAPINAM="GETAPPT"
SET SDRTNNAM="SDAMA201"
SET SDRESULT=0
+22 KILL ^TMP($JOB,SDRTNNAM,SDAPINAM)
+23 SET SDRESULT=$$VALIDATE^SDAMA200(.SDPATIEN,.SDFIELDS,.SDAPSTAT,.SDSTART,.SDEND,SDAPINAM,SDRTNNAM,.SDIOSTAT)
+24 IF SDRESULT=-1
QUIT
+25 ;
+26 ;CONVERT INPUT VALUES TO SDAPI FILTER VALUES
+27 SET SDARRAY("SORT")="P"
+28 SET SDARRAY(4)=SDPATIEN
+29 IF $GET(SDSTART)>0!($GET(SDEND)>0)
SET SDARRAY(1)=$GET(SDSTART)_";"_$GET(SDEND)
+30 ;convert Field List
+31 SET SDARRAY("FLDS")=""
+32 FOR SDX=1:1
SET SDY=$PIECE(SDFIELDS,";",SDX)
IF SDY=""
QUIT
Begin DoDot:1
+33 ; Patient Status not needed if Appt. Stat. exists.
IF SDY=12
IF SDFIELDS[3
QUIT
+34 ; Patient Status and Appointment Status are the same here.
IF SDY=12
SET SDY=3
+35 SET SDARRAY("FLDS")=SDARRAY("FLDS")_SDY_";"
End DoDot:1
+36 IF '$LENGTH(SDFIELDS)
SET SDARRAY("FLDS")="1;2;3;4;5;6;7;8;9;10;11"
+37 ;convert Appt. List
+38 SET SDZ=""
+39 ;IO Status has been validated by SDAMA200 to be I or O
+40 IF $LENGTH($GET(SDIOSTAT))=1
SET SDZ=$SELECT(SDIOSTAT="I":"I;",SDIOSTAT="O":SDAPSTAT_";")
+41 IF $LENGTH($GET(SDIOSTAT))'=1
IF $LENGTH($GET(SDAPSTAT))
Begin DoDot:1
+42 FOR SDX=1:1:$LENGTH(SDAPSTAT,";")
SET SDY=$PIECE(SDAPSTAT,";",SDX)
Begin DoDot:2
+43 SET SDZ=SDZ_$SELECT(SDY="R":"R;I;",SDY="N":"NS;NSR;",SDY="C":"CC;CP;CCR;CPR;",1:SDY_";")
End DoDot:2
End DoDot:1
+44 IF '$TEST
SET SDZ="R;I;CC;CP;CCR;CPR;NS;NSR;NT;"
+45 IF $LENGTH(SDZ)
SET SDARRAY(3)=$EXTRACT(SDZ,1,$LENGTH(SDZ)-1)
+46 ;
+47 ;CALL SDAPI TO RETRIEVE APPOINTMENT INFO
+48 SET SDRESULT=$$SDAPI^SDAMA301(.SDARRAY)
+49 ; No Appointment info returned.
IF SDRESULT=0
QUIT
+50 ;
+51 ; Error(s) Encountered.
IF SDRESULT=-1
Begin DoDot:1
+52 SET SDX=$ORDER(^TMP($JOB,"SDAMA301",""))
+53 SET SDX=$SELECT(SDX=101:101,SDX=115:114,SDX=116:114,1:117)
+54 DO ERROR^SDAMA200(SDX,"GETAPPT",0,"SDAMA201")
+55 KILL ^TMP($JOB,"SDAMA301")
End DoDot:1
QUIT
+56 ;
+57 ; Convert Appt. Info Returned from SDAPI to GETAPPT Format.
+58 FOR SDX=1,5,7,9,11,12
SET SDCNVRT(SDX)=""
+59 FOR SDX=2,4,8,10
SET SDCNVRT(SDX)="S SDDATA=$TR(SDDATA,"";"",""^"")"
+60 SET SDCNVRT(3)="S SDDATA=$P(SDDATA,"";""),SDDATA=$S(SDDATA=""R"":SDDATA,SDDATA=""I"":""R"",$E(SDDATA,1)=""C"":""C"",$E(SDDATA,1,2)=""NS"":""N"",1:""NT"")"
+61 SET SDCNVRT(6)="S SDDATA=$G(^TMP($J,""SDAMA301"",SDPATIEN,SDAPDT,""C""))"
+62 ;
+63 SET SDAPNUM=0
SET SDAPDT=""
+64 ;Loop through returned appointments from SDAPI
+65 FOR
SET SDAPDT=$ORDER(^TMP($JOB,"SDAMA301",SDPATIEN,SDAPDT))
IF SDAPDT=""
QUIT
SET SDX=^(SDAPDT)
Begin DoDot:1
+66 SET SDAPNUM=SDAPNUM+1
+67 ;Loop through requested fields
+68 FOR SDY=1:1
SET SDZ=$PIECE($GET(SDFIELDS),";",SDY)
IF SDZ=""
QUIT
Begin DoDot:2
+69 ;Retrieve data for requested field
+70 SET SDDATA=$PIECE(SDX,"^",SDZ)
+71 ;Convert Overbook to N if null value returned from SDAPI
+72 IF SDZ=7
IF SDDATA=""
SET SDDATA="N"
+73 XECUTE SDCNVRT(SDZ)
SET ^TMP($JOB,"SDAMA201","GETAPPT",SDAPNUM,SDZ)=SDDATA
End DoDot:2
+74 ;Set Patient Status Value in output based on Appt Status
+75 IF $PIECE($PIECE(SDX,U,3),";")="I"
SET ^TMP($JOB,"SDAMA201","GETAPPT",SDAPNUM,12)="I"
+76 IF $SELECT($PIECE($PIECE(SDX,U,3),";")="R":1,$PIECE($PIECE(SDX,U,3),";")="NT":1,1:0)
SET ^TMP($JOB,"SDAMA201","GETAPPT",SDAPNUM,12)="O"
End DoDot:1
+77 KILL ^TMP($JOB,"SDAMA301")
+78 QUIT
+79 ;