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

SDES2CLINICLIST.m

Go to the documentation of this file.
SDES2CLINICLIST ;ALB/TJB - SDES2 GET APPTS BY CLIN LIST2 ;DEC 14,2023
 ;;5.3;Scheduling;**869**;Aug 13, 1993;Build 13
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 ; The SDCONTEXT array is controlled by the Acheron application and its fields are
 ; needed for the storage of the required auditing information.
 ;
 ; 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
APPTBYCLINICLIST(RETNJSON,SDCONTEXT,SDPARAM) ;
 N ERRORS
 D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
 D VALPARAM(.ERRORS,.SDPARAM)
 I $D(ERRORS) S ERRORS("Clinics")="" D BUILDJSON^SDES2JSON(.RETNJSON,.ERRORS) Q
 D BUILDCLINICS(.RETNJSON,.SDCONTEXT,.SDPARAM,.ERRORS)
 Q
 ;
BUILDCLINICS(RETNJSON,SDCONTEXT,SDPARAM,ERRORS) ; 
 N APPTLIST,IENCOUNT,YESTERDAYFM,TODAYFM,CLINICIEN,PRVUSERS,CLINTODAY,TODAY
 S TODAY=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
 S IENCOUNT=0
 F  S IENCOUNT=$O(SDPARAM("CLINIC IEN",IENCOUNT)) Q:'IENCOUNT  S CLINICIEN=SDPARAM("CLINIC IEN",IENCOUNT) D
 . N TEMPLIST,DIVISION,INSTITUT,STATION
 . S CLINTODAY=$P($$ISOTFM^SDAMUTDT(TODAY,CLINICIEN),".",1)
 . S YESTERDAYFM=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
 . S TODAYFM=$$FMADD^XLFDT(CLINTODAY,"",23,59,59)
 . D APPTBYCLINIC2(.TEMPLIST,CLINICIEN,YESTERDAYFM,TODAYFM,$G(SDCONTEXT("ACHERON AUDIT ID")),$G(SDCONTEXT("USER DUZ")))
 . S DIVISION=$$GET1^DIQ(44,CLINICIEN,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")=CLINICIEN
 . M APPTLIST("Clinics",IENCOUNT)=TEMPLIST
 D BUILDJSON^SDES2JSON(.RETNJSON,.APPTLIST)
 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
 ;
APPTBYCLINIC2(SDAPPT,SDCLINICIEN,SDBEG,SDEND,SDEAS,SDDUZ) ;
 N POP,APPTIEN,APPTDT,APPTDATA,COUNTER,JSONERR,DFN,PATIENT,RESTYPE,SDRESIEN
 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
 . 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
 ... D SUMMARY(.APPTDATA,APPTIEN)
 ... S COUNTER=$G(COUNTER)+1
 ... M SDAPPT("Appt",COUNTER)=APPTDATA
 ... 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
 ;
SUMMARY(APPTDATA,IEN) ;
 ;Returns a basic set of data for a specific appointment
 ;
 ; Input
 ;  IEN - Specific appointment IEN
 ; Return
 ;  APPTDATA - Array of field names and the data for the field based on the IEN
 ;
 N APPTARY,FN,IENS,SDMSG,SDDFN,RESOURCEIEN,CLINICIEN,SIEN,OVERBOOK,STIME,ETIME,X
 N DATETIME,NUM,STATPOINTER,CLINICARY,STAT,CLINICDATA,PROV,CLINICAPPT,CUSER
 K APPTDATA
 S FN=409.84,IENS=IEN_",",OVERBOOK=0
 D GETS^DIQ(FN,IENS,".01;.02;.03;.04;.05;.06;.07;.12;.13;.121;.122;.14;.16;.17;.18;.22;1;3;4;100","IE","APPTARY","SDMSG") ;SD,814-Added 100 for the EAS Tracking Number
 S RESOURCEIEN=$G(APPTARY(FN,IENS,.07,"I"))
 S CLINICIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
 S APPTDATA("StartTime")=$G(APPTARY(FN,IENS,.01,"E"))
 S APPTDATA("StartTimeFM")=$G(APPTARY(FN,IENS,.01,"I"))
 S STIME=$G(APPTARY(FN,IENS,.01,"I"))
 S APPTDATA("EndTime")=$G(APPTARY(FN,IENS,.02,"E"))
 S ETIME=$G(APPTARY(FN,IENS,.02,"I"))
 S APPTDATA("AppointmentTypeIEN")=$G(APPTARY(FN,IENS,.06,"I"))
 S APPTDATA("LengthOfAppt")=$G(APPTARY(FN,IENS,.18,"E"))
 S APPTDATA("RequestType")=$G(APPTARY(FN,IENS,.22,"E"))
 S APPTDATA("RequestIEN")=$P($G(APPTARY(FN,IENS,.22,"I")),";")
 K APPTARY(FN,IENS,1,"I"),APPTARY(FN,IENS,1,"E")
 I $D(APPTARY(FN,IENS,1)) M APPTDATA("Note")=APPTARY(FN,IENS,1)
 E  S APPTDATA("Note")=""
 S APPTDATA("AppointmentIEN")=IEN
 S DATETIME=$G(APPTARY(FN,IENS,.03,"I"))
 S APPTDATA("CheckIn")=$$FMTE^XLFDT(DATETIME)
 S DATETIME=$G(APPTARY(FN,IENS,.04,"I"))
 S APPTDATA("CheckInEntered")=$$FMTE^XLFDT(DATETIME)
 S DATETIME=$G(APPTARY(FN,IENS,.14,"I"))
 S APPTDATA("CheckOut")=$$FMTE^XLFDT(DATETIME)
 S APPTDATA("EASTrackingNumber")=$G(APPTARY(FN,IENS,100,"I")) ;SD,814-Retrieve EAS Tracking Number
 S APPTDATA("CancelDateTime")=$$FMTE^XLFDT($G(APPTARY(FN,IENS,.12,"I")))
 S APPTDATA("CancellationReason")=$G(APPTARY(FN,IENS,.122,"E"))
 ;CancelledByUser Data Elements
 S CUSER=$G(APPTARY(FN,IENS,.121,"I"))
 I CUSER D
 .S APPTDATA("CancelledByUser","ID")=CUSER
 .S APPTDATA("CancelledByUser","Name")=$G(APPTARY(FN,IENS,.121,"E"))
 .S APPTDATA("CancelledByUser","SecId")=$$GET1^DIQ(200,CUSER,205.1,"I")
 I '$D(APPTDATA("CancelledByUser")) S APPTDATA("CancelledByUser",1)=""
 ;
 S APPTDATA("Walkin")=$G(APPTARY(FN,IENS,.13,"E"))
 ;
 ;Always send these Resource / Clinic data elements
 S APPTDATA("Clinic","IsOverbook")=0
 S APPTDATA("ResourceIEN")=RESOURCEIEN
 S APPTDATA("Resource","Name")=$G(APPTARY(FN,IENS,.07,"E"))
 S APPTDATA("Resource","ClinicIEN")=CLINICIEN
 ;847
 D SETSTATUS^SDESGETAPPTWRAP5(.APPTDATA,IEN,CLINICIEN)
 S APPTDATA("CurrentStatus")=APPTDATA("Status")
 ;
 D APPTCLINIC^SDESCLINICDATA(.CLINICDATA,CLINICIEN)
 M APPTDATA("Clinic")=CLINICDATA
 S SDDFN=$G(APPTARY(FN,IENS,.05,"I"))
 I CLINICIEN D
 . S SIEN=0
 . F  S SIEN=$O(^SC(CLINICIEN,"S",STIME,SIEN)) Q:'SIEN  D
 .. S X=$O(^SC(CLINICIEN,"S",STIME,SIEN,""),-1)
 .. Q:SDDFN'=$$GET1^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",",.01,"I")
 .. S:X OVERBOOK=$G(^SC(CLINICIEN,"S",STIME,SIEN,X,"OB"))
 .. D GETS^DIQ(44.003,SIEN_","_STIME_","_CLINICIEN_",","10.5;30","IE","CLINICAPPT","SDMSG")
 .. S APPTDATA("Clinic","CurrentEligibilityCode")=$G(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",10.5,"E"))
 .. S APPTDATA("Clinic","EligibilityOfVisit")=$G(CLINICAPPT(44.003,SIEN_","_STIME_","_CLINICIEN_",",30,"E"))
 S (SIEN,NUM)=0
 F  S SIEN=$O(^SDEC(409.84,IEN,3,SIEN)) Q:'SIEN  D
 . S NUM=NUM+1
 . S STATPOINTER=$$GET1^DIQ(409.843,SIEN_","_IEN_",",.01,"I")
 . S STAT=$$GET1^DIQ(409.842,STATPOINTER,.01,"E")
 . S DATETIME=$$GET1^DIQ(409.843,SIEN_","_IEN_",",1,"E")
 . S APPTDATA("CheckInSteps",NUM,"IEN")=SIEN
 . S APPTDATA("CheckInSteps",NUM,"Status")=$G(STAT)
 . S APPTDATA("CheckInSteps",NUM,"DateTime")=$$FMTE^XLFDT(DATETIME)
 I '$D(APPTDATA("CheckInSteps")) S APPTDATA("CheckInSteps")=""
 ;
 ;Always send these Patient data elements
 S APPTDATA("DFN")=SDDFN
 S APPTDATA("Patient","EligibilityIEN")=$$GET1^DIQ(2,SDDFN_",",.361,"I")
 S APPTDATA("Patient","Name")=$$GET1^DIQ(2,SDDFN_",",.01,"E")
 ; 864
 S APPTDATA("Patient","DateOfBirth")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.03,"I"))
 S APPTDATA("Patient","DateOfDeath")=$$FMTISO^SDAMUTDT($$GET1^DIQ(2,SDDFN_",",.351,"I"))
 ;
 ; patient comments
 D GETPATCOMMENTS(.APPTDATA,IEN)
 ; provider data elements
 S PROV=$G(APPTARY(FN,IENS,.16,"I"))
 S APPTDATA("Provider","ID")=PROV
 S APPTDATA("Provider","Name")=$G(APPTARY(FN,IENS,.16,"E"))
 S APPTDATA("Provider","SecId")=$$GET1^DIQ(200,PROV,205.1,"I")
 Q
 ;
GETPATCOMMENTS(APPTDATA,IEN) ;
 N SUBIEN,COUNT
 S SUBIEN=0,COUNT=0
 F  S SUBIEN=$O(^SDEC(409.84,IEN,6,SUBIEN)) Q:'SUBIEN  D
 .S COUNT=COUNT+1
 .S APPTDATA("PatientComments",COUNT)=$$GET1^DIQ(409.846,SUBIEN_","_IEN_",",.01,"E")
 I '$D(APPTDATA("PatientComments")) S APPTDATA("PatientComments",1)=""
 Q
 ;