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

ORCD.m

Go to the documentation of this file.
  1. ORCD ; SLC/MKB - Order Dialog utilities ;12/15/2006
  1. ;;3.0;ORDER ENTRY/RESULTS REPORTING;**8,38,68,94,161,141,195,215,243**;Dec 17,1997;Build 242
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. INPT() ; -- Return 1 or 0, if patient/order sheet = inpatient
  1. N Y S Y=$S($G(ORWARD):1,$G(^DPT(+ORVP,.105)):1,1:0)
  1. I $G(OREVENT) D ;override if delayed order
  1. . N X,X0 S X=$$EVT^OREVNTX(+OREVENT),X0=$G(^ORD(100.5,+X,0))
  1. . I $P(X0,U,12) S X0=$G(^ORD(100.5,$P(X0,U,12),0)) ;use parent
  1. . S X=$P(X0,U,2) Q:X="M" Q:X="O" ;M/O keep current inpt status
  1. . S Y=$S(X="A":1,X="T":1,1:0)
  1. . I X="D",$P(X0,U,7)=41 S Y=1 ;From ASIH = Inpt
  1. . I X="T",$P(X0,U,7),$P(X0,U,7)<4 S Y=0 ;pass = Outpt
  1. Q Y
  1. ;
  1. EXT(P,I,F) ; -- Returns external value of ORDIALOG(Prompt,Instance)
  1. N TYPE,PARAM,FNUM,IENS,X,Y,J,Z
  1. S TYPE=$E($G(ORDIALOG(P,0))),PARAM=$P($G(ORDIALOG(P,0)),U,2)
  1. S X=$G(ORDIALOG(P,I)) I X="" Q ""
  1. I TYPE="N",X<1 S X=0_+X I X="00" S X=0
  1. I "FNW"[TYPE Q X
  1. I TYPE="Y" Q $S(X:"YES",X=0:"NO",1:"")
  1. I TYPE="D" S:'$L($G(F)) F=1 Q $$FMTE^XLFDT(X,F)
  1. I TYPE="R" Q $$FTDATE(X,$G(F)) ; DAY@TIME
  1. I TYPE="P" D Q Y
  1. . S PARAM=$P(PARAM,":"),FNUM=$S(PARAM:+PARAM,1:+$P(@(U_PARAM_"0)"),U,2))
  1. . S IENS=+X_",",J=$L(PARAM,",") I J>2 F S J=J-2 Q:J'>0 S Z=$P(PARAM,",",J),IENS=IENS_$S(Z:Z,1:+$P(Z,"(",2))_","
  1. . S:'+$G(F) F=.01 S Y=$$GET1^DIQ(FNUM,IENS,+F)
  1. . I Y="",F'=.01 S Y=$$GET1^DIQ(FNUM,IENS,.01)
  1. I TYPE="S" F J=1:1:$L(PARAM,";") S Z=$P(PARAM,";",J) I $P(Z,":")=X S Y=$S(+$G(F):X,1:$P(Z,":",2)) Q
  1. Q $G(Y)
  1. ;
  1. FTDATE(X,F) ; -- Returns free text form of date (i.e. TODAY)
  1. N D,T,P,Y I X="" Q ""
  1. S X=$$UP^XLFSTR(X),D=$P(X,"@"),T=$P(X,"@",2) ; D=date,T=time parts
  1. I "NOW"[X Q "NOW"
  1. I "NOON"[X Q "NOON"
  1. I $E("MIDNIGHT",1,$L(X))=X Q "MIDNIGHT"
  1. I (X="AM")!(X="NEXT") Q X_" Lab collection"
  1. I (X="NEXTA")!(X="CLOSEST") Q $S(X="NEXTA":"NEXT",1:X)_" administration time"
  1. I $E(D)'="T",$E(D)'="V",($E(D)'="N"!($E(D,1,3)="NOV")) D Q $$FMTE^XLFDT(X,F)
  1. . N %DT S %DT="TX" D ^%DT S:Y>0 X=Y S:'$G(F) F=1
  1. S P=$S(D["+":"+",D["-":"-",1:"")
  1. I P="" S Y=$S($E(D)="T":"TODAY",$E(D)="V":"NEXT VISIT",1:"NOW")
  1. FTD1 E D
  1. . N OFFSET,NUM,UNIT
  1. . S OFFSET=$P(D,P,2),NUM=+OFFSET,UNIT=$E($P(OFFSET,NUM,2)) ; +/-#D
  1. . I $E(D)="T",NUM=1,UNIT=""!(UNIT="D") S Y=$S(P="+":"TOMORROW",1:"YESTERDAY") Q
  1. . S Y=NUM_" "_$S(UNIT="'":"MINUTE",UNIT="H":"HOUR",UNIT="W":"WEEK",UNIT="M":"MONTH",1:"DAY")
  1. . S:NUM>1 Y=Y_"S" ; plural
  1. . S:$E(D)="N" Y=Y_" "_$S(P="+":"FROM NOW",1:"AGO")
  1. . S:$E(D)="T" Y=Y_" "_$S(P="+":"FROM TODAY",1:"AGO")
  1. . S:$E(D)="V" Y=Y_" "_$S(P="+":"AFTER",1:"BEFORE")_" NEXT VISIT"
  1. I $L(T) S Y=Y_"@"_$$TIME(T)
  1. Q Y
  1. ;
  1. FTDHELP ; -- Displays ??-help for R-type prompts
  1. G R^ORCDLGH
  1. Q
  1. ;
  1. FTDCOMP(X1,X2,OPER) ; -- Compares free text dates from prompts X1 & X2
  1. ; Returns 1 or 0, IF $$VAL(X1)<OPER>$$VAL(X2) is true
  1. N X,Y,Y1,Y2,Z,%DT
  1. S X=$$VAL(X1),%DT="TX" D ^%DT S Y1=Y ; Y'>0 ??
  1. S X=$$VAL(X2),%DT="TX" D ^%DT S Y2=Y ; Y'>0 ??
  1. S Z="I "_Y1_OPER_Y2 X Z
  1. Q $T
  1. ;
  1. TIME(X) ; -- Returns 00:00 PM formatted time
  1. N Y,Z,%DT
  1. I X?1U,"BNE"[X Q $S(X="B":"BREAKFAST",X="N":"NOON",X="E":"EVENING",1:"")
  1. I "NOON"[X Q X
  1. I "MIDNIGHT"[X Q "MIDNIGHT"
  1. S X="T@"_X,%DT="TX" D ^%DT I Y'>0 Q ""
  1. S Z=$$FMTE^XLFDT(Y,"2P"),Z=$P(Z," ",2)_$$UP^XLFSTR($P(Z," ",3))
  1. Q Z
  1. ;
  1. VAL(TEXT,INST) ; -- Returns internal form of TEXT's current value
  1. N I,X S X="" S:'$G(INST) INST=1
  1. I '$D(ORDIALOG("B",TEXT)) S I=$O(ORDIALOG("B",TEXT)) Q:$E(I,1,$L(TEXT))'=TEXT X S TEXT=I ; partial match
  1. S X=$P($G(ORDIALOG("B",TEXT)),U,2) ; ptr
  1. Q $G(ORDIALOG(X,INST))
  1. ;
  1. ORDMSG(OI) ; -- Display order message for orderable OI
  1. Q:'$O(^ORD(101.43,OI,8,0)) ; no order message
  1. N I S I=0 W !
  1. F S I=$O(^ORD(101.43,OI,8,I)) Q:I'>0 W !,$G(^(I,0))
  1. W ! Q
  1. ;
  1. PTR(NAME) ; -- Returns pointer to Dialog file for prompt NAME
  1. Q +$O(^ORD(101.41,"AB",$E(NAME,1,63),0))
  1. ;
  1. NMSP(PKG) ; -- Returns package namespace from pointer
  1. N Y S Y=$$GET1^DIQ(9.4,+PKG_",",1)
  1. S:$E(Y,1,2)="PS" Y="PS" S:Y="GMRV" Y="OR"
  1. Q Y
  1. ;
  1. GETQDLG(QIFN) ; -- define ORDIALOG(PROMPT) for quick order QIFN
  1. S ORDIALOG=$$DEFDLG(QIFN) Q:'ORDIALOG
  1. D GETDLG(ORDIALOG),GETORDER("^ORD(101.41,"_QIFN_",6)")
  1. X:$D(^ORD(101.41,QIFN,3)) ^(3) ; entry action for quick order
  1. Q
  1. ;
  1. DEFDLG(QDLG) ; -- Returns default dialog for QDLG
  1. N DG,DLG,TOP S DG=+$P($G(^ORD(101.41,+QDLG,0)),U,5)
  1. S DLG=+$P($G(^ORD(100.98,DG,0)),U,4) ; default dialog
  1. I 'DLG S TOP=+$O(^ORD(100.98,"AD",DG,0)),DLG=+$P($G(^ORD(100.98,TOP,0)),U,4)
  1. Q DLG
  1. ;
  1. GETDLG(IFN) ; -- define ORDIALOG(PROMPT) for dialog IFN
  1. N SEQ,DA,ITEM,PTR,PROMPT,TEXT,INDEX,HELP,XHELP,SCREEN,ORD,INPUTXFM,LKP
  1. S SEQ=0 K ^TMP("ORWORD",$J)
  1. F S SEQ=$O(^ORD(101.41,IFN,10,"B",SEQ)) Q:SEQ'>0 S DA=0 F S DA=$O(^ORD(101.41,IFN,10,"B",SEQ,DA)) Q:'DA D
  1. . S ITEM=$G(^ORD(101.41,IFN,10,DA,0)),INPUTXFM=$G(^(.1)),HELP=$G(^(1)),SCREEN=$G(^(4)),XHELP=$G(^(6))
  1. . S PTR=$P(ITEM,U,2),TEXT=$P(ITEM,U,4),INDEX=$P(ITEM,U,10) Q:'PTR
  1. . S:'$L(TEXT) TEXT=$P(^ORD(101.41,PTR,0),U,2) K ORD
  1. . S PROMPT=$G(^ORD(101.41,PTR,1)),ORD=DA_U_$P(PROMPT,U,3)
  1. . S ORD(0)=$P(PROMPT,U)_$S($P(PROMPT,U)="S":"M",1:"")_U_$P(PROMPT,U,2)_$S($L(INPUTXFM):U_INPUTXFM,1:"")
  1. . S ORD("A")=TEXT S:$L($P(ITEM,U,13)) ORD("TTL")=$P(ITEM,U,13)
  1. . I $P(ITEM,U,7) S ORD("MAX")=$P(ITEM,U,12),ORD("MORE")=$P(ITEM,U,14) ; fields for multiples
  1. . I $L(HELP) S LKP=$P(HELP,U,2),HELP=$P(HELP,U) S:$L(HELP) ORD("?")=HELP S:$L(LKP) ORD("LKP")=$S($L(LKP,";")>1:$TR(LKP,";","^"),1:U_LKP)
  1. . S:$L(XHELP) ORD("??")=U_XHELP
  1. . S:$L(INDEX) ORD("D")=INDEX
  1. . S:$L(SCREEN) ORD("S")=SCREEN
  1. . S ORDIALOG("B",$$UP^XLFSTR($P(TEXT,":")))=SEQ_U_PTR
  1. . M ORDIALOG(PTR)=ORD
  1. Q
  1. ;
  1. GETDLG1(IFN) ; -- basic ORDIALOG(PROMPT) for dialog IFN
  1. N SEQ,DA,PROMPT,PTR,WINCTRL
  1. K ^TMP("ORWORD",$J) S SEQ=0
  1. F S SEQ=$O(^ORD(101.41,IFN,10,"B",SEQ)) Q:SEQ'>0 S DA=0 F S DA=$O(^ORD(101.41,IFN,10,"B",SEQ,DA)) Q:'DA D
  1. . S PTR=$P($G(^ORD(101.41,IFN,10,DA,0)),U,2) Q:'PTR
  1. . S WINCTRL=$P($G(^ORD(101.41,IFN,10,DA,"W")),U)
  1. . S PROMPT=$G(^ORD(101.41,PTR,1)) Q:'$L(PROMPT)
  1. . S ORDIALOG(PTR)=DA_U_$P(PROMPT,U,3)_U_WINCTRL
  1. . S ORDIALOG(PTR,0)=$P(PROMPT,U,1,2)
  1. Q
  1. ;
  1. GETORDER(ROOT,ARRAY) ; -- retrieve order values from RESPONSES in ARRAY()
  1. N ORI,ID,PTR,INST,TYPE,DA,X,ORTXT S:'$L($G(ARRAY)) ARRAY="ORDIALOG"
  1. I +ROOT=ROOT S ROOT="^OR(100,"_ROOT_",4.5)" ; assume Orders file IFN
  1. S ORI=0 F S ORI=$O(@ROOT@(ORI)) Q:ORI'>0 S ID=$G(@ROOT@(ORI,0)) D
  1. . S DA=$P(ID,U),PTR=$P(ID,U,2),INST=$P(ID,U,3) S:'INST INST=1
  1. . S:'PTR PTR=$P($G(^ORD(101.41,+ORDIALOG,10,DA,0)),U,2) Q:'PTR
  1. . Q:'$D(ORDIALOG(PTR)) S TYPE=$E($G(ORDIALOG(PTR,0))) Q:'$L(TYPE)
  1. . I TYPE'="W" S X=$G(@ROOT@(ORI,1)) S:$L(X) @ARRAY@(PTR,INST)=X Q
  1. . D RESTXT ;resolve objects
  1. . I ARRAY="ORDIALOG" M ^TMP("ORWORD",$J,PTR,INST)=@ORTXT S @ARRAY@(PTR,INST)="^TMP(""ORWORD"","_$J_","_PTR_","_INST_")"
  1. . I ARRAY'="ORDIALOG" M @ARRAY@(PTR,INST)=@ORTXT S @ARRAY@(PTR,INST)=$NA(@ARRAY@(PTR,INST))
  1. . K @ORTXT
  1. Q
  1. ;
  1. RESTXT ; -- resolve objects in text [from GETORDER+8]
  1. I $$BROKER^XWBLIB!($G(ORTYPE)="Z") M ^TMP("ORX",$J)=@ROOT@(ORI,2) S ORTXT=$NA(^TMP("ORX",$J)) Q ;return text unresolved
  1. N ARRAY,PTR,INST
  1. D BLRPLT^TIUSRVD(.ORTXT,,+$G(ORVP),,$NA(@ROOT@(ORI,2)))
  1. Q
  1. ;
  1. DUP(PROMPT,CURRENT) ; -- Compare CURRENT instance of PROMPT for duplicates
  1. N X,Y,I
  1. S X=ORDIALOG(PROMPT,CURRENT),Y=0
  1. S I=0 F S I=$O(ORDIALOG(PROMPT,I)) Q:I'>0 I I'=CURRENT,$P(ORDIALOG(PROMPT,I),U)=$P(ORDIALOG(PROMPT,CURRENT),U) S Y=1 Q
  1. Q Y
  1. ;
  1. LIST ; -- Show contents of ORDIALOG(PROMPT,"LIST")
  1. N NUM S NUM=$G(ORDIALOG(PROMPT,"LIST")) Q:'NUM
  1. W !,"Choose from"_$S('$P(NUM,U,2):" (or enter another):",1:":")
  1. LIST1 N I,DONE,CNT S (I,CNT,DONE)=0
  1. F S I=$O(ORDIALOG(PROMPT,"LIST",I)) Q:I'>0 D Q:DONE
  1. . S CNT=CNT+1 I CNT>(IOSL-2) S CNT=0 I '$$MORE S DONE=1 Q
  1. . W !,$J(I,6)_" "_$P(ORDIALOG(PROMPT,"LIST",I),U,2)
  1. Q
  1. ;
  1. SETLIST ; -- Show allowable set of codes
  1. W !,"Choose from:"
  1. SETLST1 N I,X F I=1:1:$L(DOMAIN,";") S X=$P(DOMAIN,";",I) I $L(X) D
  1. . W !,?5,$P(X,":"),?15,$P(X,":",2)
  1. Q
  1. ;
  1. MORE() ; -- show more?
  1. N X,Y,DIR
  1. S DIR(0)="EA",DIR("A")=" press <return> to continue or ^ to exit ..."
  1. D ^DIR
  1. Q +Y
  1. ;
  1. FIRST(P,I) ; -- Returns 1 or 0, if current instance I is first of multiple
  1. Q '$O(ORDIALOG(P,I),-1)
  1. ;
  1. RECALL(P,I) ; -- Returns first value for prompt P, instance I
  1. N Y S:'$G(I) I=1 S Y=$G(^TMP("ORECALL",$J,+ORDIALOG,P,I))
  1. Q Y