SDES2CLINICLIST ;ALB/TJB - SDES2 GET APPTS BY CLIN LIST2 ;DEC 14,2023
;;5.3;Scheduling;**869**;Aug 13, 1993;Build 13
;;Per VHA Directive 6402, this routine should not be modified
;
; The SDCONTEXT array is controlled by the Acheron application and its fields are
; needed for the storage of the required auditing information.
;
; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
; SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
; SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
; SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
; SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
;
; Note one SDPARAM("CLINIC IEN",1) is required additional clinics can be specified but are optional
; SDPARAM("CLINIC IEN",1)=IEN1 The clinic IEN from HOSPITAL LOCATION (#44) to list appointments (required)
; SDPARAM("CLINIC IEN",2)=IEN2 (optional)
; SDPARAM("CLINIC IEN",3)=IEN3 (optional)
; Additional clinics can be specified
; Any specified "CLINIC IEN" must be valid to proceed
APPTBYCLINICLIST(RETNJSON,SDCONTEXT,SDPARAM) ;
N ERRORS
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
D VALPARAM(.ERRORS,.SDPARAM)
I $D(ERRORS) S ERRORS("Clinics")="" D BUILDJSON^SDES2JSON(.RETNJSON,.ERRORS) Q
D BUILDCLINICS(.RETNJSON,.SDCONTEXT,.SDPARAM,.ERRORS)
Q
;
BUILDCLINICS(RETNJSON,SDCONTEXT,SDPARAM,ERRORS) ;
N APPTLIST,IENCOUNT,YESTERDAYFM,TODAYFM,CLINICIEN,PRVUSERS,CLINTODAY,TODAY
S TODAY=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
S IENCOUNT=0
F S IENCOUNT=$O(SDPARAM("CLINIC IEN",IENCOUNT)) Q:'IENCOUNT S CLINICIEN=SDPARAM("CLINIC IEN",IENCOUNT) D
. N TEMPLIST,DIVISION,INSTITUT,STATION
. S CLINTODAY=$P($$ISOTFM^SDAMUTDT(TODAY,CLINICIEN),".",1)
. S YESTERDAYFM=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
. S TODAYFM=$$FMADD^XLFDT(CLINTODAY,"",23,59,59)
. D APPTBYCLINIC2(.TEMPLIST,CLINICIEN,YESTERDAYFM,TODAYFM,$G(SDCONTEXT("ACHERON AUDIT ID")),$G(SDCONTEXT("USER DUZ")))
. S DIVISION=$$GET1^DIQ(44,CLINICIEN,3.5,"I")
. S INSTITUT=$$GET1^DIQ(40.8,DIVISION,.07,"I")
. S STATION=$$GET1^DIQ(4,INSTITUT,99,"I")
. S APPTLIST("Clinics",IENCOUNT,"Station")=STATION
. S APPTLIST("Clinics",IENCOUNT,"IEN")=CLINICIEN
. M APPTLIST("Clinics",IENCOUNT)=TEMPLIST
D BUILDJSON^SDES2JSON(.RETNJSON,.APPTLIST)
Q
;
VALPARAM(ERRORS,SDPARAM) ; Validate the clinics in the INPUTARRAY
N INDEX,CLNIEN S INDEX=""
I $D(SDPARAM("CLINIC IEN"))'>1 D ERRLOG^SDES2JSON(.ERRORS,18) Q ; no clinic array to build
; Check the clinic IEN to make sure they are valid
F S INDEX=$O(SDPARAM("CLINIC IEN",INDEX)) Q:INDEX="" S CLNIEN=SDPARAM("CLINIC IEN",INDEX) D VALCLINIEN^SDES2VAL44(.ERRORS,CLNIEN,1,0)
Q
;
APPTBYCLINIC2(SDAPPT,SDCLINICIEN,SDBEG,SDEND,SDEAS,SDDUZ) ;
N POP,APPTIEN,APPTDT,APPTDATA,COUNTER,JSONERR,DFN,PATIENT,RESTYPE,SDRESIEN
S (POP,APPTIEN,COUNTER,JSONERR)=""
K SDECY
;Validate input parameters
S SDBEG=$G(SDBEG)
S SDEND=$G(SDEND)
S SDRESIEN=""
F S SDRESIEN=$O(^SDEC(409.831,"ALOC",SDCLINICIEN,SDRESIEN)) Q:SDRESIEN="" D
. S RESTYPE=$P($G(^SDEC(409.831,SDRESIEN,0)),"^",11)
. I $P(RESTYPE,";",2)'="SC(" Q ;Must be a Hospital Loc
. S APPTDT=SDBEG
. F S APPTDT=$O(^SDEC(409.84,"ARSRC",SDRESIEN,APPTDT)) Q:APPTDT="" D Q:POP
.. I SDEND,APPTDT>SDEND S POP=1 Q ;End loop since past the end date
.. S APPTIEN=""
.. F S APPTIEN=$O(^SDEC(409.84,"ARSRC",SDRESIEN,APPTDT,APPTIEN)) Q:APPTIEN="" D
... D SUMMARY(.APPTDATA,APPTIEN)
... S COUNTER=$G(COUNTER)+1
... M SDAPPT("Appt",COUNTER)=APPTDATA
... S DFN=$G(SDAPPT("Appt",COUNTER,"DFN"))
... S PATIENT=""
... D PATIENTADDON^SDES2PATDATA(.PATIENT,DFN,$S($G(SDDUZ)'="":SDDUZ,1:DUZ))
... M SDAPPT("Appt",COUNTER,"Patient")=PATIENT
I '$D(SDAPPT("Appt")) S SDAPPT("Appt")=""
Q
;
SUMMARY(APPTDATA,IEN) ;
;Returns a basic set of data for a specific appointment
;
; Input
; IEN - Specific appointment IEN
; Return
; APPTDATA - Array of field names and the data for the field based on the IEN
;
N APPTARY,FN,IENS,SDMSG,SDDFN,RESOURCEIEN,CLINICIEN,SIEN,OVERBOOK,STIME,ETIME,X
N DATETIME,NUM,STATPOINTER,CLINICARY,STAT,CLINICDATA,PROV,CLINICAPPT,CUSER
K APPTDATA
S FN=409.84,IENS=IEN_",",OVERBOOK=0
D GETS^DIQ(FN,IENS,".01;.02;.03;.04;.05;.06;.07;.12;.13;.121;.122;.14;.16;.17;.18;.22;1;3;4;100","IE","APPTARY","SDMSG") ;SD,814-Added 100 for the EAS Tracking Number
S RESOURCEIEN=$G(APPTARY(FN,IENS,.07,"I"))
S CLINICIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
S APPTDATA("StartTime")=$G(APPTARY(FN,IENS,.01,"E"))
S APPTDATA("StartTimeFM")=$G(APPTARY(FN,IENS,.01,"I"))
S STIME=$G(APPTARY(FN,IENS,.01,"I"))
S APPTDATA("EndTime")=$G(APPTARY(FN,IENS,.02,"E"))
S ETIME=$G(APPTARY(FN,IENS,.02,"I"))
S APPTDATA("AppointmentTypeIEN")=$G(APPTARY(FN,IENS,.06,"I"))
S APPTDATA("LengthOfAppt")=$G(APPTARY(FN,IENS,.18,"E"))
S APPTDATA("RequestType")=$G(APPTARY(FN,IENS,.22,"E"))
S APPTDATA("RequestIEN")=$P($G(APPTARY(FN,IENS,.22,"I")),";")
K APPTARY(FN,IENS,1,"I"),APPTARY(FN,IENS,1,"E")
I $D(APPTARY(FN,IENS,1)) M APPTDATA("Note")=APPTARY(FN,IENS,1)
E S APPTDATA("Note")=""
S APPTDATA("AppointmentIEN")=IEN
S DATETIME=$G(APPTARY(FN,IENS,.03,"I"))
S APPTDATA("CheckIn")=$$FMTE^XLFDT(DATETIME)
S DATETIME=$G(APPTARY(FN,IENS,.04,"I"))
S APPTDATA("CheckInEntered")=$$FMTE^XLFDT(DATETIME)
S DATETIME=$G(APPTARY(FN,IENS,.14,"I"))
S APPTDATA("CheckOut")=$$FMTE^XLFDT(DATETIME)
S APPTDATA("EASTrackingNumber")=$G(APPTARY(FN,IENS,100,"I")) ;SD,814-Retrieve EAS Tracking Number
S APPTDATA("CancelDateTime")=$$FMTE^XLFDT($G(APPTARY(FN,IENS,.12,"I")))
S APPTDATA("CancellationReason")=$G(APPTARY(FN,IENS,.122,"E"))
;CancelledByUser Data Elements
S CUSER=$G(APPTARY(FN,IENS,.121,"I"))
I CUSER D
.S APPTDATA("CancelledByUser","ID")=CUSER
.S APPTDATA("CancelledByUser","Name")=$G(APPTARY(FN,IENS,.121,"E"))
.S APPTDATA("CancelledByUser","SecId")=$$GET1^DIQ(200,CUSER,205.1,"I")
I '$D(APPTDATA("CancelledByUser")) S APPTDATA("CancelledByUser",1)=""
;
S APPTDATA("Walkin")=$G(APPTARY(FN,IENS,.13,"E"))
;
;Always send these Resource / Clinic data elements
S APPTDATA("Clinic","IsOverbook")=0
S APPTDATA("ResourceIEN")=RESOURCEIEN
S APPTDATA("Resource","Name")=$G(APPTARY(FN,IENS,.07,"E"))
S APPTDATA("Resource","ClinicIEN")=CLINICIEN
;847
D SETSTATUS^SDESGETAPPTWRAP5(.APPTDATA,IEN,CLINICIEN)
S APPTDATA("CurrentStatus")=APPTDATA("Status")
;
D APPTCLINIC^SDESCLINICDATA(.CLINICDATA,CLINICIEN)
M APPTDATA("Clinic")=CLINICDATA
S SDDFN=$G(APPTARY(FN,IENS,.05,"I"))
I CLINICIEN D
. S SIEN=0
. F S SIEN=$O(^SC(CLINICIEN,"S",STIME,SIEN)) Q:'SIEN D
.. S X=$O(^SC(CLINICIEN,"S",STIME,SIEN,""),-1)
.. Q:SDDFN'=$$GET1^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",",.01,"I")
.. S:X OVERBOOK=$G(^SC(CLINICIEN,"S",STIME,SIEN,X,"OB"))
.. D GETS^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",","10.5;30","IE","CLINICAPPT","SDMSG")
.. S APPTDATA("Clinic","CurrentEligibilityCode")=$G(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",10.5,"E"))
.. S APPTDATA("Clinic","EligibilityOfVisit")=$G(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",30,"E"))
S (SIEN,NUM)=0
F S SIEN=$O(^SDEC(409.84,IEN,3,SIEN)) Q:'SIEN D
. S NUM=NUM+1
. S STATPOINTER=$$GET1^DIQ(409.843,SIEN_","_IEN_",",.01,"I")
. S STAT=$$GET1^DIQ(409.842,STATPOINTER,.01,"E")
. S DATETIME=$$GET1^DIQ(409.843,SIEN_","_IEN_",",1,"E")
. S APPTDATA("CheckInSteps",NUM,"IEN")=SIEN
. S APPTDATA("CheckInSteps",NUM,"Status")=$G(STAT)
. S APPTDATA("CheckInSteps",NUM,"DateTime")=$$FMTE^XLFDT(DATETIME)
I '$D(APPTDATA("CheckInSteps")) S APPTDATA("CheckInSteps")=""
;
;Always send these Patient data elements
S APPTDATA("DFN")=SDDFN
S APPTDATA("Patient","EligibilityIEN")=$$GET1^DIQ(2,SDDFN_",",.361,"I")
S APPTDATA("Patient","Name")=$$GET1^DIQ(2,SDDFN_",",.01,"E")
; 864
S APPTDATA("Patient","DateOfBirth")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.03,"I"))
S APPTDATA("Patient","DateOfDeath")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.351,"I"))
;
; patient comments
D GETPATCOMMENTS(.APPTDATA,IEN)
; provider data elements
S PROV=$G(APPTARY(FN,IENS,.16,"I"))
S APPTDATA("Provider","ID")=PROV
S APPTDATA("Provider","Name")=$G(APPTARY(FN,IENS,.16,"E"))
S APPTDATA("Provider","SecId")=$$GET1^DIQ(200,PROV,205.1,"I")
Q
;
N SUBIEN,COUNT
S SUBIEN=0,COUNT=0
F S SUBIEN=$O(^SDEC(409.84,IEN,6,SUBIEN)) Q:'SUBIEN D
.S COUNT=COUNT+1
.S APPTDATA("PatientComments",COUNT)=$$GET1^DIQ(409.846,SUBIEN_","_IEN_",",.01,"E")
I '$D(APPTDATA("PatientComments")) S APPTDATA("PatientComments",1)=""
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2CLINICLIST 8804 printed Nov 22, 2024@18:03:30 Page 2
SDES2CLINICLIST ;ALB/TJB - SDES2 GET APPTS BY CLIN LIST2 ;DEC 14,2023
+1 ;;5.3;Scheduling;**869**;Aug 13, 1993;Build 13
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; The SDCONTEXT array is controlled by the Acheron application and its fields are
+5 ; needed for the storage of the required auditing information.
+6 ;
+7 ; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
+8 ; SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
+9 ; SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
+10 ; SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
+11 ; SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
+12 ;
+13 ; Note one SDPARAM("CLINIC IEN",1) is required additional clinics can be specified but are optional
+14 ; SDPARAM("CLINIC IEN",1)=IEN1 The clinic IEN from HOSPITAL LOCATION (#44) to list appointments (required)
+15 ; SDPARAM("CLINIC IEN",2)=IEN2 (optional)
+16 ; SDPARAM("CLINIC IEN",3)=IEN3 (optional)
+17 ; Additional clinics can be specified
+18 ; Any specified "CLINIC IEN" must be valid to proceed
APPTBYCLINICLIST(RETNJSON,SDCONTEXT,SDPARAM) ;
+1 NEW ERRORS
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 DO VALPARAM(.ERRORS,.SDPARAM)
+4 IF $DATA(ERRORS)
SET ERRORS("Clinics")=""
DO BUILDJSON^SDES2JSON(.RETNJSON,.ERRORS)
QUIT
+5 DO BUILDCLINICS(.RETNJSON,.SDCONTEXT,.SDPARAM,.ERRORS)
+6 QUIT
+7 ;
BUILDCLINICS(RETNJSON,SDCONTEXT,SDPARAM,ERRORS) ;
+1 NEW APPTLIST,IENCOUNT,YESTERDAYFM,TODAYFM,CLINICIEN,PRVUSERS,CLINTODAY,TODAY
+2 SET TODAY=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
+3 SET IENCOUNT=0
+4 FOR
SET IENCOUNT=$ORDER(SDPARAM("CLINIC IEN",IENCOUNT))
if 'IENCOUNT
QUIT
SET CLINICIEN=SDPARAM("CLINIC IEN",IENCOUNT)
Begin DoDot:1
+5 NEW TEMPLIST,DIVISION,INSTITUT,STATION
+6 SET CLINTODAY=$PIECE($$ISOTFM^SDAMUTDT(TODAY,CLINICIEN),".",1)
+7 SET YESTERDAYFM=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
+8 SET TODAYFM=$$FMADD^XLFDT(CLINTODAY,"",23,59,59)
+9 DO APPTBYCLINIC2(.TEMPLIST,CLINICIEN,YESTERDAYFM,TODAYFM,$GET(SDCONTEXT("ACHERON AUDIT ID")),$GET(SDCONTEXT("USER DUZ")))
+10 SET DIVISION=$$GET1^DIQ(44,CLINICIEN,3.5,"I")
+11 SET INSTITUT=$$GET1^DIQ(40.8,DIVISION,.07,"I")
+12 SET STATION=$$GET1^DIQ(4,INSTITUT,99,"I")
+13 SET APPTLIST("Clinics",IENCOUNT,"Station")=STATION
+14 SET APPTLIST("Clinics",IENCOUNT,"IEN")=CLINICIEN
+15 MERGE APPTLIST("Clinics",IENCOUNT)=TEMPLIST
End DoDot:1
+16 DO BUILDJSON^SDES2JSON(.RETNJSON,.APPTLIST)
+17 QUIT
+18 ;
VALPARAM(ERRORS,SDPARAM) ; Validate the clinics in the INPUTARRAY
+1 NEW INDEX,CLNIEN
SET INDEX=""
+2 ; no clinic array to build
IF $DATA(SDPARAM("CLINIC IEN"))'>1
DO ERRLOG^SDES2JSON(.ERRORS,18)
QUIT
+3 ; Check the clinic IEN to make sure they are valid
+4 FOR
SET INDEX=$ORDER(SDPARAM("CLINIC IEN",INDEX))
if INDEX=""
QUIT
SET CLNIEN=SDPARAM("CLINIC IEN",INDEX)
DO VALCLINIEN^SDES2VAL44(.ERRORS,CLNIEN,1,0)
+5 QUIT
+6 ;
APPTBYCLINIC2(SDAPPT,SDCLINICIEN,SDBEG,SDEND,SDEAS,SDDUZ) ;
+1 NEW POP,APPTIEN,APPTDT,APPTDATA,COUNTER,JSONERR,DFN,PATIENT,RESTYPE,SDRESIEN
+2 SET (POP,APPTIEN,COUNTER,JSONERR)=""
+3 KILL SDECY
+4 ;Validate input parameters
+5 SET SDBEG=$GET(SDBEG)
+6 SET SDEND=$GET(SDEND)
+7 SET SDRESIEN=""
+8 FOR
SET SDRESIEN=$ORDER(^SDEC(409.831,"ALOC",SDCLINICIEN,SDRESIEN))
if SDRESIEN=""
QUIT
Begin DoDot:1
+9 SET RESTYPE=$PIECE($GET(^SDEC(409.831,SDRESIEN,0)),"^",11)
+10 ;Must be a Hospital Loc
IF $PIECE(RESTYPE,";",2)'="SC("
QUIT
+11 SET APPTDT=SDBEG
+12 FOR
SET APPTDT=$ORDER(^SDEC(409.84,"ARSRC",SDRESIEN,APPTDT))
if APPTDT=""
QUIT
Begin DoDot:2
+13 ;End loop since past the end date
IF SDEND
IF APPTDT>SDEND
SET POP=1
QUIT
+14 SET APPTIEN=""
+15 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",SDRESIEN,APPTDT,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:3
+16 DO SUMMARY(.APPTDATA,APPTIEN)
+17 SET COUNTER=$GET(COUNTER)+1
+18 MERGE SDAPPT("Appt",COUNTER)=APPTDATA
+19 SET DFN=$GET(SDAPPT("Appt",COUNTER,"DFN"))
+20 SET PATIENT=""
+21 DO PATIENTADDON^SDES2PATDATA(.PATIENT,DFN,$SELECT($GET(SDDUZ)'="":SDDUZ,1:DUZ))
+22 MERGE SDAPPT("Appt",COUNTER,"Patient")=PATIENT
End DoDot:3
End DoDot:2
if POP
QUIT
End DoDot:1
+23 IF '$DATA(SDAPPT("Appt"))
SET SDAPPT("Appt")=""
+24 QUIT
+25 ;
SUMMARY(APPTDATA,IEN) ;
+1 ;Returns a basic set of data for a specific appointment
+2 ;
+3 ; Input
+4 ; IEN - Specific appointment IEN
+5 ; Return
+6 ; APPTDATA - Array of field names and the data for the field based on the IEN
+7 ;
+8 NEW APPTARY,FN,IENS,SDMSG,SDDFN,RESOURCEIEN,CLINICIEN,SIEN,OVERBOOK,STIME,ETIME,X
+9 NEW DATETIME,NUM,STATPOINTER,CLINICARY,STAT,CLINICDATA,PROV,CLINICAPPT,CUSER
+10 KILL APPTDATA
+11 SET FN=409.84
SET IENS=IEN_","
SET OVERBOOK=0
+12 ;SD,814-Added 100 for the EAS Tracking Number
DO GETS^DIQ(FN,IENS,".01;.02;.03;.04;.05;.06;.07;.12;.13;.121;.122;.14;.16;.17;.18;.22;1;3;4;100","IE","APPTARY","SDMSG")
+13 SET RESOURCEIEN=$GET(APPTARY(FN,IENS,.07,"I"))
+14 SET CLINICIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
+15 SET APPTDATA("StartTime")=$GET(APPTARY(FN,IENS,.01,"E"))
+16 SET APPTDATA("StartTimeFM")=$GET(APPTARY(FN,IENS,.01,"I"))
+17 SET STIME=$GET(APPTARY(FN,IENS,.01,"I"))
+18 SET APPTDATA("EndTime")=$GET(APPTARY(FN,IENS,.02,"E"))
+19 SET ETIME=$GET(APPTARY(FN,IENS,.02,"I"))
+20 SET APPTDATA("AppointmentTypeIEN")=$GET(APPTARY(FN,IENS,.06,"I"))
+21 SET APPTDATA("LengthOfAppt")=$GET(APPTARY(FN,IENS,.18,"E"))
+22 SET APPTDATA("RequestType")=$GET(APPTARY(FN,IENS,.22,"E"))
+23 SET APPTDATA("RequestIEN")=$PIECE($GET(APPTARY(FN,IENS,.22,"I")),";")
+24 KILL APPTARY(FN,IENS,1,"I"),APPTARY(FN,IENS,1,"E")
+25 IF $DATA(APPTARY(FN,IENS,1))
MERGE APPTDATA("Note")=APPTARY(FN,IENS,1)
+26 IF '$TEST
SET APPTDATA("Note")=""
+27 SET APPTDATA("AppointmentIEN")=IEN
+28 SET DATETIME=$GET(APPTARY(FN,IENS,.03,"I"))
+29 SET APPTDATA("CheckIn")=$$FMTE^XLFDT(DATETIME)
+30 SET DATETIME=$GET(APPTARY(FN,IENS,.04,"I"))
+31 SET APPTDATA("CheckInEntered")=$$FMTE^XLFDT(DATETIME)
+32 SET DATETIME=$GET(APPTARY(FN,IENS,.14,"I"))
+33 SET APPTDATA("CheckOut")=$$FMTE^XLFDT(DATETIME)
+34 ;SD,814-Retrieve EAS Tracking Number
SET APPTDATA("EASTrackingNumber")=$GET(APPTARY(FN,IENS,100,"I"))
+35 SET APPTDATA("CancelDateTime")=$$FMTE^XLFDT($GET(APPTARY(FN,IENS,.12,"I")))
+36 SET APPTDATA("CancellationReason")=$GET(APPTARY(FN,IENS,.122,"E"))
+37 ;CancelledByUser Data Elements
+38 SET CUSER=$GET(APPTARY(FN,IENS,.121,"I"))
+39 IF CUSER
Begin DoDot:1
+40 SET APPTDATA("CancelledByUser","ID")=CUSER
+41 SET APPTDATA("CancelledByUser","Name")=$GET(APPTARY(FN,IENS,.121,"E"))
+42 SET APPTDATA("CancelledByUser","SecId")=$$GET1^DIQ(200,CUSER,205.1,"I")
End DoDot:1
+43 IF '$DATA(APPTDATA("CancelledByUser"))
SET APPTDATA("CancelledByUser",1)=""
+44 ;
+45 SET APPTDATA("Walkin")=$GET(APPTARY(FN,IENS,.13,"E"))
+46 ;
+47 ;Always send these Resource / Clinic data elements
+48 SET APPTDATA("Clinic","IsOverbook")=0
+49 SET APPTDATA("ResourceIEN")=RESOURCEIEN
+50 SET APPTDATA("Resource","Name")=$GET(APPTARY(FN,IENS,.07,"E"))
+51 SET APPTDATA("Resource","ClinicIEN")=CLINICIEN
+52 ;847
+53 DO SETSTATUS^SDESGETAPPTWRAP5(.APPTDATA,IEN,CLINICIEN)
+54 SET APPTDATA("CurrentStatus")=APPTDATA("Status")
+55 ;
+56 DO APPTCLINIC^SDESCLINICDATA(.CLINICDATA,CLINICIEN)
+57 MERGE APPTDATA("Clinic")=CLINICDATA
+58 SET SDDFN=$GET(APPTARY(FN,IENS,.05,"I"))
+59 IF CLINICIEN
Begin DoDot:1
+60 SET SIEN=0
+61 FOR
SET SIEN=$ORDER(^SC(CLINICIEN,"S",STIME,SIEN))
if 'SIEN
QUIT
Begin DoDot:2
+62 SET X=$ORDER(^SC(CLINICIEN,"S",STIME,SIEN,""),-1)
+63 if SDDFN'=$$GET1^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",",.01,"I")
QUIT
+64 if X
SET OVERBOOK=$GET(^SC(CLINICIEN,"S",STIME,SIEN,X,"OB"))
+65 DO GETS^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",","10.5;30","IE","CLINICAPPT","SDMSG")
+66 SET APPTDATA("Clinic","CurrentEligibilityCode")=$GET(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",10.5,"E"))
+67 SET APPTDATA("Clinic","EligibilityOfVisit")=$GET(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",30,"E"))
End DoDot:2
End DoDot:1
+68 SET (SIEN,NUM)=0
+69 FOR
SET SIEN=$ORDER(^SDEC(409.84,IEN,3,SIEN))
if 'SIEN
QUIT
Begin DoDot:1
+70 SET NUM=NUM+1
+71 SET STATPOINTER=$$GET1^DIQ(409.843,SIEN_","_IEN_",",.01,"I")
+72 SET STAT=$$GET1^DIQ(409.842,STATPOINTER,.01,"E")
+73 SET DATETIME=$$GET1^DIQ(409.843,SIEN_","_IEN_",",1,"E")
+74 SET APPTDATA("CheckInSteps",NUM,"IEN")=SIEN
+75 SET APPTDATA("CheckInSteps",NUM,"Status")=$GET(STAT)
+76 SET APPTDATA("CheckInSteps",NUM,"DateTime")=$$FMTE^XLFDT(DATETIME)
End DoDot:1
+77 IF '$DATA(APPTDATA("CheckInSteps"))
SET APPTDATA("CheckInSteps")=""
+78 ;
+79 ;Always send these Patient data elements
+80 SET APPTDATA("DFN")=SDDFN
+81 SET APPTDATA("Patient","EligibilityIEN")=$$GET1^DIQ(2,SDDFN_",",.361,"I")
+82 SET APPTDATA("Patient","Name")=$$GET1^DIQ(2,SDDFN_",",.01,"E")
+83 ; 864
+84 SET APPTDATA("Patient","DateOfBirth")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.03,"I"))
+85 SET APPTDATA("Patient","DateOfDeath")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.351,"I"))
+86 ;
+87 ; patient comments
+88 DO GETPATCOMMENTS(.APPTDATA,IEN)
+89 ; provider data elements
+90 SET PROV=$GET(APPTARY(FN,IENS,.16,"I"))
+91 SET APPTDATA("Provider","ID")=PROV
+92 SET APPTDATA("Provider","Name")=$GET(APPTARY(FN,IENS,.16,"E"))
+93 SET APPTDATA("Provider","SecId")=$$GET1^DIQ(200,PROV,205.1,"I")
+94 QUIT
+95 ;
+1 NEW SUBIEN,COUNT
+2 SET SUBIEN=0
SET COUNT=0
+3 FOR
SET SUBIEN=$ORDER(^SDEC(409.84,IEN,6,SUBIEN))
if 'SUBIEN
QUIT
Begin DoDot:1
+4 SET COUNT=COUNT+1
+5 SET APPTDATA("PatientComments",COUNT)=$$GET1^DIQ(409.846,SUBIEN_","_IEN_",",.01,"E")
End DoDot:1
+6 IF '$DATA(APPTDATA("PatientComments"))
SET APPTDATA("PatientComments",1)=""
+7 QUIT
+8 ;