source: WorldVistAEHR/trunk/r/CMOP-PSX/PSXYQRY.m@ 901

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

initial load of WorldVistAEHR

File size: 8.2 KB
Line 
1PSXYQRY ;BIR/HTW-Dual Sends/Receives the Query ;[ 02/20/99 5:49 PM ]
2 ;;2.0;CMOP;**17**;11 Apr 97
3EN I $P($G(^PSX(553,1,"Q")),"^")="S" S PSXSTOP=1 G TST
4 D NOW^%DTC S XZ=$P(^PSX(553.1,0),"^",3),INT=$P(^PSX(553,1,0),"^",9) S:$G(INT)'>0 INT=1
5 I $G(XZ) S LQRYTM=$P(^PSX(553.1,XZ,0),"^",2),NEXTQRY=$$FMADD^XLFDT(LQRYTM,0,INT,0,0)
6 I %>NEXTQRY G EN1
7 I %'>NEXTQRY H $$FMDIFF^XLFDT(%,LQRYTM,2)
8EN1 S (PSXCNT,PSXTRYN,RXCNT)=0,QLR=$P($G(^PSX(553,1,0)),"^",8)
9 K DD,DO
10 S (DA,X)=$P(^PSX(553.1,0),U,3)+1,DIC="^PSX(553.1,",DIC(0)="LZ",DIC("DR")="1////"_%_";4////1",DLAYGO=553.1
11F D FILE^DICN S PSXQRYID=+Y,LOG(1)="QUERY # "_PSXQRYID_" initiated."_$G(PSXQRYA) D LOG^PSXUTL
12 I $P($G(^PSX(553,1,"Q")),"^")="S" S PSXSTOP=1 G TST
13 K DA,DIC,DUOUT,DTOUT,DLAYGO,X,Y,%,DINUM,PSXPOP,TRY
14 S PSXQRY=1 D BID G:$G(PSXQUIT) TST
15 D TSOUT^PSXUTL
16 S PSXBLK=1,PSXLAST=0
17 S PSXTXT="MSH|^~\&|DHCP||"_$S($G(PSXVNDR)>1:"SI BAKER",$G(PSXVNDR)=1:"ELECTROCOM",1:"ELECTROCOM")_"||"_PSXTS_"||QRY|"_PSXQRYID_"|P|2.1|" D XMIT^PSXYSND G:$G(PSXPOP) TST
18 S PSXBLK=2,PSXLAST=1 S PSXTXT="QRD|"_PSXTS_"|R|I|"_PSXQRYID_"|||"_QLR_"^ZO|OP|OTH|ALL" D XMIT^PSXYSND G:$G(PSXPOP) TST
19 W *EOT,*TERM
20 D SLAVE
21TST D FLUSH1^PSXUTL
22 S LOG(1)="QUERY # "_$G(PSXQRYID)_" completed."_$G(PSXQRYA) S:$G(PSXSTOP) LOG(2)="DHCP STOPPED QUERY "_$G(PSXQRYID) S:$G(PSXQUIT) LOG(3)="No Response to Bid, DHCP terminated query." D LOG^PSXUTL
23 S $P(^PSX(554,1,0),"^",3)=$G(PSXQRYID)
24 K PSXHEX,PSXACK,LOG,BLK,BLKA,PSXQRYID,PSXTXT,PSXBLK,%,X,Y,PSXLAST,QLR,MESSID,MSGID,RXCNT,PSXQRY,PSXQRYA,PSXSTOP,PSXPOP,PSXQUIT
25 S ZTREQ="@"
26 G:$G(^PSX(553,1,"Q"))="S" STOP
27 G EN
28NAK D FLUSH1^PSXUTL,LOG^PSXUTL
29 W *NAK,*TERM
30 S PSXTRYN=PSXTRYN+1 G:PSXTRYN>5 ERROR G MSG
31ND I $G(^PSX(553,1,"Q"))="S" S PSXSTOP=1 Q
32 D QRY20^PSXYMSG,FLUSH1^PSXUTL,LOG^PSXUTL S PSXTRYN=PSXTRYN+1 G:PSXTRYN>5 ERROR G MSG
33RTN G:PSXCNT'>1 SLAVE
34 Q:$G(PSXQRY)=0
35 D BID G:$G(PSXQUIT) TST D TSOUT^PSXUTL K PSXTXT,PSXLAST S PSXBLK=1,PSXLAST=0
36 S PSXTXT="MSH|^~\&|DHCP||"_$S($G(PSXVNDR)>0:"SI BAKER",1:"ELECTROCOM")_"||"_PSXTS_"||ACK|"_$G(MSGID)_"|P|2.1|" D XMIT^PSXYSND Q:$G(PSXPOP)
37 S PSXBLK=2,PSXLAST=1
38 S PSXTXT="MSA|"_$S(QRYFLG=0:"AA|"_$G(MSGID)_"|",QRYFLG>0:"AR|"_MSGID_"|"_$S(QRYFLG=1:"RX NUMBER",QRYFLG=2:"STATUS",QRYFLG=3:"COMPLETED DATE",QRYFLG=4:"EMPLOYEE ID",QRYFLG=5:"NO CANCELLED REASON",1:"UNKNOWN")) D XMIT^PSXYSND Q:$G(PSXPOP)
39 I $G(QRYFLG)>0 S DR="1////1",DIE="^PSX(552.3," F I=2:1 S XX=$P(XDA,"^",I) Q:XX'>0 S DA=XX D ^DIE K DA
40 I $G(QRYFLG)>0 K DA,DIE,DR
41 W *EOT,*TERM
42 D NOW^%DTC
43 S $P(^PSX(553.1,PSXQRYID,0),"^",4)=%,$P(^PSX(553.1,PSXQRYID,0),"^",5)=5,$P(^PSX(553.1,PSXQRYID,0),"^",6)=$G(RXCNT)
44 K MESSID,MSGID,TRY,CANFLAG
45 I $G(^PSX(553,1,"Q"))="S" S PSXSTOP=1 Q
46SLAVE S BLKA=0
47 R *X:PSXDLTD
48 E D QRY1^PSXYMSG,LOG^PSXUTL G ND
49 I X'=ENQ D QRY5^PSXYMSG S TRY=$G(TRY)+1 G:$G(TRY)'>5 SLAVE G ERROR
50 R *X:PSXDLTA
51 I ('$T)!(X'=TERM) D QRY14^PSXYMSG G ERROR
52 W *ACK,0,*TERM
53 R *X:PSXDLTD G:X=STX READ I X=EOT R *X:PSXDLTA Q:X=TERM
54MSG R *X:PSXDLTD E D QRY1^PSXYMSG,LOG^PSXUTL G ND
55 I X=STX G READ
56 I X=EOT R *X:PSXDLTA I X=TERM G RTN
57 S QF="STX/EOT"
58 D QRY5^PSXYMSG ;unexpected character received
59ERROR D FLUSH1^PSXUTL,LOG^PSXUTL S QRYPOP=1
60 Q
61READ S PSXACK="" S PSXTMD=$P($H,",",2)
62GETMSG F %=1:1 D Q:'%
63 .R *X:PSXDLTA E D QRY6^PSXYMSG,LOG^PSXUTL S %=0,X="" Q
64 .D CHKD^PSXUTL I PSXTMOUT D QRY6^PSXYMSG,LOG^PSXUTL S %=0,X="" Q
65 .I %>240 D QRY7^PSXYMSG,LOG^PSXUTL S %=0,X="" Q
66 .S PSXACK=PSXACK_$C(X)
67 .I (X=ETX)!(X=ETB) S %=0
68 I X=ETX S PSXCNT=PSXCNT+1 G TEST
69 I X=ETB G TEST
70 I X=EOT R *X:PSXDLTA G:X=TERM MSG
71 I (X'=ETX)!(X'=ETB)!(X'=EOT) D QRY8^PSXYMSG G NAK
72 I PSXACK="" D QRY9^PSXYMSG G ERROR
73 Q
74TEST R *X:PSXDLTA E D QRY10^PSXYMSG G ERROR
75 I "0123456789ABCDEF"'[$C(X) D QRY11^PSXYMSG G NAK
76 S PSXSUM=$C(X)
77CHKSUM R *X:PSXDLTA E D QRY10^PSXYMSG G ERROR
78 I "0123456789ABCDEF"'[$C(X) D QRY11^PSXYMSG G NAK
79 S PSXSUM=PSXSUM_$C(X)
80 S X=PSXACK X ^%ZOSF("LPC") S PSXHEX=Y D HEX^PSXUTL
81 R *X:1 I X'=TERM D QRY5^PSXYMSG
82 I PSXHEX'=PSXSUM D QRY12^PSXYMSG G NAK
83 I PSXHEX=PSXSUM D FLUSH1^PSXUTL
84 S BLK=$E(PSXACK,1) I BLK>7 D QRY16^PSXYMSG G NAK
85 I RXCNT=QLR&($E(PSXACK,7,10)'["BTS") D QRY19^PSXYMSG,LOG^PSXUTL W *EOT,*TERM Q
86 I $E(PSXACK,7,10)["BTS|" S DA=PSXQRYID,PSXQRY=0,DIE="^PSX(553.1,",DR="4////1" S:RXCNT=0 PSXCNT=2 D ^DIE K DR,DA,DIE
87 I $E(PSXACK,7,9)["MSA"&($P(PSXACK,"|",3)'=PSXQRYID) D QRY15^PSXYMSG G NAK
88 I $E(PSXACK,7,9)["QRD"&($P(PSXACK,"|",5)'=PSXQRYID) D QRY15^PSXYMSG G NAK
89 W *ACK,BLK,*TERM D FILE G MSG
90 Q
91FILE I $E(PSXACK,7,10)["MSH|" S MESSID=$E(PSXACK,7,$L(PSXACK)-2),MSGID=$P(MESSID,"|",10),QRYFLG=0,XDA=""
92 I $E(PSXACK,7,12)["NTE|99" D
93 .S CANFLAG=0
94 .S:($P($P(PSXACK,"\",1),"|",4)="")!($P($P(PSXACK,"\",1),"|",4)[" ") QRYFLG=1 Q:QRYFLG>0 S:"CACO"'[$P(PSXACK,"\F\",2) QRYFLG=2 S:$P(PSXACK,"\F\",2)["CA" CANFLAG=1 Q:QRYFLG>0
95 .S:$P(PSXACK,"\F\",3)'?10.14N QRYFLG=3 Q:QRYFLG>0 S EMPID=$P(PSXACK,"\F\",5) S:$G(EMPID)="" QRYFLG=4 Q:QRYFLG>0 S:'$D(^XUSEC("PSXRPH",EMPID)) QRYFLG=4 Q:QRYFLG>0
96 .I $G(EMPID)>0 N X,Y S DIC=200,DIC(0)="MNZ",X=EMPID D ^DIC K DIC S:$G(Y)<1 QRYFLG=4 K X,Y Q:QRYFLG>0
97 .S RXCNT=RXCNT+1
98 I $E(PSXACK,7,13)["NTE|100" S:($G(CANFLAG)>0&($P($P(PSXACK,"\",1),"|",4)="")) QRYFLG=5
99 Q:BLK=BLKA
100 Q:$G(QRYFLG)>0
101F1 L +^PSX(552.3,0):3 G:'$T F1 S NEW=$P(^PSX(552.3,0),"^",3)+1,$P(^PSX(552.3,0),"^",4)=$P(^PSX(552.3,0),"^",4)+1,$P(^PSX(552.3,0),"^",3)=NEW L -^PSX(552.3,0)
102 G:$D(^PSX(552.3,NEW,0)) F1
103F2 L +^PSX(552.3,NEW):3 G:'$T F2 S ^PSX(552.3,NEW,0)=$E(PSXACK,7,$L(PSXACK)-2),^PSX(552.3,NEW,1)=2,^PSX(552.3,"AQ",NEW)="" L -^PSX(552.3,NEW) S XDA=$G(XDA)_"^"_NEW K NEW
104 S BLKA=BLK
105 Q
106XMIT S (PSXPOP,PSXTRYN)=0
107 S PSXLEN=$L(PSXTXT)
108 S PSXLEN=$E("00000",1,5-$L(PSXLEN))_PSXLEN
109 S PSXTXT=PSXBLK_PSXLEN_PSXTXT_$S(PSXLAST:$C(ETX),1:$C(ETB))
110 ;Get 2 byte hex Csum
111 S X=PSXTXT X ^%ZOSF("LPC") S PSXHEX=Y D HEX^PSXUTL
112 S PSXTXT=$C(STX)_PSXTXT_PSXHEX_$C(TERM)
113RETRY W PSXTXT
114 S PSXBLK=$A(PSXBLK)
115TRY R *X:PSXDLTA E D SND1 G ERROR1 ;look for ACK or NAK
116 I X=ACK R *X:PSXDLTA D:('$T)!(X'=PSXBLK) SND2 G:('$T)!(X'=PSXBLK) ERROR1 R *X:PSXDLTA D:('$T)!(X'=TERM) SND9 G:('$T)!(X'=TERM) ERROR1 Q
117 I X=NAK R *X:PSXDLTA D:('$T)!(X'=TERM) SND3 D SND4 G ERROR1
118 I X=EOT R *X:PSXDLTA D:('$T)!(X'=TERM) SND5 D SND7 G:('$T)!(X'=TERM) ERROR1 S PSXTRYN=9999 G ERROR1
119 D SND6
120ERROR1 D FLUSH1^PSXUTL,LOG^PSXUTL
121 S PSXTRYN=PSXTRYN+1
122 S PSXBLK=$C(PSXBLK)
123 G:PSXTRYN'>PSXTRYL RETRY
124 S PSXPOP=1
125 Q
126BID ;Set line bid retry counter
127 S PSXTRY=0
128BID1 G:$P($G(^PSX(553,1,"Q")),"^")="S" STOP
129 S PSXTME=$P($H,",",2)
130 U IO
131 W *ENQ,*TERM
132BID2 R *X:PSXDLTA E D MST6^PSXYMSG G BAD
133 I X=EOT R *X:PSXDLTA G:X=TERM BID2
134 I X=ENQ R *X:PSXDLTA D:'$T!(X'=TERM) MST1^PSXYMSG G:'$T!(X'=TERM) BAD S PSXTME=$P($H,",",2) S PSXTRY=PSXTRY+1 G:PSXTRY>PSXTRYM BAD D MST7^PSXYMSG,LOG^PSXUTL G BID2 ;ENQ received
135 I X=NAK R *X:PSXDLTA D:'$T!(X'=TERM) MST2^PSXYMSG G:'$T!(X'=TERM) BAD D MST5^PSXYMSG,LOG^PSXUTL G BAD
136 I X=ACK R *X:PSXDLTA D:'$T!(X'=48) MST3^PSXYMSG G:'$T!(X'=48) BAD R *X:PSXDLTA D:'$T!(X'=TERM) MST8^PSXYMSG G:($G(X)=TERM) OKAY
137 D MST4^PSXYMSG ;if X wasn't ENQ or ACK or NAK then garbage
138BAD S PSXTRY=PSXTRY+1 D FLUSH1^PSXUTL,LOG^PSXUTL G:PSXTRY'>PSXTRYM BID1
139 ;STOP interface if bid fails more that M times
140 D MST9^PSXYMSG,LOG^PSXUTL,SETPAR^PSXYSTRT
141 S PSXQUIT=1
142 ;Hibernate awhile till CMOP comes on line,then try again
143 H 45
144 G ^PSXJOB
145OKAY ;Bid for Master was succesful
146 S PSXTME=$P($H,",",2)
147 ;Quit if Status is Stopped
148 G:^PSX(553,1,"Q")="S" STOP
149 Q
150STOP K LOG S LOG(1)="Stop Query interface request detected from DHCP."
151 D LOG^PSXUTL
152 K LOG,PSXONE S LOG(1)="Stopping the Query interface now!"
153 D ^%ZISC S ZTREQ="@"
154 D LOG^PSXUTL
155 W "Done!"
156 Q
157SND1 K LOG S LOG(1)="SND1 Timer A timeout after sending a line of text."_$G(PSXBLK) Q
158SND2 K LOG S LOG(1)="SND2 ACK Received with bad block number after sending line of text, ASCII ("_$G(X)_") "_X
159 S LOG(2)="Expected ASCII ("_$G(PSXBLK)_")." Q
160SND3 K LOG S LOG(1)="SND3 NAK Received with no terminator after sending a line of text." Q
161SND4 K LOG S LOG(1)="SND4 NAK Received after sending a line of text." Q
162SND5 K LOG S LOG(1)="SND5 EOT Received with no terminator after sending a line of text." Q
163SND6 K LOG S LOG(1)="SND6 Garbage received after sending a line of text. ("_X_")" Q
164SND7 K LOG S LOG(1)="SND7 EOT Received, aborting send." Q
165SND8 K LOG S LOG(1)="SND8 Aborting Send. Error processing order # "_$P($G(^PSX(552.2,PSXQN,0)),"^",1)_". Text: "_PSXTXT Q
166SND9 K LOG S LOG(1)="SND9 ACK,"_$G(PSXBLK)_" received with no terminator after sending",LOG(2)="a line of text." Q
Note: See TracBrowser for help on using the repository browser.