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

RAHLBMS.m

Go to the documentation of this file.
  1. RAHLBMS ;HIRMFO/REL,GJC-Bridge, MedSpeak compatible to HL7 v1.6 ;11/18/97 12:12
  1. ;;5.0;Radiology/Nuclear Medicine;**4**;Mar 16, 1998
  1. EN1 ; Build the ^TMP("RARPT-REC" global when we receive the
  1. ; message from HL7.
  1. S RASUB=HL("MID") K RAERR
  1. K ^TMP("RARPT-HL7",$J) ; clean area that holds data from HL7
  1. K ^TMP("RARPT-REC",$J,RASUB) ; kill storage area for new HL7 message id
  1. S ^TMP("RARPT-REC",$J,RASUB,"RADATE")=$$DT^XLFDT()
  1. S ^TMP("RARPT-REC",$J,RASUB,"VENDOR")="IBM/MEDSPEAK"
  1. F I=1:1 X HLNEXT Q:HLQUIT'>0 S ^TMP("RARPT-HL7",$J,I)=HLNODE,J=0 F S J=$O(HLNODE(J)) Q:'J S ^TMP("RARPT-HL7",$J,I,J)=HLNODE(J)
  1. S CNT=2,SEGMNT=$G(^TMP("RARPT-HL7",$J,CNT))
  1. PID ; Pick data off the 'PID' segment.
  1. I $P(SEGMNT,HL("FS"))="PID" D
  1. . S SEGMNT=$P(SEGMNT,HL("FS"),2,99999)
  1. . I $P($P(SEGMNT,HL("FS"),3),$E(HL("ECH")))]"" D
  1. .. S ^TMP("RARPT-REC",$J,RASUB,"RADFN")=$P($P(SEGMNT,HL("FS"),3),$E(HL("ECH")))
  1. .. Q
  1. . I $P(SEGMNT,HL("FS"),19)]"" D
  1. .. S ^TMP("RARPT-REC",$J,RASUB,"RASSN")=$P(SEGMNT,HL("FS"),19)
  1. .. Q
  1. . Q
  1. E S RAERR="Missing PID segment" D XIT Q
  1. ; Save off E-Sig information (if it exists)
  1. S:$D(HL("ESIG")) ^TMP("RARPT-REC",$J,RASUB,"RAESIG")=HL("ESIG")
  1. ;
  1. OBR ; Pick data off the 'OBR' segment.
  1. K SEGMNT F S CNT=$O(^TMP("RARPT-HL7",$J,CNT)) Q:CNT="" S SEGMNT=$G(^(CNT)) Q:$P(SEGMNT,HL("FS"))="OBR" ; find the 'OBR' segment
  1. I $P($G(SEGMNT),HL("FS"))'="OBR" S RAERR="Missing OBR segment" D XIT Q
  1. S SEGMNT=$P(SEGMNT,HL("FS"),2,99999)
  1. I $P(SEGMNT,HL("FS"),3)]"" D
  1. . N RADTCN S RADTCN=$P(SEGMNT,HL("FS"),3)
  1. . S:$P($P(RADTCN,$E(HL("ECH"))),"-")]"" ^TMP("RARPT-REC",$J,RASUB,"RADTI")=$P($P(RADTCN,$E(HL("ECH"))),"-")
  1. . S:$P($P(RADTCN,$E(HL("ECH"))),"-",2)]"" ^TMP("RARPT-REC",$J,RASUB,"RACNI")=$P($P(RADTCN,$E(HL("ECH"))),"-",2)
  1. . S:$P(RADTCN,$E(HL("ECH")),2)]"" ^TMP("RARPT-REC",$J,RASUB,"RALONGCN")=$P(RADTCN,$E(HL("ECH")),2)
  1. . Q
  1. S RAHLD=$$PCEXTR^RAHLO4(CNT,SEGMNT,25,HL("FS")) K RAHL70
  1. I RAHLD="" S RAERR="Missing Report Status" D XIT Q
  1. I "AFR"'[RAHLD S RAERR="Invalid Report Status" D XIT Q
  1. S ^TMP("RARPT-REC",$J,RASUB,"RASTAT")=RAHLD
  1. S RAHLD=$$PCEXTR^RAHLO4(CNT,SEGMNT,32,HL("FS")) K RAHL70
  1. I RAHLD']"" S RAERR="Missing Provider ID" D XIT Q
  1. S RAVERF=RAHLD
  1. ; ----- Check the validity of the provider name -----
  1. I '$D(^VA(200,"B",RAVERF)) D ; check for a partial match in file 200
  1. . D VFIER ; if one partial match found, return the entry ien
  1. . Q
  1. E D ; $D(^VA(200,"B",RAVERF)) true, get the entry ien
  1. . S RAVERF=$O(^VA(200,"B",RAVERF,0))
  1. . S:'RAVERF RAERR="Invalid Provider Name"
  1. . Q
  1. I $D(RAERR) D XIT Q
  1. ; can't get resident info from medspeak
  1. S ^TMP("RARPT-REC",$J,RASUB,"RAVERF")=RAVERF,^("RATRANSCRIPT")=RAVERF,^("RASTAFF")=RAVERF,^("RAWHOCHANGE")=RAVERF
  1. ;
  1. OBX ; Pick data off the 'OBX' segments
  1. K SEGMNT F S CNT=$O(^TMP("RARPT-HL7",$J,CNT)) Q:CNT="" S SEGMNT=$G(^(CNT)) D:$P(SEGMNT,HL("FS"))="OBX" Q:$D(RAERR)
  1. . S SEGMNT=$P(SEGMNT,HL("FS"),2,9999)
  1. . I $P(SEGMNT,HL("FS"),3)']"" S RAERR="Missing Observation Identifier" Q
  1. . S OBXTYP=$P(SEGMNT,HL("FS"),3),OBXTYP=$E(OBXTYP,$F(OBXTYP,"&")) S:OBXTYP="" OBXTYP=" "
  1. . I "IDR"'[OBXTYP S RAERR="Invalid Observation Identifier" Q
  1. . D RPT Q
  1. XIT ; Clean up environment, quit
  1. D INIT^HLFNC2("RA VOICE TCP SERVER RPT",.HL) ;field separators must be cleared and reset prior to sending ACK to prevent mixed/wrong separators in ACK
  1. I $D(RAERR) D GENACK G XIT1
  1. I $D(^TMP("RARPT-REC",$J)) D EN1^RAHLO I $D(RAERR) D GENACK
  1. XIT1 K ^TMP("RARPT-REC",$J) ; kill storage area for current HL7 message id
  1. K ^TMP("RARPT-HL7",$J) ; clean up HL7 storage
  1. K CNT,OBXTYPE,X1,LIN,RADATE,RADTCN,RAERR,RAESIG,RAHLD,RANODE,RARCNT
  1. K RAVERF,RASUB,SEGMNT
  1. Q
  1. RPT ; Save off Report Text data.
  1. S RANODE=$S(OBXTYP="D":"RADX",OBXTYP="I":"RAIMP",1:"RATXT"),LIN=""
  1. S X=$P(SEGMNT,HL("FS"),5) D PAR
  1. F J=0:0 S J=$O(^TMP("RARPT-HL7",$J,CNT,J)) Q:'J S X1=^(J),X=$E(X1,1,125) D PAR I $L(X1)>125 S X=$E(X1,126,999) D PAR
  1. I X=""!(LIN'="") S L=999 D P2
  1. Q
  1. PAR ; Build text paragraph
  1. S LIN=LIN_X
  1. P1 I $L(LIN)<80 Q
  1. F L=80:-1:1 Q:$E(LIN,L)=" "
  1. D P2 S LIN=$E(LIN,L+1,999) G P1
  1. P2 ; Set node
  1. S RARCNT(OBXTYP)=$G(RARCNT(OBXTYP))+1
  1. S ^TMP("RARPT-REC",$J,RASUB,RANODE,RARCNT(OBXTYP))=$E(LIN,1,L-1) Q
  1. ;
  1. GENACK ; Compile the 'ACK' segment, generate the 'ACK' message.
  1. S HLA("HLA",1)="MSA"_HL("FS")_$S($D(RAERR):"AR",1:"AA")_HL("FS")_HL("MID")_$S($D(RAERR):HL("FS")_RAERR,1:"")
  1. S HLEID=HL("EID"),HLEIDS=HL("EIDS"),HLARYTYP="LM",HLFORMAT=1,HLRESLTA=HL("MID")
  1. D GENACK^HLMA1(HLEID,HLMTIENS,HLEIDS,HLARYTYP,HLFORMAT,.HLRESTLA)
  1. Q
  1. VFIER ; Check if the RAVERF string is a partial match to an entry in file
  1. ; 200. If if is, check to see that is a partial match to only ONE
  1. ; active provider entry in file 200.
  1. I '$L(RAVERF) S RAERR="Missing Provider information" Q
  1. K RAVCNT,RAVIEN,RAVLGTH,RAVPS
  1. S RAVLGTH=$L(RAVERF) ; length of the RAVERF string
  1. S RAVCNT=0,RAVS1=RAVERF
  1. F S RAVS1=$O(^VA(200,"B",RAVS1)) Q:RAVS1=""!($E(RAVS1,1,RAVLGTH)'=RAVERF) D Q:RAVCNT>1
  1. . ; return subscripts that have the RAVERF string as the first
  1. . ; 1 - RAVLGTH chars of RAVS1
  1. . S RAVIEN=0
  1. . F S RAVIEN=$O(^VA(200,"B",RAVS1,RAVIEN)) Q:RAVIEN'>0 D Q:RAVCNT>1
  1. .. S RAVPS=$G(^VA(200,RAVIEN,"PS"))
  1. .. S:'$P(RAVPS,"^",4)!($P(RAVPS,"^",4)>DT) RAVCNT=RAVCNT+1
  1. .. I RAVCNT=1,('$D(RAVIEN(RAVCNT))#2) S RAVIEN(RAVCNT)=RAVIEN ; when
  1. .. ; we find the first active provider save the provider ien off
  1. .. ; in a local array.
  1. .. Q
  1. . Q
  1. I RAVCNT=0 S RAERR="Invalid Provider Name" Q ; partial match not found
  1. I RAVCNT>1 S RAERR="Non-Unique Provider Name" Q ; >1 partial match
  1. S RAVERF=$G(RAVIEN(1)) S:'RAVERF RAERR="Provider Name Entry Error"
  1. K RAVCNT,RAVIEN,RAVLGTH,RAVPS
  1. Q