SDES2GETCLNSTA ;ALB/BWF - SDES2 GET CLINICS BY STATION; JUL 17,2024
;;5.3;Scheduling;**886**;Aug 13, 1993;Build 13
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
; INPUT
; SDCONTEXT Array
;
; SDINPUT("STATION NUMBER") - station number
; SDINPUT("ACTIVE ONLY") - set to '1' if only active clinics should be included (if nothing is sent, active and inactive clinics are returned)
;
GETCLINICS(JSONRETURN,SDCONTEXT,SDINPUT) ;
N STATION,INST,ERRORS,CNT,DATA,CLINIEN,CLNSTA
S DATA=$NA(^TMP("SDES2GETCLNSTA",$J,"DATA")) K @DATA
; validate context
S JSONRETURN=$NA(^TMP("SDES2GETCLNSTA",$J,"JSON")) K @JSONRETURN
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Clinic",1)="" D ENCODE^XLFJSON("ERRORS",.JSONRETURN) Q
; validate SDINPUT
I $D(SDINPUT("ACTIVE ONLY")),$G(SDINPUT("ACTIVE ONLY"))'=1 D ERRLOG^SDES2JSON(.ERRORS,52,"Invalid 'ACTIVE ONLY' flag.")
S STATION=$G(SDINPUT("STATION NUMBER"))
I STATION="" D ERRLOG^SDES2JSON(.ERRORS,196)
S INST=$$IEN^XUAF4(STATION)
I STATION]"",'INST D ERRLOG^SDES2JSON(.ERRORS,197)
I $D(ERRORS) S ERRORS("Clinic",1)="" D ENCODE^XLFJSON("ERRORS",.JSONRETURN) Q
;
S (CLINIEN,CNT)=0
F S CLINIEN=$O(^SC(CLINIEN)) Q:'CLINIEN D
.Q:$$GET1^DIQ(44,CLINIEN,2,"I")'="C"
.S CLNSTA=$$CLINSTA(CLINIEN) Q:CLNSTA=""
.I $L(STATION)=3,+CLNSTA'=STATION Q
.I $L(STATION)>3,CLNSTA'=STATION Q
.I $G(SDINPUT("ACTIVE ONLY")) Q:$$INACTIVE^SDES2UTIL(CLINIEN,DT)
.S CNT=CNT+1
.S @DATA@("Clinic",CNT,"ClinicIen")=CLINIEN
.S @DATA@("Clinic",CNT,"ResourceIen")=$O(^SDEC(409.831,"ALOC",CLINIEN,0))
.S @DATA@("Clinic",CNT,"Name")=$$GET1^DIQ(44,CLINIEN,.01,"E")
I '$D(@DATA) S @DATA@("Clinic",1)=""
D ENCODE^XLFJSON(.DATA,.JSONRETURN)
K @DATA
Q
CLINSTA(CLINIEN) ;
N DIV,INST,STA
S DIV=$$GET1^DIQ(44,CLINIEN,3.5,"I")
S INST=$$GET1^DIQ(40.8,DIV,.07,"I")
S STA=$$STA^XUAF4(INST)
Q STA
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2GETCLNSTA 1919 printed Dec 13, 2024@02:53:56 Page 2
SDES2GETCLNSTA ;ALB/BWF - SDES2 GET CLINICS BY STATION; JUL 17,2024
+1 ;;5.3;Scheduling;**886**;Aug 13, 1993;Build 13
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
+6 ; INPUT
+7 ; SDCONTEXT Array
+8 ;
+9 ; SDINPUT("STATION NUMBER") - station number
+10 ; SDINPUT("ACTIVE ONLY") - set to '1' if only active clinics should be included (if nothing is sent, active and inactive clinics are returned)
+11 ;
GETCLINICS(JSONRETURN,SDCONTEXT,SDINPUT) ;
+1 NEW STATION,INST,ERRORS,CNT,DATA,CLINIEN,CLNSTA
+2 SET DATA=$NAME(^TMP("SDES2GETCLNSTA",$JOB,"DATA"))
KILL @DATA
+3 ; validate context
+4 SET JSONRETURN=$NAME(^TMP("SDES2GETCLNSTA",$JOB,"JSON"))
KILL @JSONRETURN
+5 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+6 IF $DATA(ERRORS)
SET ERRORS("Clinic",1)=""
DO ENCODE^XLFJSON("ERRORS",.JSONRETURN)
QUIT
+7 ; validate SDINPUT
+8 IF $DATA(SDINPUT("ACTIVE ONLY"))
IF $GET(SDINPUT("ACTIVE ONLY"))'=1
DO ERRLOG^SDES2JSON(.ERRORS,52,"Invalid 'ACTIVE ONLY' flag.")
+9 SET STATION=$GET(SDINPUT("STATION NUMBER"))
+10 IF STATION=""
DO ERRLOG^SDES2JSON(.ERRORS,196)
+11 SET INST=$$IEN^XUAF4(STATION)
+12 IF STATION]""
IF 'INST
DO ERRLOG^SDES2JSON(.ERRORS,197)
+13 IF $DATA(ERRORS)
SET ERRORS("Clinic",1)=""
DO ENCODE^XLFJSON("ERRORS",.JSONRETURN)
QUIT
+14 ;
+15 SET (CLINIEN,CNT)=0
+16 FOR
SET CLINIEN=$ORDER(^SC(CLINIEN))
if 'CLINIEN
QUIT
Begin DoDot:1
+17 if $$GET1^DIQ(44,CLINIEN,2,"I")'="C"
QUIT
+18 SET CLNSTA=$$CLINSTA(CLINIEN)
if CLNSTA=""
QUIT
+19 IF $LENGTH(STATION)=3
IF +CLNSTA'=STATION
QUIT
+20 IF $LENGTH(STATION)>3
IF CLNSTA'=STATION
QUIT
+21 IF $GET(SDINPUT("ACTIVE ONLY"))
if $$INACTIVE^SDES2UTIL(CLINIEN,DT)
QUIT
+22 SET CNT=CNT+1
+23 SET @DATA@("Clinic",CNT,"ClinicIen")=CLINIEN
+24 SET @DATA@("Clinic",CNT,"ResourceIen")=$ORDER(^SDEC(409.831,"ALOC",CLINIEN,0))
+25 SET @DATA@("Clinic",CNT,"Name")=$$GET1^DIQ(44,CLINIEN,.01,"E")
End DoDot:1
+26 IF '$DATA(@DATA)
SET @DATA@("Clinic",1)=""
+27 DO ENCODE^XLFJSON(.DATA,.JSONRETURN)
+28 KILL @DATA
+29 QUIT
CLINSTA(CLINIEN) ;
+1 NEW DIV,INST,STA
+2 SET DIV=$$GET1^DIQ(44,CLINIEN,3.5,"I")
+3 SET INST=$$GET1^DIQ(40.8,DIV,.07,"I")
+4 SET STA=$$STA^XUAF4(INST)
+5 QUIT STA