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

BEHOENPS.m

Go to the documentation of this file.
BEHOENPS ;MSC/IND/DKM - Summary Report for Selected Encounter ;05-Jan-2010 08:03;PLS
 ;;1.1;BEH COMPONENTS;**005004**;Mar 20, 2007
 ;=================================================================
 ; Batch entry point
 ;   BEHFLG = Which report sections to include (default to all)
 ;            where N=all notes, S=signed notes O=orders, P=PCC data
BATCH(BEHFLG) ;EP
 N BEHQUIT,BEHVSIT,BEHDAT1,BEHDAT,BEHDATX,BEHNOW,X
 S BEHNOW=$$NOW^XLFDT,BEHNOW=$S(BEHNOW#1<.17:BEHNOW\1,1:$$FMADD^XLFDT(BEHNOW\1,-1))
 S BEHDAT1=$$GET^XPAR("PKG","BEHOENPS SUMMARY START")\1
 D:'BEHDAT1 ADD^XPAR("PKG","BEHOENPS SUMMARY START",,BEHNOW)
 S BEHDAT2=$$GET^XPAR("PKG","BEHOENPS SUMMARY END")\1
 D:'BEHDAT2 ADD^XPAR("PKG","BEHOENPS SUMMARY END",,BEHNOW)
 Q:BEHDAT1>BEHNOW
 I 'BEHDAT1 D
 .S BEHDAT1=$$NOW^XLFDT,X=BEHDAT1#1,BEHDAT1=BEHDAT1\1
 .S:X<.1 BEHDAT1=$$FMADD^XLFDT(BEHDAT1,-1)
 S:BEHDAT2<BEHDAT1 BEHDAT2=BEHDAT1
 S BEHDAT=BEHDAT1-.1,BEHDAT2=BEHDAT2+.9
 U IO
 F  S BEHDAT=$O(^AUPNVSIT("B",BEHDAT)),BEHVSIT=0 Q:'BEHDAT!(BEHDAT>BEHDAT2)  D  Q:$G(BEHQUIT)
 .F  S BEHVSIT=$O(^AUPNVSIT("B",BEHDAT,BEHVSIT)) Q:'BEHVSIT  D REPORT(BEHVSIT,.BEHQUIT,.BEHFLG)  Q:$G(BEHQUIT)
 S BEHDAT=$$FMADD^XLFDT(BEHNOW,1)
 D ^%ZISC
 Q:$G(BEHQUIT)
 D CHG^XPAR("PKG","BEHOENPS SUMMARY START",,BEHDAT)
 D CHG^XPAR("PKG","BEHOENPS SUMMARY END",,BEHDAT)
 Q
 ; RPC: Retrieve report
GETRPT(DATA,BEHVSIT,BEHFLG) ;PEP - Retrieve report
 S:'$L($G(DATA)) DATA=$$TMPGBL^CIAVMRPC(99)
 I '$G(BEHVSIT) S @DATA@(1)="No visit has been selected." Q
 D CAPTURE^CIAUHFS("D REPORT^BEHOENPS(BEHVSIT,.BEHFLG)",DATA,80)
 S:'$D(@DATA) @DATA@(1)="No information on visit"
 Q
 ; Entry point for OE/RR REPORT file
OERRRPT(ROOT,ORDFN,ID,ALPHA,OMEGA,ORDTRNG,REMOTE,ORMAX,ORFHIE) ;EP
 D GETRPT(.ROOT,$$VSTR2VIS^BEHOENCX(ORDFN,$$GETVAR^CIANBUTL("ENCOUNTER.ID.ALTERNATEVISITID",,"CONTEXT.ENCOUNTER")))
 Q
 ; Generate specified report segments for a visit abstract
REPORT(BEHVSIT,BEHQUIT,BEHFLG) ;EP
 N BEHLP,BEHRTN,BEHTBL,X,Y
 Q:BEHVSIT'>0
 F BEHLP=0:1 S X=$P($T(FLAG+BEHLP),";;",2,99) Q:'$L(X)  D
 .S Y=$P(X,";")
 .S BEHTBL(Y,0)=$P(X,";",2),BEHTBL(Y,1)=$P(X,";",3,99)
 S BEHFLG=$G(BEHFLG,"SOPX")
 F BEHLP=1:1:$L(BEHFLG) D  Q:$G(BEHQUIT)
 .S X=$E(BEHFLG,BEHLP)
 .I $D(BEHTBL(X)),@BEHTBL(X,1) D @(BEHTBL(X,0)_"(BEHVSIT,.BEHQUIT)")
 Q
 ; Report flag control
FLAG ;;N;NOTES;$D(^TIU)
 ;;S;NOTES2;$D(^TIU)
 ;;O;ORDERS;$L($T(^ORQ1))
 ;;P;PCC;$L($T(^APCDVDSP))
 ;;X;PCE;$L($T(PCE^BEHOENPS))
 ;;
 ; Display all notes associated with specified visit
 ; Optionally limit notes to those with the specified status (BEHST).
NOTES(BEHVSIT,BEHQUIT,BEHST) ;
 N IEN
 F IEN=0:0 S IEN=$O(^TIU(8925,"V",BEHVSIT,IEN)) Q:'IEN  D  Q:$G(BEHQUIT)
 .I $L($G(BEHST)),$$STATUS^TIULC(IEN)'=BEHST Q
 .D GETPN(IEN)
 Q
 ; Display all signed notes associated with specific visit
NOTES2(BEHVSIT,BEHQUIT) ;
 D NOTES(.BEHVSIT,.BEHQUIT,"completed")
 Q
 ; Display all orders associated with specified visit
ORDERS(BEHVSIT,BEHQUIT) ;
 N DAT,DFN,ORLIST,ORD,HDR,HLF,LOC,X,Y
 S X=$G(^AUPNVSIT(BEHVSIT,0)),DAT=X\1,DFN=$P(X,U,5),LOC=$P(X,U,22)_";SC(",HLF=IOM\2
 Q:'DAT
 K ^TMP("ORR",$J)
 D EN^ORQ1(DFN_";DPT(",,1,1,DAT,DAT,1)
 Q:'$D(ORLIST)
 S HDR="ORDERS"
 F X=0:0 S X=$O(^TMP("ORR",$J,ORLIST,X)) Q:'X  K ORD M ORD=^(X) D  Q:$G(BEHQUIT)
 .S Y=$P($G(^OR(100,+ORD,0)),U,10)
 .I $L(Y),Y'=LOC Q
 .D HDR(.HDR,ORD("TX")+3)
 .W "ORDER #: ",+ORD,?HLF,"STATUS: ",$P(ORD,U,6),!
 .W "START: ",$$FMTE^XLFDT($P(ORD,U,4)),?HLF,"STOP: ",$$FMTE^XLFDT($P(ORD,U,5)),!
 .F Y=0:0 S Y=$O(ORD("TX",Y)) Q:'Y  W ORD("TX",Y),!
 .W !
 K ^TMP("ORR",$J)
 Q
 ; Display all PCC data associated with specified visit
PCC(APCDVDSP,BEHQUIT) ;
 Q:DUZ("AG")'="I"
 D EN^APCDVDSP
 ;S:$G(APCDBRK) BEHQUIT=1
 Q
 ; Extract specified note
GETPN(TIUDA) ;
 Q:'$$CANDO^TIULP(TIUDA,"VIEW")
 N GBL,ERR,TIU,HLF,IDX,HDR
 S GBL=$NA(^TMP("BEHOENPS",$J)),HLF=IOM\2
 K @GBL
 D EXTRACT^TIULQ(TIUDA,GBL,.ERR,".01;.02;.03;.05;.07;.08;1202;1203;1205;1208;1209;1301;1307;1402;1501:1505;1507:1513;1701","",1,"E")
 M TIU=^TMP("BEHOENPS",$J,TIUDA)
 K ^TMP("BEHOENPS",$J)
 Q:$G(ERR)
 S HDR=TIU(.01,"E")
 D HDR(.HDR)
 W "AUTHOR: ",TIU(1202,"E"),?HLF,"PATIENT NAME: ",TIU(.02,"E"),!
 W "SIGNED BY: ",TIU(1502,"E"),?HLF,"STATUS: ",TIU(.05,"E"),!
 W "VISIT: ",TIU(.03,"E"),?HLF,"LOCATION: ",TIU(1205,"E"),!!
 F IDX=0:0 S IDX=$O(TIU("TEXT",IDX)) Q:'IDX  D  Q:$G(BEHQUIT)
 .D HDR(.HDR)
 .W:'$G(BEHQUIT) TIU("TEXT",IDX,0),!
 I '$G(BEHQUIT),$L($G(TIU(1501,"E"))) D
 .W !,"/es/ "_$G(TIU(1503,"E"))
 .W !,"Signed: "_$G(TIU(1501,"E"))
 Q
 ; Get DFN from visit ien
DFN(BEHVSIT) ;
 Q +$P($G(^AUPNVSIT(BEHVSIT,0)),U,5)
 ; Start new page and output header if exceed line count
HDR(HDR,CNT) ;
 S CNT=$G(CNT,1),HDR(0)=$G(HDR(0),IOSL)+CNT
 Q:HDR(0)<(IOSL-CNT)
 I $D(HDR(1)),$E(IOST)="C" D  Q:$G(BEHQUIT)
 .N X
 .R "Press RETURN or ENTER to continue...",X:$G(DTIME,300),!
 .S:X[U!'$T BEHQUIT=1
 E  W:$D(HDR(1)) $$CJ^XLFSTR("Continued on next page ==>",IOM)
 S HDR(0)=6,HDR(1)=$G(HDR(1))+1
 S:'$D(HDR(2)) HDR(2)="HRN: "_$$HRN^BEHOPTCX($$DFN(BEHVSIT)),HDR(3)="DOS: "_$$ENTRY^CIAUDT(+$G(^AUPNVSIT(BEHVSIT,0))),HDR(4)="VISIT IEN: "_BEHVSIT,HDR=$$CJ^XLFSTR("  "_HDR_"  ",IOM,"-")
 W @IOF,!!!,HDR(2),?IOM-$L(HDR(3))\2,HDR(3),?IOM-$L(HDR(4)),HDR(4),!,HDR,!
 W $$CJ^XLFSTR("<Page "_HDR(1)_">",IOM),!!
 Q
PCE(BEHVSIT,BEHQUIT) ;Get visit information
 ;Added this entry point for non-IHS sites
 Q:DUZ("AG")="I"
 Q:'$D(BEHVSIT)
 Q:'BEHVSIT
 Q:'$D(^AUPNVSIT(BEHVSIT,0))
 D DSP,EOJ
 Q
DSP I $D(IOF),'$D(BEHOENPS("NO IOF")) W @IOF
 N D0,DA,DIC,DIQ,DR,DL,DK,DX,S,X,XX
 S BEHBRK=0 ;ACC
 S BEHVDSH="-----------------------------"
 S XX=$$^MSCDPTID(DFN)
 S X="",$P(X,"~",80)="" W !!,X,!!,"VISIT IEN:  ",BEHVSIT,!
 S X="MRN: "_XX W !,X,!
 W BEHVDSH,"     VISIT FILE     ",BEHVDSH
 S DIC="^AUPNVSIT(",DA=BEHVSIT D EN^DIQ
DSPLY1 ;DISPLAY V FILE DATA
 S BEHVFLE=9000010 F BEHVL=0:0 S BEHVFLE=$O(^DIC(BEHVFLE)) Q:BEHVFLE>9000010.99!(BEHVFLE'=+BEHVFLE)!(BEHBRK)  D DSPLY2
 Q:BEHBRK  ;ACC
 I 'BEHBRK S X="",$P(X,"~",80)="" W !!,X,!!
 Q
DSPLY2 S BEHVNM=$P(^DIC(BEHVFLE,0),U)
 S BEHVDG=^DIC(BEHVFLE,0,"GL"),BEHVIGR=BEHVDG_"""AD"",BEHVSIT,BEHVDFN)"
 S BEHVDFN="" F BEHVI=1:1 S BEHVDFN=$O(@BEHVIGR) Q:BEHVDFN=""!(BEHBRK)  D DSPLY3 Q:BEHBRK
 Q
DSPLY3 ;
 I $Y>(IOSL-5) D HEAD Q:BEHBRK
 I BEHVI<2 S X=20-$L(BEHVNM),Y=X\2,Z=X-Y W !,BEHVDSH,$J("",Z),BEHVNM,$J("",Y),BEHVDSH
 S DIC=BEHVDG,DA=BEHVDFN,DIQ(0)="C" D EN^DIQ
 Q
 I '$D(ZTQUEUED),'$D(IO("S")),$E(IOST)="C",IO=IO(0) W !!,"Enter to continue, '^' to halt " R BEHX:DTIME S:'$T BEHBRK=1 S:BEHX="^" BEHBRK=1
 Q:BEHBRK
 K S
 W:$D(IOF) @IOF
 Q
EOJ ; EOJ CLEANUP
 I '$D(ZTQUEUED),'$D(IO("S")),'BEHBRK,'$D(BEHEIN),$E(IOST)="C",IO=IO(0) W !,"End of visit display, <ENTER> to Continue" R BEHX:DTIME
 K X,Y
 K BEHVDFN,BEHVDG,BEHVDSH,BEHVDSP,BEHVFLE,BEHVI,BEHVIGR,BEHVL,BEHVNM,BEHX,BEHBRK,BEHVSIT
 Q