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

BTIUMED1.m

Go to the documentation of this file.
BTIUMED1 ; SLC/JM - Active/Recent Med Objects Routine ;24-Sep-2013 14:41;DU
 ;;1.0;TEXT INTEGRATION UTILITIES;**1006,1011,1012**;Jun 20, 1997;Build 45
 ;
 ; All routines here are part of the LIST entry point of TIULMED
 ;
ADD(TXT) ; Saves TXT in TARGET
 S NEXTLINE=NEXTLINE+1
 I TAB S TXT="  "_TXT
 I TAB,HEADER S TXT="     "_TXT
 S @TARGET@(NEXTLINE,0)=TXT
 Q
ADDLNUM(TXT) ; Add text with Line Number added to front of string
 S TAB=0
 I HEADER D ADD($E(COUNT_")     ",1,5)_TXT) I 1
 E  D ADD(TXT)
 S TAB=1
 Q
ADDL(TXT) ; Add with ADDLNUM on FIRST
 I FIRST D  I 1
 .D ADDLNUM(TXT)
 .S FIRST=0
 E  D ADD(TXT)
 Q
ADDMED(XMODE,REC) ; if XMODE creates XSTR, if not add med to TARGET
 N DATA,FIRST,XSUM,XCOUNT,TOPLINE,WSTATUS
 S REC=$G(REC)
 S FIRST=1
 I XMODE S (XSUM,XCOUNT)=0,XSTR=""
 E  D
 .S TOPLINE=NEXTLINE+1,DATA="",WSTATUS=0
 .I $D(PHARM) D ADDP(20)
 .D ADDP(2)
 I TYPE="UD" D  I 1 ; Unit Dose Meds
 .I 'XMODE D
 ..I DETAILED D FLUSH S DATA="Give:"
 ..S DATA=DATA_" "
 .I $$PL(6) D ADDP(6) I 1
 .E  I $$PL(7) D ADDP(7) I 1
 .E  D ADDM("SIG")
 .D ADDM("MDR"),ADDM("SCH")
 .I DETAILED D FLUSH
 .D ADDM("SIO")
 .I +REC D RECON
 E  I TYPE="OP" D  I 1 ; Outpatient Meds
 .I 'XMODE,DETAILED D
 ..I $$PL(12) D
 ...S DATA=DATA_"  Qty:"
 ...D ADDP(12)
 ..I $$PL(11) D
 ...S DATA=$$STRIP(DATA_" for")
 ...D ADDP(11)
 ...S DATA=$$STRIP(DATA_" days")
 ..D WRAP
 .I $$ML("SIG") D  I 1
 ..I 'XMODE,DETAILED S DATA=$$STRIP(DATA_"  Sig:")
 ..D ADDM("SIG")
 .E  D ADDM("SIO"),ADDM("MDR"),ADDM("SCH")
 .D FLUSH
 .I $P(NODE,U,9)="HOLD" D
 ..I $$PL(18) D
 ...S DATA="Reason for HOLD: "
 ...D ADDP(18)
 ...D FLUSH
 ..;D WRAP
 .I CLININC>0 D
 ..I $$PL(19) D
 ...I CLININC=1 S DATA="Clinical Indication: "
 ...D ADDP(19)
 ...D FLUSH
 .I $P($P(NODE,U),";")["R" D
 ..I $$PL(21) D
 ...S DATA="Provider: "
 ...D ADDP(21)
 ...D FLUSH
 ..I $D(PHARM) D
 ...I $$ML("FILL") D  I 1
 ....S DATA=$$STRIP(DATA_"  Fills:")
 ....D ADDM("FILL")
 ....D FLUSH
 ...I $$ML("FILLS") D  I 1
 ....S DATA=$$STRIP(DATA_"  Past Fills:")
 ....D ADDM("FILLS")
 ....D FLUSH
 ..I $$PL(31) D
 ...N PHM,DATA,RXNO,ORD,RR,SSNUM
 ...S PHM=$P($P(NODE,U,31),";",1)
 ...S DATA="Pharm: "_$$GET1^DIQ(9009033.9,PHM,.01)_"  "_$$HLPHONE^HLFNC($$GET1^DIQ(9009033.9,PHM,2.1))
 ...D FLUSH
 ...S DATA=$$PADDR^APSPESG1(PHM)
 ...D FLUSH
 ...S RXNO=$P($P(NODE,U,31),";",2)
 ...Q:'+RXNO
 ...S DATA="Prov: "_$$GET1^DIQ(52,RXNO,4)
 ...D FLUSH
 ...S DATA="Trans: "_$$XMTDATE^BEHORXRT(RXNO)
 ...D FLUSH
 ...S ORD=$$GET1^DIQ(52,RXNO,39.3)
 ...Q:'+ORD
 ...S RR=$$VALUE^ORCSAVE2(+ORD,"SSRREQIEN")
 ...Q:'+RR
 ...S SSNUM=$$GET1^DIQ(9009033.91,RR,.1)
 ...S DATA="Number: "_SSNUM
 ...D FLUSH
 .I +REC D RECON
 E  I TYPE="IV" D  ; IV meds
 .I DETAILED D FLUSH
 .D ADDM("A")
 .I $$ML("B") D
 ..I 'XMODE S DATA=$$STRIP(DATA_" in")
 ..D ADDM("B")
 .D ADDP(3)
 .I DETAILED D FLUSH
 .D ADDM("SIO")
 .D FLUSH
 .I 'XMODE D
 ..N I
 ..F I=TOPLINE:1:NEXTLINE S @TARGET@(I,0)=$TR(@TARGET@(I,0),U," ")
 I XMODE D  I 1
 .I XSTR="" S XSTR="_"
 .E  I $L(XSTR)>80 S XSTR=$E(XCOUNT_"_"_XSUM_"_"_XSTR,1,80)
 E  D
 .D FLUSH
 .S WSTATUS=1
 .D ADDP(9)
 .S WSTATUS=0
 .I DETAILED D
 ..;D ADDDATE(TOPLINE,$S(MEDTYPE=OUTPTYPE:"Issu",1:"Strt"),15)
 ..I MEDTYPE=OUTPTYPE D  I 1
 ...N I
 ...I TOPLINE=NEXTLINE S I=TOPLINE+1
 ...E  I $L(@TARGET@(TOPLINE+1,0))<48 S I=TOPLINE+1
 ...E  S I=TOPLINE+2
 ...F  Q:(I'>NEXTLINE)  D ADD(" ")
 ...I $P(NODE,U,5)="" S @TARGET@(I,0)=$E(@TARGET@(I,0)_SPACE60,1,47)
 ...E  S @TARGET@(I,0)=$E(@TARGET@(I,0)_SPACE60,1,47)_"Refills: "_+$P(NODE,U,5)
 ...D ADDDATE(TOPLINE,"Issue",15)
 ...D ADDDATE(TOPLINE+1,"Last",10)
 ...D ADDDATE(TOPLINE+2,"Expr",4)
 ..E  D
 ...D ADDDATE(TOPLINE+1,"Stop",4)
 Q
FDT(PNUM) ;Returns formatted date from piece number
 N X,Y
 S Y=$P(NODE,U,PNUM)
 S X=$E(Y,4,5)_"-"_$E(Y,6,7)_"-"_$E($E(Y,1,3)+1700,3,4)
 Q X
ADDDATE(LINENUM,TXT,PNUM) ;Add date to TARGET
 I $$PL(PNUM) D
 .F  Q:(LINENUM'>NEXTLINE)  D ADD(" ")
 .S @TARGET@(LINENUM,0)=$E(@TARGET@(LINENUM,0)_SPACE60,1,60)_TXT_":"_$$FDT(PNUM)
 Q
XSUMS(STR,NOADD) ; XSUMs a string
 N IDX,LEN
 S LEN=$L(STR) I LEN'>0 Q
 I '$G(NOADD),$L(XSTR)<99 S XSTR=XSTR_STR
 F IDX=1:1:LEN S XCOUNT=XCOUNT+1,XSUM=XSUM+($A(STR,IDX)*XCOUNT)
 Q
WRAP ; Wraps DATA to the output
 I XMODE Q
 N IDX,LEN,MAX,DATA1,DONE
 S DONE=0
 F  Q:DONE  D
 .I WSTATUS S MAX=13
 .E  D
 ..I FIRST S MAX=41
 ..E  S MAX=39
 ..I 'HEADER S MAX=MAX+5
 ..I 'DETAILED S MAX=MAX+13
 .S LEN=$L(DATA)
 .I 'WSTATUS,LEN<MAX S DONE=1 Q
 .I LEN<MAX S IDX=LEN
 .E  F IDX=MAX:-1:2 Q:$E(DATA,IDX)=" "
 .I IDX<3 S IDX=MAX-1
 .S DATA1=$$STRIP($E(DATA,1,IDX))
 .I WSTATUS D  I 1
 ..S @TARGET@(TOPLINE,0)=$E(@TARGET@(TOPLINE,0)_SPACE60,1,LLEN)_DATA1
 .E  D ADDL(DATA1)
 .S DATA=$$STRIP($E(DATA,IDX+1,999))
 .I WSTATUS D
 ..S DONE=1,WSTATUS=0
 ..I $L(DATA)>0 D
 ...I TOPLINE'<NEXTLINE D ADD(" ")
 ...S @TARGET@(TOPLINE+1,0)=$E(@TARGET@(TOPLINE+1,0)_SPACE60,1,LLEN)_DATA
 ...S DATA=""
 Q
STRIP(X) ; Removes Leading and Trialing Spaces
 F  Q:$E(X)'=" "  S X=$E(X,2,999)
 F  Q:$E(X,$L(X))'=" "  S X=$E(X,1,$L(X)-1)
 Q X
ADDP(PNUM) ; Adds or XSUMs a piece of NODE
 I XMODE D  I 1
 .D XSUMS(PNUM,1)
 .D XSUMS($P(NODE,U,PNUM))
 E  D
 .N VALUE
 .S VALUE=$P(NODE,U,PNUM)
 .I PNUM=9,VALUE="SUSPENDED" S VALUE="ACTIVE (S)"
 .S DATA=$$STRIP(DATA_" "_VALUE)
 .D WRAP
 Q
ADDM(SUB,FORCE) ; Adds or XSUMs Multiple
 N IDX
 S IDX=0
 I XMODE D  I 1
 .D XSUMS(SUB,1)
 .F  S IDX=$O(^TMP("PS",$J,INDEX,SUB,IDX)) Q:IDX=""  D
 ..D XSUMS(^TMP("PS",$J,INDEX,SUB,IDX,0))
 E  D
 .I $G(FORCE),DETAILED  D FLUSH
 .F  S IDX=$O(^TMP("PS",$J,INDEX,SUB,IDX)) Q:IDX=""  D
 ..S DATA=$$STRIP(DATA_" "_^TMP("PS",$J,INDEX,SUB,IDX,0))
 ..D WRAP
 Q
FLUSH ; Flush the DATA buffer
 I 'XMODE,DATA'="" D
 .D WRAP
 .I DATA'="" D ADDL(DATA) S DATA=""
 Q
PL(PNUM) ;Retuns length of peice
 Q $L($P(NODE,U,PNUM))
ML(SUB) ;Returns true if multiple exists and contains data
 N IDX,ML
 S (IDX,ML)=0
 F  S IDX=$O(^TMP("PS",$J,INDEX,SUB,IDX)) Q:(IDX="")!ML  D
 .I $L(^TMP("PS",$J,INDEX,SUB,IDX,0)) S ML=1
 Q ML
ADDTITLE(DAYS) ;Adds a title line indicating which meds are in the list
 N MSG,ALL,SUP,SUPFX
 I ACTVONLY<2 S MSG="Active"
 E  S MSG=""
 I '+ACTVONLY S MSG=MSG_" and "
 I ACTVONLY=2 S MSG=MSG_"Expired in last "_DAYS_" days"
 I ACTVONLY=4 S MSG=MSG_"Medications on hold"
 S ALL=ALLMEDS
 I ALL=0 D
 .I ISINP S ALL=2
 .E  S ALL=3
 S MSG=MSG_" "
 I ALL'=3 S MSG=MSG_"Inpatient"
 I ALL=1 S MSG=MSG_" and "
 I ALL'=2 S MSG=MSG_"Outpatient"
 S MSG=MSG_" Medications"
 I SUPPLIES S SUPFX="in"
 E  S SUPFX="ex"
 S SUPFX="("_SUPFX_"cluding Supplies):"
 I $L(MSG)>51 D  I 1
 .D ADD(MSG)
 .D ADD(SUPFX)
 E  D
 .S MSG=MSG_" "_SUPFX
 .D ADD(MSG)
 D ADD(" ")
 Q
WARNING ;Inserts warning about CLASSORT if needed
 I CLASSORT D
 .N MSG
 .D ADD("* *  WARNING  * * Sorting by drug class may not be accurate!")
 .D ADD("Medications belonging to multiple drug classes will only be listed")
 .S MSG="under a single drug class."
 .I UNKNOWNS S MSG=MSG_"  In addition, the system is not able to"
 .D ADD(MSG)
 .I UNKNOWNS D ADD("determine the drug class of some medications.")
 Q
RECON ;Check for reconciliation
 N MED,REC,IEN,AIEN,WHEN,BY,NVAMED,RX
 S RX=+NODE
 S TYP=$P($P(NODE,U),";",2)
 S TYP=$S(TYP="O":"X",TYP="I":"U",1:"")
 S NVAMED=$P($P(NODE,U),";")
 S NVAMED=$E(NVAMED,$L(NVAMED))
 I NVAMED="N" S TYP="N"
 S REC=""
 S REC=$O(^BEHOCIR("G",TYP,RX,REC),-1) Q:REC=""  D
 .S IEN="" S IEN=$O(^BEHOCIR("G",TYP,RX,REC,IEN),-1) Q:IEN=""  D
 ..S AIEN=IEN_","_REC_","
 ..S WHEN=$$GET1^DIQ(90461.632,AIEN,.01)
 ..S BY=$$GET1^DIQ(90461.632,AIEN,.02)
 ..S DATA="Reconciled on: "_WHEN_" by "_BY
 ..D FLUSH
 Q