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

SCRPW16.m

Go to the documentation of this file.
SCRPW16 ;RENO/KEITH - Encounter 'Action Required' Report ; 01 Jan 99  9:27 PM
 ;;5.3;Scheduling;**139,144,155,161,336,466**;AUG 13, 1993;Build 2
 N SD,SDDIV,ZTSAVE,%DT,DIR,DTOUT,DUOUT,X,Y
 D TITL^SCRPW50("Encounter 'Action Required' Report")
 G:'$$DIVA^SCRPW17(.SDDIV) EXIT
 D SUBT^SCRPW50("**** Date Range Selection ****")
 W ! S %DT="AEPX",%DT("A")="Beginning date: " D ^%DT G:Y<1 EXIT S SD("BDT")=Y
EDT S %DT("A")="   Ending date: " W ! D ^%DT G:Y<1 EXIT
 I Y<SD("BDT") W !!,$C(7),"End date cannot be before begin date!",! G EDT
 S SD("EDT")=Y_.999999
 D SUBT^SCRPW50("*** Report Format Selection ***")
 S DIR(0)="S^D:DETAILED REPORT;S:STATISTICS ONLY",DIR("A")="Select report type",DIR("B")="DETAILED REPORT" D ^DIR G:($D(DTOUT)!$D(DUOUT)) EXIT S SD("STAT")=Y
 G:'$$ASK^SCRPW17(0,0,.SD,"",$S(SD("STAT")="D":"A",1:"A^1"),1) EXIT
 I SD("STAT")="D" K DIR S DIR(0)="Y",DIR("A")="Would you like a separate page for every clinic",DIR("B")="NO" W ! D ^DIR G:($D(DTOUT)!$D(DUOUT)) EXIT S SD("PAGE")=Y
 W !!,"This report requires 132 column output.",! S ZTSAVE("SDDIV")="",ZTSAVE("SDDIV(")="",ZTSAVE("SD(")="" D EN^XUTMDEVQ("RUN^SCRPW16","Enc. 'Act. Req.' Rpt.",.ZTSAVE) G EXIT
 ;
RUN ;Print report
 K ^TMP("SCRPW",$J),SDSEG,SDSTR,SDT S (SDOUT,SDLK)=0
 ;If date range includes TODAY, update appointment status
 I SD("BDT")'>DT,SD("EDT")'<DT D  G:SDOUT EXIT
 .D LOCK Q:SDOUT!'SDLK
 .N SDBEG,SDEND,X,%,%H,%I D NOW^%DTC S SDBEG=DT,SDEND=%
 .S SDEND=($P(SDEND,".")-1)_"."_999999
 .D EN^SDAMQ3(SDBEG,SDEND) K ^TMP("SDSTATS",$J) L -^SCRPW16("ACTION REQUIRED REPORT") Q
 S SDT(2)=$$T2^SCRPW18(),SDDT=SD("BDT"),SDSEG=$$SEGS^SCRPW18(.SDSEG) D STR^SCRPW18(.SDSTR) S (SDOUT,SDSTOP)=0,SDMD="",SDMD=$O(SDDIV(SDMD)),SDMD=$O(SDDIV(SDMD)) S:$P(SDDIV,U,2)="ALL DIVISIONS" SDMD=1
 F  S SDDT=$O(^SCE("B",SDDT)) Q:'SDDT!(SDDT>SD("EDT"))!SDOUT  S SDOE=0 F  S SDOE=$O(^SCE("B",SDDT,SDOE)) Q:'SDOE!SDOUT  D EVAL
 G:SDOUT EXIT
 S SDIV="" F  S SDIV=$O(^TMP("SCRPW",$J,SDIV)) Q:SDIV=""  D STOP Q:SDOUT  D
 .S SDFCT(SDIV)=0,SDCG="" F  S SDCG=$O(^TMP("SCRPW",$J,SDIV,1,SDCG)) Q:SDCG=""  S SDTCT=0 D CT1 S ^TMP("SCRPW",$J,SDIV,1,SDCG)=SDTCT
 .Q
 G:SDOUT EXIT
 S SDIV="" F  S SDIV=$O(SDDIV(SDIV)) Q:'SDIV  S SDIV(SDDIV(SDIV))=SDIV
 I 'SDDIV,$P(SDDIV,U,2)'="ALL DIVISIONS" S SDIV($P(SDDIV,U,2))=$$PRIM^VASITE()
 I $P(SDDIV,U,2)="ALL DIVISIONS" S SDI=0 F  S SDI=$O(^TMP("SCRPW",$J,SDI)) Q:'SDI  S SDX=$P($G(^DG(40.8,SDI,0)),U) S:$L(SDX) SDIV(SDX)=SDI
 D HD1^SCRPW18 D:$E(IOST)="C" DISP0^SCRPW23 I '$O(^TMP("SCRPW",$J,0)) S SDIV=0 D DHDR^SCRPW40(3,.SDT) D HDR^SCRPW18(.SDT,"") Q:SDOUT  S SDX="No activity found within selected report parameters!" W !!?(IOM-$L(SDX)\2),SDX G EXIT
 S SDIVN="" F  S SDIVN=$O(SDIV(SDIVN)) Q:SDIVN=""!SDOUT  S SDIV=SDIV(SDIVN) D DPRT(.SDIV)
 S SDI=0,SDI=$O(^TMP("SCRPW",$J,SDI)),SDMD=$O(^TMP("SCRPW",$J,SDI))
 G:SDOUT EXIT I SDMD S SDIV=0 D DPRT(.SDIV)
 I 'SDOUT,$E(IOST)="C" N DIR S DIR(0)="E" D ^DIR
EXIT K SD,SDARY,SDBDAY,SDCCT,SDCL,SDCLN,SDCT,SDDPT,SDDT,SDEDAY,SDFCT,SDFF,SDI,SDLINE,SDOE,SDOE0,SDORD,SDPAGE,SDPNOW,DFN,SDPT0,SDPTNA,SDR,SDSN,SDSTR
 K SDT,SDTCT,SDCG,SDX,SDMD,SDSTOP,%,SDFOUND,SDDEF,SDCO,SDAP0,SDDIV,SDIV,SDIVN,SDCI,SDCLPT,SDCLPTC,SDDIS,SDV,SDSDV,SDSDVC0,SDSEG,SDTY,SDY,%DT
 K SDLK,SCRPW16,SDCS,SDCO,SDZ,SDOUT,DIR,DTOUT,DUOUT,X,Y,ZTSAVE D KVA^VADPT,END^SCRPW50 Q
 ;
LOCK ;Prevent simultaneous runs of the appointment status update
 F SDI=1:1 L +^SCRPW16("ACTION REQUIRED REPORT"):1 D  Q:SDI>600!SDOUT!SDLK
 .I $T S SDLK=1 Q
 .D:SDI#60=0 STOP
 .Q
 Q
 ;
DPRT(SDIV) ;Print report for a division
 D DHDR^SCRPW40(3,.SDT) I '$D(^TMP("SCRPW",$J,SDIV)) D HDR^SCRPW18(.SDT,"") Q:SDOUT  S X="No 'action required' activity found for this division!" W !!?(132-$L(X)\2),X Q
 D:SDIV&(SD("STAT")="D") DET^SCRPW18 Q:SDOUT  D STAT^SCRPW18 Q
 ;
STOP ;Check for stop task request
 S:$G(ZTQUEUED) (SDOUT,ZTSTOP)=$S($$S^%ZTLOAD:1,1:0) Q
 ;
EVAL S SDSTOP=SDSTOP+1 I SDSTOP#3000=0 D STOP Q:SDOUT
 S SDOE0=$$GETOE^SDOE(SDOE),SDIV=$P(SDOE0,U,11) Q:$P(SDOE0,U,6)!'SDIV  Q:$$STCK(SDOE0)  Q:'$$DIV(SDIV)
 S SDCL=+$P(SDOE0,U,4),SDCLN=$S('SDCL:"**NONE**",1:$P(^SC(SDCL,0),U)),SDCG=$P($G(^SC(SDCL,0)),U,31),SDCG=$S(SD("FORMAT")'["G":"**NONE**",SDCG:$P(^SD(409.67,SDCG,0),U),1:"**NONE**")
 I SD("FORMAT")="SC",'$D(SD("CLINIC",SDCLN)) Q
 I SD("FORMAT")="RC",(($O(SD("CLINIC",""))]SDCLN)!(SDCLN]$O(SD("CLINIC",""),-1))) Q
 I "SS^RS"[SD("FORMAT"),'$$STCO() Q
 I SD("FORMAT")="SG",$P(SD("GROUP"),U,2)'=SDCG Q
 S DFN=$P(SDOE0,U,2) Q:'DFN  D DEM^VADPT M SDDPT=VADM
 I SD("ORDER")="A" S SDORD=SDDPT(1)
 I SD("ORDER")="D" S SDORD=$P(SDOE0,U)
 I SD("ORDER")="T" S SDSN=$P(SDDPT(2),U),SDORD=$E(SDSN,8,9)_$E(SDSN,6,7)_$E(SDSN,4,5)_$E(SDSN,1,3)_"."
 K SDARY M SDARY=SDSEG S (SDFOUND,SDY)=0 I $$CHEK^SCRPW18(SDOE,.SDARY,.SDSTR) S SDI="" F  S SDI=$O(SDARY(SDI)) Q:SDI=""  S SDX="" F  S SDX=$O(SDARY(SDI,SDX)) Q:SDX=""  D SET(SDX)
 K SDX D CLASK^SDCO2(SDOE,.SDX)
 ; SD*5.3*336 so all existing and future classification types are pulled
 I $D(SDX) S SDI=0 F  S SDI=$O(SDX(SDI)) Q:'SDI  I $P(SDX(SDI),U,2)="" D
 . I '$D(^SD(409.41,SDI,0)) S SDX="Classification required" D SET(SDX) Q
 . S SDX=$P($G(^SD(409.41,SDI,0)),U,1)_" classification required"
 . D SET(SDX)
 I 'SDFOUND,$P(SDOE0,U,8)=1,'$$CODT^SDCOU(DFN,SDDT,SDCL) S SDI=1,SDX="No check-out date" D SET(SDX)
 I 'SDFOUND S SDCO="" D EN^SDCOM(SDOE,0,,.SDCO) Q:SDCO>0
 I 'SDFOUND D
 .K SDZ D GETDX^SDOE(SDOE,"SDZ") I '$G(SDZ) D SET("No diagnosis on file")
 .K SDZ D GETPRV^SDOE(SDOE,"SDZ") I '$G(SDZ) D SET("No provider on file")
 .K SDZ D GETCPT^SDOE(SDOE,"SDZ") I '$G(SDZ) D SET("No procedure code on file")
 I 'SDFOUND S SDX="Unknown reason" D SET(SDX)
 D EV1(SDIV) D:SDMD EV1(0)
 Q
 ;
STCK(SDOE0) ;Check Status for action required
 ;Returns 0 if status=action required (14) or
 ;             status=inpatients (8) and check out date=""
 ;        1 if non-count clinic, OOS and otherwise
 I $P(SDOE0,U,4),'$$CLINIC^SDAMU($P(SDOE0,U,4)) Q 1
 I $P(SDOE0,U,12)=8,$P(SDOE0,U,7)="" Q 0
 I $P(SDOE0,U,12)'=14 Q 1
 Q 0
 ;
EV1(SDIV) S ^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN,SDORD,DFN,SDOE)=SDOE0,^TMP("SCRPW",$J,SDIV,3,DFN)=SDDPT(1)_U_SDDPT(2)
 Q
 ;
DIV(SDIV) ;Evaluate division
 ;Required input: SDIV=division ifn
 Q:'SDDIV 1  Q $D(SDDIV(SDIV))
 ;
STCO() ;Evaluate Stop Code
 Q:'SDCL 0  S SDCS=$P($G(^SC(SDCL,0)),U,7) Q:'SDCS 0  S SDCS=$P($G(^DIC(40.7,SDCS,0)),U,2) Q:'SDCS 0
 I SD("FORMAT")="SS" Q $D(SD("STOPCODE",SDCS))
 I (($O(SD("STOPCODE",""))]SDCS)!(SDCS]$O(SD("STOPCODE",""),-1))) Q 0
 Q 1
 ;
SET(SDX) D SET1(SDIV) D:SDMD SET1(0) Q
 ;
SET1(SDIV) S SDY=SDY+1,^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN,SDORD,DFN,SDOE,SDY)=SDX
 S ^TMP("SCRPW",$J,SDIV,2,SDCG,SDX)=$G(^TMP("SCRPW",$J,SDIV,2,SDCG,SDX))+1,SDFOUND=1
 Q
 ;
CT1 S SDCLN="" F  S SDCLN=$O(^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN)) Q:SDCLN=""  S SDCCT=0 D CT2 S ^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN)=SDCCT
 Q
 ;
CT2 S SDORD="" F  S SDORD=$O(^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN,SDORD)) Q:SDORD=""  S DFN="" F  S DFN=$O(^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN,SDORD,DFN)) Q:DFN=""  D CT3
 Q
 ;
CT3 S SDOE=0 F  S SDOE=$O(^TMP("SCRPW",$J,SDIV,1,SDCG,SDCLN,SDORD,DFN,SDOE)) Q:'SDOE  S SDFCT(SDIV)=SDFCT(SDIV)+1,SDTCT=SDTCT+1,SDCCT=SDCCT+1
 Q