SDESREQAPPCREATE ;ALB/RRM,MGD - VISTA SCHEDULING CREATE APPT REQ AND SCHEDULE APPT RPC ;Mar 27, 2023@10:29
;;5.3;Scheduling;**823,826,843**;Aug 13, 1993;Build 9
;;Per VHA Directive 6402, this routine should not be modified
;
;
Q ;No Direct Call
;
; The parameter list for this RPC must be kept in sync.
; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
CREATEREQANDAPPT(RETURNJSON,REQUEST) ;EP for SDES CREATE VET REQ SCHED APPT
; Input:
; REQUEST [Required] - This is the array that contains all necessary data for the creation of the appointment request,
; scheduling the appointment, and then dispositioning the appointment.
; REQUEST("APPOINTMENT END TIME") = (Required) APPT END TIME - ISO FORMAT
; REQUEST("APPOINTMENT LENGTH") = (Required) APPT LENGTH IN MINUTES (5-120)
; REQUEST("APPOINTMENT START TIME") = (Required) APPT START TIME - ISO FORMAT
; REQUEST("CLINIC IEN") = (Required) CLINIC IEN
; REQUEST("CREATE DATE") = (Required) DATE/TIME ENTERED (#409.85,9.5) in ISO8601 date/time format to include offset (e.g. CCYY-MM-DDTHH:MM-NNNN)
; REQUEST("PATIENT INDICATED DATE") = (Required) CID/PID DATE - ISO FORMAT
; REQUEST("DFN") = (Required) PATIENT IEN
; REQUEST("APPOINTMENT REASON") = (Optional) FREE TEXT (1-150)
; REQUEST("COLLATERAL VISIT") = (Optional) COLLATERAL - 1 FOR YES
; REQUEST("APPOINTMENT TYPE IEN") = (Optional) POINTER TO APPOINTMENT TYPE FILE (#409.1)
; REQUEST("APPOINTMENT TYPE NAME") = (Optional) NAME from APPOINTMENT TYPE FILE (#409.1)
; Either APPOINTMENT TYPE IEN or APPOINTMENT TYPE NAME is Required
; REQUEST("EAS") = (Optional) Enterprise APPT Scheduling Tracking Number associated to an appt.
; REQUEST("FOLLOWUP") = (Optional) FOLLOWUP VISIT - 1 FOR YES 0 FOR NO
; REQUEST("INSTITUTION NAME") = (Optional) Institution name from the INSTITUTION file
; REQUEST("MODALITY") = (Optional) Valid Values: FACE2FACE, TELEPHONE, VIDEO
; REQUEST("NOTE") = (Optional) NOTE - FREE TEXT 1-150
; REQUEST("OVERBOOK") = (Optional) OVERBOOK (0 for no, 1 for yes)
; REQUEST("PATIENT COMMENT") = (Optional) Patient-entered comments when using VAOS or other web-service (stored at 409.85,60 a word processing field)
; REQUEST("PATIENT ELIGIBILITY IEN") = (Optional) ELIGIBILITY IEN
; REQUEST("PATIENT PREFERRED END DATE",1) = (Optional) PATIENT PREFERRED END DATE 1 - ISO FORMAT
; REQUEST("PATIENT PREFERRED END DATE",2) = (Optional) PATIENT PREFERRED END DATE 2 - ISO FORMAT
; REQUEST("PATIENT PREFERRED END DATE",3) = (Optional) PATIENT PREFERRED END DATE 3 - ISO FORMAT
; REQUEST("PATIENT PREFERRED START DATE",1)= (Optional) PATIENT PREFERRED START DATE 1 - ISO FORMAT
; REQUEST("PATIENT PREFERRED START DATE",2)= (Optional) PATIENT PREFERRED START DATE 2 - ISO FORMAT
; REQUEST("PATIENT PREFERRED START DATE",3)= (Optional) PATIENT PREFERRED START DATE 3 - ISO FORMAT
; REQUEST("PATIENT STATUS") = (Optional) PATIENT STATUS - "NEW" OR "ESTABLISHED
; REQUEST("PRIORITY") = (Optional) PRIORITY - "ASAP" or FUTURE
; REQUEST("PRIORITY GROUP") = (Optional) ENROLLMENT PRIORITY - GROUP 1 - GROUP 7
; REQUEST("REQUEST COMMENT") = (Optional) REQUEST COMMENT
; REQUEST("SECONDARY STOP CODE") = (Optional) Secondary Stop Code Number pointer to CLINIC STOP file #40.7 used to populate the REQ SECONDARY STOP CODE field in 409.85
; REQUEST("SERVICE CONNECTED") = (Optional) Valid Values: YES, NO
; REQUEST("SERVICE CONNECTED PERCENTAGE") = (Optional) SC % = 0-100
; REQUEST("STATION NUMBER") = (Optional) STATION NUMBER (#99),INSTITUTION (#4)
; REQUEST("STOP CODE") = (Optional) CLINIC STOP pointer to CLINIC STOP file 40.7 used to populate the REQ SERVICE/SPECIALTY field in 409.85
; REQUEST("VAOS GUID") = (Optional) VAOS GUID
;
; Output:
; Successful Return:
; RETURNJSON = Returns the Request and Appointment IEN in JSON formatted string.
; Otherwise, JSON Errors will be returned for any invalid/missing parameters.
;
N APPTARRAY,SDCIDPREFDATE,DIK,DA,REQUESTIEN,EAS,PCMT,SDBEGDATE,INSTITUTIONIEN
N DISPOSITION,DISPBY,DISPDATE,ARY84,ARY44,ARY2,ISAPPTOVERLAP,SDREQBY
N ERRORS,RETURNERROR ;temp data storage for input validation error
N TMPJSONRETURN ;temp data storage for the create appointment json return
N REQRESULT,APPTRESULT ;holder of the decoded JSON format into an array format. the array contains the appointment request data result
N APPOINTMENT ;contains the RETURNJSON array
;
K RETURNJSON ;always kill the return json array
;check if the REQUEST array have data on it before going further.
I $O(REQUEST(""))="" D Q
. S ERRORS("Error",1)="The REQUEST array that would be used to create the appointment contains no data. There is nothing to process."
. D SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
;
S SDCIDPREFDATE=$G(REQUEST("PATIENT INDICATED DATE"))
S REQUEST("REQUESTED BY")="PATIENT" ;always REQUESTED BY PATIENT.
S REQUEST("REQUEST SUB TYPE")="APPT" ;always APPT for APPOINTMENT.
;
D VALIDATE^SDESCREATEAPPREQ(.REQUEST,.INSTITUTIONIEN,.ERRORS)
S REQUEST("PATIENT INDICATED DATE")=SDCIDPREFDATE ;put back the ISO format
D BUILDAPPTARRAY(.REQUEST,.REQRESULT,.APPTARRAY)
D POPULATEARRAYS^SDESCRTAPPTWRAP(.APPTARRAY,.ARY84,.ARY44,.ARY2)
D VALIDATE^SDESCREATEAPPT(.ERRORS,.ARY84)
D VALIDATE^SDESCREATEAPPT2(.ERRORS,.ARY2)
D RETURNERR(.ERRORS)
D VALIDATE^SDESCREATEAPPT44(.ERRORS,.ARY44)
I $O(ERRORS("Error",""))'="" D SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON),CLEANUP Q
;
;check if the requested appointment is overlapping
I $G(REQUEST("DFN"))'="",$G(REQUEST("APPOINTMENT START TIME"))'="",$G(REQUEST("APPOINTMENT LENGTH"))'="" D Q:$G(TMPJSONRETURN("Overlap"))=1
. S SDBEGDATE=$$ISOTFM^SDAMUTDT(REQUEST("APPOINTMENT START TIME"))
. S ISAPPTOVERLAP=$$CHKOVERL^SDESCHKAPPTOVP(.TMPJSONRETURN,$G(REQUEST("DFN")),SDBEGDATE,$G(REQUEST("APPOINTMENT LENGTH")))
. I $G(TMPJSONRETURN("Overlap"))=1 S ERRORS=1,ERRORS("Error",1)="Overlapping Appointment" D SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON),CLEANUP Q
;
;create the appointment request in File #409.85
S REQUEST("PATIENT INDICATED DATE")=$$ISOTFM^SDAMUTDT($G(SDCIDPREFDATE))
S REQUESTIEN=$$BUILDER^SDESCREATEAPPREQ(.REQUEST,.INSTITUTIONIEN)
S REQRESULT("Request","IEN")=$G(REQUESTIEN)
;
;create/schedule the appointment in File #409.84, File #44, and File #2
S APPTARRAY(8)="A|"_$G(REQUESTIEN)
K TMPJSONRETURN D CREATEAPPTS^SDESCRTAPPTWRAP(.TMPJSONRETURN,.APPTARRAY)
D DECODE^XLFJSON("TMPJSONRETURN","APPTRESULT","ERROR")
;if in the event an error occurred during the creation and scheduling of the appointment, delete the appointment request
I $O(APPTRESULT("Error",""))'="" D Q
. S DIK="^SDEC(409.85,",DA=$G(REQRESULT("Request","IEN")) D ^DIK
. M RETURNERROR=APPTRESULT
. D SETEMPTYOBJECT(.RETURNERROR) ;set the return object into null if an error occur
. D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURNERROR)
;
;If everything is successful, disposition the appointment request and create the JSON RETURN back to the calling application
K TMPJSONRETURN
S REQUESTIEN=$G(REQRESULT("Request","IEN"))
S EAS=$G(REQUEST("EAS"))
S PCMT=$G(REQUEST("PATIENT COMMENT"))
S DISPOSITION="REMOVED/SCHEDULED-ASSIGNED"
S DISPBY=$G(DUZ)
S DISPDATE=$TR($$FMTE^XLFDT($$NOW^XLFDT,"7DZ"),"/","-")
D DISPOSITION^SDESARCLOSE(.TMPJSONRETURN,$G(REQUESTIEN),$G(DISPOSITION),$G(DISPBY),$G(DISPDATE),$G(EAS),$G(PCMT))
M APPOINTMENT=REQRESULT
M APPOINTMENT=APPTRESULT
D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.APPOINTMENT)
D CLEANUP
Q
;
BUILDAPPTARRAY(REQUEST,REQRESULT,APPTARRAY) ;build the appointment array based from the REQUEST array
N CLINICRES
S CLINICRES=$S($G(REQUEST("CLINIC IEN"))="":"",1:$$GETRES^SDESINPUTVALUTL($G(REQUEST("CLINIC IEN")),1))
S APPTARRAY(1)=$G(REQUEST("APPOINTMENT START TIME"))
S APPTARRAY(2)=REQUEST("APPOINTMENT END TIME")
S APPTARRAY(3)=$G(REQUEST("DFN"))
S APPTARRAY(4)=CLINICRES ;CLINIC RESOURCE
S APPTARRAY(5)="" ;defaulted to Null = not a walk-in appointment
S APPTARRAY(6)=$G(REQUEST("PATIENT INDICATED DATE")) ;this is the CID/PID Date Preferred
S APPTARRAY(7)="" ;this is the EXTERNAL ID - (FREE TEXT 1-50), defaulted to NULL since this not needed
S APPTARRAY(8)="A|"_$G(REQRESULT("Request","IEN"))
S APPTARRAY(9)="" ;Not Needed since this request is always be by PATIENT
S APPTARRAY(10)=$G(REQUEST("CLINIC IEN"))
S APPTARRAY(11)=$G(REQUEST("NOTE"))
S APPTARRAY(12)=$$GET1^DIQ(409.1,$G(REQUEST("APPOINTMENT TYPE IEN")),.01,"E")
S APPTARRAY(12.5)=$G(REQUEST("APPOINTMENT TYPE NAME"))
S APPTARRAY(13)=$G(REQUEST("PATIENT STATUS"))
S APPTARRAY(14)=$G(REQUEST("APPOINTMENT LENGTH"))
S APPTARRAY(15)=$G(REQUEST("SERVICE CONNECTED"))
S APPTARRAY(16)=$G(REQUEST("SERVICE CONNECTED PERCENTAGE"))
S APPTARRAY(17)="FALSE" ;MRTC is set to FALSE since all appointment coming from VAOS are ALL SINGLE APPOINTMENT
S APPTARRAY(18)="" ;PARENT REQUEST (APPT REQUEST IEN) is set to NULL, all appointment coming from VAOS are ALL SINGLE APPOINTMENT
S APPTARRAY(19)=$G(REQUEST("EAS"))
S APPTARRAY(20)=$G(REQUEST("APPOINTMENT REASON")) ;This is the APPOINTMENT REASON - defaulting to NULL
S APPTARRAY(21)=$G(REQUEST("PATIENT ELIGIBILITY IEN")) ;This is PATIENT ELIGIBILITY IEN pointer to DIC(8
S APPTARRAY(22)=$G(REQUEST("OVERBOOK")) ;OVERBOOK (0 for no, 1 for yes)
S APPTARRAY(23)="" ;LAB DATE/TIME - ISO FORMAT
S APPTARRAY(24)="" ;XRAY DATE/TIME - ISO FORMAT
S APPTARRAY(25)="" ;EKG DATE/TIME - ISO FORMAT
S APPTARRAY(26)=3 ;Always set to '3' FOR SCHEDULED VISIT -this is per Judy Mercado
S APPTARRAY(27)=$G(REQUEST("COLLATERAL VISIT")) ;COLLATERAL - 1 FOR YES
S APPTARRAY(28)="P" ;Always set to 'P' FOR OTHER THAN 'NEXT AVA.' (PATIENT REQ.)-this is per Judy Mercado
S APPTARRAY(29)=0 ;Always set to '0' FOR NOT INDICATED TO BE A 'NEXT AVA.' APPT -this is per Judy Mercado
S APPTARRAY(30)=$G(REQUEST("FOLLOWUP"))
Q
;
SETERRORRETURN(ERRORS,RETURNERROR,RETURNJSON) ;
M RETURNERROR=ERRORS
D SETEMPTYOBJECT(.RETURNERROR) ;set the return object into null if an error occur
D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURNERROR)
Q
;
SETEMPTYOBJECT(RETURNERROR) ;set the return object into null if an error occur
S RETURNERROR("Request","IEN")=""
S RETURNERROR("Appointment","IEN")=""
Q
;
CLEANUP ;
K ERRORS,RETURNERROR,ISDFNVALID,ISDATETIMEVALID,ISEASVALID,INSTITUTIONIEN,ISCLINSTOPVALID,ISREQUESTBYVALID,ISPROVIDERVALID,ISMODALITYVALID,ISMODALINVALID
K ISPIDVALID,ISPRIGROUPVALID,ISREQTYPEVALID,ISPRIORITYVALID,ISSERVCONNVALID,ISAPPTTYPEVALID,ISPATSTATVALID,ISDATEPREFVALID,ISMTRCDATAVALID,ISCPRSDATAVALID
Q
;
RETURNERR(ERRORS) ;
N LASTSUB,CNTR
;this error will always be generated since the appointment request IEN do not yet exist yet
;when the appointment array is validated
S LASTSUB=$O(ERRORS("Error",""),-1),CNTR=0
F CNTR=1:1:LASTSUB I $G(ERRORS("Error",CNTR))["Appointment Request Type" K ERRORS("Error",CNTR)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESREQAPPCREATE 12001 printed Dec 13, 2024@02:57:41 Page 2
SDESREQAPPCREATE ;ALB/RRM,MGD - VISTA SCHEDULING CREATE APPT REQ AND SCHEDULE APPT RPC ;Mar 27, 2023@10:29
+1 ;;5.3;Scheduling;**823,826,843**;Aug 13, 1993;Build 9
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ;
+5 ;No Direct Call
QUIT
+6 ;
+7 ; The parameter list for this RPC must be kept in sync.
+8 ; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
CREATEREQANDAPPT(RETURNJSON,REQUEST) ;EP for SDES CREATE VET REQ SCHED APPT
+1 ; Input:
+2 ; REQUEST [Required] - This is the array that contains all necessary data for the creation of the appointment request,
+3 ; scheduling the appointment, and then dispositioning the appointment.
+4 ; REQUEST("APPOINTMENT END TIME") = (Required) APPT END TIME - ISO FORMAT
+5 ; REQUEST("APPOINTMENT LENGTH") = (Required) APPT LENGTH IN MINUTES (5-120)
+6 ; REQUEST("APPOINTMENT START TIME") = (Required) APPT START TIME - ISO FORMAT
+7 ; REQUEST("CLINIC IEN") = (Required) CLINIC IEN
+8 ; REQUEST("CREATE DATE") = (Required) DATE/TIME ENTERED (#409.85,9.5) in ISO8601 date/time format to include offset (e.g. CCYY-MM-DDTHH:MM-NNNN)
+9 ; REQUEST("PATIENT INDICATED DATE") = (Required) CID/PID DATE - ISO FORMAT
+10 ; REQUEST("DFN") = (Required) PATIENT IEN
+11 ; REQUEST("APPOINTMENT REASON") = (Optional) FREE TEXT (1-150)
+12 ; REQUEST("COLLATERAL VISIT") = (Optional) COLLATERAL - 1 FOR YES
+13 ; REQUEST("APPOINTMENT TYPE IEN") = (Optional) POINTER TO APPOINTMENT TYPE FILE (#409.1)
+14 ; REQUEST("APPOINTMENT TYPE NAME") = (Optional) NAME from APPOINTMENT TYPE FILE (#409.1)
+15 ; Either APPOINTMENT TYPE IEN or APPOINTMENT TYPE NAME is Required
+16 ; REQUEST("EAS") = (Optional) Enterprise APPT Scheduling Tracking Number associated to an appt.
+17 ; REQUEST("FOLLOWUP") = (Optional) FOLLOWUP VISIT - 1 FOR YES 0 FOR NO
+18 ; REQUEST("INSTITUTION NAME") = (Optional) Institution name from the INSTITUTION file
+19 ; REQUEST("MODALITY") = (Optional) Valid Values: FACE2FACE, TELEPHONE, VIDEO
+20 ; REQUEST("NOTE") = (Optional) NOTE - FREE TEXT 1-150
+21 ; REQUEST("OVERBOOK") = (Optional) OVERBOOK (0 for no, 1 for yes)
+22 ; REQUEST("PATIENT COMMENT") = (Optional) Patient-entered comments when using VAOS or other web-service (stored at 409.85,60 a word processing field)
+23 ; REQUEST("PATIENT ELIGIBILITY IEN") = (Optional) ELIGIBILITY IEN
+24 ; REQUEST("PATIENT PREFERRED END DATE",1) = (Optional) PATIENT PREFERRED END DATE 1 - ISO FORMAT
+25 ; REQUEST("PATIENT PREFERRED END DATE",2) = (Optional) PATIENT PREFERRED END DATE 2 - ISO FORMAT
+26 ; REQUEST("PATIENT PREFERRED END DATE",3) = (Optional) PATIENT PREFERRED END DATE 3 - ISO FORMAT
+27 ; REQUEST("PATIENT PREFERRED START DATE",1)= (Optional) PATIENT PREFERRED START DATE 1 - ISO FORMAT
+28 ; REQUEST("PATIENT PREFERRED START DATE",2)= (Optional) PATIENT PREFERRED START DATE 2 - ISO FORMAT
+29 ; REQUEST("PATIENT PREFERRED START DATE",3)= (Optional) PATIENT PREFERRED START DATE 3 - ISO FORMAT
+30 ; REQUEST("PATIENT STATUS") = (Optional) PATIENT STATUS - "NEW" OR "ESTABLISHED
+31 ; REQUEST("PRIORITY") = (Optional) PRIORITY - "ASAP" or FUTURE
+32 ; REQUEST("PRIORITY GROUP") = (Optional) ENROLLMENT PRIORITY - GROUP 1 - GROUP 7
+33 ; REQUEST("REQUEST COMMENT") = (Optional) REQUEST COMMENT
+34 ; REQUEST("SECONDARY STOP CODE") = (Optional) Secondary Stop Code Number pointer to CLINIC STOP file #40.7 used to populate the REQ SECONDARY STOP CODE field in 409.85
+35 ; REQUEST("SERVICE CONNECTED") = (Optional) Valid Values: YES, NO
+36 ; REQUEST("SERVICE CONNECTED PERCENTAGE") = (Optional) SC % = 0-100
+37 ; REQUEST("STATION NUMBER") = (Optional) STATION NUMBER (#99),INSTITUTION (#4)
+38 ; REQUEST("STOP CODE") = (Optional) CLINIC STOP pointer to CLINIC STOP file 40.7 used to populate the REQ SERVICE/SPECIALTY field in 409.85
+39 ; REQUEST("VAOS GUID") = (Optional) VAOS GUID
+40 ;
+41 ; Output:
+42 ; Successful Return:
+43 ; RETURNJSON = Returns the Request and Appointment IEN in JSON formatted string.
+44 ; Otherwise, JSON Errors will be returned for any invalid/missing parameters.
+45 ;
+46 NEW APPTARRAY,SDCIDPREFDATE,DIK,DA,REQUESTIEN,EAS,PCMT,SDBEGDATE,INSTITUTIONIEN
+47 NEW DISPOSITION,DISPBY,DISPDATE,ARY84,ARY44,ARY2,ISAPPTOVERLAP,SDREQBY
+48 ;temp data storage for input validation error
NEW ERRORS,RETURNERROR
+49 ;temp data storage for the create appointment json return
NEW TMPJSONRETURN
+50 ;holder of the decoded JSON format into an array format. the array contains the appointment request data result
NEW REQRESULT,APPTRESULT
+51 ;contains the RETURNJSON array
NEW APPOINTMENT
+52 ;
+53 ;always kill the return json array
KILL RETURNJSON
+54 ;check if the REQUEST array have data on it before going further.
+55 IF $ORDER(REQUEST(""))=""
Begin DoDot:1
+56 SET ERRORS("Error",1)="The REQUEST array that would be used to create the appointment contains no data. There is nothing to process."
+57 DO SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
End DoDot:1
QUIT
+58 ;
+59 SET SDCIDPREFDATE=$GET(REQUEST("PATIENT INDICATED DATE"))
+60 ;always REQUESTED BY PATIENT.
SET REQUEST("REQUESTED BY")="PATIENT"
+61 ;always APPT for APPOINTMENT.
SET REQUEST("REQUEST SUB TYPE")="APPT"
+62 ;
+63 DO VALIDATE^SDESCREATEAPPREQ(.REQUEST,.INSTITUTIONIEN,.ERRORS)
+64 ;put back the ISO format
SET REQUEST("PATIENT INDICATED DATE")=SDCIDPREFDATE
+65 DO BUILDAPPTARRAY(.REQUEST,.REQRESULT,.APPTARRAY)
+66 DO POPULATEARRAYS^SDESCRTAPPTWRAP(.APPTARRAY,.ARY84,.ARY44,.ARY2)
+67 DO VALIDATE^SDESCREATEAPPT(.ERRORS,.ARY84)
+68 DO VALIDATE^SDESCREATEAPPT2(.ERRORS,.ARY2)
+69 DO RETURNERR(.ERRORS)
+70 DO VALIDATE^SDESCREATEAPPT44(.ERRORS,.ARY44)
+71 IF $ORDER(ERRORS("Error",""))'=""
DO SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
DO CLEANUP
QUIT
+72 ;
+73 ;check if the requested appointment is overlapping
+74 IF $GET(REQUEST("DFN"))'=""
IF $GET(REQUEST("APPOINTMENT START TIME"))'=""
IF $GET(REQUEST("APPOINTMENT LENGTH"))'=""
Begin DoDot:1
+75 SET SDBEGDATE=$$ISOTFM^SDAMUTDT(REQUEST("APPOINTMENT START TIME"))
+76 SET ISAPPTOVERLAP=$$CHKOVERL^SDESCHKAPPTOVP(.TMPJSONRETURN,$GET(REQUEST("DFN")),SDBEGDATE,$GET(REQUEST("APPOINTMENT LENGTH")))
+77 IF $GET(TMPJSONRETURN("Overlap"))=1
SET ERRORS=1
SET ERRORS("Error",1)="Overlapping Appointment"
DO SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
DO CLEANUP
QUIT
End DoDot:1
if $GET(TMPJSONRETURN("Overlap"))=1
QUIT
+78 ;
+79 ;create the appointment request in File #409.85
+80 SET REQUEST("PATIENT INDICATED DATE")=$$ISOTFM^SDAMUTDT($GET(SDCIDPREFDATE))
+81 SET REQUESTIEN=$$BUILDER^SDESCREATEAPPREQ(.REQUEST,.INSTITUTIONIEN)
+82 SET REQRESULT("Request","IEN")=$GET(REQUESTIEN)
+83 ;
+84 ;create/schedule the appointment in File #409.84, File #44, and File #2
+85 SET APPTARRAY(8)="A|"_$GET(REQUESTIEN)
+86 KILL TMPJSONRETURN
DO CREATEAPPTS^SDESCRTAPPTWRAP(.TMPJSONRETURN,.APPTARRAY)
+87 DO DECODE^XLFJSON("TMPJSONRETURN","APPTRESULT","ERROR")
+88 ;if in the event an error occurred during the creation and scheduling of the appointment, delete the appointment request
+89 IF $ORDER(APPTRESULT("Error",""))'=""
Begin DoDot:1
+90 SET DIK="^SDEC(409.85,"
SET DA=$GET(REQRESULT("Request","IEN"))
DO ^DIK
+91 MERGE RETURNERROR=APPTRESULT
+92 ;set the return object into null if an error occur
DO SETEMPTYOBJECT(.RETURNERROR)
+93 DO BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURNERROR)
End DoDot:1
QUIT
+94 ;
+95 ;If everything is successful, disposition the appointment request and create the JSON RETURN back to the calling application
+96 KILL TMPJSONRETURN
+97 SET REQUESTIEN=$GET(REQRESULT("Request","IEN"))
+98 SET EAS=$GET(REQUEST("EAS"))
+99 SET PCMT=$GET(REQUEST("PATIENT COMMENT"))
+100 SET DISPOSITION="REMOVED/SCHEDULED-ASSIGNED"
+101 SET DISPBY=$GET(DUZ)
+102 SET DISPDATE=$TRANSLATE($$FMTE^XLFDT($$NOW^XLFDT,"7DZ"),"/","-")
+103 DO DISPOSITION^SDESARCLOSE(.TMPJSONRETURN,$GET(REQUESTIEN),$GET(DISPOSITION),$GET(DISPBY),$GET(DISPDATE),$GET(EAS),$GET(PCMT))
+104 MERGE APPOINTMENT=REQRESULT
+105 MERGE APPOINTMENT=APPTRESULT
+106 DO BUILDJSON^SDESBUILDJSON(.RETURNJSON,.APPOINTMENT)
+107 DO CLEANUP
+108 QUIT
+109 ;
BUILDAPPTARRAY(REQUEST,REQRESULT,APPTARRAY) ;build the appointment array based from the REQUEST array
+1 NEW CLINICRES
+2 SET CLINICRES=$SELECT($GET(REQUEST("CLINIC IEN"))="":"",1:$$GETRES^SDESINPUTVALUTL($GET(REQUEST("CLINIC IEN")),1))
+3 SET APPTARRAY(1)=$GET(REQUEST("APPOINTMENT START TIME"))
+4 SET APPTARRAY(2)=REQUEST("APPOINTMENT END TIME")
+5 SET APPTARRAY(3)=$GET(REQUEST("DFN"))
+6 ;CLINIC RESOURCE
SET APPTARRAY(4)=CLINICRES
+7 ;defaulted to Null = not a walk-in appointment
SET APPTARRAY(5)=""
+8 ;this is the CID/PID Date Preferred
SET APPTARRAY(6)=$GET(REQUEST("PATIENT INDICATED DATE"))
+9 ;this is the EXTERNAL ID - (FREE TEXT 1-50), defaulted to NULL since this not needed
SET APPTARRAY(7)=""
+10 SET APPTARRAY(8)="A|"_$GET(REQRESULT("Request","IEN"))
+11 ;Not Needed since this request is always be by PATIENT
SET APPTARRAY(9)=""
+12 SET APPTARRAY(10)=$GET(REQUEST("CLINIC IEN"))
+13 SET APPTARRAY(11)=$GET(REQUEST("NOTE"))
+14 SET APPTARRAY(12)=$$GET1^DIQ(409.1,$GET(REQUEST("APPOINTMENT TYPE IEN")),.01,"E")
+15 SET APPTARRAY(12.5)=$GET(REQUEST("APPOINTMENT TYPE NAME"))
+16 SET APPTARRAY(13)=$GET(REQUEST("PATIENT STATUS"))
+17 SET APPTARRAY(14)=$GET(REQUEST("APPOINTMENT LENGTH"))
+18 SET APPTARRAY(15)=$GET(REQUEST("SERVICE CONNECTED"))
+19 SET APPTARRAY(16)=$GET(REQUEST("SERVICE CONNECTED PERCENTAGE"))
+20 ;MRTC is set to FALSE since all appointment coming from VAOS are ALL SINGLE APPOINTMENT
SET APPTARRAY(17)="FALSE"
+21 ;PARENT REQUEST (APPT REQUEST IEN) is set to NULL, all appointment coming from VAOS are ALL SINGLE APPOINTMENT
SET APPTARRAY(18)=""
+22 SET APPTARRAY(19)=$GET(REQUEST("EAS"))
+23 ;This is the APPOINTMENT REASON - defaulting to NULL
SET APPTARRAY(20)=$GET(REQUEST("APPOINTMENT REASON"))
+24 ;This is PATIENT ELIGIBILITY IEN pointer to DIC(8
SET APPTARRAY(21)=$GET(REQUEST("PATIENT ELIGIBILITY IEN"))
+25 ;OVERBOOK (0 for no, 1 for yes)
SET APPTARRAY(22)=$GET(REQUEST("OVERBOOK"))
+26 ;LAB DATE/TIME - ISO FORMAT
SET APPTARRAY(23)=""
+27 ;XRAY DATE/TIME - ISO FORMAT
SET APPTARRAY(24)=""
+28 ;EKG DATE/TIME - ISO FORMAT
SET APPTARRAY(25)=""
+29 ;Always set to '3' FOR SCHEDULED VISIT -this is per Judy Mercado
SET APPTARRAY(26)=3
+30 ;COLLATERAL - 1 FOR YES
SET APPTARRAY(27)=$GET(REQUEST("COLLATERAL VISIT"))
+31 ;Always set to 'P' FOR OTHER THAN 'NEXT AVA.' (PATIENT REQ.)-this is per Judy Mercado
SET APPTARRAY(28)="P"
+32 ;Always set to '0' FOR NOT INDICATED TO BE A 'NEXT AVA.' APPT -this is per Judy Mercado
SET APPTARRAY(29)=0
+33 SET APPTARRAY(30)=$GET(REQUEST("FOLLOWUP"))
+34 QUIT
+35 ;
SETERRORRETURN(ERRORS,RETURNERROR,RETURNJSON) ;
+1 MERGE RETURNERROR=ERRORS
+2 ;set the return object into null if an error occur
DO SETEMPTYOBJECT(.RETURNERROR)
+3 DO BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURNERROR)
+4 QUIT
+5 ;
SETEMPTYOBJECT(RETURNERROR) ;set the return object into null if an error occur
+1 SET RETURNERROR("Request","IEN")=""
+2 SET RETURNERROR("Appointment","IEN")=""
+3 QUIT
+4 ;
CLEANUP ;
+1 KILL ERRORS,RETURNERROR,ISDFNVALID,ISDATETIMEVALID,ISEASVALID,INSTITUTIONIEN,ISCLINSTOPVALID,ISREQUESTBYVALID,ISPROVIDERVALID,ISMODALITYVALID,ISMODALINVALID
+2 KILL ISPIDVALID,ISPRIGROUPVALID,ISREQTYPEVALID,ISPRIORITYVALID,ISSERVCONNVALID,ISAPPTTYPEVALID,ISPATSTATVALID,ISDATEPREFVALID,ISMTRCDATAVALID,ISCPRSDATAVALID
+3 QUIT
+4 ;
RETURNERR(ERRORS) ;
+1 NEW LASTSUB,CNTR
+2 ;this error will always be generated since the appointment request IEN do not yet exist yet
+3 ;when the appointment array is validated
+4 SET LASTSUB=$ORDER(ERRORS("Error",""),-1)
SET CNTR=0
+5 FOR CNTR=1:1:LASTSUB
IF $GET(ERRORS("Error",CNTR))["Appointment Request Type"
KILL ERRORS("Error",CNTR)
+6 QUIT