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

MMRSCDI2.m

Go to the documentation of this file.
MMRSCDI2 ;LEIDOS/TCK - Print CDI report ; 4/12/17 11:57am
 ;;1.0;MRSA TOOLS REPORTS MENU;**4,5**;Mar 22, 2009;Build 146
 ;
MAIN ;
 N EXTFLG,MMRSLOC
 S NOCONF=0
 ;check if parameters are setup.
 I '$D(ZTQUEUED) D  Q
 .W !!,"This option can only be run via TaskMan"
 .W !
 D CLEAN
 D CHECK^MMRSIPC
 D CHECK
 I $D(EXTFLG) W ! H 2 Q
 S NOW=$$NOW^XLFDT(),MMRSNOW=NOW
 S FIRST=$E(NOW,1,5)_"01"
 S ENDDT=$$FMADD^XLFDT(FIRST,-1,0,0,0)_".24"
 S STRTDT=$E(ENDDT,1,5)_"01",DFLTDT=STRTDT
 S DFLTDT=STRTDT
 K EXTFLG
 S MMRSNOW=$$NOW^XLFDT()
 D MAIN2
 D QUIT
 Q
 ;
CHECK ; Check if lab tests and etiologies are setup
 N II,XX,TST,MRSASTAP,ORG,ETIONAME,MMRSET,MMRSI
 S (MDROETIO,TSTSTP)=0
 I $D(^MMRS(104.1)) D
 .S II=0 F  S II=$O(^MMRS(104.1,II)) Q:II'>0  D  Q:MDROETIO!(TSTSTP)
 ..Q:'$D(^MMRS(104.1,II,0))
 ..S ORGP=$P(^MMRS(104.1,II,0),"^")
 ..Q:$G(ORGP)'>0
 ..S ETIO=$$GET1^DIQ(104.2,ORGP,.01,"E")
 ..S ETIO=$$UPPER^DGUTL(ETIO)
 ..Q:ETIO'["DIFF"
 ..S IX=0
 ..F  S IX=$O(^MMRS(104.1,II,3,IX)) Q:IX'>0  D  Q:TSTSTP
 ...I $G(IX)>0 D
 ....Q:'$D(^MMRS(104.1,II,3,IX,0))
 ....S III=IX_","_II_","
 ....Q:III=""
 ....S TST=$$GET1^DIQ(104.15,III,.01,"E")
 ....I $G(TST)'=""&(TST["DIFF") S TSTSTP=1
 ....Q:$G(TST)'["DIFF"
 ....S TSTSTP=1
 ..I $D(^MMRS(104.1,II,6)) D
 ...S IXI=0 F  S IXI=$O(^MMRS(104.1,II,6,IXI)) Q:IXI'>0  D  Q:MDROETIO
 ....Q:IXI=""
 ....Q:'IXI
 ....S III=IXI_","_II_","
 ....S XX=$$GET1^DIQ(104.109,III,.01,"E")
 ....Q:XX'["CLOSTRIDIUM"
 ....S ETIONAME=XX,ORG=II,MDROETIO=ORG
 ;
ERROR ;
 I 'TSTSTP&'MDROETIO D
 .S EXTFLG=1
 .W !!,"   >>>The report cannot be run because either the Laboratory Test(s) "
 .W !,"       or the 'CLOSTRIDIUM DIFFICLE' Etiology are not setup "
 .W !,"       in the LAB SEARCH/EXTRACT parameters file, (104.1)."
 Q
 ;
MAIN2 ; Entry for queuing
 S MMRSNOW=$$NOW^XLFDT()
 I '$D(MMRSDIV) D PRT  Q
 D GETPARAM ; Load parameters in temp global
 D PRT
 Q
 ;
GTDIV(MMRSDIV) ;
 N I,TST,ETI,DPTR,STAID,DIV,DPTR
 S I=0
 F  S I=$O(^MMRS(104.1,I)) Q:$G(I)'>0  D  Q:$G(I)'>0
 .I $P(^MMRS(104.1,I,3,0),"^",3)>0 D
 ..S LIEN=1_","_I_","
 ..S TST=$$GET1^DIQ(104.15,LIEN,.01,"I")
 .I $P(^MMRS(104.1,I,6,0),"^",3)>0 D
 ..S LIEN=1_","_I_","
 ..S ETI=$$GET1^DIQ(104.109,LIEN,.01,"I")
 .I $G(TST)'>0&($G(ETI)'>0) K LIEN Q
 .S DPTR=$$GET1^DIQ(104.1,I,1,"I") Q:DPTR=""
 .S DIV=$$GET1^DIQ(104,DPTR,.01,"I") Q:DIV=""
 .S STAID=$$GET1^DIQ(40.8,DIV,.01,"E") Q:STAID=""
 .S MMRSDIV(STAID)=DIV
 .S (STAID,DIV,DPTR)=""
 Q
 ;
CLEAN ;
 K ^TMP($J,"MMRSCDI")
 K ^TMP($J,"MMRS")
 K ^TMP($J,"MMRSCD")
 Q
 ;
GETPARAM ; Loads lab search/extract parameters from file 104.1
 N TSTNM,TST,TEST,IEN,TIEN,ITOP,TOP,ETOP,IBACT,BACT,EBACT
 N ETIOL,ETIOLOGY,ANTI,ANTIM,INC,MRSASTAP,ETIONAME,MMRSI,MMRSET,ORG
 N MDRO
 Q:'$D(MMRSDIV)
 S DIVN="",CHK=1,NOCONF=0
 S MMRSMDRO=$O(^MMRS(104.2,"B","C. diff",0))
 I $G(MMRSDIV)="ALL" D GETDIV(.MMRSDIV)
 F  S DIVN=$O(MMRSDIV(DIVN)) Q:DIVN'?.N  D  Q:NOCONF
 .Q:DIVN=""
 .S PTR=$$GET1^DIQ(104,DIVN,.01,"I")
 .S DIVSN=$$GET1^DIQ(40.8,PTR,.01,"E")
 .I $G(DIVSN)="" S NOCONF=1 Q
 .K MMRSDIV(DIVN)
 .S MMRSDIV(DIVSN)=DIVN
 S DIVSN=""
 F  S DIVSN=$O(MMRSDIV(DIVSN)) Q:DIVSN=""!(NOCONF)  D  Q:NOCONF
 .K ^TMP($J,"MMRSCD")
 .S MDRO=MMRSMDRO
 .S DIVN=MMRSDIV(DIVSN)
 .I $G(DIVN)'>0 S DIVSN="" S NOCONF=1 Q
 .S IEN="",IEN=$O(^MMRS(104.1,"C",DIVN,MMRSMDRO,IEN))
 .Q:$G(IEN)'>0
 .S ORGP=$$GET1^DIQ(104.1,IEN,.01,"I")
 .D CHKPAR^MMRSCDI(ORGP,DIVN,.CHK)
 .I 'CHK S NOCONF=1 Q
 .S (FND,TST,INC)=0
 .I TSTSTP D
 ..S TIEN=0 F  S TIEN=$O(^MMRS(104.1,IEN,3,TIEN)) Q:'TIEN  D
 ...S TEST=$P($G(^MMRS(104.1,IEN,3,TIEN,0)),U,1)
 ...Q:'TEST
 ...S INC=INC+1
 ...S ^TMP($J,"MMRSCD","T",MDRO,TEST,0)=$P($G(^MMRS(104.1,IEN,3,TIEN,0)),U,2,3)
 .I MDROETIO D
 ..S IBACT=0 F  S IBACT=$O(^MMRS(104.1,MMRSMDRO,4,IBACT)) Q:'IBACT  D
 ...S BACT=$G(^MMRS(104.1,MMRSMDRO,4,IBACT,0))
 ...I BACT'="" S ^TMP($J,"MMRSCD","BACT",MDRO,"INC_REMARK",IBACT)=BACT
 ..S EBACT=0 F  S EBACT=$O(^MMRS(104.1,MMRSMDRO,5,EBACT)) Q:'EBACT  D
 ...S BACT=$G(^MMRS(104.1,MMRSMDRO,5,EBACT,0))
 ...I BACT'="" S ^TMP($J,"MMRSCD","BACT",MDRO,"EXC_REMARK",EBACT)=BACT
 ..S ETIOL=0 F  S ETIOL=$O(^MMRS(104.1,IEN,6,ETIOL)) Q:'ETIOL  D
 ...S ETIOLOGY=$G(^MMRS(104.1,IEN,6,ETIOL,0))
 ...I 'ETIOLOGY K ^TMP($J,"MMRSCD","ETIOL")
 ...S ^TMP($J,"MMRSCD","ETIOL",MDRO,+ETIOLOGY)=""
 ...S ANTI=0 F  S ANTI=$O(^MMRS(104.1,MMRSMDRO,6,ETIOL,1,ANTI)) Q:'ANTI  D
 ....S ANTIM=$P($G(^MMRS(104.1,MMRSMDRO,6,ETIOL,1,ANTI,0)),U)
 ....I ANTIM S ^TMP($J,"MMRSCD","ETIOL",MDRO,ETIOLOGY,ANTI)=$G(^MMRS(104.1,IEN,6,ETIOL,1,ANTI,0))
 ...I $G(ETIOLOGY)'="" D
 ....D FIND^DIC(61.2,,".01E;@","PM","CLOSTRIDIUM DIFFICILE",,"B",,,"MMRSET")
 ..S MMRSI="" F  S MMRSI=$O(MMRSET("DILIST",MMRSI)) Q:MMRSI=""  I +MMRSI>0  D
 ...S ETIONAME=$P($G(MMRSET("DILIST",MMRSI,0)),U,2)
 ...S ORG=$P($G(MMRSET("DILIST",MMRSI,0)),U,1)
 ...I ETIONAME'["CLOSTRIDIUM DIFFICILE" Q
 ...K ^TMP($J,"MMRSCD","ETIOL",MMRSMDRO,ORG)
 ...S ^TMP($J,"MMRSCD","ETIOL",MMRSMDRO,ORG)=""
 .D SETDATA
 Q
 ;
GETDIV(MMRSDIV) ;
 N I,TST,ETI,DPTR,STAID,DIV,DPTR
 S I=0
 F  S I=$O(^MMRS(104,I)) Q:$G(I)'>0  D  Q:$G(I)'>0
 .S MMRSDIV(I)=""
 Q
 ;
SETDATA ;
 N LOCATION,LOCNAME,DFN,LOCTYPE,MMRSI,SDRESULT,Y,WLOC,WARD,WARDNAME,VAIP,WRDNME
 S DFN=0 F  S DFN=$O(^DPT(DFN)) Q:'DFN  D
 .Q:'$D(^PXRMINDX(63,"PI",DFN))
 .Q:$G(DFN)'>0
 .D SETDATA2(DFN)
 Q
 ;
SETDATA2(DFN) ;
 N INTT,IEN,INDATE,INIFN,MRSA,MRSACULT,LABORDER,TSTNM,LABTEST,ORDITM,ORDTEMP,PATNM,VADM,DCDATE
 S LOC=""
 S (CDIVT,PCD)=""
 ;Get MRSA history
 D GETLAB^MMRSCDI1(DFN,.MRSA,MMRSMDRO,MMRSNOW,"CD")
 Q:'$D(MRSA)
 S I="" F  S I=$O(MRSA(I)) Q:I=""  D
 .Q:I=""
 .S CDIVT=I
 .S MRSA=$P(MRSA(I),"^",1,2)
 .S LOC=+$P(MRSA(I),"^",3)
 .S DVSN=$$GET1^DIQ(44,+LOC,3.5,"E")
 .Q:DVSN'=DIVSN
 .S WARDNAME=$$GET1^DIQ(44,+LOC,.01,"E")
 .;Get Order info
 .S LABORDER="^^"
 .Q:'CDIVT
 .S MRSA=$P(MRSA(I),"^",2)
 .S LRFILE=44
 .S STPCD=$$GET1^DIQ(LRFILE,+LOC,8,"I")
 .S TYPE=$$GET1^DIQ(LRFILE,+LOC,2,"E")
 .S SERV=$$GET1^DIQ(LRFILE,+LOC,9,"E")
 .D GTDATE(DFN,CDIVT,.INDATE,.DCDATE)
 .I $G(TYPE)'="",TYPE'="WARD" S (INDATE,DCDATE)=""
 .I $D(^TMP($J,"MMRSCD","T")) D
 ..S MDRO="" F  S MDRO=$O(^TMP($J,"MMRSCD","T",MDRO)) Q:MDRO=""  D
 ...Q:$G(MDRO)'>0
 ...S TST="" F  S TST=$O(^TMP($J,"MMRSCD","T",MDRO,TST)) Q:TST=""  D
 ....N TESTS D GORDITM(TST,.LABORDER,.TESTS) ;MIA/LMT - Added with patch MMRS*1*1
 .S PCD="",PATNM=$$GET1^DIQ(2,DFN,.01,"E")
 .Q:$D(^TMP($J,"MMRSCDI",WARDNAME,PATNM,DFN,CDIVT))
 .I $D(^TMP($J,"MMRSCDI",WARDNAME,PATNM,DFN)) D
 ..S PCD=999999999999999
 ..S PCD=$O(^TMP($J,"MMRSCDI",WARDNAME,PATNM,DFN,PCD),-1)
 .S CD=CDIVT,CD=$O(MRSA(CD),-1)
 .I $G(CD)>0,CD<CDIVT S PCD=CD
 .Q:CDIVT<STRTDT
 .S ^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM,DFN,CDIVT)=$G(TYPE)_U_$G(SERV)_U_$G(STPCD)_U_$G(CDIVT)_U_$G(INDATE)_U_$G(DCDATE)_U_$G(MRSA)_U_$G(PCD),PCD=""
 K MRSA
 Q
 ;
GTDATE(DFN,CDIVT,IND,DCDT) ;
 N DATE,IEN
 S (IND,DCDT)="",FND=0
 Q:$G(CDIVT)=""
 Q:'$D(^DGPM("APTT1",DFN))
 S DATE=9999999999,TT=1
 F  S DATE=$O(^DGPM("APTT"_TT,DFN,DATE),-1) Q:DATE=""  D  Q:FND
 .Q:DATE=""
 .I CDIVT<DATE Q
 .S IEN="",IEN=$O(^DGPM("APTT"_TT,DFN,DATE,IEN))
 .Q:$G(IEN)'>0
 .I $G(IEN)>0 D
 ..S IND=$$GET1^DIQ(405,IEN,.01,"I")
 ..S WRD=$$GET1^DIQ(405,IEN,.06,"E")
 ..S LOCNME="",LOCNME=$$GET1^DIQ(44,LOC,.01,"E")
 .I WRD=LOCNME S FND=1
 .S NXDT=$O(^DGPM("APTT"_TT,DFN,DATE),-1)
 .I $G(NXDT)'>0 K NXDT S FND=1
 .I $G(NXDT)>0 S DATE=NXDT,NXDT=""
 .Q:$G(DATE)'>0
 .S IEN="",IEN=$O(^DGPM("APTT"_TT,DFN,DATE,IEN))
 .S TIEN=$$GET1^DIQ(405,IEN,.17,"I")
 .I $G(TIEN)'>0 Q
 .S DCDT=$$GET1^DIQ(405,TIEN,.01,"I")
 .I DCDT>CDIVT S FND=1,DCDT="" Q
 .I DCDT'="" S FND=1 Q
 Q
 ;
GORDITM(LABTEST,LABORDER,TESTS) ;MIA/LMT - Added with patch MMRS*1*1 - Include panels in search
 N ORDITM,ORDTEMP,LABPANEL
 I $D(TESTS(LABTEST)) Q  ;prevent infinite recursion; if site has Panel A within Panel B, and Panel B within Panel A
 S TESTS(LABTEST)=1 ;mark that we have searched this test (to prevent infinite recursion)
 S ORDITM=0 F  S ORDITM=$O(^ORD(101.43,"ID",LABTEST_";99LRT",ORDITM)) Q:'ORDITM  D
 .S ORDTEMP=$$GETORD(DFN,ORDITM,INDATE)
 .I $P(LABORDER,U,1)'="YES"!(($P(LABORDER,U,3)'="YES")&($P(ORDTEMP,U,3)="YES")) S LABORDER=ORDTEMP
 S LABPANEL=0 F  S LABPANEL=$O(^LAB(60,"AB",LABTEST,LABPANEL)) Q:'LABPANEL  D
 .D GORDITM(LABPANEL,.LABORDER,.TESTS) ;Recursive call to check for tests within panels
 Q
GETORD(DFN,ORDITM,INDATE) ;
 N RESULT,START,STOP,DAS,STATUS,ORUPCHUK,LABREC
 S RESULT="^^"
 S START=$$FMADD^XLFDT(INDATE,-1)-.0000001
 F  S START=$O(^PXRMINDX(100,"PI",DFN,ORDITM,START)) Q:'START  D
 .S STOP="" F  S STOP=$O(^PXRMINDX(100,"PI",DFN,ORDITM,START,STOP)) Q:STOP=""  D
 ..S DAS="" F  S DAS=$O(^PXRMINDX(100,"PI",DFN,ORDITM,START,STOP,DAS)) Q:DAS=""  D
 ...D EN^ORX8(+DAS)
 ...S STATUS=$P(ORUPCHUK("ORSTS"),U,1)
 ...I STATUS'=2,STATUS'=5,STATUS'=6 Q
 ...S LABREC="NO"
 ...I STATUS=6!(STATUS=2) S LABREC="YES"
 ...I $P(RESULT,U,3)'="YES" S RESULT="YES^"_START_U_LABREC
 Q RESULT
PRT ;
 I '$D(MMRSDIV) D  Q
 .W !!,"    >>>Divisions are not setup in Taskman. You must configure the"
 .W !,"        the Divisions for this report in TaskMan in order for the "
 .W !,"        report to run."
 .W !!
 I NOCONF D  Q
 .W !!,"   >>>The report cannot be run because either the Laboratory Tests "
 .W !,"       or the 'CLOSTRIDIUM DIFFICILE' Etiology are not setup "
 .W !,"       in the LAB SEARCH/EXTRACT parameters file, (104.1)."
 .W !!
 N LN,PG,LOCNAME,PATNM,DFN,NODE,LAST4,INTT,ADT,ORDDATE,VADM,QUIT,COUNT,DOB,PRVCDI
 K ^TMP($J,"MMRSCDI","T")
 K ^TMP($J,"MMRSCDI","ETIOL")
 S $P(LN,"-",160)=""
 S PG=1,QUIT=0,DVS=""
 F  S DVS=$O(MMRSDIV(DVS)) Q:DVS=""  D
 .S DIVSN=DVS
 .I '$D(^TMP($J,"MMRSCDI",DIVSN)) D  Q
 ..S WARDNAME=""
 ..D PRTHDRS
 ..W !!,"NO RECORDS FOUND FOR REPORTING PERIOD."
 .S WARDNAME="" F  S WARDNAME=$O(^TMP($J,"MMRSCDI",DIVSN,WARDNAME)) Q:WARDNAME=""  D  Q:QUIT
 ..I WARDNAME="" S QUIT=1 Q
 ..Q:'$D(^TMP($J,"MMRSCDI",DIVSN,WARDNAME))
 ..D PRTHDRS
 ..S PATNM="" F  S PATNM=$O(^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM)) Q:PATNM=""  D
 ...I PATNM?.N K ^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM) Q
 ...S DFN=0 F  S DFN=$O(^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM,DFN)) Q:'DFN  D  Q:'DFN
 ....S CD=0 F  S CD=$O(^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM,DFN,CD)) Q:'CD  D
 .....S NODE=$G(^TMP($J,"MMRSCDI",DIVSN,WARDNAME,PATNM,DFN,CD))
 .....S TYPE=$P(NODE,"^")
 .....S SERV=$P(NODE,"^",2)
 .....S STPCD=$P(NODE,"^",3)
 .....S CDIVT=$P(NODE,"^",4) I $G(CDIVT)>0 D
 ......S CDIVT=$$FMTE^XLFDT(CDIVT,2)
 ......I CDIVT["@" S CDIVT=$TR(CDIVT,"@"," ")
 .....S INDATE=$P(NODE,"^",5) I $G(INDATE)>0 D
 ......S INDATE=$$FMTE^XLFDT(INDATE,2)
 ......I INDATE["@" S INDATE=$TR(INDATE,"@"," ")
 .....S DCDT=$P(NODE,U,6) I $G(DCDT)>0 D
 ......S DCDT=$$FMTE^XLFDT(DCDT,2)
 ......I DCDT["@" S DCDT=$TR(DCDT,"@"," ")
 .....S PRVCDI=$P(NODE,U,8) I $G(PRVCDI)>0 D
 ......S PRVCDI=$$FMTE^XLFDT(PRVCDI,2)
 ......I PRVCDI["@" S PRVCDI=$TR(PRVCDI,"@"," ")
 .....D KVA^VADPT
 .....D DEM^VADPT
 .....S LAST4=$E($P(VADM(2),U),6,9)
 .....D KVA^VADPT
 .....S ORDDATE=$P(NODE,"^",5)
 .....I ORDDATE S ORDDATE=$$FMTE^XLFDT(ORDDATE,"2M")
 .....S DOB=$$GET1^DIQ(2,DFN,.03,"E")
 .....W !,$E(PATNM,1,30),?25,LAST4,?30,DOB,?42,$G(CDIVT),?70,$G(INDATE),?90,$G(WARDNAME),?106,$G(DCDT),?130,$G(PRVCDI)
 .....S COUNT=$G(COUNT)+1
 .....S DL="^"
 ....S PRVCDI=""
 ....I $Y+2>IOSL D PRTHDRS
 W !!,"END OF REPORT"
 Q
 ;
PRTHDRS ; Helper Function for PRT - Prints report headers
 W @IOF
 W ?13,"FACILITY CDI CASES REPORT"
 W !,?13,"Division: ",DIVSN
 W !,?13,"Geographical Location: ",WARDNAME
 W !,?13,"Report period: ",$$FMTE^XLFDT(STRTDT)," to ",$$FMTE^XLFDT(ENDDT)
 W !,?13,"Report printed on: ",$$FMTE^XLFDT(MMRSNOW),?75,"PAGE: ",PG
 W !,"PATIENT",?25,"SSN",?30,"DOB",?42,"CDI Event D/T",?70,"ADM D/T",?90,"LOCATION",?105,"DC D/T",?130,"PREV CDI Event D/T"
 W !,LN
 S PG=PG+1
 Q
ASKDVC ;Prompts user for device of output (allows queuing)
 W !!
 N MMRSVAR,ZTSK
 W !!!,"This report is designed for a 132 column format (compressed).",!
 S MMRSVAR("STRTDT")="",MMRSVAR("DFLTDT")="",MMRSVAR("ENDDT")=""
 S MMRSVAR("MMRSNOW")="",MMRSVAR("TSTSTP")="",MMRSVAR("MDROETIO")=""
 S MMRSVAR("MMRSDIV")="",MMRSVAR("MMRSDIV(")=""
 D EN^XUTMDEVQ("MAIN2^MMRSCDI2","Print CDI report (MMRSCDI2)",.MMRSVAR,"QM",1)
 W:$D(ZTSK) !,"Report Queued to Print ("_ZTSK_").",!
 Q
 ;
QUIT ;
 K ENDDT,FND,CDI,LCPTR,LRFILE,MMRSMDRO,PCDIVT,PRINT,PCDIVT,SERV
 K STPCD,STRTDT,TYPE,WPTR,WRDPTR,X2,X10,X12,X2,X3,X4,X5,X6,X7,X8,X9
 K X1,X11,MRSA,^TMP($J),ORGP,MDROETIO,CNT,PCD,CD,ETIO,III,IX,I
 K LOC,MMRSNOW,PTR,TSTSTP,MMRSDIV,NOCONF,CHK,DFLTDT,DIVN,DIVSN,DL
 K DVS,DVSN,FIRST,IXI,LOCNME,NOW,TT,WRD,ZTQUEUED
 Q
 ;