source: WorldVistAEHR/trunk/r/CLINICAL_PROCEDURES-MD/MDCVT1.m@ 808

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

initial load of WorldVistAEHR

File size: 9.3 KB
Line 
1MDCVT1 ; HOIFO/NCA - Medicine Package Conversion (Cont.) ;1/6/05 15:12
2 ;;1.0;CLINICAL PROCEDURES;**5**;Apr 01, 2004;Build 1
3 ; Integration Agreements:
4 ; IA# 4630 [Subscription] Calls to GMRCCP.
5 ; IA# 3535 [Subscription] Calls to TIUSRVP.
6 ; IA# 4508 [Subscription] Call to TIUSRVPT.
7 ; IA# 4588 [Subscription] Call to MAGMC2CP
8 ; IA# 2729 [Supported] Calls to XMXAPI.
9 ; IA#10063 [Supported] %ZTLOAD routine calls.
10 ;
11CONVERT(MDNOD,MDGLB) ; [Function] Convert Medicine Report to TIU Document
12 ; Input parameters
13 ; 1. MDNOD [Literal/Required]
14 ; 2. MDGLB [Reference/Required]
15 ;
16 ; Returns the TIU Note IEN
17 ; or 0 if report is skipped because Convert flag is set to "NO" or Report Converted
18 ; or -1^Error message
19 ; (Note: Error messages will be filed in Subfile 703.92 field .1)
20 ;
21 N MDCONV,MDEX,MDFIEN,MDFILE,MDFLG,MDGN,MDP,MDPROC,MDRES,MDTITL,MDUSER,MDX
22 S (MDGN,MDP)=MDNOD
23 S (MDEX,MDRES)="",MDFLG=0
24 S MDFIEN=+MDP Q:'MDFIEN "-1^No IEN for "_MDP
25 S MDFILE=+$P(MDP,"MCAR(",2) Q:'MDFILE "-1^No File Number for "_MDP
26 I $O(^MDD(702,"ACONV",MDFIEN_";MCAR("_MDFILE_",",0)) Q "-1^Already Converted."
27 S MDPAT=$$GET1^DIQ(MDFILE,MDFIEN_",","MEDICAL PATIENT","I")
28 I 'MDPAT S MDPAT=$$GET1^DIQ(MDFILE,MDFIEN_",","PATIENT","I")
29 I 'MDPAT Q "-1^No Medical Patient."
30 ; Get Medicine Parameter
31 S MDPROC=$G(^MDD(703.9,1,1,MDFILE,0))
32 ; Get CP Definition and Convert?
33 S MDCONV=$P(MDPROC,"^",3) I '+MDCONV D SKIP^MDCVT(MDP,"CONVERT Y/N flag set to No.") Q 0
34 S MDTITL=$P(MDPROC,"^",5) S:'MDTITL MDTITL=$$LOCATN^MDSTATU(MDGN)
35 Q:MDTITL'>0 "-1^No Historical Note Title."
36 S MDPROC=$P(MDPROC,"^",2) S:'MDPROC MDPROC=$$LOCATP^MDSTATU(MDGN)
37 Q:'MDPROC "-1^No CP definition for "_MDP
38 S MDUSER=$P($G(^MDD(703.9,1,0)),U,3) I 'MDUSER Q "-1^No Administrative Closure User Designated."
39 ; Get Existing TIU Note
40 S MDX=$O(^MDD(703.9,1,2,"B",MDP,0))
41 I +MDX S MDX=$G(^MDD(703.9,1,2,+MDX,0))
42 I +$P(MDX,"^",3) S MDEX=+$P(MDX,"^",3) Q MDEX
43 ; Create TIU Note
44 S MDRES=$$NEWTIU(MDFILE,MDPAT,MDFIEN,MDPROC,MDTITL,MDUSER,.MDGLB) I +MDRES<1 D LOGERR^MDCVT(MDP,$P(MDRES,"^",2)) S $P(MDRES,"^")=-1 Q MDRES
45 Q +MDRES
46 ;
47NEWTIU(MDFILE,MDPAT,MDFIEN,MDPROC,MDTITL,MDU,MDGLB) ; [Function] Create New TIU Note for Medicine Reports
48 ; Input parameters
49 ; 1. MDFILE [Literal/Required]
50 ; 2. MDPAT [Literal/Required]
51 ; 3. MDFIEN [Literal/Required]
52 ; 4. MDPROC [Literal/Required]
53 ; 5. MDTITL [Literal/Required]
54 ; 6. MDGLB [Reference/Required]
55 ;
56 N MDADD,MDCHKI,MDCODE,MDD,MDDT,MDERR,MDFDA,MDIEN,MDIENS,MDK,MDLOC,MDNOTE,MDRET,MDSSTR,MDVST,MDVSTR,MDWP
57 ; Get Hospital Location
58 S MDLOC=$$HOSP^MDSTATU(MDFIEN_";MCAR("_MDFILE)
59 I 'MDLOC S MDLOC=$$GET1^DIQ(702.01,+MDPROC_",",.05,"I")
60 Q:'MDLOC "0^No Hospital Location."
61 S MDCODE=$$GET1^DIQ(MDFILE,MDFIEN_",","SUMMARY","I")
62 I MDCODE'="" S MDCODE=$S(MDCODE="N":1,MDCODE="A":2,MDCODE="B":3,MDCODE="MI":2,MDCODE="MO":2,MDCODE="S":2,1:4)
63 E S MDCHKI=$$CHKINT(MDFILE,MDFIEN),MDCODE=$S(+MDCHKI:(MDCHKI+4),1:"")
64 S MDDT=$$GET1^DIQ(MDFILE,MDFIEN_",",.01,"I")
65 ; Set Un-dictated status
66 ;S MDWP(.05)=1
67 ; Set Author/Dictator and Entered By
68 ;S MDWP(1202)=MDU,MDWP(1302)=MDU
69 ; Set Procedure Summary Code and Date/Time of Procedure
70 S MDWP(70201)=MDCODE,MDWP(70202)=MDDT
71 F MDK=0:0 S MDK=$O(@MDGLB@(MDK)) Q:'MDK S MDWP("TEXT",MDK,0)=$G(@MDGLB@(MDK))
72 D NOW^%DTC S MDD=% K %
73 S MDFDA(702,"+1,",.01)=MDPAT
74 S MDFDA(702,"+1,",.02)=MDD
75 S MDFDA(702,"+1,",.03)=DUZ
76 S MDFDA(702,"+1,",.04)=MDPROC
77 S MDFDA(702,"+1,",.09)=4 ; Status = Checked-In
78 D UPDATE^DIE("","MDFDA","MDIEN","MDERR") Q:$D(MDERR)
79 S MDRET=$$EN1^MDPCE(MDIEN(1),MDDT,MDPROC_"^"_MDLOC,"E","A")
80 I +MDRET S MDVST=+MDRET,MDSSTR=$P(MDRET,"^",2),MDVSTR=$P(MDSSTR,";",3)_";"_$P(MDSSTR,";",2)_";"_$P(MDSSTR,";")
81 I +MDRET<1 D DELETE(MDIEN(1)) Q MDRET
82 S MDNOTE="" D MAKE^TIUSRVP(.MDNOTE,MDPAT,MDTITL,$P(MDVSTR,";",2),MDLOC,MDVST,.MDWP,MDVSTR,1,1)
83 ; Add the TIU Document Reference
84 S MDIENS=MDIEN(1)_","
85 I +MDNOTE S MDFDA(702,MDIENS,.06)=MDNOTE D FILE^DIE("","MDFDA","MDERR")
86 I +MDNOTE'>0 D DELETE(MDIEN(1))
87 Q MDNOTE
88 ;
89UPD(MDGB,MDNOD,MDTI,MDT) ; Do consults and Imaging update and log response
90 N MDCONS,MDECON,MDUSR,MDEFLG,MDIMG,MDNOTE,MDR,MDR1,MDRET,MDSTUD,MDTT,MDWP,MDX1 S (MDEFLG,MDRET)=0
91 ; Get the existing study
92 ;
93 S MDSTUD=$O(^MDD(702,"ATIU",+MDTI,0)) Q:'MDSTUD
94 ;
95 ;Get existing consult
96 ;
97 S MDECON=$$GET1^DIQ(702,MDSTUD_",",.05,"I")
98 ;
99 ; Get Administrative Closure Person
100 ;
101 S MDUSR=$P($G(^MDD(703.9,1,0)),U,3) Q:'MDUSR
102 S MDTT=$S(+$G(MDT)>0:0,1:1)
103 S MDCONS=$$CVTCONS^MDCVT1(MDTT,MDNOD,+MDTI)
104 I +MDCONS<0&($P(MDCONS,U,2)'["No MC results sent") D LOGERR^MDCVT(MDNOD,"Consults error: "_$P(MDCONS,U,2)) Q
105 I +MDCONS>0 K MDWP I +$P(MDCONS,U,3) D Q:MDEFLG
106 .S MDWP(1405)=+$P(MDCONS,U,3)_";GMR(123,"
107 .D UPDATE^TIUSRVP(.MDNOTE,+MDTI,.MDWP,1)
108 .I +MDNOTE<1 D LOGERR^MDCVT(MDNOD,"COULDN'T UPDATE THE NOTE") S MDEFLG=1 Q
109 .I +$P(MDCONS,U,3) S MDFDA(702,MDSTUD_",",.05)=+$P(MDCONS,U,3) D FILE^DIE("","MDFDA")
110 .Q
111 ; Do imaging update and log response
112 Q:$$GET1^DIQ(702,MDSTUD_",",.09,"I")=3
113 I $O(@MDGB@(2005,0)) D Q:MDRET<0 ; Quit on Imaging error
114 .S (MDIMG,MDX1)=0
115 .F S MDX1=$O(@MDGB@(2005,MDX1)) Q:'MDX1 D Q:MDRET<0
116 ..S MDIMG=+@MDGB@(2005,MDX1,0)
117 ..S MDRET=$$CVTIMG(MDTT,MDNOD,MDTI,MDIMG)
118 ..D:MDRET<0 LOGERR^MDCVT(MDNOD,"Imaging error: "_$P(MDRET,U,2))
119 Q:MDRET<0 K MDFDA S MDFDA(702,MDSTUD_",",.09)=3,MDFDA(702,MDSTUD_",",.3)=MDNOD D FILE^DIE("","MDFDA") W "."
120 ;
121 ; Close the record with Administrative Closure
122 S (MDR,MDR1)=""
123 I +MDTI D ADMNCLOS^TIUSRVPT(.MDR,+MDTI,"M",MDUSR) I '+MDR D DELETE^TIUSRVP(.MDR1,+MDTI) D LOGERR^MDCVT(MDNOD,"Can't Administrative close document")
124 Q
125PROC(MDX5,MDX6) ; Get Medicine Procedure Name
126 N LL,LL6,LL8
127 I MDX5="MCAR(699" S LL=$P($G(^MCAR(699,MDX6,0)),U,12) Q:LL'>0 S LL=$P($G(^MCAR(697.2,+LL,0)),U) Q LL
128 I MDX5="MCAR(699.5" D
129 .S LL6=$P($G(^MCAR(699.5,MDX6,0)),U,6),LL8=$P($G(^MCAR(699.5,MDX6,0)),U,8)
130 .S LL=$P($G(^MCAR(699.5,MDX6,0)),U,6) Q:'LL S LL=$P($G(^MCAR(697.2,LL,0)),U) Q LL
131 I MDX5[694 S LL=$P($G(^MCAR(694,MDX6,0)),U,3) Q:'LL S LL=$P(^MCAR(697.2,LL,0),U) Q LL
132 S LL=$O(^MCAR(697.2,"C",MDX5,0)),LL=$P(^MCAR(697.2,LL,0),U,1)
133 Q LL
134CVTIMG(MDTST,MDN,MDTIU,MDIMAGES) ; Call Imaging API
135 Q $$TIU^MAGMC2CP(MDTST,MDN,MDTIU,.MDIMAGES)
136CVTCONS(MDTST,MDN,MDTIU) ; Call Consults API
137 Q $$MCCNVT^GMRCCP(MDTST,MDN,MDTIU)
138CHKINT(MDFL,MDMREC) ; Check to see if record from Medical Device
139 ; Returns 1 or 0
140 N MDN1,MDF
141 I MDFL=691 S MDN1=$G(^MCAR(691,+MDMREC,10,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
142 I MDFL=691.1 S MDN1=$G(^MCAR(691.1,+MDMREC,43,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
143 I MDFL=691.5 S MDN1=$G(^MCAR(691.5,+MDMREC,9,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
144 I MDFL=691.6 S MDN1=$G(^MCAR(691.6,+MDMREC,7,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
145 I MDFL=691.8 S MDN1=$G(^MCAR(691.8,+MDMREC,12,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
146 I MDFL=698.3 S MDN1=$G(^MCAR(698.3,+MDMREC,10,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
147 I MDFL=699 S MDN1=$G(^MCAR(699,+MDMREC,33,0)) I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) Q 1
148 I MDFL=700 S MDF=0 D Q:MDF 1
149 .S MDN1=$G(^MCAR(700,+MDMREC,25,0))
150 .I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) S MDF=1 Q
151 .S MDN1=$G(^MCAR(700,+MDMREC,3,0))
152 .I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) S MDF=1 Q
153 .S MDN1=$G(^MCAR(700,+MDMREC,4,0))
154 .I +$P(MDN1,U,3)&($P(MDN1,U,3)>1) S MDF=1 Q
155 I +$P($G(^MCAR(MDFL,+MDMREC,2005,0)),U,4)>0 Q 1
156 Q 0
157BLD() ; Build the list of reports to convert
158 W ! K DIR S DIR(0)="YA",DIR("A")="Build the list of reports to convert? "
159 S DIR("A",1)="You can rebuild the list to check for new Medicine Reports that"
160 S DIR("A",2)="may have been added since the last time you ran the Build Conversion List.",DIR("B")="NO" D ^DIR K DIR
161 ;
162 Q:Y<1 1 ; User said no to re-build
163 Q:$D(DIRUT)!$D(DIROUT)!(Y<1) 0 ; User has cancelled
164 ;
165 K DIR S DIR(0)="YA",DIR("A")="Queue the conversion list build? ",DIR("B")="YES" D ^DIR K DIR
166 I Y=0 D QBLD Q 1 ; User has opted to do it now
167 I Y=1 D Q 0 ; User has queued the build
168 .S ZTRTN="QBLD^MDCVT1"
169 .S ZTDESC="Medicine Conversion List Build"
170 .S ZTREQ="@",ZTSAVE("ZTREQ")="",MDQUE=1,MDDUZ=DUZ,ZTSAVE("MDDUZ")="",ZTSAVE("MDQUE")=""
171 .S (ZTDTH,ZTIO)=""
172 .D ^%ZTLOAD
173 .I $G(ZTSK) W "Task Queued"
174 .E W "Task Cancelled"
175 Q 0 ; User cancelled out of the queueing
176 ;
177QBLD ; Queued entry point for re-build
178 L +(^MDD(703.9,1,2)):5 E Q
179 N MDGBL,MDPTR,MDFDA,MDFL,MDIEN,MDY,X2
180 S X2="" F S X2=$O(^MDD(703.9,1,1,X2)) Q:X2="" S MDY=$G(^(X2,0)) D
181 .Q:'+$P(MDY,U,3)
182 .S MDFL=$P(MDY,U),MDGBL="^MCAR("_MDFL_",""B"")"
183 .F S MDGBL=$Q(@MDGBL) Q:MDGBL="" Q:$QS(MDGBL,2)'="B" D
184 ..Q:'$P($G(^MCAR(MDFL,+$QS(MDGBL,4),0)),U,2)
185 ..S MDPTR=$QS(MDGBL,4)_";MCAR("_MDFL_","
186 ..D SYNC^MDCVT(MDPTR)
187 L -(^MDD(703.9,1,2))
188 I +$G(MDQUE) D
189 .N TXT,XMTO,XMBODY,XMDUZ,XMSUBJ
190 .S XMINSTR("FROM")=.5,XMSUBJ="Conversion List"
191 .S XMTO=$G(MDDUZ) Q:'XMTO
192 .S TXT(1)="The Queued Conversion List is finished."
193 .S TXT(2)="You can run the Medicine report conversion process.",XMBODY="TXT"
194 .D SENDMSG^XMXAPI(DUZ,XMSUBJ,XMBODY,XMTO,.XMINSTR)
195 .K MDQUE,MDDUZ
196 Q
197DELETE(MDIN) ; Delete study upon unsuccessful Note Creation
198 N MDFDA
199 S MDFDA(702,MDIN_",",.01)=""
200 D FILE^DIE("","MDFDA")
201 N DA,DIK S DA=+MDIN,DIK="^MDD(702," D ^DIK
202 Q
203TOTALS(MDSTAT) ; Count by Status
204 S MDSTAT("E")=0
205 S MDSTAT("E")=MDSTAT("TOT")-(MDSTAT("S")+MDSTAT("CR")+MDSTAT("CT"))
206 W @IOF,!,"Conversion Totals",!,$TR($J("",35)," ","-")
207 W !,"Converted REAL Mode: ",$J(+$G(MDSTAT("CR")),9)
208 W !,"Converted TEST Mode: ",$J(+$G(MDSTAT("CT")),9)
209 W !,"Skipped: ",$J(+$G(MDSTAT("S")),9)
210 W !,"Error: ",$J(+$G(MDSTAT("E")),9)
211 Q
Note: See TracBrowser for help on using the repository browser.