LRPXAPI ;SLC/STAFF Lab Extract APIs ;2/26/04 13:34
;;5.2;LAB SERVICE;**295**;Sep 27, 1994
;
; lab extract API routines
; dbia 4245
; no need to namespace local variables when calling these APIs
; the LRPXAPP routine shows examples of calling these APIs
; parameters: (.parameter is a call by reference)
; .TESTS array(ien)=ien^test name
; .VALUES array(seq of recent first)=col date/time^TEST^comment flag^RESULT
; .PATS array(dfn)=dfn^patient name
; .DATES array(-date)=date
; DFN is patient ien
; MAX is optional, # of tests,values,pts to return/call, default is 100
; .NEXT is optional, if NEXT'=0 then not finished
; COND is optional, condition for value (example I V>30), default is ""
; TYPE is [C M A] and is optional, default is C
; DATE1 is optional, earliest date, default is 0 (oldest)
; DATE2 is optional, latest date, default is 9999999 (most recent)
; .DATA is lab result or array(STYPE,#)= specimen, comments, datanumbers
; DATE is collection date/time
; ITEM is test number in file 60 for Chem data
; ITEM is "M;[S T O A M];[S T O A M] ien" for Micro data
; ITEM is "A;[S T O D M E F P I];[S T O D M E F P I] ien" for AP data
; SOURCE is optional, array reference used as alternate list of patients
; .RESULT is patient's test result (result^flag^...)
; NODE is data reference in ^PXRMINDX( indexes "lrdfn;CH;lridt;lrdn"
; LRDFN is lab patient ien
; LRIDT is lab collection time (inverted)
; LRDN is lab datanumbers for test values
; STYPE is "S" specimen node, "C" comments, "V" data nodes, "A" all
; .ERR is -1 when data cannot be found
;
; -- TESTS returns tests (items) on patient; dfn required --
;
TESTS(TESTS,DFN,TYPE,MAX,NEXT,COND,DATE1,DATE2) ; API
I $G(TESTS)?1U1UN1.14UNP,'$G(MAX) S MAX=1000000000 ; default for ^TMP is all, else 100 tests
E S MAX=+$G(MAX,100)
S TYPE=$G(TYPE,"C") ; default is CH data
I TYPE="C" D TESTS^LRPXAPI1(.TESTS,+$G(DFN),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
D TESTS^LRPXAPI3(.TESTS,+$G(DFN),TYPE,MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
Q
;
; -- RESULTS returns results on patient; dfn required --
;
RESULTS(VALUES,DFN,ITEM,MAX,NEXT,COND,DATE1,DATE2) ; API
N TYPE
I $G(VALUES)?1U1UN1.14UNP,'$G(MAX) S MAX=1000000000 ; default for ^TMP is all, else 100 results
E S MAX=+$G(MAX,100)
S ITEM=$G(ITEM)
I ITEM'=+ITEM,$L(ITEM)<5 D Q ; results for all of type or partial item
. S MAX=+$G(MAX,10)
. S TYPE=$E(ITEM)
. I TYPE="C"!'$L(TYPE) D RESULTS^LRPXAPI1(.VALUES,+$G(DFN),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
. D RESULTS^LRPXAPI3(.VALUES,+$G(DFN),ITEM,MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
I ITEM=+ITEM D TRESULTS^LRPXAPI1(.VALUES,+$G(DFN),ITEM,MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
S TYPE=$E(ITEM)
D TRESULTS^LRPXAPI3(.VALUES,+$G(DFN),TYPE,ITEM,MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
Q
;
; -- PATIENTS returns patients with a specific item; item required --
;
PATIENTS(PATS,ITEM,SOURCE,MAX,NEXT,COND,DATE1,DATE2) ; API
N TYPE
I $G(PATS)?1U1UN1.14UNP,'$G(MAX) S MAX=1000000000 ; default for ^TMP is all, else 100 patients
E S MAX=+$G(MAX,100)
S ITEM=$G(ITEM,0)
I ITEM=0!'$L($G(ITEM)) D ALLPATS^LRPXAPI3(.PATS,$G(SOURCE),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
I ITEM'=+ITEM,$L(ITEM)<5 D Q ; patients for all of type or partial item
. S TYPE=$E(ITEM)
. I TYPE="C" D PTS^LRPXAPI1(.PATS,$G(SOURCE),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
. D PTS^LRPXAPI3(.PATS,TYPE,ITEM,$G(SOURCE),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
I ITEM=+ITEM D PATIENTS^LRPXAPI1(.PATS,ITEM,$G(SOURCE),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
S TYPE=$E(ITEM)
D PATIENTS^LRPXAPI3(.PATS,TYPE,ITEM,$G(SOURCE),MAX,.NEXT,$G(COND),$G(DATE1),$G(DATE2)) Q
Q
;
; -- DATES returns col date/times as (date) or (type,date); dfn required --
;
DATES(DATES,DFN,TYPE,MAX,NEXT,DATE1,DATE2) ; API
I $G(DATES)?1U1UN1.14UNP,'$G(MAX) S MAX=1000000000 ; default for ^TMP is all, else 100 date/times
E S MAX=+$G(MAX,100)
S TYPE=$G(TYPE,"C") ; default is CH data
D DATES^LRPXAPI1(.DATES,+$G(DFN),TYPE,MAX,.NEXT,$G(DATE1),$G(DATE2))
Q
;
; ------------ other extract APIs --------------------
;
VALUE(RESULT,DFN,DATE,TEST,COND,ERR) ; API
; returns result node as RESULT; dfn, date, test required
D VALUE^LRPXAPI2(.RESULT,+$G(DFN),+$G(DATE),+$G(TEST),$G(COND),.ERR)
Q
;
LRVALUE(RESULT,LRDFN,LRIDT,LRDN,COND,ERR) ; API
; returns result node as RESULT; lrdfn, lridt, lrdn required
D LRVALUE^LRPXAPI2(.RESULT,+$G(LRDFN),+$G(LRIDT),+$G(LRDN),$G(COND),.ERR)
Q
;
LRPXRM(RESULT,NODE,ITEM,TYPES) ; API
; returns lab data using ^PXRMINDX indexes; node, item required
; types of data: V value, S specimen, C comments, or combinations
D LRPXRM^LRPXAPI2(.RESULT,$G(NODE),$G(ITEM),$G(TYPES,"VS"))
Q
;
SPEC(DATA,DFN,DATE,STYPE,ERR) ; API
; returns specimen node, comments, data nodes
; returned in array DATA; dfn, date required
D SPEC^LRPXAPI2(.DATA,+$G(DFN),+$G(DATE),$G(STYPE),.ERR)
Q
;
LRSPEC(DATA,LRDFN,LRIDT,STYPE,ERR) ; API
; returns specimen node, comments, data nodes
; returned in array DATA; lrdfn, lridt required
D LRSPEC^LRPXAPI2(.DATA,+$G(LRDFN),+$G(LRIDT),$G(STYPE),.ERR)
Q
;
VERIFIED(LRDFN,LRIDT) ; API $$(lrdfn,lridt) -> 1 if verified, else 0
Q $$VERIFIED^LRPXAPI2(+$G(LRDFN),+$G(LRIDT))
;
MIVERIFY(LRDFN,LRIDT,SUB) ; $$(lrdfn,lridt,sub) -> 1 if verified, else 0
Q $$MIVERIFY^LRPXAPI2(+$G(LRDFN),+$G(LRIDT),$G(SUB,"MI"))
;
APVERIFY(LRDFN,LRIDT,SUB) ; $$(lrdfn,lridt,sub) -> 1 if verified, else 0
Q $$APVERIFY^LRPXAPI2(+$G(LRDFN),+$G(LRIDT),$G(SUB))
;
VAL(LRDFN,LRIDT,LRDN) ; API $$(lrdfn,lridt,lrdn) -> result node
Q $$VAL^LRPXAPI2(+$G(LRDFN),+$G(LRIDT),+$G(LRDN))
;
REFVAL(NODE) ; API $$(reference node) -> data node
Q $$REFVAL^LRPXAPI2($G(NODE))
;
Q $$COMMENT^LRPXAPI2(+$G(LRDFN),+$G(LRIDT))
;
ACCY(TESTS,ACC,BDN) ; API
; returns TESTS from yearly accession, ACC, BDN required
; BDN is beginning date number
D ACCY^LRPXAPI2(.TESTS,ACC,BDN)
Q
;
CHNODE(ARRAY,NODE) ; API
; returns ARRAY of values on CH result node
D CHNODE^LRPXAPI2(.ARRAY,$G(NODE))
Q
;
HASITEM(DFN,ITEM) ; API $$(dfn,item) -> 1 if patient has item, else 0
I $D(^PXRMINDX(63,"PI",+$G(DFN),$G(ITEM,0))) Q 1
Q 0
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HLRPXAPI 6380 printed Dec 13, 2024@02:19:28 Page 2
LRPXAPI ;SLC/STAFF Lab Extract APIs ;2/26/04 13:34
+1 ;;5.2;LAB SERVICE;**295**;Sep 27, 1994
+2 ;
+3 ; lab extract API routines
+4 ; dbia 4245
+5 ; no need to namespace local variables when calling these APIs
+6 ; the LRPXAPP routine shows examples of calling these APIs
+7 ; parameters: (.parameter is a call by reference)
+8 ; .TESTS array(ien)=ien^test name
+9 ; .VALUES array(seq of recent first)=col date/time^TEST^comment flag^RESULT
+10 ; .PATS array(dfn)=dfn^patient name
+11 ; .DATES array(-date)=date
+12 ; DFN is patient ien
+13 ; MAX is optional, # of tests,values,pts to return/call, default is 100
+14 ; .NEXT is optional, if NEXT'=0 then not finished
+15 ; COND is optional, condition for value (example I V>30), default is ""
+16 ; TYPE is [C M A] and is optional, default is C
+17 ; DATE1 is optional, earliest date, default is 0 (oldest)
+18 ; DATE2 is optional, latest date, default is 9999999 (most recent)
+19 ; .DATA is lab result or array(STYPE,#)= specimen, comments, datanumbers
+20 ; DATE is collection date/time
+21 ; ITEM is test number in file 60 for Chem data
+22 ; ITEM is "M;[S T O A M];[S T O A M] ien" for Micro data
+23 ; ITEM is "A;[S T O D M E F P I];[S T O D M E F P I] ien" for AP data
+24 ; SOURCE is optional, array reference used as alternate list of patients
+25 ; .RESULT is patient's test result (result^flag^...)
+26 ; NODE is data reference in ^PXRMINDX( indexes "lrdfn;CH;lridt;lrdn"
+27 ; LRDFN is lab patient ien
+28 ; LRIDT is lab collection time (inverted)
+29 ; LRDN is lab datanumbers for test values
+30 ; STYPE is "S" specimen node, "C" comments, "V" data nodes, "A" all
+31 ; .ERR is -1 when data cannot be found
+32 ;
+33 ; -- TESTS returns tests (items) on patient; dfn required --
+34 ;
TESTS(TESTS,DFN,TYPE,MAX,NEXT,COND,DATE1,DATE2) ; API
+1 ; default for ^TMP is all, else 100 tests
IF $GET(TESTS)?1U1UN1.14UNP
IF '$GET(MAX)
SET MAX=1000000000
+2 IF '$TEST
SET MAX=+$GET(MAX,100)
+3 ; default is CH data
SET TYPE=$GET(TYPE,"C")
+4 IF TYPE="C"
DO TESTS^LRPXAPI1(.TESTS,+$GET(DFN),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+5 DO TESTS^LRPXAPI3(.TESTS,+$GET(DFN),TYPE,MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+6 QUIT
+7 ;
+8 ; -- RESULTS returns results on patient; dfn required --
+9 ;
RESULTS(VALUES,DFN,ITEM,MAX,NEXT,COND,DATE1,DATE2) ; API
+1 NEW TYPE
+2 ; default for ^TMP is all, else 100 results
IF $GET(VALUES)?1U1UN1.14UNP
IF '$GET(MAX)
SET MAX=1000000000
+3 IF '$TEST
SET MAX=+$GET(MAX,100)
+4 SET ITEM=$GET(ITEM)
+5 ; results for all of type or partial item
IF ITEM'=+ITEM
IF $LENGTH(ITEM)<5
Begin DoDot:1
+6 SET MAX=+$GET(MAX,10)
+7 SET TYPE=$EXTRACT(ITEM)
+8 IF TYPE="C"!'$LENGTH(TYPE)
DO RESULTS^LRPXAPI1(.VALUES,+$GET(DFN),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+9 DO RESULTS^LRPXAPI3(.VALUES,+$GET(DFN),ITEM,MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
End DoDot:1
QUIT
+10 IF ITEM=+ITEM
DO TRESULTS^LRPXAPI1(.VALUES,+$GET(DFN),ITEM,MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+11 SET TYPE=$EXTRACT(ITEM)
+12 DO TRESULTS^LRPXAPI3(.VALUES,+$GET(DFN),TYPE,ITEM,MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+13 QUIT
+14 ;
+15 ; -- PATIENTS returns patients with a specific item; item required --
+16 ;
PATIENTS(PATS,ITEM,SOURCE,MAX,NEXT,COND,DATE1,DATE2) ; API
+1 NEW TYPE
+2 ; default for ^TMP is all, else 100 patients
IF $GET(PATS)?1U1UN1.14UNP
IF '$GET(MAX)
SET MAX=1000000000
+3 IF '$TEST
SET MAX=+$GET(MAX,100)
+4 SET ITEM=$GET(ITEM,0)
+5 IF ITEM=0!'$LENGTH($GET(ITEM))
DO ALLPATS^LRPXAPI3(.PATS,$GET(SOURCE),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+6 ; patients for all of type or partial item
IF ITEM'=+ITEM
IF $LENGTH(ITEM)<5
Begin DoDot:1
+7 SET TYPE=$EXTRACT(ITEM)
+8 IF TYPE="C"
DO PTS^LRPXAPI1(.PATS,$GET(SOURCE),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+9 DO PTS^LRPXAPI3(.PATS,TYPE,ITEM,$GET(SOURCE),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
End DoDot:1
QUIT
+10 IF ITEM=+ITEM
DO PATIENTS^LRPXAPI1(.PATS,ITEM,$GET(SOURCE),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+11 SET TYPE=$EXTRACT(ITEM)
+12 DO PATIENTS^LRPXAPI3(.PATS,TYPE,ITEM,$GET(SOURCE),MAX,.NEXT,$GET(COND),$GET(DATE1),$GET(DATE2))
QUIT
+13 QUIT
+14 ;
+15 ; -- DATES returns col date/times as (date) or (type,date); dfn required --
+16 ;
DATES(DATES,DFN,TYPE,MAX,NEXT,DATE1,DATE2) ; API
+1 ; default for ^TMP is all, else 100 date/times
IF $GET(DATES)?1U1UN1.14UNP
IF '$GET(MAX)
SET MAX=1000000000
+2 IF '$TEST
SET MAX=+$GET(MAX,100)
+3 ; default is CH data
SET TYPE=$GET(TYPE,"C")
+4 DO DATES^LRPXAPI1(.DATES,+$GET(DFN),TYPE,MAX,.NEXT,$GET(DATE1),$GET(DATE2))
+5 QUIT
+6 ;
+7 ; ------------ other extract APIs --------------------
+8 ;
VALUE(RESULT,DFN,DATE,TEST,COND,ERR) ; API
+1 ; returns result node as RESULT; dfn, date, test required
+2 DO VALUE^LRPXAPI2(.RESULT,+$GET(DFN),+$GET(DATE),+$GET(TEST),$GET(COND),.ERR)
+3 QUIT
+4 ;
LRVALUE(RESULT,LRDFN,LRIDT,LRDN,COND,ERR) ; API
+1 ; returns result node as RESULT; lrdfn, lridt, lrdn required
+2 DO LRVALUE^LRPXAPI2(.RESULT,+$GET(LRDFN),+$GET(LRIDT),+$GET(LRDN),$GET(COND),.ERR)
+3 QUIT
+4 ;
LRPXRM(RESULT,NODE,ITEM,TYPES) ; API
+1 ; returns lab data using ^PXRMINDX indexes; node, item required
+2 ; types of data: V value, S specimen, C comments, or combinations
+3 DO LRPXRM^LRPXAPI2(.RESULT,$GET(NODE),$GET(ITEM),$GET(TYPES,"VS"))
+4 QUIT
+5 ;
SPEC(DATA,DFN,DATE,STYPE,ERR) ; API
+1 ; returns specimen node, comments, data nodes
+2 ; returned in array DATA; dfn, date required
+3 DO SPEC^LRPXAPI2(.DATA,+$GET(DFN),+$GET(DATE),$GET(STYPE),.ERR)
+4 QUIT
+5 ;
LRSPEC(DATA,LRDFN,LRIDT,STYPE,ERR) ; API
+1 ; returns specimen node, comments, data nodes
+2 ; returned in array DATA; lrdfn, lridt required
+3 DO LRSPEC^LRPXAPI2(.DATA,+$GET(LRDFN),+$GET(LRIDT),$GET(STYPE),.ERR)
+4 QUIT
+5 ;
VERIFIED(LRDFN,LRIDT) ; API $$(lrdfn,lridt) -> 1 if verified, else 0
+1 QUIT $$VERIFIED^LRPXAPI2(+$GET(LRDFN),+$GET(LRIDT))
+2 ;
MIVERIFY(LRDFN,LRIDT,SUB) ; $$(lrdfn,lridt,sub) -> 1 if verified, else 0
+1 QUIT $$MIVERIFY^LRPXAPI2(+$GET(LRDFN),+$GET(LRIDT),$GET(SUB,"MI"))
+2 ;
APVERIFY(LRDFN,LRIDT,SUB) ; $$(lrdfn,lridt,sub) -> 1 if verified, else 0
+1 QUIT $$APVERIFY^LRPXAPI2(+$GET(LRDFN),+$GET(LRIDT),$GET(SUB))
+2 ;
VAL(LRDFN,LRIDT,LRDN) ; API $$(lrdfn,lridt,lrdn) -> result node
+1 QUIT $$VAL^LRPXAPI2(+$GET(LRDFN),+$GET(LRIDT),+$GET(LRDN))
+2 ;
REFVAL(NODE) ; API $$(reference node) -> data node
+1 QUIT $$REFVAL^LRPXAPI2($GET(NODE))
+2 ;
+1 QUIT $$COMMENT^LRPXAPI2(+$GET(LRDFN),+$GET(LRIDT))
+2 ;
ACCY(TESTS,ACC,BDN) ; API
+1 ; returns TESTS from yearly accession, ACC, BDN required
+2 ; BDN is beginning date number
+3 DO ACCY^LRPXAPI2(.TESTS,ACC,BDN)
+4 QUIT
+5 ;
CHNODE(ARRAY,NODE) ; API
+1 ; returns ARRAY of values on CH result node
+2 DO CHNODE^LRPXAPI2(.ARRAY,$GET(NODE))
+3 QUIT
+4 ;
HASITEM(DFN,ITEM) ; API $$(dfn,item) -> 1 if patient has item, else 0
+1 IF $DATA(^PXRMINDX(63,"PI",+$GET(DFN),$GET(ITEM,0)))
QUIT 1
+2 QUIT 0
+3 ;