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

ALPBHL1U.m

Go to the documentation of this file.
  1. ALPBHL1U ;OIFO-DALLAS MW,SED,KC -HL7 MESSAGE SEGMENT PARSER AND UPDATE ;2/6/21 15:41
  1. ;;3.0;BAR CODE MED ADMIN;**7,69,59,73,87,127,108,129**;May 2002;Build 16
  1. ;
  1. ; passed parameters common to all functions:
  1. ; IEN = patient's internal entry number in file 53.7
  1. ; OIEN = the order number's internal entry number in file 53.7
  1. ; DATA = the HL7 message line
  1. ; FS = the HL7 field separator character (e.g., "|" or "^")
  1. ; CS = the HL7 component separator character (e.g., "~")
  1. ; ECH = the HL7 encoding characters
  1. ; ERR = an array passed by reference, returned containing
  1. ; FileMan DBS call error array (if any)
  1. ;
  1. ;*69 - A New NTE segment will now contain WP unlimited text. This
  1. ; text will also contain formatted text escape character \.br\
  1. ; NTE tag will now rebuild work arrays honoring the line break
  1. ; escape character prior to storing into BCMA BACKUP DATA #53.7.
  1. ;**73- Add Clinic name to Order multiple for orders that were placed
  1. ; in a clinic vs. a Ward.
  1. ;*87 - Add Remove logic to pull out new fields and store to DB
  1. ;*108- add ZZZ segment for Hazardous drug flags
  1. ;
  1. AL1(IEN,DATA,FS,CS,ERR) ; process AL1 (allergies) segment...
  1. I +$G(IEN)'>0!($G(DATA)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("AL1","",.ERR) Q
  1. N ALPBALG,ALPBALGN,ALPBFILE,ALPBNEXT,ALPBSCHD,ALPBX,SCS,ALPBXX,ALPBSCHDLE1,ALPBX2,ALPBYY
  1. S ALPBALG=+$P(DATA,FS,4)
  1. I ALPBALG'>0 D ERRBLD^ALPBUTL1("AL1","Undefined allergy "_DATA,.ERR) Q
  1. S ALPBALGN=$P($P(DATA,FS,4),CS,2)
  1. ; is this allergy already on file for this patient?...
  1. I $D(^ALPB(53.7,IEN,1,"B",ALPBALG)) S ERR("DIERR")=0 Q
  1. ; if not, file it...
  1. S ALPBNEXT=+$O(^ALPB(53.7,IEN,1," "),-1)+1
  1. S ALPBFILE(53.701,"+"_ALPBNEXT_","_IEN_",",.01)=ALPBALG
  1. S ALPBFILE(53.701,"+"_ALPBNEXT_","_IEN_",",1)=ALPBALGN
  1. D UPDATE^DIE("","ALPBFILE","ALPBNEXT","ERR")
  1. Q
  1. ;
  1. ORC(IEN,OIEN,DATA,MLOG,FS,CS,ERR) ; process ORC (common order) segment...
  1. ; MLOG = if 1 then this is an ORC segment with a Med Log update
  1. ; if 0 then this is a common order update
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(MLOG)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("ORC","",.ERR) Q
  1. N ALPBFIEN,ALPBFILE,ALPBMREC,ALPBNEXT,ALPBTEXT,ALPBX,SVZERO ;*87
  1. S ALPBFIEN=OIEN_","_IEN_","
  1. ; ORC segment with NO MedLog data...
  1. I +MLOG=0 D
  1. .S ALPBX=$P(DATA,FS,1)
  1. .; order status...
  1. .S ALPBFILE(53.702,ALPBFIEN,2)=$P(DATA,FS,6)
  1. .; provider...
  1. .S ALPBFILE(53.702,ALPBFIEN,5)=$P($P(DATA,FS,13),CS,2)
  1. .; entry person/rph...
  1. .S ALPBFILE(53.702,ALPBFIEN,5.1)=$P($P(DATA,FS,11),CS,2)
  1. .; verified by...
  1. .S ALPBFILE(53.702,ALPBFIEN,5.2)=$P($P(DATA,FS,12),CS,2)
  1. .; set clinic name in new DD field 3.5 if a clinic order ;*73
  1. .S ALPBFILE(53.702,ALPBFIEN,3.5)=$P(DATA,FS,22)
  1. .D UPDATE^DIE("","ALPBFILE","","ERR")
  1. .; if this is a pending order, add special instructions...
  1. .I $P($P(DATA,FS,6),CS,1)="IP" D
  1. ..S ALPBTEXT(1)="CAUTION! THIS IS A PENDING ORDER :: CHECK WITH PROVIDER OR PHARMACIST!"
  1. ..D WP^DIE(53.702,ALPBFIEN,8,"A","ALPBTEXT","ERR")
  1. ..K ALPBTEXT
  1. ; ORC segment with specific MedLog data...
  1. I +MLOG=1 D
  1. .; ALPBX = med log date/time...
  1. .S ALPBX=$$FMDATE^HLFNC($P(DATA,FS,10))
  1. .I ALPBX="" K ALPBX Q
  1. .; ALPBMREC = med log record number...
  1. .S ALPBMREC=+$P($P(DATA,FS,3),CS,1)
  1. .;
  1. .;UPDATE, If the med log entry is already on file, update and quit.
  1. .; check for both an entry on file for the log date/time ("B" xref)
  1. .; or med log record number ("C" xref)...
  1. .S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,10,"B",ALPBX,""),-1)
  1. .I ALPBNEXT'>0 S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,10,"C",ALPBMREC,""))
  1. .I ALPBNEXT>0 D Q
  1. ..S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,.01)=ALPBX
  1. ..S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,1)=$P($P(DATA,FS,11),CS,2)
  1. ..S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,2)=$P($P(DATA,FS,6),CS,2)
  1. ..I ALPBMREC>0 S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,3)=ALPBMREC
  1. ..;if remove status, save associated Given info for storing *87
  1. ..D:$P($P(DATA,FS,6),CS,2)["REMOVE"
  1. ...S SVZERO=$G(^ALPB(53.7,IEN,2,OIEN,10,ALPBNEXT,0))
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,4)=$P(SVZERO,U,1)
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,5)=$P(SVZERO,U,2)
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,6)=$P(SVZERO,U,3)
  1. ..;if Given cur action, then always set assoc Give fields to null *87
  1. ..D:$P($P(DATA,FS,6),CS,2)["GIVEN"
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,4)=""
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,5)=""
  1. ...S ALPBFILE(53.70213,ALPBNEXT_","_ALPBFIEN,6)=""
  1. ..;
  1. ..D UPDATE^DIE("","ALPBFILE","","ERR")
  1. .K ALPBNEXT
  1. .;
  1. .;ADD, If not...
  1. .S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,10," "),-1) ;bug fix *87
  1. .S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,.01)=ALPBX
  1. .; med log entry person...
  1. .S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,1)=$P($P(DATA,FS,11),CS,2)
  1. .; med log transaction message...
  1. .S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,2)=$P($P(DATA,FS,6),CS,2)
  1. .; med log record number...
  1. .I ALPBMREC>0 S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,3)=ALPBMREC
  1. .;if Given cur action, then always init assoc. fields to null *87
  1. .D:$P($P(DATA,FS,6),CS,2)["GIVEN"
  1. ..S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,4)=""
  1. ..S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,5)=""
  1. ..S ALPBFILE(53.70213,"+"_ALPBNEXT_","_ALPBFIEN,6)=""
  1. .;
  1. .D UPDATE^DIE("","ALPBFILE","ALPBNEXT","ERR")
  1. Q
  1. ;
  1. PV1(IEN,DATA,FS,CS,ERR) ; process PV1 (patient visit/movement) segment...
  1. I +$G(IEN)=0!($G(DATA)="") D ERRBLD^ALPBUTL1("PV1","",.ERR) Q
  1. N ALPBFIEN,ALPBFILE,ALPBX
  1. S ALPBFIEN=IEN_","
  1. S ALPBX=$P(DATA,FS,4)
  1. ; ward...
  1. S ALPBFILE(53.7,ALPBFIEN,4)=$P(ALPBX,CS)
  1. ; room...
  1. S ALPBFILE(53.7,ALPBFIEN,5)=$P(ALPBX,CS,2)
  1. ; bed...
  1. S ALPBFILE(53.7,ALPBFIEN,6)=$P(ALPBX,CS,3)
  1. D FILE^DIE("","ALPBFILE","ERR")
  1. Q
  1. ;
  1. RXO(IEN,OIEN,DATA,FS,CS,ERR) ; process RXO (pharmacy prescription order) segment...
  1. ; for inpatient meds, this segment contains an orderable item. this
  1. ; module is ONLY called if the order is "P"ending. it only files the
  1. ; orderable item if no drug is on file for the order.
  1. N ALPBDIEN,ALPBDRUG,ALPBFILE,ALPBNEXT
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("RXO","",.ERR) Q
  1. S ALPBDIEN=+$P($P(DATA,FS,2),CS,4)
  1. S ALPBDRUG=$P($P(DATA,FS,2),CS,5)
  1. I ALPBDIEN'>0 D ERRBLD^ALPBUTL1("RXO","Invalid drug IEN in RXO segment",.ERR) Q
  1. ; if there is ANY drug already on file, quit...
  1. I +$O(^ALPB(53.7,IEN,2,OIEN,7,0))>0 Q
  1. ; if not, file it...
  1. S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,7," "),-1)+1
  1. S ALPBFILE(53.703,"+"_ALPBNEXT_","_OIEN_","_IEN_",",.01)=ALPBDIEN
  1. S ALPBFILE(53.703,"+"_ALPBNEXT_","_OIEN_","_IEN_",",1)=ALPBDRUG
  1. D UPDATE^DIE("","ALPBFILE","ALPBNEXT","ERR")
  1. Q
  1. ;
  1. RXE(IEN,OIEN,DATA,FS,CS,ECH,ERR) ; process RXE (order detail) segment...
  1. ; this segment may contain the drug name, though there may not be a drug
  1. ; because this can also be used for order detail for IV's which are
  1. ; contained in an RXC segment. this segment can also contain start/stop
  1. ; date&time, dosage and schedule
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(FS)="")!($G(CS)="")!($G(ECH)="") D ERRBLD^ALPBUTL1("RXE","",.ERR) Q
  1. N ALPBDIEN,ALPBDRUG,ALPBFIEN,ALPBFILE,ALPBNEXT,ALPBSCHD,ALPBX,SCS
  1. N ALPBDOA,ALPBREMV,ALPBTIMG,ALPBADM ;*87
  1. S SCS=$E(ECH,4)
  1. S ALPBFIEN=OIEN_","_IEN_","
  1. ; for drug, we'll use the one that came from the Drug file...
  1. S ALPBDIEN=+$P($P(DATA,FS,3),CS,4)
  1. S ALPBDRUG=$P($P(DATA,FS,3),CS,5)
  1. ; is this drug already on file for this order? if not, add it...
  1. I ALPBDIEN>0&('$D(^ALPB(53.7,IEN,2,OIEN,7,"B",ALPBDIEN))) D
  1. .S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,7," "),-1)+1
  1. .S ALPBFILE(53.703,"+"_ALPBNEXT_","_ALPBFIEN,.01)=ALPBDIEN
  1. .S ALPBFILE(53.703,"+"_ALPBNEXT_","_ALPBFIEN,1)=ALPBDRUG
  1. .D UPDATE^DIE("","ALPBFILE","ALPBNEXT","ERR")
  1. .K ALPBFERR,ALPBFILE,ALPBNEXT
  1. S ALPBX=$P(DATA,FS,2)
  1. ; start date/time...
  1. S ALPBFILE(53.702,ALPBFIEN,4)=$$FMDATE^HLFNC($P(ALPBX,CS,4))
  1. ; stop date/time...
  1. S ALPBFILE(53.702,ALPBFIEN,4.1)=$$FMDATE^HLFNC($P(ALPBX,CS,5))
  1. ; dosage...
  1. S ALPBFILE(53.702,ALPBFIEN,7)=$P(ALPBX,CS,8)
  1. ; schedule... alter getting directly from RXE.1.2 pieces ;*87
  1. S ALPBTIMG=$P(ALPBX,CS,2)
  1. S ALPBSCHD=$$UNESC^ALPBGEN($P(ALPBTIMG,SCS,1))
  1. S ALPBREMV=$P(ALPBTIMG,SCS,3)
  1. S ALPBDOA=$P(ALPBTIMG,SCS,4)
  1. ; end ;*87
  1. I $P(DATA,FS,24)'="" S ALPBSCHD=ALPBSCHD_" "_$P(DATA,FS,24)
  1. I $P($P(DATA,FS,25),CS,5)'="" S ALPBSCHD=ALPBSCHD_" "_$P($P(DATA,FS,25),CS,5)
  1. S ALPBFILE(53.702,ALPBFIEN,7.2)=ALPBSCHD
  1. ; timing...
  1. ;convert adm & rem times to 4 digit, store them & DOA to 53.7 *87
  1. S ALPBADM=$P($P(DATA,FS,22),CS,2)
  1. S:+ALPBADM ALPBADM=$$CNVRT4(ALPBADM,"-")
  1. S:+ALPBREMV ALPBREMV=$$CNVRT4(ALPBREMV,"-")
  1. S ALPBFILE(53.702,ALPBFIEN,7.3)=ALPBADM
  1. S ALPBFILE(53.702,ALPBFIEN,7.4)=ALPBREMV
  1. S ALPBFILE(53.702,ALPBFIEN,7.5)=ALPBDOA
  1. ;
  1. D UPDATE^DIE("","ALPBFILE","","ERR")
  1. Q
  1. ;
  1. RXR(IEN,OIEN,DATA,FS,CS,ERR) ; process RXR (med administration route) segment...
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("RXR","",.ERR) Q
  1. N ALPBFILE
  1. ; route...
  1. S ALPBFILE(53.702,OIEN_","_IEN_",",7.1)=$P($P(DATA,FS,2),CS,5)
  1. D UPDATE^DIE("","ALPBFILE","","ERR")
  1. Q
  1. ;
  1. RXC(IEN,OIEN,DATA,FS,CS,ERR) ; process RXC (IV orders: additives/solutions) segment...
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("RXC","",.ERR) Q
  1. N ALPBFILE,ALPBFNOD,ALPBGNOD,ALPBNAM,ALPBNEXT,ALPBNUM,ALPBTYP,ALPBUNIT
  1. S ALPBTYP=$P(DATA,FS,2)
  1. S ALPBGNOD=$S(ALPBTYP="A":8,ALPBTYP="B":9,1:0)
  1. I ALPBGNOD=0 D ERRBLD^ALPBUTL1("RXC","Unable to determine Additive or Solution in RXC segment",.ERR) Q
  1. S ALPBFNOD="53.7021"_$S(ALPBGNOD=8:1,1:2)
  1. S ALPBNUM=$P($P(DATA,FS,3),CS,4)
  1. ; is this additive or solution already on file?...
  1. I $D(^ALPB(53.7,IEN,2,OIEN,ALPBGNOD,"B",ALPBNUM)) S ERR("DIERR")=0 Q
  1. ; if not, file it...
  1. S ALPBNAM=$P($P(DATA,FS,3),CS,5)
  1. S ALPBUNIT=$P(DATA,FS,4)_$P($P(DATA,FS,5),CS,5)
  1. S ALPBNEXT=+$O(^ALPB(53.7,IEN,2,OIEN,ALPBGNOD," "),-1)+1
  1. S ALPBFILE(ALPBFNOD,"+"_ALPBNEXT_","_OIEN_","_IEN_",",.01)=ALPBNUM
  1. S ALPBFILE(ALPBFNOD,"+"_ALPBNEXT_","_OIEN_","_IEN_",",1)=ALPBNAM
  1. S ALPBFILE(ALPBFNOD,"+"_ALPBNEXT_","_OIEN_","_IEN_",",2)=ALPBUNIT
  1. D UPDATE^DIE("","ALPBFILE","ALPBNEXT","ERR")
  1. Q
  1. ;
  1. NTE(IEN,OIEN,DATA,FS,CS,ERR) ; process NTE (note) segment...
  1. ; note: in the case of NTE segments, DATA is passed in as an array.
  1. ; NTE data can be in multiple nodes, the first subscript of which
  1. ; contains the actual NTE segments itself.
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($D(DATA)=0)!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("NTE","",.ERR) Q
  1. N ALPBFILE,I
  1. ; check the status of this order. if it is pending, abort
  1. ; and do not file any special comments (note ORC module comments)...
  1. I $E($P($G(^ALPB(53.7,IEN,2,OIEN,0)),"^",3),1,2)="IP" Q
  1. ; examine DATA(1) and from the Pharmacy package code in the second
  1. ; field, insert a header at the first subscript level of our working
  1. ; array (which we will pass to the FileMan call)...
  1. S ALPBFILE(1)=$S($P(DATA(1),FS,2)=6:"Provider Comments:",$P(DATA(1),FS,2)=21:"Special Instructions:",1:"Other Info:")
  1. ;
  1. ;*69 Rebuild the WP Instructions from the formatted NTE segment.
  1. ; The NTE text will be put into the DATA array and can contain
  1. ; the escape character \.br\ for line break. The line break will
  1. ; allow this routine to store the WP text exactly how the Rph
  1. ; keyed it in IM backdoor. They may have keyed in hard returns
  1. ; and spaces, so to create an aligned columnar table, i.e.
  1. ; an Insulin sliding scale.
  1. S DATA(1)=$P(DATA(1),FS,4) ;reset DATA(1) from piece 4 of DATA(1)
  1. ;
  1. ; Unwrap DATA array into one large field, 64k is limit
  1. N ALEN,DLEN,ELEN,QUIT,ALLTXT,NEWALPB
  1. S QUIT=0,ALLTXT=""
  1. ;
  1. ; Put formatted NTE array together as one line up to 64k
  1. F I=0:0 S I=$O(DATA(I)) Q:'I D Q:QUIT
  1. .S ALEN=$L(ALLTXT),DLEN=$L(DATA(I))
  1. .I ALEN+DLEN>65536 S ELEN=65536-ALEN S ALLTXT=ALLTXT_$E(DATA(I),1,ELEN) S QUIT=1 Q
  1. .S ALLTXT=ALLTXT_DATA(I)
  1. ;
  1. ; Build new work array from the formatted lines of the large field
  1. D HL7FMT(ALLTXT,.NEWALPB)
  1. ;
  1. ; Now add back to the text of the new working array into the original
  1. ; work array beginning with element 2, as element 1 has the heading
  1. ; 129 Added condition to check if Other Info and get P4 on line 1
  1. ; ex. line 1(NEWALPB)has NTE^21^L^TEST order for ZZTEST patient
  1. ; the rest does not had NTE^21^L segment so get the whole piece
  1. ;
  1. I ALPBFILE(1)="Other Info:" F I=0:0 S I=$O(NEWALPB(I)) Q:'I D
  1. . I I=1 S ALPBFILE(I+1)=$P(NEWALPB(I),"^",4)
  1. . I I>1 S ALPBFILE(I+1)=NEWALPB(I)
  1. I ALPBFILE(1)'="Other Info:" F I=0:0 S I=$O(NEWALPB(I)) Q:'I S ALPBFILE(I+1)=NEWALPB(I)
  1. ;
  1. ; Store new WP text to field 8
  1. D WP^DIE(53.702,OIEN_","_IEN_",",8,"","ALPBFILE","ERR")
  1. Q
  1. ;
  1. ZZZ(IEN,OIEN,DATA,FS,CS,ERR) ; process Hazardous Drug flags segment *108
  1. I +$G(IEN)'>0!(+$G(OIEN)'>0)!($G(DATA)="")!($G(FS)="")!($G(CS)="") D ERRBLD^ALPBUTL1("ORC","",.ERR) Q
  1. N ALPBFIEN,ALPBFILE
  1. S ALPBFIEN=OIEN_","_IEN_","
  1. S ALPBFILE(53.702,ALPBFIEN,14)=$S($P(DATA,FS,5)="Y":1,1:0) ;HAZ Handle
  1. S ALPBFILE(53.702,ALPBFIEN,15)=$S($P(DATA,FS,6)="Y":1,1:0) ;HAZ Dispose
  1. D UPDATE^DIE("","ALPBFILE","","ERR")
  1. Q
  1. ;
  1. HL7FMT(NEWLN,AR) ;Unwrap formatted text array lines into a new array
  1. ; the escape character, \.br\ ,will cause a new array element to
  1. ; begin with the text after the escape character.
  1. N ESC,LIN,LN,QUIT,I
  1. S QUIT=0
  1. F I=1:1 S LN=NEWLN D Q:QUIT
  1. . S ESC=$F(LN,"\.br\")
  1. . I ESC=6 S LIN="",NEWLN=$E(LN,ESC,65536) S AR(I)=LIN Q
  1. . I ESC=0 S LIN=NEWLN,NEWLN="" S AR(I)=LIN,QUIT=1 Q
  1. . S LIN=$E(LN,1,ESC-6)
  1. . S NEWLN=$E(LN,ESC,65536)
  1. . S AR(I)=LIN
  1. Q
  1. ;
  1. CNVRT4(STR,SEP) ;Converts a time string to 4 digit for consistency
  1. ; STR - string of times
  1. ; SEP - seperator character between times
  1. ;
  1. N QQ
  1. F QQ=1:1:$L(STR,SEP) S $P(STR,SEP,QQ)=$E($P(STR,SEP,QQ)_"0000",1,4)
  1. Q STR