source: WorldVistAEHR/trunk/r/DSS_EXTRACTS-ECX/ECXLBB.m@ 619

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

initial load of WorldVistAEHR

File size: 9.5 KB
Line 
1ECXLBB ;DALOI/KML - DSS BLOOD BANK EXTRACT ; 8/12/08 1:00pm
2 ;;3.0;DSS EXTRACTS;**78,84,90,92,104,105,102**;Dec 22, 1997;Build 17
3 ;Per VHA Directive 97-033 this routine should not be modified. Medical Device # BK970021
4 ; access to the LAB DATA file (#63) is supported by
5 ; controlled subscription to IA 525 (global root ^LR)
6 ; access to the BLOOD PRODUCT (#66) is supported by IA 4510
7BEG ;entry point from option
8 D SETUP I ECFILE="" Q
9 D ^ECXTRAC,^ECXKILL
10 Q
11START ; Entry point from tasked job
12 ; begin package specific extract
13 N ECTRSP,ECADMT,ECTODT,ECENCTR,ECPAT,ECLRDFN,ECXPHY,ECXPHYPC,ECPHYNPI
14 N ECD,ECXDFN,ECARRY,EC66,ECERR,ECTRFDT,ECTRFTM,ECX,ECINOUT,ECXINST
15 ;variables ECFILE,EC23,ECXYM,ECINST,ECSD,ECSD1,ECED passed in
16 ; by taskmanager
17 ; ECED defined in ^ECXTRAC - it represents the end date of the extract
18 ; sort process. TRANSFUSION DATE should be within start and end dates
19 ; ECED and ECSD were assigned with input provided by the user interface
20 ; and ECSD1 = ECSD-.1
21 ; Read through the TRANSFUSION RECORD sub-file (63.017) of
22 ; the LAB DATA file (#63)
23 ;the global nodes containing transfusion record entries are constructed
24 ; by calculating the TRANSFUSION DATE/TIME (.01)
25 ; into its reverse date/time representation and then DINUM'd when
26 ;filing the record entry
27 ; ECD equals the reverse date/time of ECED+.3 and will need to be
28 ; reset for each DFN.
29 I $D(ZTQUEUED),$$S^%ZTLOAD S QFLG=1 Q ;quit if tasked and user sends stop request (QFLG assigned in ECXTRAC)
30AUDRPT ; entry point for pre-extract audit report
31 S ECTODT=9999999-ECSD1,ECLRDFN=0
32 F S ECLRDFN=$O(^LR(ECLRDFN)) Q:'ECLRDFN S ECXDFN=$$GETDFN(ECLRDFN),ECERR=$$PAT(ECXDFN) S ECD=9999999-(ECED+.3) F S ECD=$O(^LR(ECLRDFN,1.6,ECD)) Q:ECERR Q:'ECD!(ECD>ECTODT) S EC0=^LR(ECLRDFN,1.6,ECD,0) D
33 .; ECARRY(1)=TRANSFUSION DATE AND TIME,
34 .; ECARRY(3)=COMPONENT, ECARRY(4)=COMPONENT ABBREVIATION
35 .; ECARRY(5)=UNITS POOLED, ECARRY(6)=TRANSFUSION REACTION,
36 .; ECARRY(7)=VOLUME TRANSFUSED, ECARRY(8)=TRANSFUSION REACTION TYPE
37 .; ECARRY(9)=REQUESTING PROVIDER, ECARRY(10)=REQUEST. PROV. PERSON CLASS
38 .; ECARRY(11)=UNIT MODIFIED,ECARRY(12)=UNIT MODIFICATION
39 .; ECARRY(13)=PRODUCTION DIVISION CODE
40 . S ECARRY(1)=$P(EC0,"^"),EC66=$G(^LAB(66,$P(EC0,"^",2),0))
41 . S ECARRY(3)=$E($P(EC66,"^"),1,15),ECARRY(4)=$P(EC66,"^",2)
42 . S ECARRY(5)=$S(+$P(EC0,"^",7)=0:1,1:+$P(EC0,"^",7))
43 . S ECARRY(6)=$S($P(EC0,"^",8)=1:"Y",1:"N"),ECARRY(7)=$P(EC0,"^",10)
44 . S ECARRY(8)=$E($P($G(^LAB(65.4,+$P(EC0,"^",11),0)),"^"),1,10)
45 . S (ECARRY(9),ECARRY(10),ECARRY(13))="" D GETRPRV
46 . S ECARRY(11)=$$MODIFIED(),(ECXPHY,ECXPHYPC,ECPHYNPI)=""
47 . S ECARRY(12)=$S(ECARRY(11)="Y":$$UNITMODS(),1:"")
48 . D GETDATA
49 . K ECARRY
50 D AUDRPT^ECXLBB1
51 Q
52UNITMODS() ; Get modification criteria from fields #.06 and #3 from file #66
53 N MODARY,MO,EC66A,MODSTR,STR3
54 S MODARY("DIVIDED")="D",MODARY("POOLED")="P",MODARY("WASHED")="W"
55 S MODARY("FROZEN")="F",MODARY("LEUKOCYTE POOR")="L"
56 S MODARY("REJUVENATED")="R",MODARY("DEGLYCEROLIZED")="G"
57 S MODARY("IRRADIATED")="I",MODARY("SEPARATED")="S"
58 ;if modification criteria is null determine value from description
59 S MODSTR=$S($P(EC66,U,6)'="":$P(EC66,U,6),1:$$CHKMOD^ECXLBB1($P(EC66,"^")))
60 ;get modification criteria for entries at field #3 in file #66
61 S MOD=0 F S MOD=$O(^LAB(66,$P(EC0,"^",2),3,MOD)) Q:'MOD D
62 .S EC66A=$G(^LAB(66,MOD,0)) I EC66A="" Q
63 .S STR3=$S($P(EC66A,U,6)'="":$P(EC66A,U,6),1:$$CHKMOD^ECXLBB1($P(EC66A,"^")))
64 .I STR3'="",MODSTR'[STR3 S MODSTR=MODSTR_STR3
65 Q MODSTR
66MODIFIED() ; Was unit modified
67 ; Init variables
68 N XMATCH,UNIT,MOD,COMPID,MODNODE,MODTO
69 S (XMATCH,UNIT)=0,MOD=""
70 ; Check input
71 Q:'$G(ECLRDFN)!'$P(EC0,U,2) "N"
72 ;Find xmatch for blood component request
73 S XMATCH=$O(^LR(ECLRDFN,1.8,$P(EC0,U,2),1,XMATCH)) Q:'XMATCH "N"
74 ;Get blood inventory file (#65) pointer
75 S UNIT=$P($G(^LR(ECLRDFN,1.8,$P(EC0,"^",2),1,XMATCH,0)),U)
76 ;Look at disposition field (#4.1) in blood inventory file (#65)
77 S MOD=$P($G(^LRD(65,+XMATCH,4)),U),COMPID=$P(EC66,U,3)
78 ; Get 'the modified to' entry pointer to blood inventory file (#66)
79 I MOD="MO" S MODTO=0 F S MODTO=$O(^LRD(65,+XMATCH,9,MODTO)) Q:'MODTO D
80 .S MODNODE=$G(^LRD(65,+XMATCH,9,MODTO,0)) Q:$P(^(0),U,3)'>1
81 .Q:$P(MODNODE,U,2)'=COMPID
82 .; Set the modify to unit ien for file (#66)
83 Q $S(MOD="MO":"Y",1:"N")
84GETRPRV ; get requesting provider, requesting provider person class and
85 ; production division code
86 ; input: ECD =INVERTED DATE SUBSCRIPT
87 ; ECARRY(1)=TRANSFUSION DATE AND TIME
88 ; note: Accessioned data in file #68 is stored up to 90 days.
89 N ECXBNOD,ACC,ACCDT,ACCNODE,PERCLS
90 I ECARRY(1)="" Q ;there is no transfusion date
91 ;get BLOOD BANK record, field #1, in file #63 located on "BB" node
92 ;since there is a slight time lapse, $O will find the BB record
93 S ECXBNOD=$O(^LR(ECLRDFN,"BB",ECD)) I ECXBNOD="" Q
94 S ECXBNOD=^LR(ECLRDFN,"BB",ECXBNOD,0) I ECXBNOD="" Q
95 ;Compose accession number,originating from field #.06 subfile #63.01
96 ; ex. ACC=BB 0528 27
97 S ACC=$P(ECXBNOD,U,6),ACC=$TR($P(ACC," ",2,99)," ")
98 S ACCDT=$E(ECARRY(1),1,3)_$E(ACC,1,4),NUM=$E(ACC,5,99)
99 ;Get field #2 from file #68, field #1 from subfile #68.01 which is
100 ;subfile #68.02. Look at 29=blood bank ien, from 0th node, get fields
101 ;#6.5 PROVIDER and #26 DIV
102 I (ACCDT)=""!(NUM="") Q
103 ; identify bb accession area the patient was in to get the right DIV
104 S AREA=$$AREA
105 S ACCNODE=$G(^LRO(68,+AREA,1,ACCDT,1,NUM,0))
106 S ECARRY(9)=$P(ACCNODE,U,8) I ECARRY(9)'="" D
107 . S PERCLS=$$GET^XUA4A72(ECARRY(9),ACCDT)
108 . I +PERCLS>0 S ECARRY(10)=$P(PERCLS,U,7)
109 . S ECREQNPI=$$NPI^XUSNPI("Individual_ID",ECARRY(9),ACCDT)
110 . S:+ECREQNPI'>0 ECREQNPI="" S ECREQNPI=$P(ECREQNPI,U)
111 . S ECARRY(9)=2_ECARRY(9)
112 S DIV=$P($G(^LRO(68,+AREA,1,ACCDT,1,NUM,.4)),U)
113 I DIV'="" S ECARRY(13)=$$RADDIV^ECXDEPT(DIV)
114 Q
115AREA() ; resolve accession area's ien to use and validate
116 ; Accession number
117 ; Patient LRDFN
118 ; note: if there is only one accession area use '29'
119 N A,CNT,BBLIST,DFN,ACC,AREA,DATE,TDATE,ACCNODE
120 S (CNT,FLAG,A)=0,DFN=""
121 ; set the date from the "bb" node in file (#63)
122 S DATE=$P(ECXBNOD,U)
123 ; setup array for bb accession areas if more than one
124 F S A=$O(^LRO(68,A)) Q:'A I $P($G(^LRO(68,A,0)),"^",2)="BB" D
125 . S BBLIST(A)=""
126 . S CNT=CNT+1
127 I CNT'>1 Q 29
128 S AREA=0 F S AREA=$O(BBLIST(AREA)) Q:'AREA D Q:FLAG
129 . ; get additional accession information for validation
130 . S ACCNODE=$G(^LRO(68,AREA,1,$P(DATE,"."),1,NUM,0))
131 . S ACC=$G(^LRO(68,AREA,1,$P(DATE,"."),1,NUM,.2))
132 . S DFN=$P($G(ACCNODE),U)
133 . S TDATE=$P($G(^LRO(68,AREA,1,$P(DATE,"."),1,NUM,3)),U)
134 . I (DFN=ECLRDFN)&(ACC=$P(ECXBNOD,U,6))&(DATE=TDATE) S FLAG=1
135 Q AREA
136GETDATA ; gather rest of extract data that will be recorded in an
137 ; entry in file 727.829
138 S ECTRFDT=$$ECXDOB^ECXUTL(ECARRY(1)),ECTRFTM=$$ECXTIME^ECXUTL(ECARRY(1))
139 S ECX=$$INP^ECXUTL2(ECXDFN,ECARRY(1)),ECINOUT=$P(ECX,U),ECTRSP=$P(ECX,U,3),ECADMT=$P(ECX,U,4) ; [FLD #5]
140 ;
141 ;- Observation patient indicator (YES/NO)
142 S ECXOBS=$$OBSPAT^ECXUTL4(ECINOUT,ECTRSP)
143 ;- If no encounter number don't file record
144 S ECENCTR=$$ENCNUM^ECXUTL4(ECINOUT,ECPAT("SSN"),ECADMT,ECARRY(1),ECTRSP,ECXOBS,ECHEAD,,) ; [FLD #6]
145 Q:ECENCTR=""
146 ;get emergency response indicator (FEMA)
147 S ECXERI=ECPAT("ERI")
148 ;
149 S ECXSTR=$G(EC23)_"^"_ECINST_"^"_ECXDFN_"^"_ECPAT("SSN")_"^"_ECPAT("NAME")_"^"_ECINOUT_"^"_ECENCTR_"^"_ECTRFDT_"^"_ECTRFTM_"^"_ECARRY(3)_"^"_ECARRY(4)_"^"_ECARRY(5)_"^"_ECARRY(7)_"^"_ECARRY(6)_"^"_ECARRY(8)_"^BB"_ECARRY(13)_"^^"
150 I $G(ECXLOGIC)>2005 S ECXSTR=ECXSTR_U_ECXPHY_U_ECXPHYPC
151 I $G(ECXLOGIC)>2006 D
152 .S ECXSTR=ECXSTR_U_ECXERI_U_ECARRY(11)_U_ECARRY(12)_U_ECARRY(9)_U_ECARRY(10)_U_ECARRY(13)_U
153 I '$D(ECXRPT) D FILE(ECXSTR) Q
154 S ^TMP("ECXLBB",$J,ECXDFN,ECD)=ECXSTR ;temporary global array
155 ; used in ECXPLBB (pre-extract audit report)
156 Q
157GETDFN(ECXLRDFN) ;
158 ; INPUT - LRDFN
159 ; OUTPUT - DFN
160 ; Obtains DFN (Patient ID) from LRDFN (Lab Patient ID).
161 ; If no valid DFN exists, 0 is returned.
162 S ECXLRDFN=+$G(ECXLRDFN)
163 I $P($G(^LR(ECXLRDFN,0)),"^",2)'=2 Q 0
164 Q +$P(^LR(ECXLRDFN,0),"^",3)
165 ;
166PAT(ECXDFN) ;get/set patient data
167 ; INPUT - ECXDFN = patient ien (DFN)
168 ; OUTPUT - ECPAT array:
169 ; ECPAT("SSN")
170 ; ECPAT("NAME")
171 ; returns 0 or 1 in ECXERR - 0=successful
172 ; 1=error condition
173 N X,OK,ECXERR
174 ;get data
175 S ECXERR=0
176 K ECXPAT S OK=$$PAT^ECXUTL3(ECXDFN,"","1;3",.ECPAT)
177 I 'OK S ECXERR=1
178 Q ECXERR
179 ;
180FILE(ECODE) ;
181 ; Input - ECODE = extract record
182 ;
183 ; record the extract record at a global node in file 727.829
184 ; sequence #^year/month of extract^extract #^facility^patient dfn^SSN^
185 ; name^i/o pt indicator^encounter #^date of transfusion^time of
186 ; transfusion^component^component abbrev^# of units^volume in mm^
187 ; reaction^reaction type^feeder location^DSS product dept^DSS IP #
188 ; ordering physician^ordering physician pc^emergency response indicator
189 ; (FEMA)^unit modified^unit modification^requesting provider^request.
190 ; provider person class^ordering provider npi ECPHYNPI
191 ;ECODE1- requesting provider npi ECREQNPI
192 ;note: DSS product dept and DSS IP # are dependent on the release of
193 ; ECX*3*61
194 N DA,DIK,EC7
195 S EC7=$O(^ECX(ECFILE,999999999),-1),EC7=EC7+1
196 S ECODE=EC7_"^"_ECODE
197 I ECXLOGIC>2007 D
198 .S ECODE=ECODE_ECPHYNPI_U
199 .S ECODE1=$G(ECREQNPI)
200 S ^ECX(ECFILE,EC7,0)=ECODE,^ECX(ECFILE,EC7,1)=$G(ECODE1),ECRN=ECRN+1
201 S DA=EC7,DIK="^ECX("_ECFILE_"," D IX1^DIK K DIK,DA
202 Q
203 ;
204 ;
205SETUP ;Set required input for ECXTRAC.
206 S ECHEAD="LBB"
207 D ECXDEF^ECXUTL2(ECHEAD,.ECPACK,.ECGRP,.ECFILE,.ECRTN,.ECPIECE,.ECVER)
208 Q
209 ;
210LOCAL ; to extract nightly for local use not to be transmitted to TSI
211 ; should be queued with a 1D frequency
212 D SETUP,^ECXTLOCL,^ECXKILL Q
213 ;
214QUE ; entry point for the background requeuing handled by ECXTAUTO
215 D SETUP,QUE^ECXTAUTO,^ECXKILL
216 Q
217 ;
218 ;ECXLBB
Note: See TracBrowser for help on using the repository browser.