SDES2GETCANSLOTS ;ALB/MGD,JAS,BLB - VISTA SCHEDULING RPCS GET CLINIC CANCELLED SLOTS ; May 21, 2024@16:10
;;5.3;Scheduling;**866,880,893**;Aug 13, 1993;Build 6
;;Per VHA Directive 6402, this routine should not be modified
;
; External References
; -------------------
; Reference to $$FIND1^DIC in ICR #2051
; Reference to $$GET1^DIQ in ICR #2056
;
Q ;No Direct Call
;
; RPC: SDES2 GET CANCELLED SLOTS
;
GETCANCSLOTS(JSONRETURN,SDCONTEXT,SDCANCDATA) ;
; This RPC returns cancelled slots within a given timeframe for a given clinic in JSON format.
; Input:
; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
; SDCONTEXT("USER DUZ") = [required] - The DUZ of the user taking action in the calling application.
; SDCONTEXT("USER SECID") = [optional] - The SECID of the user taking action in the calling application.
; SDCONTEXT("PATIENT DFN") = [optional] - The DFN/IEN of the target patient from the calling application.
; SDCONTEXT("PATIENT ICN") = [optional] - The ICN of the target patient from the calling application.
;
; SDCANCDATA("CLINICIEN") = [required] - The Internal Entry Number (IEN) from the HOSPITAL LOCATION File #44
; SDCANCDATA("SDESSTART") = [required] - The Start Date of search in ISO8601 format CCYY-MM-DDTHH:MM-OFFSET
; SDCANCDATA("SDESENDDATE") = [required] - The End Date of search in ISO8601 format CCYY-MM-DDTHH:MM-OFFSET
;
; JSONRETURN = [required] - This is where the retrieved data is stored in JSON format.
;
N SDGETCANCSLOTS,SDCLNAME,ERROR,SDCLRESIEN,SDTMPARY
S ERROR=0
; validate context
D VALCONTEXT^SDES2VALCONTEXT(.SDGETCANCSLOTS,.SDCONTEXT)
I $D(SDGETCANCSLOTS) S SDGETCANCSLOTS("CancelledSlots",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS) Q
;
; validate cancdata input parameters
D VALIDATEINPUT(.SDGETCANCSLOTS,.SDCANCDATA,.ERROR)
I ERROR S SDGETCANCSLOTS("CancelledSlots",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS) Q
;
K SDTMPARY
S SDTMPARY=$NA(^TMP($J,"CLNCANCSLOTS"))
K @SDTMPARY
D GETSLOTS^SDEC57(SDTMPARY,$G(SDCANCDATA("SDCLRESIEN")),$G(SDCANCDATA("SDESSTART")),$G(SDCANCDATA("SDESENDDATE")))
D BUILDDATA(.SDGETCANCSLOTS,.SDCANCDATA,SDTMPARY)
K @SDTMPARY
I ERROR!('$D(SDGETCANCSLOTS("CancelledSlots"))) S SDGETCANCSLOTS("CancelledSlots",1)=""
D BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS)
K SDGETCANCSLOTS
Q
;
VALIDATEINPUT(SDGETCANCSLOTS,SDCANCDATA,ERROR) ;validate input parameters
N CLINICIEN,SDERR,EFLAG,SFLAG,SDESSTART,SDESENDDATE,SDVALERROR
S (SFLAG,EFLAG)=0
;validate CLINIC IEN
S CLINICIEN=$G(SDCANCDATA("CLINICIEN"))
D VALFILEIEN^SDES2VALUTIL(.SDVALERROR,.SDGETCANCSLOTS,44,CLINICIEN,1,,67,19)
I SDVALERROR=0 S ERROR=1 Q
I +CLINICIEN>0 D Q:ERROR
. S SDCLNAME=$$GET1^DIQ(44,CLINICIEN_",",.01,"I") ;retrieve the clinic name
. I SDCLNAME="" D ERRLOG^SDESJSON(.SDGETCANCSLOTS,80) S ERROR=1 Q ;clinic IEN not found
. S SDCLRESIEN=$$FIND1^DIC(409.831,"","MX",SDCLNAME,"","","SDERR") ;retrieve the resource IEN for the clinic
. I $D(SDERR) D ERRLOG^SDESJSON(.SDGETCANCSLOTS,70) S ERROR=1 Q ;invalid clinic resource id
. S SDCANCDATA("SDCLRESIEN")=SDCLRESIEN
;
;validate start date
S SDESSTART=$G(SDCANCDATA("SDESSTART"))
S SDESSTART=$$VALISODTTM^SDES2VALISODTTM(.SDGETCANCSLOTS,SDESSTART,CLINICIEN,1,25,27)
I SDESSTART="" S ERROR=1 Q
I $P(SDESSTART,".",2)="" S ERROR=1 D ERRLOG^SDES2JSON(.SDGETCANCSLOTS,27) Q
S SDCANCDATA("SDESSTARTDTTM")=SDESSTART
S SDCANCDATA("SDESSTART")=$P(SDESSTART,".",1)
;
;validate end date
S SDESENDDATE=$G(SDCANCDATA("SDESENDDATE"))
S SDESENDDATE=$$VALISODTTM^SDES2VALISODTTM(.SDGETCANCSLOTS,SDESENDDATE,CLINICIEN,1,26,28)
I SDESENDDATE="" S ERROR=1 Q
I $P(SDESENDDATE,".",2)="" S ERROR=1 D ERRLOG^SDES2JSON(.SDGETCANCSLOTS,28) Q
S SDCANCDATA("SDESENDDTTM")=SDESENDDATE
S SDCANCDATA("SDESENDDATE")=$P(SDESENDDATE,".",1)
;
;validate end date after start date
I SDESSTART>SDESENDDATE S ERROR=1 D ERRLOG^SDESJSON(.SDGETCANCSLOTS,242)
Q
;
BUILDDATA(SDGETCANCSLOTS,SDCANCDATA,SDTMPARY) ; retrieve clinic availability data
N CLINICIEN,SDP1,SDP2,SDP3,SDP4,SDSLOTS,SDSTOPTM,SDSTRTTM,SDTOTAL,II,SDDIV,SDINST,SDAPDTTM,SDCANMSG,SDFIRST,CANCELDATE
I $O(@SDTMPARY@(""))="" Q
S CLINICIEN=$G(SDCANCDATA("CLINICIEN"))
S SDTOTAL=@SDTMPARY@("CNT"),SDFIRST=1
F II=1:1:SDTOTAL D
. S SDP1=$P(@SDTMPARY@(II),U,2) ;start date
. S SDP2=$P(@SDTMPARY@(II),U,3) ;end date
. I (SDP1<SDCANCDATA("SDESSTARTDTTM"))!(('SDFIRST)&(SDP1>SDCANCDATA("SDESENDDTTM"))) Q
. I SDFIRST,$D(^SC(CLINICIEN,"S",+SDP1))<1 D ; Use first populated slot
. . I II=1 S SDFIRST=0 Q
. . S II=II-1,SDFIRST=0
. . S SDP1=$P(@SDTMPARY@(II),U,2) ; Use first populated slot
. . S SDP2=$P(@SDTMPARY@(II),U,3)
. S SDP3=+$P(@SDTMPARY@(II),U,4) ;open slots available
. S SDP4=$P(@SDTMPARY@(II),U,5) ;access type (1=available, 2=not available, 3=cancelled)
. Q:SDP4'=3 ; Only return cancelled slots
. I $P(SDP1,".",2)=""!($P(SDP1,".",2)="00") S $P(SDP1,".",2)="0001"
. S SDSTRTTM=$$FMTISO^SDAMUTDT(SDP1,CLINICIEN)
. S SDSTOPTM=$$FMTISO^SDAMUTDT(SDP2,CLINICIEN)
.S CANCELDATE=$P($$ISOTFM^SDAMUTDT(SDSTRTTM),".")
. S SDSLOTS=$P(@SDTMPARY@(II),U,4)
. S SDSLOTS=$S(SDSLOTS=" ":"",1:SDSLOTS)
. S SDSLOTS=$S(SDP4=3:"X",1:SDSLOTS)
. S SDGETCANCSLOTS("CancelledSlots",II,"BeginTime")=SDSTRTTM
. S SDGETCANCSLOTS("CancelledSlots",II,"EndTime")=SDSTOPTM
. S SDGETCANCSLOTS("CancelledSlots",II,"SlotsAvail")=SDSLOTS
. S SDAPDTTM=+SDP1
. S SDCANMSG=$S($D(^SC(CLINICIEN,"FULL DAY CANCEL",CANCELDATE)):$$GET1^DIQ(44.1902,CANCELDATE_","_CLINICIEN_",",.02),1:$$GET1^DIQ(44.001,SDAPDTTM_","_CLINICIEN_",",1400))
. S SDGETCANCSLOTS("CancelledSlots",II,"CancelMessage")=SDCANMSG
; Changes for 831 start
I $G(CLINICIEN) D
.S SDDIV=$$GET1^DIQ(44,CLINICIEN_",",3.5,"I")
.S:SDDIV SDINST=$$GET1^DIQ(40.8,SDDIV_",",.07,"I")
.I $$GET1^DIQ(4,SDINST,800,"I")="" D
..S SDGETCANCSLOTS("CancelledSlots",0.1,"Error")="No Timezone set for Clinic."
..I $$GET1^DIQ(8989.3,1,217,"I")="" S SDGETCANCSLOTS("CancelledSlots",0.2,"Error")="No Timezone set for Institution in Kernel Parameters (#8989.3) file."
; Changes for 831 end
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2GETCANSLOTS 6253 printed Dec 13, 2024@02:53:54 Page 2
SDES2GETCANSLOTS ;ALB/MGD,JAS,BLB - VISTA SCHEDULING RPCS GET CLINIC CANCELLED SLOTS ; May 21, 2024@16:10
+1 ;;5.3;Scheduling;**866,880,893**;Aug 13, 1993;Build 6
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; External References
+5 ; -------------------
+6 ; Reference to $$FIND1^DIC in ICR #2051
+7 ; Reference to $$GET1^DIQ in ICR #2056
+8 ;
+9 ;No Direct Call
QUIT
+10 ;
+11 ; RPC: SDES2 GET CANCELLED SLOTS
+12 ;
GETCANCSLOTS(JSONRETURN,SDCONTEXT,SDCANCDATA) ;
+1 ; This RPC returns cancelled slots within a given timeframe for a given clinic in JSON format.
+2 ; Input:
+3 ; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
+4 ; SDCONTEXT("USER DUZ") = [required] - The DUZ of the user taking action in the calling application.
+5 ; SDCONTEXT("USER SECID") = [optional] - The SECID of the user taking action in the calling application.
+6 ; SDCONTEXT("PATIENT DFN") = [optional] - The DFN/IEN of the target patient from the calling application.
+7 ; SDCONTEXT("PATIENT ICN") = [optional] - The ICN of the target patient from the calling application.
+8 ;
+9 ; SDCANCDATA("CLINICIEN") = [required] - The Internal Entry Number (IEN) from the HOSPITAL LOCATION File #44
+10 ; SDCANCDATA("SDESSTART") = [required] - The Start Date of search in ISO8601 format CCYY-MM-DDTHH:MM-OFFSET
+11 ; SDCANCDATA("SDESENDDATE") = [required] - The End Date of search in ISO8601 format CCYY-MM-DDTHH:MM-OFFSET
+12 ;
+13 ; JSONRETURN = [required] - This is where the retrieved data is stored in JSON format.
+14 ;
+15 NEW SDGETCANCSLOTS,SDCLNAME,ERROR,SDCLRESIEN,SDTMPARY
+16 SET ERROR=0
+17 ; validate context
+18 DO VALCONTEXT^SDES2VALCONTEXT(.SDGETCANCSLOTS,.SDCONTEXT)
+19 IF $DATA(SDGETCANCSLOTS)
SET SDGETCANCSLOTS("CancelledSlots",1)=""
DO BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS)
QUIT
+20 ;
+21 ; validate cancdata input parameters
+22 DO VALIDATEINPUT(.SDGETCANCSLOTS,.SDCANCDATA,.ERROR)
+23 IF ERROR
SET SDGETCANCSLOTS("CancelledSlots",1)=""
DO BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS)
QUIT
+24 ;
+25 KILL SDTMPARY
+26 SET SDTMPARY=$NAME(^TMP($JOB,"CLNCANCSLOTS"))
+27 KILL @SDTMPARY
+28 DO GETSLOTS^SDEC57(SDTMPARY,$GET(SDCANCDATA("SDCLRESIEN")),$GET(SDCANCDATA("SDESSTART")),$GET(SDCANCDATA("SDESENDDATE")))
+29 DO BUILDDATA(.SDGETCANCSLOTS,.SDCANCDATA,SDTMPARY)
+30 KILL @SDTMPARY
+31 IF ERROR!('$DATA(SDGETCANCSLOTS("CancelledSlots")))
SET SDGETCANCSLOTS("CancelledSlots",1)=""
+32 DO BUILDJSON^SDES2JSON(.JSONRETURN,.SDGETCANCSLOTS)
+33 KILL SDGETCANCSLOTS
+34 QUIT
+35 ;
VALIDATEINPUT(SDGETCANCSLOTS,SDCANCDATA,ERROR) ;validate input parameters
+1 NEW CLINICIEN,SDERR,EFLAG,SFLAG,SDESSTART,SDESENDDATE,SDVALERROR
+2 SET (SFLAG,EFLAG)=0
+3 ;validate CLINIC IEN
+4 SET CLINICIEN=$GET(SDCANCDATA("CLINICIEN"))
+5 DO VALFILEIEN^SDES2VALUTIL(.SDVALERROR,.SDGETCANCSLOTS,44,CLINICIEN,1,,67,19)
+6 IF SDVALERROR=0
SET ERROR=1
QUIT
+7 IF +CLINICIEN>0
Begin DoDot:1
+8 ;retrieve the clinic name
SET SDCLNAME=$$GET1^DIQ(44,CLINICIEN_",",.01,"I")
+9 ;clinic IEN not found
IF SDCLNAME=""
DO ERRLOG^SDESJSON(.SDGETCANCSLOTS,80)
SET ERROR=1
QUIT
+10 ;retrieve the resource IEN for the clinic
SET SDCLRESIEN=$$FIND1^DIC(409.831,"","MX",SDCLNAME,"","","SDERR")
+11 ;invalid clinic resource id
IF $DATA(SDERR)
DO ERRLOG^SDESJSON(.SDGETCANCSLOTS,70)
SET ERROR=1
QUIT
+12 SET SDCANCDATA("SDCLRESIEN")=SDCLRESIEN
End DoDot:1
if ERROR
QUIT
+13 ;
+14 ;validate start date
+15 SET SDESSTART=$GET(SDCANCDATA("SDESSTART"))
+16 SET SDESSTART=$$VALISODTTM^SDES2VALISODTTM(.SDGETCANCSLOTS,SDESSTART,CLINICIEN,1,25,27)
+17 IF SDESSTART=""
SET ERROR=1
QUIT
+18 IF $PIECE(SDESSTART,".",2)=""
SET ERROR=1
DO ERRLOG^SDES2JSON(.SDGETCANCSLOTS,27)
QUIT
+19 SET SDCANCDATA("SDESSTARTDTTM")=SDESSTART
+20 SET SDCANCDATA("SDESSTART")=$PIECE(SDESSTART,".",1)
+21 ;
+22 ;validate end date
+23 SET SDESENDDATE=$GET(SDCANCDATA("SDESENDDATE"))
+24 SET SDESENDDATE=$$VALISODTTM^SDES2VALISODTTM(.SDGETCANCSLOTS,SDESENDDATE,CLINICIEN,1,26,28)
+25 IF SDESENDDATE=""
SET ERROR=1
QUIT
+26 IF $PIECE(SDESENDDATE,".",2)=""
SET ERROR=1
DO ERRLOG^SDES2JSON(.SDGETCANCSLOTS,28)
QUIT
+27 SET SDCANCDATA("SDESENDDTTM")=SDESENDDATE
+28 SET SDCANCDATA("SDESENDDATE")=$PIECE(SDESENDDATE,".",1)
+29 ;
+30 ;validate end date after start date
+31 IF SDESSTART>SDESENDDATE
SET ERROR=1
DO ERRLOG^SDESJSON(.SDGETCANCSLOTS,242)
+32 QUIT
+33 ;
BUILDDATA(SDGETCANCSLOTS,SDCANCDATA,SDTMPARY) ; retrieve clinic availability data
+1 NEW CLINICIEN,SDP1,SDP2,SDP3,SDP4,SDSLOTS,SDSTOPTM,SDSTRTTM,SDTOTAL,II,SDDIV,SDINST,SDAPDTTM,SDCANMSG,SDFIRST,CANCELDATE
+2 IF $ORDER(@SDTMPARY@(""))=""
QUIT
+3 SET CLINICIEN=$GET(SDCANCDATA("CLINICIEN"))
+4 SET SDTOTAL=@SDTMPARY@("CNT")
SET SDFIRST=1
+5 FOR II=1:1:SDTOTAL
Begin DoDot:1
+6 ;start date
SET SDP1=$PIECE(@SDTMPARY@(II),U,2)
+7 ;end date
SET SDP2=$PIECE(@SDTMPARY@(II),U,3)
+8 IF (SDP1<SDCANCDATA("SDESSTARTDTTM"))!(('SDFIRST)&(SDP1>SDCANCDATA("SDESENDDTTM")))
QUIT
+9 ; Use first populated slot
IF SDFIRST
IF $DATA(^SC(CLINICIEN,"S",+SDP1))<1
Begin DoDot:2
+10 IF II=1
SET SDFIRST=0
QUIT
+11 SET II=II-1
SET SDFIRST=0
+12 ; Use first populated slot
SET SDP1=$PIECE(@SDTMPARY@(II),U,2)
+13 SET SDP2=$PIECE(@SDTMPARY@(II),U,3)
End DoDot:2
+14 ;open slots available
SET SDP3=+$PIECE(@SDTMPARY@(II),U,4)
+15 ;access type (1=available, 2=not available, 3=cancelled)
SET SDP4=$PIECE(@SDTMPARY@(II),U,5)
+16 ; Only return cancelled slots
if SDP4'=3
QUIT
+17 IF $PIECE(SDP1,".",2)=""!($PIECE(SDP1,".",2)="00")
SET $PIECE(SDP1,".",2)="0001"
+18 SET SDSTRTTM=$$FMTISO^SDAMUTDT(SDP1,CLINICIEN)
+19 SET SDSTOPTM=$$FMTISO^SDAMUTDT(SDP2,CLINICIEN)
+20 SET CANCELDATE=$PIECE($$ISOTFM^SDAMUTDT(SDSTRTTM),".")
+21 SET SDSLOTS=$PIECE(@SDTMPARY@(II),U,4)
+22 SET SDSLOTS=$SELECT(SDSLOTS=" ":"",1:SDSLOTS)
+23 SET SDSLOTS=$SELECT(SDP4=3:"X",1:SDSLOTS)
+24 SET SDGETCANCSLOTS("CancelledSlots",II,"BeginTime")=SDSTRTTM
+25 SET SDGETCANCSLOTS("CancelledSlots",II,"EndTime")=SDSTOPTM
+26 SET SDGETCANCSLOTS("CancelledSlots",II,"SlotsAvail")=SDSLOTS
+27 SET SDAPDTTM=+SDP1
+28 SET SDCANMSG=$SELECT($DATA(^SC(CLINICIEN,"FULL DAY CANCEL",CANCELDATE)):$$GET1^DIQ(44.1902,CANCELDATE_","_CLINICIEN_",",.02),1:$$GET1^DIQ(44.001,SDAPDTTM_","_CLINICIEN_",",1400))
+29 SET SDGETCANCSLOTS("CancelledSlots",II,"CancelMessage")=SDCANMSG
End DoDot:1
+30 ; Changes for 831 start
+31 IF $GET(CLINICIEN)
Begin DoDot:1
+32 SET SDDIV=$$GET1^DIQ(44,CLINICIEN_",",3.5,"I")
+33 if SDDIV
SET SDINST=$$GET1^DIQ(40.8,SDDIV_",",.07,"I")
+34 IF $$GET1^DIQ(4,SDINST,800,"I")=""
Begin DoDot:2
+35 SET SDGETCANCSLOTS("CancelledSlots",0.1,"Error")="No Timezone set for Clinic."
+36 IF $$GET1^DIQ(8989.3,1,217,"I")=""
SET SDGETCANCSLOTS("CancelledSlots",0.2,"Error")="No Timezone set for Institution in Kernel Parameters (#8989.3) file."
End DoDot:2
End DoDot:1
+37 ; Changes for 831 end
+38 QUIT