ORX8 ;SLC/DCM,MKB - OE/RR Orders file extracts ;12/10/2015 12:32
;;3.0;ORDER ENTRY/RESULTS REPORTING;**13,21,48,68,92,141,163,272,377**;Dec 17, 1997;Build 582
;
EN(ORIFN) ;Returns data from file 100 in the ORUPCHUK array [DBIA#871]
Q:'$D(ORIFN) Q:'$D(^OR(100,+ORIFN,0)) K ORUPCHUK
D A
K ORTX,X0,X3,%X,%Y,J,ORINDX,X
Q
A S X0=^OR(100,ORIFN,0),X3=^(3),ORUPCHUK("ORPK")=$S($D(^(4)):^(4),1:"")
S ORUPCHUK("ORVP")=$P(X0,"^",2),ORUPCHUK("ORPCL")=$P(X0,"^",5),X=$P(X0,"^",6),ORUPCHUK("ORDUZ")=X_"^"_$$GET1^DIQ(200,+X,.01),ORUPCHUK("ORODT")=$P(X0,"^",7),ORUPCHUK("ORSTOP")=$P(X0,"^",9),ORUPCHUK("ORL")=$P(X0,"^",10)
S X=$P(X0,"^",11),ORUPCHUK("ORTO")=X_"^"_$S($D(^ORD(100.98,+X,0)):$P(^(0),"^"),1:"")
S X=$P(X3,"^",3),ORUPCHUK("ORSTS")=X_"^"_$P(^ORD(100.01,X,0),"^"),ORUPCHUK("ORSTRT")=$P(X0,"^",8),X=$P(X0,"^",4),(ORUPCHUK("ORNP"),ORUPCHUK("ORPV"))=X_"^"_$S(X:$$GET1^DIQ(200,+X,.01),1:"")
D TEXT^ORQ12(.ORTX,ORIFN,$G(ORLENGTH))
I $O(ORTX(0)) S %X="ORTX(",%Y="ORUPCHUK(""ORTX""," D %XY^%RCR
Q
;
VALUE(IFN,ID,INST,FORMAT) ; -- Returns value of prompt by ID
N PRMT
I '$G(IFN)!('$D(^OR(100,+$G(IFN),0)))!($G(ID)="") Q ""
N I,Y S I=0,Y="" S:'$G(INST) INST=1
F S I=$O(^OR(100,+IFN,4.5,"ID",ID,I)) Q:I'>0 I $P($G(^OR(100,+IFN,4.5,+I,0)),U,3)=INST S PRMT=+$P(^(0),U,2),Y=$G(^(1)) Q
I $L(Y),$G(PRMT),$G(FORMAT)="E" D ; get external form of Y
. N ORDIALOG S ORDIALOG(PRMT,0)=$G(^ORD(101.41,PRMT,1))
. S ORDIALOG(PRMT,1)=Y,Y=$$EXT^ORCD(PRMT,1)
Q Y
;
OI(IFN) ; -- Returns [first] orderable item for order IFN in the format
; ifn ^ name ^ pkg id [DBIA#2467]
I '$G(IFN)!('$D(^OR(100,+$G(IFN),0))) Q ""
N I,X,Y S I=$O(^OR(100,+IFN,.1,0)),X=$G(^(+I,0)),Y=""
I X,$D(^ORD(101.43,+X,0)) S Y=+X_U_$P(^(0),U,1,2)
Q Y
;
OIS(RESULT,IFN) ; -- Returns array of orderable items for order IFN
N OI,POS
S POS=0 F S POS=$O(^OR(100,+IFN,4.5,"ID","ORDERABLE",POS)) Q:POS'>0 D
.S OI=+$G(^OR(100,+IFN,4.5,POS,1)) I OI'>0 Q
.I '$D(^ORD(101.43,OI)) Q
.S RESULT(OI)=$P($G(^ORD(101.43,OI,0)),U,1,2)
Q
;
LATEST(ORPAT,ORIT,ORY) ; -- Return most recent orders for ORPAT,ORIT as
; ORY = total number of orders found (or 0 if none found)
; ORY(ORSTS) = ORIFN ^ Ord'd By ^ Entered ^ StartDt ^ StopDt ^ Loc ^ Sts
; where ORSTS is the ien in the Order Status file #100.01 [DBIA#2842]
;
N ORVP,ORIDT,ORIFN,OR0,OR3,ORSTS,ORSTSNM
S ORVP=+ORPAT_";DPT(",ORY=0 Q:'$G(ORPAT) Q:'$G(ORIT) ;invalid input
S ORIDT=0 F S ORIDT=$O(^OR(100,"AOI",+ORIT,ORVP,ORIDT)) Q:ORIDT'>0 D
. S ORIFN=0 F S ORIFN=$O(^OR(100,"AOI",+ORIT,ORVP,ORIDT,ORIFN)) Q:ORIFN'>0 D
.. S OR0=$G(^OR(100,+ORIFN,0)),OR3=$G(^(3)),ORSTS=+$P(OR3,U,3)
.. Q:ORSTS'>0 Q:$G(ORY(ORSTS)) ;return only latest order per status
.. S ORSTSNM=$$LOW^XLFSTR($P($G(^ORD(100.01,ORSTS,0)),U))
.. S ORY=ORY+1,ORY(ORSTS)=ORIFN_U_$P(OR0,U,4)_U_$P(OR0,U,7,10)_U_ORSTSNM
Q
;
DELAYED(ORY,ORDER) ; -- Return delayed order(s) with same OrdItem as ORDER
; in ORY(ORIFN) = PatEventPtr ^ EventName
;
N ORI,ORIT,ORIFN,EVT,PTEVT S (ORY,ORI)=0
F S ORI=$O(^OR(100,+ORDER,.1,ORI)) Q:ORI'>0 S ORIT=+$G(^(ORI,0)) D
. S EVT=0 F S EVT=$O(^ORE(100.2,"AE",+ORVP,EVT)) Q:EVT<1 S PTEVT=+$O(^(EVT,0)) D ;pending events
.. S ORIFN=0 F S ORIFN=+$O(^OR(100,"AEVNT",ORVP,PTEVT,ORIFN)) Q:ORIFN<1 D ;delayed orders
... Q:ORIFN=+ORDER Q:'$D(^OR(100,ORIFN,.1,"B",ORIT))
... Q:"^1^2^7^12^13^14^"[(U_$P($G(^OR(100,ORIFN,3)),U,3)_U) ;terminated
... S ORY=ORY+1,ORY(ORIFN)=PTEVT_U_$P($G(^ORD(100.5,EVT,0)),U)
Q
;
PKGID(ORIFN) ; -- Return package identifier for order ORIFN [DBIA#3071]
Q $G(^OR(100,+$G(ORIFN),4))
;
ES(ORDER) ; -- Returns the signature status of ORDER [DBIA#3632]
; -1 = invalid order#
; "" = no signature required
; 0 = not signed (needs ES)
; 1 = electronically or digitally signed
; 2 = signed on chart
; 3 = corrected or canceled order
N X,Y,DA I '$G(ORDER)!'$D(^OR(100,+$G(ORDER),0)) Q -1
S DA=+$P(ORDER,";",2) S:DA<1 DA=+$P($G(^OR(100,+ORDER,3)),U,7)
S X=$P($G(^OR(100,+ORDER,8,DA,0)),U,4)
S Y=$S(X=2:0,X=1!(X=7):1,X=0!(X=4):2,X=5!(X=6):3,1:"")
Q Y
;
AND(DAD) ; -- Return 1 or 0, if all conjunctions are AND [DBIA#3632]
N I,Y S I=0,Y=1
F S I=+$O(^OR(100,+$G(DAD),4.5,"ID","CONJ",I)) Q:I<1 I $E($G(^OR(100,+$G(DAD),4.5,I,1)))'="A" S Y=0 Q
Q Y
OITM(IEN,FILE) ; -- Return 101.43 ien for package IEN;FILE
; where FILE = "99xxx" as passed in HL7 messages
Q $O(^ORD(101.43,"ID",+$G(IEN)_";"_$G(FILE),0))
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HORX8 4495 printed Oct 16, 2024@18:38:29 Page 2
ORX8 ;SLC/DCM,MKB - OE/RR Orders file extracts ;12/10/2015 12:32
+1 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**13,21,48,68,92,141,163,272,377**;Dec 17, 1997;Build 582
+2 ;
EN(ORIFN) ;Returns data from file 100 in the ORUPCHUK array [DBIA#871]
+1 if '$DATA(ORIFN)
QUIT
if '$DATA(^OR(100,+ORIFN,0))
QUIT
KILL ORUPCHUK
+2 DO A
+3 KILL ORTX,X0,X3,%X,%Y,J,ORINDX,X
+4 QUIT
A SET X0=^OR(100,ORIFN,0)
SET X3=^(3)
SET ORUPCHUK("ORPK")=$SELECT($DATA(^(4)):^(4),1:"")
+1 SET ORUPCHUK("ORVP")=$PIECE(X0,"^",2)
SET ORUPCHUK("ORPCL")=$PIECE(X0,"^",5)
SET X=$PIECE(X0,"^",6)
SET ORUPCHUK("ORDUZ")=X_"^"_$$GET1^DIQ(200,+X,.01)
SET ORUPCHUK("ORODT")=$PIECE(X0,"^",7)
SET ORUPCHUK("ORSTOP")=$PIECE(X0,"^",9)
SET ORUPCHUK("ORL")=$PIECE(X0,"^",10)
+2 SET X=$PIECE(X0,"^",11)
SET ORUPCHUK("ORTO")=X_"^"_$SELECT($DATA(^ORD(100.98,+X,0)):$PIECE(^(0),"^"),1:"")
+3 SET X=$PIECE(X3,"^",3)
SET ORUPCHUK("ORSTS")=X_"^"_$PIECE(^ORD(100.01,X,0),"^")
SET ORUPCHUK("ORSTRT")=$PIECE(X0,"^",8)
SET X=$PIECE(X0,"^",4)
SET (ORUPCHUK("ORNP"),ORUPCHUK("ORPV"))=X_"^"_$SELECT(X:$$GET1^DIQ(200,+X,.01),1:"")
+4 DO TEXT^ORQ12(.ORTX,ORIFN,$GET(ORLENGTH))
+5 IF $ORDER(ORTX(0))
SET %X="ORTX("
SET %Y="ORUPCHUK(""ORTX"","
DO %XY^%RCR
+6 QUIT
+7 ;
VALUE(IFN,ID,INST,FORMAT) ; -- Returns value of prompt by ID
+1 NEW PRMT
+2 IF '$GET(IFN)!('$DATA(^OR(100,+$GET(IFN),0)))!($GET(ID)="")
QUIT ""
+3 NEW I,Y
SET I=0
SET Y=""
if '$GET(INST)
SET INST=1
+4 FOR
SET I=$ORDER(^OR(100,+IFN,4.5,"ID",ID,I))
if I'>0
QUIT
IF $PIECE($GET(^OR(100,+IFN,4.5,+I,0)),U,3)=INST
SET PRMT=+$PIECE(^(0),U,2)
SET Y=$GET(^(1))
QUIT
+5 ; get external form of Y
IF $LENGTH(Y)
IF $GET(PRMT)
IF $GET(FORMAT)="E"
Begin DoDot:1
+6 NEW ORDIALOG
SET ORDIALOG(PRMT,0)=$GET(^ORD(101.41,PRMT,1))
+7 SET ORDIALOG(PRMT,1)=Y
SET Y=$$EXT^ORCD(PRMT,1)
End DoDot:1
+8 QUIT Y
+9 ;
OI(IFN) ; -- Returns [first] orderable item for order IFN in the format
+1 ; ifn ^ name ^ pkg id [DBIA#2467]
+2 IF '$GET(IFN)!('$DATA(^OR(100,+$GET(IFN),0)))
QUIT ""
+3 NEW I,X,Y
SET I=$ORDER(^OR(100,+IFN,.1,0))
SET X=$GET(^(+I,0))
SET Y=""
+4 IF X
IF $DATA(^ORD(101.43,+X,0))
SET Y=+X_U_$PIECE(^(0),U,1,2)
+5 QUIT Y
+6 ;
OIS(RESULT,IFN) ; -- Returns array of orderable items for order IFN
+1 NEW OI,POS
+2 SET POS=0
FOR
SET POS=$ORDER(^OR(100,+IFN,4.5,"ID","ORDERABLE",POS))
if POS'>0
QUIT
Begin DoDot:1
+3 SET OI=+$GET(^OR(100,+IFN,4.5,POS,1))
IF OI'>0
QUIT
+4 IF '$DATA(^ORD(101.43,OI))
QUIT
+5 SET RESULT(OI)=$PIECE($GET(^ORD(101.43,OI,0)),U,1,2)
End DoDot:1
+6 QUIT
+7 ;
LATEST(ORPAT,ORIT,ORY) ; -- Return most recent orders for ORPAT,ORIT as
+1 ; ORY = total number of orders found (or 0 if none found)
+2 ; ORY(ORSTS) = ORIFN ^ Ord'd By ^ Entered ^ StartDt ^ StopDt ^ Loc ^ Sts
+3 ; where ORSTS is the ien in the Order Status file #100.01 [DBIA#2842]
+4 ;
+5 NEW ORVP,ORIDT,ORIFN,OR0,OR3,ORSTS,ORSTSNM
+6 ;invalid input
SET ORVP=+ORPAT_";DPT("
SET ORY=0
if '$GET(ORPAT)
QUIT
if '$GET(ORIT)
QUIT
+7 SET ORIDT=0
FOR
SET ORIDT=$ORDER(^OR(100,"AOI",+ORIT,ORVP,ORIDT))
if ORIDT'>0
QUIT
Begin DoDot:1
+8 SET ORIFN=0
FOR
SET ORIFN=$ORDER(^OR(100,"AOI",+ORIT,ORVP,ORIDT,ORIFN))
if ORIFN'>0
QUIT
Begin DoDot:2
+9 SET OR0=$GET(^OR(100,+ORIFN,0))
SET OR3=$GET(^(3))
SET ORSTS=+$PIECE(OR3,U,3)
+10 ;return only latest order per status
if ORSTS'>0
QUIT
if $GET(ORY(ORSTS))
QUIT
+11 SET ORSTSNM=$$LOW^XLFSTR($PIECE($GET(^ORD(100.01,ORSTS,0)),U))
+12 SET ORY=ORY+1
SET ORY(ORSTS)=ORIFN_U_$PIECE(OR0,U,4)_U_$PIECE(OR0,U,7,10)_U_ORSTSNM
End DoDot:2
End DoDot:1
+13 QUIT
+14 ;
DELAYED(ORY,ORDER) ; -- Return delayed order(s) with same OrdItem as ORDER
+1 ; in ORY(ORIFN) = PatEventPtr ^ EventName
+2 ;
+3 NEW ORI,ORIT,ORIFN,EVT,PTEVT
SET (ORY,ORI)=0
+4 FOR
SET ORI=$ORDER(^OR(100,+ORDER,.1,ORI))
if ORI'>0
QUIT
SET ORIT=+$GET(^(ORI,0))
Begin DoDot:1
+5 ;pending events
SET EVT=0
FOR
SET EVT=$ORDER(^ORE(100.2,"AE",+ORVP,EVT))
if EVT<1
QUIT
SET PTEVT=+$ORDER(^(EVT,0))
Begin DoDot:2
+6 ;delayed orders
SET ORIFN=0
FOR
SET ORIFN=+$ORDER(^OR(100,"AEVNT",ORVP,PTEVT,ORIFN))
if ORIFN<1
QUIT
Begin DoDot:3
+7 if ORIFN=+ORDER
QUIT
if '$DATA(^OR(100,ORIFN,.1,"B",ORIT))
QUIT
+8 ;terminated
if "^1^2^7^12^13^14^"[(U_$PIECE($GET(^OR(100,ORIFN,3)),U,3)_U)
QUIT
+9 SET ORY=ORY+1
SET ORY(ORIFN)=PTEVT_U_$PIECE($GET(^ORD(100.5,EVT,0)),U)
End DoDot:3
End DoDot:2
End DoDot:1
+10 QUIT
+11 ;
PKGID(ORIFN) ; -- Return package identifier for order ORIFN [DBIA#3071]
+1 QUIT $GET(^OR(100,+$GET(ORIFN),4))
+2 ;
ES(ORDER) ; -- Returns the signature status of ORDER [DBIA#3632]
+1 ; -1 = invalid order#
+2 ; "" = no signature required
+3 ; 0 = not signed (needs ES)
+4 ; 1 = electronically or digitally signed
+5 ; 2 = signed on chart
+6 ; 3 = corrected or canceled order
+7 NEW X,Y,DA
IF '$GET(ORDER)!'$DATA(^OR(100,+$GET(ORDER),0))
QUIT -1
+8 SET DA=+$PIECE(ORDER,";",2)
if DA<1
SET DA=+$PIECE($GET(^OR(100,+ORDER,3)),U,7)
+9 SET X=$PIECE($GET(^OR(100,+ORDER,8,DA,0)),U,4)
+10 SET Y=$SELECT(X=2:0,X=1!(X=7):1,X=0!(X=4):2,X=5!(X=6):3,1:"")
+11 QUIT Y
+12 ;
AND(DAD) ; -- Return 1 or 0, if all conjunctions are AND [DBIA#3632]
+1 NEW I,Y
SET I=0
SET Y=1
+2 FOR
SET I=+$ORDER(^OR(100,+$GET(DAD),4.5,"ID","CONJ",I))
if I<1
QUIT
IF $EXTRACT($GET(^OR(100,+$GET(DAD),4.5,I,1)))'="A"
SET Y=0
QUIT
+3 QUIT Y
OITM(IEN,FILE) ; -- Return 101.43 ien for package IEN;FILE
+1 ; where FILE = "99xxx" as passed in HL7 messages
+2 QUIT $ORDER(^ORD(101.43,"ID",+$GET(IEN)_";"_$GET(FILE),0))