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

SDEC29.m

Go to the documentation of this file.
SDEC29 ;ALB/SAT - VISTA SCHEDULING RPCS ;JAN 15, 2016
 ;;5.3;Scheduling;**627,740**;Aug 13, 1993;Build 12
 ;
 Q
 ;
COPYAPPT(SDECY,SDECRES,SDEC44,SDECBEG,SDECEND) ;Copy appointments from HOSPITAL LOCATION to SDEC RESOURCE
 ;COPYAPPT(SDECY,SDECRES,SDEC44,SDECBEG,SDECEND)  external parameter tag is in SDEC
 ;Copy appointments from HOSPITAL LOCATION entry SDEC44 to SDEC RESOURCE entry SDECRES
 ;Beginning with appointments on day SDECBEG and ending on SDECEND, inclusive
 ;
 ;Returns ADO Recordset formatted fields containing count of records copied and error message:
 ;
 ;
 S SDECY="^TMP(""SDEC"","_$J_")"
 K @SDECY
 N SDECI,SDECST,%DT,X,Y,ZTDESC,ZTDTH,ZTRTN,ZTSAVE,ZTSK
 S SDECI=0
 S ^TMP("SDEC",$J,0)="T00010TASK_NUMBER^T00020ERRORID"_$C(30)
 ;
 ;Convert beginning and ending dates
 ;
 S X=SDECBEG,%DT="X" D ^%DT S SDECBEG=$P(Y,"."),SDECBEG=SDECBEG-1
 I Y=-1 D ERR(SDECI,0,"Routine: SDEC29, Error: Invalid Date") Q
 S X=SDECEND,%DT="X" D ^%DT S SDECEND=$P(Y,"."),SDECEND=SDECEND+1
 I Y=-1 D ERR(SDECI,0,"Routine: SDEC29, Error: Invalid Date") Q
 ;
 S ZTRTN="ZTM^SDEC29",ZTDTH=$H,ZTDESC="COPY PATIENT APPTS"
 S ZTSAVE("SDECBEG")="",ZTSAVE("SDECEND")="",ZTSAVE("SDEC44")="",ZTSAVE("SDECRES")=""
 D ^%ZTLOAD
 ;
 S SDECI=SDECI+1
 S SDECST=$S($G(ZTSK)>0:"OK",1:"Unable to create task.")
 S ^TMP("SDEC",$J,SDECI)=$G(ZTSK)_"^"_SDECST_$C(30)_$C(31)
 Q
 ;
ZTM ;EP
 ;Taskman entry point
 ;$O through ^SC(SDEC44,"S",
 Q:'$D(ZTSK)
 N SDECCNT,SDECIEN,SDECNOD,SDECNOTE,SDECCAN,SDECPAT,SDECLEN,SDECMADE,SDECCLRK,SDECPAT,SDECQUIT
 S SDECCNT=0,SDECQUIT=0
 S ^TMP("SDEC29",$J,ZTSK)=SDECCNT
 ;TSTART
 F  S SDECBEG=$O(^SC(SDEC44,"S",SDECBEG)) Q:'+SDECBEG  Q:SDECBEG>SDECEND  Q:SDECQUIT  D
 . S SDECIEN=0 F  S SDECIEN=$O(^SC(SDEC44,"S",SDECBEG,1,SDECIEN)) Q:'+SDECIEN  Q:SDECQUIT  D
 . . S SDECNOD=$G(^SC(SDEC44,"S",SDECBEG,1,SDECIEN,0))
 . . Q:'+SDECNOD
 . . S SDECCAN=$P(SDECNOD,U,9)
 . . Q:SDECCAN="C"
 . . S SDECPAT=$P(SDECNOD,U)
 . . S SDECLEN=$P(SDECNOD,U,2) ;duration in minutes
 . . S SDECCLRK=$P(SDECNOD,U,6) ;appt made by (clerk)
 . . S SDECMADE=$P(SDECNOD,U,7) ;date appt made
 . . S SDECNOTE=$P(SDECNOD,U,4) ;'OTHER' field contains note
 . . S SDECCNT=SDECCNT+$$XFER(SDECRES,SDECBEG,SDECPAT,SDECLEN,SDECCLRK,SDECMADE,SDECNOTE)
 . . I +SDECCNT,SDECCNT#10=0 S ^TMP("SDEC29",$J,ZTSK)=SDECCNT_" records copied." ;every 10th record
 . . I $D(^TMP("SDEC29",$J,ZTSK,"CANCEL")) S SDECQUIT=1 ;Check for cancel flag
 . . Q
 . Q
 ;I 'SDECQUIT TCOMMIT
 ;E  TROLLBACK
 S ^TMP("SDEC29",$J,ZTSK)=$S(SDECQUIT:"Cancelled.  No records copied.",1:"Finished.  "_SDECCNT_" records copied.")
 Q
 ;
ZTMERR ;
 ;TROLLBACK
 D ^%ZTER
 Q
 ;
XFER(SDECRES,SDECBEG,SDECPAT,SDECLEN,SDECCLRK,SDECMADE,SDECNOTE) ;EP
 ;
 ;Copy record to SDEC APPOINTMENT file
 ;Return 1 if record copied, otherwise 0
 ;
 ;$O Thru ^SDECAPPT to determine if this appt already added
 N SDECEND,SDECIEN,SDECFND,SDECPAT2,SDECFDA,SDECIENS
 S SDECIEN=0,SDECFND=0
 F  S SDECIEN=$O(^SDEC(409.84,"ARSRC",SDECRES,SDECBEG,SDECIEN)) Q:'+SDECIEN  D  Q:SDECFND
 . S SDECNOD=$G(^SDEC(409.84,SDECIEN,0))
 . Q:'+SDECNOD
 . S SDECPAT2=$P(SDECNOD,U,5)
 . S SDECFND=0
 . I SDECPAT2=SDECPAT S SDECFND=1
 . Q
 Q:SDECFND 0
 ;
 ;Add to SDEC APPOINTMENT
 S SDECEND=SDECBEG
 ;Calculate ending time from beginning time and duration.
 S SDECEND=$$ADDMIN(SDECBEG,SDECLEN)
 S SDECIENS="+1,"
 S SDECFDA(409.84,SDECIENS,.01)=SDECBEG
 S SDECFDA(409.84,SDECIENS,.02)=SDECEND
 S SDECFDA(409.84,SDECIENS,.05)=SDECPAT
 S SDECFDA(409.84,SDECIENS,.07)=SDECRES
 S SDECFDA(409.84,SDECIENS,.08)=SDECCLRK
 S SDECFDA(409.84,SDECIENS,.09)=SDECMADE
 ;
 K SDECIEN
 D UPDATE^DIE("","SDECFDA","SDECIEN","SDECMSG")
 S SDECIEN=+$G(SDECIEN(1))
 I '+SDECIEN Q 0
 ;
 ;Add WP field
 I SDECNOTE]"" S SDECNOTE(.5)=SDECNOTE,SDECNOTE="" D
 . D WP^DIE(409.84,SDECIEN_",",1,"","SDECNOTE","SDECMSG")
 ;
 Q 1
 ;
ERR(SDECI,SDECCNT,SDECERR) ;Error processing
 S SDECI=SDECI+1
 S ^TMP("SDEC",$J,SDECI)=SDECCNT_"^"_SDECERR_$C(30)
 S SDECI=SDECI+1
 S ^TMP("SDEC",$J,SDECI)=$C(31)
 Q
 ;
ETRAP ;EP Error trap entry
 D ^%ZTER
 I '$D(SDECI) N SDECI S SDECI=999
 S SDECI=SDECI+1
 D ERR(SDECI,$G(SDECCNT),"Routine: SDEC29, Error")
 Q
 ;
CPSTAT(SDECY,SDECTSK) ;Copy Appointment Status
 ;CPSTAT(SDECY,SDECTSK)  external parameter tag is in SDEC
 ;Return status (copied record count) of tasked job having ZTSK=SDECTSK
 ;
 S SDECY="^TMP(""SDEC"","_$J_")"
 K @SDECY
 N SDECI,SDECCNT
 S SDECI=0
 S ^TMP("SDEC",$J,0)="T00020RECORD_COUNT^T00020ERRORID"_$C(30)
 S SDECCNT=$G(^TMP("SDEC29",$J,SDECTSK))
 I SDECCNT["Finished" K ^TMP("SDEC29",$J,SDECTSK)
 I SDECCNT["Cancelled" K ^TMP("SDEC29",$J,SDECTSK)
 S SDECI=SDECI+1
 S ^TMP("SDEC",$J,SDECI)=SDECCNT_"^"_"OK"_$C(30)_$C(31)
 Q
 ;
CPCANC(SDECY,SDECTSK) ;Copy Appointment Cancel
 ;CPCANC(SDECY,SDECTSK)  external parameter tag is in SDEC
 ;Signal tasked job having ZTSK=SDECTSK to cancel
 ;Returns current record count of copy process
 ;
 S SDECY="^TMP(""SDEC"","_$J_")"
 N SDECI,SDECCNT
 S SDECI=0
 S ^TMP("SDEC",$J,0)="T00020RECORD_COUNT^T00020ERRORID"_$C(30)
 S SDECCNT=$G(^TMP("SDEC29",$J,SDECTSK))
 I SDECCNT["FINISHED" K ^TMP("SDEC29",$J,SDECTSK)
 E  S ^TMP("SDEC29",$J,SDECTSK,"CANCEL")=""
 S SDECI=SDECI+1
 S ^TMP("SDEC",$J,SDECI)=SDECCNT_"^"_"OK"_$C(30)_$C(31)
 Q
 ;
ADDMIN(SDECSTRT,SDECLEN) ;
 ;
 ;Add SDECLEN minutes to time SDECSTRT and return end time
 N SDECEND,SDECH,SDECM,SDECSTIM,SDECETIM
 S SDECEND=$P(SDECSTRT,".")
 ;
 ;Convert start time to minutes past midnight
 S SDECSTIM=$P(SDECSTRT,".",2)
 S SDECSTIM=SDECSTIM_"0000"
 S SDECSTIM=$E(SDECSTIM,1,4)
 S SDECH=$E(SDECSTIM,1,2)
 S SDECH=SDECH*60
 S SDECH=SDECH+$E(SDECSTIM,3,4)
 ;
 ;Add duration to find minutes past midnight of end time
 S SDECETIM=SDECH+SDECLEN
 ;
 ;Convert back to a time
 S SDECH=SDECETIM\60
 S SDECH="00"_SDECH
 S SDECH=$E(SDECH,$L(SDECH)-1,$L(SDECH))
 S SDECM=SDECETIM#60
 S SDECM="00"_SDECM
 S SDECM=$E(SDECM,$L(SDECM)-1,$L(SDECM))
 S SDECETIM=SDECH_SDECM
 I SDECETIM>2400 S SDECETIM=2400
 S $P(SDECEND,".",2)=SDECETIM
 Q SDECEND