SDESCANCELRSNS ;ALB/JAS,LAB - SDES GET CANCEL REASONS RPC ;Dec 6, 2023
;;5.3;Scheduling;**836,845,867**;Aug 13, 1993;Build 8
;;Per VHA Directive 6402, this routine should not be modified
;
GETCANCELRSNS(CANCELRSNSRET,REASONSTAT) ; GET CANCEL REASONS from file 409.2
; INPUT: REASONSTAT - (optional) Flag: show inactive 0=active only (default); 1=show active and inactive
;
N CANCREASONNAME,CANCREASONREC,CANCREASONTYP,HASFIELDS,RETURN,RETCOUNT
S (CANCREASONNAME,CANCREASONREC,CANCREASONTYP,HASFIELDS,RETURN)="",RETCOUNT=1
;
; Check input parameter flag
;
S:($G(REASONSTAT)="") REASONSTAT=0 ;default to active only if no input value
I "01"'[$G(REASONSTAT) D
. D ERRLOG^SDESJSON(.SDESERR,267) M RETURN=SDESERR ;invalid parameter flag value
;
; Loop through file 409.2's "NAME" x-ref
;
I '$D(RETURN("Error")) D
. F S CANCREASONNAME=$O(^SD(409.2,"B",CANCREASONNAME)) Q:CANCREASONNAME="" D
. . S CANCREASONREC=$O(^SD(409.2,"B",CANCREASONNAME,""))
. . S HASFIELDS=$$GETREASONFIELDS(.RSNFIELDSARRAY,CANCREASONREC,REASONSTAT,RETCOUNT)
. . I HASFIELDS M RETURN=RSNFIELDSARRAY S RETCOUNT=RETCOUNT+1
;
D BUILDJSON^SDESBUILDJSON(.CANCELRSNSRET,.RETURN)
D CLEANUP
Q
;
GETREASONFIELDS(CANCELREASON,CANCREASONIEN,REASONSTAT,RETCOUNT) ; GET CANCEL REASON FIELDS
;
N DIQERROR,FILENUMBER,FIELDNUMBERS,HASDATA,RSNIENSTRING,REASONFIELDS
S DIQERROR=""
S FILENUMBER=409.2
S FIELDNUMBERS=".01;2;4;5;6"
S RSNIENSTRING=CANCREASONIEN_","
;
D GETS^DIQ(FILENUMBER,CANCREASONIEN,FIELDNUMBERS,"IE","REASONFIELDS","DIQERROR")
;
I DIQERROR S CANCELREASON("Error",1)=DIQERROR
I 'DIQERROR D
.I 'REASONSTAT,$G(REASONFIELDS(FILENUMBER,RSNIENSTRING,4,"I")) Q
.S CANCELREASON("CancelReasons",RETCOUNT,"ReasonIEN")=CANCREASONIEN
.S CANCELREASON("CancelReasons",RETCOUNT,"ReasonName")=$G(REASONFIELDS(FILENUMBER,RSNIENSTRING,.01,"E"))
.S CANCELREASON("CancelReasons",RETCOUNT,"ReasonType")=$G(REASONFIELDS(FILENUMBER,RSNIENSTRING,2,"E"))
.S CANCELREASON("CancelReasons",RETCOUNT,"ReasonSystemUse")=$G(REASONFIELDS(FILENUMBER,RSNIENSTRING,6,"E"))
.S CANCELREASON("CancelReasons",RETCOUNT,"ReopenRequestUponCancel")=$G(REASONFIELDS(FILENUMBER,RSNIENSTRING,5,"E"))
S HASDATA=$D(CANCELREASON)>1
Q HASDATA
;
CLEANUP ; Cleanup variables arrays to prevent leaking
;
K DIQERROR,ERRORFLAG,FIELDNUMBERS,FILENUMBER,HASDATA,HASFIELDS
K REASONFIELDS,RETCOUNT,RETURN,RSNFIELDSARRAY,RSNIENSTRING,SDESERR
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESCANCELRSNS 2461 printed Dec 13, 2024@02:55:58 Page 2
SDESCANCELRSNS ;ALB/JAS,LAB - SDES GET CANCEL REASONS RPC ;Dec 6, 2023
+1 ;;5.3;Scheduling;**836,845,867**;Aug 13, 1993;Build 8
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
GETCANCELRSNS(CANCELRSNSRET,REASONSTAT) ; GET CANCEL REASONS from file 409.2
+1 ; INPUT: REASONSTAT - (optional) Flag: show inactive 0=active only (default); 1=show active and inactive
+2 ;
+3 NEW CANCREASONNAME,CANCREASONREC,CANCREASONTYP,HASFIELDS,RETURN,RETCOUNT
+4 SET (CANCREASONNAME,CANCREASONREC,CANCREASONTYP,HASFIELDS,RETURN)=""
SET RETCOUNT=1
+5 ;
+6 ; Check input parameter flag
+7 ;
+8 ;default to active only if no input value
if ($GET(REASONSTAT)="")
SET REASONSTAT=0
+9 IF "01"'[$GET(REASONSTAT)
Begin DoDot:1
+10 ;invalid parameter flag value
DO ERRLOG^SDESJSON(.SDESERR,267)
MERGE RETURN=SDESERR
End DoDot:1
+11 ;
+12 ; Loop through file 409.2's "NAME" x-ref
+13 ;
+14 IF '$DATA(RETURN("Error"))
Begin DoDot:1
+15 FOR
SET CANCREASONNAME=$ORDER(^SD(409.2,"B",CANCREASONNAME))
if CANCREASONNAME=""
QUIT
Begin DoDot:2
+16 SET CANCREASONREC=$ORDER(^SD(409.2,"B",CANCREASONNAME,""))
+17 SET HASFIELDS=$$GETREASONFIELDS(.RSNFIELDSARRAY,CANCREASONREC,REASONSTAT,RETCOUNT)
+18 IF HASFIELDS
MERGE RETURN=RSNFIELDSARRAY
SET RETCOUNT=RETCOUNT+1
End DoDot:2
End DoDot:1
+19 ;
+20 DO BUILDJSON^SDESBUILDJSON(.CANCELRSNSRET,.RETURN)
+21 DO CLEANUP
+22 QUIT
+23 ;
GETREASONFIELDS(CANCELREASON,CANCREASONIEN,REASONSTAT,RETCOUNT) ; GET CANCEL REASON FIELDS
+1 ;
+2 NEW DIQERROR,FILENUMBER,FIELDNUMBERS,HASDATA,RSNIENSTRING,REASONFIELDS
+3 SET DIQERROR=""
+4 SET FILENUMBER=409.2
+5 SET FIELDNUMBERS=".01;2;4;5;6"
+6 SET RSNIENSTRING=CANCREASONIEN_","
+7 ;
+8 DO GETS^DIQ(FILENUMBER,CANCREASONIEN,FIELDNUMBERS,"IE","REASONFIELDS","DIQERROR")
+9 ;
+10 IF DIQERROR
SET CANCELREASON("Error",1)=DIQERROR
+11 IF 'DIQERROR
Begin DoDot:1
+12 IF 'REASONSTAT
IF $GET(REASONFIELDS(FILENUMBER,RSNIENSTRING,4,"I"))
QUIT
+13 SET CANCELREASON("CancelReasons",RETCOUNT,"ReasonIEN")=CANCREASONIEN
+14 SET CANCELREASON("CancelReasons",RETCOUNT,"ReasonName")=$GET(REASONFIELDS(FILENUMBER,RSNIENSTRING,.01,"E"))
+15 SET CANCELREASON("CancelReasons",RETCOUNT,"ReasonType")=$GET(REASONFIELDS(FILENUMBER,RSNIENSTRING,2,"E"))
+16 SET CANCELREASON("CancelReasons",RETCOUNT,"ReasonSystemUse")=$GET(REASONFIELDS(FILENUMBER,RSNIENSTRING,6,"E"))
+17 SET CANCELREASON("CancelReasons",RETCOUNT,"ReopenRequestUponCancel")=$GET(REASONFIELDS(FILENUMBER,RSNIENSTRING,5,"E"))
End DoDot:1
+18 SET HASDATA=$DATA(CANCELREASON)>1
+19 QUIT HASDATA
+20 ;
CLEANUP ; Cleanup variables arrays to prevent leaking
+1 ;
+2 KILL DIQERROR,ERRORFLAG,FIELDNUMBERS,FILENUMBER,HASDATA,HASFIELDS
+3 KILL REASONFIELDS,RETCOUNT,RETURN,RSNFIELDSARRAY,RSNIENSTRING,SDESERR
+4 QUIT