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

SDEC02.m

Go to the documentation of this file.
SDEC02 ;ALB/SAT,PC,MGD - VISTA SCHEDULING RPCS ;Aug 25, 2020@21:11
 ;;5.3;Scheduling;**627,642,658,672,722,694,824**;Aug 13, 1993;Build 3
 ;;Per VHA Directive 2004-038, this routine should not be modified
 ;
 ; Reference to ^DPT in ICR #10035
 ;
 Q
 ;
CRSCHED(SDECY,SDECRES,SDECSTART,SDECEND,SDECWKIN,MAXREC,LASTSUB) ;Create Resource Appointment Schedule   ;alb/sat 672
 ;CRSCHED(SDECY,SDECRES,SDECSTART,SDECEND,SDECWKIN)  external parameter tag is in SDEC
 ;Create Resource Appointment Schedule recordset
 ;On error, returns 0 in APPOINTMENTID field and error text in NOTE field
 ;
 ;$O Thru ^SDEC(409.84,"ARSRC", RESOURCE, STARTTIME, APPTID)
 ;SDECRES   - pipe | delimited list of resource names
 ;SDECSTART - Start date/time in external form
 ;SDECEND   - End Date/time in external form
 ;SDECWKIN  - Include Walk-ins 1=return walkins; 0=skip walk-ins
 ;9-27-2004 Added walkin to returned datatable
 ;TODO: Change SDECRES from names to IDs
 ;RETURN:
 ;  Global Array in which each array entry contains data for the Resource Appointment Schedule separated by ^:
 ; 1. APPOINTMENTID
 ; 2. START_TIME
 ; 3. END_TIME
 ; 4. CHECKIN
 ; 5. AUXTIME
 ; 6. PATIENTID
 ; 7. PATIENTNAME
 ; 8. RESOURCENAME
 ; 9. NOSHOW
 ;10. HRN
 ;11. ACCESSTYPEID
 ;12. WALKIN
 ;13. CHECKOUT
 ;14. VPROVIDER
 ;15. CANCELLED
 ;16. NOTE
 ;17. DAPTDT
 ;18. APPTREQTYPE
 ;19. DIEDON
 ;20. EESTAT - Patient Status  N=NEW  E=ESTABLISHED
 ;21. MULT   - data from MULT APPTS MADE field of SDEC APPT REQUEST separated by pipe   ;alb/sat 642
 ;             each pipe piece contains the following ~ pieces:
 ;             1. MULT APPTS MADE - pointer to SDEC APPOINTMENT
 ;             2. PARENT REQUEST  - pointer to SDEC APPT REQUEST
 ;22. SDPARENT - PARENT REQUEST from SDEC APPT REQUEST. Pointer to SDEC APPT REQUEST.   ;alb/sat 642
 ;23. RESOURCEID | STARTTIME | APPTID
 ;24. SSN
 ;25. DOB
 ;26. patient sensitive & record access checks
 ;27. APPTTYPE - APPOINTMENT TYPE (#.06)
 ;
 N SDECERR,SDECIEN,SDECDEPD,SDECDEPN,SDECRESD,SDECI,SDECJ,SDECRESN,SDECS,SDECAD,SDECZ,SDECQ,SDECNOD,SDECTMP
 N SDECPAT,SDECNOT,SDECZPCD,SDECPCD,SDDDT,SDAPTYP
 N SDCNT,SDI   ;alb/sat 672
 N %DT,X,Y
 K ^TMP("SDEC02",$JOB)
 S SDECERR=""
 S SDCNT=0     ;alb/sat 672
 S SDECY="^TMP(""SDEC02"","_$JOB_")"
 ;                1                   2                3              4             5             6
 S SDECTMP="I00020APPOINTMENTID^D00030START_TIME^D00030END_TIME^D00030CHECKIN^D00030AUXTIME^I00020PATIENTID^"
 ;                        7                 8                  9            10        11                 12
 S SDECTMP=SDECTMP_"T00030PATIENTNAME^T00030RESOURCENAME^I00005NOSHOW^T00020HRN^I00005ACCESSTYPEID^I00005WALKIN^"
 ;                        13             14              15              16         17           18
 S SDECTMP=SDECTMP_"D00030CHECKOUT^I00020VPROVIDER^T00020CANCELLED^T00250NOTE^T00030DAPTDT^T00030APPTREQTYPE^"
 ;alb/sat 642 added MULT and SDPARENT  ;alb/sat 672 added SLAST,SSN,DOB,SENSITIVE
 ;                       19           20           21         22             23           24        25        26              27
 S SDECTMP=SDECTMP_"T00030DIEDON^T00030EESTAT^T00250MULT^T00030SDPARENT^T00050SDLAST^T00030SSN^T00030DOB^T00100SENSITIVE^T00030APPTTYP"
 S ^TMP("SDEC02",$JOB,0)=SDECTMP_$CHAR(30)
 ;
 ;
 ;  Change date/time conversion so midnight is handled properly.  wtc 694 4/24/18
 ;
 ;S:SDECSTART["@0000" SDECSTART=$P(SDECSTART,"@")
 ;S:SDECEND["@0000" SDECEND=$P(SDECEND,"@")
 ;S %DT="T",X=SDECSTART D ^%DT S SDECSTART=Y
 S SDECSTART=$$NETTOFM^SDECDATE(SDECSTART,"N") ;
 I SDECSTART=-1 S ^TMP("SDEC02",$JOB,0)=^TMP("SDEC02",$JOB,0)_$CHAR(31) Q
 ; need to set the start date back to midnight if no time is sent to us from VSE
 I $PIECE(SDECSTART,".",2)="" S SDECSTART=$$FMADD^XLFDT(SDECSTART,-1)_".24"   ;pwc *694  1/13/2020
 ;S %DT="T",X=SDECEND D ^%DT S SDECEND=Y
 S SDECEND=$$NETTOFM^SDECDATE(SDECEND,"Y") ;
 I SDECEND=-1 S ^TMP("SDEC02",$JOB,0)=^TMP("SDEC02",$JOB,0)_$CHAR(31) Q
 S MAXREC=$GET(MAXREC) S:'MAXREC MAXREC=9999999   ;alb/sat 672
 S LASTSUB=$GET(LASTSUB)   ;alb/sat 672
 ;
 S SDECI=0
 D STRES
 ;
 S ^TMP("SDEC02",$JOB,SDECI)=^TMP("SDEC02",$JOB,SDECI)_$CHAR(31)
 Q
 ;
STRES ;
 S SDI=$SELECT($PIECE(LASTSUB,"|",1)'="":$PIECE(LASTSUB,"|",1),1:1)   ;alb/sat 672
 N SDECRESA,SDECRSND,SDECRST,SDCL,NEWRES,SDRSLTS,SDECOVR ;*zeb+34 722 1/17/19 include appts for resources that share clinics
 I SDECRES["|" D  I 1
 . S SDECRESA=SDECRES
 E  D
 . S SDECRESA="|"_SDECRES_"|"
 . I '+SDECRES Q:'$DATA(^SDEC(409.831,"B",SDECRES))
 . I '+SDECRES S SDECRES=$ORDER(^SDEC(409.831,"B",SDECRES,0))
 . S SDECRSND=$GET(^SDEC(409.831,SDECRES,0))
 . S SDECRST=$PIECE($PIECE(SDECRSND,U,11),";",2)
 . I SDECRST'="SC(" D  Q
 . . S SDECRESA=SDECRESA_"|"_SDECRES
 . S SDCL=$PIECE(SDECRSND,U,4)
 . S NEWRES=""
 . F  S NEWRES=$ORDER(^SDEC(409.831,"ALOC",SDCL,NEWRES)) Q:NEWRES=""  D
 . . Q:NEWRES=SDECRES
 . . S SDECRESA=SDECRESA_"|"_NEWRES_U_$PIECE(^SDEC(409.831,SDECRES,0),U,1)
 F SDECJ=1:1:$LENGTH(SDECRESA,"|") S SDECRESN=$PIECE(SDECRESA,"|",SDECJ) D
 . Q:SDECRESN=""
 . S SDECOVR=""
 . I SDECRESN[U S SDECOVR=$PIECE(SDECRESN,U,2),SDECRESD=$PIECE(SDECRESN,U,1)
 . E  S SDECRESD=SDECRESN
 . ;I +SDECRESN Q:'$D(^SDEC(409.831,+SDECRESN,0))
 . ;I +SDECRESN S SDECRESD=SDECRESN
 . ;I '+SDECRESN Q:'$D(^SDEC(409.831,"B",SDECRESN))
 . ;I '+SDECRESN S SDECRESD=$O(^SDEC(409.831,"B",SDECRESN,0))
 . ;Q:'+SDECRESD
 . S SDECRESN=$PIECE($GET(^SDEC(409.831,SDECRESD,0)),U,1)
 . ;Q:'$D(^SDEC(409.84,"ARSRC",SDECRESD))
 . S SDECS=$SELECT($PIECE(LASTSUB,"|",2):$PIECE(LASTSUB,"|",2),1:SDECSTART)-.0001   ;alb/sat 672
 . F  S SDECS=$ORDER(^SDEC(409.84,"ARSRC",SDECRESD,SDECS)) Q:'+SDECS  Q:SDECS>SDECEND  D  Q:SDCNT'<MAXREC   ;alb/sat 672
 . . S SDECAD=$SELECT($PIECE(LASTSUB,"|",3)'="":$PIECE(LASTSUB,"|",3),1:0)   ;alb/sat 672
 . . S LASTSUB=""   ;alb/sat 672
 . . ;alb/sat 672
 . . S:SDECOVR="" SDECOVR=SDECRESN ;*zeb+1 722 1/17/19 allow override of name for resources in same clinic
 . . F  S SDECAD=$ORDER(^SDEC(409.84,"ARSRC",SDECRESD,SDECS,SDECAD)) Q:'+SDECAD  D:'$DATA(SDRSLTS(SDECAD)) STCOMM(SDECAD,SDECOVR,SDECRESD) S SDRSLTS(SDECAD)=1 Q:SDCNT'<MAXREC
 Q
 ;
STCOMM(SDECAD,SDECRESN,SDRES)      ;
 ;SDECAD is the sdec appointment IEN
 N CHECKIN,SDECC,SDECCAN,SDECCO,SDECQ,SDECZ,SDECSUBC,SDECHRN,SDECPATD,SDECATID,SDECISWK
 N DIEDON,SDECVPRV,REQFILE,REQIEN,REQTYPE
 N SDDEMO,SDSENS,SDTMP   ;alb/sat 672
 S SDTMP=""   ;alb/sat 672
 Q:'$DATA(^SDEC(409.84,SDECAD,0))
 S SDECNOD=^SDEC(409.84,SDECAD,0)
 S SDECCAN=($PIECE(SDECNOD,U,12)]"")  ;CANCELLED flag  1=cancelled; 0=not cancelled
 S SDECISWK=0
 S:$PIECE(SDECNOD,U,13)="y" SDECISWK=1
 I +$GET(SDECWKIN) Q:SDECISWK  ;Don't return walkins if appt is WALKIN and SDECWKIN is 1
 S SDECCO=$TRANSLATE($$FMTE^XLFDT($PIECE(SDECNOD,U,14)),"@"," ") ;APPOINTMENT CHECKOUT TIME
 S SDECVPRV=$PIECE(SDECNOD,U,16) ;POINTER TO V PROVIDER TABLE ^AUPNVPRV
 S SDECZ=SDECAD_"^"
 F SDECQ=1:1:4 D
 . S Y=$PIECE(SDECNOD,U,SDECQ)
 . ;
 . ;  Change date/time conversion so midnight is handled properly.  wtc 694 4/24/18
 . ;
 . ;X ^DD("DD") S Y=$TR(Y,"@"," ")
 . S Y=$$FMTONET^SDECDATE(Y,"Y") ;
 . S Y=$TRANSLATE(Y,"@"," ")   ;remove the @ and replace with a space between date/time  pwc *694  1/13/2020
 . S SDECZ=SDECZ_Y_"^"
 S SDECPATD=$PIECE(SDECNOD,U,5)
 D PDEMO^SDECU3(.SDDEMO,SDECPATD)
 I $PIECE(SDECZ,U,4)="" S CHECKIN=$$CHECKIN(SDRES,$PIECE(SDECNOD,U,1),SDECPATD,SDECAD) S:CHECKIN'="" $PIECE(SDECZ,U,4)=$PIECE(CHECKIN,U,1),$PIECE(SDECZ,U,5)=$PIECE(CHECKIN,U,2)   ;if no checkin, check appointment checkin
 S $PIECE(SDECZ,"^",6)=SDECPATD ;PATIENT ID
 S SDECPAT=""
 I SDECPATD]"",$DATA(^DPT(SDECPATD,0)) S SDECPAT=$PIECE(^DPT(SDECPATD,0),U)
 S $PIECE(SDECZ,"^",7)=SDECPAT ;PATIENT NAME
 S $PIECE(SDECZ,"^",8)=SDECRESN ;RESOURCENAME
 S $PIECE(SDECZ,"^",9)=+$PIECE(SDECNOD,U,10) ;NOSHOW
 S SDECHRN=""
 I $DATA(DUZ(2)),DUZ(2)>0 S SDECHRN=$PIECE($GET(^AUPNPAT(SDECPATD,41,DUZ(2),0)),U,2) ;HRN
 S $PIECE(SDECZ,"^",10)=SDECHRN
 S SDECATID=$PIECE(SDECNOD,U,6)
 S:'+SDECATID SDECATID=0 ;UNKNOWN TYPE
 S $PIECE(SDECZ,"^",11)=SDECATID
 S $PIECE(SDECZ,"^",12)=SDECISWK
 S $PIECE(SDECZ,"^",13)=SDECCO  ;CHECKOUT TIME
 S $PIECE(SDECZ,"^",14)=SDECVPRV  ;POINTER TO NEW PERSON
 S $PIECE(SDECZ,"^",15)=SDECCAN   ;CANCELLED
 ;NOTE  [16]
 S SDECNOT="",SDECQ=0 F  S SDECQ=$ORDER(^SDEC(409.84,SDECAD,1,SDECQ)) Q:'+SDECQ  D
 . S SDECNOT=$GET(^SDEC(409.84,SDECAD,1,SDECQ,0))
 . S:$EXTRACT(SDECNOT,$LENGTH(SDECNOT)-1,$LENGTH(SDECNOT))'=" " SDECNOT=SDECNOT_" "
 . S SDTMP=SDTMP_$SELECT(SDTMP'="":" ",1:"")_$TRANSLATE(SDECNOT,"^"," ")   ;alb/sat 672
 . ;S SDECI=SDECI+1  ;alb/sat 672 - removed
 . ;S ^TMP("SDEC02",$J,SDECI)=$TR(SDECNOT,"^"," ")  ;alb/sat 658   ;alb/sat 672 - removed
 ;S ^TMP("SDEC02",$J,SDECI)=^TMP("SDEC02",$J,SDECI)_"^"   ;alb/sat 672 - replaced
 S $PIECE(SDECZ,"^",16)=SDTMP   ;alb/sat 672
 ;additional data
 ;S SDECZ=""   ;alb/sat 672 - removed
 S $PIECE(SDECZ,"^",17)=$SELECT($PIECE(SDECNOD,U,20)'="":$$FMTE^XLFDT($PIECE(SDECNOD,U,20)),1:"")   ;alb/sat 672
 ;appt request type
 S SDAPTYP=$PIECE($GET(^SDEC(409.84,SDECAD,2)),U,1)
 S:SDAPTYP'="" SDAPTYP=$SELECT($PIECE(SDAPTYP,";",2)["SDWL":"E",$PIECE(SDAPTYP,";",2)["GMR":"C",$PIECE(SDAPTYP,";",2)="SD(403.5,":"R",$PIECE(SDAPTYP,";",2)="SDEC(409.85,":"A",1:"")_"|"_$PIECE(SDAPTYP,";",1)
 S $PIECE(SDECZ,"^",18)=SDAPTYP  ;[18]  ;alb/sat 672
 S DIEDON="" D DIEDON^ORWPT(.DIEDON,SDECPATD)
 S $PIECE(SDECZ,"^",19)=DIEDON  ;[19]  ;alb/sat 672
 S $PIECE(SDECZ,"^",20)=$$GET1^DIQ(409.84,SDECAD_",",.23,"E")  ;[20]  ;alb/sat 672
 I $PIECE(SDAPTYP,"|",1)="A" S $PIECE(SDECZ,"^",21)=$$MULT(SDAPTYP)   ;[21] [22]  alb/sat 642  ;alb/sat 672
 I $PIECE(SDAPTYP,"|",1)="A" S $PIECE(SDECZ,"^",22)=$$GET1^DIQ(409.85,$PIECE(SDAPTYP,"|",2)_",",43.8,"I")  ;[21] [22]  alb/sat 642  ;alb/sat 672
 S $PIECE(SDECZ,"^",24)=$GET(SDDEMO("SSN"))  ;[24]   ;alb/sat 672 - added
 S $PIECE(SDECZ,"^",25)=$GET(SDDEMO("DOB"))  ;[25]   ;alb/sat 672 - added
 S SDSENS=$$PTSEC^SDECUTL(SDECPATD) S $PIECE(SDECZ,"^",26)=SDSENS  ;[26]  ;alb/sat 672 - added
 S REQTYPE=$$GET1^DIQ(409.84,SDECAD_",",.22,"I")
 S REQIEN=$P(REQTYPE,";",1),REQFILE=$P(REQTYPE,";",2)
 I REQFILE["123" S REQTYPE=$$GET1^DIQ(123,REQIEN_",",4,"E")
 I REQFILE["409.85" S REQTYPE=$$GET1^DIQ(409.85,REQIEN_",",4,"E")
 I REQFILE["403.5"!(REQFILE["409.3") S REQTYPE=""
 S $PIECE(SDECZ,"^",27)=REQTYPE ; APPOINTMENT TYPE (#.06)
 S SDCNT=SDCNT+1 I SDCNT'<MAXREC S $PIECE(SDECZ,"^",23)=SDECJ_"|"_SDECS_"|"_SDECAD   ;[23] ;alb/sat 672 - last subscript on last rec
 S SDECI=SDECI+1 S ^TMP("SDEC02",$JOB,SDECI)=SDECZ_$CHAR(30)  ;alb/sat 672
 Q
CHECKIN(SDRES,SDT,DFN,APPT)  ;alb/sat 642 - if no checkin, check appointment checkin
 ; SDRES    - resource id
 ; SDT      - appointment date/time in external format
 ; DFN - patient ID
 N CHECKIN,ENTERED,SDCL,SDFDA,SDI,SDNOD,Y
 S (CHECKIN,ENTERED)=""
 S SDCL=$$GET1^DIQ(409.831,SDRES_",",.04,"I")
 S SDI=0 F  S SDI=$ORDER(^SC(SDCL,"S",SDT,1,SDI)) Q:SDI'>0  D  Q:CHECKIN'=""
 .S SDNOD=$GET(^SC(SDCL,"S",SDT,1,SDI,0))
 .Q:$PIECE(SDNOD,U,1)'=DFN
 .I $DATA(^SC(SDCL,"S",SDT,1,SDI,"C")) D
 ..S CHECKIN=$PIECE($GET(^SC(SDCL,"S",SDT,1,SDI,"C")),U,1)
 ..S ENTERED=$PIECE($GET(^SC(SDCL,"S",SDT,1,SDI,"C")),U,5)
 ..S:CHECKIN'="" SDFDA(409.84,APPT_",",.03)=CHECKIN
 ..S:ENTERED'="" SDFDA(409.84,APPT_",",.04)=ENTERED
 ..D:$DATA(SDFDA) UPDATE^DIE("","SDFDA")
 .. S Y=CHECKIN
 .. ;
 .. ;  Change date/time conversion so midnight is handled properly.  wtc 694 4/24/18
 .. ;
 .. ;X ^DD("DD") S CHECKIN=$TR(Y,"@"," ")
 .. S CHECKIN=$$FMTONET^SDECDATE(CHECKIN,"Y") ;
 .. ;S Y=ENTERED
 .. ;X ^DD("DD") S ENTERED=$TR(Y,"@"," ")
 .. S ENTERED=$$FMTONET^SDECDATE(ENTERED,"Y") ;
 Q CHECKIN_U_ENTERED
MULT(SDAPTYP)  ;get data from MULT APPTS MADE field of SDEC APPT REQUEST file   ;alb/sat 642
 N ARIEN,SDI,MULT1,MULTL
 S MULTL=""
 S ARIEN=$PIECE(SDAPTYP,"|",2)
 S SDI=0 F  S SDI=$ORDER(^SDEC(409.85,ARIEN,2,SDI)) Q:SDI'>0  D
 .S MULT1=$PIECE($GET(^SDEC(409.85,ARIEN,2,SDI,0)),"^",1)
 .S MULTL=$SELECT(MULTL'="":MULTL_"|",1:"")_MULT1
 Q MULTL
 ;
ERR(SDECI,SDECERR) ;Error processing
 S SDECI=SDECI+1
 S ^TMP("SDEC02",$JOB,SDECI)="0^^^^^^^^^^^"_SDECERR_$CHAR(30)
 S SDECI=SDECI+1
 S ^TMP("SDEC02",$JOB,SDECI)=$CHAR(31)
 Q
 ;
ETRAP ;EP Error trap entry
 D ^%ZTER
 I '$DATA(SDECI) N SDECI S SDECI=999999
 S SDECI=SDECI+1
 D ERR(SDECI,"SDEC31 Error")
 Q