source: ccr/trunk/labRPMS/C0CLA7Q.m@ 1039

Last change on this file since 1039 was 446, checked in by George Lilly, 16 years ago

update to lab extract for RPMS

File size: 4.8 KB
RevLine 
[446]1C0CLA7Q ;WV/JMC - CCD/CCR Lab HL7 Query Utility ;May 4, 2009
[434]2 ;;n.n;;****;
[433]3 ;
4 ;
5 Q
6 ;
7 ;
8LAB(C0CPTID,C0CSDT,C0CEDT,C0CSC,C0CSPEC,C0CERR,C0CDEST,C0CHL7) ; Entry point for Lab Result Query
9 ;
10 ;
11 K ^TMP("C0C-VLAB",$J)
12 ;
13 ; Check and retrieve lab results from LAB DATA file (#63)
[435]14 S C0CDEST=$$GCPR^LA7QRY($G(C0CPTID),$G(C0CSDT),$G(C0CEDT),.C0CSC,.C0CSPEC,.C0CERR,$G(C0CDEST),$G(C0CHL7))
[433]15 ;
16 ; If V LAB file present then check for lab results that are only in this file
17 ; If results found in V Lab file then build results and add to above results.
[434]18 I $D(^AUPNVLAB) D
19 . D VCHECK
20 . I $D(^TMP("C0C-VLAB",$J,3)) D VBUILD
[433]21 ;
22 ;K ^TMP("C0C-VLAB",$J)
23 ;
24 Q C0CDEST
25 ;
26 ;
27VCHECK ; If V LAB file present then check for lab results that are only in this file.
28 ;
[435]29 N C0CDA,C0CEND,C0CROOT,C0CVLAB,LA7PTID,LA7SC,LA7SCRC,LA7SPEC
[433]30 ;
31 S LA7PTID=C0CPTID
32 D PATID^LA7QRY2
33 I $D(LA7ERR) Q
34 ;
35 ; Resolve search codes to lab datanames
[435]36 S LA7SC=$G(C0CSC)
37 I $T(SCLIST^LA7QRY2)'="" D
38 . N TMP
39 . S LA7SCSRC=$G(C0CSC)
40 . S TMP=$$SCLIST^LA7QRY2(LA7SCSRC)
41 . S LA7SC=TMP
[433]42 ;
[435]43 I LA7SC'="*" D CHKSC^LA7QRY1
44 ;
[433]45 ; Convert specimen codes to file #61 Topography entries
46 S LA7SPEC=$G(C0CSPEC)
47 I LA7SPEC'="*" D SPEC^LA7QRY1
48 ;
[435]49 S C0CROOT="^AUPNVLAB(""ALR4"",DFN,C0CSDT)",C0CEND=0
[433]50 ;
51 F S C0CROOT=$Q(@C0CROOT) Q:C0CROOT="" D Q:C0CEND
52 . I $QS(C0CROOT,1)'="ALR4"!($QS(C0CROOT,2)'=DFN) S C0CEND=1 Q ; Left x-ref or patient
53 . I $QS(C0CROOT,3)>C0CEDT S C0CEND=1 Q ; Exceeded end date/time
[435]54 . S C0CDA=$QS(C0CROOT,4)
[433]55 . I $D(^TMP("C0C-VLAB",$J,1,C0CDA)) Q ; Already checked during scan of file #63
[446]56 . I $P($G(^AUPNVLAB(C0CDA,11)),"^",8)=1 Q ; Source is LAB DATA file - skip
[433]57 . D VCHK1
58 ;
59 ;
60 Q
61 ;
62 ;
63VBUILD ; Build results found only in V LAB file into HL7 structure.
64 ;
65 ;
66 Q
67 ;
68 ;
69LNCHK ; Check for corresponding entry in V LAB file and related LOINC code for a result in file #63.
70 ; Call from LA7QRY2
71 ;
[438]72 N DFN,C0C60,C0C63,C0CACC,C0CDA,C0CDT,C0CLN,C0CPDA,C0CPTEST,C0CSPEC,C0CTEST,X
[433]73 ;
74 S DFN=$P(^LR(LRDFN,0),"^",3)
75 S C0C63(0)=^LR(LRDFN,LRSS,LRIDT,0)
[438]76 S C0CDT=$P(C0C63(0),"^"),C0CACC=$P(C0C63(0),"^",6),C0CSPEC=$P(C0C63(0),"^",5)
77 S (C0CTEST,C0CTEST(64),C0CPTEST,C0CPTEST(64),C0CLN)=""
[433]78 ;
[446]79 ; ^AUPNVLAB("ALR1",5380,"EKT 0307 48",173,3080307.211055,5427197)=""
[433]80 ;
[438]81 S C0C60=""
[433]82 F S C0C60=$O(^LAB(60,"C",LRSS_";"_LRSB_";1",C0C60)) Q:'C0C60 D Q:C0CLN'=""
[438]83 . D FINDDT
[433]84 . I C0CDA<1 Q
[446]85 . I $P($G(^AUPNVLAB(C0CDA,11)),"^",8)'=1 Q ; Source is not LAB DATA file - skip
[433]86 . S C0CLN=$P($G(^AUPNVLAB(C0CDA,11)),"^",13)
[435]87 . S C0CPDA=$P($G(^AUPNVLAB(C0CDA,12)),"^",8)
88 . I C0CPDA="" S C0CPDA=C0CDA
[438]89 . S C0CTEST=$P($G(^AUPNVLAB(C0CDA,0)),"^"),X=$P($G(^LAB(60,C0CTEST,64)),"^",2)
90 . I X S C0CTEST(64)=$P($G(^LAM(X,0)),"^",2)
91 . S C0CPTEST=$P($G(^AUPNVLAB(C0CPDA,0)),"^"),X=$P($G(^LAB(60,C0CPTEST,64)),"^")
92 . I X S C0CPTEST(64)=$P($G(^LAM(X,0)),"^",2)
[433]93 . S ^TMP("C0C-VLAB",$J,1,C0CDA)=""
[435]94 . I C0CDA'=C0CPDA S ^TMP("C0C-VLAB",$J,1,C0CPDA)=""
[438]95 . S ^TMP("C0C-VLAB",$J,2,LRDFN,LRSS,LRIDT,LRSB)=C0CPTEST(64)_"^"_C0CTEST(64)_"^"_C0CLN_"^"_C0CDA_"^"_C0CTEST_"^"_C0CPDA_"^"_C0CPTEST
[433]96 ;
[438]97 S X=$P(LA7X,"^",3)
98 ; If order NLT then update if no order NLT
99 I C0CPTEST(64),$P(X,"!")="" S $P(X,"!")=C0CPTEST(64)
100 ;
101 ; If result NLT then update if no result NLT
102 I C0CTEST(64),$P(X,"!",2)="" S $P(X,"!",2)=C0CTEST(64)
103 ;
[433]104 ; If LOINC found then update variable with LN code
[438]105 I C0CLN'="",$P(X,"!",3)="" S $P(X,"!",3)=C0CLN
[433]106 ;
[438]107 S $P(LA7X,"^",3)=X
108 ;
[433]109 Q
110 ;
111 ;
[438]112TMPCHK ; Check if LN/NLT codes saved from V LAB file above and use when building OBR/OBX segments
113 ; Called from LA7VOBX1
114 ;
115 N I,X
116 ;
117 S X=$G(^TMP("C0C-VLAB",$J,2,LRDFN,LRSS,LRIDT,LRSB))
118 I X="" Q
119 F I=1:1:3 I $P(LA7X,"!",I)="",$P(X,"^",I)'="" S $P(LA7X,"!",I)=$P(X,"^",I)
120 S $P(LA7VAL,"^",3)=LA7X
121 ;
122 Q
123 ;
124 ;
[433]125VCHK1 ; Check the entry in V Lab to determine if it meets criteria
126 ;
127 N C0CVLAB,I
128 ;
[446]129 F I=0,12 S C0CVLAB(I)=$G(^AUPNVLAB(C0CDA,I))
[433]130 ;
[434]131 ; JMC 04/13/09 - Store anything for now that meets date criteria.
[433]132 D VSTORE
133 ;
134 Q
135 ;
136 ;
137VSTORE ; Store entry for building in HL7 message when parent is from V LAB file.
138 ;
[435]139 N C0CPDA,C0CPTEST
[434]140 ;
141 ; Determine parent test to use for OBR segment
[435]142 S C0CPDA=$P(C0CVLAB(12),"^",8)
143 I C0CPDA="" S C0CPDA=C0CDA
[434]144 ;
[435]145 ; Determine parent test
146 S C0CPTEST=$P($G(^AUPNVLAB(C0CPDA,0)),"^")
[434]147 ;
[435]148 S ^TMP("C0C-VLAB",$J,3,$P(C0CVLAB(0),"^",2),$P(C0CVLAB(12),"^"),C0CPTEST,C0CDA)=C0CPDA
149 ;
[433]150 Q
[438]151 ;
152 ;
153FINDDT ; Find entry in V LAB for the date/time or one close to it.
154 ; RPMS stores related specimen entries under the same date/time.
155 ; Lab file #63 creates unique entries with slightly different times.
156 ;
157 S C0CDA=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,C0CDT,0))
158 I C0CDA>0 Q
159 ;
160 ; If entry found then confirm that specimen type matches.
161 N C0CDTY
162 S C0CDTY=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,0))
163 I C0CDTY D
164 . I $P(C0CDT,".")'=$P(C0CDTY,".") Q
165 . S C0CDA=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,C0CDTY,0))
166 . I C0CSPEC'=$P($G(^AUPNVLAB(C0CDA,11)),"^",3) S C0CDA=""
167 ;
168 Q
Note: See TracBrowser for help on using the repository browser.