source: FOIAVistA/trunk/r/CLINICAL_PROCEDURES-MD/MDCVT.m@ 1582

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

initial load of FOIAVistA 6/30/08 version

File size: 9.2 KB
Line 
1MDCVT ; HOIFO/DP/NCA - Medicine Package Conversion ;10/20/04 12:49
2 ;;1.0;CLINICAL PROCEDURES;**5**;Apr 01, 2004;Build 1
3 ; Integration Agreements:
4 ; IA# 2263 [Supported] XPAR parameter calls.
5 ; IA# 2320 [Supported] %ZISH calls.
6 ; IA#10031 [Supported] DDS call to bring up Screen Man
7 ;
8EN ; [Procedure] Main entry point to convert database to TIU notes
9 N MDCNVT,MDDIR,MDFILE,MDREC,MDTEST,MDTIUI,MDXR,ORHFS,X,Y
10 S (MDCNVT("CR"),MDCNVT("CT"),MDCNVT("E"),MDCNVT("S"),MDCNVT("TOT"))=0
11 I $$GET^XPAR("SYS","MD MEDICINE CONVERTED",1) W !!,"Already Converted" Q
12 I '$P($G(^MDD(703.9,1,0)),U,3) W !!,"No Administrative Closure Person." Q
13 S MDTEST=+$P($G(^MDD(703.9,1,0)),U,2)'=1
14 S MDXR=$O(^MDD(703.9,1,2,"AS","")) I MDXR="" W !!,"No Conversion List. Run Build Conversion List option." Q
15 ;
16 W @IOF,!,"Medicine to Clinical Procedure Conversion"
17 K DIR S DIR(0)="YA"
18 S DIR("A")="Ok to continue? "
19 S DIR("A",1)="Running conversion in "_$S(MDTEST:"TEST",1:"REAL")_" mode.",DIR("B")="NO" D ^DIR K DIR Q:$D(DIRUT)!$D(DIROUT)!(Y<1)
20 ;
21 ; Set up the HFS variables
22 S MDFILE="MDCVT.TXT",MDDIR=$P($G(^MDD(703.9,1,.1)),U)
23 S X=$$TESTHFS() I '+X W !!,"HFS Device Error: ",$P(X,U,2) Q
24 ;
25 ; Last Chance
26 W ! K DIR S DIR(0)="YA"
27 S DIR("A")="Ready to "_$S(MDTEST:"test the conversion of",1:"convert")_" the Medicine Files? "
28 S DIR("B")="NO" D ^DIR K DIR Q:$D(DIRUT)!$D(DIROUT)!(Y<1)
29 ;
30 ; See if previous errors need to be reset
31 W !!,"Conversion in progress...",!
32 D RESET
33 ;
34 ; Set MDREC up here - This prevents loss on M error trap in EN1
35 S MDREC=0
36 ;
37 W !?5,"[.] Indicates converted record"
38 W !?5,"[*] Indicates error in record",!!
39 ;
40EN1 ; [Procedure] Resumes on error via $ETRAP variable
41 N $ESTACK,$ETRAP S $ETRAP="ERR^MDCVT"
42 N MDCONS,MDECON,MDFDA,MDNODE,MDNOTE,MDOK,MDPR,MDR,MDR1,MDSTUD,MDUSR,MDX1
43 F S MDREC=$O(^MDD(703.9,1,2,"AS","R",MDREC)) Q:'MDREC D
44 .S MDPTR=$$GET1^DIQ(703.92,MDREC_",1,",.01) Q:MDPTR=""
45 .S MDGBL=U_$P(MDPTR,";",2)_$P(MDPTR,";",1)_")"
46 .S MDCNVT("TOT")=MDCNVT("TOT")+1
47 .I '$P($G(^MDD(703.9,1,1,+$P(MDGBL,"(",2),0)),U,3) D Q
48 ..D SKIP(MDPTR,"Report type not marked for conversion")
49 ..S MDCNVT("S")=MDCNVT("S")+1
50 .S MDSTAT=$P($G(@MDGBL@("ES")),U,7)
51 .I MDSTAT="" D Q:'MDOK
52 ..S MDOK=+$P($G(^MDD(703.9,1,1,+$P(MDGBL,"(",2),0)),U,4)
53 ..D:'MDOK LOGERR(MDPTR,"Unable to determine status")
54 .I MDSTAT="S" D SKIP(MDPTR,"Report Superseded") S MDCNVT("S")=MDCNVT("S")+1 Q
55 .I MDSTAT["D" D LOGERR(MDPTR,"Report in Draft/Problem Draft status") Q
56 .;I MDSTAT="RNV" D LOGERR(MDPTR,"Report not verified") Q
57 .I MDTEST W "." ; Progress indicator
58 .;
59 .; Produce report using HFS device MDHFS
60 .S %ZIS("HFSNAME")=MDDIR_MDFILE,%ZIS("HFSMODE")="W",IOP="MDHFS;P-MDHFS"
61 .D ^%ZIS I POP D LOGERR(MDPTR,"No HFS Access or device MDHFS") Q
62 .S ORHFS="SCRATCH"
63 .U IO D EN^MCAPI(MDPTR,0) D ^%ZISC
64 .;
65 .; Fetch the report text
66 .K ^TMP($J)
67 .S X=$$FTG^%ZISH(MDDIR,MDFILE,$NA(^TMP($J,1)),2)
68 .;
69 .; Delete the Host File
70 .S DELETE(MDFILE)=""
71 .S X=$$DEL^%ZISH(MDDIR,"DELETE")
72 .; Is it a valid report?
73 .S LINES=$O(^TMP($J,""),-1)
74 .S BYTES=0 F X=0:0 S X=$O(^TMP($J,X)) Q:'X S BYTES=BYTES+$L(^(X))
75 .I LINES<5&(^TMP($J,2)["BAD MEDICINE") D LOGERR(MDPTR,^TMP($J,2)) Q
76 .;
77 .; Get Legal header For Report
78 .S RESULTS=$NA(^TMP($J)) D GETHDR^MDESPRT(.RESULTS,MDPTR)
79 .;
80 .; If test mode quit at this point
81 .I MDTEST D FINISH(MDPTR,LINES,BYTES,"") S MDCNVT("CT")=MDCNVT("CT")+1 Q
82 .;
83 .; If real mode set to Unspecified Error status and proceed
84 .;D LOGERR(MDPTR,"Unspecified Error")
85 .S MDNODE=$G(^MDD(703.9,1,2,+MDREC,0))
86 .S MDNODE=$P(MDNODE,U,1)
87 .;
88 .; Create the note
89 .S MDTIUI=$$CONVERT^MDCVT1(MDNODE,$NA(^TMP($J)))
90 .I +MDTIUI'>0 D LOGERR(MDPTR,"Couldn't create the TIU document") Q
91 .;
92 .; Update Consults and Imaging
93 .;
94 .D UPD^MDCVT1(MDGBL,MDNODE,MDTIUI,MDTEST)
95 .;
96 .; Flag as finished
97 .;
98 .D FINISH(MDPTR,LINES,BYTES,MDTIUI) S MDCNVT("CR")=MDCNVT("CR")+1
99 ;
100 D TOTALS^MDCVT1(.MDCNVT)
101 Q
102 ;
103TESTHFS() ; Verify HFS is working properly
104 N MDNOW
105 S %ZIS("HFSNAME")=MDDIR_MDFILE,%ZIS("HFSMODE")="W",IOP="MDHFS;P-MDHFS"
106 D ^%ZIS I POP W !,"No HFS Access or missing device MDHFS" Q 0
107 S X=1 D Q:'X 0
108 .I IOT'="HFS" W !,"Device MDHFS not of type HFS" S X=0
109 .I IOST'="P-MDHFS" W !,"Missing Terminal Type P-MDHFS" S X=0 Q
110 .I IOSL'=88 W !,"Improper Page Length in Terminal Type P-MDHFS" S X=0
111 .I IOM'=80 W !,"Improper Page Width in Terminal Type P-MDHFS" S X=0
112 .I IOF'="#" W !,"Improper Form Feed in Terminal Type P-MDHFS" S X=0
113 ;
114 D NOW^%DTC S MDNOW=% K %
115 U IO W !!,MDNOW
116 D ^%ZISC
117 ;
118 ; Fetch the text
119 K ^TMP($J)
120 S X=$$FTG^%ZISH(MDDIR,MDFILE,$NA(^TMP($J,1)),2)
121 I 'X W !,"Unable to retrieve data back from Host File" Q 0
122 I ^TMP($J,3)'=MDNOW W !,"Error verifying data in Host File" Q 0
123 ;
124 ; Delete the Host File
125 S DELETE(MDFILE)=""
126 S X=$$DEL^%ZISH(MDDIR,"DELETE")
127 I X'=1 W !,"Unable delete Host File" Q 0
128 Q 1
129 ;
130ERR ; M Error trap submodule to document error and continue
131 D LOGERR(MDPTR,$ECODE)
132 I $G(ION)="MDHFS" D ^%ZISC ; Close device if using the HFS
133 G EN1
134 ;
135FINISH(MDPTR,LINES,BYTES,TIUIEN) ; Update status to converted
136 N MDFDA,MDIEN,MDIENS
137 S MDIEN=$O(^MDD(703.9,1,2,"B",MDPTR,0))
138 I MDIEN<1 W !,"Error, no log entry ",MDPTR Q
139 S MDIENS=MDIEN_",1,"
140 I MDTEST S MDFDA(703.92,MDIENS,.02)="CT"
141 E S MDFDA(703.92,MDIENS,.02)="CR"
142 S MDFDA(703.92,MDIENS,.03)=TIUIEN
143 S MDFDA(703.92,MDIENS,.04)=LINES
144 S MDFDA(703.92,MDIENS,.05)=BYTES
145 S MDFDA(703.92,MDIENS,.1)=LINES_" lines, "_BYTES_" bytes"
146 D FILE^DIE("","MDFDA")
147 Q
148 ;
149LOGERR(MDPTR,ERRMSG) ; Log conversion error
150 N MDFDA,MDIEN,MDIENS
151 S MDIEN=$O(^MDD(703.9,1,2,"B",MDPTR,0))
152 I MDIEN<1 W !,"Error, no log entry ",MDPTR Q
153 S MDIENS=MDIEN_",1,"
154 S MDFDA(703.92,MDIENS,.02)="E"
155 S MDFDA(703.92,MDIENS,.1)=$TR(ERRMSG,U,"~")
156 D FILE^DIE("","MDFDA")
157 W "*" ; Progress indicator
158 Q
159 ;
160RESET ; Reset error status reports to READY TO CONVERT
161 N MDIEN S MDIEN=0
162 ; Check for real mode and convert test conversions
163 I 'MDTEST F S MDIEN=$O(^MDD(703.9,1,2,"AS","CT",MDIEN)) Q:'MDIEN D
164 .N MDFDA
165 .S MDFDA(703.92,MDIEN_",1,",.02)="R"
166 .D FILE^DIE("","MDFDA")
167 ; Regardless of mode switch skipped back to ready
168 F S MDIEN=$O(^MDD(703.9,1,2,"AS","S",MDIEN)) Q:'MDIEN D
169 .N MDFDA
170 .S MDFDA(703.92,MDIEN_",1,",.02)="R"
171 .D FILE^DIE("","MDFDA")
172 ; Regardless of mode switch errors back to ready
173 F S MDIEN=$O(^MDD(703.9,1,2,"AS","E",MDIEN)) Q:'MDIEN D
174 .N MDFDA
175 .S MDFDA(703.92,MDIEN_",1,",.02)="R"
176 .D FILE^DIE("","MDFDA")
177 Q
178 ;
179REBUILD ; [Procedure] Build the file manually
180 N MDROOT
181 S X=$P(^MDD(703.9,0),U,1,2)_U_U K ^MDD(703.9) S ^MDD(703.9,0)=X
182 S MDROOT=$NA(^MDD(703.9,1))
183 S @MDROOT@(0)="DEFAULT"
184 S @MDROOT@(1,0)="^703.91P^^"
185 F X=691,691.1,691.5,691.6,691.7,691.8,694,694.5,698,698.1,698.2,698.3,699,699.5,700,701 S @MDROOT@(1,X,0)=X
186 S DA=1,DIK="^MDD(703.9," D IXALL^DIK K DA,DIK
187 Q
188 ;
189SETUP ; [Procedure]
190 I '$O(^MDD(703.9,0)) W !,"Initializing..." D REBUILD,SETDEF^MDSTATU
191 S DDSFILE=703.9,DR="[MD MAIN]",DA=1 D ^DDS
192 Q
193 ;
194SKIP(MDPTR,REASON) ; [Procedure] Skip Report
195 N MDFDA,MDIEN,MDIENS
196 S MDIEN=$O(^MDD(703.9,1,2,"B",MDPTR,0))
197 I MDIEN<1 W !,"Error, no log entry ",MDPTR Q
198 S MDIENS=MDIEN_",1,"
199 S MDFDA(703.92,MDIENS,.02)="S"
200 S MDFDA(703.92,MDIENS,.1)=$TR(REASON,U,"~")
201 D FILE^DIE("","MDFDA")
202 Q
203 ;
204SYNC(MDPTR) ; Make sure entry exists
205 N MDFDA
206 Q:$O(^MDD(703.9,1,2,"B",MDPTR,0))
207 Q:$O(^MDD(702,"ACONV",MDPTR,0))
208 S MDFDA(703.92,"+1,1,",.01)=MDPTR
209 S MDFDA(703.92,"+1,1,",.02)="R"
210 D UPDATE^DIE("","MDFDA")
211 Q
212 ;
213LOCKOUT ; Lockout Options and set API Flag
214 D ^MDOUTOR
215 Q
216 ;
217STATUS(MDPTR) ; [Procedure] Return status of VPtr
218 S X=$O(^MDD(703.9,1,2,"B",MDPTR,0))
219 I X Q $P($G(^MDD(703.9,1,2,X,0)),U,2) ; Return actual status
220 N MDFDA,MDIEN,MDMSG
221 S MDFDA(703.92,"+1,1,",.01)=MDPTR
222 S MDFDA(703.92,"+1,1,",.02)="N"
223 D UPDATE^DIE("","MDFDA","MDIEN","MDMSG")
224 I $G(MDIEN(1))<1 W !,"Error adding to conversion log ",MDPTR Q -1
225 Q "N"
226 ;
227SUMMARY ; Disk space requirements
228 N FILE,LP,TOTB,TOTC,TOTL,X
229 W !!,"Summarizing..."
230 K ^TMP($J)
231 S (TOTL,TOTC,TOTB)=0
232 S MDSTAT=$O(^MDD(703.9,1,2,"AS","C")) ; will be CT or CR
233 I MDSTAT'["C" W !!,"No report was converted. You MUST run the conversion in TEST or",!,"REAL mode first to be able to display the Disk Space Requirements." Q
234 D S1 I MDSTAT="CR" S MDSTAT="CT" D S1
235 W @IOF,!,"FILE",?42,$J("COUNT",8),?52,$J("LINES",8),?62,$J("BYTES",12)
236 W !,$TR($J("",79)," ","-")
237 S X="" F S X=$O(^TMP($J,X)) Q:X="" D
238 .W !,$E($P(@X,U,1),1,40)
239 .W ?42,$J(^TMP($J,X,"C"),8)
240 .W ?52,$J(^TMP($J,X,"L"),8)
241 .W ?62,$J(^TMP($J,X,"B"),12)
242 .S TOTC=TOTC+^TMP($J,X,"C")
243 .S TOTL=TOTL+^TMP($J,X,"L")
244 .S TOTB=TOTB+^TMP($J,X,"B")
245 W !?42,$TR($J("",37)," ","=")
246 W !?42,$J(TOTC,8),?52,$J(TOTL,8),?62,$J(TOTB,12) K ^TMP($J)
247 Q
248 ;
249S1 ; Loop for both CT or CR Statuses
250 N X S X="" F S X=$O(^MDD(703.9,1,2,"AS",MDSTAT,X)) Q:X="" D
251 .S FILE=$P($G(^MDD(703.9,1,2,X,0)),U,1)
252 .S FILE=U_$P(FILE,";",2)_"0)"
253 .S ^TMP($J,FILE,"C")=$G(^TMP($J,FILE,"C"))+1
254 .S ^TMP($J,FILE,"L")=$G(^TMP($J,FILE,"L"))+$P(^MDD(703.9,1,2,X,0),U,4)
255 .S ^TMP($J,FILE,"B")=$G(^TMP($J,FILE,"B"))+$P(^MDD(703.9,1,2,X,0),U,5)
256 Q
257TOTALS ; Count by Status
258 N MDSTAT S MDSTAT=""
259 F S MDSTAT=$O(^MDD(703.9,1,2,"AS",MDSTAT)) Q:MDSTAT="" D
260 .S Y=0 F X=0:0 S X=$O(^MDD(703.9,1,2,"AS",MDSTAT,X)) Q:'X S Y=Y+1
261 .S MDSTAT(MDSTAT)=Y
262 W @IOF,!,"Conversion Totals",!,$TR($J("",35)," ","-")
263 W !,"Converted REAL Mode: ",$J(+$G(MDSTAT("CR")),9)
264 W !,"Converted TEST Mode: ",$J(+$G(MDSTAT("CT")),9)
265 W !,"Skipped: ",$J(+$G(MDSTAT("S")),9)
266 W !,"Error: ",$J(+$G(MDSTAT("E")),9)
267 Q
268 ;
Note: See TracBrowser for help on using the repository browser.