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

BOPT1.m

Go to the documentation of this file.
BOPT1 ;IHS/ILC/ALG/CIA/PLS - ILC Send and Receive;07-Mar-2006 12:04;SM
 ;;1.0;AUTOMATED DISPENSING INTERFACE;**1**;Jul 26, 2005
 Q
 ;This rtn loops through the BOP QUEUE file #90355.1
 ;looking for HL7 messages to build, send or receive.
 ;ENTRY
GO ; EP
 S BOPOOS=$G(^%ZOSF("OS"))
 Q:'$D(BOPDIV)  Q:'$D(BOPOCK)  Q:'$D(BOPIP)
 L ^BOP(90355,"S",BOPDIV):1
 I '$T  G EXIT
 N IO
 D SETUP^BOPTCP
 ;IHS exemption approved on March 16, 2005
 I XCSNT N $ESTACK,$ETRAP S $ETRAP="D ERROR^BOPTCP"
 S CT=0
OPEN D CALL^%ZISTCP(BOPIP,BOPOCK)
 G LOOP:'POP S CT=CT+1 H 30 G OPEN:CT<5
 Q
LOOP I '$P(^BOP(90355,1,3,BOPDIV,0),U,2) G CLOSE
 I +$G(^BOP(90355,1,12))=1 G CLOSE
 S COUNTER=0,STOP=0
 F  S COUNTER=$O(^BOP(90355.1,"AS",0,COUNTER)) Q:COUNTER'>0  Q:STOP  D
 .S NODE=^BOP(90355.1,COUNTER,0)
 .I $P(NODE,U,11)>3 K ^BOP(90355.1,"AS",0,COUNTER) Q
 .I $P(NODE,U,2)'="Q03" Q:$P(NODE,U,12)'=BOPDIV&($P(NODE,U,4)'="MFN")
 .S STATUS=$P(NODE,"^",10)
 .Q:STATUS=99
 .;Get BOP Site and Location Decode Code
 .S Y=$$SITE^BOPTU(1),BOPITE=$P(Y,U),BOPTYPE=$P(Y,U,2)
 .;
 .S ACTION=$P(NODE,"^",2)
 .K OUT D @ACTION
 .S OUT(CONT)=OUT(CONT)_$C(28,13)
 .S CT=0
SEND .K IN S BOPACKE=0
 .D SDATA^BOPTCP("OUT")
 .S $P(^BOP(90355.1,COUNTER,0),U,10)=1
 .D GDATA^BOPTCP("IN")
 .S RESP=$O(IN(0)) Q:RESP=""  D  I CT<5,$G(BOPACKE) G SEND
 ..S HDR=IN(RESP)
 ..Q:HDR'["MSH"
 ..I $P(HDR,"|",9)'["ACK" S $P(^BOP(90355.1,COUNTER,0),U,10)=3 Q
 ..S RESP=$O(IN(RESP)) Q:RESP=""
 ..S ACK1=IN(RESP)
 ..I $P(ACK1,"|",2)="AA" S $P(^BOP(90355.1,COUNTER,0),U,10)=9
 ..I  K ^BOP(90355.1,"AS",0,COUNTER),^BOP(90355.1,COUNTER,"O") D  ; update node
 ...N %DT,X,Y S %DT="ST",X="NOW" D ^%DT S ^BOP(90355.1,COUNTER,"O",0)=Y K %DT,X,Y
 ...I $G(CONT)>0 F AAA=1:1:$G(CONT) S CCC=$G(OUT(AAA)) I CCC'="" F BBB=1:1 S ^BOP(90355.1,COUNTER,"O",AAA,BBB)=$E(CCC,1,252),CCC=$E(CCC,253,$L(CCC)) Q:CCC=""
 ..I $P(ACK1,"|",2)="AE" S $P(^BOP(90355.1,COUNTER,0),U,10)=3,CT=CT+1 S BOPACKE=1 Q
 ..I $P(ACK1,"|",2)="AR" S $P(^BOP(90355.1,COUNTER,0),U,10)=3,CT=CT+1 S BOPACKE=1 Q
 .I $G(BOPACKE) S C=$P(NODE,U,11)+1,$P(^BOP(90355.1,COUNTER,0),U,11)=C
 H 15 G LOOP
CLOSE D CLOSE^%ZISTCP D EXIT
 Q
 ;
A01 ;Build an Admit A01 ;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2,OBXW^BOPT3,OBXH^BOPT3
 D DG1^BOPT3,AL1^BOPT3
 Q
A02 ;Build a Transfer A02;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 D OBXW^BOPT3,OBXH^BOPT3,DG1^BOPT3,AL1^BOPT3
 Q
A03 ;Build a Discharge A03;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A04 ;Build a Registration A04;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2,OBXW^BOPT3,OBXH^BOPT3
 D DG1^BOPT3,AL1^BOPT3
 Q
A06 ;Build a Change Out to In pat A06;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A07 ;Build a Change In to Out pat A07;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A08 ;Build an Update A08;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 S X=$G(^BOP(90355.1,COUNTER,0)),X=$P(X,"^",21)
 I X=1 D OBXH^BOPT3 Q
 I X=2 D OBXW^BOPT3 Q
 I X=3!(X=5) D DG1^BOPT3 Q
 I X=4 D AL1^BOPT3 Q
 Q
A11 ;Build a Cancel Admit A11;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A17 ;Build a Swap Bed
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A18 ;Build a Merge Info A18;not implemented
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,MRG^BOPT2,PV1^BOPT2
 Q
A23 ;Build a Delete Pat A23;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
A34 ;Build a Merge ID only A34;not implemented
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,MRG^BOPT2,PV1^BOPT2
 Q
A35 ;Build a Merge Account only A35;not implemented
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,EVN^BOPT2,PID^BOPT2,MRG^BOPT2,PV1^BOPT2
 Q
O01 ;Order a Drug O01
 ;RXC seg. is not implemented as no IV solutions done at this time
 S TYPE="RDE",CONT=0
 D MSH^BOPT2,PID^BOPT2,PV1^BOPT2,ORC^BOPT3,RXE^BOPT3
 I +$P($G(^BOP(90355.1,COUNTER,8)),U,6)=1 D RXC^BOPT3
 D RXR^BOPT3
 Q
A13 ;FOR an A13;
 S TYPE="ADT",CONT=0
 D MSH^BOPT2,PID^BOPT2,PV1^BOPT2
 Q
Q03 ;Data Link Response
 S TYPE="QRY",CONT=0
 D MSH^BOPT2
 S TIME=$$HLDATE^HLFNC($P(NODE,U,3)),TIME=$P(TIME,"-",1)
 S CONT=CONT+1,OUT(CONT)="QRD|"_TIME_"|D|D|ETO|||||ETR|"_$C(13)
 S CONT=CONT+1,OUT(CONT)="DSP|"_$C(13)
 Q
ERROR ;Set up to send alert
 Q
EXIT ;
 D PURGE
 K COUNTER,NODE,STATUS,ACTION,FLD,ENCD,COM,REP,ESC,SCOM,CONT,RESP
 Q
 ; Loop thru QUEUE and purge eligible records
PURGE ;
 N DA,DIK,DTK,EDT,QDT
 ;Set days to keep (default to 7)
 S DTK=$P($G(^BOP(90355,1,4)),U,5) S:'DTK DTK=7
 S EDT=$$FMADD^XLFDT(DT,-DTK)
 S DIK="^BOP(90355.1,"
 F QDT=0 F  S QDT=$O(^BOP(90355.1,"B",QDT)) Q:'QDT!(QDT>EDT)  D
 .S DA=0 F  S DA=$O(^BOP(90355.1,"B",QDT,DA)) Q:'DA  D
 ..I $$CANDEL(DA) D
 ...D ^DIK
 Q
 ; Return a 1 if a queue record can be deleted
CANDEL(IEN) ;
 N NODE0
 S NODE0=^BOP(90355.1,IEN,0)
 I $P(NODE0,U,4)'="",$P(NODE0,U,10)=9 Q 1
 I '$L($P($G(^BOP(90355.1,IEN,99)),U,2)) Q 1
 I $P(NODE0,U,4)="",$P(^BOP(90355.1,IEN,99),U,2)=9 Q 1
 Q 0