VistA-FOIAVistA/r/SURGERY-SR/SROQD0.m

65 lines
4.6 KiB
Mathematica

SROQD0 ;BIR/ADM-Cases with Deaths within 30 Days ; [ 02/05/99 9:38 AM ]
;;3.0; Surgery ;**62,70,50,87**;24 Jun 9
;
;** NOTICE: This routine is part of an implementation of a nationally
;** controlled procedure. Local modifications to this routine
;** are prohibited.
;
AC F S SRSD=$O(^SRF("AC",SRSD)) Q:'SRSD!(SRSD>SRED)!SRSOUT S SRTN=0 F S SRTN=$O(^SRF("AC",SRSD,SRTN)) Q:'SRTN I $D(^SRF(SRTN,0)),$$MANDIV^SROUTL0(SRINSTP,SRTN) S SRDTH=0 D CASE I SRDTH S ^TMP("SRDTH",$J,DFN)=""
D MORT S DFN=0 F S DFN=$O(^TMP("SRDEATH",$J,DFN)) Q:'DFN D:SRSEL=1 TOT D:SRSEL=2 SPEC D:SRSEL=3 INDEX
D CLEAN
Q
TOT S SRNM=^TMP("SRNM",$J,DFN) I $O(^TMP("SRREL",$J,DFN,0))="" S SRIOSTAT=^TMP("SRDEATH",$J,DFN),SRTN=^TMP("SRINOUT",$J,DFN,SRIOSTAT),^TMP("SRSEC",$J,SRIOSTAT,SRNM,DFN)=SRTN Q
S SRSD=$O(^TMP("SRREL",$J,DFN,0)) I SRSD S SRTN=$O(^TMP("SRREL",$J,DFN,SRSD,0)) I SRTN S SRIOSTAT=^TMP("SRREL",$J,DFN,SRSD,SRTN),^TMP("SRSEC",$J,SRIOSTAT,SRNM,DFN)=SRTN
Q
SPEC S SRNM=^TMP("SRNM",$J,DFN) I $O(^TMP("SRREL",$J,DFN,0))="" S SRNAT=^TMP("SRDEATH",$J,DFN),SRTN=^TMP("SRNAT",$J,DFN,SRNAT),^TMP("SRSEC",$J,SRNAT,SRNM,DFN)=SRTN Q
S SRSD=$O(^TMP("SRREL",$J,DFN,0)) I SRSD S SRTN=$O(^TMP("SRREL",$J,DFN,SRSD,0)) I SRTN S SRNAT=^TMP("SRREL",$J,DFN,SRSD,SRTN),^TMP("SRSEC",$J,SRNAT,SRNM,DFN)=SRTN
Q
INDEX S SRNM=^TMP("SRNM",$J,DFN) I $O(^TMP("SRREL",$J,DFN,0))="" S SRPROC=^TMP("SRDEATH",$J,DFN),SRTN=^TMP("SRNAT",$J,DFN,SRPROC),^TMP("SRSEC",$J,SRPROC,SRNM,DFN)=SRTN Q
S SRSD=$O(^TMP("SRREL",$J,DFN,0)) I SRSD S SRTN=$O(^TMP("SRREL",$J,DFN,SRSD,0)) I SRTN S SRPROC=^TMP("SRREL",$J,DFN,SRSD,SRTN),^TMP("SRSEC",$J,SRPROC,SRNM,DFN)=SRTN
Q
CASE ; examine case
Q:'$P($G(^SRF(SRTN,.2)),"^",12)!($P($G(^SRF(SRTN,"NON")),"^")="Y")!$P($G(^SRF(SRTN,30)),"^")
S SR(0)=^SRF(SRTN,0),DFN=$P(SR(0),"^") D DEM^VADPT Q:'$P(VADM(6),"^")
S SRIOSTAT=$P(SR(0),"^",12) I SRIOSTAT'="I"&(SRIOSTAT'="O") S VAIP("D")=SRSD D IN5^VADPT S SRIOSTAT=$S(VAIP(13):"I",1:"O") K VAIP
S Y=$P(SR(0),"^",4),SRSS=$S(Y:Y,1:9999)
I SRSEL=2 S SRNAT=$S(SRSS=9999:9999,1:$P(^SRO(137.45,SRSS,0),"^",2))
I SRSD<$P(VADM(6),"^") S X1=SRSD,X2=30 D C^%DTC I $P(VADM(6),"^")'>X S SRDTH=1
I SRDTH S ^TMP("SRDTH",$J,DFN)=""
Q
TMP ; update ^TMP
S SRREL=$P($G(^SRF(SRTN,.4)),"^",7) I '$D(^TMP("SR",$J,DFN)) S ^TMP("SRPAT",$J,VADM(1),DFN)=VA("PID")_"^"_$P(VADM(3),"^")_"^"_$P(VADM(6),"^"),^TMP("SRNM",$J,DFN)=VADM(1)
S ^TMP("SR",$J,DFN,SRSD,SRTN)=SRSS_"^"_SRIOSTAT_"^"_SRREL_"^"_$P($G(^SRF(SRTN,"CON")),"^")
I SRSEL=1 S ^TMP("SRDEATH",$J,DFN)=SRIOSTAT,^TMP("SRINOUT",$J,DFN,SRIOSTAT)=SRTN,^TMP("SRNAT",$J,DFN,SRSS)=SRTN I SRREL="R" S ^TMP("SRREL",$J,DFN,(9999999-SRSD),SRTN)=SRIOSTAT
I SRSEL=2 S ^TMP("SRDEATH",$J,DFN)=SRNAT,^TMP("SRNAT",$J,DFN,SRNAT)=SRTN I SRREL="R" S ^TMP("SRREL",$J,DFN,(9999999-SRSD),SRTN)=SRNAT
I SRSEL=3 D DRPT^SROQ0A
Q
PAGE I $E(IOST)="P"!SRHDR G HDR
D PRESS^SROQD I SRSOUT Q
HDR ; print heading
I $D(ZTQUEUED) D ^SROSTOP I SRHALT S SRSOUT=1 Q
W:$Y @IOF W:$E(IOST)="P" !,?(IOM-$L(SRINST)\2),SRINST W !,?(IOM-$L(SRRPT)\2),SRRPT,?(IOM-10),$J("PAGE "_SRPAGE,9),!,?(IOM-$L(SRFRTO)\2),SRFRTO
W !,?(IOM-$L(SRPRINT)\2),SRPRINT I SRIO'="A" S X=$S(SRIO="I":"INPATIENT",1:"OUTPATIENT")_" DEATHS" W !,?(IOM-$L(X)\2),X
Q:SRHDR2
W !,?124,"DEATH",!,"OP DATE",?10,"CASE #",?22,"IN/OUT",?31,"SURGICAL SPECIALTY",?69,"PROCEDURE(S)",?123,"RELATED"
S SRHDR=0,SRPAGE=SRPAGE+1 W ! F I=1:1:IOM W "="
I SRSNM W !,SRNAME_" * * Continued from previous page * *",!
Q
SUM ; print category totals
D:$Y+6>IOSL PAGE Q:SRSOUT
W !,"TOTAL DEATHS: "_SRDTOT
Q
MORT ; look for operations in next quarter
S X1=SDATE,X2=-30 D C^%DTC S SRSD1=9999999.999999-(X-.0001),X1=EDATE,X2=30 D C^%DTC S SRED1=9999999.999999-(X+.9999)
S DFN=0 F S DFN=$O(^TMP("SRDTH",$J,DFN)) Q:'DFN D DEM^VADPT D
.K ^TMP("SRTN",$J) S SRINV=SRED1 F S SRINV=$O(^SRF("ADT",DFN,SRINV)) Q:'SRINV!(SRINV>SRSD1) S SRTN=0 F S SRTN=$O(^SRF("ADT",DFN,SRINV,SRTN)) Q:'SRTN D
..S ^TMP("SRTN",$J,$P(^SRF(SRTN,0),"^",9),SRTN)=""
.S SRSD=0 F S SRSD=$O(^TMP("SRTN",$J,SRSD)) Q:'SRSD S SRTN=0 F S SRTN=$O(^TMP("SRTN",$J,SRSD,SRTN)) Q:'SRTN S SRDTH=0 D CASE I SRDTH D TMP
Q
CLEAN ; deselect deaths attributable to operations outside date range
S SRNAT="" F S SRNAT=$O(^TMP("SRSEC",$J,SRNAT)) Q:SRNAT="" S SRNM="" F S SRNM=$O(^TMP("SRSEC",$J,SRNAT,SRNM)) Q:SRNM="" S DFN=0 F S DFN=$O(^TMP("SRSEC",$J,SRNAT,SRNM,DFN)) Q:'DFN D
.S SRTN=^TMP("SRSEC",$J,SRNAT,SRNM,DFN),SRSDATE=$P(^SRF(SRTN,0),"^",9) I SRSDATE>(EDATE+.9999)!(SRSDATE<(SDATE-.0001)) D
..K ^TMP("SRSEC",$J,SRNAT,SRNM,DFN),^TMP("SRDEATH",$J,DFN),^TMP("SRNM",$J,DFN),^TMP("SRPAT",$J,SRNM,DFN)
..K ^TMP("SRINOUT",$J,DFN),^TMP("SRNAT",$J,DFN),^TMP("SRREL",$J,DFN),^TMP("SR",$J,DFN)
Q