ALPBHL2 ;OIFO-DALLAS MW,SED,KC - BCBU main HL7 message processor ;01/01/03
;;3.0;BAR CODE MED ADMIN;**7,8,1018**;Mar 2004;Build 27
;
S ALPBECH=HL("ECH")
S ALPBCS=$E(ALPBECH)
S ALPBFS=HL("FS")
S ALPBHREC=$S(+$G(HLMTIEN)>0:HLMTIEN,1:$G(HL("MID")))
;
; process the entire HL7 message's lines into local array...
;F I=1:1 X HLNEXT Q:+$G(HLQUIT)'>0 D
S I=0 F S I=$O(HLA("HLS",I)) Q:I'>0 S HLNODE=$G(HLA("HLS",I)) Q:HLNODE="" D ;VAOIT FOXK
.S ALPBSEG=$P(HLNODE,ALPBFS,1)
.; store patient ID and order segments in a special way...
.I ALPBSEG="PID"!(ALPBSEG="ORC")!(ALPBSEG="PV1")!(ALPBSEG="RXO") S ALPBMTXT(ALPBSEG)=HLNODE
.I ALPBSEG="AL1" S ALPBMTXT("AL1")=1
.S ALPBMTXT(I)=HLNODE
.; get any continuation lines...
.S J=0
.F S J=$O(HLNODE(J)) Q:'J S ALPBMTXT(I,J)=HLNODE(J)
.K ALPBSEG
;
; retrieve patient ID data from the PID segment...
S ALPBX=$G(ALPBMTXT("PID"))
I ALPBX'="" D
.D GETPID^ALPBUTL2(ALPBX,ALPBFS,ALPBCS,ALPBECH,.ALPBDATA)
.S ALPBPDFN=$G(ALPBDATA(1))
.S ALPBPNAM=$G(ALPBDATA(2))
.S ALPBPSSN=$G(ALPBDATA(3))
.S ALPBPDOB=$G(ALPBDATA(4))
.S ALPBPSEX=$G(ALPBDATA(5))
.K ALPBDATA
K ALPBX
; we must have patient's SSN (ALPBPSSN) to process this message...
I $G(ALPBPSSN)="" D Q
.D ERRBLD^ALPBUTL1("PID","Invalid/missing SSN",.ALPBFERR)
.D ERRLOG^ALPBUTL1(0,0,ALPBHREC,"PID",$G(ALPBMTXT("PID"),"PID segment undefined"),.ALPBFERR)
.K ALPBFERR
.D CLEAN
K ALPBMTXT("PID")
;
; using patient's DFN, get BCBU record number...
S ALPBIEN=0
I $D(^ALPB(53.7,ALPBPDFN)) S ALPBIEN=ALPBPDFN
; create new record?...
I ALPBIEN'>0 D
.S DIC="^ALPB(53.7,"
.S DIC(0)="LZ"
.S DINUM=ALPBPDFN
.S DLAYGO=53.7
.S X=ALPBPNAM
.D FILE^DICN
.K DIC,DINUM,DLAYGO
.S ALPBIEN=+Y
; if ALPBIEN'>0 then patient record find or creation error...
I +ALPBIEN'>0 D Q
.D ERRBLD^ALPBUTL1("","Failed to find/create patient record",.ALPBFERR)
.D ERRLOG^ALPBUTL1(0,0,ALPBHREC,"",$G(ALPBPDFN,"DFN undefined")_"^"_$G(ALPBPNAM,"Name undefined")_"^"_$G(ALPBPSSN,"SSN undefined"),.ALPBFERR)
.K ALPBFERR
.D CLEAN
;
; check PV1 segment to see if this is a discharge movement. if so,
; delete the patient's BCBU record and quit...
I $P($G(ALPBMTXT("PV1")),ALPBFS,37)'="" D Q
.D DELPT^ALPBUTL(+$G(ALPBIEN))
.D CLEAN
;
; file/update patient demographic data...
S ALPBFILE(53.7,ALPBIEN_",",.01)=ALPBPNAM
S ALPBFILE(53.7,ALPBIEN_",",1)=ALPBPSSN
S ALPBFILE(53.7,ALPBIEN_",",2)=ALPBPDOB
S ALPBFILE(53.7,ALPBIEN_",",3)=ALPBPSEX
D FILE^DIE("","ALPBFILE","ALPBFERR")
I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),0,$G(ALPBHREC),"PID","Demographics update failed",.ALPBFERR)
K ALPBFERR,ALPBFILE
;
; if the allergies flag is set (ALPBMTXT("AL1")), delete any
; allergies on file (they will be rebuilt by this message)...
I +$G(ALPBMTXT("AL1")) D DELALG^ALPBUTL2(ALPBIEN)
;
; if there is no ORC (order) segment, process the rest of the
; message and quit...
I $G(ALPBMTXT("ORC"))="" D PM Q
;
; retrieve order number and transaction date from ORC segment...
D GETORC^ALPBUTL2($G(ALPBMTXT("ORC")),$G(ALPBFS),$G(ALPBCS),.ALPBDATA)
S ALPBMLOG=$S($G(ALPBDATA(0))="ML":1,1:0)
S ALPBORDN=$G(ALPBDATA(1))
S ALPBORDT=$G(ALPBDATA(2))
S ALPBORDC=+$G(ALPBDATA(3))
; ALPBOTYP="V" for IV, "U" for Unit Dose, or "P" for Pending
S ALPBOTYP=$G(ALPBDATA(4))
K ALPBDATA
;
; we must have an order number to process the order-specific data,
; if we do not then log that error condition and quit...
I $G(ALPBORDN)="" D Q
.D ERRBLD^ALPBUTL1("","No order number in ORC segment",.ALPBFERR)
.D ERRLOG^ALPBUTL1(0,0,ALPBHREC,"ORC",$G(ALPBMTXT("ORC"),"ORC segment not defined"),.ALPBFERR)
.K ALPBFERR
.D CLEAN
K ALPBMTXT("ORC")
;
; using CPRS order number, check to see if the order is already on
; file. if so, and status is PENDING delete the order record...
I ALPBORDC>0 D
.;LOOP Through. May have replaced orders so need to check all
.S ALPBI=0
.F S ALPBI=$O(^ALPB(53.7,ALPBIEN,2,"ACPRS",ALPBORDC,ALPBI)) Q:+ALPBI'>0 D
..I $E($P($G(^ALPB(53.7,ALPBIEN,2,ALPBI,0)),"^",3),1,2)'="IP" Q
..D DELORD^ALPBUTL(ALPBIEN,ALPBI)
K ALPBI
;
; existing order's record number?...
K ALPBOIEN
S ALPBOIEN=+$O(^ALPB(53.7,ALPBIEN,2,"B",ALPBORDN,0))
; if this isn't a Med Log update, and this order is already on
; file, delete its drug(s), additive(s) and/or solution(s) --
; they will be rebuilt by the other segments in this message...
I +$G(ALPBMLOG)=0&(ALPBOIEN>0) D CLORD^ALPBUTL2(ALPBIEN,ALPBOIEN)
; create new order record?...
I +$G(ALPBOIEN)=0 D
.S ALPBOIEN=+$O(^ALPB(53.7,ALPBIEN,2," "),-1)+1
.S ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",.01)=ALPBORDN
.; don't file a 0 (zero) CPRS order number...
.I ALPBORDC>0 S ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",1)=ALPBORDC
.S ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",3)=ALPBORDT
.S ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",6)=ALPBOTYP
.D UPDATE^DIE("","ALPBFILE","ALPBOIEN","ALPBFERR")
.I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(ALPBIEN,"0",ALPBHREC,"NEWORD","",.ALPBFERR)
.K ALPBFERR,ALPBFILE
;
PM ; process the message segments...
S I=0
F S I=$O(ALPBMTXT(I)) Q:'I D
.S ALPBDATA=ALPBMTXT(I)
.S ALPBSEG=$P(ALPBDATA,ALPBFS)
.; allergies segment...
.I ALPBSEG="AL1" D
..D AL1^ALPBHL1U(+$G(ALPBIEN),$G(ALPBDATA),$G(ALPBFS),$G(ALPBCS),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"AL1",$G(ALPBDATA),.ALPBFERR)
..K ALPBFERR
.; general order segment...
.I ALPBSEG="ORC" D
..D ORC^ALPBHL1U(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBDATA),$G(ALPBMLOG),$G(ALPBFS),$G(ALPBCS),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"ORC",$G(ALPBDATA),.ALPBFERR)
..K ALPBFERR
.; patient movement/location segment...
.I ALPBSEG="PV1" D
..D PV1^ALPBHL1U(+$G(ALPBIEN),$G(ALPBDATA),$G(ALPBFS),$G(ALPBCS),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"PV1",$G(ALPBDATA),.ALPBFERR)
..K ALPBFERR
.; IV orders segment...
.I ALPBSEG="RXC" D
..D RXC^ALPBHL1U(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBDATA),$G(ALPBFS),$G(ALPBCS),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"RXC",$G(ALPBDATA),.ALPBFERR)
..K ALPBFERR
.; drug, additives and/or solutions segment...
.I ALPBSEG="RXE" D
..I $G(ALPBDATA)="" Q
..; if this is a Pending order, check to see if a drug is included in this RXE seg. if not, let's try to add the one that may be in the RXO seg...
..I +$P($P(ALPBDATA,ALPBFS,3),ALPBCS,4)=0 S $P(ALPBDATA,ALPBFS,3)=$P($G(ALPBMTXT("RXO")),ALPBFS,2)
..;chech for any continuation lines
..S J=0 F S J=$O(ALPBMTXT(I,J)) Q:'J S ALPBDATA=ALPBDATA_ALPBMTXT(I,J)
..D RXE^ALPBHL1U(+$G(ALPBIEN),+$G(ALPBOIEN),ALPBDATA,$G(ALPBFS),$G(ALPBCS),$G(ALPBECH),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"RXE",ALPBDATA,.ALPBFERR)
..K ALPBFERR
.; med route...
.I ALPBSEG="RXR" D
..D RXR^ALPBHL1U(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBDATA),$G(ALPBFS),$G(ALPBCS),.ALBPFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"RXR",$G(ALPBDATA),.ALPBFERR)
..K ALPBFERR
.; provider comments, special instructions or other print info...
.I ALPBSEG="NTE" D
..; NTE segments can be multiple-lines. set up an array (ALPBNTE(...)) to pass to the filer...
..; the first node will be the one that contains the NTE segment identifier
..S ALPBNTE(1)=ALPBDATA
..S ALPBX=1
..; loop from ALPBMTXT(I) to retrieve any continuation lines...
..S J=0
..F S J=$O(ALPBMTXT(I,J)) Q:'J D
...S ALPBX=ALPBX+1
...S ALPBNTE(ALPBX)=ALPBMTXT(I,J)
..K ALPBX,J
..D NTE^ALPBHL1U(+$G(ALPBIEN),+$G(ALPBOIEN),.ALPBNTE,$G(ALPBFS),$G(ALPBCS),.ALPBFERR)
..I +$G(ALPBFERR("DIERR")) D ERRLOG^ALPBUTL1(+$G(ALPBIEN),+$G(ALPBOIEN),$G(ALPBHREC),"NTE",ALPBDATA,.ALPBFERR)
..K ALPBFERR,ALPBNTE
.K ALPBDATA,ALPBSEG
;
; set RECORD LAST UPDATED field...
S ALPBLUPD=$$NOW^XLFDT()
I $G(^ALPB(53.7,+$G(ALPBIEN),0))'="" D
.S ALPBFILE(53.7,ALPBIEN_",",7)=ALPBLUPD
.D FILE^DIE("","ALPBFILE","ALPBFERR")
.K ALPBFERR,ALPBFILE
;
; update PARAMETER file with last update date...
S ALPBPARM=+$O(^ALPB(53.71,0))
I ALPBPARM>0 D
.S ALPBFILE(53.71,ALPBPARM_",",4)=ALPBLUPD
.D FILE^DIE("","ALPBFILE","ALPBFERR")
.K ALPBFERR,ALPBFILE
K ALPBLUPD,ALPBPARM
;
CLEAN K ALPBCS,ALPBDATA,ALPBECH,ALPBFS,ALPBHREC,ALPBIEN,ALPBMLOG,ALPBMTXT
K ALPBOIEN,ALPBORDC,ALPBORDN,ALPBORDT,ALPBOTYP,ALPBPDFN,ALPBPDOB
K ALPBPNAM,ALPBPSEX,ALPBPSSN,ALPBSEG
Q
ALPBHL2 ;OIFO-DALLAS MW,SED,KC - BCBU main HL7 message processor ;01/01/03
+1 ;;3.0;BAR CODE MED ADMIN;**7,8,1018**;Mar 2004;Build 27
+2 ;
+3 SET ALPBECH=HL("ECH")
+4 SET ALPBCS=$EXTRACT(ALPBECH)
+5 SET ALPBFS=HL("FS")
+6 SET ALPBHREC=$SELECT(+$GET(HLMTIEN)>0:HLMTIEN,1:$GET(HL("MID")))
+7 ;
+8 ; process the entire HL7 message's lines into local array...
+9 ;F I=1:1 X HLNEXT Q:+$G(HLQUIT)'>0 D
+10 ;VAOIT FOXK
SET I=0
FOR
SET I=$ORDER(HLA("HLS",I))
IF I'>0
QUIT
SET HLNODE=$GET(HLA("HLS",I))
IF HLNODE=""
QUIT
Begin DoDot:1
+11 SET ALPBSEG=$PIECE(HLNODE,ALPBFS,1)
+12 ; store patient ID and order segments in a special way...
+13 IF ALPBSEG="PID"!(ALPBSEG="ORC")!(ALPBSEG="PV1")!(ALPBSEG="RXO")
SET ALPBMTXT(ALPBSEG)=HLNODE
+14 IF ALPBSEG="AL1"
SET ALPBMTXT("AL1")=1
+15 SET ALPBMTXT(I)=HLNODE
+16 ; get any continuation lines...
+17 SET J=0
+18 FOR
SET J=$ORDER(HLNODE(J))
IF 'J
QUIT
SET ALPBMTXT(I,J)=HLNODE(J)
+19 KILL ALPBSEG
End DoDot:1
+20 ;
+21 ; retrieve patient ID data from the PID segment...
+22 SET ALPBX=$GET(ALPBMTXT("PID"))
+23 IF ALPBX'=""
Begin DoDot:1
+24 DO GETPID^ALPBUTL2(ALPBX,ALPBFS,ALPBCS,ALPBECH,.ALPBDATA)
+25 SET ALPBPDFN=$GET(ALPBDATA(1))
+26 SET ALPBPNAM=$GET(ALPBDATA(2))
+27 SET ALPBPSSN=$GET(ALPBDATA(3))
+28 SET ALPBPDOB=$GET(ALPBDATA(4))
+29 SET ALPBPSEX=$GET(ALPBDATA(5))
+30 KILL ALPBDATA
End DoDot:1
+31 KILL ALPBX
+32 ; we must have patient's SSN (ALPBPSSN) to process this message...
+33 IF $GET(ALPBPSSN)=""
Begin DoDot:1
+34 DO ERRBLD^ALPBUTL1("PID","Invalid/missing SSN",.ALPBFERR)
+35 DO ERRLOG^ALPBUTL1(0,0,ALPBHREC,"PID",$GET(ALPBMTXT("PID"),"PID segment undefined"),.ALPBFERR)
+36 KILL ALPBFERR
+37 DO CLEAN
End DoDot:1
QUIT
+38 KILL ALPBMTXT("PID")
+39 ;
+40 ; using patient's DFN, get BCBU record number...
+41 SET ALPBIEN=0
+42 IF $DATA(^ALPB(53.7,ALPBPDFN))
SET ALPBIEN=ALPBPDFN
+43 ; create new record?...
+44 IF ALPBIEN'>0
Begin DoDot:1
+45 SET DIC="^ALPB(53.7,"
+46 SET DIC(0)="LZ"
+47 SET DINUM=ALPBPDFN
+48 SET DLAYGO=53.7
+49 SET X=ALPBPNAM
+50 DO FILE^DICN
+51 KILL DIC,DINUM,DLAYGO
+52 SET ALPBIEN=+Y
End DoDot:1
+53 ; if ALPBIEN'>0 then patient record find or creation error...
+54 IF +ALPBIEN'>0
Begin DoDot:1
+55 DO ERRBLD^ALPBUTL1("","Failed to find/create patient record",.ALPBFERR)
+56 DO ERRLOG^ALPBUTL1(0,0,ALPBHREC,"",$GET(ALPBPDFN,"DFN undefined")_"^"_$GET(ALPBPNAM,"Name undefined")_"^"_$GET(ALPBPSSN,"SSN undefined"),.ALPBFERR)
+57 KILL ALPBFERR
+58 DO CLEAN
End DoDot:1
QUIT
+59 ;
+60 ; check PV1 segment to see if this is a discharge movement. if so,
+61 ; delete the patient's BCBU record and quit...
+62 IF $PIECE($GET(ALPBMTXT("PV1")),ALPBFS,37)'=""
Begin DoDot:1
+63 DO DELPT^ALPBUTL(+$GET(ALPBIEN))
+64 DO CLEAN
End DoDot:1
QUIT
+65 ;
+66 ; file/update patient demographic data...
+67 SET ALPBFILE(53.7,ALPBIEN_",",.01)=ALPBPNAM
+68 SET ALPBFILE(53.7,ALPBIEN_",",1)=ALPBPSSN
+69 SET ALPBFILE(53.7,ALPBIEN_",",2)=ALPBPDOB
+70 SET ALPBFILE(53.7,ALPBIEN_",",3)=ALPBPSEX
+71 DO FILE^DIE("","ALPBFILE","ALPBFERR")
+72 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),0,$GET(ALPBHREC),"PID","Demographics update failed",.ALPBFERR)
+73 KILL ALPBFERR,ALPBFILE
+74 ;
+75 ; if the allergies flag is set (ALPBMTXT("AL1")), delete any
+76 ; allergies on file (they will be rebuilt by this message)...
+77 IF +$GET(ALPBMTXT("AL1"))
DO DELALG^ALPBUTL2(ALPBIEN)
+78 ;
+79 ; if there is no ORC (order) segment, process the rest of the
+80 ; message and quit...
+81 IF $GET(ALPBMTXT("ORC"))=""
DO PM
QUIT
+82 ;
+83 ; retrieve order number and transaction date from ORC segment...
+84 DO GETORC^ALPBUTL2($GET(ALPBMTXT("ORC")),$GET(ALPBFS),$GET(ALPBCS),.ALPBDATA)
+85 SET ALPBMLOG=$SELECT($GET(ALPBDATA(0))="ML":1,1:0)
+86 SET ALPBORDN=$GET(ALPBDATA(1))
+87 SET ALPBORDT=$GET(ALPBDATA(2))
+88 SET ALPBORDC=+$GET(ALPBDATA(3))
+89 ; ALPBOTYP="V" for IV, "U" for Unit Dose, or "P" for Pending
+90 SET ALPBOTYP=$GET(ALPBDATA(4))
+91 KILL ALPBDATA
+92 ;
+93 ; we must have an order number to process the order-specific data,
+94 ; if we do not then log that error condition and quit...
+95 IF $GET(ALPBORDN)=""
Begin DoDot:1
+96 DO ERRBLD^ALPBUTL1("","No order number in ORC segment",.ALPBFERR)
+97 DO ERRLOG^ALPBUTL1(0,0,ALPBHREC,"ORC",$GET(ALPBMTXT("ORC"),"ORC segment not defined"),.ALPBFERR)
+98 KILL ALPBFERR
+99 DO CLEAN
End DoDot:1
QUIT
+100 KILL ALPBMTXT("ORC")
+101 ;
+102 ; using CPRS order number, check to see if the order is already on
+103 ; file. if so, and status is PENDING delete the order record...
+104 IF ALPBORDC>0
Begin DoDot:1
+105 ;LOOP Through. May have replaced orders so need to check all
+106 SET ALPBI=0
+107 FOR
SET ALPBI=$ORDER(^ALPB(53.7,ALPBIEN,2,"ACPRS",ALPBORDC,ALPBI))
IF +ALPBI'>0
QUIT
Begin DoDot:2
+108 IF $EXTRACT($PIECE($GET(^ALPB(53.7,ALPBIEN,2,ALPBI,0)),"^",3),1,2)'="IP"
QUIT
+109 DO DELORD^ALPBUTL(ALPBIEN,ALPBI)
End DoDot:2
End DoDot:1
+110 KILL ALPBI
+111 ;
+112 ; existing order's record number?...
+113 KILL ALPBOIEN
+114 SET ALPBOIEN=+$ORDER(^ALPB(53.7,ALPBIEN,2,"B",ALPBORDN,0))
+115 ; if this isn't a Med Log update, and this order is already on
+116 ; file, delete its drug(s), additive(s) and/or solution(s) --
+117 ; they will be rebuilt by the other segments in this message...
+118 IF +$GET(ALPBMLOG)=0&(ALPBOIEN>0)
DO CLORD^ALPBUTL2(ALPBIEN,ALPBOIEN)
+119 ; create new order record?...
+120 IF +$GET(ALPBOIEN)=0
Begin DoDot:1
+121 SET ALPBOIEN=+$ORDER(^ALPB(53.7,ALPBIEN,2," "),-1)+1
+122 SET ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",.01)=ALPBORDN
+123 ; don't file a 0 (zero) CPRS order number...
+124 IF ALPBORDC>0
SET ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",1)=ALPBORDC
+125 SET ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",3)=ALPBORDT
+126 SET ALPBFILE(53.702,"+"_ALPBOIEN_","_ALPBIEN_",",6)=ALPBOTYP
+127 DO UPDATE^DIE("","ALPBFILE","ALPBOIEN","ALPBFERR")
+128 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(ALPBIEN,"0",ALPBHREC,"NEWORD","",.ALPBFERR)
+129 KILL ALPBFERR,ALPBFILE
End DoDot:1
+130 ;
PM ; process the message segments...
+1 SET I=0
+2 FOR
SET I=$ORDER(ALPBMTXT(I))
IF 'I
QUIT
Begin DoDot:1
+3 SET ALPBDATA=ALPBMTXT(I)
+4 SET ALPBSEG=$PIECE(ALPBDATA,ALPBFS)
+5 ; allergies segment...
+6 IF ALPBSEG="AL1"
Begin DoDot:2
+7 DO AL1^ALPBHL1U(+$GET(ALPBIEN),$GET(ALPBDATA),$GET(ALPBFS),$GET(ALPBCS),.ALPBFERR)
+8 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"AL1",$GET(ALPBDATA),.ALPBFERR)
+9 KILL ALPBFERR
End DoDot:2
+10 ; general order segment...
+11 IF ALPBSEG="ORC"
Begin DoDot:2
+12 DO ORC^ALPBHL1U(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBDATA),$GET(ALPBMLOG),$GET(ALPBFS),$GET(ALPBCS),.ALPBFERR)
+13 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"ORC",$GET(ALPBDATA),.ALPBFERR)
+14 KILL ALPBFERR
End DoDot:2
+15 ; patient movement/location segment...
+16 IF ALPBSEG="PV1"
Begin DoDot:2
+17 DO PV1^ALPBHL1U(+$GET(ALPBIEN),$GET(ALPBDATA),$GET(ALPBFS),$GET(ALPBCS),.ALPBFERR)
+18 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"PV1",$GET(ALPBDATA),.ALPBFERR)
+19 KILL ALPBFERR
End DoDot:2
+20 ; IV orders segment...
+21 IF ALPBSEG="RXC"
Begin DoDot:2
+22 DO RXC^ALPBHL1U(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBDATA),$GET(ALPBFS),$GET(ALPBCS),.ALPBFERR)
+23 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"RXC",$GET(ALPBDATA),.ALPBFERR)
+24 KILL ALPBFERR
End DoDot:2
+25 ; drug, additives and/or solutions segment...
+26 IF ALPBSEG="RXE"
Begin DoDot:2
+27 IF $GET(ALPBDATA)=""
QUIT
+28 ; if this is a Pending order, check to see if a drug is included in this RXE seg. if not, let's try to add the one that may be in the RXO seg...
+29 IF +$PIECE($PIECE(ALPBDATA,ALPBFS,3),ALPBCS,4)=0
SET $PIECE(ALPBDATA,ALPBFS,3)=$PIECE($GET(ALPBMTXT("RXO")),ALPBFS,2)
+30 ;chech for any continuation lines
+31 SET J=0
FOR
SET J=$ORDER(ALPBMTXT(I,J))
IF 'J
QUIT
SET ALPBDATA=ALPBDATA_ALPBMTXT(I,J)
+32 DO RXE^ALPBHL1U(+$GET(ALPBIEN),+$GET(ALPBOIEN),ALPBDATA,$GET(ALPBFS),$GET(ALPBCS),$GET(ALPBECH),.ALPBFERR)
+33 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"RXE",ALPBDATA,.ALPBFERR)
+34 KILL ALPBFERR
End DoDot:2
+35 ; med route...
+36 IF ALPBSEG="RXR"
Begin DoDot:2
+37 DO RXR^ALPBHL1U(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBDATA),$GET(ALPBFS),$GET(ALPBCS),.ALBPFERR)
+38 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"RXR",$GET(ALPBDATA),.ALPBFERR)
+39 KILL ALPBFERR
End DoDot:2
+40 ; provider comments, special instructions or other print info...
+41 IF ALPBSEG="NTE"
Begin DoDot:2
+42 ; NTE segments can be multiple-lines. set up an array (ALPBNTE(...)) to pass to the filer...
+43 ; the first node will be the one that contains the NTE segment identifier
+44 SET ALPBNTE(1)=ALPBDATA
+45 SET ALPBX=1
+46 ; loop from ALPBMTXT(I) to retrieve any continuation lines...
+47 SET J=0
+48 FOR
SET J=$ORDER(ALPBMTXT(I,J))
IF 'J
QUIT
Begin DoDot:3
+49 SET ALPBX=ALPBX+1
+50 SET ALPBNTE(ALPBX)=ALPBMTXT(I,J)
End DoDot:3
+51 KILL ALPBX,J
+52 DO NTE^ALPBHL1U(+$GET(ALPBIEN),+$GET(ALPBOIEN),.ALPBNTE,$GET(ALPBFS),$GET(ALPBCS),.ALPBFERR)
+53 IF +$GET(ALPBFERR("DIERR"))
DO ERRLOG^ALPBUTL1(+$GET(ALPBIEN),+$GET(ALPBOIEN),$GET(ALPBHREC),"NTE",ALPBDATA,.ALPBFERR)
+54 KILL ALPBFERR,ALPBNTE
End DoDot:2
+55 KILL ALPBDATA,ALPBSEG
End DoDot:1
+56 ;
+57 ; set RECORD LAST UPDATED field...
+58 SET ALPBLUPD=$$NOW^XLFDT()
+59 IF $GET(^ALPB(53.7,+$GET(ALPBIEN),0))'=""
Begin DoDot:1
+60 SET ALPBFILE(53.7,ALPBIEN_",",7)=ALPBLUPD
+61 DO FILE^DIE("","ALPBFILE","ALPBFERR")
+62 KILL ALPBFERR,ALPBFILE
End DoDot:1
+63 ;
+64 ; update PARAMETER file with last update date...
+65 SET ALPBPARM=+$ORDER(^ALPB(53.71,0))
+66 IF ALPBPARM>0
Begin DoDot:1
+67 SET ALPBFILE(53.71,ALPBPARM_",",4)=ALPBLUPD
+68 DO FILE^DIE("","ALPBFILE","ALPBFERR")
+69 KILL ALPBFERR,ALPBFILE
End DoDot:1
+70 KILL ALPBLUPD,ALPBPARM
+71 ;
CLEAN KILL ALPBCS,ALPBDATA,ALPBECH,ALPBFS,ALPBHREC,ALPBIEN,ALPBMLOG,ALPBMTXT
+1 KILL ALPBOIEN,ALPBORDC,ALPBORDN,ALPBORDT,ALPBOTYP,ALPBPDFN,ALPBPDOB
+2 KILL ALPBPNAM,ALPBPSEX,ALPBPSSN,ALPBSEG
+3 QUIT