Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: SDESAPPTREQ2

SDESAPPTREQ2.m

Go to the documentation of this file.
SDESAPPTREQ2 ;ALB/ANU - APPOINTMENT REQUEST CREATE/UPDATE IN FILE2 ;Feb 16, 2022
 ;;5.3;Scheduling;**809**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
 ; This entry point is used for both the SDES SET APT REQ 2 CREATE and SDES SET APT REQ 2 UPDATE RPCs.
 ; The parameter list for each RPC must be kept in sync. This includes in the Remote Procedure file definition.
 ;
ARSET(SDECY,SDAPPTUPD,SDPATIENTDFN,SDCLNIEN,SDAPPTDTTM,SDLABDTTM,SDXRAYDTTM,SDEKGDTTM,SDVSTPURP,SDAPPTTYPE,SDCOLLATERAL,SDSCHREQTYPE,SDNXTAVAAPPT,SDFOLLOWUP) ; Create/Update Appointment Request
 ; INP - Input parameters array
 ;
 ; SDAPPTUPD = (req - integer) 1 for Update and 0 for Create Appointment
 ; SDPATIENTDFN = (req - integer) DFN Pointer to PATIENT file 2
 ; SDCLNIEN = (req - integer) IEN point to HOSPTIAL LOCATION file 44
 ; SDAPPTDTTM = (req - date) appointment date and time in ISO 8601 extended format (e.g. 2022-01-19T20:15:44)
 ; SDLABDTTM = (date) Lab Date/Time
 ; SDXRAYDTTM = (date) X-Ray Date/Time
 ; SDEKGDTTM = (date) EKG Date/Time
 ; SDVSTPURP = (req - integer) Visit Purpose (Values - 1 to 4)
 ; SDAPPTTYPE = (text) Appointment Type, Pointer to #409.1 (required for create)
 ; SDCOLLATERAL = (integer) Collateral Visit (1,0)
 ; SDSCHREQTYPE = (req - text) Scheduling Request Type (N,C,P etc.,)
 ; SDNXTAVAAPPT = (req - integer) Next Available Appointment Indicator (0,1,2,3)
 ; SDFOLLOWUP = (integer) Followup Visit
 ;
 N POP,SDAPTREQ
 ;
 D VALIDATE
 I 'POP D
 .I +SDAPPTUPD=1 D UPDATE Q
 .I +SDAPPTUPD=0 D CREATE Q
 D BUILDER
 Q
 ;
VALIDATE ; Validate
 ;
 S POP=0
 ; 
 ;
 I SDAPPTUPD'=1,SDAPPTUPD'=0 S SDAPTREQ("Error",1)="Invalid Update Flag." Q
 ;
 ; Patient DFN
 S SDPATIENTDFN=$G(SDPATIENTDFN,"")
 I SDPATIENTDFN="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,1) Q
 I SDPATIENTDFN'="",'$D(^DPT(+SDPATIENTDFN,0)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,2) Q
 ;
 ; Clinic IEN
 S SDCLNIEN=$G(SDCLNIEN,"")
 I SDCLNIEN="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,18) Q
 I '$D(^SC(+SDCLNIEN,0)) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,19) Q
 I $$INACTIVE^SDEC32(+SDCLNIEN) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,19) Q
 ;
 ; Appointment Type
 S SDAPPTTYPE=$G(SDAPPTTYPE,"")
 I SDAPPTUPD=0,SDAPPTTYPE="" D ERRLOG^SDESJSON(.SDAPTREQ,60) S POP=1 Q
 I SDAPPTTYPE'="",('$D(^SD(409.1,"B",SDAPPTTYPE))) D ERRLOG^SDESJSON(.SDAPTREQ,61) S POP=1 Q
 I SDAPPTTYPE'="",($D(^SD(409.1,"B",SDAPPTTYPE))) S SDAPPTTYPE=$O(^SD(409.1,"B",SDAPPTTYPE,0))
 ;
 ; Appointment date/time of appt
 S SDAPPTDTTM=$G(SDAPPTDTTM,"")
 I SDAPPTDTTM="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,76) Q
 S SDAPPTDTTM=$$ISOTFM^SDAMUTDT(SDAPPTDTTM,SDCLNIEN)
 ;S SDAPPTDTTM=$$GMTTFM^SDAMUTDT(SDAPPTDTTM)
 I SDAPPTDTTM=-1 S SDAPPTDTTM="",POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,77) Q
 I SDAPPTUPD=0,SDAPPTDTTM<DT S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,59) Q
 ;
 ; Lab Dt/Tm
 S SDLABDTTM=$G(SDLABDTTM,"")
 I SDLABDTTM'="" S SDLABDTTM=$$ISOTFM^SDAMUTDT(SDLABDTTM,SDCLNIEN)
 ;I SDLABDTTM'="" S SDLABDTTM=$$GMTTFM^SDAMUTDT(SDLABDTTM)
 I SDLABDTTM=-1 S SDLABDTTM="",POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,147) Q
 ;
 ; XRAY Dt/Tm
 S SDXRAYDTTM=$G(SDXRAYDTTM,"")
 I SDXRAYDTTM'="" S SDXRAYDTTM=$$ISOTFM^SDAMUTDT(SDXRAYDTTM,SDCLNIEN)
 ;I SDXRAYDTTM'="" S SDXRAYDTTM=$$GMTTFM^SDAMUTDT(SDXRAYDTTM)
 I SDXRAYDTTM=-1 S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,145) Q
 ;
 ; EKG Dt/Tm
 S SDEKGDTTM=$G(SDEKGDTTM,"")
 I SDEKGDTTM'="" S SDEKGDTTM=$$ISOTFM^SDAMUTDT(SDEKGDTTM,SDCLNIEN)
 ;I SDEKGDTTM'="" S SDEKGDTTM=$$GMTTFM^SDAMUTDT(SDEKGDTTM)
 I SDEKGDTTM=-1 S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,146) Q
 ;
 ; Purpose of Visit
 S SDVSTPURP=$G(SDVSTPURP,"")
 S SDVSTPURP=$E(SDVSTPURP,1,1)
 I SDVSTPURP="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,149) Q
 I "1234"'[+SDVSTPURP S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,148) Q
 ;
 ; Collateral Visit
 S SDCOLLATERAL=$G(SDCOLLATERAL,"")
 S SDCOLLATERAL=$E(SDCOLLATERAL,1,1)
 I SDCOLLATERAL'="",("01"'[SDCOLLATERAL) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,150) Q
 ;
 ; Scheduling Request Type
 S SDSCHREQTYPE=$G(SDSCHREQTYPE,"")
 S SDSCHREQTYPE=$E(SDSCHREQTYPE,1,1)
 I SDSCHREQTYPE="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,151) Q
 I ("NCPWMAO"'[SDSCHREQTYPE) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,152) Q
 ;
 ; Next Available Appointment Indicator
 S SDNXTAVAAPPT=$G(SDNXTAVAAPPT,"")
 S SDNXTAVAAPPT=$E(SDNXTAVAAPPT,1,1)
 I SDNXTAVAAPPT="" S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,154) Q
 I ("0123"'[SDNXTAVAAPPT) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,153) Q
 ;
 ; Followup Visit
 S SDFOLLOWUP=$G(SDFOLLOWUP,"")
 I SDFOLLOWUP'="",("01"'[SDFOLLOWUP) S POP=1 D ERRLOG^SDESJSON(.SDAPTREQ,155) Q
 ;
 Q
 ;
CREATE ;Build FDA array to creat a new entry in 2
 ; add appt to file 2
 N SDECFDA,SDECIENS,SDERR
 I $D(^DPT(SDPATIENTDFN,"S",SDAPPTDTTM,0)) S SDAPTREQ("Error",1)="Appointment Already Exists in File #2 for this Date/Time" Q
 S SDECIENS="?+2,"_SDPATIENTDFN_","
 S SDECIENS(2)=SDAPPTDTTM
 S SDECFDA(2.98,SDECIENS,".01")=$$NULLDEL(SDCLNIEN)
 S SDECFDA(2.98,SDECIENS,"3")=$S($G(^DPT(+$G(SDPATIENTDFN),.1))'="":"I",1:"")
 S SDECFDA(2.98,SDECIENS,"5")=$$NULLDEL(SDLABDTTM) ;lab date/time
 S SDECFDA(2.98,SDECIENS,"6")=$$NULLDEL(SDXRAYDTTM) ;xray date/time
 S SDECFDA(2.98,SDECIENS,"7")=$$NULLDEL(SDEKGDTTM) ;ekg date/time
 S SDECFDA(2.98,SDECIENS,"9")=$$NULLDEL(SDVSTPURP) ;Purpose of Visit
 S SDECFDA(2.98,SDECIENS,"9.5")=$$NULLDEL(SDAPPTTYPE)
 S SDECFDA(2.98,SDECIENS,"13")=$$NULLDEL(SDCOLLATERAL) ; Collateral Visit
 S SDECFDA(2.98,SDECIENS,"14")="@"
 S SDECFDA(2.98,SDECIENS,"15")="@"
 S SDECFDA(2.98,SDECIENS,"16")="@"
 S SDECFDA(2.98,SDECIENS,"17")="@"
 S SDECFDA(2.98,SDECIENS,"19")=$$NULLDEL(DUZ) ;data entry clerk
 S SDECFDA(2.98,SDECIENS,"20")=$$NOW^XLFDT
 S SDECFDA(2.98,SDECIENS,"21")="@"
 S SDECFDA(2.98,SDECIENS,"25")=$$NULLDEL(SDSCHREQTYPE) ;scheduling request type
 S SDECFDA(2.98,SDECIENS,"26")=$$NULLDEL(SDNXTAVAAPPT) ;Next ava. appt. indicator
 S SDECFDA(2.98,SDECIENS,"28")=$$NULLDEL(SDFOLLOWUP) ;follow-up visit yes/no
 D UPDATE^DIE("","SDECFDA","SDECIENS","SDERR")
 I $D(SDERR) S SDAPTREQ("Error",1)="Error trying to create Appointment in File #2." Q
 S SDAPTREQ("Success")="Appointment is successfully created."
 Q
 ;
NULLDEL(STR) ;return "@" to delete a field if the new data would be null ;*zeb+tag 722 2/19/19 added to support APPADD
 Q $S(STR]"":STR,1:"@")
 ;
UPDATE ;Find ien for appt in file 2
 ; Update appt in file 2
 N SDECFDA,SDECIENS,SDERR
 I '$D(^DPT(SDPATIENTDFN,"S",SDAPPTDTTM,0)) S SDAPTREQ("Error",1)="Appointment is not found in File #2 for this Date/Time" Q
 S SDECIENS=SDAPPTDTTM_","_SDPATIENTDFN_","
 S SDECFDA(2.98,SDECIENS,".01")=SDCLNIEN
 S SDECFDA(2.98,SDECIENS,"3")=$S($G(^DPT(+$G(SDPATIENTDFN),.1))'="":"I",1:"")
 S SDECFDA(2.98,SDECIENS,"5")=SDLABDTTM ;lab date/time
 S SDECFDA(2.98,SDECIENS,"6")=SDXRAYDTTM ;xray date/time
 S SDECFDA(2.98,SDECIENS,"7")=SDEKGDTTM ;ekg date/time
 S SDECFDA(2.98,SDECIENS,"9")=SDVSTPURP ;Purpose of Visit
 S SDECFDA(2.98,SDECIENS,"9.5")=SDAPPTTYPE
 S SDECFDA(2.98,SDECIENS,"13")=SDCOLLATERAL ; Collateral Visit
 S SDECFDA(2.98,SDECIENS,"14")=""
 S SDECFDA(2.98,SDECIENS,"15")=""
 S SDECFDA(2.98,SDECIENS,"16")=""
 S SDECFDA(2.98,SDECIENS,"17")=""
 S SDECFDA(2.98,SDECIENS,"19")=DUZ ;data entry clerk
 S SDECFDA(2.98,SDECIENS,"20")=$$NOW^XLFDT
 S SDECFDA(2.98,SDECIENS,"25")=SDSCHREQTYPE ;scheduling request type
 S SDECFDA(2.98,SDECIENS,"26")=SDNXTAVAAPPT ;Next ava. appt. indicator
 S SDECFDA(2.98,SDECIENS,"28")=SDFOLLOWUP ;follow-up visit yes/no
 D FILE^DIE("","SDECFDA","SDERR")
 I $D(SDERR) S SDAPTREQ("Error",1)="Error trying to update Appointment in File #2." Q
 S SDAPTREQ("Success")="Appointment is successfully updated."
 Q
 ;
BUILDER ;Convert data to JSON
 N JSONERR
 S JSONERR=""
 D ENCODE^SDESJSON(.SDAPTREQ,.SDECY,.JSONERR)
 Q