SDES2CANCLNAVAIL ;ALB/BLB,BLB,TJB,BLB,JAS - SDES2 CANCEL CLINIC AVAILABILITY ; JULY 1, 2024
;;5.3;Scheduling;**869,873,875,880,886**;Aug 13, 1993;Build 13
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
CANCEL(JSON,SDCONTEXT,CANCEL) ;
N ERRORS,RETURN
;
D VALIDATE(.ERRORS,.SDCONTEXT,.CANCEL,$G(CANCEL("CLINIC IEN")),$G(CANCEL("FULL PARTIAL FLAG")),$G(CANCEL("REMARKS")))
I $D(ERRORS) S ERRORS("CancelClinicAvailability",1)="" D BUILDJSON^SDES2JSON(.JSON,.ERRORS) Q
;
D CANCELAVAIL(CANCEL("CLINIC IEN"),CANCEL("START DATE TIME"),CANCEL("END DATE TIME"),CANCEL("FULL PARTIAL FLAG"),$G(CANCEL("REMARKS")))
D CANCELAPPTS(CANCEL("CLINIC IEN"),CANCEL("START DATE TIME"),CANCEL("END DATE TIME"),CANCEL("FULL PARTIAL FLAG"),$G(CANCEL("REMARKS")),.SDCONTEXT,.RETURN)
;
S RETURN("CancelClinicAvailability",1)="Clinic availability has been successfully cancelled."
D BUILDJSON^SDES2JSON(.JSON,.RETURN)
Q
;
CANCELAVAIL(CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG,CANCELREMARKS) ;
N PARTIALCANCELIEN,PARTIALCANCELFDA,CANCELDATE,DATE,ADDAPPTNODEFDA,CANCELMESSAGEFDA,NEWAPPTDATE,NEWSCHEDULEFDA,DATEINC
N HRCLNDISPBEG,STARTOFDAY,INCREMENT,CANENDTIME,CANSTARTTIME,ST,SDXX,BLOCKLEN,CANDTTMEND,DH,DISPINCPERHR,I5,P,PARTIALCANAVAIL,X,Y
;
S HRCLNDISPBEG=$$GET1^DIQ(44,CLINICIEN,1914,"I")
I HRCLNDISPBEG="" S HRCLNDISPBEG=8
S STARTOFDAY=$S($L(HRCLNDISPBEG):HRCLNDISPBEG,1:8)
S DISPINCPERHR=$$GET1^DIQ(44,CLINICIEN,1917,"I")
S INCREMENT=$S(DISPINCPERHR="":4,DISPINCPERHR<3:4,DISPINCPERHR:DISPINCPERHR,1:4)
S CANENDTIME=$$TC($P(ENDDATETIME,".",2),$P(STARTDATETIME,"."),STARTOFDAY,INCREMENT)
S CANSTARTTIME=$$TC($P(STARTDATETIME,".",2),$P(STARTDATETIME,"."),STARTOFDAY,INCREMENT)
S ST=$P(CANSTARTTIME,U,3)
S CANDTTMEND=$P(CANENDTIME,U,2)
S SDXX=$P(CANENDTIME,U,3)
;
I FLAG="P" D
.S CANCELDATE=$P(STARTDATETIME,".")
.S PARTIALCANCELFDA(44.05,"+1,"_CLINICIEN_",",.01)=STARTDATETIME
.S PARTIALCANCELFDA(44.05,"+1,"_CLINICIEN_",",1)=$P(CANENDTIME,"^")
.S PARTIALCANCELIEN(1)=STARTDATETIME
.D UPDATE^DIE(,"PARTIALCANCELFDA","PARTIALCANCELIEN") K PARTIALCANCELFDA
.
.I $D(^SC(CLINICIEN,"S",STARTDATETIME,0)) D
..S ADDAPPTNODEFDA(44.001,STARTDATETIME_","_CLINICIEN_",",.01)=STARTDATETIME
..S ADDAPPTNODEFDA(44.001,STARTDATETIME_","_CLINICIEN_",",1400)="CANCELLED UNTIL "_ENDDATETIME_$S(CANCELREMARKS?.P:"",1:" ("_CANCELREMARKS_")")
..D FILE^DIE(,"ADDAPPTNODEFDA") K ADDAPPTNODEFDA
.;
.I '$D(^SC(CLINICIEN,"S",STARTDATETIME,0)) D
..S CANCELMESSAGEFDA(44.001,"+1,"_CLINICIEN_",",.01)=STARTDATETIME
..S CANCELMESSAGEFDA(44.001,"+1,"_CLINICIEN_",",1400)="CANCELLED UNTIL "_ENDDATETIME_$S(CANCELREMARKS?.P:"",1:" ("_CANCELREMARKS_")")
..S NEWAPPTDATE(1)=STARTDATETIME
..D UPDATE^DIE(,"CANCELMESSAGEFDA","NEWAPPTDATE") K CANCELMESSAGEFDA
.;
.S PARTIALCANAVAIL=$$GET1^DIQ(44.005,$P(STARTDATETIME,".")_","_CLINICIEN_",",1,"E")
.S PARTIALCANAVAIL=PARTIALCANAVAIL_$J("",SDXX-$L(PARTIALCANAVAIL))
.S Y=""
.S BLOCKLEN=CANDTTMEND-STARTDATETIME
.I $G(BLOCKLEN)<100,$L(PARTIALCANAVAIL)<77 S PARTIALCANAVAIL=PARTIALCANAVAIL_" " ; pad 4 empty spaces needed for blocks < 60 minutes
.F X=0:2:SDXX D
..S DH=$E(PARTIALCANAVAIL,X+INCREMENT+INCREMENT)
..S P=$S(X<ST:DH_$E(PARTIALCANAVAIL,X+1+INCREMENT+INCREMENT),X=SDXX:$S(Y="[":Y,1:DH)_$E(PARTIALCANAVAIL,X+1+INCREMENT+INCREMENT),1:$S(Y="["&(X=ST):"]",1:"X")_"X")
..S Y=$S(DH="]":"",DH="[":DH,1:Y)
..S PARTIALCANAVAIL=$E(PARTIALCANAVAIL,1,X-1+INCREMENT+INCREMENT)_P_$E(PARTIALCANAVAIL,X+2+INCREMENT+INCREMENT,999)
.S:'$F(PARTIALCANAVAIL,"[") I5=$F(PARTIALCANAVAIL,"X"),PARTIALCANAVAIL=$E(PARTIALCANAVAIL,1,(I5-2))_"["_$E(PARTIALCANAVAIL,I5,999)
;
;
F DATEINC=0:1 S DATE=$$FMADD^XLFDT($P(STARTDATETIME,"."),DATEINC) Q:'DATE!(DATE>$P(ENDDATETIME,".")) D
.S ^SC(CLINICIEN,"ST",$P(DATE,"."),"CAN")=$G(^SC(CLINICIEN,"ST",$P(DATE,"."),1))
.S NEWSCHEDULEFDA(44.005,DATE_","_CLINICIEN_",",1)=$S(FLAG="P":PARTIALCANAVAIL,1:" "_$E($P(DATE,"."),6,7)_" **CANCELLED**")
.D FILE^DIE(,"NEWSCHEDULEFDA") K NEWSCHEDULEFDA
Q
;
CANCELAPPTS(CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG,CANCELREMARKS,SDCONTEXT,RETURN) ;
N CANCELAPPT,DATETIME,JSONCANCELRETURN,CANCELLED,RESOURCEIEN,APPTIEN,COUNT
;
I ENDDATETIME'["." S ENDDATETIME=ENDDATETIME_.2359
S RESOURCEIEN=$$GETRESOURCE(CLINICIEN)
S COUNT=0
S DATETIME=STARTDATETIME-.0001
F S DATETIME=$O(^SC(CLINICIEN,"S",DATETIME)) Q:'DATETIME!(DATETIME>=ENDDATETIME) D
.S APPTIEN=0
.F S APPTIEN=$O(^SDEC(409.84,"ARSRC",RESOURCEIEN,DATETIME,APPTIEN)) Q:'APPTIEN D
..I $$GET1^DIQ(409.84,APPTIEN,.12,"I") Q
..;
..S COUNT=COUNT+1
..S CANCELAPPT("APPT IEN")=APPTIEN
..S CANCELAPPT("DFN")=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
..S CANCELAPPT("CLINIC IEN")=CLINICIEN
..S CANCELAPPT("CANCEL REASON")="CLINIC CANCELLED"
..S CANCELAPPT("CANCELLED BY")="C"
..D CANCELAPPT^SDES2CANCELAPPT(.JSONCANCELRETURN,.SDCONTEXT,.CANCELAPPT)
..D DECODE^XLFJSON("JSONCANCELRETURN","CANCELLED")
..S RETURN("CancelledAppointment",COUNT,"AppointmentID")=$G(CANCELLED("Appointment","Cancelled")) K CANCELLED
..;
..I FLAG="P" D
...D EN^SDTMPHLC(CLINICIEN,STARTDATETIME,ENDDATETIME,"P",CANCELREMARKS)
..I FLAG="F" D
...D EN^SDTMPHLC(CLINICIEN,$P(STARTDATETIME,"."),,"C","**CANCELLED**")
Q
;
VALIDATE(ERRORS,SDCONTEXT,CANCEL,CLINICIEN,FLAG,REMARKS) ;
N VAL
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
D VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,CLINICIEN,1,,18,19)
;
S CANCEL("START DATE TIME")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(CANCEL("START DATE TIME")),CLINICIEN,1,9,11)
S CANCEL("END DATE TIME")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(CANCEL("END DATE TIME")),CLINICIEN,1,10,12)
I $G(CANCEL("START DATE TIME"))>$G(CANCEL("END DATE TIME")) D ERRLOG^SDESJSON(.ERRORS,13)
;
D VALIDATEFLAG(.ERRORS,FLAG,$G(CANCEL("START DATE TIME")),$G(CANCEL("END DATE TIME")))
I $L(REMARKS),$L(REMARKS)<3!($L(REMARKS)>160) D ERRLOG^SDESJSON(.ERRORS,255)
I $D(ERRORS) Q
;
D VALCLINICDETAILS(.ERRORS,CLINICIEN,$G(CANCEL("START DATE TIME")),$G(CANCEL("END DATE TIME")),FLAG) ;
Q
;
VALCLINICDETAILS(ERRORS,CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG) ;
N SCHEDULEDATE,CANCELDATETIME,CANCELSTART,CANCELEND,SUBIEN,APPTDATETIME,DATEINC
;
I FLAG="P",$P(STARTDATETIME,".")'=$P(ENDDATETIME,".") D ERRLOG^SDESJSON(.ERRORS,576) Q
F DATEINC=0:1 S SCHEDULEDATE=$$FMADD^XLFDT($P(STARTDATETIME,"."),DATEINC) Q:'SCHEDULEDATE!(SCHEDULEDATE>$P(ENDDATETIME,"."))!($D(ERRORS)) D
.I $$INACTIVE^SDESUTIL(CLINICIEN,SCHEDULEDATE) D ERRLOG^SDESJSON(.ERRORS,525) Q
.I $$GET1^DIQ(44.005,SCHEDULEDATE_","_CLINICIEN_",",1,"I")["CANCELLED" D ERRLOG^SDESJSON(.ERRORS,248) Q
.I $$GET1^DIQ(44.005,SCHEDULEDATE_","_CLINICIEN_",",1,"I")'["[" D ERRLOG^SDESJSON(.ERRORS,249) Q
.I FLAG="F",$D(^SC(CLINICIEN,"ST",SCHEDULEDATE,"CAN")) D ERRLOG^SDESJSON(.ERRORS,250) Q
.;
.S APPTDATETIME=STARTDATETIME-.0001
.F S APPTDATETIME=$O(^SC(CLINICIEN,"S",APPTDATETIME)) Q:'APPTDATETIME!(APPTDATETIME>=ENDDATETIME)!($D(ERRORS)) D
..S SUBIEN=0
..F S SUBIEN=$O(^SC(CLINICIEN,"S",APPTDATETIME,1,SUBIEN)) Q:'SUBIEN!($D(ERRORS)) D
...I $$GET1^DIQ(44.003,SUBIEN_","_APPTDATETIME_","_CLINICIEN_",",310)="CANCELLED" Q
...I $$GET1^DIQ(44.003,SUBIEN_","_APPTDATETIME_","_CLINICIEN_",",303,"I") D ERRLOG^SDESJSON(.ERRORS,247)
.;
.I FLAG="P",$D(^SC(CLINICIEN,"ST",$P(SCHEDULEDATE,"."),"CAN")) D
..S CANCELDATETIME=$P(STARTDATETIME,".")
..F S CANCELDATETIME=$O(^SC(CLINICIEN,"SDCAN",CANCELDATETIME)) Q:'CANCELDATETIME!($P(CANCELDATETIME,".")>$P(STARTDATETIME,"."))!($D(ERRORS)) D
...S CANCELSTART=$$GET1^DIQ(44.05,CANCELDATETIME_","_CLINICIEN_",",.01,"I")
...S CANCELEND=$P(CANCELSTART,".")_"."_$P($$GET1^DIQ(44.05,CANCELDATETIME_","_CLINICIEN_",",1,"I"),".",1)*1
...I STARTDATETIME>=CANCELEND!(ENDDATETIME<=CANCELSTART)!(CANCELSTART>=ENDDATETIME)!(CANCELEND<=STARTDATETIME) Q
...D ERRLOG^SDESJSON(.ERRORS,250)
Q
;
VALIDATEFLAG(ERRORS,FLAG,STARTDATETIME,ENDDATETIME) ;
I '$L($G(FLAG)) D ERRLOG^SDESJSON(.ERRORS,245) Q
I $G(FLAG)'="F",$G(FLAG)'="P" D ERRLOG^SDESJSON(.ERRORS,246)
;
I $G(FLAG)="F" D
.I STARTDATETIME["."!(ENDDATETIME[".") D ERRLOG^SDESJSON(.ERRORS,552) Q
I $G(FLAG)="P" D
.I STARTDATETIME'["."!(ENDDATETIME'[".") D ERRLOG^SDESJSON(.ERRORS,551)
Q
;
GETRESOURCE(CLINICIEN) ;
S RESOURCEIEN=0
F S RESOURCEIEN=$O(^SDEC(409.831,"ALOC",CLINICIEN,RESOURCEIEN)) Q:'RESOURCEIEN!(RESOURCEIEN) D
.I $$GET1^DIQ(409.831,RESOURCEIEN,.012,"E")="CLINIC" D
.S RESOURCEIEN=$O(^SDEC(409.831,"ALOC",CLINICIEN,RESOURCEIEN))
Q RESOURCEIEN
;
TC(TIME,SD,STARTOFDAY,SI) ;
N %DT,X,Y,SDXX,FTIME,MSG
; fix times less than 4 characters
S FTIME=SD_"."_TIME
S FTIME=$P($$FMTE^XLFDT(FTIME,"T"),"@",2)
S FTIME=$TR(FTIME,":","")
S X=$$FMTE^XLFDT(SD)_"@"_FTIME,%DT="T"
D ^%DT
I Y<0!(X["?") Q ""
S X=$E($P(Y_"0000",".",2),1,4)
S SDXX=$E(X,3,4)
S SDXX=X\100-STARTOFDAY*SI+(SDXX*SI\60)*2
I SDXX<0 S MSG="Day Starts at "_STARTOFDAY,Y=-1
I SDXX>72 S MSG="Day Ends prior to provided end time "_X,Y=-1
Q X_U_Y_U_SDXX_U_$G(MSG)
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2CANCLNAVAIL 9089 printed Oct 16, 2024@18:54 Page 2
SDES2CANCLNAVAIL ;ALB/BLB,BLB,TJB,BLB,JAS - SDES2 CANCEL CLINIC AVAILABILITY ; JULY 1, 2024
+1 ;;5.3;Scheduling;**869,873,875,880,886**;Aug 13, 1993;Build 13
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
CANCEL(JSON,SDCONTEXT,CANCEL) ;
+1 NEW ERRORS,RETURN
+2 ;
+3 DO VALIDATE(.ERRORS,.SDCONTEXT,.CANCEL,$GET(CANCEL("CLINIC IEN")),$GET(CANCEL("FULL PARTIAL FLAG")),$GET(CANCEL("REMARKS")))
+4 IF $DATA(ERRORS)
SET ERRORS("CancelClinicAvailability",1)=""
DO BUILDJSON^SDES2JSON(.JSON,.ERRORS)
QUIT
+5 ;
+6 DO CANCELAVAIL(CANCEL("CLINIC IEN"),CANCEL("START DATE TIME"),CANCEL("END DATE TIME"),CANCEL("FULL PARTIAL FLAG"),$GET(CANCEL("REMARKS")))
+7 DO CANCELAPPTS(CANCEL("CLINIC IEN"),CANCEL("START DATE TIME"),CANCEL("END DATE TIME"),CANCEL("FULL PARTIAL FLAG"),$GET(CANCEL("REMARKS")),.SDCONTEXT,.RETURN)
+8 ;
+9 SET RETURN("CancelClinicAvailability",1)="Clinic availability has been successfully cancelled."
+10 DO BUILDJSON^SDES2JSON(.JSON,.RETURN)
+11 QUIT
+12 ;
CANCELAVAIL(CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG,CANCELREMARKS) ;
+1 NEW PARTIALCANCELIEN,PARTIALCANCELFDA,CANCELDATE,DATE,ADDAPPTNODEFDA,CANCELMESSAGEFDA,NEWAPPTDATE,NEWSCHEDULEFDA,DATEINC
+2 NEW HRCLNDISPBEG,STARTOFDAY,INCREMENT,CANENDTIME,CANSTARTTIME,ST,SDXX,BLOCKLEN,CANDTTMEND,DH,DISPINCPERHR,I5,P,PARTIALCANAVAIL,X,Y
+3 ;
+4 SET HRCLNDISPBEG=$$GET1^DIQ(44,CLINICIEN,1914,"I")
+5 IF HRCLNDISPBEG=""
SET HRCLNDISPBEG=8
+6 SET STARTOFDAY=$SELECT($LENGTH(HRCLNDISPBEG):HRCLNDISPBEG,1:8)
+7 SET DISPINCPERHR=$$GET1^DIQ(44,CLINICIEN,1917,"I")
+8 SET INCREMENT=$SELECT(DISPINCPERHR="":4,DISPINCPERHR<3:4,DISPINCPERHR:DISPINCPERHR,1:4)
+9 SET CANENDTIME=$$TC($PIECE(ENDDATETIME,".",2),$PIECE(STARTDATETIME,"."),STARTOFDAY,INCREMENT)
+10 SET CANSTARTTIME=$$TC($PIECE(STARTDATETIME,".",2),$PIECE(STARTDATETIME,"."),STARTOFDAY,INCREMENT)
+11 SET ST=$PIECE(CANSTARTTIME,U,3)
+12 SET CANDTTMEND=$PIECE(CANENDTIME,U,2)
+13 SET SDXX=$PIECE(CANENDTIME,U,3)
+14 ;
+15 IF FLAG="P"
Begin DoDot:1
+16 SET CANCELDATE=$PIECE(STARTDATETIME,".")
+17 SET PARTIALCANCELFDA(44.05,"+1,"_CLINICIEN_",",.01)=STARTDATETIME
+18 SET PARTIALCANCELFDA(44.05,"+1,"_CLINICIEN_",",1)=$PIECE(CANENDTIME,"^")
+19 SET PARTIALCANCELIEN(1)=STARTDATETIME
+20 DO UPDATE^DIE(,"PARTIALCANCELFDA","PARTIALCANCELIEN")
KILL PARTIALCANCELFDA
+21 +22 IF $DATA(^SC(CLINICIEN,"S",STARTDATETIME,0))
Begin DoDot:2
+23 SET ADDAPPTNODEFDA(44.001,STARTDATETIME_","_CLINICIEN_",",.01)=STARTDATETIME
+24 SET ADDAPPTNODEFDA(44.001,STARTDATETIME_","_CLINICIEN_",",1400)="CANCELLED UNTIL "_ENDDATETIME_$SELECT(CANCELREMARKS?.P:"",1:" ("_CANCELREMARKS_")")
+25 DO FILE^DIE(,"ADDAPPTNODEFDA")
KILL ADDAPPTNODEFDA
End DoDot:2
+26 ;
+27 IF '$DATA(^SC(CLINICIEN,"S",STARTDATETIME,0))
Begin DoDot:2
+28 SET CANCELMESSAGEFDA(44.001,"+1,"_CLINICIEN_",",.01)=STARTDATETIME
+29 SET CANCELMESSAGEFDA(44.001,"+1,"_CLINICIEN_",",1400)="CANCELLED UNTIL "_ENDDATETIME_$SELECT(CANCELREMARKS?.P:"",1:" ("_CANCELREMARKS_")")
+30 SET NEWAPPTDATE(1)=STARTDATETIME
+31 DO UPDATE^DIE(,"CANCELMESSAGEFDA","NEWAPPTDATE")
KILL CANCELMESSAGEFDA
End DoDot:2
+32 ;
+33 SET PARTIALCANAVAIL=$$GET1^DIQ(44.005,$PIECE(STARTDATETIME,".")_","_CLINICIEN_",",1,"E")
+34 SET PARTIALCANAVAIL=PARTIALCANAVAIL_$JUSTIFY("",SDXX-$LENGTH(PARTIALCANAVAIL))
+35 SET Y=""
+36 SET BLOCKLEN=CANDTTMEND-STARTDATETIME
+37 ; pad 4 empty spaces needed for blocks < 60 minutes
IF $GET(BLOCKLEN)<100
IF $LENGTH(PARTIALCANAVAIL)<77
SET PARTIALCANAVAIL=PARTIALCANAVAIL_" "
+38 FOR X=0:2:SDXX
Begin DoDot:2
+39 SET DH=$EXTRACT(PARTIALCANAVAIL,X+INCREMENT+INCREMENT)
+40 SET P=$SELECT(X<ST:DH_$EXTRACT(PARTIALCANAVAIL,X+1+INCREMENT+INCREMENT),X=SDXX:$SELECT(Y="[":Y,1:DH)_$EXTRACT(PARTIALCANAVAIL,X+1+INCREMENT+INCREMENT),1:$SELECT(Y="["&(X=ST):"]",1:"X")_"X")
+41 SET Y=$SELECT(DH="]":"",DH="[":DH,1:Y)
+42 SET PARTIALCANAVAIL=$EXTRACT(PARTIALCANAVAIL,1,X-1+INCREMENT+INCREMENT)_P_$EXTRACT(PARTIALCANAVAIL,X+2+INCREMENT+INCREMENT,999)
End DoDot:2
+43 if '$FIND(PARTIALCANAVAIL,"[")
SET I5=$FIND(PARTIALCANAVAIL,"X")
SET PARTIALCANAVAIL=$EXTRACT(PARTIALCANAVAIL,1,(I5-2))_"["_$EXTRACT(PARTIALCANAVAIL,I5,999)
End DoDot:1
+44 ;
+45 ;
+46 FOR DATEINC=0:1
SET DATE=$$FMADD^XLFDT($PIECE(STARTDATETIME,"."),DATEINC)
if 'DATE!(DATE>$PIECE(ENDDATETIME,"."))
QUIT
Begin DoDot:1
+47 SET ^SC(CLINICIEN,"ST",$PIECE(DATE,"."),"CAN")=$GET(^SC(CLINICIEN,"ST",$PIECE(DATE,"."),1))
+48 SET NEWSCHEDULEFDA(44.005,DATE_","_CLINICIEN_",",1)=$SELECT(FLAG="P":PARTIALCANAVAIL,1:" "_$EXTRACT($PIECE(DATE,"."),6,7)_" **CANCELLED**")
+49 DO FILE^DIE(,"NEWSCHEDULEFDA")
KILL NEWSCHEDULEFDA
End DoDot:1
+50 QUIT
+51 ;
CANCELAPPTS(CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG,CANCELREMARKS,SDCONTEXT,RETURN) ;
+1 NEW CANCELAPPT,DATETIME,JSONCANCELRETURN,CANCELLED,RESOURCEIEN,APPTIEN,COUNT
+2 ;
+3 IF ENDDATETIME'["."
SET ENDDATETIME=ENDDATETIME_.2359
+4 SET RESOURCEIEN=$$GETRESOURCE(CLINICIEN)
+5 SET COUNT=0
+6 SET DATETIME=STARTDATETIME-.0001
+7 FOR
SET DATETIME=$ORDER(^SC(CLINICIEN,"S",DATETIME))
if 'DATETIME!(DATETIME>=ENDDATETIME)
QUIT
Begin DoDot:1
+8 SET APPTIEN=0
+9 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,DATETIME,APPTIEN))
if 'APPTIEN
QUIT
Begin DoDot:2
+10 IF $$GET1^DIQ(409.84,APPTIEN,.12,"I")
QUIT
+11 ;
+12 SET COUNT=COUNT+1
+13 SET CANCELAPPT("APPT IEN")=APPTIEN
+14 SET CANCELAPPT("DFN")=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
+15 SET CANCELAPPT("CLINIC IEN")=CLINICIEN
+16 SET CANCELAPPT("CANCEL REASON")="CLINIC CANCELLED"
+17 SET CANCELAPPT("CANCELLED BY")="C"
+18 DO CANCELAPPT^SDES2CANCELAPPT(.JSONCANCELRETURN,.SDCONTEXT,.CANCELAPPT)
+19 DO DECODE^XLFJSON("JSONCANCELRETURN","CANCELLED")
+20 SET RETURN("CancelledAppointment",COUNT,"AppointmentID")=$GET(CANCELLED("Appointment","Cancelled"))
KILL CANCELLED
+21 ;
+22 IF FLAG="P"
Begin DoDot:3
+23 DO EN^SDTMPHLC(CLINICIEN,STARTDATETIME,ENDDATETIME,"P",CANCELREMARKS)
End DoDot:3
+24 IF FLAG="F"
Begin DoDot:3
+25 DO EN^SDTMPHLC(CLINICIEN,$PIECE(STARTDATETIME,"."),,"C","**CANCELLED**")
End DoDot:3
End DoDot:2
End DoDot:1
+26 QUIT
+27 ;
VALIDATE(ERRORS,SDCONTEXT,CANCEL,CLINICIEN,FLAG,REMARKS) ;
+1 NEW VAL
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 DO VALFILEIEN^SDES2VALUTIL(.VAL,.ERRORS,44,CLINICIEN,1,,18,19)
+4 ;
+5 SET CANCEL("START DATE TIME")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(CANCEL("START DATE TIME")),CLINICIEN,1,9,11)
+6 SET CANCEL("END DATE TIME")=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(CANCEL("END DATE TIME")),CLINICIEN,1,10,12)
+7 IF $GET(CANCEL("START DATE TIME"))>$GET(CANCEL("END DATE TIME"))
DO ERRLOG^SDESJSON(.ERRORS,13)
+8 ;
+9 DO VALIDATEFLAG(.ERRORS,FLAG,$GET(CANCEL("START DATE TIME")),$GET(CANCEL("END DATE TIME")))
+10 IF $LENGTH(REMARKS)
IF $LENGTH(REMARKS)<3!($LENGTH(REMARKS)>160)
DO ERRLOG^SDESJSON(.ERRORS,255)
+11 IF $DATA(ERRORS)
QUIT
+12 ;
+13 ;
DO VALCLINICDETAILS(.ERRORS,CLINICIEN,$GET(CANCEL("START DATE TIME")),$GET(CANCEL("END DATE TIME")),FLAG)
+14 QUIT
+15 ;
VALCLINICDETAILS(ERRORS,CLINICIEN,STARTDATETIME,ENDDATETIME,FLAG) ;
+1 NEW SCHEDULEDATE,CANCELDATETIME,CANCELSTART,CANCELEND,SUBIEN,APPTDATETIME,DATEINC
+2 ;
+3 IF FLAG="P"
IF $PIECE(STARTDATETIME,".")'=$PIECE(ENDDATETIME,".")
DO ERRLOG^SDESJSON(.ERRORS,576)
QUIT
+4 FOR DATEINC=0:1
SET SCHEDULEDATE=$$FMADD^XLFDT($PIECE(STARTDATETIME,"."),DATEINC)
if 'SCHEDULEDATE!(SCHEDULEDATE>$PIECE(ENDDATETIME,"."))!($DATA(ERRORS))
QUIT
Begin DoDot:1
+5 IF $$INACTIVE^SDESUTIL(CLINICIEN,SCHEDULEDATE)
DO ERRLOG^SDESJSON(.ERRORS,525)
QUIT
+6 IF $$GET1^DIQ(44.005,SCHEDULEDATE_","_CLINICIEN_",",1,"I")["CANCELLED"
DO ERRLOG^SDESJSON(.ERRORS,248)
QUIT
+7 IF $$GET1^DIQ(44.005,SCHEDULEDATE_","_CLINICIEN_",",1,"I")'["["
DO ERRLOG^SDESJSON(.ERRORS,249)
QUIT
+8 IF FLAG="F"
IF $DATA(^SC(CLINICIEN,"ST",SCHEDULEDATE,"CAN"))
DO ERRLOG^SDESJSON(.ERRORS,250)
QUIT
+9 ;
+10 SET APPTDATETIME=STARTDATETIME-.0001
+11 FOR
SET APPTDATETIME=$ORDER(^SC(CLINICIEN,"S",APPTDATETIME))
if 'APPTDATETIME!(APPTDATETIME>=ENDDATETIME)!($DATA(ERRORS))
QUIT
Begin DoDot:2
+12 SET SUBIEN=0
+13 FOR
SET SUBIEN=$ORDER(^SC(CLINICIEN,"S",APPTDATETIME,1,SUBIEN))
if 'SUBIEN!($DATA(ERRORS))
QUIT
Begin DoDot:3
+14 IF $$GET1^DIQ(44.003,SUBIEN_","_APPTDATETIME_","_CLINICIEN_",",310)="CANCELLED"
QUIT
+15 IF $$GET1^DIQ(44.003,SUBIEN_","_APPTDATETIME_","_CLINICIEN_",",303,"I")
DO ERRLOG^SDESJSON(.ERRORS,247)
End DoDot:3
End DoDot:2
+16 ;
+17 IF FLAG="P"
IF $DATA(^SC(CLINICIEN,"ST",$PIECE(SCHEDULEDATE,"."),"CAN"))
Begin DoDot:2
+18 SET CANCELDATETIME=$PIECE(STARTDATETIME,".")
+19 FOR
SET CANCELDATETIME=$ORDER(^SC(CLINICIEN,"SDCAN",CANCELDATETIME))
if 'CANCELDATETIME!($PIECE(CANCELDATETIME,".")>$PIECE(STARTDATETIME,"."))!($DATA(ERRORS))
QUIT
Begin DoDot:3
+20 SET CANCELSTART=$$GET1^DIQ(44.05,CANCELDATETIME_","_CLINICIEN_",",.01,"I")
+21 SET CANCELEND=$PIECE(CANCELSTART,".")_"."_$PIECE($$GET1^DIQ(44.05,CANCELDATETIME_","_CLINICIEN_",",1,"I"),".",1)*1
+22 IF STARTDATETIME>=CANCELEND!(ENDDATETIME<=CANCELSTART)!(CANCELSTART>=ENDDATETIME)!(CANCELEND<=STARTDATETIME)
QUIT
+23 DO ERRLOG^SDESJSON(.ERRORS,250)
End DoDot:3
End DoDot:2
End DoDot:1
+24 QUIT
+25 ;
VALIDATEFLAG(ERRORS,FLAG,STARTDATETIME,ENDDATETIME) ;
+1 IF '$LENGTH($GET(FLAG))
DO ERRLOG^SDESJSON(.ERRORS,245)
QUIT
+2 IF $GET(FLAG)'="F"
IF $GET(FLAG)'="P"
DO ERRLOG^SDESJSON(.ERRORS,246)
+3 ;
+4 IF $GET(FLAG)="F"
Begin DoDot:1
+5 IF STARTDATETIME["."!(ENDDATETIME[".")
DO ERRLOG^SDESJSON(.ERRORS,552)
QUIT
End DoDot:1
+6 IF $GET(FLAG)="P"
Begin DoDot:1
+7 IF STARTDATETIME'["."!(ENDDATETIME'[".")
DO ERRLOG^SDESJSON(.ERRORS,551)
End DoDot:1
+8 QUIT
+9 ;
GETRESOURCE(CLINICIEN) ;
+1 SET RESOURCEIEN=0
+2 FOR
SET RESOURCEIEN=$ORDER(^SDEC(409.831,"ALOC",CLINICIEN,RESOURCEIEN))
if 'RESOURCEIEN!(RESOURCEIEN)
QUIT
Begin DoDot:1
+3 IF $$GET1^DIQ(409.831,RESOURCEIEN,.012,"E")="CLINIC"
Begin DoDot:2
End DoDot:2
+4 SET RESOURCEIEN=$ORDER(^SDEC(409.831,"ALOC",CLINICIEN,RESOURCEIEN))
End DoDot:1
+5 QUIT RESOURCEIEN
+6 ;
TC(TIME,SD,STARTOFDAY,SI) ;
+1 NEW %DT,X,Y,SDXX,FTIME,MSG
+2 ; fix times less than 4 characters
+3 SET FTIME=SD_"."_TIME
+4 SET FTIME=$PIECE($$FMTE^XLFDT(FTIME,"T"),"@",2)
+5 SET FTIME=$TRANSLATE(FTIME,":","")
+6 SET X=$$FMTE^XLFDT(SD)_"@"_FTIME
SET %DT="T"
+7 DO ^%DT
+8 IF Y<0!(X["?")
QUIT ""
+9 SET X=$EXTRACT($PIECE(Y_"0000",".",2),1,4)
+10 SET SDXX=$EXTRACT(X,3,4)
+11 SET SDXX=X\100-STARTOFDAY*SI+(SDXX*SI\60)*2
+12 IF SDXX<0
SET MSG="Day Starts at "_STARTOFDAY
SET Y=-1
+13 IF SDXX>72
SET MSG="Day Ends prior to provided end time "_X
SET Y=-1
+14 QUIT X_U_Y_U_SDXX_U_$GET(MSG)
+15 ;