source: WorldVistAEHR/trunk/r/ORDER_ENTRY_RESULTS_REPORTING-OR-OCX--ORRC--ORRJ/ORMPS.m@ 814

Last change on this file since 814 was 623, checked in by George Lilly, 15 years ago

revised back to 6/30/08 version

File size: 9.2 KB
RevLine 
[623]1ORMPS ; SLC/MKB - Process Pharmacy ORM msgs ;12/3/03 10:32
2 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**3,54,62,86,92,94,116,138,152,141,165,149,213,195**;Dec 17, 1997
3 ;
4EN ; -- entry point
5 I '$L($T(@ORDCNTRL)) Q ;S ORERR="Invalid order control code" Q
6 I ORDCNTRL'="SN",ORDCNTRL'="ZC",ORDCNTRL'="ZP",'ORIFN!('$D(^OR(100,+ORIFN,0))) S ORERR="Invalid OE/RR order number" Q
7 N ORSTS,RXE,ZRX,ORWHO,ORNOW
8 S ORSTS=$$STATUS(ORDSTS),RXE=$$RXE,ZRX=$$ZRX D QT^ORMPS1 ;QT in RXE
9 S ORNOW=+$E($$NOW^XLFDT,1,12),ORWHO=+$P(ZRX,"|",6) S:'ORWHO ORWHO=DUZ
10 S:ORLOG ORLOG=+$E(ORLOG,1,12) ;no seconds
11 S:'$L(ORNATR) ORNATR=$P(ZRX,"|",3) S:OREASON["^" OREASON=$P(OREASON,U,5)
12 I ORNATR="D",'$L(OREASON) S OREASON="DUPLICATE"
13 D @ORDCNTRL
14 Q
15 ;
16ZV ; -- Verified
17 N ORUSR,ORVER,ORDA,ORES,ORI
18 S ORUSR=+$P(ORC,"|",12),ORVER="N" Q:'ORUSR
19 S ORDA=+$P($G(^OR(100,+ORIFN,3)),U,7),ORES(+ORIFN_";"_ORDA)=""
20 Q:$P($G(^OR(100,+ORIFN,8,ORDA,0)),U,8) ;already verified
21 D REPLCD^ORCACT1 ;get unverified replaced orders
22 S ORI="" F S ORI=$O(ORES(ORI)) Q:ORI="" D
23 . S ORDA=+$P(ORI,";",2)
24 . D VERIFY^ORCSAVE2(+ORI,ORDA,"N",ORUSR,ORLOG)
25 Q
26 ;
27ZP ; -- Purged
28 Q:'ORIFN Q:'$D(^OR(100,+ORIFN,0))
29 K ^OR(100,+ORIFN,4) I "^3^5^6^15^"[(U_$P($G(^(3)),U,3)_U) D STATUS^ORCSAVE2(+ORIFN,14) ;Remove pkg reference, sts=lapsed if still active
30 Q
31 ;
32ZR ; -- Purged as requested [ack]
33 D DELETE^ORCSAVE2(+ORIFN)
34 Q
35 ;
36ZU ; -- Unable to purge [ack]
37 S $P(^OR(100,+ORIFN,3),U)=$$NOW^XLFDT ;update Last Activity
38 Q
39 ;
40XR ; -- Changed as requested [ack]
41 N ORIG S ORIG=$P(^OR(100,+ORIFN,3),U,5) I ORIG,$P(^OR(100,ORIG,3),U,3)'=12 D STATUS^ORCSAVE2(ORIG,12)
42OK ; -- Order accepted, PS order # assigned [ack]
43 S ^OR(100,+ORIFN,4)=PKGIFN ;PS identifier
44 D:ORSTS STATUS^ORCSAVE2(+ORIFN,ORSTS)
45 Q
46 ;
47ZC ; -- convert orders
48 N RXO,RXC,ORDIALOG,ORDG,ORPKG,ORP,ORSIG,ORIG,TYPE,EVNT
49 I '$D(^VA(200,ORDUZ,0)) S ORERR="Missing or invalid entering person" Q
50 I '$D(^VA(200,ORNP,0)) S ORERR="Missing or invalid ordering provider" Q
51 I 'RXE S ORERR="Missing or invalid RXE segment" Q
52 S RXO=$$RXO,RXC=$$RXC K ^TMP("ORWORD",$J)
53 D @($S(RXC:"IV",$G(ORCAT)="I":"UDOSE",1:"OUT")_"^ORMPS1")
54ZC1 ; continue
55 Q:$D(ORERR) I 'ORIFN!('$D(^OR(100,+ORIFN,0))) D Q ;create
56 . K ORIFN D SN1 Q:'$G(ORIFN) S ORDCNTRL="SN"
57 . I ORSTOP,ORSTOP<ORNOW S $P(^OR(100,ORIFN,3),U)=ORSTOP
58 S ORIFN=+ORIFN D RESPONSE^ORCSAVE K ^TMP("ORWORD",$J)
59 S ^OR(100,ORIFN,4)=PKGIFN,$P(^(0),U,5)=+ORDIALOG_";ORD(101.41,"
60 D DATES^ORCSAVE2(ORIFN,ORSTRT,ORSTOP),STATUS^ORCSAVE2(ORIFN,ORSTS):ORSTS
61 Q
62 ;
63SN ; -- New backdoor order, return OE# via NA msg
64 I $$FINISHED^ORMPS2 D RO^ORMPS2 Q ;change action instead
65 N RXO,RXC,ORDIALOG,ORDG,ORPKG,ORP,ORSIG,ORIG,TYPE,EVNT,ZSC
66 I '$D(^VA(200,ORDUZ,0)) S ORERR="Missing or invalid entering person" Q
67 I '$D(^VA(200,ORNP,0)) S ORERR="Missing or invalid ordering provider" Q
68 ; I '$G(ORL) S ORERR="Missing or invalid patient location" Q
69 I 'RXE S ORERR="Missing or invalid RXE segment" Q
70 S RXO=$$RXO,RXC=$$RXC K ^TMP("ORWORD",$J),ORIFN
71 D @($S(RXC:"IV",$G(ORCAT)="I":"UDOSE",1:"OUT")_"^ORMPS1") Q:$D(ORERR)
72SN1 ; save order
73 D EN^ORCSAVE I '$G(ORIFN) S ORERR="Cannot create new order" G SNQ
74 D BDOSTR^ORWDBA3 ;DG1 & ZCL data
75 S ORIG=+$P(ZRX,"|",2),TYPE=$P(ZRX,"|",4) I ORIG D ;set fwd/bwd ptrs
76 . S TYPE=$S(TYPE="R":2,1:1) Q:'$D(^OR(100,ORIG,0))
77 . S $P(^OR(100,ORIFN,3),U,5)=ORIG,$P(^(3),U,11)=TYPE
78 . S $P(^OR(100,ORIG,3),U,6)=ORIFN,EVNT=$P(^(0),U,17)
79 . I $L(EVNT),TYPE=1 S $P(^OR(100,ORIFN,0),U,17)=EVNT
80 . I TYPE=2,$G(ORCAT)="I" S ORSTRT=ORLOG D PARENT^ORMPS3 ;ck if complex
81 I $G(ORCAT)="O" S ZSC=$$ZSC^ORMPS1 I ZSC,$P(ZSC,"|",2)'?2.3U S ^OR(100,ORIFN,5)=$TR($P(ZSC,"|",2,7),"|","^") ;1 or 0 instead of [N]SC
82SN2 D DATES^ORCSAVE2(ORIFN,ORSTRT,ORSTOP)
83 D:ORSTS STATUS^ORCSAVE2(ORIFN,ORSTS)
84 D RELEASE^ORCSAVE2(ORIFN,1,ORLOG,ORDUZ,ORNATR)
85 ; if unsigned edit, leave ORIFN unsigned & mark ORIG as Sig Not Req'd
86 S ORSIG=$S('ORIG:1,TYPE'=1:1,$P($G(^OR(100,ORIG,8,1,0)),U,4)'=2:1,1:0)
87 D SIGSTS^ORCSAVE2(ORIFN,1):ORSIG,SIGN^ORCSAVE2(ORIG,,,5,1):'ORSIG
88 I ORDCNTRL="SN" D ;print
89 . S:ORNATR="" $P(^OR(100,ORIFN,8,1,0),U,12)="" ;CHCS/OP orders
90 . S ORP(1)=ORIFN_";1"_$S(ORNATR="":"^^^^1",$G(ORL):"^1",1:"")
91 . I ORP(1)["^" D PRINTS^ORWD1(.ORP,+$G(ORL))
92 S ^OR(100,ORIFN,4)=PKGIFN
93SNQ K ^TMP("ORWORD",$J)
94 Q
95 ;
96XX ; -- Changed (new order not necessary)
97 Q:$P($G(^OR(100,+ORIFN,3)),U,3)=5 ;pending - update when finished
98 I '$$CHANGED^ORMPS2 D SC Q ;ck sts/dates only
99RO ; -- Replacement order (finished)
100 S:ORNATR="" ORNATR="S" D RO^ORMPS2
101 Q
102 ;
103SC ; -- Status changed (verified, expired, suspended, renewed, reinstate)
104 N OR0,OR3,ZSC,DONE S OR0=$G(^OR(100,+ORIFN,0)),OR3=$G(^(3))
105 I $P(OR3,U,3)=5,ORSTS=6 D Q:$G(DONE)
106 . I $$CHANGED^ORMPS2 S ORNATR="S" D RO^ORMPS2 S DONE=1 Q
107 . I $P(ZRX,"|",7)="TPN",+$P(OR0,U,11)'=$O(^ORD(100.98,"B","TPN",0)) D
108 .. N DA,DR,DIE,ORDG S ORDG=+$O(^ORD(100.98,"B","TPN",0))
109 .. S DA=+ORIFN,DR="23////"_ORDG,DIE="^OR(100," D ^DIE
110 . I $P(OR3,U,11)=2,$P(OR0,U,12)="I" S ORSTRT=+$P($G(^OR(100,+ORIFN,8,1,0)),U,16) ;use Release Date for inpt renewals
111 I $P(OR0,U,12)="I",$P(ZRX,"|",4)="R",+$P(ZRX,"|",2)=+ORIFN S ORSTRT=$P(OR0,U,8) ;keep orig start when renewed
112 D DATES^ORCSAVE2(+ORIFN,ORSTRT,ORSTOP)
113 D:ORSTS STATUS^ORCSAVE2(+ORIFN,ORSTS)
114 I ORSTS=$P(OR3,U,3),ORSTOP'=$P(OR0,U,9) D SETALL^ORDD100(+ORIFN) ;AC xrf
115 S ^OR(100,+ORIFN,4)=PKGIFN
116 I "^1^13^"[(U_$P(OR3,U,3)_U),"^3^5^6^15^"[(U_ORSTS_U) D ;reinstated
117 . I $P($G(^OR(100,+ORIFN,8,+$P(OR3,U,7),0)),U,2)="DC" S ^(2)=ORNOW_U_ORWHO ; When^Who reinstated order
118 . S I="?" F S I=$O(^OR(100,+ORIFN,8,I),-1) Q:'+I I $P(^(I,0),U,15)="" S $P(^OR(100,+ORIFN,3),U,7)=I Q ;138 Finds current action
119 . K ^OR(100,+ORIFN,6) D SETALL^ORDD100(+ORIFN)
120 I $G(ORCAT)="O" S ZSC=$$ZSC^ORMPS1 I ZSC,$P(ZSC,"|",2)'?2.3U S ^OR(100,+ORIFN,5)=$TR($P(ZSC,"|",2,7),"|","^") ;1 or 0 instead of [N]SC
121 Q
122 ;
123STATUS(X) ; -- HL7 order status
124 N Y S Y=$S(X="IP":5,X="CM":6,X="DC":1,X="ZE":7,X="HD":3,X="ZX":11,X="RP":12,X="ZZ":15,X="ZS":6,X="ZU":6,1:"")
125 Q Y
126 ;
127DE ; -- Data Errors
128 Q
129 ;
130UA ; -- Unable to accept [ack]
131UX ; -- Unable to change [ack]
132 S:'$L(ORNATR) ORNATR="X" ;Rejected
133 S ^OR(100,+ORIFN,6)=$O(^ORD(100.02,"C",ORNATR,0))_U_U_ORNOW_U_U_OREASON
134 I $P($G(^OR(100,+ORIFN,3)),U,11)=2 N ORIG S ORIG=$P(^(3),U,5) S:ORIG $P(^OR(100,ORIG,3),U,6)="" ;remove fwd ptr if pending renewal
135 D STATUS^ORCSAVE2(+ORIFN,13)
136UC ; -- Unable to cancel [ack]
137UD ; -- Unable to discontinue [ack]
138UH ; -- Unable to hold [ack]
139UR ; -- Unable to release hold [ack]
140 N ORDA S ORDA=+$P(ORIFN,";",2) I ORDA D
141 . S $P(^OR(100,+ORIFN,8,ORDA,0),U,15)=13 ;request rejected
142 . S:$L(OREASON) ^OR(100,+ORIFN,8,ORDA,1)=OREASON
143 Q
144 ;
145OC ; -- Cancelled (before pharmacist's verification)
146 G:ORTYPE="ORR" UA S:ORNATR="A" ORWHO=""
147 S:'ORSTS ORSTS=13 S:ORSTS=12 ORNATR="S"
148 S ^OR(100,+ORIFN,6)=$S($L(ORNATR):$O(^ORD(100.02,"C",ORNATR,0)),1:"")_U_ORWHO_U_ORNOW_U_U_OREASON
149 I $P($G(^OR(100,+ORIFN,3)),U,11)=2 N ORIG S ORIG=$P(^(3),U,5) S:ORIG $P(^OR(100,ORIG,3),U,6)="" ;remove fwd ptr when pending renewal cancelled
150 S ^OR(100,+ORIFN,4)=PKGIFN S:ORSTOP>ORNOW ORSTOP=ORNOW
151 D UPDATE(ORSTS,"DC")
152 Q
153 ;
154CR ; -- Cancelled [ack]
155 D STATUS^ORCSAVE2(+ORIFN,13) S ^OR(100,+ORIFN,4)=PKGIFN
156 Q
157 ;
158OD ; -- Discontinued (cancelled after pharmacist's verification)
159 S:'ORSTS ORSTS=1 S:ORSTS=12 ORNATR="C"
160 I ORNATR="A" S ORWHO="" I $G(DGPMT)=3,$$MVT^DGPMOBS(DGPMDA) D XTMP^ORMEVNT ;save order#
161 S ^OR(100,+ORIFN,6)=$S($L(ORNATR):$O(^ORD(100.02,"C",ORNATR,0)),1:"")_U_ORWHO_U_ORNOW_U_U_OREASON
162 S ^OR(100,+ORIFN,4)=PKGIFN S:ORSTOP>ORNOW ORSTOP=ORNOW
163 D UPDATE(ORSTS,"DC")
164 Q
165 ;
166DR ; -- Discontinued [ack]
167 D STATUS^ORCSAVE2(+ORIFN,1) S ^OR(100,+ORIFN,4)=PKGIFN
168 Q
169 ;
170OH ; -- Held
171 S:'ORSTS ORSTS=3 D UPDATE(ORSTS,"HD")
172 Q
173 ;
174HR ; -- Held [ack]
175 D STATUS^ORCSAVE2(+ORIFN,3)
176 Q
177 ;
178RL ; -- Released hold
179OE ; -- Released hold
180 N ORDA S ORDA=+$P(^OR(100,+ORIFN,3),U,7)
181 I $P($G(^OR(100,+ORIFN,8,ORDA,0)),U,2)="HD" S $P(^(2),U,1,2)=ORNOW_U_ORWHO
182 S:'$G(ORSTS) ORSTS=6 D UPDATE(ORSTS,"RL")
183 Q
184 ;
185OR ; -- Released / [ack]
186 S:'ORSTS ORSTS=6 D STATUS^ORCSAVE2(+ORIFN,ORSTS)
187 D:ORSTRT!ORSTOP DATES^ORCSAVE2(+ORIFN,ORSTRT,ORSTOP)
188 Q
189 ;
190UPDATE(ORSTS,ORACT) ; -- continue
191 N ORX,ORDA,ORP D:$G(ORSTS) STATUS^ORCSAVE2(+ORIFN,ORSTS)
192 D:ORSTRT!ORSTOP DATES^ORCSAVE2(+ORIFN,ORSTRT,ORSTOP)
193 S ORX=$$CREATE^ORX1(ORNATR) D:ORX
194 . S ORDA=$$ACTION^ORCSAVE(ORACT,+ORIFN,ORNP,OREASON,ORNOW,ORWHO)
195 . I ORDA'>0 S ORERR="Cannot create new order action" Q
196 . D RELEASE^ORCSAVE2(+ORIFN,ORDA,ORNOW,ORWHO,ORNATR)
197 . D SIGSTS^ORCSAVE2(+ORIFN,ORDA)
198 . I $G(ORL) S ORP(1)=+ORIFN_";"_ORDA_"^1" D PRINTS^ORWD1(.ORP,+ORL)
199 . S $P(^OR(100,+ORIFN,3),U,7)=ORDA
200 I 'ORX,ORACT="DC",'$$ACTV^ORX1(ORNATR) S $P(^OR(100,+ORIFN,3),U,7)=0
201 D:$G(ORACT)="DC" CANCEL^ORCSEND(+ORIFN)
202 Q
203 ;
204RXO() ; -- RXO segment
205 N I,X S X="",I=$O(@ORMSG@(+ORC))
206 I I,$E(@ORMSG@(I),1,3)="RXO" S X=I_U_@ORMSG@(I)
207 Q X
208 ;
209RXE() ; -- RXE segment
210 N X,I,SEG S X="",I=+ORC
211 F S I=$O(@ORMSG@(I)) Q:I'>0 S SEG=$E(@ORMSG@(I),1,3) Q:SEG="ORC" I SEG="RXE" S X=I_U_@ORMSG@(I) Q
212 Q X
213 ;
214RXR() ; -- RXR segment
215 N X,I,SEG S X="",I=+RXE
216 F S I=$O(@ORMSG@(I)) Q:I'>0 S SEG=$E(@ORMSG@(I),1,3) Q:SEG="ORC" I SEG="RXR" S X=I_U_@ORMSG@(I) Q
217 Q X
218 ;
219RXC() ; -- [First] RXC segment
220 N X,I,SEG S X="",I=+RXE
221 F S I=$O(@ORMSG@(I)) Q:I'>0 S SEG=$E(@ORMSG@(I),1,3) Q:SEG="ORC" I SEG="RXC" S X=I Q
222 Q X
223 ;
224ZRX() ; -- ZRX segment
225 N X,I,SEG S X="",I=+ORC
226 F S I=$O(@ORMSG@(I)) Q:I'>0 S SEG=$E(@ORMSG@(I),1,3) Q:SEG="ORC" I SEG="ZRX" S X=I_U_@ORMSG@(I) Q
227 Q X
Note: See TracBrowser for help on using the repository browser.