source: ccr/branches/ohum/p/C0CRARPT.m@ 1476

Last change on this file since 1476 was 1433, checked in by Sam Habiel, 12 years ago

Update based on OHUM's latest routines

File size: 9.3 KB
RevLine 
[1428]1C0CRARPT ; C0C/ELN - CCR/CCD PROCESSING FOR RAD REPORT ; 19/10/2010
[1433]2 ;;1.2;C0C;;May 11, 2012;Build 47
[1428]3MAP(MIXML,DFN,MOXML) ;TO MAKE THIS COMPATIBLE WITH OLD CALLING FOR EXTRACT
4 ; ASSUMES THAT EXTRACT HAS BEEN RUN AND THE VARIABLES STORED IN MIVAR
5 ; MIXML,MIVAR, AND MOXML ARE PASSED BY NAME
6 ; MIXML IS THE TEMPLATE TO USE
7 ; MOXML IS THE OUTPUT XML ARRAY
8 ; DFN IS THE PATIENT RECORD NUMBER
9 N C0COXML,C0CO,C0CV,C0CIXML
10 I '$D(MIVAR) S C0CV="" ;DEFAULT
11 E S C0CV=MIVAR ;PASSED VARIABLE ARRAY
12 I '$D(MIXML) S C0CIXML="" ;DEFAULT
13 E S C0CIXML=MIXML ;PASSED INPUT XML
14 D RPCMAP(.C0COXML,DFN,C0CV,C0CIXML) ; CALL RPC TO DO THE WORK
15 I '$D(MOXML) D Q
16 . S C0CO=$NA(^TMP("C0CCCR",$J,DFN,"RESULTS")) ;DEFAULT FOR OUTPUT
17 . M @C0CO=C0COXML ; COPY RESULTS TO OUTPUT
18 E D
19 . N C0COOXML
20 . S CCRGLO=$NA(^TMP("C0CCCR",$J,DFN,"CCR"))
21 . D QUERY^C0CXPATH(CCRGLO,"//ContinuityOfCareRecord/Body/Results","C0CRSXML")
22 . S C0COCNT=$O(C0CRSXML(""),-1)
23 . S C0CRES=0
24 . F S C0CRES=$O(C0COXML(C0CRES)) Q:C0CRES="" D
25 . . Q:$G(C0COXML(C0CRES))="<Results>"!($G(C0COXML(C0CRES))="</Results>")
26 . . S C0CRSXML(C0COCNT)=$G(C0COXML(C0CRES))
27 . . S C0COCNT=C0COCNT+1
28 . S C0CRSXML(C0COCNT)="</Results>"
29 . S C0CRSXML(0)=C0COCNT
30 . D REPLACE^C0CXPATH(CCRGLO,"","//ContinuityOfCareRecord/Body")
31 . D INSERT^C0CXPATH(CCRGLO,"C0CRSXML","//ContinuityOfCareRecord/Body")
32 S C0CO=MOXML,@C0CO@(0)=0
33 K C0CRSXML,C0COCNT,C0COXML,C0CRES
34 Q
35RPCMAP(RTN,DFN,RMIVAR,RMIXML) ; RPC ENTRY POINT FOR MAPPING RESULTS
36 ; RTN IS PASSED BY REFERENCE
37 N C0CT0,C0CT,C0CV ; CCR TEMPLATE, RESULTS SUBTEMPLATE, VARIABLES
38 N C0CRT,C0CTT ; TEST REQUEST TEMPLATE, TEST RESULT TEMPLATE
39 I '$D(DEBUG) S DEBUG=0 ; DEFAULT NO DEBUGGING
40 I RMIXML="" D ; INPUT XML NOT PASSED
41 . D LOAD^C0CCCR0("C0CT0") ; LOAD ENTIRE CCR TEMPLATE
42 . D QUERY^C0CXPATH("C0CT0","//ContinuityOfCareRecord/Body/Results","C0CT0R")
43 . S C0CT="C0CT0R" ; NAME OF EXTRACTED RESULTS TEMPLATE
44 E S C0CT=RMIXML ; WE ARE PASSED THE RESULTS PART OF THE TEMPLATE
45 I RMIVAR="" D ; LOCATION OF VARIABLES NOT PASSED
46 . S C0CV=$NA(^TMP("C0CCCR",$J,"RESULTS")) ;DEFAULT VARIABLE LOCATION
47 E S C0CV=RMIVAR ; PASSED LOCATIONS OF VARS
48 D CP^C0CXPATH(C0CT,"C0CRT") ; START MAKING TEST REQUEST TEMPLATE
49 D REPLACE^C0CXPATH("C0CRT","","//Results/Result/Test") ; DELETE TEST FROM REQ
50 D QUERY^C0CXPATH(C0CT,"//Results/Result/Test","C0CTT") ; MAKE TEST TEMPLATE
51 D EXTRACT("C0CT",DFN,) ; FIRST CALL EXTRACT
52 I '$D(@C0CV@(0)) D Q ; NO VARS THERE
53 . S RTN(0)=0 ; PASS BACK NO RESULTS INDICATOR
54 ; NO RESULTS
55 I @C0CV@(0)=0 S RTN(0)=0 Q
56 S RIMVARS=$NA(^TMP("C0CRIM","VARS",DFN,"RESULTS"))
57 K @RIMVARS
58 M @RIMVARS=@C0CV ; UPDATE RIMVARS SO THEY STAY IN SYNCH
59 N C0CI,C0CIN,C0CJ,C0CJE,C0CJS,C0CJN,C0CMAP,C0CTMAP,C0CTMP
60 S C0CIN=@C0CV@(0) ; COUNT OF RESULTS (OBR)
61 N C0CRTMP ; AREA TO BUILD ONE RESULT REQUEST AND ALL TESTS FOR IT
62 N C0CRBASE S C0CRBASE=$NA(^TMP($J,"TESTTMP")) ;WORK AREA
63 N C0CRBLD ; BUILD LIST FOR XML - THE BUILD IS DELAYED UNTIL THE END
64 ; TO IMPROVE PERFORMANCE
65 D QUEUE^C0CXPATH("C0CRBLD","C0CRT",1,1) ;<Results>
66 F C0CI=1:1:C0CIN D ; LOOP THROUGH VARIABLES
67 . K C0CMAP,C0CTMP ;EMPTY OUT LAST BATCH OF VARIABLES
68 . S C0CRTMP=$NA(@C0CRBASE@(C0CI)) ;PARTITION OF WORK AREA FOR EACH TEST
69 . S C0CMAP=$NA(@C0CV@(C0CI)) ;
70 . D MAP^C0CXPATH("C0CRT",C0CMAP,C0CRTMP) ; MAP OBR DATA
71 . D QUEUE^C0CXPATH("C0CRBLD",C0CRTMP,2,@C0CRTMP@(0)-4) ;UP TO <Test>
72 . I $D(@C0CMAP@("M","TEST",0)) D ; TESTS EXIST
73 . . S C0CJN=@C0CMAP@("M","TEST",0) ; NUMBER OF TESTS
74 . . K C0CTO ; CLEAR OUTPUT VARIABLE
75 . . F C0CJ=1:1:C0CJN D ;FOR EACH TEST RESULT
76 . . . K C0CTMAP ; EMPTY MAPS FOR TEST RESULTS
77 . . . S C0CTMP=$NA(@C0CRBASE@(C0CI,C0CJ)) ;WORK AREA FOR TEST RESULTS
78 . . . S C0CTMAP=$NA(@C0CMAP@("M","TEST",C0CJ)) ;
79 . . . D MAP^C0CXPATH("C0CTT",C0CTMAP,C0CTMP) ; MAP TO TMP
80 . . . I C0CJ=1 S C0CJS=2 E S C0CJS=1 ;FIRST TIME,SKIP THE <Test>
81 . . . I C0CJ=C0CJN S C0CJE=@C0CTMP@(0)-1 E S C0CJE=@C0CTMP@(0) ;</Test>
82 . . . S C0CJS=1 S C0CJE=@C0CTMP@(0) ; INSERT ALL OF THE TEXT XML
83 . . . D QUEUE^C0CXPATH("C0CRBLD",C0CTMP,C0CJS,C0CJE) ; ADD TO BUILD LIST
84 . D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0)-1,C0CRT(0)-1) ;</Result>
85 D QUEUE^C0CXPATH("C0CRBLD","C0CRT",C0CRT(0),C0CRT(0)) ;</Results>
86 D BUILD^C0CXPATH("C0CRBLD","RTN") ;RENDER THE XML
87 K @C0CRBASE ; CLEAR OUT TEMPORARY STURCTURE
88 Q
89EXTRACT(ILXML,DFN,OLXML) ; EXTRACT RADIOLOGY REPORTS INTO THE C0CLVAR GLOBAL
90 S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR RADS VARS
91 S RADFN=DFN
92 D GHL7^C0CRAHL7 ; GET HL7 MESSAGE FOR THIS PATIENT
93 ;ELN K @C0CLB ; CLEAR OUT OLD VARS IF ANY
94 N QTSAV S QTSAV=$G(C0CQT) ;SAVE QUIET FLAG
95 S C0CQT=1 ; SURPRESS LISTING
96 D LIST ; EXTRACT THE VARIABLES
97 ;S C0CQT=QTSAV ; RESET SILENT FLAG
98 K ^TMP("HLS",$J),^TMP("C0CCCR","RATBL") ; KILL HL7 MESSAGE OUTPUT
99 K C0CLB,C0CLB2,C0CLI,C0CLOBX,RADFN
100 I $D(OLXML) S @OLXML@(0)=0 ; EXTRACT DOES NOT PRODUCE XML... SEE MAP^C0CLABS
101 Q
102LIST ; LIST THE HL7 MESSAGE; ALSO, EXTRACT THE RESULT VARIABLES TO C0CLB
103 N C0CI,C0CJ,C0COBT,C0CHB,C0CVAR,C0CTAB,C0CTYP
104 I '$D(C0CLB) S C0CLB=$NA(^TMP("C0CCCR",$J,"RESULTS")) ; BASE GLB FOR LABS VARS
105 I '$D(C0CQT) S C0CQT=0
106 I '$D(DFN) S DFN=1 ; DEFAULT TEST PATIENT
107 I '$D(^TMP("C0CCCR","RATBL",0))!($G(^TMP("C0CCCR","RATBL",0))'="V3") D
108 . D SETTBL^C0CLABS ;INITIALIZE LAB TABLE
109 . K ^TMP("C0CCCR","RATBL")
110 . M ^TMP("C0CCCR","RATBL")=^TMP("C0CCCR","LABTBL")
111 I '$D(^TMP("HLS",$J,1)) D GHL7^C0CRAHL7 ; GET HL7 MGS IF NOT ALREADY DONE
112 S C0CTAB=$NA(^TMP("C0CCCR","RATBL")) ; BASE OF OBX TABLE
113 S C0CHB=$NA(^TMP("HLS",$J))
114 S C0CI=""
115 S @C0CLB@(0)=$O(^TMP("C0CCCR",$J,"RESULTS",""),-1) ; INITALIZE RESULTS VARS COUNT
116 F S C0CI=$O(@C0CHB@(C0CI)) Q:C0CI="" D ; FOR ALL RECORDS IN HL7 MSG
117 . K C0CVAR,XV ; CLEAR OUT VARIABLE VALUES
118 . S C0CTYP=$P(@C0CHB@(C0CI),"|",1)
119 . D LTYP^C0CLABS(@C0CHB@(C0CI),C0CTYP,.C0CVAR,C0CQT)
120 . M XV=C0CVAR ;
121 . I C0CTYP="OBR" D ; BEGINNING OF NEW SECTION
122 . . S @C0CLB@(0)=@C0CLB@(0)+1 ; INCREMENT COUNT
123 . . S C0CLI=@C0CLB@(0) ; INDEX FOR THIS RESULT
124 . . ;M @C0CLB@(C0CLI)=C0CVAR ; PERSIST THE OBR VARS
125 . . S XV("RESULTOBJECTID")="RESULT_"_C0CLI
126 . . S C0CX1=XV("RESULTSOURCEACTORID") ; SOURCE FROM OBR
127 . . S XV("RESULTSOURCEACTORID")="ACTORPROVIDER_"_$P($P(C0CX1,"^",1),"-",1)
128 . . S C0CX1=XV("RESULTASSESSMENTDATETIME") ;DATE TIME IN HL7 FORMAT
129 . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
130 . . S XV("RESULTASSESSMENTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
131 . . M @C0CLB@(C0CLI)=XV ; PERSIST THE OBR VARS
132 . . S C0CLOBX=0 ; MARK THE BEGINNING OF A NEW SECTION
133 . I C0CTYP="OBX" D ; SPECIAL CASE FOR OBX3
134 . . ; RESULTTESTCODEVALUE
135 . . ; RESULTTESTDESCRIPTIONTEXT
136 . . I C0CVAR("C3")="C4" D ; PRIMARY CODE "CPT"
137 . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; THE CPT CODE VALUE
138 . . . S XV("RESULTTESTCODINGSYSTEM")="CPT" ; DISPLAY NAME FOR CPT
139 . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; DESCRIPTION TEXT
140 . . E I C0CVAR("C6")'="" D ; NO CPT CODES, USE SECONDARY IF PRESENT
141 . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C4") ; SECONDARY CODE VALUE
142 . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C6") ; SECONDARY CODE NAME
143 . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C5") ; SECONDARY TEXT
144 . . E D ; NO SECONDARY, USE PRIMARY
145 . . . S XV("RESULTTESTCODEVALUE")=C0CVAR("C1") ; PRIMARY CODE VALUE
146 . . . S XV("RESULTTESTCODINGSYSTEM")=C0CVAR("C3") ; PRIMARY DISPLAY NAME
147 . . . S XV("RESULTTESTDESCRIPTIONTEXT")=C0CVAR("C2") ; USE PRIMARY TEXT
148 . . N C0CZG S C0CZG=XV("RESULTTESTNORMALDESCTEXT") ;
149 . . S XV("RESULTTESTNORMALDESCTEXT")=C0CZG
150 . . S C0CZG=XV("RESULTTESTVALUE")
151 . . S XV("RESULTTESTVALUE")=C0CZG
152 . . I C0CLOBX=0 D ; FIRST TEST RESULT FOR THIS SECTION
153 . . . S C0CLB2=$NA(@C0CLB@(C0CLI,"M","TEST")) ; INDENT FOR TEST RESULTS
154 . . S C0CLOBX=C0CLOBX+1 ; INCREMENT TEST COUNT
155 . . S @C0CLB2@(0)=C0CLOBX ; STORE THE TEST COUNT
156 . . S XV("RESULTTESTOBJECTID")="RESULTTEST_"_C0CLI_"_"_C0CLOBX
157 . . S C0CX1=XV("RESULTTESTSOURCEACTORID") ; TEST SOURCE
158 . . S C0CX2=$P($P(C0CX1,"^",1),"-",1) ; PULL OUT STATION NUMBER
159 . . S XV("RESULTTESTSOURCEACTORID")="ACTORORGANIZATION_"_C0CX2
160 . . S XV("RESULTTESTNORMALSOURCEACTORID")=XV("RESULTTESTSOURCEACTORID")
161 . . S C0CX1=XV("RESULTTESTDATETIME") ;DATE TIME IN HL7 FORMAT
162 . . S C0CX2=$$HL7TFM^XLFDT(C0CX1,"L") ;FM DT LOCAL
163 . . S XV("RESULTTESTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CX2,"DT") ;UTC TIME
164 . . M @C0CLB2@(C0CLOBX)=XV ; PERSIST THE TEST RESULT VARIABLES
165 K XV,C0CZG,C0CX1,C0CX2,C0CVAR
166 Q
Note: See TracBrowser for help on using the repository browser.