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

EDPLAB.m

Go to the documentation of this file.
  1. EDPLAB ;SLC/MKB - EDIS lab result utilities ; 9/1/22 9:27am
  1. ;;2.0;EMERGENCY DEPARTMENT;**6,20**;May 2, 2012;Build 7
  1. ;External reference ^ORX8 supported by DBIA 871
  1. ;
  1. EN(EDPRES,PARAM) ; -- Return lab results as XML in EDPRES
  1. ; Required: "patient" identifier (DFN)
  1. ; Optional: "start"-"stop" date range
  1. ; "total" - total number of accessions
  1. ; "list" - 1 for list of testID's only
  1. ; "testID"s for result history of test(s)
  1. ;
  1. K @EDPRES
  1. ;D ADD^EDPHIST("<results>")
  1. ;N ARRAY,EDPARR S ARRAY=$NA(EDPARR("results",1))
  1. N ARRAY,EDPARR S ARRAY=$NA(^TMP("EDPLAB",$J,"results",1)) K @ARRAY
  1. ;
  1. ;
  1. ; validate input parameters
  1. N DFN,TEST,TESTIDS,BEG,END,MAX,X,I,LIST,TSEQ,TIDT
  1. S DFN=+$$VAL("patient") I DFN<1 D G ENQ
  1. . ;D XML^EDPX("<error msg='Missing or invalid patient identifier' />")
  1. . S @ARRAY@("error",1,"msg")="Missing or invalid patient identifier"
  1. ;S I=0 F S I=$O(PARAM("testID",I)) Q:I<1 S X=+PARAM("testID",I),TEST(X)=""
  1. S TESTIDS=$$VAL("testID")
  1. I $L(TESTIDS) D
  1. .F I=1:1 S X=$P(TESTIDS,U,I) Q:'$L(X) D
  1. ..S TSEQ=$P(X,";"),TIDT=$P(X,";",2) Q:'TSEQ!('$L(TIDT))
  1. ..I X S TEST(TIDT,TSEQ)=""
  1. ;
  1. ; get optional date range, max# accessions
  1. S BEG=$$VAL("start"),END=$$VAL("stop"),MAX=$$VAL("total"),LIST=$$VAL("list")
  1. I BEG,END,END<BEG N X S X=BEG,BEG=END,END=X ;switch
  1. I END,$L(END,".")<2 S END=END_".24"
  1. ; search Lab for results
  1. N ACNT,ICNT,DONE,SUB,IDT,SEQ,MORE
  1. K ^TMP("LRRR",$J) D RR^LR7OR1(DFN,,BEG,END)
  1. S (ACNT,ICNT,DONE)=0
  1. S SUB="" F S SUB=$O(^TMP("LRRR",$J,DFN,SUB)) G:SUB="" ENQ D
  1. .; BWF 2/2/2012 - for now we are only returning CH (chemistry)
  1. .Q:SUB'="CH"
  1. .S IDT=0 F S IDT=$O(^TMP("LRRR",$J,DFN,SUB,IDT)) Q:IDT<1 D Q:DONE
  1. .. I $D(TEST) Q:'$D(TEST(IDT))
  1. .. S (MORE,SEQ)=0
  1. .. F S SEQ=$O(^TMP("LRRR",$J,DFN,SUB,IDT,SEQ)) Q:SEQ<1 S X=$G(^(SEQ)) D
  1. ... I $D(TEST) Q:'$D(TEST(IDT,SEQ))
  1. ... K EDPX
  1. ... I '$G(LIST) S EDPX("id")=SUB_";"_IDT_";"_SEQ
  1. ... S MORE=1
  1. ... D TMP(.EDPX,DFN,SUB,IDT,SEQ,LIST) ;parse into EDPX("att")=value
  1. ... S ICNT=ICNT+1 M @ARRAY@("item",ICNT)=EDPX
  1. ... ;D ADDA^EDPHIST("item",.EDPX)
  1. .. S:MORE ACNT=ACNT+1 I $G(MAX),ACNT'<MAX S DONE=1
  1. Q
  1. ;
  1. ENQ ;end
  1. D TOXMLG^EDPXML(ARRAY,EDPRES)
  1. Q
  1. ;
  1. ORD(EDPRES,PARAM) ; -- Return results history for lab orders
  1. K EDPRES ;D ADD^EDPHIST("<results>")
  1. D ADD^EDPHIST("<results>")
  1. N ARRAY,EDPARR S ARRAY=$NA(EDPARR("results",1))
  1. ;
  1. ; validate input parameters
  1. N DFN,LOG,IN,MAX
  1. S DFN=+$$VAL("patient") I DFN<1 D G ORQ
  1. . S @ARRAY@("error",1,"msg")="Missing or invalid patient identifier"
  1. S LOG=+$O(^EDP(230,"APA",DFN,0)),IN=$P($G(^EDP(230,LOG,0)),U,8)
  1. S MAX=$$VAL("total")
  1. ;
  1. K ^TMP("LRRR",$J) D RR^LR7OR1(DFN)
  1. ;
  1. ; get results for tests in each order
  1. N EDPI,ORIFN,EDPY,EDPTST,ORPK,SUB,IDT,SEQ,EDPX,X,ORUPCHUK
  1. S EDPI=0 F S EDPI=$O(PARAM("order",EDPI)) Q:EDPI<1 D
  1. . ; add order info
  1. . S ORIFN=+$G(PARAM("order",EDPI)) Q:ORIFN<1 K EDPX
  1. . S EDPX("id")=ORIFN,X=$$GET1^DIQ(100,ORIFN_",",5,"I")
  1. . S EDPX("statusId")=X,EDPX("statusName")=$$STATUS(X,ORIFN)
  1. . S X=$P($$OI^ORX8(ORIFN),U,2),EDPX("name")=$$ESC(X) ;if null?
  1. . D EN^ORX8(ORIFN)
  1. . S X=ORUPCHUK("ORSTRT")
  1. . I 'X S X=ORUPCHUK("ORODT")
  1. . S EDPX("collectedTS")=X,EDPX("ack")=$$ACK^EDPHIST(ORIFN)
  1. . M @ARRAY@("order",1)=EDPX
  1. . ;
  1. . ; add order results from visit
  1. . S ORPK=$$PKGID^ORX8(ORIFN) Q:$L(ORPK,";")'>3 ;no results
  1. . S SUB=$P(ORPK,";",4),IDT=$P(ORPK,";",5) K EDPTST
  1. . S SEQ=0 F S SEQ=$O(^TMP("LRRR",$J,DFN,SUB,IDT,SEQ)) Q:SEQ<1 D
  1. .. K EDPX S EDPX("id")=SUB_";"_IDT_";"_SEQ
  1. .. D TMP^EDPLAB(.EDPX,DFN,SUB,IDT,SEQ) ;parse into EDPX("att")=value
  1. .. M @ARRAY@("visit",1,"item",1)=EDPX
  1. .. S X=$G(EDPX("testID")) S:X EDPTST(X)=""
  1. . ;
  1. . ; add prior results of same tests [up to MAX# collections]
  1. . N ACNT,ICNT,DONE,MATCH S (ACNT,ICNT,DONE)=0
  1. . F S IDT=$O(^TMP("LRRR",$J,DFN,SUB,IDT)) Q:IDT<1 D Q:DONE
  1. .. S SEQ=0,MATCH=0
  1. .. F S SEQ=$O(^TMP("LRRR",$J,DFN,SUB,IDT,SEQ)) Q:SEQ<1 S X=$G(^(SEQ)) D
  1. ... Q:'$D(EDPTST(+X)) ;not a matching test
  1. ... K EDPX S EDPX("id")=SUB_";"_IDT_";"_SEQ,MATCH=1
  1. ... ;K EDPX S EDPX("id")="CH;"_IDT_";"_SEQ,MATCH=1
  1. ... ;D TMP^EDPLAB(.EDPX,DFN,"CH",IDT,SEQ) ;parse into EDPX("att")=value
  1. ... D TMP^EDPLAB(.EDPX,DFN,SUB,IDT,SEQ) ;parse into EDPX("att")=value
  1. ... S ICNT=ICNT+1 M @ARRAY@("history",1,"item",ICNT)=EDPX
  1. .. S:MATCH ACNT=ACNT+1 I $G(MAX),ACNT'<MAX S DONE=1
  1. ORQ ; end
  1. ;D ADD("</results>")
  1. D TOXML^EDPXML(.EDPARR,.EDPRES)
  1. Q
  1. ;
  1. VAL(X) Q $G(PARAM(X,1))
  1. ;
  1. ESC(X) ; -- escape outgoing XML
  1. ; Q $ZCONVERT(X,"O","HTML") ; uncomment for fastest performance on Cache
  1. ;
  1. N I,Y,QOT S QOT=""""
  1. S Y=$P(X,"&") F I=2:1:$L(X,"&") S Y=Y_"&"_$P(X,"&",I)
  1. S X=Y,Y=$P(X,"<") F I=2:1:$L(X,"<") S Y=Y_"<"_$P(X,"<",I)
  1. S X=Y,Y=$P(X,">") F I=2:1:$L(X,">") S Y=Y_">"_$P(X,">",I)
  1. S X=Y,Y=$P(X,"'") F I=2:1:$L(X,"'") S Y=Y_"'"_$P(X,"'",I)
  1. S X=Y,Y=$P(X,QOT) F I=2:1:$L(X,QOT) S Y=Y_"""_$P(X,QOT,I)
  1. Q Y
  1. ;
  1. STATUS(STS,ORDER) ; -- Return result status for ORDER status
  1. N Y,X
  1. S STS=+$G(STS),ORDER=+$G(ORDER)
  1. I STS=1 S Y="Order discontinued" D:ORDER ;look for reason
  1. . S X=$$GET1^DIQ(100,ORDER_",",65) S:'$L(X) X=$$GET1^DIQ(100,ORDER_",",64)
  1. . I $L(X) S Y=Y_" ("_X_")"
  1. I STS=2 S Y="Results"_$S($$ACKD^EDPHIST(ORDER):" acknowledged",1:" available")
  1. I STS=3 S Y="On hold"
  1. I STS=5 S Y="Order pending"
  1. I STS=6 S Y="Specimen in lab" ;"Active"
  1. I STS=7 S Y="Order expired"
  1. I STS=8 S Y="Scheduled"
  1. I STS=9 S Y="Partial results available"
  1. I STS=10!(STS=11) S Y="Order not released"
  1. I STS=12 S Y="Order discontinued (changed)"
  1. I STS=13 S Y="Order cancelled"
  1. I STS=14 S Y="Order discontinued (lapsed)"
  1. I STS=15 S Y="Order renewed"
  1. Q Y
  1. ;
  1. TMP(Y,DFN,SUB,IDT,SEQ,LIST) ; -- Return ^TMP("LRRR",$J,DFN,SUB,IDT,SEQ) data
  1. ; in Y("attribute")=value
  1. ; I SUB = MI or BB ??
  1. N X0,X,XC,FAC,ACK
  1. S X0=$G(^TMP("LRRR",$J,DFN,SUB,IDT,SEQ))
  1. ;
  1. ; BWF 2/2/2012 - Due to errors occuring on the client side when too much data
  1. ; is retrieved from this call, an initial call can now be made that will return
  1. ; a list of the available labs. The client side will then be able to call back in
  1. ; with a list of labs being requested in smaller chunks.
  1. ; If LIST is passed as '1', only pass back the list of testID's and collected date
  1. I $G(LIST) S Y("testID")=SEQ_";"_IDT Q
  1. ;
  1. S Y("subscript")=SUB,Y("accession")=SUB_";"_IDT
  1. ;S Y("collectedTS")=$$FMTHL7^XLFDT(9999999-IDT)
  1. S Y("collectedTS")=(9999999-IDT)
  1. ; BWF 6/14/13 - Added $$ESC for testName
  1. S Y("testID")=+X0,Y("testName")=$$ESC($P($G(^LAB(60,+X0,0)),U)),X=+$P($G(^(.1)),U,6)
  1. S Y("printOrder")=$S(X:+X,1:SEQ/1000000)
  1. S:$L($P(X0,U,2)) Y("result")=$P(X0,U,2)
  1. I $G(Y("result"))'="" D
  1. .I Y("result")["<" S Y("result")=$$ESC(Y("result"))
  1. .I Y("result")[">" S Y("result")=$$ESC(Y("result"))
  1. S:$L($P(X0,U,4)) Y("units")=$$ESC($P(X0,U,4))
  1. S:$L($P(X0,U,3)) Y("deviation")=$$ESC($P(X0,U,3))
  1. S X=$P(X0,U,5) I $L(X),X["-" S Y("low")=$$ESC($P(X,"-")),Y("high")=$$ESC($P(X,"-",2))
  1. S Y("printName")=$$ESC($P(X0,U,15))
  1. S Y("number")=$P(X0,U,16)
  1. S X=+$P(X0,U,19) D ;sample & specimen
  1. . N SPC,CS,LRDFN
  1. . S:X<1 LRDFN=+$G(^DPT(DFN,"LR")),X=+$P($G(^LR(LRDFN,SUB,IDT,0)),U,5)
  1. . S SPC=$G(^LAB(61,X,0)) Q:'$L(SPC)
  1. . S Y("specimen")=$P(SPC,U),CS=+$P(SPC,U,6)
  1. . S:CS Y("sample")=$P($G(^LAB(62,CS,0)),U)
  1. S X=+$P(X0,U,17),XC=$Q(^LRO(69,"C",X))
  1. I $P(XC,",",1,3)=("^LRO(69,""C"","_X) D ;get Lab Order info
  1. . N LRO,LR3
  1. . S LRO=$G(^LRO(69,+$P(XC,",",4),1,+$P(XC,",",5),0)),LR3=$G(^(3))
  1. . ;S X=+$P(LRO,U,6) S:X Y("provider")=X_U_$P($G(^VA(200,X,0)),U)
  1. . S X=+$P(LRO,U,11) ;S:X Y("order")=X
  1. . S ACK=$$ACK^EDPHIST(X,1)
  1. . ;S Y("ack")=$P(ACK,U),Y("ackdt")=$P(ACK,U,2)
  1. . ;S X=$P(LR3,U,2) S:X Y("resultedTS")=$$FMTHL7^XLFDT(X)
  1. . S X=$P(LR3,U,2) S:X Y("resultedTS")=(X)
  1. S FAC=$$SITE^VASITE S:FAC Y("stnNum")=$P(FAC,U,3),Y("stnName")=$P(FAC,U,2)
  1. ; bwf 12/21/2011 removed setting of 'comments' to bypass errors occuring with the parser on client side
  1. ;I $D(^TMP("LRRR",$J,DFN,SUB,IDT,"N")) D ;M Y("comment")=^("N")
  1. ;. N I S I=1,X=$G(^TMP("LRRR",$J,DFN,SUB,IDT,"N",I))
  1. ;. F S I=$O(^TMP("LRRR",$J,DFN,SUB,IDT,"N",I)) Q:I<1 S X=X_$C(13,10)_^(I)
  1. ;. S Y("comment")=$$ESC(X)
  1. Q