[1586] | 1 | C0CLA7Q ;WV/JMC - CCD/CCR Lab HL7 Query Utility ;Jul 6, 2009 ; 10/30/12 10:16am
|
---|
| 2 | ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
|
---|
[1544] | 3 | ;
|
---|
[1586] | 4 | ; (C) 2009 John McCormack
|
---|
[1544] | 5 | ;
|
---|
[1586] | 6 | ; This program is free software: you can redistribute it and/or modify
|
---|
| 7 | ; it under the terms of the GNU Affero General Public License as
|
---|
| 8 | ; published by the Free Software Foundation, either version 3 of the
|
---|
| 9 | ; License, or (at your option) any later version.
|
---|
| 10 | ;
|
---|
| 11 | ; This program is distributed in the hope that it will be useful,
|
---|
| 12 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | ; GNU Affero General Public License for more details.
|
---|
| 15 | ;
|
---|
| 16 | ; You should have received a copy of the GNU Affero General Public License
|
---|
| 17 | ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 18 | ;
|
---|
| 19 | ;
|
---|
[1544] | 20 | Q
|
---|
| 21 | ;
|
---|
| 22 | ;
|
---|
| 23 | LAB(C0CPTID,C0CSDT,C0CEDT,C0CSC,C0CSPEC,C0CERR,C0CDEST,C0CHL7) ; Entry point for Lab Result Query
|
---|
| 24 | ;
|
---|
| 25 | ;
|
---|
| 26 | K ^TMP("C0C-VLAB",$J)
|
---|
| 27 | ;
|
---|
| 28 | ; Check and retrieve lab results from LAB DATA file (#63)
|
---|
| 29 | S C0CDEST=$$GCPR^LA7QRY($G(C0CPTID),$G(C0CSDT),$G(C0CEDT),.C0CSC,.C0CSPEC,.C0CERR,$G(C0CDEST),$G(C0CHL7))
|
---|
| 30 | ;
|
---|
| 31 | ; If V LAB file present then check for lab results that are only in this file
|
---|
| 32 | ; If results found in V Lab file then build results and add to above results.
|
---|
| 33 | I $D(^AUPNVLAB) D
|
---|
| 34 | . D VCHECK
|
---|
| 35 | . I $D(^TMP("C0C-VLAB",$J,3)) D VBUILD
|
---|
| 36 | ;
|
---|
| 37 | ;K ^TMP("C0C-VLAB",$J)
|
---|
| 38 | ;
|
---|
| 39 | Q C0CDEST
|
---|
| 40 | ;
|
---|
| 41 | ;
|
---|
| 42 | VCHECK ; If V LAB file present then check for lab results that are only in this file.
|
---|
| 43 | ;
|
---|
| 44 | N C0CDA,C0CEND,C0CROOT,C0CVLAB,LA7PTID,LA7SC,LA7SCRC,LA7SPEC
|
---|
| 45 | ;
|
---|
| 46 | S LA7PTID=C0CPTID
|
---|
| 47 | D PATID^LA7QRY2
|
---|
| 48 | I $D(LA7ERR) Q
|
---|
| 49 | ;
|
---|
| 50 | ; Resolve search codes to lab datanames
|
---|
| 51 | S LA7SC=$G(C0CSC)
|
---|
| 52 | I $T(SCLIST^LA7QRY2)'="" D
|
---|
| 53 | . N TMP
|
---|
| 54 | . S LA7SCRC=$G(C0CSC)
|
---|
| 55 | . S TMP=$$SCLIST^LA7QRY2(LA7SCRC)
|
---|
| 56 | . S LA7SC=TMP
|
---|
| 57 | ;
|
---|
| 58 | I LA7SC'="*" D CHKSC^LA7QRY1
|
---|
| 59 | ;
|
---|
| 60 | ; Convert specimen codes to file #61 Topography entries
|
---|
| 61 | S LA7SPEC=$G(C0CSPEC)
|
---|
| 62 | I LA7SPEC'="*" D SPEC^LA7QRY1
|
---|
| 63 | ;
|
---|
| 64 | S C0CROOT="^AUPNVLAB(""ALR4"",DFN,C0CSDT)",C0CEND=0
|
---|
| 65 | ;
|
---|
| 66 | F S C0CROOT=$Q(@C0CROOT) Q:C0CROOT="" D Q:C0CEND
|
---|
| 67 | . I $QS(C0CROOT,1)'="ALR4"!($QS(C0CROOT,2)'=DFN) S C0CEND=1 Q ; Left x-ref or patient
|
---|
| 68 | . I $QS(C0CROOT,3)>C0CEDT S C0CEND=1 Q ; Exceeded end date/time
|
---|
| 69 | . S C0CDA=$QS(C0CROOT,4)
|
---|
| 70 | . I $D(^TMP("C0C-VLAB",$J,1,C0CDA)) Q ; Already checked during scan of file #63
|
---|
| 71 | . I $P($G(^AUPNVLAB(C0CDA,11)),"^",8)=1 Q ; Source is LAB DATA file - skip
|
---|
| 72 | . D VCHK1
|
---|
| 73 | ;
|
---|
| 74 | ;
|
---|
| 75 | Q
|
---|
| 76 | ;
|
---|
| 77 | ;
|
---|
| 78 | VBUILD ; Build results found only in V LAB file into HL7 structure.
|
---|
| 79 | ;
|
---|
| 80 | ;
|
---|
| 81 | Q
|
---|
| 82 | ;
|
---|
| 83 | ;
|
---|
| 84 | LNCHK ; Check for corresponding entry in V LAB file and related LOINC code for a result in file #63.
|
---|
| 85 | ; Call from LA7QRY2
|
---|
| 86 | ;
|
---|
| 87 | N DFN,C0C60,C0C63,C0CACC,C0CDA,C0CDT,C0CLN,C0CPDA,C0CPTEST,C0CSPEC,C0CTEST,X
|
---|
| 88 | ;
|
---|
| 89 | S DFN=$P(^LR(LRDFN,0),"^",3)
|
---|
| 90 | S C0C63(0)=^LR(LRDFN,LRSS,LRIDT,0)
|
---|
| 91 | S C0CDT=$P(C0C63(0),"^"),C0CACC=$P(C0C63(0),"^",6),C0CSPEC=$P(C0C63(0),"^",5)
|
---|
| 92 | S (C0CTEST,C0CTEST(64),C0CPTEST,C0CPTEST(64),C0CLN)=""
|
---|
| 93 | ;
|
---|
| 94 | ; ^AUPNVLAB("ALR1",5380,"EKT 0307 48",173,3080307.211055,5427197)=""
|
---|
| 95 | ;
|
---|
| 96 | S C0C60=""
|
---|
| 97 | F S C0C60=$O(^LAB(60,"C",LRSS_";"_LRSB_";1",C0C60)) Q:'C0C60 D Q:C0CLN'=""
|
---|
| 98 | . D FINDDT
|
---|
| 99 | . I C0CDA<1 Q
|
---|
| 100 | . I $P($G(^AUPNVLAB(C0CDA,11)),"^",8)'=1 Q ; Source is not LAB DATA file - skip
|
---|
| 101 | . S C0CLN=$P($G(^AUPNVLAB(C0CDA,11)),"^",13)
|
---|
| 102 | . S C0CPDA=$P($G(^AUPNVLAB(C0CDA,12)),"^",8)
|
---|
| 103 | . I C0CPDA,'$D(^AUPNVLAB(C0CPDA,0)) S C0CPDA="" ; Dangling pointer
|
---|
| 104 | . I C0CPDA="" S C0CPDA=C0CDA
|
---|
| 105 | . S C0CTEST=$P($G(^AUPNVLAB(C0CDA,0)),"^"),X=$P($G(^LAB(60,C0CTEST,64)),"^",2)
|
---|
| 106 | . I X S C0CTEST(64)=$P($G(^LAM(X,0)),"^",2)
|
---|
| 107 | . S C0CPTEST=$P($G(^AUPNVLAB(C0CPDA,0)),"^"),X=$P($G(^LAB(60,C0CPTEST,64)),"^")
|
---|
| 108 | . I X S C0CPTEST(64)=$P($G(^LAM(X,0)),"^",2)
|
---|
| 109 | . S ^TMP("C0C-VLAB",$J,1,C0CDA)=""
|
---|
| 110 | . I C0CDA'=C0CPDA S ^TMP("C0C-VLAB",$J,1,C0CPDA)=""
|
---|
| 111 | . S ^TMP("C0C-VLAB",$J,2,LRDFN,LRSS,LRIDT,LRSB)=C0CPTEST(64)_"^"_C0CTEST(64)_"^"_C0CLN_"^"_C0CDA_"^"_C0CTEST_"^"_C0CPDA_"^"_C0CPTEST
|
---|
| 112 | ;
|
---|
| 113 | S X=$P(LA7X,"^",3)
|
---|
| 114 | ; If order NLT then update if no order NLT
|
---|
| 115 | I C0CPTEST(64),$P(X,"!")="" S $P(X,"!")=C0CPTEST(64)
|
---|
| 116 | ;
|
---|
| 117 | ; If result NLT then update if no result NLT
|
---|
| 118 | I C0CTEST(64),$P(X,"!",2)="" S $P(X,"!",2)=C0CTEST(64)
|
---|
| 119 | ;
|
---|
| 120 | ; If LOINC found then update variable with LN code
|
---|
| 121 | I C0CLN'="",$P(X,"!",3)="" S $P(X,"!",3)=C0CLN
|
---|
| 122 | ;
|
---|
| 123 | S $P(LA7X,"^",3)=X
|
---|
| 124 | ;
|
---|
| 125 | Q
|
---|
| 126 | ;
|
---|
| 127 | ;
|
---|
| 128 | TMPCHK ; Check if LN/NLT codes saved from V LAB file above and use when building OBR/OBX segments
|
---|
| 129 | ; Called from LA7VOBX1
|
---|
| 130 | ;
|
---|
| 131 | N I,X
|
---|
| 132 | ;
|
---|
| 133 | S X=$G(^TMP("C0C-VLAB",$J,2,LRDFN,LRSS,LRIDT,LRSB))
|
---|
| 134 | I X="" Q
|
---|
| 135 | F I=1:1:3 I $P(LA7X,"!",I)="",$P(X,"^",I)'="" S $P(LA7X,"!",I)=$P(X,"^",I)
|
---|
| 136 | S $P(LA7VAL,"^",3)=LA7X
|
---|
| 137 | ;
|
---|
| 138 | Q
|
---|
| 139 | ;
|
---|
| 140 | ;
|
---|
| 141 | VCHK1 ; Check the entry in V Lab to determine if it meets criteria
|
---|
| 142 | ;
|
---|
| 143 | N C0CVLAB,I
|
---|
| 144 | ;
|
---|
| 145 | F I=0,12 S C0CVLAB(I)=$G(^AUPNVLAB(C0CDA,I))
|
---|
| 146 | ;
|
---|
| 147 | ; JMC 04/13/09 - Store anything for now that meets date criteria.
|
---|
| 148 | D VSTORE
|
---|
| 149 | ;
|
---|
| 150 | Q
|
---|
| 151 | ;
|
---|
| 152 | ;
|
---|
| 153 | VSTORE ; Store entry for building in HL7 message when parent is from V LAB file.
|
---|
| 154 | ;
|
---|
| 155 | N C0CPDA,C0CPTEST
|
---|
| 156 | ;
|
---|
| 157 | ; Determine parent test to use for OBR segment
|
---|
| 158 | S C0CPDA=$P(C0CVLAB(12),"^",8)
|
---|
| 159 | I C0CPDA="" S C0CPDA=C0CDA
|
---|
| 160 | ;
|
---|
| 161 | ; Determine parent test
|
---|
| 162 | S C0CPTEST=$P($G(^AUPNVLAB(C0CPDA,0)),"^")
|
---|
| 163 | ;
|
---|
| 164 | S ^TMP("C0C-VLAB",$J,3,$P(C0CVLAB(0),"^",2),$P(C0CVLAB(12),"^"),C0CPTEST,C0CDA)=C0CPDA
|
---|
| 165 | ;
|
---|
| 166 | Q
|
---|
| 167 | ;
|
---|
| 168 | ;
|
---|
| 169 | FINDDT ; Find entry in V LAB for the date/time or one close to it.
|
---|
| 170 | ; RPMS stores related specimen entries under the same date/time.
|
---|
| 171 | ; Lab file #63 creates unique entries with slightly different times.
|
---|
| 172 | ;
|
---|
| 173 | S C0CDA=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,C0CDT,0))
|
---|
| 174 | I C0CDA>0 Q
|
---|
| 175 | ;
|
---|
| 176 | ; If entry found then confirm that specimen type matches.
|
---|
| 177 | N C0CDTY
|
---|
| 178 | S C0CDTY=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,0))
|
---|
| 179 | I C0CDTY D
|
---|
| 180 | . I $P(C0CDT,".")'=$P(C0CDTY,".") Q
|
---|
| 181 | . S C0CDA=$O(^AUPNVLAB("ALR1",DFN,C0CACC,C0C60,C0CDTY,0))
|
---|
| 182 | . I C0CSPEC'=$P($G(^AUPNVLAB(C0CDA,11)),"^",3) S C0CDA=""
|
---|
| 183 | ;
|
---|
| 184 | Q
|
---|