source: WorldVistAEHR/trunk/r/CMOP-PSX/PSXMISC1.m@ 1753

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

revised back to 6/30/08 version

File size: 7.6 KB
Line 
1PSXMISC1 ;BIR/WPB,BAB-Transmission Data Validation ;MAR 1,2002@13:13:34
2 ;;2.0;CMOP;**3,18,23,28,30,42,41,52,54,58**;11 Apr 97;Build 2
3 ;Reference to ^PSDRUG( supported by DBIA #1983
4 ;Reference to ^PS(52.5, supported by DBIA #1978
5 ;Reference to ^PSRX( supported by DBIA #1977
6 ;Reference to ^PS(55, supported by DBIA #2228
7 ;Reference to PROD2^PSNAPIS supported by DBIA #2531
8 ;Reference to ^PSSLOCK supported by DBIA #2789
9 ;Reference to CHKRX^PSOBAI supported by DBIA #4910
10CHKDATA ;checks the data elements in PSRX before putting the rx in 550.2
11 Q:'$D(^PS(52.5,REC,0))
12 K DRUGCHK,PSXRXERR,PSXDGST,WARNS
13 S (RXN,PSXPTR)=$P($G(^PS(52.5,REC,0)),"^",1) I PSXPTR="" S PSXOK=8 Q
14 D PSOL^PSSLOCK(RXN) S PSOMSG=+PSOMSG ; sets PSOMSG
15 I ($P(^PS(52.5,REC,0),U,3)'=XDFN)!($P(^PSRX(PSXPTR,0),U,2)'=XDFN) S PSXOK=8 Q
16 I '$D(^PSRX(PSXPTR,0)) S PSXOK=8 Q
17 S RXNUM=$P($G(^PSRX(PSXPTR,0)),"^",6),RXEX=$P($G(^PSRX(PSXPTR,0)),"^",1)
18 I $G(^PSDRUG(RXNUM,"ND"))'="" D
19 .S PTRA=$P($G(^PSDRUG(RXNUM,"ND")),U,1),PTRB=$P($G(^PSDRUG(RXNUM,"ND")),U,3)
20 .I $G(PTRA)'="" S ZX=$$PROD2^PSNAPIS(PTRA,PTRB),DRUGCHK=$P($G(ZX),"^",3)
21 S:$G(DRUGCHK)'="" PSXDGST=$P(ZX,"^",2)_"^"_$P(ZX,"^")
22 I '$D(DRUGCHK) S DRUGCHK=0
23 S:'$D(^PSDRUG("AQ",RXNUM)) PSXOK=1
24 S:$G(DRUGCHK)'=1 PSXOK=1
25 I $P(^PSDRUG(RXNUM,2),"^",3)'["O" S PSXOK=1,PSXCK=RXNUM D UNMARK^PSXUTL
26 S:$P($G(^PSRX(PSXPTR,"STA")),U,1)'=5 PSXOK=5
27 ;gets the fill number by ordering thru the refill node for the last
28 ;refill number
29 S FILNUM=0 F REF=0:0 S REF=$O(^PSRX(PSXPTR,1,REF)) Q:REF'>0 S:REF>0 FILNUM=REF S:REF="" FILNUM=0
30 ;I $G(PSXFLAG)=2 S PSXOK=0 Q
31 S RXF=FILNUM
32 S REL=$S(RXF>0:$P($G(^PSRX(RXN,1,RXF,0)),U,18),RXF=0:$P($G(^PSRX(RXN,2)),U,13),1:"") I $G(REL)'="" S PSXOK=6
33 S:((PSXOK=0)&(FILNUM>0)&($P($G(^PSRX(PSXPTR,1,FILNUM,0)),"^",2)'="M")) PSXOK=3
34 S:((PSXOK=0)&(FILNUM'>0)&($P($G(^PSRX(PSXPTR,0)),"^",11)'="M")) PSXOK=3
35 I $G(^PS(52.5,REC,"P"))="1" S PSXOK=4
36 S PSXDIV=$S(FILNUM=0:$P($G(^PSRX(PSXPTR,2)),U,9),FILNUM>0:$P($G(^PSRX(PSXPTR,1,FILNUM,0)),"^",9),1:"")
37 ;If trans div does not match Rx div eliminate
38 I PSXDIV'=PSOSITE S PSXOK=7 Q
39 ; Changes for Controlled subs
40 N PSXCSC,PSXCSD S PSXCSRX=""
41 S PSXCSC=$P($G(^PSDRUG(RXNUM,0)),"^",3)
42 ;Can't trans DEA schedule 1 or 2
43 I $G(PSXCSC)[1!$G(PSXCSC)[2 S PSXOK=10 Q
44 ;If CS must be DEA 3-5 to qualify
45 F PSXCSD=3:1:5 I PSXCSC[PSXCSD S PSXCSRX=1
46 ;If not CS drug and CS trans eliminate
47 I ($G(PSXCSRX)<1)&($G(PSXCS)=1) S PSXOK=9 Q
48 ;If CS drug and not CS trans eliminate
49 I ($G(PSXCSRX)=1)&($G(PSXCS)<1) S PSXOK=9 Q
50 ; Checks for do not mail and expiration date thereof
51 ; moved to under NOGO
52 ;
53 G:PSXOK'=0 STOP
54NOGO ;any rx that does not pass the following checks will not be transmitted
55 ;and an error message will be generated and sent to the user who
56 ;initiated the transmission. All that pass the checks will be sent.
57 S RXERR=0,PSXRXERR=RXEX_"^"_RXF
58 I RXEX[" " S RXERR=13,PSXRXERR=PSXRXERR_"^"_RXERR
59 S QTY=$S(RXF>0:$P($G(^PSRX(RXN,1,RXF,0)),U,4),RXF=0:$P($G(^PSRX(RXN,0)),U,7),1:"") G:$G(QTY)'=""&($G(QTY)>0)&(QTY?.N)!(QTY?.N1".".N) NG1 S RXERR=2,PSXRXERR=PSXRXERR_"^"_RXERR
60NG1 S PHY=$S(RXF>0:$P($G(^PSRX(RXN,1,RXF,0)),U,17),RXF=0:$P($G(^PSRX(RXN,0)),U,4),1:"") I PHY="" S RXERR=3,PSXRXERR=PSXRXERR_"^"_RXERR
61 S DAYS=$S(RXF>0:$P($G(^PSRX(RXN,1,RXF,0)),U,10),RXF=0:$P($G(^PSRX(RXN,0)),U,8),1:"") I (DAYS'>0)!(DAYS="") S RXERR=4,PSXRXERR=PSXRXERR_"^"_RXERR
62 S PHARCLK=$S(RXF>0:$P($G(^PSRX(RXN,1,RXF,0)),U,7),RXF=0:$P($G(^PSRX(RXN,0)),U,16),1:"") I PHARCLK="" S RXERR=9,PSXRXERR=PSXRXERR_"^"_RXERR
63 S DRUG=$P($G(^PSRX(RXN,0)),U,6),PSTAT=$P($G(^(0)),U,3),FDATE=$P($G(^PSRX(RXN,2)),U,2)
64 D TSTSIG
65 S DFN=$P($G(^PSRX(RXN,0)),U,2) D ADD^VADPT I ($G(VAPA(1))="")!($G(VAPA(4))="")!($P($G(VAPA(5)),"^",2)="")!($G(VAPA(6))'>0)!($P($G(VAPA(11)),"^",2)'>0) S RXERR=10,PSXRXERR=PSXRXERR_"^"_RXERR
66 D DEM^VADPT
67 I VADM(1)["MERGING" S RXERR=17,PSXRXERR=PSXRXERR_"^"_RXERR
68 ;MVP OIFO BAY PINES;ELR;PSX*2*52 CHANGED RXERR FROM 10 TO 19. ADDED NEW ERROR IN PSXERR
69 I $G(VA("PID"))["000-00" S RXERR=19,PSXRXERR=PSXRXERR_"^"_RXERR ; SSN ["000-00" indicates test patient
70 S (CNTR,XC,DUPFLG)=0,DUPRX="" F S XC=$O(^PSRX("B",RXEX,XC)) Q:XC'>0 S CNTR=CNTR+1,DUPRX=DUPRX_"^"_XC
71 I CNTR>1 D
72 .Q:$P(DUPRX,"^",3)=""
73 .F I2=2:1 S I1=$P(DUPRX,"^",I2) Q:I1="" S PSREC=$O(^PS(52.5,"B",I1,"")) Q:$G(PSREC)'>0 S:($P(^PS(52.5,PSREC,0),"^",2)<PSXDTRG&($P(^PS(52.5,PSREC,0),"^",7)="Q")) DUPFLG=1
74 S:$G(DUPFLG)>0 PSXRXERR=PSXRXERR_"^"_"14"
75 K CNTR,XC,DUPRX,I2,I1,PSREC,DUPFLG
76 I $D(^PSRX(PSXPTR,4,0)) D
77 .S RXERR=""
78 .S ZX=0 F S ZX=$O(^PSRX(PSXPTR,4,ZX)) Q:ZX'>0 D
79 ..I $P(^PSRX(PSXPTR,4,ZX,0),"^",3)=RXF&($P(^PSRX(PSXPTR,4,ZX,0),"^",4)'=3) S RXERR=12
80 ..I $P(^PSRX(PSXPTR,4,ZX,0),"^",3)=RXF&($P(^PSRX(PSXPTR,4,ZX,0),"^",4)=3) S RXERR=""
81 .I RXERR'="" S PSXRXERR=PSXRXERR_"^"_RXERR
82 I DRUG="" S RXERR=5,PSXRXERR=PSXRXERR_"^"_RXERR
83 I DRUG S WARNS=$P(^PSDRUG(DRUG,0),"^",8) D
84 .;IF USING NEW WARNING SOURCE, LENGTH OF OLD WARNINGS DOESN'T MATTER
85 .I '$D(PSSWSITE) S PSSWSITE=+$O(^PS(59.7,0))
86 .I $P($G(^PS(59.7,PSSWSITE,10)),"^",10)="N" Q
87 .I $G(WARNS) S:$L(WARNS)>11 RXERR=16,PSXRXERR=PSXRXERR_"^"_RXERR
88 I SIG="" S RXERR=6,PSXRXERR=PSXRXERR_"^"_RXERR
89 I PSTAT="" S RXERR=7,PSXRXERR=PSXRXERR_"^"_RXERR
90 I FDATE'?7N S RXERR=8,PSXRXERR=PSXRXERR_"^"_RXERR
91 I '$$MAILOK(RXN) D
92 . S COM="Removed from CMOP Suspense - Mail Status Change" D NOW^%DTC S DTTM=% K % D ACTLOG^PSXRPPL
93 . D DELETE^PSXRPPL S PSXOK=1
94 . ;MVP OIFO BAY PINES;ELR;PSX*2*5 DELETE MM MSG FOR DO NOT MAIL
95 . ;S RXERR=15,PSXRXERR=PSXRXERR_"^"_RXERR ;mail message to users
96 I $D(^TMP($J,"PSXBAI",DFN)),'$G(^TMP($J,"PSXBAI",DFN)) D
97 . S PSXOK=8
98 . D CHKACT(PSXPTR)
99 . I '$G(PSXFIRST) K PSXRXERR Q
100 . S COM="Bad Address Indicator or Foreign Address. Not removed from CMOP Suspense" D NOW^%DTC S DTTM=% K % D ACTLOG^PSXRPPL
101 . S RXERR=20,PSXRXERR=PSXRXERR_"^"_RXERR ;mail message to users
102PSOMSG I +PSOMSG=0 S RXERR=18,PSXRXERR=PSXRXERR_"^"_RXERR ; from PSSLOCK
103 I $P($G(PSXRXERR),"^",3)'="" S PSXOK=8 D ER7^PSXERR
104STOP K DAYS,DRUG,FDATE,PHARCLK,PHY,PSTAT,QTY,RXERR,RXEX,SIG,VAPA(1),DRUGCHK,PTRA,PTRB,REL,RXNUM,PHARCLK1,ZX,VAPA(4),VAPA(5),VAPA(6)
105 Q
106 ;
107TSTSIG ; include testing for BAD characters in SIG
108 I $P(^PSRX(RXN,"SIG"),"^",2)'>0 S SIG=$P(^PSRX(RXN,"SIG"),"^") D TSTCHAR
109 I $P(^PSRX(RXN,"SIG"),"^",2)=1 N L S L=0 F S L=$O(^PSRX(RXN,"SIG1",L)) Q:L'>0 S SIG=$G(^PSRX(RXN,"SIG1",L,0)) D TSTCHAR Q:SIG=""
110 Q
111TSTCHAR ; test each character of SIG for certain characters
112 N I,C
113 I '$D(^TMP($J,"PSXCHAR")) D
114 . F I=0:1:31 S ^TMP($J,"PSXCHAR",I)=""
115 . F I=92,94,124,127 S ^TMP($J,"PSXCHAR",I)=""
116 F I=1:1:$L(SIG) S C=$A($E(SIG,I)) I $D(^TMP($J,"PSXCHAR",C)) S SIG="" Q
117 Q
118MAILOK(TRX) ; return 1 if patient still in mail status & ok to CMOP
119 N PSOMDT,PSOMC,DFN
120 S DFN=$P(^PSRX(TRX,0),"^",2),PSOMDT=$P($G(^PS(55,DFN,0)),"^",5),PSOMC=$P($G(^PS(55,DFN,0)),"^",3)
121 I (PSOMC>1&(PSOMDT>DT))!(PSOMC>1&(PSOMDT<1)) Q 0
122 Q 1
123ADDROK(TRX) ; return 1 if not foreign and not bad address indicator
124 N DFN,PSOFORGN
125 S DFN=$P($G(^PSRX(TRX,0)),"^",2) I DFN="" Q:0
126 I $D(^TMP($J,"PSXBAI",DFN)) Q:+(^TMP($J,"PSXBAI",DFN))
127 D ADD^VADPT
128 S PSOFORGN=$P($G(VAPA(25)),"^",2) I PSOFORGN'="",PSOFORGN'["UNITED STATES" S PSOFORGN=1
129 I PSOFORGN S ^TMP($J,"PSXBAI",DFN)=0 Q 0
130 I $T(CHKRX^PSOBAI)']"" S ^TMP($J,"PSXBAI",DFN)=1 Q 1
131 N PSORX,PSOBADR
132 S PSORX=TRX
133 S PSOBADR=$$CHKRX^PSOBAI(PSORX)
134 I '$P(PSOBADR,"^") S ^TMP($J,"PSXBAI",DFN)=1 Q 1
135 I $P(PSOBADR,"^",2)=1 S ^TMP($J,"PSXBAI",DFN)=1 Q 1
136 S ^TMP($J,"PSXBAI",DFN)=0
137 Q 0
138 ;
139CHKACT(RXN) ; SEE IF FILL IS ALREADY ON ACTIVITY LOG FOR FOREIGN OR BAD ADDRESS
140 N JJ,RFCNT,XX,COM
141 S PSXFIRST=1
142 S COM="Bad Address Indicator or Foreign Address."
143 S RFCNT=0 F RF=0:0 S RF=$O(^PSRX(RXN,1,RF)) Q:'RF S RFCNT=$S(RF<6:RF,1:RF+1)
144 S JJ=0 F S JJ=$O(^PSRX(RXN,"A",JJ)) Q:'JJ S XX=$G(^PSRX(RXN,"A",JJ,0)) I $P(XX,"^",4)=RFCNT,$P(XX,"^",5)[COM S PSXFIRST=0 Q
145 Q
Note: See TracBrowser for help on using the repository browser.