SDESRTVCLN2 ;ALB/MGD,ANU,LAB,MGD,ANU,JAS,LAB,DJS,JAS,LAB,BWF - Get Clinic Info based on Clinic IEN ;DEC 5, 2023
;;5.3;Scheduling;**823,825,827,828,833,836,851,864,867,871**;Aug 13, 1993;Build 13
;;Per VHA Directive 6402, this routine should not be modified
;
; Documented API's and Integration Agreements
; -------------------------------------------
; Reference to $$GETS^DIQ is supported by IA #2056
; Reference to $$GETS1^DIQ is supported by IA #2056
;
; copy of SDESRTVCLN
Q
;
JSONCLNINFO(RETSDCLNJSON,SDCLNIEN,SDEAS,HASHFLG) ;Get Clinic info
;INPUT - SDCLNIEN (Clinic IEN)
; - SDEAS [optional] - Enterprise Appointment Scheduling (EAS) Tracking Number associated to an appointment.
; - HASHFLG - Flag to update hash value for clinic or not (0 - no (default), 1- yes )
;RETURN PARAMETER:
;
;{"Clinic": {
;"Abbreviation": "STPDN-M",
;"AdminInpatientMeds": "",
;"AllowPatScheduling": "",
;"AllowableConsecutiveNoShows": "",
;"ApptCancelLetter": "",
;"CHAR4": "",
;"CancelLetter": "",
;"CheckinCheckoutTime": "",
;"ClinicIEN": 2174,
;"ClinicName": "STPDN-M",
;"ClinicStatus": "ACTIVE" or "INACTIVE"
;"CreditStopCodeAMISNum": "",
;"CreditStopCodeName": "",
;"CreditStopCodeNum": "",
;"DefaultApptType": "",
;"DefaultToPCPractitioner": "",
;"DisplayClinicAppt": "",
;"DivisionIEN": 1,
;"DivisionName": "CHEYENNE VAMROC",
;"ECheckinAllowed": "",
;"Hash": "F712AC20443E444B4CBF3ECD95AA3B2706BC2964",
;"HolidaySchedule": "",
;"HourClinicDisplayBegins": 8,
;"Inactivate Date": "",
;"IncrementsPerHr": "",
;"LastHashTimestamp": 3220901.160618,
;"LengthOfAppt": "",
;"MaxDaysForFutureBooking": "",
;"MeetsAtThisFacility": "",
;"NoShowLetter": "",
;"NoShowLetterIEN": "",
;"NonCountClinic": "",
;"OverbooksPerDayMax": "",
;"PatientFriendlyName": "",
;"PhysicalLocation": "",
;"PreApptLetter": "",
;"PreCheckinAllowed": "",
;"Principal": "",
;"ProhibitAccessToClinic": "",
;"Provider": {
; "DefaultForClinic": "",
; "IEN": "",
; "Name": ""},
;"Reactivate Date": "",
;"ReqActionProfiles": "",
;"ReqXrayFilms": "",
;"Service": "",
;"StationNumber": 442,
;"StopCodeAMISNum": "",
;"StopCodeName": "",
;"StopCodeNum": "",
;"Telephone": "",
;"TelephoneExtension": "",
;"Timezone": "EASTERN",
;"TimezoneException": 1,
;"VariableApptLength": "",
;"WorkloadValidationCheckout": ""}}
;
N RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN,SDECI,ERRORS,SDCLNJSON
S (RETURN,ELGFIELDSARRAY,HASFIELDS)=""
;
D VALIDATECLINIC(.ERRORS,$G(SDCLNIEN))
D VALIDATEEAS(.ERRORS,$G(SDEAS))
D VALIDATEHASHFLG(.ERRORS,.HASHFLG)
;
I $D(ERRORS) M RETURN=ERRORS
I '$D(ERRORS) S HASFIELDS=$$BLDCLNREC(.ELGFIELDSARRAY,SDCLNIEN)
I HASFIELDS M RETURN=ELGFIELDSARRAY
;
D BUILDJSON^SDESBUILDJSON(.SDCLNJSON,.RETURN) ;build json without hash
I $D(ERRORS) M RETSDCLNJSON=SDCLNJSON
I HASFIELDS D
.D ADDHASH(SDCLNIEN,.ELGFIELDSARRAY,.SDCLNJSON,HASHFLG)
.K RETURN
.M RETURN=ELGFIELDSARRAY
.D BUILDJSON^SDESBUILDJSON(.RETSDCLNJSON,.RETURN) ;json includes hash
D CLEANUP
Q
;
ADDHASH(CLIN,ELGFIELDSARRAY,SDCLNJSON,HASHFLG) ;Add hash to output
NEW HASH,HASHDATE
D:HASHFLG UPDATECLINICHASH(CLIN,.HASH,.HASHDATE,.SDCLNJSON)
S HASH=$$GET1^DIQ(44,SDCLNIEN_",",2900)
S HASHDATE=$$FMTISO^SDAMUTDT($$GET1^DIQ(44,CLIN,2901,"I"),CLIN)
S ELGFIELDSARRAY("Clinic","LastHashTimestamp")=HASHDATE
S ELGFIELDSARRAY("Clinic","Hash")=HASH
Q
;
UPDATECLINICHASH(CLIN,HASH,HASHDATE,SDCLNJSON) ;update clinic with new hash
N FDA,FDAERR
S HASH=$$SHAN^XLFSHAN(160,SDCLNJSON(1))
S HASHDATE=$$NOW^XLFDT
S FDA(44,CLIN_",",2900)=HASH
S FDA(44,CLIN_",",2901)=HASHDATE
D FILE^DIE(,"FDA","FDAERR") K FDA
Q
;
ADDHASH2CLIN(IEN) ; add HASH to clinic after creation of clinic
N HASH,HASHDATE,SDCLNJSON,SDCLNSREC
D BLDCLNREC(.SDCLNSREC,IEN)
D BUILDJSON^SDESBUILDJSON(.SDCLNJSON,.SDCLNSREC)
D UPDATECLINICHASH(IEN,.HASH,.HASHDATE,.SDCLNJSON)
Q
;
VALIDATECLINIC(ERRORS,CLINIC) ;
I CLINIC="" D ERRLOG^SDESJSON(.ERRORS,18)
I CLINIC'="",'$D(^SC(CLINIC,0)) D ERRLOG^SDESJSON(.ERRORS,19)
Q
;
VALIDATEEAS(ERRORS,EAS) ;
I $L(EAS) S EAS=$$EASVALIDATE^SDESUTIL($G(EAS))
I $P($G(EAS),U)=-1 D ERRLOG^SDESJSON(.ERRORS,142) Q
Q
;
VALIDATEHASHFLG(ERRORS,HASHFLG) ;
S HASHFLG=$SELECT($G(HASHFLG)="":0,1:HASHFLG)
I (HASHFLG'=0)&(HASHFLG'=1) D ERRLOG^SDESJSON(.ERRORS,267)
Q
;
BLDCLNREC(SDCLNSREC,SDCLNIEN) ;Get Clinic data
;
N SDFIELDS,SDDATA,SDMSG,SDX,SDC,TIMEZONE,TIMEZONEEXC,USRCNT,USRIEN,STATUS,SDSTATUS,RESIEN
S SDECI=$G(SDECI,0)
S SDFIELDS=".01;1;3.5;8;9;10;24;60;61;62;200;1914;2502;2504;2505;2506;2507;2802;99;99.1;2000;2000.5;2508;2509;2510;2511;2801;30;2001;2002;1918.5;2503;2500;1916;1918;20;21;1912;1913;1917"
D GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
S SDECI=SDECI+1
S SDCLNSREC("Clinic","ClinicIEN")=$G(SDCLNIEN) ;Clinic IEN
S SDCLNSREC("Clinic","ClinicName")=$G(SDDATA(44,SDCLNIEN_",",.01,"E")) ;Clinic Name
S SDCLNSREC("Clinic","Abbreviation")=$G(SDDATA(44,SDCLNIEN_",",1,"E")) ;Clinic Abbreviation
S SDCLNSREC("Clinic","PatientFriendlyName")=$G(SDDATA(44,SDCLNIEN_",",60,"E")) ;Patient Friendly Name
S SDCLNSREC("Clinic","StationNumber")=$$STATIONNUMBER^SDESUTIL(SDCLNIEN) ;Clinic station number
S SDCLNSREC("Clinic","MeetsAtThisFacility")=$G(SDDATA(44,SDCLNIEN_",",2504,"E")) ;Clinic meets at this facility?
S SDCLNSREC("Clinic","AllowPatScheduling")=$G(SDDATA(44,SDCLNIEN_",",61,"E")) ;Allow Direct Patient Scheduling?
S SDCLNSREC("Clinic","DisplayClinicAppt")=$G(SDDATA(44,SDCLNIEN_",",62,"E")) ;DISPLAY CLIN APPT TO PATIENTS?
S SDCLNSREC("Clinic","Service")=$G(SDDATA(44,SDCLNIEN_",",9,"E")) ;Service
S SDCLNSREC("Clinic","NonCountClinic")=$G(SDDATA(44,SDCLNIEN_",",2502,"E")) ;NON-COUNT CLINIC? (Y OR N)
S SDCLNSREC("Clinic","DivisionIEN")=$G(SDDATA(44,SDCLNIEN_",",3.5,"I")) ;Division
S SDCLNSREC("Clinic","DivisionName")=$G(SDDATA(44,SDCLNIEN_",",3.5,"E")) ;Division
S STATUS=$$INACTIVE^SDESUTIL(SDCLNIEN,DT),SDSTATUS=$S(STATUS=0:"ACTIVE",1:"INACTIVE") ;Get status of clinic
S SDCLNSREC("Clinic","ClinicStatus")=SDSTATUS
S SDCLNSREC("Clinic","StopCodeName")=$G(SDDATA(44,SDCLNIEN_",",8,"E")) ;Stop Code Name
S SDCLNSREC("Clinic","StopCodeNum")=$G(SDDATA(44,SDCLNIEN_",",8,"I")) ;Stop Code IEN
S SDCLNSREC("Clinic","StopCodeAMISNum")=$$GET1^DIQ(40.7,$G(SDDATA(44,SDCLNIEN_",",8,"I")),1) ;Stop Code AMIS Number
S SDCLNSREC("Clinic","DefaultApptType")=$G(SDDATA(44,SDCLNIEN_",",2507,"E")) ;Default Appointment type
S SDCLNSREC("Clinic","AdminInpatientMeds")=$G(SDDATA(44,SDCLNIEN_",",2802,"E")) ;ADMINISTER INPATIENT MEDS?
S SDCLNSREC("Clinic","Telephone")=$G(SDDATA(44,SDCLNIEN_",",99,"E")) ;TELEPHONE
S SDCLNSREC("Clinic","TelephoneExtension")=$G(SDDATA(44,SDCLNIEN_",",99.1,"E")) ;TELEPHONE Extension
S SDCLNSREC("Clinic","ReqXrayFilms")=$G(SDDATA(44,SDCLNIEN_",",2000,"E")) ;REQUIRE X-RAY FILMS?
S SDCLNSREC("Clinic","ReqActionProfiles")=$G(SDDATA(44,SDCLNIEN_",",2000.5,"E")) ;REQUIRE ACTION PROFILES?
S SDCLNSREC("Clinic","NoShowLetter")=$G(SDDATA(44,SDCLNIEN_",",2508,"E")) ;NO SHOW LETTER
S SDCLNSREC("Clinic","NoShowLetterIEN")=$G(SDDATA(44,SDCLNIEN_",",2508,"I")) ;NO SHOW IEN
S SDCLNSREC("Clinic","PreApptLetter")=$G(SDDATA(44,SDCLNIEN_",",2509,"E")) ;PRE-APPOINTMENT LETTER
S SDCLNSREC("Clinic","CancelLetter")=$G(SDDATA(44,SDCLNIEN_",",2510,"E")) ;CLINIC CANCELLATION LETTER
S SDCLNSREC("Clinic","ApptCancelLetter")=$G(SDDATA(44,SDCLNIEN_",",2511,"E")) ;APPT. CANCELLATION LETTER
S SDCLNSREC("Clinic","CheckinCheckoutTime")=$G(SDDATA(44,SDCLNIEN_",",24,"E")) ;ASK FOR CHECK IN/OUT TIME
S SDCLNSREC("Clinic","DefaultToPCPractitioner")=$G(SDDATA(44,SDCLNIEN_",",2801,"E")) ;DEFAULT TO PC PRACTITIONER?
S SDCLNSREC("Clinic","WorkloadValidationCheckout")=$G(SDDATA(44,SDCLNIEN_",",30,"E")) ;WORKLOAD VALIDATION AT CHK OUT
S SDCLNSREC("Clinic","AllowableConsecutiveNoShows")=$G(SDDATA(44,SDCLNIEN_",",2001,"E")) ;ALLOWABLE CONSECUTIVE NO-SHOWS
S SDCLNSREC("Clinic","MaxDaysForFutureBooking")=$G(SDDATA(44,SDCLNIEN_",",2002,"E")) ;MAX # DAYS FOR FUTURE BOOKING
S SDCLNSREC("Clinic","HolidaySchedule")=$G(SDDATA(44,SDCLNIEN_",",1918.5,"E")) ;SCHEDULE ON HOLIDAYS?
S SDCLNSREC("Clinic","CreditStopCodeNum")=$G(SDDATA(44,SDCLNIEN_",",2503,"I")) ;CREDIT STOP IEN
S SDCLNSREC("Clinic","CreditStopCodeName")=$G(SDDATA(44,SDCLNIEN_",",2503,"E")) ;CREDIT STOP NAME
S SDCLNSREC("Clinic","CreditStopCodeAMISNum")=$$GET1^DIQ(40.7,$G(SDDATA(44,SDCLNIEN_",",2503,"I")),1) ;Credit Stop Code AMIS Number
S SDCLNSREC("Clinic","ProhibitAccessToClinic")=$G(SDDATA(44,SDCLNIEN_",",2500,"E")) ;PROHIBIT ACCESS TO CLINIC?
S SDCLNSREC("Clinic","PhysicalLocation")=$G(SDDATA(44,SDCLNIEN_",",10,"E")) ;PHYSICAL LOCATION
S SDCLNSREC("Clinic","Principal")=$G(SDDATA(44,SDCLNIEN_",",1916,"E")) ;PRINCIPAL Clinic
S SDCLNSREC("Clinic","OverbooksPerDayMax")=$G(SDDATA(44,SDCLNIEN_",",1918,"E")) ;OVERBOOKS/DAY MAXIMUM
S SDCLNSREC("Clinic","ECheckinAllowed")=$G(SDDATA(44,SDCLNIEN_",",20,"E")) ;E-CHECKIN ALLOWED
S SDCLNSREC("Clinic","PreCheckinAllowed")=$G(SDDATA(44,SDCLNIEN_",",21,"E")) ;PRE-CHECKIN ALLOWED NO
S SDCLNSREC("Clinic","LengthOfAppt")=$G(SDDATA(44,SDCLNIEN_",",1912,"E")) ;LENGTH OF APP'T
S SDCLNSREC("Clinic","VariableApptLength")=$G(SDDATA(44,SDCLNIEN_",",1913,"E")) ;VARIABLE APP'NTMENT LENGTH
S SDCLNSREC("Clinic","IncrementsPerHr")=$G(SDDATA(44,SDCLNIEN_",",1917,"E")) ;DISPLAY INCREMENTS PER HOUR
S SDCLNSREC("Clinic","HourClinicDisplayBegins")=$S($G(SDDATA(44,SDCLNIEN_",",1914,"E"))'="":$G(SDDATA(44,SDCLNIEN_",",1914,"E")),1:8) ; HOUR CLINIC DISPLAY BEGINS
S TIMEZONE=$$TIMEZONEDATA^SDESUTIL($G(SDCLNIEN)),TIMEZONEEXC=$P($G(TIMEZONE),U,3),TIMEZONE=$P($G(TIMEZONE),U)
S SDCLNSREC("Clinic","Timezone")=TIMEZONE
S SDCLNSREC("Clinic","TimezoneException")=TIMEZONEEXC
S SDCLNSREC("Clinic","Inactivate Date")=$$FMTISO^SDAMUTDT($G(SDDATA(44,SDCLNIEN_",",2505,"I"))) ;Inactivate Date
S SDCLNSREC("Clinic","Reactivate Date")=$$FMTISO^SDAMUTDT($G(SDDATA(44,SDCLNIEN_",",2506,"I"))) ;Reactivate Date
S SDCLNSREC("Clinic","PbspID")=$G(SDDATA(44,SDCLNIEN_",",200,"E"))
; Get CHAR4 Data
N CHAR4
S CHAR4=$$CHAR4^SDESUTIL($G(SDDATA(44,SDCLNIEN_",",.01,"E")))
S SDCLNSREC("Clinic","CHAR4")=CHAR4
; Special Instructions Multiple
S SDX="",SDC=0
S SDFIELDS="1910*"
K SDDATA,SDMSG
D GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"E","SDDATA","SDMSG")
F S SDX=$O(SDDATA(44.03,SDX)) Q:SDX="" D
. S SDC=SDC+1
. S SDCLNSREC("Clinic","Special Instructions",SDC)=$G(SDDATA(44.03,SDX,.01,"E"))
; Providers Multiple
S SDX="",SDC=0
S SDFIELDS="2600*"
K SDDATA,SDMSG
D GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
F S SDX=$O(SDDATA(44.1,SDX)) Q:SDX="" D
. S SDC=SDC+1
. S SDCLNSREC("Clinic","Provider",SDC,"Name")=$G(SDDATA(44.1,SDX,.01,"E"))
. S SDCLNSREC("Clinic","Provider",SDC,"IEN")=$G(SDDATA(44.1,SDX,.01,"I"))
. S SDCLNSREC("Clinic","Provider",SDC,"DefaultForClinic")=$G(SDDATA(44.1,SDX,.02,"E"))
; Diagnosis Multiple
S SDX="",SDC=0
S SDFIELDS="2700*"
K SDDATA,SDMSG
D GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"E","SDDATA","SDMSG")
F S SDX=$O(SDDATA(44.11,SDX)) Q:SDX="" D
. S SDC=SDC+1
. S SDCLNSREC("Clinic","Diagnosis",SDC,"Code")=$G(SDDATA(44.11,SDX,.01,"E"))
. S SDCLNSREC("Clinic","Diagnosis",SDC,"DefaultForClinic")=$G(SDDATA(44.11,SDX,.02,"E"))
; Return all Privileged Users
S (USRCNT,USRIEN)=0
F S USRIEN=$O(^SC(SDCLNIEN,"SDPRIV",USRIEN)) Q:'USRIEN D
.S USRCNT=USRCNT+1
.S SDCLNSREC("Clinic","PrivilegedUser",USRCNT,"IEN")=USRIEN
.S SDCLNSREC("Clinic","PrivilegedUser",USRCNT,"Name")=$$GET1^DIQ(44.04,USRIEN_","_SDCLNIEN,.01)
;I USRCNT=0 S SDCLNSREC("Clinic","PrivilegedUser","Error",1)="No privileged users are found."
;
; get resource IEN
S RESIEN=""
F S RESIEN=$O(^SDEC(409.831,"ALOC",$G(SDCLNIEN),RESIEN)) Q:(RESIEN="")!$D(SDCLNSREC("Clinic","Resource IEN")) D
. I $$GET1^DIQ(409.831,RESIEN,.012,"E")="CLINIC" D
. . S SDCLNSREC("Clinic","Resource IEN")=RESIEN
S RESIEN=$O(^SDEC(409.831,"ALOC",$G(SDCLNIEN),RESIEN))
;
I $D(SDCLNSREC("Clinic")) Q 1
S SDCLNSREC("Clinic")=""
Q 0
;
CLEANUP ; kill vars
K RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN,SDECI,ERRORS
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESRTVCLN2 12277 printed Dec 13, 2024@02:57:44 Page 2
SDESRTVCLN2 ;ALB/MGD,ANU,LAB,MGD,ANU,JAS,LAB,DJS,JAS,LAB,BWF - Get Clinic Info based on Clinic IEN ;DEC 5, 2023
+1 ;;5.3;Scheduling;**823,825,827,828,833,836,851,864,867,871**;Aug 13, 1993;Build 13
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; Documented API's and Integration Agreements
+5 ; -------------------------------------------
+6 ; Reference to $$GETS^DIQ is supported by IA #2056
+7 ; Reference to $$GETS1^DIQ is supported by IA #2056
+8 ;
+9 ; copy of SDESRTVCLN
+10 QUIT
+11 ;
JSONCLNINFO(RETSDCLNJSON,SDCLNIEN,SDEAS,HASHFLG) ;Get Clinic info
+1 ;INPUT - SDCLNIEN (Clinic IEN)
+2 ; - SDEAS [optional] - Enterprise Appointment Scheduling (EAS) Tracking Number associated to an appointment.
+3 ; - HASHFLG - Flag to update hash value for clinic or not (0 - no (default), 1- yes )
+4 ;RETURN PARAMETER:
+5 ;
+6 ;{"Clinic": {
+7 ;"Abbreviation": "STPDN-M",
+8 ;"AdminInpatientMeds": "",
+9 ;"AllowPatScheduling": "",
+10 ;"AllowableConsecutiveNoShows": "",
+11 ;"ApptCancelLetter": "",
+12 ;"CHAR4": "",
+13 ;"CancelLetter": "",
+14 ;"CheckinCheckoutTime": "",
+15 ;"ClinicIEN": 2174,
+16 ;"ClinicName": "STPDN-M",
+17 ;"ClinicStatus": "ACTIVE" or "INACTIVE"
+18 ;"CreditStopCodeAMISNum": "",
+19 ;"CreditStopCodeName": "",
+20 ;"CreditStopCodeNum": "",
+21 ;"DefaultApptType": "",
+22 ;"DefaultToPCPractitioner": "",
+23 ;"DisplayClinicAppt": "",
+24 ;"DivisionIEN": 1,
+25 ;"DivisionName": "CHEYENNE VAMROC",
+26 ;"ECheckinAllowed": "",
+27 ;"Hash": "F712AC20443E444B4CBF3ECD95AA3B2706BC2964",
+28 ;"HolidaySchedule": "",
+29 ;"HourClinicDisplayBegins": 8,
+30 ;"Inactivate Date": "",
+31 ;"IncrementsPerHr": "",
+32 ;"LastHashTimestamp": 3220901.160618,
+33 ;"LengthOfAppt": "",
+34 ;"MaxDaysForFutureBooking": "",
+35 ;"MeetsAtThisFacility": "",
+36 ;"NoShowLetter": "",
+37 ;"NoShowLetterIEN": "",
+38 ;"NonCountClinic": "",
+39 ;"OverbooksPerDayMax": "",
+40 ;"PatientFriendlyName": "",
+41 ;"PhysicalLocation": "",
+42 ;"PreApptLetter": "",
+43 ;"PreCheckinAllowed": "",
+44 ;"Principal": "",
+45 ;"ProhibitAccessToClinic": "",
+46 ;"Provider": {
+47 ; "DefaultForClinic": "",
+48 ; "IEN": "",
+49 ; "Name": ""},
+50 ;"Reactivate Date": "",
+51 ;"ReqActionProfiles": "",
+52 ;"ReqXrayFilms": "",
+53 ;"Service": "",
+54 ;"StationNumber": 442,
+55 ;"StopCodeAMISNum": "",
+56 ;"StopCodeName": "",
+57 ;"StopCodeNum": "",
+58 ;"Telephone": "",
+59 ;"TelephoneExtension": "",
+60 ;"Timezone": "EASTERN",
+61 ;"TimezoneException": 1,
+62 ;"VariableApptLength": "",
+63 ;"WorkloadValidationCheckout": ""}}
+64 ;
+65 NEW RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN,SDECI,ERRORS,SDCLNJSON
+66 SET (RETURN,ELGFIELDSARRAY,HASFIELDS)=""
+67 ;
+68 DO VALIDATECLINIC(.ERRORS,$GET(SDCLNIEN))
+69 DO VALIDATEEAS(.ERRORS,$GET(SDEAS))
+70 DO VALIDATEHASHFLG(.ERRORS,.HASHFLG)
+71 ;
+72 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
+73 IF '$DATA(ERRORS)
SET HASFIELDS=$$BLDCLNREC(.ELGFIELDSARRAY,SDCLNIEN)
+74 IF HASFIELDS
MERGE RETURN=ELGFIELDSARRAY
+75 ;
+76 ;build json without hash
DO BUILDJSON^SDESBUILDJSON(.SDCLNJSON,.RETURN)
+77 IF $DATA(ERRORS)
MERGE RETSDCLNJSON=SDCLNJSON
+78 IF HASFIELDS
Begin DoDot:1
+79 DO ADDHASH(SDCLNIEN,.ELGFIELDSARRAY,.SDCLNJSON,HASHFLG)
+80 KILL RETURN
+81 MERGE RETURN=ELGFIELDSARRAY
+82 ;json includes hash
DO BUILDJSON^SDESBUILDJSON(.RETSDCLNJSON,.RETURN)
End DoDot:1
+83 DO CLEANUP
+84 QUIT
+85 ;
ADDHASH(CLIN,ELGFIELDSARRAY,SDCLNJSON,HASHFLG) ;Add hash to output
+1 NEW HASH,HASHDATE
+2 if HASHFLG
DO UPDATECLINICHASH(CLIN,.HASH,.HASHDATE,.SDCLNJSON)
+3 SET HASH=$$GET1^DIQ(44,SDCLNIEN_",",2900)
+4 SET HASHDATE=$$FMTISO^SDAMUTDT($$GET1^DIQ(44,CLIN,2901,"I"),CLIN)
+5 SET ELGFIELDSARRAY("Clinic","LastHashTimestamp")=HASHDATE
+6 SET ELGFIELDSARRAY("Clinic","Hash")=HASH
+7 QUIT
+8 ;
UPDATECLINICHASH(CLIN,HASH,HASHDATE,SDCLNJSON) ;update clinic with new hash
+1 NEW FDA,FDAERR
+2 SET HASH=$$SHAN^XLFSHAN(160,SDCLNJSON(1))
+3 SET HASHDATE=$$NOW^XLFDT
+4 SET FDA(44,CLIN_",",2900)=HASH
+5 SET FDA(44,CLIN_",",2901)=HASHDATE
+6 DO FILE^DIE(,"FDA","FDAERR")
KILL FDA
+7 QUIT
+8 ;
ADDHASH2CLIN(IEN) ; add HASH to clinic after creation of clinic
+1 NEW HASH,HASHDATE,SDCLNJSON,SDCLNSREC
+2 DO BLDCLNREC(.SDCLNSREC,IEN)
+3 DO BUILDJSON^SDESBUILDJSON(.SDCLNJSON,.SDCLNSREC)
+4 DO UPDATECLINICHASH(IEN,.HASH,.HASHDATE,.SDCLNJSON)
+5 QUIT
+6 ;
VALIDATECLINIC(ERRORS,CLINIC) ;
+1 IF CLINIC=""
DO ERRLOG^SDESJSON(.ERRORS,18)
+2 IF CLINIC'=""
IF '$DATA(^SC(CLINIC,0))
DO ERRLOG^SDESJSON(.ERRORS,19)
+3 QUIT
+4 ;
VALIDATEEAS(ERRORS,EAS) ;
+1 IF $LENGTH(EAS)
SET EAS=$$EASVALIDATE^SDESUTIL($GET(EAS))
+2 IF $PIECE($GET(EAS),U)=-1
DO ERRLOG^SDESJSON(.ERRORS,142)
QUIT
+3 QUIT
+4 ;
VALIDATEHASHFLG(ERRORS,HASHFLG) ;
+1 SET HASHFLG=$SELECT($GET(HASHFLG)="":0,1:HASHFLG)
+2 IF (HASHFLG'=0)&(HASHFLG'=1)
DO ERRLOG^SDESJSON(.ERRORS,267)
+3 QUIT
+4 ;
BLDCLNREC(SDCLNSREC,SDCLNIEN) ;Get Clinic data
+1 ;
+2 NEW SDFIELDS,SDDATA,SDMSG,SDX,SDC,TIMEZONE,TIMEZONEEXC,USRCNT,USRIEN,STATUS,SDSTATUS,RESIEN
+3 SET SDECI=$GET(SDECI,0)
+4 SET SDFIELDS=".01;1;3.5;8;9;10;24;60;61;62;200;1914;2502;2504;2505;2506;2507;2802;99;99.1;2000;2000.5;2508;2509;2510;2511;2801;30;2001;2002;1918.5;2503;2500;1916;1918;20;21;1912;1913;1917"
+5 DO GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
+6 SET SDECI=SDECI+1
+7 ;Clinic IEN
SET SDCLNSREC("Clinic","ClinicIEN")=$GET(SDCLNIEN)
+8 ;Clinic Name
SET SDCLNSREC("Clinic","ClinicName")=$GET(SDDATA(44,SDCLNIEN_",",.01,"E"))
+9 ;Clinic Abbreviation
SET SDCLNSREC("Clinic","Abbreviation")=$GET(SDDATA(44,SDCLNIEN_",",1,"E"))
+10 ;Patient Friendly Name
SET SDCLNSREC("Clinic","PatientFriendlyName")=$GET(SDDATA(44,SDCLNIEN_",",60,"E"))
+11 ;Clinic station number
SET SDCLNSREC("Clinic","StationNumber")=$$STATIONNUMBER^SDESUTIL(SDCLNIEN)
+12 ;Clinic meets at this facility?
SET SDCLNSREC("Clinic","MeetsAtThisFacility")=$GET(SDDATA(44,SDCLNIEN_",",2504,"E"))
+13 ;Allow Direct Patient Scheduling?
SET SDCLNSREC("Clinic","AllowPatScheduling")=$GET(SDDATA(44,SDCLNIEN_",",61,"E"))
+14 ;DISPLAY CLIN APPT TO PATIENTS?
SET SDCLNSREC("Clinic","DisplayClinicAppt")=$GET(SDDATA(44,SDCLNIEN_",",62,"E"))
+15 ;Service
SET SDCLNSREC("Clinic","Service")=$GET(SDDATA(44,SDCLNIEN_",",9,"E"))
+16 ;NON-COUNT CLINIC? (Y OR N)
SET SDCLNSREC("Clinic","NonCountClinic")=$GET(SDDATA(44,SDCLNIEN_",",2502,"E"))
+17 ;Division
SET SDCLNSREC("Clinic","DivisionIEN")=$GET(SDDATA(44,SDCLNIEN_",",3.5,"I"))
+18 ;Division
SET SDCLNSREC("Clinic","DivisionName")=$GET(SDDATA(44,SDCLNIEN_",",3.5,"E"))
+19 ;Get status of clinic
SET STATUS=$$INACTIVE^SDESUTIL(SDCLNIEN,DT)
SET SDSTATUS=$SELECT(STATUS=0:"ACTIVE",1:"INACTIVE")
+20 SET SDCLNSREC("Clinic","ClinicStatus")=SDSTATUS
+21 ;Stop Code Name
SET SDCLNSREC("Clinic","StopCodeName")=$GET(SDDATA(44,SDCLNIEN_",",8,"E"))
+22 ;Stop Code IEN
SET SDCLNSREC("Clinic","StopCodeNum")=$GET(SDDATA(44,SDCLNIEN_",",8,"I"))
+23 ;Stop Code AMIS Number
SET SDCLNSREC("Clinic","StopCodeAMISNum")=$$GET1^DIQ(40.7,$GET(SDDATA(44,SDCLNIEN_",",8,"I")),1)
+24 ;Default Appointment type
SET SDCLNSREC("Clinic","DefaultApptType")=$GET(SDDATA(44,SDCLNIEN_",",2507,"E"))
+25 ;ADMINISTER INPATIENT MEDS?
SET SDCLNSREC("Clinic","AdminInpatientMeds")=$GET(SDDATA(44,SDCLNIEN_",",2802,"E"))
+26 ;TELEPHONE
SET SDCLNSREC("Clinic","Telephone")=$GET(SDDATA(44,SDCLNIEN_",",99,"E"))
+27 ;TELEPHONE Extension
SET SDCLNSREC("Clinic","TelephoneExtension")=$GET(SDDATA(44,SDCLNIEN_",",99.1,"E"))
+28 ;REQUIRE X-RAY FILMS?
SET SDCLNSREC("Clinic","ReqXrayFilms")=$GET(SDDATA(44,SDCLNIEN_",",2000,"E"))
+29 ;REQUIRE ACTION PROFILES?
SET SDCLNSREC("Clinic","ReqActionProfiles")=$GET(SDDATA(44,SDCLNIEN_",",2000.5,"E"))
+30 ;NO SHOW LETTER
SET SDCLNSREC("Clinic","NoShowLetter")=$GET(SDDATA(44,SDCLNIEN_",",2508,"E"))
+31 ;NO SHOW IEN
SET SDCLNSREC("Clinic","NoShowLetterIEN")=$GET(SDDATA(44,SDCLNIEN_",",2508,"I"))
+32 ;PRE-APPOINTMENT LETTER
SET SDCLNSREC("Clinic","PreApptLetter")=$GET(SDDATA(44,SDCLNIEN_",",2509,"E"))
+33 ;CLINIC CANCELLATION LETTER
SET SDCLNSREC("Clinic","CancelLetter")=$GET(SDDATA(44,SDCLNIEN_",",2510,"E"))
+34 ;APPT. CANCELLATION LETTER
SET SDCLNSREC("Clinic","ApptCancelLetter")=$GET(SDDATA(44,SDCLNIEN_",",2511,"E"))
+35 ;ASK FOR CHECK IN/OUT TIME
SET SDCLNSREC("Clinic","CheckinCheckoutTime")=$GET(SDDATA(44,SDCLNIEN_",",24,"E"))
+36 ;DEFAULT TO PC PRACTITIONER?
SET SDCLNSREC("Clinic","DefaultToPCPractitioner")=$GET(SDDATA(44,SDCLNIEN_",",2801,"E"))
+37 ;WORKLOAD VALIDATION AT CHK OUT
SET SDCLNSREC("Clinic","WorkloadValidationCheckout")=$GET(SDDATA(44,SDCLNIEN_",",30,"E"))
+38 ;ALLOWABLE CONSECUTIVE NO-SHOWS
SET SDCLNSREC("Clinic","AllowableConsecutiveNoShows")=$GET(SDDATA(44,SDCLNIEN_",",2001,"E"))
+39 ;MAX # DAYS FOR FUTURE BOOKING
SET SDCLNSREC("Clinic","MaxDaysForFutureBooking")=$GET(SDDATA(44,SDCLNIEN_",",2002,"E"))
+40 ;SCHEDULE ON HOLIDAYS?
SET SDCLNSREC("Clinic","HolidaySchedule")=$GET(SDDATA(44,SDCLNIEN_",",1918.5,"E"))
+41 ;CREDIT STOP IEN
SET SDCLNSREC("Clinic","CreditStopCodeNum")=$GET(SDDATA(44,SDCLNIEN_",",2503,"I"))
+42 ;CREDIT STOP NAME
SET SDCLNSREC("Clinic","CreditStopCodeName")=$GET(SDDATA(44,SDCLNIEN_",",2503,"E"))
+43 ;Credit Stop Code AMIS Number
SET SDCLNSREC("Clinic","CreditStopCodeAMISNum")=$$GET1^DIQ(40.7,$GET(SDDATA(44,SDCLNIEN_",",2503,"I")),1)
+44 ;PROHIBIT ACCESS TO CLINIC?
SET SDCLNSREC("Clinic","ProhibitAccessToClinic")=$GET(SDDATA(44,SDCLNIEN_",",2500,"E"))
+45 ;PHYSICAL LOCATION
SET SDCLNSREC("Clinic","PhysicalLocation")=$GET(SDDATA(44,SDCLNIEN_",",10,"E"))
+46 ;PRINCIPAL Clinic
SET SDCLNSREC("Clinic","Principal")=$GET(SDDATA(44,SDCLNIEN_",",1916,"E"))
+47 ;OVERBOOKS/DAY MAXIMUM
SET SDCLNSREC("Clinic","OverbooksPerDayMax")=$GET(SDDATA(44,SDCLNIEN_",",1918,"E"))
+48 ;E-CHECKIN ALLOWED
SET SDCLNSREC("Clinic","ECheckinAllowed")=$GET(SDDATA(44,SDCLNIEN_",",20,"E"))
+49 ;PRE-CHECKIN ALLOWED NO
SET SDCLNSREC("Clinic","PreCheckinAllowed")=$GET(SDDATA(44,SDCLNIEN_",",21,"E"))
+50 ;LENGTH OF APP'T
SET SDCLNSREC("Clinic","LengthOfAppt")=$GET(SDDATA(44,SDCLNIEN_",",1912,"E"))
+51 ;VARIABLE APP'NTMENT LENGTH
SET SDCLNSREC("Clinic","VariableApptLength")=$GET(SDDATA(44,SDCLNIEN_",",1913,"E"))
+52 ;DISPLAY INCREMENTS PER HOUR
SET SDCLNSREC("Clinic","IncrementsPerHr")=$GET(SDDATA(44,SDCLNIEN_",",1917,"E"))
+53 ; HOUR CLINIC DISPLAY BEGINS
SET SDCLNSREC("Clinic","HourClinicDisplayBegins")=$SELECT($GET(SDDATA(44,SDCLNIEN_",",1914,"E"))'="":$GET(SDDATA(44,SDCLNIEN_",",1914,"E")),1:8)
+54 SET TIMEZONE=$$TIMEZONEDATA^SDESUTIL($GET(SDCLNIEN))
SET TIMEZONEEXC=$PIECE($GET(TIMEZONE),U,3)
SET TIMEZONE=$PIECE($GET(TIMEZONE),U)
+55 SET SDCLNSREC("Clinic","Timezone")=TIMEZONE
+56 SET SDCLNSREC("Clinic","TimezoneException")=TIMEZONEEXC
+57 ;Inactivate Date
SET SDCLNSREC("Clinic","Inactivate Date")=$$FMTISO^SDAMUTDT($GET(SDDATA(44,SDCLNIEN_",",2505,"I")))
+58 ;Reactivate Date
SET SDCLNSREC("Clinic","Reactivate Date")=$$FMTISO^SDAMUTDT($GET(SDDATA(44,SDCLNIEN_",",2506,"I")))
+59 SET SDCLNSREC("Clinic","PbspID")=$GET(SDDATA(44,SDCLNIEN_",",200,"E"))
+60 ; Get CHAR4 Data
+61 NEW CHAR4
+62 SET CHAR4=$$CHAR4^SDESUTIL($GET(SDDATA(44,SDCLNIEN_",",.01,"E")))
+63 SET SDCLNSREC("Clinic","CHAR4")=CHAR4
+64 ; Special Instructions Multiple
+65 SET SDX=""
SET SDC=0
+66 SET SDFIELDS="1910*"
+67 KILL SDDATA,SDMSG
+68 DO GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"E","SDDATA","SDMSG")
+69 FOR
SET SDX=$ORDER(SDDATA(44.03,SDX))
if SDX=""
QUIT
Begin DoDot:1
+70 SET SDC=SDC+1
+71 SET SDCLNSREC("Clinic","Special Instructions",SDC)=$GET(SDDATA(44.03,SDX,.01,"E"))
End DoDot:1
+72 ; Providers Multiple
+73 SET SDX=""
SET SDC=0
+74 SET SDFIELDS="2600*"
+75 KILL SDDATA,SDMSG
+76 DO GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"IE","SDDATA","SDMSG")
+77 FOR
SET SDX=$ORDER(SDDATA(44.1,SDX))
if SDX=""
QUIT
Begin DoDot:1
+78 SET SDC=SDC+1
+79 SET SDCLNSREC("Clinic","Provider",SDC,"Name")=$GET(SDDATA(44.1,SDX,.01,"E"))
+80 SET SDCLNSREC("Clinic","Provider",SDC,"IEN")=$GET(SDDATA(44.1,SDX,.01,"I"))
+81 SET SDCLNSREC("Clinic","Provider",SDC,"DefaultForClinic")=$GET(SDDATA(44.1,SDX,.02,"E"))
End DoDot:1
+82 ; Diagnosis Multiple
+83 SET SDX=""
SET SDC=0
+84 SET SDFIELDS="2700*"
+85 KILL SDDATA,SDMSG
+86 DO GETS^DIQ(44,SDCLNIEN_",",SDFIELDS,"E","SDDATA","SDMSG")
+87 FOR
SET SDX=$ORDER(SDDATA(44.11,SDX))
if SDX=""
QUIT
Begin DoDot:1
+88 SET SDC=SDC+1
+89 SET SDCLNSREC("Clinic","Diagnosis",SDC,"Code")=$GET(SDDATA(44.11,SDX,.01,"E"))
+90 SET SDCLNSREC("Clinic","Diagnosis",SDC,"DefaultForClinic")=$GET(SDDATA(44.11,SDX,.02,"E"))
End DoDot:1
+91 ; Return all Privileged Users
+92 SET (USRCNT,USRIEN)=0
+93 FOR
SET USRIEN=$ORDER(^SC(SDCLNIEN,"SDPRIV",USRIEN))
if 'USRIEN
QUIT
Begin DoDot:1
+94 SET USRCNT=USRCNT+1
+95 SET SDCLNSREC("Clinic","PrivilegedUser",USRCNT,"IEN")=USRIEN
+96 SET SDCLNSREC("Clinic","PrivilegedUser",USRCNT,"Name")=$$GET1^DIQ(44.04,USRIEN_","_SDCLNIEN,.01)
End DoDot:1
+97 ;I USRCNT=0 S SDCLNSREC("Clinic","PrivilegedUser","Error",1)="No privileged users are found."
+98 ;
+99 ; get resource IEN
+100 SET RESIEN=""
+101 FOR
SET RESIEN=$ORDER(^SDEC(409.831,"ALOC",$GET(SDCLNIEN),RESIEN))
if (RESIEN="")!$DATA(SDCLNSREC("Clinic","Resource IEN"))
QUIT
Begin DoDot:1
+102 IF $$GET1^DIQ(409.831,RESIEN,.012,"E")="CLINIC"
Begin DoDot:2
+103 SET SDCLNSREC("Clinic","Resource IEN")=RESIEN
End DoDot:2
End DoDot:1
+104 SET RESIEN=$ORDER(^SDEC(409.831,"ALOC",$GET(SDCLNIEN),RESIEN))
+105 ;
+106 IF $DATA(SDCLNSREC("Clinic"))
QUIT 1
+107 SET SDCLNSREC("Clinic")=""
+108 QUIT 0
+109 ;
CLEANUP ; kill vars
+1 KILL RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN,SDECI,ERRORS
+2 QUIT
+3 ;