1 | C0CENC ; CCDCCR/GPL - CCR/CCD PROCESSING FOR ENCOUNTERS ; 05/21/10
|
---|
2 | ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
|
---|
3 | ;Copyright 2010 George Lilly, University of Minnesota and others.
|
---|
4 | ;
|
---|
5 | ; This program is free software: you can redistribute it and/or modify
|
---|
6 | ; it under the terms of the GNU Affero General Public License as
|
---|
7 | ; published by the Free Software Foundation, either version 3 of the
|
---|
8 | ; License, or (at your option) any later version.
|
---|
9 | ;
|
---|
10 | ; This program is distributed in the hope that it will be useful,
|
---|
11 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | ; GNU Affero General Public License for more details.
|
---|
14 | ;
|
---|
15 | ; You should have received a copy of the GNU Affero General Public License
|
---|
16 | ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | ;
|
---|
18 | W "NO ENTRY FROM TOP",!
|
---|
19 | Q
|
---|
20 | ;
|
---|
21 | EXTRACT(ENCXML,DFN,ENCOUT) ; EXTRACT ENCOUNTERS INTO XML TEMPLATE
|
---|
22 | ; ENCXML AND ENCOUT ARE PASSED BY NAME SO GLOBALS CAN BE USED
|
---|
23 | ;
|
---|
24 | D SETVARS^C0CPROC ; SET UP VARIABLES FOR PROCEDUCRES, ENCOUNTERS, AND NOTES
|
---|
25 | ;I '$D(@C0CENC) D TIUGET(DFN,C0CENC,C0CPRC,C0CNTE) ; GET VARS IF NOT THERE
|
---|
26 | K @C0CENC
|
---|
27 | D TIUGET(DFN,C0CENC,C0CPRC,C0CNTE) ; GET ENCOUNTERS
|
---|
28 | D MAP(ENCXML,C0CENC,ENCOUT) ;MAP RESULTS FOR ENCOUNTERS
|
---|
29 | Q
|
---|
30 | ;
|
---|
31 | TIUGET(DFN,C0CENC,C0CPRC,C0CNTE) ; CALLS ENTRY^C0CCPT TO GET PROCEDURES,
|
---|
32 | ; ENCOUNTERS AND NOTES. RETURNS THEM IN RNF2 ARRAYS PASSED BY NAME
|
---|
33 | ; C0CENC: ENCOUNTERS, C0CPRC: PROCEDURES, C0CNTE: NOTES
|
---|
34 | ; READY TO BE MAPPED TO XML BY MAP^C0CENC, MAP^C0CPROC, AND MAP^C0CCMT
|
---|
35 | ; THESE RETURN ARRAYS ARE NOT INITIALIZED, BUT ARE ADDED TO IF THEY
|
---|
36 | ; EXIST. THIS IS SO THAT ADDITIONAL PROCEDURES CAN BE OBTAINED FROM
|
---|
37 | ; THE SURGERY PACKGE AND ADDITIONAL COMMENTS FROM OTHER CCR SECTIONS
|
---|
38 | ;
|
---|
39 | ;K VISIT,LST,NOTE
|
---|
40 | I '$D(C0CPRC) D SETVARS^C0CPROC ; INITIALIZE WORK AREAS IF NOT ALREADY THERE
|
---|
41 | I '$D(VISIT) D ENTRY^C0CCPT(DFN,,,1) ; RETURNS VISIT LOCAL VARIABLE
|
---|
42 | ; NEED TO ADD START AND END DATES FROM PARAMETERS
|
---|
43 | N ZI S ZI=""
|
---|
44 | N PREVCPT,PREVDT S (PREVCPT,PREVDT)=""
|
---|
45 | F S ZI=$O(VISIT(ZI),-1) Q:ZI="" D ; REVERSE TIME ORDER - MOST RECENT FIRST
|
---|
46 | . N ZDATE
|
---|
47 | . S ZDATE=$$DATE(VISIT(ZI,"DATE",0))
|
---|
48 | . S ZPRVARY=$NA(VISIT(ZI,"PRV"))
|
---|
49 | . N ZPRV
|
---|
50 | . S ZPRV=$$PRV(ZPRVARY) ; THE PRIMARY PROVIDER OBJECT IN THE FORM
|
---|
51 | . ; ACTORPROVIDER_IEN WHERE IEN IS THE PROVIDER IEN IN NEW PERSON
|
---|
52 | . ; ENCOBJECTID - ENCOUNTER OBJECT ID
|
---|
53 | . ; ENCDATETIME - ENCOUNTER DATE TIME
|
---|
54 | . ; ENCTYPETXT - ENCOUNTER TYPE (PLANNING TO USE ADMINISTRATIVE CPT IF AVAIL)
|
---|
55 | . ; ENCTYPECODE - CODE OF TYPE - PLANNING CPT CODE
|
---|
56 | . ; ENCTYPECODESYS - CODING SYSTEM OF TYPE - CPT-4
|
---|
57 | . ; ENCDESCTXT - ENCOUNTER DESCRIPTION TEXT
|
---|
58 | . ; ENCDESCCODE - ENCOUNTER DESCRIPTION CODE
|
---|
59 | . ; ENCDESCCODESYS - ENCOUNTER DESCRIPTION CODE SYSTEM
|
---|
60 | . ; ENCLOCACTORID - ENCOUNTER LOCATION ACTOR ID
|
---|
61 | . ; ENCPRVACTORID - ENCOUNTER PRACTIONER ACTOR ID
|
---|
62 | . ; ENCINDTXT - ENCOUNTER INDICATION TEXT
|
---|
63 | . ; ENCINDCODE - ENCOUNTER INDICATION CODE
|
---|
64 | . ; ENCINDCODESYS - ENCOUNTER INDICATION CODE SYSTEM
|
---|
65 | . ; ENCACTORID - ENCOUNTER SOURCE ACTOR ID
|
---|
66 | . ; ENCCOMMENTID - ENCOUNTER COMMENT ID - POINTER TO NOTE IN COMMENT SECTION
|
---|
67 | . S ZRNF("ENCOBJECTID")="ENCOUNTER_"_ZI
|
---|
68 | . S ZRNF("ENCDATETIME")=ZDATE ; ENCOUNTER DATE TIME
|
---|
69 | . S ZRNF("ENCTYPETXT")=""
|
---|
70 | . S ZRNF("ENCTYPECODE")=""
|
---|
71 | . S ZRNF("ENCTYPECODESYS")=""
|
---|
72 | . S ZRNF("ENCDESCTXT")=""
|
---|
73 | . S ZRNF("ENCDESCCODE")=""
|
---|
74 | . S ZRNF("ENCDESCCODESYS")=""
|
---|
75 | . N TYPTXT,TYPCDE,TYPSYS ; WILL BE UPDATED BY GETTYPE CALL
|
---|
76 | . I $$GETTYPE("VISIT(ZI)",.TYPTXT,.TYPCDE,.TYPSYS) D ; RETURNS FALSE IF NO TYPE
|
---|
77 | . . S ZRNF("ENCTYPETXT")=TYPTXT
|
---|
78 | . . S ZRNF("ENCTYPECODE")=TYPCDE
|
---|
79 | . . S ZRNF("ENCTYPECODESYS")=TYPSYS
|
---|
80 | . . S ZRNF("ENCDESCTXT")=TYPTXT ; FOR NOW, DESCRIPTION IS SAME AS TYPE
|
---|
81 | . . S ZRNF("ENCDESCCODE")=TYPCDE ; DESCRIPTION IS REQUIRED (TYPE IS NOT)
|
---|
82 | . . S ZRNF("ENCDESCCODESYS")=TYPSYS ; NEED TO CLARIFY FOR VISTA
|
---|
83 | . S ZRNF("ENCLOCACTORID")="ACTORORGANIZATION_1"
|
---|
84 | . S ZRNF("ENCPRVACTORID")=ZPRV ; PRIMARY PROVIDER LISTED FOR THE ENCOUNTER
|
---|
85 | . S ZRNF("ENCINDTXT")="" ; WE WILL PUT POINTERS TO PROBLEMS HERE
|
---|
86 | . S ZRNF("ENCINDCODE")=""
|
---|
87 | . S ZRNF("ENCINDCODESYS")=""
|
---|
88 | . S ZRNF("ENCACTORID")=ZPRV ; SOURCE WILL BE PRIMARY PROVIDER
|
---|
89 | . S ZRNF("ENCCOMMENTID")=""
|
---|
90 | . I $G(VISIT(ZI,"TEXT",1))'="" D ; THERE IS A NOTE
|
---|
91 | . . M @C0CNTE@(ZI,"TEXT")=VISIT(ZI,"TEXT") ; COPY THE TEXT OF THE NOTE
|
---|
92 | . . S @C0CNTE@(ZI,"COMMENTOBJECTID")="NOTE_"_ZI
|
---|
93 | . . S @C0CNTE@(ZI,"CMTDATETIME")=ZDATE ; DATE OF THE NOTE
|
---|
94 | . . S @C0CNTE@(ZI,"ACTORSOURCEID")=ZPRV ; SOURCE OF THE NOTE
|
---|
95 | . . S ZRNF("ENCCOMMENTID")="NOTE_"_ZI ; POINT TO THE NOTE FROM THE ENCOUNTER
|
---|
96 | . D RNF1TO2^C0CRNF(C0CENC,"ZRNF") ; ADD THIS ROW TO THE ARRAY
|
---|
97 | . ;S PREVCPT=ZCPT
|
---|
98 | . ;S PREVDT=ZDATE
|
---|
99 | N ZRIM S ZRIM=$NA(^TMP("C0CRIM","VARS",DFN,"ENCOUNTERS"))
|
---|
100 | M @ZRIM=@C0CENC@("V")
|
---|
101 | K VISIT,LST,NOTE
|
---|
102 | Q
|
---|
103 | ;
|
---|
104 | GETTYPE(ZARY,ZTXT,ZCDE,ZSYS) ; EXTRINSIC WHICH RETURNS FALSE IF NO ENCOUNTER TYPE
|
---|
105 | ; UPDATES ZTXT WITH ENCOUNTER TYPE TEXT, ZCDE WITH ENCOUNTER TYPE CODE
|
---|
106 | ; AND ZSYS WITH ENCOUNTER TYPE CODING SYSTEM
|
---|
107 | ; THIS ROUTINE SHOULD BE UPDATED TO SEARCH FOR AN ADMINISTRATIVE CPT CODE
|
---|
108 | ; INSTEAD OF JUST THE FIRST ONE IN THE LIST - GPL 1/23/10
|
---|
109 | N ZS,ZC
|
---|
110 | S ZC="" S ZS=""
|
---|
111 | S (ZTXT,ZCDE,ZSYS)=""
|
---|
112 | F S ZC=$O(@ZARY@("CPT",ZC)) Q:ZC="" D ; TRY AND FIND A "99" CPT CODE
|
---|
113 | . N ZT
|
---|
114 | . S ZT=$$CPT^C0CPROC(@ZARY@("CPT",ZC)) ; VALUES IN A CPT MULTIPLE
|
---|
115 | . I $E($P(ZT,U,1),1,2)="99" S ZS=ZT ; IS IT AN ADMIN CPT CODE?
|
---|
116 | I ZS'="" D ; CODED ENCOUNTER TYPE FOUND
|
---|
117 | . S ZTXT=$P(ZS,U,2)_" "_$P(ZS,U,3) ; USE BOTH PIECES FOR THE TYPE
|
---|
118 | . S ZCDE=$P($$CPT^C0CPROC(ZS),U,1) ; CPT CODE FOR ENCOUTER
|
---|
119 | . S ZSYS=""
|
---|
120 | . I ZCDE'="" S ZSYS="CPT-4" ; ONLY HAVE A CODING SYSTEM IF THERE IS A CODE
|
---|
121 | I ZS="" S ZTXT=$$ANYTXT(ZARY) ; TRY AND GET FREE FORM TEXT FROM CPT MULTIPLES
|
---|
122 | I ZTXT="" Q 0 ; FAILED
|
---|
123 | W !,ZTXT
|
---|
124 | Q 1 ; SUCCESS
|
---|
125 | ;
|
---|
126 | ANYTXT(ZVST) ; EXTRINSIC WHICH RETURNS TEXT FROM THE CPT MULTIPLE
|
---|
127 | ; OF A VISIT ARRAY WITHOUT CHECKING THE CPT CODE (THAT HAVING FAILED)
|
---|
128 | ; ZVST IS THE VISIT ARRAY AND IS PASSED BY NAME
|
---|
129 | ; RETURNS TEXT TO USE AS ENCOUNTER TYPE IF ANY
|
---|
130 | N ZK,ZL
|
---|
131 | S ZK="" S ZL=""
|
---|
132 | F S ZK=$O(@ZVST@("CPT",ZK)) Q:ZK="" D ; LOOK FOR SOME TEXT TO USE
|
---|
133 | . N ZT
|
---|
134 | . S ZT=$G(@ZVST@("CPT",ZK)) ; LOOK AT THIS CPT MULTIPLE
|
---|
135 | . I $P(ZT,U,2)_" "_$P(ZT,U,3)'=" " S ZL=$P(ZT,U,2)_" "_$P(ZT,U,3)
|
---|
136 | . ; CONCATENATE PIECE 2 AND 3 OF THE CPT MULTIPLE FOR A TYPE
|
---|
137 | I ZL="" S ZL=$G(@ZVST@("CLASS")) ; USE THE NOTE DOCUMENT CLASS FOR ENCOUTNER TYPE
|
---|
138 | Q ZL
|
---|
139 | ;
|
---|
140 | PRV(IARY) ; RETURNS THE PRIMARY PROVIDER FROM THE "PRV" ARRAY PASSED BY NAME
|
---|
141 | N ZI,ZR,ZRTN S ZI="" S ZR="" S ZRTN=""
|
---|
142 | F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ; FOR EACH PRV SEG
|
---|
143 | . I ZR'="" Q ;ONLY WANT THE FIRST PRIMARY PROVIDER
|
---|
144 | . I $P(@IARY@(ZI),U,5)=1 S ZR=$P(@IARY@(ZI),U,1)
|
---|
145 | I ZR'="" S ZRTN="ACTORPROVIDER_"_ZR
|
---|
146 | Q ZRTN
|
---|
147 | ;
|
---|
148 | DATE(ISTR) ; EXTRINSIC TO RETURN THE DATE IN CCR FORMAT
|
---|
149 | Q $$FMDTOUTC^C0CUTIL(ISTR,"DT")
|
---|
150 | ;
|
---|
151 | CPT(ISTR) ; EXTRINSIC THAT SEARCHES FOR CPT CODES AND RETURNS
|
---|
152 | ; CPT^CATEGORY^TEXT
|
---|
153 | N Z1,Z2,Z3,ZRTN
|
---|
154 | S Z1=$P(ISTR,U,1)
|
---|
155 | I Z1="" D ;
|
---|
156 | . I ISTR["(CPT-4 " S Z1=$P($P(ISTR,"(CPT-4 ",2),")",1)
|
---|
157 | I Z1'="" D ; IF THERE IS A CPT CODE IN THERE
|
---|
158 | . ;S Z1=$P(ISTR,U,1)
|
---|
159 | . S Z2=$P(ISTR,U,2)
|
---|
160 | . S Z3=$P(ISTR,U,3)
|
---|
161 | . S ZRTN=Z1_U_Z2_U_Z3
|
---|
162 | E S ZRTN=""
|
---|
163 | Q ZRTN
|
---|
164 | ;
|
---|
165 | MAP(ENCXML,C0CENC,ENCOUT) ; MAP PROCEDURES XML
|
---|
166 | ;
|
---|
167 | N ZTEMP S ZTEMP=$NA(^TMP("C0CCCR",$J,DFN,"ENCTEMP")) ;WORK AREA FOR TEMPLATE
|
---|
168 | K @ZTEMP
|
---|
169 | N ZBLD
|
---|
170 | S ZBLD=$NA(^TMP("C0CCCR",$J,DFN,"ENCBLD")) ; BUILD LIST AREA
|
---|
171 | D QUEUE^C0CXPATH(ZBLD,ENCXML,1,1) ; FIRST LINE
|
---|
172 | N ZINNER
|
---|
173 | D QUERY^C0CXPATH(ENCXML,"//Encounters/Encounter","ZINNER") ;ONE ENCOUNTER
|
---|
174 | N ZTMP,ZVAR,ZI
|
---|
175 | S ZI=""
|
---|
176 | F S ZI=$O(@C0CENC@("V",ZI)) Q:ZI="" D ;FOR EACH ENCOUNTER
|
---|
177 | . S ZTMP=$NA(@ZTEMP@(ZI)) ;THIS ENCOUNTER XML
|
---|
178 | . S ZVAR=$NA(@C0CENC@("V",ZI)) ;THIS ENCOUNTER VARIABLES
|
---|
179 | . D MAP^C0CXPATH("ZINNER",ZVAR,ZTMP) ; MAP THE PROCEDURE
|
---|
180 | . D QUEUE^C0CXPATH(ZBLD,ZTMP,1,@ZTMP@(0)) ;QUE FOR BUILD
|
---|
181 | D QUEUE^C0CXPATH(ZBLD,ENCXML,@ENCXML@(0),@ENCXML@(0))
|
---|
182 | N ZZTMP
|
---|
183 | D BUILD^C0CXPATH(ZBLD,ENCOUT) ;BUILD FINAL XML
|
---|
184 | K @ZTEMP,@ZBLD,@C0CENC
|
---|
185 | Q
|
---|
186 | ;
|
---|