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

SDES2APPTCLNLST.m

Go to the documentation of this file.
SDES2APPTCLNLST ;ALB/TJB - SDES2 GET APPTS CLINIEN LIST  ;DEC 1,2023
 ;;5.3;Scheduling;**867**;Aug 13, 1993;Build 8
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; Reference to PATIENT in ICR #10035
 ; COPY OF SDESAPPT4
 Q
 ;
 ;INPUT - 
 ; 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
 ;
APPTBYCLNLIST(RETNJSON,SDCONTEXT,SDPARAM) ;
 N APPTLIST,IENCOUNT,YESTERDAYEXTERNL,TODAYEXTERNAL,ERRORS
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 D VALPARAM(.ERRORS,.SDPARAM)
 I $D(ERRORS) S ERRORS("Clinics")="" D BUILDJSON^SDES2JSON(.RETNJSON,.ERRORS) Q
 ;
 D BUILDCLINAPPT(.RETNJSON,.SDCONTEXT,.SDPARAM,.ERRORS)
 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
 ;
BUILDCLINAPPT(RETNJSON,SDCONTEXT,SDPARAM,ERRORS) ; Build the list of appointments for clinics specified
 N APPTLIST,IENCOUNT,YESTERDAYFM,TODAYFM,CLINTODAY,TODAYISO,TODAYEOD,SDCLINIC,INDEX
 S TODAYFM=$$NOW^XLFDT
 S TODAYISO=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
 ;
 S INDEX="",IENCOUNT=0
 F  S INDEX=$O(SDPARAM("CLINIC IEN",INDEX)) Q:INDEX=""  S IENCOUNT=IENCOUNT+1,SDCLINIC=SDPARAM("CLINIC IEN",INDEX) D
 . N TEMPLIST,VALDT
 . ; The date conversions need to be done on a per clinic basis because of timezones
 . S CLINTODAY=$P($$ISOTFM^SDAMUTDT(TODAYISO,SDCLINIC),".",1)
 . S YESTERDAYFM=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
 . S TODAYEOD=$$FMADD^XLFDT(CLINTODAY,"",23,59,59)
 . D APPTBYCLINIC2EXT(.TEMPLIST,SDCLINIC,YESTERDAYFM,TODAYEOD,$G(SDCONTEXT("USER DUZ")),"")
 . N DIVISION,INSTITUT,STATION
 . S DIVISION=$$GET1^DIQ(44,SDCLINIC,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")=SDCLINIC
 . M APPTLIST("Clinics",IENCOUNT)=TEMPLIST
 D BUILDJSON^SDES2JSON(.RETNJSON,.APPTLIST)
 Q
 ;
APPTBYCLINIC2EXT(SDAPPT,SDCLINICIEN,SDBEG,SDEND,SDDUZ,SDEAS) ;
 N POP,APPTIEN,APPTDT,APPTDATA,COUNTER,JSONERR,DFN,PATIENT,RESTYPE,SDRESIEN
 N SDBEGDATE,SDENDDATE,SDVIEWAPPTBY,SDAPPTIEN,SDALLAPPTARY
 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-.0001
 . S SDEND=SDEND+.0001
 . 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
 ... S SDVIEWAPPTBY=2 ;view appointment using APPOINTMENT IEN from SDEC APPOINTMENT File #409.84
 ... S SDAPPTIEN=APPTIEN
 ... S DFN=$$GET1^DIQ(409.84,SDAPPTIEN,.05,"I")
 ... S SDBEGDATE=$$GET1^DIQ(409.84,SDAPPTIEN,.01,"I")
 ... S SDENDDATE=$$GET1^DIQ(409.84,SDAPPTIEN,.02,"I")
 ... D GETAPPOINTMENTS^SDESGETAPPTWRAP4(.SDALLAPPTARY,DFN,SDBEGDATE,SDENDDATE,SDVIEWAPPTBY,SDAPPTIEN)
 ... S COUNTER=$G(COUNTER)+1
 ... M SDAPPT("Appt",COUNTER)=SDALLAPPTARY("Appointment",1)
 ... ;
 ... ;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
 ;