SDESAPPTREQ40984 ;ALB/ANU,MGD - VISTA SCHEDULING RPCS GET MISSION ELIGIBILITY ; June 16, 2022@15:20
;;5.3;Scheduling;**813,819**;Aug 13, 1993;Build 5
;;Per VHA Directive 6402, this routine should not be modified
;
;External References
;-------------------
; Reference to $$GETS^DIQ in ICR #2056
; Reference to $$GETS1^DIQ in ICR #2056
; Reference to $$SITE^VASITE in ICR #10112
; Reference to $$FIND1^DIC in ICR #2051
; Reference to ^%DT in ICR #10003
;
Q
;
; This entry point is used for both the SDES SET APT REQ 40984 CREATE and SDES SET APT REQ 40984 UPDATE RPCs.
; The parameter list for each RPC must be kept in sync. This includes in the Remote Procedure file definition.
;
ARSET(APTRETURN,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Create/Update Appointment Request
; This RPC creates an entry in SDEC APPOINTMENT file #409.84.
; Input:
;
; SDAPPTSTARTDTTM - [required] - Appointment Start Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
; SDAPPTENDDTTM - [required] - Appointment End Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
; SDPATIENTDFN - [required] - ien of patient file 2
; SDRESOURCE - [required] - Resource, Pointer to SDEC Resource File
; SDATYPID - [optional] - Access Type ID used for 2 purposes:
; if SDATYPID - "WALKIN" then create a walkin appt.
; if SDATYPID - a number, then it is the access type id (used for rebooking)
; SDDDTTM - [optional] - Desired date of Appointment Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
; SDEXTID - [optional] - External ID (free format)
; SDAPPTREQTYPE - [required] - Appt Request type - variable pointer pointer to one of these files:
; APPT REQ - A|<REQ IEN> A|123
; SD WAIT LIST - E|<WL IEN> E|123
; REQUEST/CONSULTATION - C|<CONSULT IEN> C|123
; RECALL REMINDERS - R|^<RECALL IEN> R|123
; SDPROVIEN - [optional] - Provider Pointer to NEW PERSON file #200
; SDCLNID - [required] - Clinic ID pointer to HOSPITAL LOCATION file 44
; SDNOTE - [optional] - Represents a note, Only the 1st 150 characters are used
; SDAPPTYPE - [optional] - Appointment Type, Pointer to #409.1. Only used for Consults
; SDEESTAT - [optional] - This is the flag for either "N"ew or "E"stablished status regarding the SD WAIT LIST (#409.3) file.
; SDAPPTLENGTH - [optional] - Appointment length in minutes (5 - 120)
; SDEAS - [optional] - Enterprise Appointment Scheduling (EAS) Tracking Number associated to an appointment.
;
N HASVLDERRORS,RETURN,HASFIELDS,ELGFIELDSARRAY,VLDERRORS
N SDSAVESTRT,SDRESOURCED,SDECRNOD,SDECWKIN
S (RETURN,VLDERRORS,APTFIELDSARRAY,HASFIELDS)=""
;
S HASVLDERRORS=$$VALIDATE(.VLDERRORS,.SDAPPTSTARTDTTM,.SDAPPTENDDTTM,.SDPATIENTDFN,.SDRESOURCE,.SDATYPID,.SDDDTTM,.SDEXTID,.SDAPPTREQTYPE,.SDPROVIEN,.SDCLNID,.SDNOTE,.SDAPPTYPE,.SDEESTAT,.SDAPPTLENGTH,.SDEAS)
I HASVLDERRORS M RETURN=VLDERRORS
I 'HASVLDERRORS S HASFIELDS=$$CRTAPPT(.APTFIELDSARRAY,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS)
I HASFIELDS M RETURN=APTFIELDSARRAY
;
D BUILDJSON(.APTRETURN,.RETURN)
D CLEANUP
Q
;
VALIDATE(ERRORS,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Validate input
N ERRORFLAG,SDECTMP,SDECERR
;
; Appointment Start Date and Time
S SDAPPTSTARTDTTM=$G(SDAPPTSTARTDTTM,"")
I SDAPPTSTARTDTTM="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,165) Q $D(ERRORFLAG)
S SDAPPTSTARTDTTM=$$ISOTFM^SDAMUTDT(SDAPPTSTARTDTTM,SDCLNID)
I SDAPPTSTARTDTTM=-1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,166) Q $D(ERRORFLAG)
S SDSAVESTRT=SDAPPTSTARTDTTM ;save date/time for consult request
;
; Appointment End Date and Time
S SDAPPTENDDTTM=$G(SDAPPTENDDTTM,"")
I SDAPPTENDDTTM="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,167) Q $D(ERRORFLAG)
S SDAPPTENDDTTM=$$ISOTFM^SDAMUTDT(SDAPPTENDDTTM,SDCLNID)
I SDAPPTENDDTTM=-1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,168) Q $D(ERRORFLAG)
I $L(SDAPPTENDDTTM,".")=1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,168) Q $D(ERRORFLAG)
I SDAPPTSTARTDTTM>SDAPPTENDDTTM S SDECTMP=SDAPPTENDDTTM,SDAPPTENDDTTM=SDAPPTSTARTDTTM,SDAPPTSTARTDTTM=SDECTMP
;
; Patient DFN
S SDPATIENTDFN=$G(SDPATIENTDFN,"")
I SDPATIENTDFN="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,1) Q $D(ERRORFLAG)
I SDPATIENTDFN'="",'$D(^DPT(+SDPATIENTDFN,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,2) Q $D(ERRORFLAG)
;
; Resource
S SDECERR=0
S SDRESOURCE=$G(SDRESOURCE,"")
I SDRESOURCE="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,69) Q $D(ERRORFLAG)
I +SDRESOURCE,'$D(^SDEC(409.831,SDRESOURCE,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,70) Q $D(ERRORFLAG)
I '+SDRESOURCE,'$D(^SDEC(409.831,"B",SDRESOURCE)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,70) Q $D(ERRORFLAG)
S SDRESOURCED=$S(+SDRESOURCE:+SDRESOURCE,1:$O(^SDEC(409.831,"B",SDRESOURCE,0)))
S SDECRNOD=$G(^SDEC(409.831,SDRESOURCED,0))
I SDECRNOD="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,70) Q $D(ERRORFLAG)
;
; Access Type ID
S SDECWKIN=0
S SDATYPID=$G(SDATYPID,"")
I SDATYPID="WALKIN" S SDECWKIN=1
I SDATYPID'?.N&(SDATYPID'="WALKIN") S SDATYPID=""
;
; Desired Date of Appointment
S SDDDTTM=$G(SDDDTTM,"")
I SDDDTTM'="" S SDDDTTM=$$ISOTFM^SDAMUTDT(SDDDTTM,SDCLNID)
I SDDDTTM=-1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,58) Q $D(ERRORFLAG)
I SDDDTTM="",SDATYPID'="WALKIN" S SDDDTTM=$P(SDAPPTSTARTDTTM,".",1)
;
; appt request type
S SDAPPTREQTYPE=$G(SDAPPTREQTYPE,"")
I SDAPPTREQTYPE="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,60) Q $D(ERRORFLAG)
I ";E;R;C;A;"'[(";"_$P(SDAPPTREQTYPE,"|",1)_";") S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,61) Q $D(ERRORFLAG)
I +$P(SDAPPTREQTYPE,"|",2)=0 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,61) Q $D(ERRORFLAG)
I SDAPPTREQTYPE'="" D
.I $P(SDAPPTREQTYPE,"|",1)="E" I '$D(^SDWL(409.3,+$P(SDAPPTREQTYPE,"|",2),0)) S SDAPPTREQTYPE=""
.I $P(SDAPPTREQTYPE,"|",1)="R" I '$D(^SD(403.5,+$P(SDAPPTREQTYPE,"|",2),0)) S SDAPPTREQTYPE=""
.I $P(SDAPPTREQTYPE,"|",1)="C" I '$D(^GMR(123,+$P(SDAPPTREQTYPE,"|",2),0)) S SDAPPTREQTYPE=""
.I $P(SDAPPTREQTYPE,"|",1)="A" I '$D(^SDEC(409.85,+$P(SDAPPTREQTYPE,"|",2),0)) S SDAPPTREQTYPE=""
I SDAPPTREQTYPE="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,61) Q $D(ERRORFLAG)
;
; Clinic IEN
S SDCLNID=$G(SDCLNID,"")
I SDCLNID="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,18) Q $D(ERRORFLAG)
I '$D(^SC(+SDCLNID,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,19) Q $D(ERRORFLAG)
;
; Note
S SDNOTE=$G(SDNOTE,"") S:SDNOTE'="" SDNOTE=$TR($E(SDNOTE,1,150),"^"," ")
;
; APPTYPE
S SDAPPTYPE=$G(SDAPPTYPE,"") I SDAPPTYPE'="",'$D(^SD(409.1,+SDAPPTYPE,0)) S SDAPPTYPE=""
;
; Patient Status
S SDEESTAT=$G(SDEESTAT)
I SDEESTAT="" D
.I $P(SDAPPTREQTYPE,"|",1)="E" S SDEESTAT=$$GET1^DIQ(409.3,$P(SDAPPTREQTYPE,"|",2)_",",27,"I")
.I $P(SDAPPTREQTYPE,"|",1)="A" S SDEESTAT=$$GET1^DIQ(409.3,$P(SDAPPTREQTYPE,"|",2)_",",.02,"I")
S SDEESTAT=$S(SDEESTAT="N":"N",SDEESTAT="NEW":"N",SDEESTAT="E":"E",SDEESTAT="ESTABLISHED":"E",1:"")
;
; Appt length - if passed in, must be 5-120
S SDAPPTLENGTH=$G(SDAPPTLENGTH)
I ((SDAPPTLENGTH'="")&((+SDAPPTLENGTH<5)!(+SDAPPTLENGTH>120))) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,116) Q $D(ERRORFLAG)
;
; validate EAS
S SDEAS=$G(SDEAS,"")
I $L(SDEAS) S SDEAS=$$EASVALIDATE^SDESUTIL(SDEAS)
I SDEAS=-1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,142) Q $D(ERRORFLAG)
;
; validate provider
I '$D(^VA(200,+$G(SDPROVIEN),0)) S SDPROVIEN=""
S SDEXTID=$G(SDEXTID,"")
;
Q $D(ERRORFLAG)
;
CRTAPPT(ELGARRAY,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Create Appt
N HASDATA,SDECAPPTID
S SDECAPPTID=""
S ELGARRAY("Appointment","Code")="0"
S ELGARRAY("Appointment","Message")="Unable to add appointment to SDEC APPOINTMENT file."
S SDECAPPTID=$$SDECADD^SDEC07(SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCED,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDSAVESTRT,SDRESOURCE,SDAPPTYPE,SDEESTAT,1,+SDAPPTLENGTH,SDEAS)
I SDECAPPTID D
.S ELGARRAY("Appointment","Code")="1"
.S ELGARRAY("Appointment","IEN")=SDECAPPTID
.S ELGARRAY("Appointment","Message")="Created an appointment in SDEC APPOINTMENT file."
S HASDATA=($D(ELGARRAY)>1)
Q HASDATA
;
BUILDJSON(JSONRETURN,INPUT) ; Build JSON format
S JSONERROR=""
D ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
Q
;
CLEANUP ; Cleanup
K HASVLDERRORS,RETURN,HASFIELDS,APTFIELDSARRAY,SDSAVESTRT,SDRESOURCED,SDECRNOD,SDECWKIN
K ERRORFLAG
K HASDATA
K JSONERROR
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESAPPTREQ40984 9165 printed Oct 16, 2024@18:56:07 Page 2
SDESAPPTREQ40984 ;ALB/ANU,MGD - VISTA SCHEDULING RPCS GET MISSION ELIGIBILITY ; June 16, 2022@15:20
+1 ;;5.3;Scheduling;**813,819**;Aug 13, 1993;Build 5
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ;External References
+5 ;-------------------
+6 ; Reference to $$GETS^DIQ in ICR #2056
+7 ; Reference to $$GETS1^DIQ in ICR #2056
+8 ; Reference to $$SITE^VASITE in ICR #10112
+9 ; Reference to $$FIND1^DIC in ICR #2051
+10 ; Reference to ^%DT in ICR #10003
+11 ;
+12 QUIT
+13 ;
+14 ; This entry point is used for both the SDES SET APT REQ 40984 CREATE and SDES SET APT REQ 40984 UPDATE RPCs.
+15 ; The parameter list for each RPC must be kept in sync. This includes in the Remote Procedure file definition.
+16 ;
ARSET(APTRETURN,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Create/Update Appointment Request
+1 ; This RPC creates an entry in SDEC APPOINTMENT file #409.84.
+2 ; Input:
+3 ;
+4 ; SDAPPTSTARTDTTM - [required] - Appointment Start Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
+5 ; SDAPPTENDDTTM - [required] - Appointment End Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
+6 ; SDPATIENTDFN - [required] - ien of patient file 2
+7 ; SDRESOURCE - [required] - Resource, Pointer to SDEC Resource File
+8 ; SDATYPID - [optional] - Access Type ID used for 2 purposes:
+9 ; if SDATYPID - "WALKIN" then create a walkin appt.
+10 ; if SDATYPID - a number, then it is the access type id (used for rebooking)
+11 ; SDDDTTM - [optional] - Desired date of Appointment Date and time in ISO 8601 extended format (e.g. 2022-01-19T09:00-04:00)
+12 ; SDEXTID - [optional] - External ID (free format)
+13 ; SDAPPTREQTYPE - [required] - Appt Request type - variable pointer pointer to one of these files:
+14 ; APPT REQ - A|<REQ IEN> A|123
+15 ; SD WAIT LIST - E|<WL IEN> E|123
+16 ; REQUEST/CONSULTATION - C|<CONSULT IEN> C|123
+17 ; RECALL REMINDERS - R|^<RECALL IEN> R|123
+18 ; SDPROVIEN - [optional] - Provider Pointer to NEW PERSON file #200
+19 ; SDCLNID - [required] - Clinic ID pointer to HOSPITAL LOCATION file 44
+20 ; SDNOTE - [optional] - Represents a note, Only the 1st 150 characters are used
+21 ; SDAPPTYPE - [optional] - Appointment Type, Pointer to #409.1. Only used for Consults
+22 ; SDEESTAT - [optional] - This is the flag for either "N"ew or "E"stablished status regarding the SD WAIT LIST (#409.3) file.
+23 ; SDAPPTLENGTH - [optional] - Appointment length in minutes (5 - 120)
+24 ; SDEAS - [optional] - Enterprise Appointment Scheduling (EAS) Tracking Number associated to an appointment.
+25 ;
+26 NEW HASVLDERRORS,RETURN,HASFIELDS,ELGFIELDSARRAY,VLDERRORS
+27 NEW SDSAVESTRT,SDRESOURCED,SDECRNOD,SDECWKIN
+28 SET (RETURN,VLDERRORS,APTFIELDSARRAY,HASFIELDS)=""
+29 ;
+30 SET HASVLDERRORS=$$VALIDATE(.VLDERRORS,.SDAPPTSTARTDTTM,.SDAPPTENDDTTM,.SDPATIENTDFN,.SDRESOURCE,.SDATYPID,.SDDDTTM,.SDEXTID,.SDAPPTREQTYPE,.SDPROVIEN,.SDCLNID,.SDNOTE,.SDAPPTYPE,.SDEESTAT,.SDAPPTLENGTH,.SDEAS)
+31 IF HASVLDERRORS
MERGE RETURN=VLDERRORS
+32 IF 'HASVLDERRORS
SET HASFIELDS=$$CRTAPPT(.APTFIELDSARRAY,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS)
+33 IF HASFIELDS
MERGE RETURN=APTFIELDSARRAY
+34 ;
+35 DO BUILDJSON(.APTRETURN,.RETURN)
+36 DO CLEANUP
+37 QUIT
+38 ;
VALIDATE(ERRORS,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Validate input
+1 NEW ERRORFLAG,SDECTMP,SDECERR
+2 ;
+3 ; Appointment Start Date and Time
+4 SET SDAPPTSTARTDTTM=$GET(SDAPPTSTARTDTTM,"")
+5 IF SDAPPTSTARTDTTM=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,165)
QUIT $DATA(ERRORFLAG)
+6 SET SDAPPTSTARTDTTM=$$ISOTFM^SDAMUTDT(SDAPPTSTARTDTTM,SDCLNID)
+7 IF SDAPPTSTARTDTTM=-1
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,166)
QUIT $DATA(ERRORFLAG)
+8 ;save date/time for consult request
SET SDSAVESTRT=SDAPPTSTARTDTTM
+9 ;
+10 ; Appointment End Date and Time
+11 SET SDAPPTENDDTTM=$GET(SDAPPTENDDTTM,"")
+12 IF SDAPPTENDDTTM=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,167)
QUIT $DATA(ERRORFLAG)
+13 SET SDAPPTENDDTTM=$$ISOTFM^SDAMUTDT(SDAPPTENDDTTM,SDCLNID)
+14 IF SDAPPTENDDTTM=-1
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,168)
QUIT $DATA(ERRORFLAG)
+15 IF $LENGTH(SDAPPTENDDTTM,".")=1
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,168)
QUIT $DATA(ERRORFLAG)
+16 IF SDAPPTSTARTDTTM>SDAPPTENDDTTM
SET SDECTMP=SDAPPTENDDTTM
SET SDAPPTENDDTTM=SDAPPTSTARTDTTM
SET SDAPPTSTARTDTTM=SDECTMP
+17 ;
+18 ; Patient DFN
+19 SET SDPATIENTDFN=$GET(SDPATIENTDFN,"")
+20 IF SDPATIENTDFN=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,1)
QUIT $DATA(ERRORFLAG)
+21 IF SDPATIENTDFN'=""
IF '$DATA(^DPT(+SDPATIENTDFN,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,2)
QUIT $DATA(ERRORFLAG)
+22 ;
+23 ; Resource
+24 SET SDECERR=0
+25 SET SDRESOURCE=$GET(SDRESOURCE,"")
+26 IF SDRESOURCE=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,69)
QUIT $DATA(ERRORFLAG)
+27 IF +SDRESOURCE
IF '$DATA(^SDEC(409.831,SDRESOURCE,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,70)
QUIT $DATA(ERRORFLAG)
+28 IF '+SDRESOURCE
IF '$DATA(^SDEC(409.831,"B",SDRESOURCE))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,70)
QUIT $DATA(ERRORFLAG)
+29 SET SDRESOURCED=$SELECT(+SDRESOURCE:+SDRESOURCE,1:$ORDER(^SDEC(409.831,"B",SDRESOURCE,0)))
+30 SET SDECRNOD=$GET(^SDEC(409.831,SDRESOURCED,0))
+31 IF SDECRNOD=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,70)
QUIT $DATA(ERRORFLAG)
+32 ;
+33 ; Access Type ID
+34 SET SDECWKIN=0
+35 SET SDATYPID=$GET(SDATYPID,"")
+36 IF SDATYPID="WALKIN"
SET SDECWKIN=1
+37 IF SDATYPID'?.N&(SDATYPID'="WALKIN")
SET SDATYPID=""
+38 ;
+39 ; Desired Date of Appointment
+40 SET SDDDTTM=$GET(SDDDTTM,"")
+41 IF SDDDTTM'=""
SET SDDDTTM=$$ISOTFM^SDAMUTDT(SDDDTTM,SDCLNID)
+42 IF SDDDTTM=-1
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,58)
QUIT $DATA(ERRORFLAG)
+43 IF SDDDTTM=""
IF SDATYPID'="WALKIN"
SET SDDDTTM=$PIECE(SDAPPTSTARTDTTM,".",1)
+44 ;
+45 ; appt request type
+46 SET SDAPPTREQTYPE=$GET(SDAPPTREQTYPE,"")
+47 IF SDAPPTREQTYPE=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,60)
QUIT $DATA(ERRORFLAG)
+48 IF ";E;R;C;A;"'[(";"_$PIECE(SDAPPTREQTYPE,"|",1)_";")
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,61)
QUIT $DATA(ERRORFLAG)
+49 IF +$PIECE(SDAPPTREQTYPE,"|",2)=0
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,61)
QUIT $DATA(ERRORFLAG)
+50 IF SDAPPTREQTYPE'=""
Begin DoDot:1
+51 IF $PIECE(SDAPPTREQTYPE,"|",1)="E"
IF '$DATA(^SDWL(409.3,+$PIECE(SDAPPTREQTYPE,"|",2),0))
SET SDAPPTREQTYPE=""
+52 IF $PIECE(SDAPPTREQTYPE,"|",1)="R"
IF '$DATA(^SD(403.5,+$PIECE(SDAPPTREQTYPE,"|",2),0))
SET SDAPPTREQTYPE=""
+53 IF $PIECE(SDAPPTREQTYPE,"|",1)="C"
IF '$DATA(^GMR(123,+$PIECE(SDAPPTREQTYPE,"|",2),0))
SET SDAPPTREQTYPE=""
+54 IF $PIECE(SDAPPTREQTYPE,"|",1)="A"
IF '$DATA(^SDEC(409.85,+$PIECE(SDAPPTREQTYPE,"|",2),0))
SET SDAPPTREQTYPE=""
End DoDot:1
+55 IF SDAPPTREQTYPE=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,61)
QUIT $DATA(ERRORFLAG)
+56 ;
+57 ; Clinic IEN
+58 SET SDCLNID=$GET(SDCLNID,"")
+59 IF SDCLNID=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,18)
QUIT $DATA(ERRORFLAG)
+60 IF '$DATA(^SC(+SDCLNID,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,19)
QUIT $DATA(ERRORFLAG)
+61 ;
+62 ; Note
+63 SET SDNOTE=$GET(SDNOTE,"")
if SDNOTE'=""
SET SDNOTE=$TRANSLATE($EXTRACT(SDNOTE,1,150),"^"," ")
+64 ;
+65 ; APPTYPE
+66 SET SDAPPTYPE=$GET(SDAPPTYPE,"")
IF SDAPPTYPE'=""
IF '$DATA(^SD(409.1,+SDAPPTYPE,0))
SET SDAPPTYPE=""
+67 ;
+68 ; Patient Status
+69 SET SDEESTAT=$GET(SDEESTAT)
+70 IF SDEESTAT=""
Begin DoDot:1
+71 IF $PIECE(SDAPPTREQTYPE,"|",1)="E"
SET SDEESTAT=$$GET1^DIQ(409.3,$PIECE(SDAPPTREQTYPE,"|",2)_",",27,"I")
+72 IF $PIECE(SDAPPTREQTYPE,"|",1)="A"
SET SDEESTAT=$$GET1^DIQ(409.3,$PIECE(SDAPPTREQTYPE,"|",2)_",",.02,"I")
End DoDot:1
+73 SET SDEESTAT=$SELECT(SDEESTAT="N":"N",SDEESTAT="NEW":"N",SDEESTAT="E":"E",SDEESTAT="ESTABLISHED":"E",1:"")
+74 ;
+75 ; Appt length - if passed in, must be 5-120
+76 SET SDAPPTLENGTH=$GET(SDAPPTLENGTH)
+77 IF ((SDAPPTLENGTH'="")&((+SDAPPTLENGTH<5)!(+SDAPPTLENGTH>120)))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,116)
QUIT $DATA(ERRORFLAG)
+78 ;
+79 ; validate EAS
+80 SET SDEAS=$GET(SDEAS,"")
+81 IF $LENGTH(SDEAS)
SET SDEAS=$$EASVALIDATE^SDESUTIL(SDEAS)
+82 IF SDEAS=-1
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,142)
QUIT $DATA(ERRORFLAG)
+83 ;
+84 ; validate provider
+85 IF '$DATA(^VA(200,+$GET(SDPROVIEN),0))
SET SDPROVIEN=""
+86 SET SDEXTID=$GET(SDEXTID,"")
+87 ;
+88 QUIT $DATA(ERRORFLAG)
+89 ;
CRTAPPT(ELGARRAY,SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCE,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDAPPTYPE,SDEESTAT,SDAPPTLENGTH,SDEAS) ; Create Appt
+1 NEW HASDATA,SDECAPPTID
+2 SET SDECAPPTID=""
+3 SET ELGARRAY("Appointment","Code")="0"
+4 SET ELGARRAY("Appointment","Message")="Unable to add appointment to SDEC APPOINTMENT file."
+5 SET SDECAPPTID=$$SDECADD^SDEC07(SDAPPTSTARTDTTM,SDAPPTENDDTTM,SDPATIENTDFN,SDRESOURCED,SDATYPID,SDDDTTM,SDEXTID,SDAPPTREQTYPE,SDPROVIEN,SDCLNID,SDNOTE,SDSAVESTRT,SDRESOURCE,SDAPPTYPE,SDEESTAT,1,+SDAPPTLENGTH,SDEAS)
+6 IF SDECAPPTID
Begin DoDot:1
+7 SET ELGARRAY("Appointment","Code")="1"
+8 SET ELGARRAY("Appointment","IEN")=SDECAPPTID
+9 SET ELGARRAY("Appointment","Message")="Created an appointment in SDEC APPOINTMENT file."
End DoDot:1
+10 SET HASDATA=($DATA(ELGARRAY)>1)
+11 QUIT HASDATA
+12 ;
BUILDJSON(JSONRETURN,INPUT) ; Build JSON format
+1 SET JSONERROR=""
+2 DO ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
+3 QUIT
+4 ;
CLEANUP ; Cleanup
+1 KILL HASVLDERRORS,RETURN,HASFIELDS,APTFIELDSARRAY,SDSAVESTRT,SDRESOURCED,SDECRNOD,SDECWKIN
+2 KILL ERRORFLAG
+3 KILL HASDATA
+4 KILL JSONERROR
+5 QUIT