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

SDESCHKAPPTOVP.m

Go to the documentation of this file.
SDESCHKAPPTOVP ;ALB/ANU,TJB - VISTA SCHEDULING RPCS - Routine to check for Appointment Overlaps ; June 17, 2024
 ;;5.3;Scheduling;**820,881**;Aug 13, 1993;Build 10
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ;External References
 ;-------------------
 ; Reference to $$GETS^DIQ,$$GETS1^DIQ in ICR #2056
 ;
 Q
 ;
 ;
CHKOVERLAP(RETURNJSON,SDDFN,SDBEGDATE,SDDUR) ;
 ;
 ; Input:
 ;    SDDFN         [Required] = Patient's DFN from PATIENT File #2.
 ;    SDBEGDATE     [Required] = The beginning date/time in ISO8601 Time Format for the search.
 ;    SDDUR         [Required] = Duration of the appointment
 ;
 ; Output:
 ;    RETURNJSON = Returns overlap flag (0-No, 1-Yes) in JSON format. JSON Errors will be returned for any invalid/missing parameters.
 ;
 N RETURN,HASFIELDS,ELGFIELDSARRAY,ELGRETURN
 N ISDFNVALID,ISBEGDTVALID,ISDURVALID
 S (RETURN,ELGFIELDSARRAY,HASFIELDS)=""
 S SDBEGDATE=$G(SDBEGDATE)
 ;
 S ISDFNVALID=$$VALIDATEPTDFN(.ERRORS,$G(SDDFN))
 S ISBEGDTVALID=$$VALIDATEBEGDATE(.ERRORS,.SDBEGDATE)
 S ISDURVALID=$$VALIDATEDUR(.ERRORS,$G(SDDUR))
 ;
 I $D(ERRORS) M RETURN=ERRORS
 I '$D(ERRORS) S HASFIELDS=$$CHKOVERL(.ELGFIELDSARRAY,SDDFN,SDBEGDATE,SDDUR)
 I HASFIELDS M RETURN=ELGFIELDSARRAY
 ;
 D BUILDJSON^SDESBUILDJSON(.RETURNJSON,.RETURN)
 D CLEANUP
 Q
 ;
VALIDATEBEGDATE(ERRORS,SDBEGDATE)   ;Validate Beginning Date
 N ERRORFLAG
 I $G(SDBEGDATE)="" D ERRLOG^SDESJSON(.ERRORS,25) S ERRORFLAG=1 Q $D(ERRORFLAG)
 S SDBEGDATE=$$ISOTFM^SDAMUTDT(SDBEGDATE)
 I $G(SDBEGDATE)=-1 S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,27) Q $D(ERRORFLAG)
 I $P(SDBEGDATE,".",2)="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,27) Q $D(ERRORFLAG)
 Q $D(ERRORFLAG)
 ;
VALIDATEPTDFN(ERRORS,SDDFN) ; VALIDATE PATIENT DFN
 N ERRORFLAG
 I SDDFN="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,1) Q $D(ERRORFLAG)
 I SDDFN'="",'$D(^DPT(SDDFN,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,2) Q $D(ERRORFLAG)
 Q $D(ERRORFLAG)
 ;
VALIDATEDUR(ERRORS,SDDUR) ; Validate Duration
 N ERRORFLAG
 I SDDUR="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,115) Q $D(ERRORFLAG)
 I (+SDDUR<5)!(+SDDUR>240) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,116) Q $D(ERRORFLAG)
 Q $D(ERRORFLAG)
 ;
CHKOVERL(ELGARRAY,SDDFN,SDBEGDATE,SDDUR) ; View Appointment using DFN of the patient
 N SDOVERLAP,SDENDDATE,SDAPPSDATE,SDAPPEDATE,IEN,SDNOD,HASDATA,SDAPPDUR,SDCANDATE
 S SDOVERLAP=0
 S SDENDDATE=$$FMADD^XLFDT(SDBEGDATE,0,0,+SDDUR,0)
 S SDAPPSDATE=$P(SDBEGDATE,".",1)_.0001
 F  S SDAPPSDATE=$O(^SDEC(409.84,"APTDT",SDDFN,SDAPPSDATE)) Q:SDAPPSDATE=""  Q:$P(SDAPPSDATE,".",1)>SDENDDATE  D
 .S IEN=""
 .F  S IEN=$O(^SDEC(409.84,"APTDT",SDDFN,SDAPPSDATE,IEN)) Q:IEN=""  D
 ..S SDNOD=$G(^SDEC(409.84,IEN,0))
 ..Q:SDNOD=""  ;appointment data missing
 ..S SDCANDATE=$$GET1^DIQ(409.84,IEN_",",.12,"I")
 ..Q:$G(SDCANDATE)'=""
 ..S SDAPPEDATE=$$GET1^DIQ(409.84,IEN_",",.02,"I")
 ..S SDAPPDUR=$$GET1^DIQ(409.84,IEN_",",.18,"I")
 ..I SDAPPEDATE="" S SDAPPEDATE=$$FMADD^XLFDT(SDBEGDATE,0,0,+SDAPPDUR,0)
 ..I SDBEGDATE>=SDAPPSDATE,SDBEGDATE<SDAPPEDATE S SDOVERLAP=1
 ..I SDENDDATE>SDAPPSDATE,SDENDDATE<=SDAPPEDATE S SDOVERLAP=1
 I SDOVERLAP S ELGARRAY("Overlap")="1"
 I 'SDOVERLAP S ELGARRAY("Overlap")="0"
 S HASDATA=($D(ELGARRAY)>1)
 Q HASDATA
 Q
 ;
CLEANUP ;
 K RETURNERROR,SDALLAPPTARY,SDBEG,SDEND,ERRORFLAG,ERRORS,ISDFNVALID,ISBEGDTVALID,ISDURVALID
 K SDOVERLAP,SDENDDATE,SDAPPSDATE,SDAPPEDATE,IEN,SDNOD,HASDATA,SDAPPDUR,SDCANDATE
 Q
 ;