SDES2SEARCHCLNAT ;ALB/BLB - SDES2 SEARCH CLINIC ATTRIBUTES;Nov 3, 2023@8:11
;;5.3;Scheduling;**866**;Aug 13, 1993;Build 22
;;Per VHA Directive 6402, this routine should not be modified
;
; Reference to INSTITUTION in ICR #10090
Q
;
SEARCH(JSON,SDCONTEXT,SEARCH) ;
N SEARCHRESULTS,ERRORS
;
D VALIDATE(.ERRORS,.SDCONTEXT,$G(SEARCH("SEARCHSTRING")),$G(SEARCH("STATION")),$G(SEARCH("DATETIME")),$G(SEARCH("RETURNACTIVE")),$G(SEARCH("LENGTH OF APPOINTMENT")))
I $D(ERRORS) S ERRORS("Clinic",1)="" D BUILDJSON^SDESBUILDJSON(.JSON,.ERRORS) Q
;
D SEARCHCLINICS(.SEARCHRESULTS,$G(SEARCH("SEARCHSTRING")),$S($G(SEARCH("DATETIME")):$$ISOTFM^SDAMUTDT(SEARCH("DATETIME")),1:DT),$G(SEARCH("STATION")),$G(SEARCH("LENGTH OF APPOINTMENT")),$G(SEARCH("RETURNACTIVE")))
D BUILDJSON^SDESBUILDJSON(.JSON,.SEARCHRESULTS)
Q
;
SEARCHCLINICS(SEARCHRESULTS,SEARCHSTRING,DATE,STATIONNUMBER,APPTLENGTH,ACTIVE) ;
N CLINICIEN,CLINICIEN,COUNT,STRING2SEARCH
;
I ACTIVE="" S ACTIVE=0
;
S COUNT=0
S STRING2SEARCH=$S($L($$GETSUB^SDES2UTIL(SEARCHSTRING)):$$GETSUB^SDES2UTIL(SEARCHSTRING),1:0)
F S STRING2SEARCH=$O(^SC("B",STRING2SEARCH)) Q:STRING2SEARCH=""!(STRING2SEARCH'[SEARCHSTRING) D
.S CLINICIEN=0
.F S CLINICIEN=$O(^SC("B",STRING2SEARCH,CLINICIEN)) Q:'CLINICIEN D
..;
..; filter by active status
..I ACTIVE=0,$$INACTIVE^SDESUTIL(CLINICIEN,DATE) Q
..;
..; filter by station number
..I STATIONNUMBER'="",$$GET1^DIQ(4,$$GET1^DIQ(40.8,$$GET1^DIQ(44,CLINICIEN,3.5,"I"),.07,"I"),99,"I")'[STATIONNUMBER Q
..;
..; filter by appointment length
..I APPTLENGTH,APPTLENGTH'=$$GET1^DIQ(44,CLINICIEN,1912,"I") Q
..;
..S COUNT=COUNT+1
..D POPULATE(.SEARCHRESULTS,CLINICIEN,.COUNT)
I '$D(SEARCHRESULTS("Clinic")) S SEARCHRESULTS("Clinic")=""
Q
;
POPULATE(SEARCHRESULTS,CLINICIEN,COUNT) ;
N CLINICATTRIBUTES,PROVIDERCOUNT,PROVIDERIEN,RESOURCETYPE,PROVIDERSUBIEN
;
D GETS^DIQ(44,CLINICIEN_",",".01;1;8;16;60;2502;2503","IE","CLINICATTRIBUTES")
;
S SEARCHRESULTS("Clinic",COUNT,"Abbreviation")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",1,"E"))
S SEARCHRESULTS("Clinic",COUNT,"ClinicIEN")=CLINICIEN
S SEARCHRESULTS("Clinic",COUNT,"ClinicAppointmentLength")=$$GET1^DIQ(44,CLINICIEN,1912,"I")
S SEARCHRESULTS("Clinic",COUNT,"ClinicName")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",.01,"E"))
S SEARCHRESULTS("Clinic",COUNT,"ClinicStatus")=$S($$INACTIVE^SDESUTIL(CLINICIEN,DATE)=1:"Inactive",1:"Active")
S SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeIEN")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"I"))
S SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeName")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"E"))
S SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeAMIS")=$$GET1^DIQ(40.7,$G(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"I")),1,"I")
S SEARCHRESULTS("Clinic",COUNT,"PatientFriendlyName")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",60,"E"))
S SEARCHRESULTS("Clinic",COUNT,"StopCodeIEN")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",8,"I"))
S SEARCHRESULTS("Clinic",COUNT,"StopCodeName")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",8,"E"))
S SEARCHRESULTS("Clinic",COUNT,"StopCodeAMIS")=$$GET1^DIQ(40.7,$G(CLINICATTRIBUTES(44,CLINICIEN_",",8,"I")),1,"I")
S SEARCHRESULTS("Clinic",COUNT,"NonCountClinic")=$G(CLINICATTRIBUTES(44,CLINICIEN_",",2502,"E"))
S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderIEN")=""
S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderName")=""
S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderSecID")=""
;
S PROVIDERSUBIEN=0,PROVIDERCOUNT=0
F S PROVIDERSUBIEN=$O(^SC(CLINICIEN,"PR",PROVIDERSUBIEN)) Q:'PROVIDERSUBIEN D
.S PROVIDERIEN=$$GET1^DIQ(44.1,PROVIDERSUBIEN_","_CLINICIEN_",",.01,"I")
.;
.I $$GET1^DIQ(44.1,PROVIDERSUBIEN_","_CLINICIEN_",",.02,"I") D Q
..S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderIEN")=PROVIDERIEN
..S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderName")=$$GET1^DIQ(200,PROVIDERIEN,.01,"E")
..S SEARCHRESULTS("Clinic",COUNT,"DefaultProviderSecID")=$$GET1^DIQ(200,PROVIDERIEN,205.1,"I")
.;
.S PROVIDERCOUNT=PROVIDERCOUNT+1
.S SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"ID")=PROVIDERIEN
.S SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"Name")=$$GET1^DIQ(200,PROVIDERIEN,.01,"E")
.S SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"SecID")=$$GET1^DIQ(200,PROVIDERIEN,205.1,"I")
; set empty object if no records are found
I '$D(SEARCHRESULTS("Clinic",COUNT,"Providers")) S SEARCHRESULTS("Clinic",COUNT,"Providers",1)=""
Q
;
VALIDATE(ERRORS,SDCONTEXT,SEARCHSTRING,STATIONNUMBER,DATE,ACTIVE,APPTLENGTH) ;
;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT) I $D(ERRORS) Q
;
I APPTLENGTH D
.I APPTLENGTH<10!(APPTLENGTH>240) D ERRLOG^SDESJSON(.ERRORS,116) Q
.I APPTLENGTH#15'=0,(APPTLENGTH#10'=0) D ERRLOG^SDESJSON(.ERRORS,116) Q
;
I ($L(SEARCHSTRING)<2)!($L(SEARCHSTRING)>30) D ERRLOG^SDESJSON(.ERRORS,473) Q
;
I STATIONNUMBER'="",'$D(^DIC(4,"D",STATIONNUMBER)) D ERRLOG^SDESJSON(.ERRORS,197) Q
;
I DATE'="" S DATE=$$ISOTFM^SDAMUTDT(DATE) I DATE=-1 D ERRLOG^SDESJSON(.ERRORS,244) Q
;
I ACTIVE'="",ACTIVE'=0,ACTIVE'=1 D ERRLOG^SDESJSON(.ERRORS,518)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2SEARCHCLNAT 5127 printed Nov 22, 2024@18:04:32 Page 2
SDES2SEARCHCLNAT ;ALB/BLB - SDES2 SEARCH CLINIC ATTRIBUTES;Nov 3, 2023@8:11
+1 ;;5.3;Scheduling;**866**;Aug 13, 1993;Build 22
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; Reference to INSTITUTION in ICR #10090
+5 QUIT
+6 ;
SEARCH(JSON,SDCONTEXT,SEARCH) ;
+1 NEW SEARCHRESULTS,ERRORS
+2 ;
+3 DO VALIDATE(.ERRORS,.SDCONTEXT,$GET(SEARCH("SEARCHSTRING")),$GET(SEARCH("STATION")),$GET(SEARCH("DATETIME")),$GET(SEARCH("RETURNACTIVE")),$GET(SEARCH("LENGTH OF APPOINTMENT")))
+4 IF $DATA(ERRORS)
SET ERRORS("Clinic",1)=""
DO BUILDJSON^SDESBUILDJSON(.JSON,.ERRORS)
QUIT
+5 ;
+6 DO SEARCHCLINICS(.SEARCHRESULTS,$GET(SEARCH("SEARCHSTRING")),$SELECT($GET(SEARCH("DATETIME")):$$ISOTFM^SDAMUTDT(SEARCH("DATETIME")),1:DT),$GET(SEARCH("STATION")),$GET(SEARCH("LENGTH OF APPOINTMENT")),$GET(SEARCH("RETURNACTIVE")))
+7 DO BUILDJSON^SDESBUILDJSON(.JSON,.SEARCHRESULTS)
+8 QUIT
+9 ;
SEARCHCLINICS(SEARCHRESULTS,SEARCHSTRING,DATE,STATIONNUMBER,APPTLENGTH,ACTIVE) ;
+1 NEW CLINICIEN,CLINICIEN,COUNT,STRING2SEARCH
+2 ;
+3 IF ACTIVE=""
SET ACTIVE=0
+4 ;
+5 SET COUNT=0
+6 SET STRING2SEARCH=$SELECT($LENGTH($$GETSUB^SDES2UTIL(SEARCHSTRING)):$$GETSUB^SDES2UTIL(SEARCHSTRING),1:0)
+7 FOR
SET STRING2SEARCH=$ORDER(^SC("B",STRING2SEARCH))
if STRING2SEARCH=""!(STRING2SEARCH'[SEARCHSTRING)
QUIT
Begin DoDot:1
+8 SET CLINICIEN=0
+9 FOR
SET CLINICIEN=$ORDER(^SC("B",STRING2SEARCH,CLINICIEN))
if 'CLINICIEN
QUIT
Begin DoDot:2
+10 ;
+11 ; filter by active status
+12 IF ACTIVE=0
IF $$INACTIVE^SDESUTIL(CLINICIEN,DATE)
QUIT
+13 ;
+14 ; filter by station number
+15 IF STATIONNUMBER'=""
IF $$GET1^DIQ(4,$$GET1^DIQ(40.8,$$GET1^DIQ(44,CLINICIEN,3.5,"I"),.07,"I"),99,"I")'[STATIONNUMBER
QUIT
+16 ;
+17 ; filter by appointment length
+18 IF APPTLENGTH
IF APPTLENGTH'=$$GET1^DIQ(44,CLINICIEN,1912,"I")
QUIT
+19 ;
+20 SET COUNT=COUNT+1
+21 DO POPULATE(.SEARCHRESULTS,CLINICIEN,.COUNT)
End DoDot:2
End DoDot:1
+22 IF '$DATA(SEARCHRESULTS("Clinic"))
SET SEARCHRESULTS("Clinic")=""
+23 QUIT
+24 ;
POPULATE(SEARCHRESULTS,CLINICIEN,COUNT) ;
+1 NEW CLINICATTRIBUTES,PROVIDERCOUNT,PROVIDERIEN,RESOURCETYPE,PROVIDERSUBIEN
+2 ;
+3 DO GETS^DIQ(44,CLINICIEN_",",".01;1;8;16;60;2502;2503","IE","CLINICATTRIBUTES")
+4 ;
+5 SET SEARCHRESULTS("Clinic",COUNT,"Abbreviation")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",1,"E"))
+6 SET SEARCHRESULTS("Clinic",COUNT,"ClinicIEN")=CLINICIEN
+7 SET SEARCHRESULTS("Clinic",COUNT,"ClinicAppointmentLength")=$$GET1^DIQ(44,CLINICIEN,1912,"I")
+8 SET SEARCHRESULTS("Clinic",COUNT,"ClinicName")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",.01,"E"))
+9 SET SEARCHRESULTS("Clinic",COUNT,"ClinicStatus")=$SELECT($$INACTIVE^SDESUTIL(CLINICIEN,DATE)=1:"Inactive",1:"Active")
+10 SET SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeIEN")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"I"))
+11 SET SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeName")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"E"))
+12 SET SEARCHRESULTS("Clinic",COUNT,"CreditStopCodeAMIS")=$$GET1^DIQ(40.7,$GET(CLINICATTRIBUTES(44,CLINICIEN_",",2503,"I")),1,"I")
+13 SET SEARCHRESULTS("Clinic",COUNT,"PatientFriendlyName")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",60,"E"))
+14 SET SEARCHRESULTS("Clinic",COUNT,"StopCodeIEN")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",8,"I"))
+15 SET SEARCHRESULTS("Clinic",COUNT,"StopCodeName")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",8,"E"))
+16 SET SEARCHRESULTS("Clinic",COUNT,"StopCodeAMIS")=$$GET1^DIQ(40.7,$GET(CLINICATTRIBUTES(44,CLINICIEN_",",8,"I")),1,"I")
+17 SET SEARCHRESULTS("Clinic",COUNT,"NonCountClinic")=$GET(CLINICATTRIBUTES(44,CLINICIEN_",",2502,"E"))
+18 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderIEN")=""
+19 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderName")=""
+20 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderSecID")=""
+21 ;
+22 SET PROVIDERSUBIEN=0
SET PROVIDERCOUNT=0
+23 FOR
SET PROVIDERSUBIEN=$ORDER(^SC(CLINICIEN,"PR",PROVIDERSUBIEN))
if 'PROVIDERSUBIEN
QUIT
Begin DoDot:1
+24 SET PROVIDERIEN=$$GET1^DIQ(44.1,PROVIDERSUBIEN_","_CLINICIEN_",",.01,"I")
+25 ;
+26 IF $$GET1^DIQ(44.1,PROVIDERSUBIEN_","_CLINICIEN_",",.02,"I")
Begin DoDot:2
+27 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderIEN")=PROVIDERIEN
+28 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderName")=$$GET1^DIQ(200,PROVIDERIEN,.01,"E")
+29 SET SEARCHRESULTS("Clinic",COUNT,"DefaultProviderSecID")=$$GET1^DIQ(200,PROVIDERIEN,205.1,"I")
End DoDot:2
QUIT
+30 ;
+31 SET PROVIDERCOUNT=PROVIDERCOUNT+1
+32 SET SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"ID")=PROVIDERIEN
+33 SET SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"Name")=$$GET1^DIQ(200,PROVIDERIEN,.01,"E")
+34 SET SEARCHRESULTS("Clinic",COUNT,"Providers",PROVIDERCOUNT,"SecID")=$$GET1^DIQ(200,PROVIDERIEN,205.1,"I")
End DoDot:1
+35 ; set empty object if no records are found
+36 IF '$DATA(SEARCHRESULTS("Clinic",COUNT,"Providers"))
SET SEARCHRESULTS("Clinic",COUNT,"Providers",1)=""
+37 QUIT
+38 ;
VALIDATE(ERRORS,SDCONTEXT,SEARCHSTRING,STATIONNUMBER,DATE,ACTIVE,APPTLENGTH) ;
+1 ;
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
IF $DATA(ERRORS)
QUIT
+3 ;
+4 IF APPTLENGTH
Begin DoDot:1
+5 IF APPTLENGTH<10!(APPTLENGTH>240)
DO ERRLOG^SDESJSON(.ERRORS,116)
QUIT
+6 IF APPTLENGTH#15'=0
IF (APPTLENGTH#10'=0)
DO ERRLOG^SDESJSON(.ERRORS,116)
QUIT
End DoDot:1
+7 ;
+8 IF ($LENGTH(SEARCHSTRING)<2)!($LENGTH(SEARCHSTRING)>30)
DO ERRLOG^SDESJSON(.ERRORS,473)
QUIT
+9 ;
+10 IF STATIONNUMBER'=""
IF '$DATA(^DIC(4,"D",STATIONNUMBER))
DO ERRLOG^SDESJSON(.ERRORS,197)
QUIT
+11 ;
+12 IF DATE'=""
SET DATE=$$ISOTFM^SDAMUTDT(DATE)
IF DATE=-1
DO ERRLOG^SDESJSON(.ERRORS,244)
QUIT
+13 ;
+14 IF ACTIVE'=""
IF ACTIVE'=0
IF ACTIVE'=1
DO ERRLOG^SDESJSON(.ERRORS,518)
+15 QUIT
+16 ;