source: WorldVistAEHR/trunk/r/LAB_SERVICE-LR-LS/LR7OR1.m@ 1604

Last change on this file since 1604 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.7 KB
Line 
1LR7OR1 ;slc/dcm - Get Lab results ;8/11/97
2 ;;5.2;LAB SERVICE;**121,187,219,230,256,310,340,348**;Sep 27, 1994
3RR(DFN,ORD,SDATE,EDATE,SUB,TEST,FLAG,COUNT,SPEC,UNVER) ;Get LAB results for patient
4 ;DFN = Patient DFN, ptr to file 2 (Required)
5 ;ORD = Lab Link from OE/RR (ORPK node) (Optional)
6 ;SDATE = start date to begin search in fileman format (Optional)
7 ;EDATE = end date to end search in fileman format (Optional)
8 ;SUB =set to CH,MI,AP or ALL to specify lab (Optional)
9 ; subsection. A null entry will imply ALL.
10 ;TEST = Test to do lookup on (Optional). A null parameter will get all tests
11 ;FLAG = L for local test ID, N for National test ID (Optional)
12 ; this is specified for both input and output
13 ;COUNT =Count of results to return. Each Date/time counts as 1 (optional)
14 ;SPEC =ptr file 61 to specify specimen (optional).
15 ; If specified, no AP results are returned.
16 ;UNVER =1 to include unverified data
17 ;Output is set in ^TMP("LRRR",$J,dfn,subscript,inverse d/t,seq)=
18 ; testID^result^flag^units^refrange^resultstatus(F or P)^^^natlCode^natlName^system^Verifyby^^Theraputicflag(T or "")^PrintName^Accession^Order#^Specimen
19 N LRDFN,LRDPF,SEX,AGE,DOB,ORDT,ORSN,II,III,DRAW,TSTY,SS,CT1
20 Q:'$G(DFN)
21 S LRDFN=$$LRDFN(DFN),LRDPF="2^DPT("
22 Q:'LRDFN
23 S SEX=$P($G(@("^"_$P(LRDPF,"^",2)_+DFN_",0)")),"^",2)
24 S DOB=$P($G(@("^"_$P(LRDPF,"^",2)_+DFN_",0)")),"^",3),AGE=$S($D(DT)&(DOB?7N):DT-DOB\10000,1:"??")
25 D DTRNG
26 S SUB=$S($G(SUB)="ALL":"CHMIAP",$L($G(SUB)):SUB,1:"CHMIAP"),FLAG=$S('$L($G(FLAG)):"L",1:FLAG)
27 I $G(TEST),FLAG="L",'$D(^LAB(60,TEST)) Q ;No-Match on Local testID
28 I $G(TEST),FLAG="N" S TEST=$O(^LAB(60,"AC",TEST,0)) Q:'TEST ;No-Match on National testID
29 I $G(TEST) S SUB=$P(^LAB(60,TEST,0),"^",4) Q:'$L(SUB) ;Test with no subscript
30 K ^TMP("LRRR",$J),^TMP("LRAPI",$J) S COUNT=$S($G(COUNT):COUNT,1:9999999),CT1=1
31 I $G(ORD) S ORDT=0 D Q
32 . I $G(TEST) Q:'$D(^LAB(60,TEST,0)) S X=^(0) I $P(X,"^",4)="CH" D
33 .. I $L($P(X,"^",5)) S TSTY($P($P(X,"^",5),";",2))=TEST
34 .. I '$L($P(X,"^",5)) D EN^LR7OU1(TEST)
35 . I ORD["^" S ORDT=$P(ORD,"^"),ORSN=$P(ORD,"^",2) I ORDT,ORSN D SN Q ;OE/RR 2.5 unconverted orders
36 . I ORD'[";" F S ORDT=$O(^LRO(69,"C",ORD,ORDT)) Q:ORDT<1 S ORSN=0 F S ORSN=$O(^LRO(69,"C",ORD,ORDT,ORSN)) Q:ORSN<1 D SN ;Early CPRS when only LR# stored
37 . I ORD[";" S ORDT=$P(ORD,";",2),ORSN=$P(ORD,";",3) I ORDT,ORSN D SN
38 I SUB["CH" D CH^LR7OR2(SDATE,EDATE,$G(TEST),COUNT,$G(SPEC),$G(UNVER))
39 I SUB["MI" D MI(SDATE,EDATE,COUNT,$G(SPEC))
40 ;I SUB["BB" D BB(SDATE,EDATE,COUNT,$G(SPEC))
41 I SUB["AP",'$G(SPEC) D AP(SDATE,EDATE,COUNT)
42 Q
43MI(SDATE,EDATE,COUNT,SPEC) ;Get MI Subscript data
44 Q:'$D(SDATE) Q:'$D(EDATE) Q:'$D(COUNT) Q:'$D(CT1)
45 K ^TMP("LRX",$J)
46 S IVDT=SDATE F S IVDT=$O(^LR(LRDFN,"MI",IVDT)) Q:IVDT<1!(IVDT>EDATE)!(CT1>COUNT) K LRX S CTR=99,CT1=CT1+1 D MI^LR7OB63A(SPEC) M ^TMP("LRRR",$J,DFN,"MI",IVDT)=^TMP("LRX",$J,69,99,63)
47 K ^TMP("LRX",$J) Q
48BB(SDATE,EDATE,COUNT,SPEC) ;Get BB Subscript data
49 Q
50 Q:'$D(SDATE) Q:'$D(EDATE) Q:'$D(COUNT) Q:'$D(CT1)
51 K ^TMP("LRX",$J)
52 S IVDT=SDATE F S IVDT=$O(^LR(LRDFN,"BB",IVDT)) Q:IVDT<1!(IVDT>EDATE)!(CT1>COUNT) K LRX S CTR=99,CT1=CT1+1 D BB1^LR7OB63(SPEC) M ^TMP("LRRR",$J,DFN,"BB",IVDT)=^TMP("LRX",$J,69,99,63)
53 K ^TMP("LRX",$J) Q
54AP(SDATE,EDATE,COUNT) ;Get AP Subscript data (EM,CY,AU,SP)
55 N LRSS K ^TMP("LRX",$J)
56 Q:'$D(SDATE) Q:'$D(EDATE) Q:'$D(COUNT) Q:'$D(CT1)
57 S CTR=99 D AU^LR7OB63D M ^TMP("LRRR",$J,DFN,"AU")=^TMP("LRX",$J,69,99,63)
58 F LRSS="EM","CY","SP" S IVDT=SDATE F S IVDT=$O(^LR(LRDFN,LRSS,IVDT)) Q:IVDT<1!(IVDT>EDATE)!(CT1>COUNT) K LRX S CTR=99,CT1=CT1+1 D SS^LR7OB63C(LRSS) M ^TMP("LRRR",$J,DFN,LRSS,IVDT)=^TMP("LRX",$J,69,99,63)
59 K ^TMP("LRX",$J) Q
60TEST ;Test the RR entry point
61 N X1,X2,X3,X4,X5,DIC,%DT,X,Y
62 K ^TMP("LRRR",$J),^TMP("LRAPI",$J) S (X1,X2,X3,X4,X5)=""
63 D ^LRDPA Q:'DFN
64O1 W !,"Select Lab Order #: " R X:DTIME Q:'$T!(X["^")
65 I $L(X),'$D(^LRO(69,"C",X)) W !!,X_" is not a valid order number." G O1
66 I $L(X),$D(^LRO(69,"C",X)) S X5=X,DIC=60,DIC(0)="AEQM",DIC("A")="Select Test (optional): " D ^DIC S X3=$S(Y>0:+Y,1:"") Q:Y<0&(X["^") G T2
67 S %DT="AETS",%DT("A")="Select Start Date: " D ^%DT S X1=$S(Y>0:Y,1:"") I Y<0,X["^" Q
68 S %DT="AETS",%DT("A")="Select End Date: " D ^%DT S X2=$S(Y>0:Y,1:"") I Y<0,X["^" Q
69 S DIC=60,DIC(0)="AEQM",DIC("A")="Look for specific Test: " D ^DIC S X3=$S(Y>0:+Y,1:"") I Y<0,X["^" Q
70 I 'X3 D
71T1 . W !,"Enter a lab area to search on (ALL,CH,MI,AP): " R X:DTIME Q:'$T!(X["^")
72 . IF "ALLCHMIAP"'[X W !!,"Bad input, enter ALL, CH, MI, or AP" G T1
73 . S X4=$S("ALLCHMIAP"[X:X,1:"")
74T2 D RR(DFN,X5,X1,X2,X4,X3)
75 W !!,$S($D(^TMP("LRRR",$J)):"Data found!",1:"NO Data found!")
76 Q
77DTRNG ;Date range setup
78 I $G(EDATE)<$G(SDATE) S X=EDATE,EDATE=SDATE,SDATE=X
79 I $G(EDATE) S EDATE=$S($L(EDATE,".")=2:EDATE+.000001,1:EDATE+1)
80 I $G(SDATE) S SDATE=$S($L(SDATE,".")=2:SDATE-.000001,1:SDATE)
81 S SDATE=$S($G(SDATE):9999999-SDATE,1:9999999),EDATE=$S($G(EDATE):9999999-EDATE,1:1)
82 S X=EDATE,EDATE=SDATE,SDATE=X
83 Q
84SN ;Get the subs
85 D 69^LR7OB69(ORDT,ORSN) Q:'$D(^TMP("LRX",$J,69))
86 S II=0 F S II=$O(^TMP("LRX",$J,69,II)) Q:II<1 S DRAW=$P($G(^TMP("LRX",$J,69,II,68)),"^",4),SS=$P($G(^LRO(68,+$P(^TMP("LRX",$J,69,II),"^",4),0)),"^",2) D
87 . S III=0 F S III=$O(^TMP("LRX",$J,69,II,63,III)) Q:III<1 I $S($D(TSTY):$D(TSTY(III)),1:1) D
88 .. I $P(^TMP("LRX",$J,69,II,63,III),U,6)="" Q
89 .. S ^TMP("LRRR",$J,DFN,SS,9999999-DRAW,III)=^TMP("LRX",$J,69,II,63,III)
90 . I $D(^TMP("LRX",$J,69,II,63,"N")),$O(^TMP("LRRR",$J,DFN,SS,9999999-DRAW,0)) M ^TMP("LRRR",$J,DFN,SS,9999999-DRAW,"N")=^TMP("LRX",$J,69,II,63,"N")
91 Q
92LRDFN(IFN,FILEROOT) ;Get LRDFN
93 ;IFN=Internal file number
94 ;FILEROOT=Root of file to get LRDFN (optional) "DPT(" is default
95 Q:'$G(IFN) ""
96 I '$L($G(FILEROOT)) S FILEROOT="DPT("
97 S X=$S($D(@("^"_FILEROOT_+IFN_",""LR"")")):+^("LR"),1:"")
98 I X,'$D(^LR(X,0)) S X=""
99 Q X
Note: See TracBrowser for help on using the repository browser.