SDESCLNSEARCH ;ALB/MGD,BWF - CLINIC NAME SEARCH AND LIMITED DATA RETURN ;JUL 7, 2023
;;5.3;Scheduling;**824,851,861**;Aug 13, 1993;Build 17
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
;External References
;-------------------
; Reference to $$ACTIVPRV^PXAPI is supported by IA #2349
;
; RPC = SDES SEARCH CLINIC ATTRIBUTES
SEARCHCLIN(JSONRETURN,SEARCHSTRING,STATION,DATE) ;Search for clinics and provide return of matches and limited date in JSON STRING
; INPUT
; SEARCHSTRING (Req) = free text string that represents the recall clinic name that will be searched
; STATION (Opt) = Station Number: If present, the search would be limited to matching clinics at the given institution.
; If absent, the search would take place across all divisions/institutions. Example values: 534, 534GB
; DATE (Opt) = Date in ISO 8601 format to use for Clinic Status verification. If not passed in, default to DT.
; OUTPUT - JSONRETURN
; List of Recall Clinics from the RECALL REMINDERS (#403.5) file with the following data.
; Field List:
; 1. Clinic IEN
; 2. Clinic name
; 3. Patient friendly name
; 4. Default provider IEN
; 5. Default Provider name
; 6. Default Provider SECID
; 7. Stop code IEN
; 8. Stop code NAME
; 9. Stop code AMIS
; 10. Credit stop code IEN
; 11. Credit stop code name
; 12. Credit stop code AMIS
; 13. Status (Active or Inactive) If not passed in, default to DT
; 14. Non-count (Y or N)
;
N CLINICLIST,ERROREXISTS,ERRORLIST,CLINICLIST
K JSONRETURN
S SEARCHSTRING=$G(SEARCHSTRING),STATION=$G(STATION),DATE=$G(DATE)
S ERROREXISTS=0
S ERROREXISTS=$$VALIDATEINPUT(.ERRORLIST,SEARCHSTRING,STATION,.DATE)
I ERROREXISTS S ERRORLIST("Clinic",1)="" D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.ERRORLIST) Q
D GETCLINICLIST(SEARCHSTRING,STATION,DATE,.CLINICLIST)
D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.CLINICLIST)
Q
;
VALIDATEINPUT(ERRORLIST,SEARCHSTRING,STATION,DATE) ; validate incoming parameters
; input - ERRORLIST = passed in by reference, represents the errors that could be generated when validating the searchstring
; SEARCHSTRING = represents the name or partial name of the Recall Clinic
; STATION = Station Number
; returns 0 or 1
; 0 = no validation errors
; 1 = validation errors
N NOMATCHFOUND,INACTIVEONDATE
S (NOMATCHFOUND,INACTIVEONDATE)=0
S SEARCHSTRING=$TR(SEARCHSTRING,$C(13)_$C(10)_$C(9),"")
I ($L(SEARCHSTRING)<2)!($L(SEARCHSTRING)>30) D Q 1
. D ERRLOG^SDESJSON(.ERRORLIST,473)
I STATION'="",(($L(STATION)<3)!($L(STATION)>7)) D Q 1
. D ERRLOG^SDESJSON(.ERRORLIST,197)
I STATION'="" D Q:NOMATCHFOUND 1
. D FIND^DIC(4,,"@;99","X",STATION,,"D",,,"RESULTS")
. I '$D(RESULTS("DILIST",2)) D
. . S NOMATCHFOUND=1
. . D ERRLOG^SDESJSON(.ERRORLIST,197)
I DATE="" S DATE=DT
I DATE'="",DATE'?7N S DATE=$$ISOTFM^SDAMUTDT(DATE,"")
I DATE=-1 D ERRLOG^SDESJSON(.ERRORLIST,244) Q 1
Q 0
;
GETCLINICLIST(SEARCHSTRING,STATION,DATE,CLINICLIST) ; pull matching recall clinics using the first input parameter passed in by the RPC
; Input - SEARCHSTRING = string that represents the name of the recall clinic
; STATION = Station Number
; DATE = Fileman Date to use for Clinic Status verification
; CLINICLIST = passed in by reference; represents the array that will be returned as output
; Output - CLINICLIST = list of recall clinic names, clinic IENs and the associated recall reminder IENs.
N CLINCNT,RESULTS,SUB3
K CLINICLIST
S (SUB3,CLINCNT)=0
D FIND^DIC(44,,"@;.01",,SEARCHSTRING,,"B^C",,,"RESULTS")
F S SUB3=$O(RESULTS("DILIST",2,SUB3)) Q:SUB3="" D
. S CLINICIEN=$G(RESULTS("DILIST",2,SUB3))
. I STATION'="" Q:$$WRONGDIVISION(CLINICIEN,STATION)
. Q:$$INACTIVE^SDESUTIL(CLINICIEN,DATE)
. S CLINCNT=CLINCNT+1
. I CLINICIEN D BUILDRETURN(CLINICIEN,CLINCNT,.CLINICLIST)
I CLINCNT=0 S CLINICLIST("Clinic",1)=""
Q
;
BUILDRETURN(CLINICIEN,CLINCNT,CLINICLIST) ;Build return array with recall reminder clinic data
; input - CLINICIEN = IEN of clinic in #44
; CLINICLIST = passed by reference, represents the array of recall clinics and associated data that will be returned to the client
; output - CLINICLIST = recall clinic array and their associated data to be sent back to the client
;
N STATUS,SDFIELDS,SDDATA,PRVCNT,CLINPROVIDER,PROVIDERID,PROVIDERNAME,DEFAULTPROVIDER,PROVIDERSECID
S SDFIELDS=".01;1;8;16;60;2502;2503"
D GETS^DIQ(44,CLINICIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
S CLINICLIST("Clinic",CLINCNT,"Abbreviation")=$G(SDDATA(44,CLINICIEN_",",1,"E"))
S CLINICLIST("Clinic",CLINCNT,"ClinicIEN")=CLINICIEN
S CLINICLIST("Clinic",CLINCNT,"ClinicName")=$G(SDDATA(44,CLINICIEN_",",.01,"E"))
S CLINICLIST("Clinic",CLINCNT,"PatientFriendlyName")=$G(SDDATA(44,CLINICIEN_",",60,"E"))
; initialize default provider fields to null to ensure they are always defined (in the event no default provider is found)
S CLINICLIST("Clinic",CLINCNT,"DefaultProviderIEN")=""
S CLINICLIST("Clinic",CLINCNT,"DefaultProviderName")=""
S CLINICLIST("Clinic",CLINCNT,"DefaultProviderSecID")=""
S CLINICLIST("Clinic",CLINCNT,"StopCodeIEN")=$G(SDDATA(44,CLINICIEN_",",8,"I"))
S CLINICLIST("Clinic",CLINCNT,"StopCodeName")=$G(SDDATA(44,CLINICIEN_",",8,"E"))
S CLINICLIST("Clinic",CLINCNT,"StopCodeAMIS")=$$GET1^DIQ(40.7,$G(SDDATA(44,CLINICIEN_",",8,"I")),1,"I")
S CLINICLIST("Clinic",CLINCNT,"CreditStopCodeIEN")=$G(SDDATA(44,CLINICIEN_",",2503,"I"))
S CLINICLIST("Clinic",CLINCNT,"CreditStopCodeName")=$G(SDDATA(44,CLINICIEN_",",2503,"E"))
S CLINICLIST("Clinic",CLINCNT,"CreditStopCodeAMIS")=$$GET1^DIQ(40.7,$G(SDDATA(44,CLINICIEN_",",2503,"I")),1,"I")
S CLINICLIST("Clinic",CLINCNT,"NonCountClinic")=$G(SDDATA(44,CLINICIEN_",",2502,"E"))
S STATUS=$$INACTIVE^SDESUTIL(CLINICIEN,DATE),STATUS=$S(STATUS=1:"Inactive",1:"Active")
S CLINICLIST("Clinic",CLINCNT,"ClinicStatus")=STATUS
S PRVCNT=0
S CLINPROVIDER=0 F S CLINPROVIDER=$O(^SC(CLINICIEN,"PR",CLINPROVIDER)) Q:'CLINPROVIDER D
.S PROVIDERID=$$GET1^DIQ(44.1,CLINPROVIDER_","_CLINICIEN_",",.01,"I")
.S PROVIDERNAME=$$GET1^DIQ(200,PROVIDERID,.01,"E")
.S PROVIDERSECID=$$GET1^DIQ(200,PROVIDERID,205.1,"I")
.S DEFAULTPROVIDER=$$GET1^DIQ(44.1,CLINPROVIDER_","_CLINICIEN_",",.02,"I")
.I DEFAULTPROVIDER D Q
..S CLINICLIST("Clinic",CLINCNT,"DefaultProviderIEN")=PROVIDERID
..S CLINICLIST("Clinic",CLINCNT,"DefaultProviderName")=$$GET1^DIQ(200,PROVIDERID,.01,"E")
..S CLINICLIST("Clinic",CLINCNT,"DefaultProviderSecID")=PROVIDERSECID
.S PRVCNT=PRVCNT+1
.S CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"Name")=PROVIDERNAME
.S CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"ID")=PROVIDERID
.S CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"SecID")=PROVIDERSECID
; set empty object if no records are found
I '$D(CLINICLIST("Clinic",CLINCNT,"Providers")) S CLINICLIST("Clinic",CLINCNT,"Providers",1)=""
Q
;
WRONGDIVISION(CLINICIEN,STATION) ;
; Screen out Clinics that don't match passed in Station Number
N DIVISION,INSTIEN,STATIONID
S DIVISION=$$GET1^DIQ(44,CLINICIEN,3.5,"I")
S INSTIEN=$$GET1^DIQ(40.8,DIVISION,.07,"I")
S STATIONID=$$GET1^DIQ(4,INSTIEN,99,"I")
I STATIONID'[STATION Q 1
Q 0
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESCLNSEARCH 7238 printed Nov 22, 2024@18:06:09 Page 2
SDESCLNSEARCH ;ALB/MGD,BWF - CLINIC NAME SEARCH AND LIMITED DATA RETURN ;JUL 7, 2023
+1 ;;5.3;Scheduling;**824,851,861**;Aug 13, 1993;Build 17
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
+6 ;External References
+7 ;-------------------
+8 ; Reference to $$ACTIVPRV^PXAPI is supported by IA #2349
+9 ;
+10 ; RPC = SDES SEARCH CLINIC ATTRIBUTES
SEARCHCLIN(JSONRETURN,SEARCHSTRING,STATION,DATE) ;Search for clinics and provide return of matches and limited date in JSON STRING
+1 ; INPUT
+2 ; SEARCHSTRING (Req) = free text string that represents the recall clinic name that will be searched
+3 ; STATION (Opt) = Station Number: If present, the search would be limited to matching clinics at the given institution.
+4 ; If absent, the search would take place across all divisions/institutions. Example values: 534, 534GB
+5 ; DATE (Opt) = Date in ISO 8601 format to use for Clinic Status verification. If not passed in, default to DT.
+6 ; OUTPUT - JSONRETURN
+7 ; List of Recall Clinics from the RECALL REMINDERS (#403.5) file with the following data.
+8 ; Field List:
+9 ; 1. Clinic IEN
+10 ; 2. Clinic name
+11 ; 3. Patient friendly name
+12 ; 4. Default provider IEN
+13 ; 5. Default Provider name
+14 ; 6. Default Provider SECID
+15 ; 7. Stop code IEN
+16 ; 8. Stop code NAME
+17 ; 9. Stop code AMIS
+18 ; 10. Credit stop code IEN
+19 ; 11. Credit stop code name
+20 ; 12. Credit stop code AMIS
+21 ; 13. Status (Active or Inactive) If not passed in, default to DT
+22 ; 14. Non-count (Y or N)
+23 ;
+24 NEW CLINICLIST,ERROREXISTS,ERRORLIST,CLINICLIST
+25 KILL JSONRETURN
+26 SET SEARCHSTRING=$GET(SEARCHSTRING)
SET STATION=$GET(STATION)
SET DATE=$GET(DATE)
+27 SET ERROREXISTS=0
+28 SET ERROREXISTS=$$VALIDATEINPUT(.ERRORLIST,SEARCHSTRING,STATION,.DATE)
+29 IF ERROREXISTS
SET ERRORLIST("Clinic",1)=""
DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.ERRORLIST)
QUIT
+30 DO GETCLINICLIST(SEARCHSTRING,STATION,DATE,.CLINICLIST)
+31 DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.CLINICLIST)
+32 QUIT
+33 ;
VALIDATEINPUT(ERRORLIST,SEARCHSTRING,STATION,DATE) ; validate incoming parameters
+1 ; input - ERRORLIST = passed in by reference, represents the errors that could be generated when validating the searchstring
+2 ; SEARCHSTRING = represents the name or partial name of the Recall Clinic
+3 ; STATION = Station Number
+4 ; returns 0 or 1
+5 ; 0 = no validation errors
+6 ; 1 = validation errors
+7 NEW NOMATCHFOUND,INACTIVEONDATE
+8 SET (NOMATCHFOUND,INACTIVEONDATE)=0
+9 SET SEARCHSTRING=$TRANSLATE(SEARCHSTRING,$CHAR(13)_$CHAR(10)_$CHAR(9),"")
+10 IF ($LENGTH(SEARCHSTRING)<2)!($LENGTH(SEARCHSTRING)>30)
Begin DoDot:1
+11 DO ERRLOG^SDESJSON(.ERRORLIST,473)
End DoDot:1
QUIT 1
+12 IF STATION'=""
IF (($LENGTH(STATION)<3)!($LENGTH(STATION)>7))
Begin DoDot:1
+13 DO ERRLOG^SDESJSON(.ERRORLIST,197)
End DoDot:1
QUIT 1
+14 IF STATION'=""
Begin DoDot:1
+15 DO FIND^DIC(4,,"@;99","X",STATION,,"D",,,"RESULTS")
+16 IF '$DATA(RESULTS("DILIST",2))
Begin DoDot:2
+17 SET NOMATCHFOUND=1
+18 DO ERRLOG^SDESJSON(.ERRORLIST,197)
End DoDot:2
End DoDot:1
if NOMATCHFOUND
QUIT 1
+19 IF DATE=""
SET DATE=DT
+20 IF DATE'=""
IF DATE'?7N
SET DATE=$$ISOTFM^SDAMUTDT(DATE,"")
+21 IF DATE=-1
DO ERRLOG^SDESJSON(.ERRORLIST,244)
QUIT 1
+22 QUIT 0
+23 ;
GETCLINICLIST(SEARCHSTRING,STATION,DATE,CLINICLIST) ; pull matching recall clinics using the first input parameter passed in by the RPC
+1 ; Input - SEARCHSTRING = string that represents the name of the recall clinic
+2 ; STATION = Station Number
+3 ; DATE = Fileman Date to use for Clinic Status verification
+4 ; CLINICLIST = passed in by reference; represents the array that will be returned as output
+5 ; Output - CLINICLIST = list of recall clinic names, clinic IENs and the associated recall reminder IENs.
+6 NEW CLINCNT,RESULTS,SUB3
+7 KILL CLINICLIST
+8 SET (SUB3,CLINCNT)=0
+9 DO FIND^DIC(44,,"@;.01",,SEARCHSTRING,,"B^C",,,"RESULTS")
+10 FOR
SET SUB3=$ORDER(RESULTS("DILIST",2,SUB3))
if SUB3=""
QUIT
Begin DoDot:1
+11 SET CLINICIEN=$GET(RESULTS("DILIST",2,SUB3))
+12 IF STATION'=""
if $$WRONGDIVISION(CLINICIEN,STATION)
QUIT
+13 if $$INACTIVE^SDESUTIL(CLINICIEN,DATE)
QUIT
+14 SET CLINCNT=CLINCNT+1
+15 IF CLINICIEN
DO BUILDRETURN(CLINICIEN,CLINCNT,.CLINICLIST)
End DoDot:1
+16 IF CLINCNT=0
SET CLINICLIST("Clinic",1)=""
+17 QUIT
+18 ;
BUILDRETURN(CLINICIEN,CLINCNT,CLINICLIST) ;Build return array with recall reminder clinic data
+1 ; input - CLINICIEN = IEN of clinic in #44
+2 ; CLINICLIST = passed by reference, represents the array of recall clinics and associated data that will be returned to the client
+3 ; output - CLINICLIST = recall clinic array and their associated data to be sent back to the client
+4 ;
+5 NEW STATUS,SDFIELDS,SDDATA,PRVCNT,CLINPROVIDER,PROVIDERID,PROVIDERNAME,DEFAULTPROVIDER,PROVIDERSECID
+6 SET SDFIELDS=".01;1;8;16;60;2502;2503"
+7 DO GETS^DIQ(44,CLINICIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
+8 SET CLINICLIST("Clinic",CLINCNT,"Abbreviation")=$GET(SDDATA(44,CLINICIEN_",",1,"E"))
+9 SET CLINICLIST("Clinic",CLINCNT,"ClinicIEN")=CLINICIEN
+10 SET CLINICLIST("Clinic",CLINCNT,"ClinicName")=$GET(SDDATA(44,CLINICIEN_",",.01,"E"))
+11 SET CLINICLIST("Clinic",CLINCNT,"PatientFriendlyName")=$GET(SDDATA(44,CLINICIEN_",",60,"E"))
+12 ; initialize default provider fields to null to ensure they are always defined (in the event no default provider is found)
+13 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderIEN")=""
+14 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderName")=""
+15 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderSecID")=""
+16 SET CLINICLIST("Clinic",CLINCNT,"StopCodeIEN")=$GET(SDDATA(44,CLINICIEN_",",8,"I"))
+17 SET CLINICLIST("Clinic",CLINCNT,"StopCodeName")=$GET(SDDATA(44,CLINICIEN_",",8,"E"))
+18 SET CLINICLIST("Clinic",CLINCNT,"StopCodeAMIS")=$$GET1^DIQ(40.7,$GET(SDDATA(44,CLINICIEN_",",8,"I")),1,"I")
+19 SET CLINICLIST("Clinic",CLINCNT,"CreditStopCodeIEN")=$GET(SDDATA(44,CLINICIEN_",",2503,"I"))
+20 SET CLINICLIST("Clinic",CLINCNT,"CreditStopCodeName")=$GET(SDDATA(44,CLINICIEN_",",2503,"E"))
+21 SET CLINICLIST("Clinic",CLINCNT,"CreditStopCodeAMIS")=$$GET1^DIQ(40.7,$GET(SDDATA(44,CLINICIEN_",",2503,"I")),1,"I")
+22 SET CLINICLIST("Clinic",CLINCNT,"NonCountClinic")=$GET(SDDATA(44,CLINICIEN_",",2502,"E"))
+23 SET STATUS=$$INACTIVE^SDESUTIL(CLINICIEN,DATE)
SET STATUS=$SELECT(STATUS=1:"Inactive",1:"Active")
+24 SET CLINICLIST("Clinic",CLINCNT,"ClinicStatus")=STATUS
+25 SET PRVCNT=0
+26 SET CLINPROVIDER=0
FOR
SET CLINPROVIDER=$ORDER(^SC(CLINICIEN,"PR",CLINPROVIDER))
if 'CLINPROVIDER
QUIT
Begin DoDot:1
+27 SET PROVIDERID=$$GET1^DIQ(44.1,CLINPROVIDER_","_CLINICIEN_",",.01,"I")
+28 SET PROVIDERNAME=$$GET1^DIQ(200,PROVIDERID,.01,"E")
+29 SET PROVIDERSECID=$$GET1^DIQ(200,PROVIDERID,205.1,"I")
+30 SET DEFAULTPROVIDER=$$GET1^DIQ(44.1,CLINPROVIDER_","_CLINICIEN_",",.02,"I")
+31 IF DEFAULTPROVIDER
Begin DoDot:2
+32 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderIEN")=PROVIDERID
+33 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderName")=$$GET1^DIQ(200,PROVIDERID,.01,"E")
+34 SET CLINICLIST("Clinic",CLINCNT,"DefaultProviderSecID")=PROVIDERSECID
End DoDot:2
QUIT
+35 SET PRVCNT=PRVCNT+1
+36 SET CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"Name")=PROVIDERNAME
+37 SET CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"ID")=PROVIDERID
+38 SET CLINICLIST("Clinic",CLINCNT,"Providers",PRVCNT,"SecID")=PROVIDERSECID
End DoDot:1
+39 ; set empty object if no records are found
+40 IF '$DATA(CLINICLIST("Clinic",CLINCNT,"Providers"))
SET CLINICLIST("Clinic",CLINCNT,"Providers",1)=""
+41 QUIT
+42 ;
WRONGDIVISION(CLINICIEN,STATION) ;
+1 ; Screen out Clinics that don't match passed in Station Number
+2 NEW DIVISION,INSTIEN,STATIONID
+3 SET DIVISION=$$GET1^DIQ(44,CLINICIEN,3.5,"I")
+4 SET INSTIEN=$$GET1^DIQ(40.8,DIVISION,.07,"I")
+5 SET STATIONID=$$GET1^DIQ(4,INSTIEN,99,"I")
+6 IF STATIONID'[STATION
QUIT 1
+7 QUIT 0