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

BLRRLMUM.m

Go to the documentation of this file.
BLRRLMUM ; IHS/MSC/MKK - Reference Lab Meaningful Use Microbiology utilities  ; 22-Oct-2013 09:22 ; MKK
 ;;5.2;IHS LABORATORY;**1033**;NOV 1, 1997
 ;
LABSTOR(LRDFN,LRSS,LRIDT) ; Store incoming HL7 data into the Lab Data file
 NEW (DILOCKTM,DISYS,DT,DTIME,DUZ,IO,IOBS,IOF,IOM,ION,IOS,IOSL,IOST,IOT,IOXY,LRDFN,LRIDT,LRSS,U,XPARSYS,XQXFLG)
 ;
 D CHKITOUT
 ;
 S NOWDTIME=$$HTE^XLFDT($H,"2MZ")
 ;
 S LRUID=+$G(^LR(LRDFN,LRSS,LRIDT,"ORU"))          ; Get UID
 Q:LRUID<1
 ;
 S PIEN=$$SHL7SEGS^BLRRLMUU(LRUID)                 ; Store HL7 data in ^TMP
 Q:PIEN<1
 ;
 S ^LR(LRDFN,LRSS,LRIDT,"HL7")=PIEN_"^"            ; Store 62.49 IEN
 ;
 ; Store the various HL7 segments' data
 S SEG=""
 F  S SEG=$O(^TMP("BLRRLMUU",$J,LRUID,PIEN,SEG))  Q:SEG=""  D
 . S SEGIEN=0
 . F  S SEGIEN=$O(^TMP("BLRRLMUU",$J,LRUID,PIEN,SEG,SEGIEN))  Q:SEGIEN<1  D @SEG
 ;
 Q
 ;
MSH ; EP - Don't process anything in the MSH Segment
 Q
 ;
PID ; EP - Don't process anything in the PID Segment
 Q
 ;
OBR ; EP
 Q
 ;
OBX ; EP
 NEW ANSDTT,DATANAME,F60IEN,ORGANISM,ORGPTR,REFLAB,RLPTR,STATUS,STR,TESTNAME,TSTLOINC
 ;
 S STR=$G(^LAHM(62.49,PIEN,150,SEGIEN,0))
 ;
 S TSTLOINC=$P($P(STR,"|",4),"^")
 S TESTNAME=$P($P(STR,"|",4),"^",2)
 S ORIGTEXT=$P($P(STR,"|",4),"^",9)
 ;
 S F60IEN=+$$FIND1^DIC(60,,,ORIGTEXT_",")
 I F60IEN D     ; Store File 60 Pointer
 . K FDA
 . S FDA(63.061,"+1,"_LRIDT_","_LRDFN_",",.01)=F60IEN_"^"_$$GET1^DIQ(60,F60IEN,"NAME")
 . D UPDATE^DIE(,"FDA",,"ERRS")
 ;
 ; Reference Lab
 S RLPTR=$P($P(STR,"|",24),"^",10)
 I $L(RLPTR) D
 . S REFLAB=+$$FIND1^DIC(4,,,RLPTR,"D")
 . S:REFLAB ^LR(LRDFN,LRSS,LRIDT,"RF")=REFLAB
 ;
 ; Signing Physician
 S SIGNSTR=$P(STR,"|",26)
 S SIGNNPI=$P(SIGNSTR,"^")     ; NPI
 S SIGNPHY=$P(SIGNSTR,"^",2)_", "_$TR($P(SIGNSTR,"^",3,6),"^"," ") ; Name
 S SIGNPHY=$$TRIM^XLFSTR(SIGNPHY,"LR"," ")    ; Get rid of leading & trailing blanks
 ;
 ; IEN into 62.49
 S ^LR(LRDFN,LRSS,LRIDT,"HL7")=PIEN
 ;
 ; Organism
 S ORGANISM=$P(STR,"|",6)
 S ORSNOMED=$P(ORGANISM,"^")
 S ORGSEQ=+$P(STR,"|",5)
 ;
 Q:$L(ORGANISM)<1!(ORGSEQ<1)
 ;
 S ORGPTR=+$$FIND1^DIC(61.2,,"M",+ORGANISM)
 I ORGPTR D
 . D ^XBFMK
 . K IENS,FDA
 . S IENS(1)=ORGSEQ
 . S FDA(63.3,"+1,"_LRIDT_","_LRDFN_",",.01)=ORGPTR
 . ;
 . D UPDATE^DIE(,"FDA","IENS","ERRS")
 ;
 S UNITS=$P($P(STR,"|",7),"^")
 S:$L(UNITS) UNITS=$$GET1^DIQ(90475.3,UNITS,"I")
 ;
 S FLAG=$P(STR,"|",9)
 S STATUS=$P(STR,"|",12)
 S RELDATE=$$HL7TFM^XLFDT($P(STR,"|",15))
 ;
 K IENS,FDA
 S IENS=LRIDT_","_LRDFN_","
 S:$L(RELDATE) FDA(63.3,IENS,9999901)=RELDATE
 S FDA(63.3,IENS,9999902)=STATUS
 S FDA(63.3,IENS,9999903)=FLAG
 S:$L(UNITS) FDA(63.3,IENS,9999905)=UNITS
 ;
 D UPDATE^DIE(,"FDA","IENS","ERRS")
 ;
 ; Performing Hospital
 S HOSPITAL=$P(STR,"|",24)
 S ADDRESS=$P(STR,"|",25)
 S ADDRL1=$P(ADDRESS,"^"),ADDRL2=$P(ADDRESS,"^",2)
 S CITY=$P(ADDRESS,"^",3),STATE=$P(ADDRESS,"^",4),ZIPCODE=$P(ADDRESS,"^",5)
 S COUNTY=$P(ADDRESS,"^",5),COUNTRY=$P(ADDRESS,"^",6)
 ;
 ; Performing Provider?
 S PERFHMDS=$P(STR,"|",26)
 S MDID=$P(PERFHMDS,"^")
 S MDNAME=$$TRIM^XLFSTR($P(PERFHMDS,"^",2)_","_$P(PERFHMDS,"^",3)_" "_$P(PERFHMDS,"^",4),"LR"," ")
 ;
 ; Get IEN into COUNTRY CODE (#779.004) file
 S ICOUNTRY=0
 I $L(COUNTRY) D
 . D FIND^DIC(779.004,,,,COUNTRY,,,,,"TARGET","ERRS")
 . S ICOUNTRY=+$O(TARGET("DILIST",2,0))
 ;
 Q:$L(COUNTY)<1&(ICOUNTRY<1)
 ;
 K FDA
 S:$L(COUNTY) FDA(63.05,IENS,9999996)=COUNTY
 S:ICOUNTRY FDA(63.05,IENS,9999997)=ICOUNTRY
 D UPDATE^DIE(,"FDA","IENS","ERRS")
 ;
 Q
 ;
ORC ; EP
 Q
 ;
SPM ; EP
 Q
 ;
CHKITOUT ; EP - Determine if data exists in ^LAH
 NEW AUTOINSP,LA7INST,LRAA,LRAD,LRAN,LRAS,LRIFN,LRLL,LRUID,NOWDTIME
 ;
 S NOWDTIME=$$HTE^XLFDT($H,"2MZ")
 ;
 S LA7INST=$$GET1^DIQ(9009029,DUZ(2),3001)
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"01","LA7INST")=LA7INST
 ;
 Q:$L(LA7INST)<1                              ; Quit if no Reference Lab
 ;
 S AUTOINSP=+$O(^LAB(62.4,"B",LA7INST,""))    ; Auto Instrument IEN
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"02,","AUTOINSP")=AUTOINSP
 ;
 Q:AUTOINSP<1                                 ; Quit if No Auto Instrument
 ;
 S LRLL=$$GET1^DIQ(62.4,AUTOINSP,3,"I")       ; LOAD/WORK LIST
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"03,","LRLL")=LRLL
 ;
 S LRUID=+$G(^LR(LRDFN,LRSS,LRIDT,"ORU"))     ; Get UID
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"04,","LRUID")=LRUID
 ;
 S LRIFN=$O(^LAH(LRLL,1,"U",LRUID,0))
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"05,","LRIFN")=LRIFN
 ;
 Q:LRIFN<1                                    ; Quit if no data in ^LAH for the LRUID
 ;
 Q:'$D(^LAH(LRLL,1,LRIFN,0))#2                ; Quit if no data in ^LAH for the LRIFN
 ;
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"06","LRIFN")=LRIFN
 S ^XTMP("BLRRLMUM",NOWDTIME,$J,"07","LRUID")=LRUID
 Q
 ;
LABIHSMS(LRAA,LRAD,LRAN) ; EP - After LAMIAUT0 Verification, move IHS Subnodes to proper nodes in Lab Data file
 NEW (DILOCKTM,DISYS,DT,DTIME,DUZ,IO,IOBS,IOF,IOM,ION,IOS,IOSL,IOST,IOT,IOXY,LRAA,LRAD,LRAN,U,XPARSYS,XQXFLG)
 ;
 S LRDFN=+$G(^LRO(68,LRAA,1,LRAD,1,LRAN,0)),LRIDT=$P($G(^(3)),"^",5),LRSS="MI"
 ;
 D LABSTOR(LRDFN,LRSS,LRIDT)
 D MAKEANTI
 D MAKEOIHS
 ;
 Q
 ;
MAKEANTI ; EP - Create new ANTIMICROBIAL SUSCEPTIBILITY nodes
 S ORGIEN=.9999999
 F  S ORGIEN=$O(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN))  Q:ORGIEN<1  D
 . Q:$D(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,"IHSOBX"))<1
 . ;
 . S ORGSTR=$G(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,"IHSOBX"))
 . S ANTI1=0
 . F  S ANTI1=$O(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,"ISO",ANTI1))  Q:ANTI1<1  D
 .. S ANTI(ANTI1)=$G(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,"ISO",ANTI1))
 .. S ANTI(ANTI1)=$G(ANTI(ANTI1))_$G(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,"ISO","IHSOBX",ANTI1))
 . ;
 . S ORGANISM=$G(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,0))
 . S ANTI1=0
 . F  S ANTI1=$O(ANTI(ANTI1))  Q:ANTI1<1  D
 .. S ANTISTR=$G(ANTI(ANTI1))
 .. S DRUGNODE=$P(ANTISTR,"^",2)
 .. S DRUGRES=$P(ANTISTR,"^",3)
 .. S DRUGUNIT=$P($P(ANTISTR,"^",4),"~")
 .. S DRUGSUSP=$P(ANTISTR,"^",5)
 .. S DRUGSUSP=$S($L(DRUGSUSP):DRUGSUSP,1:"S")
 .. S DRUGSTAT=$P(ANTISTR,"^",6)
 .. S DRUGDATE=$P(ANTISTR,"^",7)
 .. S DRUGREFL=$P(ANTISTR,"^",8)
 .. S DRUGNIEN=+$O(^LAB(62.06,"AD",DRUGNODE,0))
 .. S DRUGNAME=$$GET1^DIQ(62.06,DRUGNIEN,"NAME")
 .. ;
 .. D MAKE14
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE),"^")=DRUGSUSP
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE,"IHS"),"^")=DRUGRES    ; Result
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE,"IHS"),"^",2)=DRUGUNIT ; Units
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE,"IHS"),"^",3)=DRUGSTAT ; Status
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE,"IHS"),"^",4)=DRUGDATE ; Date/Time
 .. S $P(^LR(LRDFN,LRSS,LRIDT,3,ORGIEN,DRUGNODE,"IHS"),"^",5)=DRUGREFL ; Referring Lab
 ;
 Q
 ;
MAKE14 ; EP - Make node 14, IFF drug not already there
 NEW FDA,FOUNDIT,IEN,IENARRAY,ERRS,DRUGS
 ;
 S (DRUGS,FOUNDIT)=0
 F  S DRUGS=$O(^LR(LRDFN,LRSS,LRIDT,14,DRUGS))  Q:DRUGS<1!(FOUNDIT)  D
 . S:$G(^LR(LRDFN,LRSS,LRIDT,14,DRUGS,0))[DRUGNAME FOUNDIT=FOUNDIT+1
 Q:FOUNDIT
 ;
 S FDA(63.42,"?+1,"_LRIDT_","_LRDFN_",",.01)=DRUGNAME
 S FDA(63.42,"?+1,"_LRIDT_","_LRDFN_",",2)=DRUGRES
 S FDA(63.42,"?+1,"_LRIDT_","_LRDFN_",",9999990)=DRUGDATE
 S FDA(63.42,"?+1,"_LRIDT_","_LRDFN_",",9999991)=DRUGREFL
 D UPDATE^DIE("S","FDA",,"ERRS")
 ;
 Q:$D(ERRS)<1
 ;
 ; Record Error
 S HNOW=$H
 S ^XTMP("BLRRLMUM")=$$HTFM^XLFDT(+$H+30)_"^"_$$DT^XLFDT_"^ERR UPDATING LAB MICRO RESULT"
 M ^XTMP("BLRRLMUM",HNOW,"MAKE14","01 FDA")=FDA
 M ^XTMP("BLRRLMUM",HNOW,"MAKE14","02 ERRS")=ERRS
 Q
 ;
MAKEOIHS ; EP - Stuff "other" fields with IHS Data
 S IENS=LRAN_","_LRAD_","_LRAA_","
 S LRAS=$$GET1^DIQ(68.02,IENS,15)             ; Get Accession Number
 S LRUID=+$$GET1^DIQ(68.02,IENS,16)           ; Get UID
 Q:LRUID<1
 ;
 S PIEN=$$SHL7SEGS^BLRRLMUU(LRUID)            ; Get UID pointer to 62.49
 ;
 D UPDLTXNL
 Q
 ;
UPDLTXNL ; EP - Update IHS Lab Transaction Log file
 S BLRLOGDA=+$$FIND1^DIC(9009022,,"M",LRAS)   ; Get 9009022 IEN
 Q:BLRLOGDA<1
 ;
 K FDA,ERRS
 S FDA(9009022,BLRLOGDA_",",102)="R"          ; Set to "Resulted"
 D UPDATE^DIE("S","FDA",,"ERRS")
 ;
 I $D(ERRS)<1 D TOP^BLRQUE(BLRLOGDA,0)  Q     ; If no errors, Requeue Txn to be re-filed into PCC
 ;
 ; Record Error
 S HNOW=$H
 S ^XTMP("BLRRLMUM")=$$HTFM^XLFDT(+$H+30)_"^"_$$DT^XLFDT_"^ERR UPDATING LAB MICRO RESULT"
 M ^XTMP("BLRRLMUM",HNOW,"MAKEOIHS","01 FDA")=FDA
 M ^XTMP("BLRRLMUM",HNOW,"MAKEOIHS","02 ERRS")=ERRS
 Q
 ;
TESTANTI ; EP
 NEW (DILOCKTM,DISYS,DT,DTIME,DUZ,IO,IOBS,IOF,IOM,ION,IOS,IOSL,IOST,IOT,IOXY,LRDFN,LRIDT,LRSS,U,XPARSYS,XQXFLG)
 ;
 D ^LRWU4
 W !!
 ;
 S LRDFN=+$G(^LRO(68,LRAA,1,LRAD,1,LRAN,0)),LRIDT=$P($G(^(3)),"^",5)
 S LRSS=$$GET1^DIQ(68,LRAA,.02,"I")
 ;
 D MAKEANTI
 Q