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

SDESAPPTLETTERSV.m

Go to the documentation of this file.
SDESAPPTLETTERSV ;ALB/BWF - VISTA SCHEDULING RPCS - VISTA LETTER PRINT ; September 07, 2022
 ;;5.3;Scheduling;**825**;Aug 13, 1993;Build 2
 ;;Per VHA Directive 6402, this routine should not be modified
 Q
 ; Print single appointment
PRINTAPPT(SDRES,APPTIEN,TYPE,PDEV) ;
 N ERRORS,PRINTRES
 S APPTIEN=$G(APPTIEN),TYPE=$G(TYPE),PDEV=$G(PDEV)
 D VALAPPTIEN(.ERRORS,.APPTIEN)
 D VALTYPE(.ERRORS,TYPE)
 D VALPDEV(.ERRORS,PDEV)
 I $D(ERRORS) S ERRORS("PrintResult",1)="" D BUILDJSON^SDESBUILDJSON(.SDRES,.ERRORS) Q
 D PRINT1(.PRINTRES,.ERRORS,APPTIEN,TYPE,PDEV)
 I '$D(PRINTRES) S PRINTRES("PrintResult",1)=""
 M PRINTRES=ERRORS
 D BUILDJSON^SDESBUILDJSON(.SDRES,.PRINTRES)
 Q
 ; Print list of appointments
PRINTAPPTS(SDRES,APPTIENS,TYPE,PDEV) ;
 N ERRORS,PRINTRES,PAPPT
 S TYPE=$G(TYPE),PDEV=$G(PDEV)
 D VALAPPTLIST(.ERRORS,.APPTIENS)
 D VALTYPE(.ERRORS,TYPE)
 D VALPDEV(.ERRORS,PDEV)
 I $D(ERRORS) S ERRORS("PrintResult",1)="" D BUILDJSON^SDESBUILDJSON(.SDRES,.ERRORS) Q
 S PAPPT=0 F  S PAPPT=$O(APPTIENS(PAPPT)) Q:'PAPPT  D
 .D PRINT1(.PRINTRES,.ERRORS,PAPPT,TYPE,PDEV)
 .; log errors for each appointment and kill ERRORS so errors are not duplicated
 .I $D(ERRORS) D
 ..D PRINTRESERR(.PRINTRES,PAPPT,.ERRORS)
 ..K ERRORS
 I $D(ERRORS),'$D(PRINTRES("PrintResult")) S ERRORS("PrintResult",1)="" D BUILDJSON^SDESBUILDJSON(.SDRES,.ERRORS) Q
 D BUILDJSON^SDESBUILDJSON(.SDRES,.PRINTRES)
 Q
VALAPPTIEN(ERRORS,APPTIEN) ;
 I APPTIEN="" D ERRLOG^SDESJSON(.ERRORS,14) Q
 I '$D(^SDEC(409.84,APPTIEN)) D ERRLOG^SDESJSON(.ERRORS,15)
 Q
VALAPPTLIST(ERRORS,APPTLIST) ;
 I '$O(APPTLIST(0)) D ERRLOG^SDESJSON(.ERRORS,254) Q
 Q
VALTYPE(ERRORS,TYPE) ;
 I TYPE="" D ERRLOG^SDESJSON(.ERRORS,228) Q
 I "PCN"'[TYPE D ERRLOG^SDESJSON(.ERRORS,226)
 Q
VALPDEV(ERRORS,PDEV) ;
 I 'PDEV D ERRLOG^SDESJSON(.ERRORS,279) Q
 I '$D(^%ZIS(1,PDEV)) D ERRLOG^SDESJSON(.ERRORS,280)
 Q
PRINT1(PRINTRES,ERRORS,APPTIEN,TYPE,PDEV) ;
 N APPTIENS,SDTTM,DFN,SDRES,SC,APPTDATA,SDT
 S TYPE=$G(TYPE),PDEV=$G(PDEV)
 I '$D(^SDEC(409.84,APPTIEN)) D ERRLOG^SDESJSON(.ERRORS,52,"Invalid appointment ID "_APPTIEN_".") Q
 S APPTIENS=APPTIEN_","
 D GETS^DIQ(409.84,APPTIENS,".01;.05;.07","I","APPTDATA")
 S (SDT,SDTTM)=$G(APPTDATA(409.84,APPTIENS,.01,"I"))
 S DFN=$G(APPTDATA(409.84,APPTIENS,.05,"I"))
 S SDRES=$G(APPTDATA(409.84,APPTIENS,.07,"I"))
 I $$BADADR^DGUTL3(+DFN) D  Q
 .D ERRLOG^SDESJSON(.ERRORS,281)
 I 'SDRES D  Q
 .D ERRLOG^SDESJSON(.ERRORS,282)
 S SC=$$GET1^DIQ(409.831,SDRES,.04,"I")
 I 'SC D  Q
 .D ERRLOG^SDESJSON(.ERRORS,283)
 I TYPE="P" D PREAPPT(.PRINTRES,.ERRORS,SC,APPTIEN,SDTTM,DFN,PDEV)
 I TYPE="C" D CANCEL(.PRINTRES,.ERRORS,SC,APPTIEN,SDTTM,DFN,PDEV)
 I TYPE="N" D NOSHOW(.PRINTRES,.ERRORS,SC,APPTIEN,SDTTM,DFN,PDEV)
 Q
PREAPPT(RESULTS,ERRORS,SC,APPTIEN,SDTTM,DFN,SDID) ;print pre-appointment letter
 N SDY,DFBD,SDED,SDLET,SDBD,SDED,L0,SD9,VAUTNALL,VAUTNI,S1,SDLT,SDV,SDWH,SDLET1
 N SDFORM,L2,J,SDCL,L,S,SDAMTYP,SDC,SDFN,SDLET,SDX
 S SDY=0 F  S SDY=$O(^SC(SC,"S",SDTTM,1,SDY)) Q:SDY=""  Q:$P($G(^SC(SC,"S",SDTTM,1,SDY,0)),U,1)=DFN
 I SDY="" D ERRLOG^SDESJSON(.ERRORS,52,"Clinic appointment not found.") Q
 ;check for a PRE-APPT letter defined
 S SDCL=$$GET1^DIQ(44,SC,.01,"I")
 S SDLET=$$GET1^DIQ(44,SC,2509,"I")
 I SDLET="" D ERRLOG^SDESJSON(.ERRORS,52,"A pre-appointment letter is not defined for "_SDCL_".") Q
 ;
 ; pre-define letter type (P), the division, date for appt, etc.
 S SDWH=$$GET1^DIQ(409.84,APPTIEN,.17,"I")
 S (SDBD,SDED)=SDTTM,L0="P",SD9=0,VAUTNALL=1,VAUTNI=2,S1="P",SDLT=1,SDV1=1,SDFORM=""
 S L2=$S(L0="P":"^SDL1",1:"^SDL1"),J=SDBD
 S (A,SDFN,S)=DFN
 S L="^SDL1"
 S SDC=SC,SDX=SDTTM
 S SDLET1=SDLET
 S SDAMTYP="P"   ;always by patient
 ;I SDY["DPT(" S SDAMTYP="P",SDFN=+SDY
 ;I SDY["SC(" S SDAMTYP="C",SDCLN=+SDY
 ; prepare to queue the letter if the user so desires
 N %ZIS,IOP,POP,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE
 S IOP="`"_SDID
 S %ZIS("B")="",POP=0,%ZIS="MQ" D ^%ZIS
 I POP D ERRLOG^SDESJSON(.ERRORS,285) Q
 S ZTIO=ION,ZTRTN="QUE^SDM1A",ZTDESC="PRINT PRE-APPT LETTER",ZTDTH=$$NOW^XLFDT   ;,ZTSAVE("*")=""
 F ZTS="A","AUTO(","DFN","DUZ","S","SC","SDCL","SDFORM","SDLET","SDWH","SDX" S ZTSAVE(ZTS)=""
 D ^%ZTLOAD K IO("Q")
 D PRINTRES(.RESULTS,APPTIEN)
 Q
 ;
CANCEL(RESULTS,ERRORS,SC,APPTIEN,SDTTM,DFN,SDID) ;
 N A,SDCL,SDL,APPTSTAT,SDWH
 S SDL=""
 S A=DFN
 S APPTSTAT=$$GET1^DIQ(409.84,APPTIEN,.17,"I")
 S SDCL(1)=SC_U_SDTTM
 I $D(^SC(SC,"LTR")) D
 .I APPTSTAT["P" S SDL=$$GET1^DIQ(44,SC,2511,"I")
 .I APPTSTAT'["P" S SDL=$$GET1^DIQ(44,SC,2510,"I")
 I SDL="" D ERRLOG^SDESJSON(.ERRORS,52,$S(APPTSTAT["P":"An appointment",1:"A clinic")_" cancellation letter is not defined for "_$$GET1^DIQ(44,SC,.01,"E")_".") Q
 S SDWH=APPTSTAT
 ;
 N %ZIS,POP,ZTDESC,ZTIO,ZTRTN,ZTSAVE
 I APPTSTAT'="C",APPTSTAT'="PC" D ERRLOG^SDESJSON(.ERRORS,284) Q
 S IOP="`"_SDID
 S %ZIS("B")="",POP=0,%ZIS="MQ" D ^%ZIS   ;alb/sat 665 - change ^%ZIS params to match PRE
 I POP D ERRLOG^SDESJSON(.ERRORS,285) Q
 S ZTIO=ION,ZTRTN="SDLET^SDCNP1A",ZTDESC="PRINT CANCEL APPOINTMENT LETTER",ZTDTH=$$NOW^XLFDT F ZTS="SDCL(","DUZ","DFN","DT","A","SDWH","AUTO(" S ZTSAVE(ZTS)=""
 K ZTS D ^%ZTLOAD K IO("Q")
 D PRINTRES(.RESULTS,APPTIEN)
 Q
NOSHOW(RESULTS,ERRORS,SC,APPTIEN,SDTTM,DFN,SDID)   ;print no-show appointment letter
 N ALS,ANS,C,DATEND,SDDT,SDLET,SDLT1,SDNSACT,SDTIME,SDV1,SDCLINNAME,APPTSTAT,SDT
 I SDTTM="" D ERRLOG^SDESJSON(.ERRORS,285) Q
 S APPTSTAT=$$GET1^DIQ(409.84,APPTIEN,.17,"I")
 I APPTSTAT'="N",(APPTSTAT'="NA") D ERRLOG^SDESJSON(.ERRORS,286) Q
 S SDT=$P(SDTTM,".",1)
 S ALS="Y",ANS="N",C=SC,SDDT=DT
 S DATEND=SDT+.9
 S (SDLT1,SDLET)=""
 S SDNSACT=0
 S SDV1=$$GET1^DIQ(44,SC,3.5,"I")
 S SDTIME=$$GET1^DIQ(409.84,APPTIEN,.101,"I")
 S SDCLINNAME=$$GET1^DIQ(44,SC,.01,"E")
 S:SDTIME="" SDTIME="*"
 S SDLET=$$GET1^DIQ(44,SC,2508,"I")
 I 'SDLET D ERRLOG^SDESJSON(.ERRORS,52,"A No-show letter is not defined for "_SDCLINNAME_".") Q
 S IOP="`"_SDID
 S %ZIS("B")="",POP=0,%ZIS="MQ" D ^%ZIS   ;alb/sat 665 - change ^%ZIS params to match PRE
 I POP D ERRLOG^SDESJSON(.ERRORS,285) Q
 S ZTIO=ION,ZTRTN="START^SDN0",ZTDESC="PRINT NO SHOW APPOINTMENT LETTER",ZTDTH=$$NOW^XLFDT F ZTS="SC","SDDT","ALS","ANS","SDLET","SDV1","SDT","C","DATEND","SDTIME","SDLT1","AUTO(","SDNSACT" S ZTSAVE(ZTS)=""
 K ZTS D ^%ZTLOAD K IO("Q")
 D PRINTRES(.RESULTS,APPTIEN)
 Q
 ; set up print results for each item
PRINTRES(RESULTS,APPTIEN) ;
 N CURCNT
 S CURCNT=$O(RESULTS("PrintResults",99999999),-1)+1
 S RESULTS("PrintResults",CURCNT,"AppointmentID")=APPTIEN
 S RESULTS("PrintResults",CURCNT,"Status")="Print Queued."
 Q
PRINTRESERR(RESULTS,APPTIEN,ERRORS) ;
 N CURCNT,ERRCNT
 S ERRCNT=0 F  S ERRCNT=$O(ERRORS("Error",ERRCNT)) Q:'ERRCNT  D
 .S CURCNT=$O(RESULTS("PrintResults",99999999),-1)+1
 .S RESULTS("PrintResults",CURCNT,"AppointmentID")=APPTIEN
 .S RESULTS("PrintResults",CURCNT,"Status")=$G(ERRORS("Error",ERRCNT))
 Q