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

LA7CQRY1.m

Go to the documentation of this file.
LA7CQRY1 ;VA/DALOI/JMC - Lab HL7 Query Utility ; 11-Apr-2014 13:52 ; MAW
 ;;5.2;AUTOMATED LAB INSTRUMENTS;**46,61,1027,68,1033**;NOV 1, 1997
 ;
 ;;VA Patches:  46,61,68     ;Sep 27, 1994;Build 56
 ;
 ; Reference to ADM^VADPT2 supported by DBIA #325
 ; Reference to BLDPID^VAFCQRY supported by DBIA #3630
 Q
 ;
CHKSC ; Check search NLT/LOINC codes
 ;
 N J
 ;
 S J=0
 F  S J=$O(LA7SCDE(J)) Q:'J  D
 . N X
 . S X=LA7SCDE(J)
 . I $P(X,"^",2)="NLT",$D(^LAM("E",$P(X,"^"))) D  Q
 . . S ^TMP("LA7-NLT",$J,$P(X,"^"))=""
 . I $P(X,"^",2)="LN",$D(^LAB(95.3,$P($P(X,"^"),"-"))) D  Q
 . . S ^TMP("LA7-LN",$J,$P($P(X,"^"),"-"))=""
 . S LA7QERR(6)="Unknown search code "_$P(X,"^")_" passed"
 . K LA7SCDE(J)
 Q
 ;
 ;
SPEC ; Convert HL7 Specimen Codes to File #61, Topography codes
 ; Find all topographies that use this HL7 specimen code
 N J,K,L
 ;
 S J=0
 F  S J=$O(LA7SPEC(J)) Q:'J  D
 . S K=LA7SPEC(J),L=0
 . F  S L=$O(^LAB(61,"HL7",K,L)) Q:'L  S ^TMP("LA7-61",$J,L)=""
 Q
 ;
 ;
BUILDMSG ; Build HL7 message with result of query
 ;
 I $G(LA7NOMSG)=1 N HL,HLECH,HLFS,HLQ,LA7ECH,LA7FS,LA7MSH
 N LA,LA763,LA7ID,LA7NTESN,LA7NVAF,LA7OBRSN,LA7OBXSN,LA7PIDSN,LA7QUIT,LA7ROOT,LA7X,LRIDT,LRPOC,LRSS,X
 N LA7SITE,LA7FAC,LA7VER,LA7CCNT
 ;
 ; Create dummy MSH to pass HL7 delimiters
 S LA7SITE=$O(^BLRRLMU("B",DUZ(2),0))
 S LA7FAC=$P($G(^DIC(4,DUZ(2),0)),U)
 S LA7VER=$P($G(^BLRRLMU(LA7SITE,0)),U,2)
 I $G(LA7NOMSG)=1 D
 . I $L($G(LA7HL7))'=5 S LA7HL7="|^\~&"
 . S (HL("FS"),HLFS,LA7FS)=$E(LA7HL7),(HL("ECH"),HLECH,LA7ECH)=$E(LA7HL7,2,5)
 . S (HLQ,HL("Q"))=""
 . S LA7MSH(0)=$$MSH^LA7CHDR(LA7FS,LA7ECH,LA7SITE)
 . D FILESEG^LA7VHLU(GBL,.LA7MSH)
 I '$G(LA7INPT) D
 .S LA7SFT(0)=$$SFT(LA7FS,LA7ECH,LA7SITE)  ;MU2 sft segment
 .D FILE6249^LA7VHLU(LA76249,.LA7SFT)
 .D FILESEG^LA7VHLU(GBL,.LA7SFT)  ;add to the message
 ;
 F X="AUTO-INST","LRDFN","LRIDT","SUB","HUID","NLT","RUID","SITE" S LA(X)=""
 ;
 ; Find POC user to identify those specimens that are POC.
 S LRPOC=$$FIND1^DIC(200,"","OX","LRLAB,POC","B","")
 ;
 S LA7CCNT=0
 ; Take search results and put in HL7 message structure
 S LA7ROOT="^TMP(""LA7-QRY"",$J)",(LA7QUIT,LA7PIDSN)=0,LA7ID="LA7QRY-O-"
 F  S LA7ROOT=$Q(@LA7ROOT) Q:LA7ROOT=""  D  Q:LA7QUIT
 . S LA7CCNT=LA7CCNT+1
 . I $QS(LA7ROOT,1)'="LA7-QRY"!($QS(LA7ROOT,2)'=$J) S LA7QUIT=1 Q
 . ;MU2 added code below because of panel
 . ; I LA7CCNT=1 D
 . ;. D PAT
 . ;. S PIDNTE(0)=$$PIDNTE(LA7FS,LA7ECH,DFN)  ;MU2 pid nte segment
 . ;. I $G(PIDNTE(0))]"" D
 . ;.. D FILE6249^LA7VHLU(LA76249,.PIDNTE)
 . ;.. D FILESEG^LA7VHLU(GBL,.PIDNTE)
 . ;. S NK1(0)=$$NK1(LA7FS,LA7ECH,DFN)  ;MU2 nk1 segment
 . ;. I $G(NK1(0))]"" D
 . ;.. D FILE6249^LA7VHLU(LA76249,.NK1)
 . ;.. D FILESEG^LA7VHLU(GBL,.NK1)
 . ;. D ORC
 . ; D OBX
 . ; I $G(LRSS)="CH" D
 . ; . S SPM(0)=$$SPM^LA7CORU(LA7FS,LA7ECH,LA7UID)
 . ; . D FILE6249^LA7VHLU(LA76249,.SPM)
 . ; . D FILESEG^LA7VHLU(GBL,.SPM)
 . ; D OBXAAO(LA7FS,LA7ECH,LA7UID,LRDFN,LRIDT)  ;MU2 ask at order questions
 . ; maw put below back in when done with those segments
 . ; S LA7SPM(0)=$$SPM^LA7CORU()
 . ; D FILESEG^LA7VHLU(GBL,.LA7SPM)
 . I LA("LRDFN")'=$QS(LA7ROOT,3) D
 .. D PAT
 .. S PIDNTE(0)=$$PIDNTE(LA7FS,LA7ECH,DFN)  ;MU2 pid nte segment
 .. I $G(PIDNTE(0))]"" D
 ... D FILE6249^LA7VHLU(LA76249,.PIDNTE)
 ... D FILESEG^LA7VHLU(GBL,.PIDNTE)
 .. I '$G(LA7INPT) S NK1(0)=$$NK1(LA7FS,LA7ECH,DFN)  ;MU2 nk1 segment
 .. I $G(NK1(0))]"" D
 ... D FILE6249^LA7VHLU(LA76249,.NK1)
 ... D FILESEG^LA7VHLU(GBL,.NK1)
 . I LA("LRIDT")'=$QS(LA7ROOT,4) D
 .. I $G(LA7INTYP)=30,$G(LA7OBRSN) D
 ... D PAT
 ... S PIDNTE(0)=$$PIDNTE(LA7FS,LA7ECH,DFN)  ;MU2 pid nte segment
 ... I $G(PIDNTE(0))]"" D
 .... D FILE6249^LA7VHLU(LA76249,.PIDNTE)
 .... D FILESEG^LA7VHLU(GBL,.PIDNTE)
 ... I '$G(LA7INPT) S NK1(0)=$$NK1(LA7FS,LA7ECH,DFN)  ;MU2 nk1 segment
 ... I $G(NK1(0))]"" D
 .... D FILE6249^LA7VHLU(LA76249,.NK1)
 .... D FILESEG^LA7VHLU(GBL,.NK1)
 .. I '$G(LA7INPT) D ORC
 . I LA("SUB")'=$QS(LA7ROOT,5) D
 .. I $G(LA7INTYP)=30,$G(LA7OBRSN) D
 ... D PAT
 ... I '$G(LA7INPT) S PIDNTE(0)=$$PIDNTE(LA7FS,LA7ECH,DFN)  ;MU2 pid nte segment
 ... I $G(PIDNTE(0))]"" D
 .... D FILE6249^LA7VHLU(LA76249,.PIDNTE)
 .... D FILESEG^LA7VHLU(GBL,.PIDNTE)
 ... I '$G(LA7INPT) S NK1(0)=$$NK1(LA7FS,LA7ECH,DFN)  ;MU2 nk1 segment
 ... I $G(NK1(0))]"" D
 .... D FILE6249^LA7VHLU(LA76249,.NK1)
 .... D FILESEG^LA7VHLU(GBL,.NK1)
 .. D ORC
 . I LA("NLT")'=$P($QS(LA7ROOT,6),"!") D ORC
 . D OBX
 I $G(LRSS)="CH" D
 . I $G(LA7INPT),$G(LA7ADDON) Q  ;mu2 inpatient
 . S SPM(0)=$$SPM^LA7CORU(LA7FS,LA7ECH,LA7UID)
 . D FILE6249^LA7VHLU(LA76249,.SPM)
 . D FILESEG^LA7VHLU(GBL,.SPM)
 D OBXAAO(LA7FS,LA7ECH,LA7UID,LRDFN,LRIDT)  ;MU2 ask at order questions
 Q
 ;
 ;
SFT(FS,ECH,SITE) ;-- return the SFT segment
 N SFT,CS,RS,SC,SFTA
 S CS=$E(ECH,1,1)
 S RS=$E(ECH,2,2)
 S SC=$E(ECH,4,4)
 F I=1:1:6 S SFT(I)=""
 S SFTA=$G(^BLRRLMU(SITE,"SFT"))
 S SFT="SFT"
 S SFT(1)=$$SFT1^LA7MUSFT(CS,SC,SFTA)
 S SFT(2)=$$SFT2^LA7MUSFT(SFTA)
 S SFT(3)=$$SFT3^LA7MUSFT(SFTA)
 S SFT(4)=$$SFT4^LA7MUSFT(SFTA)
 S SFT(6)=$$SFT6^LA7MUSFT(SFTA)
 F J=1:1:6 S $P(SFT,FS,J+1)=SFT(J)
 Q SFT
 ;
PID(FS,ECH,LDFN,DF) ;return the pid segment
 N I,J,CS,RS,FAC,AL,MMN,MLNM,MFNM,MMI,MSFX,MPRX,MPSFX,M2,ADD1,ADD2,PH1,PH2,ETH,EDA
 S FAC=$P($G(^DIC(4,DUZ(2),0)),U)
 S CS=$E(ECH,1,1)
 S RS=$E(ECH,2,2)
 S SC=$E(ECH,4,4)
 F I=1:1:39 S PID(I)=""
 S PID="PID"
 S LRDFN=LDFN,DFN=DF
 D DEM^LRX
 S AL=$P($G(^DPT(DF,.01,1,0)),U)  ;MU2 get one alias
 S PID(1)=1
 S PID(3)=$$PID3^LA7MUPID(CS,RS,SC,DFN,SSN)
 S PID(5)=$$PID5^LA7MUPID(CS,RS,AL)
 S PID(6)=$$PID6^LA7MUPID(CS,DFN)
 S PID(7)=$$PID7^LA7MUPID()
 S PID(8)=$$PID8^LA7MUPID()
 S PID(10)=$$PID10^LA7MUPID(CS)
 S PID(11)=$$PID11^LA7MUPID(CS,DFN)
 S PID(13)=$$PID13^LA7MUPID(CS,DFN)
 S PID(14)=$$PID14^LA7MUPID(CS,DFN)
 S EDA=$O(^DPT(DF,.06,"B",0))
 I EDA S ETH=$P($G(^DPT(DF,.06,EDA,0)),U)
 I $G(ETH) S PID(22)=$$PID22^LA7MUPID(CS,DFN,ETH,LA7SITE)
 S PID(29)=$$PID29^LA7MUPID(DFN)
 S PID(30)=$$PID30^LA7MUPID(DFN)
 S PID(33)=$$PID33^LA7MUPID(DFN)
 S PID(34)=$$PID34^LA7MUPID(CS,LA7FAC)
 I '$G(LA7INPT) S PID(35)=$$PID35^LA7MUPID(CS,LA7SITE)
 F J=1:1:39 S $P(PID,FS,J+1)=PID(J)
 Q PID
 ;
PAT ; Build PID/PV1 segments
 N LA7PID,LA7PV1
 S (LA("LRDFN"),LRDFN)=$QS(LA7ROOT,3)
 S LRDPF=$P(^LR(LRDFN,0),"^",2),DFN=$P(^(0),"^",3)
 S LA7PID(0)=$$PID(LA7FS,LA7ECH,LRDFN,DFN)
 D FILESEG^LA7VHLU(GBL,.LA7PID)
 I '$G(LA7NOMSG),$G(LA76249) D FILE6249^LA7VHLU(LA76249,.LA7PID)
 S (LA7OBRSN,LA7OBXSN,LA7NTESN)=0,(LA("LRIDT"),LA("SUB"))=""
 Q
 ;
 ;
PIDNTE(FS,ECH,DF) ;build the PID NTE segment
 Q:'$D(^AUPNPAT(DF,14,0)) ""
 N PDA,REM,CS,RS,SC,NTE,CNT
 S CS=$E(ECH,1,1)
 S RS=$E(ECH,2,2)
 S SC=$E(ECH,3,3)
 F I=1:1:8 S NTE(I)=""
 S NTE="NTE"
 S REM=""
 S CNT=0
 S PDA=0 F  S PDA=$O(^AUPNPAT(DF,14,PDA)) Q:'PDA  D
 . S REM=REM_$G(^AUPNPAT(DF,14,PDA,0))
 . S CNT=CNT+1
 . I CNT>1 S REM=REM_" "
 S NTE(1)=1
 S NTE(2)="P"
 S NTE(3)=$G(REM)
 S NTE(4)="RE"_CS_"Remark"_CS_"HL70364"_CS_"C"_CS_"Comment"_CS_"L"_CS_LA7VER_CS_"1.0"
 F J=1:1:8 S $P(NTE,FS,J+1)=NTE(J)
 Q NTE
 ;
NK1(FS,ECH,DF) ; build the NK1 segment
 N FLAG
 S FLAG=""
 I $D(^DPT(DF,.21)) S FLAG=1
 I $D(^DPT(DF,.291)) S FLAG=1
 I '$G(FLAG) Q ""
 N DATA,REM,CS,RS,SC,NK1,MMN,MLNM,M2,MFNM,MMI,MSFX,MPRX,MPSFX,RES,RELI,RLHL
 S CS=$E(ECH,1,1)
 S RS=$E(ECH,2,2)
 S SC=$E(ECH,4,4)
 F I=1:1:39 S NK1(I)=""
 S DATA=$G(^DPT(DF,.21))
 S NK1="NK1"
 S NK1(1)=1
 I $G(DATA)]"" D
 . S NK1(2)=$$NK12^LA7MUNK1(CS,DATA)
 . S NK1(3)=$$NK13^LA7MUNK1(CS,DF,DATA)
 . S NK1(4)=$$NK14^LA7MUNK1(CS,DF,DATA)
 . S NK1(5)=$$NK15^LA7MUNK1(CS,DF,DATA)
 S NK1(13)=$$NK113^LA7MUNK1(CS,DF,SC)
 S NK1(30)=$$NK130^LA7MUNK1(CS,DF)
 S NK1(31)=$$NK131^LA7MUNK1(CS,DF)
 S NK1(32)=$$NK132^LA7MUNK1(CS,DF)
 F J=1:1:39 S $P(NK1,FS,J+1)=NK1(J)
 Q NK1
 ;
PV1MU2(FS,ECH,DF) ;-- build the MU2 PV1 segment
 N PV1
 F I=1:1:52 S PV1(I)=""
 S PV1="PV1"
 S PV1(1)=1
 S PV1(2)=$S($G(^DPT(DF,.1))]"":"I",1:"O")
 S PV1(4)="C"
 S PV1(44)=$$FMTHL7^XLFDT($P($G(LA763(0)),U))  ;admit date
 S PV1(45)=$$FMTHL7^XLFDT($P($G(LA763(0)),U,3))  ;discharge date
 F J=1:1:52 S $P(PV1,FS,J+1)=PV1(J)
 Q PV1
 ;
ORC ; Build ORC segment
 ;
 N LA764,LA7NLT,LRNMSP,X
 ;
 S (LA("LRIDT"),LRIDT)=$QS(LA7ROOT,4),(LA("SUB"),LRSS)=$QS(LA7ROOT,5)
 S LA763(0)=$G(^LR(LA("LRDFN"),LA("SUB"),LA("LRIDT"),0))
 S X=$G(^LR(LA("LRDFN"),LA("SUB"),LA("LRIDT"),"ORU"))
 S LA("HUID")=$P(X,"^"),LRNMSP="LR"
 I LA("HUID")="" S LA("HUID")=$P(LA763(0),"^",6)
 S LA("HUID","NMSP")=LRNMSP
 I "CHMI"[LA("SUB") S LA("HUID","SITE")=$P(LA763(0),"^",14)
 E  S LA("HUID","SITE")=""
 ;
 I '$G(LA7UID) S LA7UID=$G(LA("HUID"))
 S LA("RUID")=$P(X,"^",5),LRNMSP="LR"
 I LRPOC,LRPOC=$P(X,"^",4) S LRNMSP="LRPOC"
 S LA("RUID","NMSP")=LRNMSP
 S LA("RUID","SITE")=$P(X,"^",3)
 I LA("RUID")="" D
 . S LA("RUID")=LA("HUID")
 . S LA("RUID","NMSP")=LA("HUID","NMSP")
 . S LA("RUID","SITE")=LA("HUID","SITE")
 ;
 S LA("SITE")=$P(X,"^",2)
 S LA7NVAF=$$NVAF^LA7VHLU2(0),LA7NTESN=0
 ;
 S (LA("NLT"),LA7NLT)=$P($QS(LA7ROOT,6),"!"),(LA764,LA("ORD"))=""
 I LA7NLT'="" D
 . S LA764=+$O(^LAM("E",LA7NLT,0))
 . I LA764 S LA("ORD")=$$GET1^DIQ(64,LA764_",",.01)
 ;
 I '$G(LA7INPT) D
 .S PV1(0)=$$PV1MU2(LA7FS,LA7ECH,DFN)
 .D FILE6249^LA7VHLU(LA76249,.PV1)
 .D FILESEG^LA7VHLU(GBL,.PV1)
 D ORC^LA7CORU,OBR
 ;
 Q
 ;
 ;
OBR ; Build OBR segment
 ;
 N LA7RS
 ;
 I LA("SUB")="CH" D
 . D OBR^LA7CORU
 . I $G(LA7INPT),$G(LA7ADDON) S LA7OBXSN=0 Q  ;mu2 inpatient
 . D NTE^LA7CORU
 . I $G(LA7INPT),$G(LA7REJ) Q  ;mu2 inpatient
 . S TQ1(0)=$$TQ1^LA7CORU(LA7FS,LA7ECH,LA7UID,LRDFN,LRIDT)
 . D FILE6249^LA7VHLU(LA76249,.TQ1)
 . D FILESEG^LA7VHLU(GBL,.TQ1)
 . S LA7OBXSN=0
 ;
 Q
 ;
 ;
OBX ; Build OBX segment
 ;
 N LA7DATA,LA7VT
 ;
 S LA7NTESN=0
 I LA("SUB")="MI" D MI^LA7CORU1 Q
 ; I "CYEMSP"[LA("SUB") D AP^LA7CORU2 Q
 ;
 S LA7VT=$QS(LA7ROOT,7)
 I $G(LA7INPT),$$ADDON(LA7VT) D
 . S SPM(0)=$$SPM^LA7CORU(LA7FS,LA7ECH,LA7UID)
 . D FILE6249^LA7VHLU(LA76249,.SPM)
 . D FILESEG^LA7VHLU(GBL,.SPM)
 . S LA7ORCSN=1
 . S LA7ORCSN=LA7ORCSN+1
 . D ORC
 D OBX^LA7COBX(LA("LRDFN"),LA("SUB"),LA("LRIDT"),LA7VT,.LA7DATA,.LA7OBXSN,LA7FS,LA7ECH)
 I '$D(LA7DATA) Q
 D FILESEG^LA7VHLU(GBL,.LA7DATA)
 I '$G(LA7NOMSG),$G(LA76249) D FILE6249^LA7VHLU(LA76249,.LA7DATA)
 ; Send any test interpretation from file #60
 D INTRP^LA7CORUA
 ;
 ; Mark result as sent - set to 1, if corrected results set to 2
 I LA("SUB")="CH" D
 . I $P(^LR(LA("LRDFN"),LA("SUB"),LA("LRIDT"),$P(LA7VT,"^")),"^",10)>1 Q
 . S $P(^LR(LA("LRDFN"),LA("SUB"),LA("LRIDT"),$P(LA7VT,"^")),"^",10)=$S($P(LA7VT,"^",2)="C":2,1:1)
 ;
 Q
 ;
 ;
ADDON(TST) ;-- check to see if this was an addon
 N TSTIEN,ORD,ROOT,DAT,NODE,ADDON
 S ADDON=0
 S TSTIEN=$O(^LAB(60,"C","CH;"_TST_";1",0))
 I 'TSTIEN Q ADDON
 S ORD=$G(^LRO(68,LRAA,1,LRAD,1,LRAN,.1))
 I 'ORD Q 0
 S ROOT=$Q(^LRO(69,"C",ORD))
 S DAT=$QS(ROOT,4)
 S NODE=$QS(ROOT,5)
 N NDA
 S NDA=0 F  S NDA=$O(^LRO(69,DAT,1,NODE,2,NDA)) Q:'NDA  D
 . Q:$P($G(^LRO(69,DAT,1,NODE,2,NDA,0)),U)'=TSTIEN
 . I $G(^LRO(69,DAT,1,NODE,2,NDA,1,1,0))["Added" S LA7ADDON=$P($G(^LRO(69,DAT,1,NODE,2,2,0)),U),ADDON=1
 Q ADDON
 ;
PV1 ; Build PV1 segment for HDR
 N LA7DT,LA7PCE,LA7SDENC,LRDX,LRIDT,LRSS,LRUID,VADMVT,VAINDT
 S LRIDT=$QS(LA7ROOT,4),LRSS=$QS(LA7ROOT,5),LA7DT=0
 I LRIDT,LRSS'="" S LA7DT=$P($G(^LR(LRDFN,LRSS,LRIDT,0)),"^")
 I 'LA7DT Q
 ;
 S LRDX=""
 ; Determine if an inpatient at time of specimen and build inpatient PV1.
 S VAINDT=LA7DT D ADM^VADPT2
 I VADMVT S LA7PV1(0)=$$IN^VAFHLPV1(DFN,LA7DT,",3,6,7,10,18,21,36,39,44,45,",VADMVT,"",1,LRDX)
 ;
 ; If not an inpatient then build outpatient PV1.
 I 'VADMVT D
 . N LA7VPTR
 . S LA7PCE=$$PCENC^LA7VHLU3(LRDFN,LRSS,LRIDT),LA7VPTR=""
 . I LA7PCE'="" D
 . . S LA7SDENC=$$SDENC^LA7VHLU3(LA7PCE)
 . . I LA7SDENC'="" S LA7VPTR=LA7SDENC_";SCE("
 . I LA7VPTR="" S LA7VPTR=DFN_";DPT("
 . ; S LA7PV1(0)=$$OUT^VAFHLPV1(DFN,"",LA7DT,LA7VPTR,"A",1)
 . S:$D(^VAT(391.71)) LA7PV1(0)=$$OUT^VAFHLPV1(DFN,"",LA7DT,LA7VPTR,"A",1)     ; IHS/MSC/MKK - LR*5.2*1032 - Only Call if ADT/HL7 PIVOT file exists
 ;
 D FILESEG^LA7VHLU(GBL,.LA7PV1)
 I '$G(LA7NOMSG),$G(LA76249) D FILE6249^LA7VHLU(LA76249,.LA7PV1)
 Q
 ;
OBXAAO(FS,ECH,ACC,LDFN,LIDT)  ;-build the OBX ask at order questions
 N ROI
 S ROI=$O(^BLRRLO("ACC",ACC,0))
 Q:'ROI
 N CS,RS,SC,RDA,OBX,OBY
 S CS=$E(ECH,1,1)
 S RS=$E(ECH,2,2)
 S SC=$E(ECH,3,3)
 F I=1:1:25 S OBY(I)=""
 S RDA=0 F  S RDA=$O(^BLRRLO(ROI,4,RDA)) Q:'RDA  D
 . Q:$P($G(^BLRRLO(ROI,4,RDA,0)),U,3)="SPM5"
 . Q:$P($G(^BLRRLO(ROI,4,RDA,0)),U,3)="SPM9"
 . S OBX(0)="OBX"
 . S OBY(1)=1
 . S OBY(2)="SN"
 . S OBY(3)=$$OBX3^LA7MUOBX(CS,ACC,ROI,RDA)
 . S OBY(5)=$$OBX5^LA7MUOBX(CS,ACC,ROI,RDA)
 . S OBY(6)=$$OBX6^LA7MUOBX(CS)
 . S OBY(11)="F"
 . S OBY(14)=$$FMTHL7^XLFDT($P($G(^LR(LDFN,LRSS,LIDT,0)),U))
 . S OBY(18)=$$FMTHL7^XLFDT($P($G(^LR(LDFN,LRSS,LIDT,0)),U))
 . S OBY(19)=$$FMTHL7^XLFDT($S($P($G(LA763(0)),U):$P($G(LA763(0)),U),1:DT))
 . S OBY(23)=$$OBX23^LA7COBX(4,DUZ(2),LA7FS,LA7ECH)
 . S $P(OBY(23),$E(LA7ECH,1),6)="CLIA"_$E(LA7ECH,4)_"2.16.840.1.113883.4.7"_$E(LA7ECH,4)_"ISO"
 . S $P(OBY(23),$E(LA7ECH,1),7)="XX"
 . S $P(OBY(23),$E(LA7ECH,1),10)=$P($G(^DIC(4,DUZ(2),99)),U)
 . S OBY(24)=$$OBX24^LA7COBX(4,DUZ(2),DT,LA7FS,LA7ECH)
 . S $P(OBY(24),$E(LA7ECH),6)="USA"
 . S $P(OBY(24),$E(LA7ECH),7)="L"
 . S $P(OBY(24),$E(LA7ECH),9)=$$LZERO^LA7MUPID($P(OBY(24),$E(LA7ECH),5),5)  ;MU2 county code same as zip for now
 . S OBY(25)=$$OBX25^LA7COBX($$GET1^DIQ(9009029,DUZ(2),3027,"I"),DUZ(2),LA7FS,LA7ECH)
 . S $P(OBY(25),$E(LA7ECH),9)="NPI"_$E(LA7ECH,4)_"2.16.840.1.113883.4.6"_$E(LA7ECH,4)_"ISO"
 . S $P(OBY(25),$E(LA7ECH),10)="L"
 . S $P(OBY(25),$E(LA7ECH),13)="NPI"
 . S $P(OBY(25),$E(LA7ECH),14)="NPI_Facility"_$E(LA7ECH,4)_"2.16.840.1.113883.3.72.5.26"_$E(LA7ECH,4)_"ISO"
 . S $P(OBY(25),$E(LA7ECH),21)=$P(OBY(25),$E(LA7ECH),6)
 . F J=1:1:25 S $P(OBX(0),FS,J+1)=OBY(J)
 . D FILE6249^LA7VHLU(LA76249,.OBX)
 . D FILESEG^LA7VHLU(GBL,.OBX)
 Q
 ;
LOOKTAB(TYPE,TAB,VAL,ECH) ;-- find the value and description in the HL7 tables
 N DESC,IENI,GBL
 S GBL="^BHLTBL"
 I TYPE="" S GBL="^BHLOTBL"
 S IENI=$O(@GBL@("AVAL",TAB,VAL,0))
 Q:'IENI
 S DESC=$P($G(@GBL@(IENI,0)),U,3)
 Q VAL_ECH_DESC_ECH_TYPE_TAB
 ;
LOOKDSC(TYPE,TAB,DSC,ECH) ;-- find a reverse value based on description
 N VAL,IENI,GBL
 S GBL="^BHLOTBL"
 I TYPE="" S GBL="^BHLOTBL"
 S IENI=$O(@GBL@("ADSC",TAB,DSC,0))
 Q:'IENI
 S VAL=$P($G(@GBL@(IENI,0)),U,2)
 Q VAL_ECH_ECH_TYPE_TAB