source: WorldVistAEHR/trunk/r/CLINICAL_PROCEDURES-MD/MDRPCOT2.m@ 1270

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

initial load of WorldVistAEHR

File size: 7.4 KB
Line 
1MDRPCOT2 ; HOIFO/NCA - Object RPCs (TMDTransaction) Continued 2;10/29/04 12:20 ;3/12/08 09:18
2 ;;1.0;CLINICAL PROCEDURES;**6**;Apr 01, 2004;Build 102
3 ; Integration Agreements:
4 ; IA# 2693 [Subscription] TIU Extractions.
5 ; IA# 3535 [Subscription] Calls to TIUSRVP.
6ADDMSG ; [Procedure] Add message to transaction
7 N MDIEN,MDIENS,MDRET
8 Q:'$G(DATA("TRANSACTION"))
9 Q:$G(DATA("MESSAGE"))=""
10 S MDIEN=+DATA("TRANSACTION"),MDIENS="+1,"_MDIEN_","
11 D NOW^%DTC S DATA("DATE")=%
12 S MDFDA(702.091,MDIENS,.01)=+$O(^MDD(702,+MDIEN,.091,"A"),-1)+1
13 S MDFDA(702.091,MDIENS,.02)=DATA("DATE")
14 S MDFDA(702.091,MDIENS,.03)=$G(DATA("PKG"),"UNKNOWN")
15 S MDFDA(702.091,MDIENS,.09)=DATA("MESSAGE")
16 D UPDATE^DIE("","MDFDA","MDRET")
17 Q
18 ;
19FILEMSG(STUDY,MDPKG,MDSTAT,MDMSG) ; [Procedure] File Study Status and Message.
20 S DATA("TRANSACTION")=STUDY,DATA("PKG")=MDPKG
21 S DATA("MESSAGE")=$P(MDMSG,"^",2)
22 D STATUS(STUDY_",",MDSTAT,$P(MDMSG,"^",2)),ADDMSG
23 Q
24 ;
25STATUS(MDIENS,MDSTAT,MDMSG) ; [Procedure] Update transaction status
26 S MDFDA(702,MDIENS,.08)=$G(MDMSG)
27 S MDFDA(702,MDIENS,.09)=MDSTAT
28 D FILE^DIE("","MDFDA")
29 Q
30 ;
31SUBMIT(MDDATA,MDESIG,MDG1) ; [Procedure] Process the Image(s) Submission.
32 ; Input: MDDATA - Study ID
33 ; MDESIG - Electronic Signature
34 ; MDG1 - ^TMP global with the text of the report
35 ; Output: -1^Error Message or
36 ; 1^Successful Message
37 N MDRESUL,MDSTUDY,MDG2,RES
38 S MDSTUDY=+MDDATA,(RES,MDRESUL)=""
39 ; Create New TIU Document
40 S MDRESUL=$$NEWTIUN(MDSTUDY)
41 ;S MDRESUL=$$NEWTIUN(MDSTUDY)
42 ; File TIU Error messages
43 ;I +MDRESUL<0 D FILEMSG(MDSTUDY,"TIU",2,MDRESUL) Q MDRESUL
44 I +MDRESUL<0 D Q RES
45 .D FILEMSG(MDSTUDY,"TIU",2,MDRESUL)
46 .S RES=MDRESUL
47 ; Update the text of the TIU document
48 S MDG2=@($NA(MDG1))
49 I +$O(@MDG2@(""),-1) D Q:RES'="" RES
50 .S MDRESUL=$$UPDATE(MDSTUDY,MDESIG,MDG2)
51 .I +MDRESUL<0 D Q
52 ..D FILEMSG(MDSTUDY,"TIU",2,MDRESUL)
53 ..S RES=MDRESUL
54 ; Submit and export the images
55 ;S MDRESUL=$$SUBMIT^MDRPCOT1(MDSTUDY)
56 ; File message
57 ;D FILEMSG(MDSTUDY,"IMAGING",$S(+MDRESUL>0:+MDRESUL,1:2),MDRESUL)
58 S RES=MDRESUL
59 Q RES
60 ;
61GETDATA(STUDY) ; [Function] Return the Necessary data for creating a TIU note.
62 ; Return: Patient DFN_"^"_TIU title_"^"_Hospital Location_"^"_TIU Note
63 ; IEN_"^"_Consult #_"^"_CP Definition IEN_"^"_Visit String_"^"
64 ; New Visit Flag
65 ; or
66 ; -1^Error Message
67 N DFN,MDCON,MDFN,MDIEN,MDIENS,MDLOC,MDNEWV,MDNOTE,MDNVST,MDPROC,MDVSTR,MDTITL,MDX,MDTST
68 S MDIEN=+STUDY,MDIENS=MDIEN_",",MDNVST=0
69 I $$GET1^DIQ(702,MDIENS,.01)="" Q "-1^No such study entry."
70 ; Get DFN
71 S DFN=$$GET1^DIQ(702,MDIEN,.01,"I")
72 I 'DFN Q "-1^No DFN."
73 ; Get CP Def
74 S MDPROC=$$GET1^DIQ(702,MDIEN,.04,"I")
75 I 'MDPROC Q "-1^No CP Def."
76 ; Get Consult
77 S MDCON=$$GET1^DIQ(702,MDIEN,.05,"I")
78 I 'MDCON Q "-1^No Consult #."
79 ; Get TIU Note Title
80 S MDTITL=$$GET1^DIQ(702.01,+MDPROC_",",.04,"I")
81 I 'MDTITL Q "-1^No TIU Note Title."
82 S MDVSTR=$$GET1^DIQ(702,MDIEN,.07)
83 I MDVSTR="" Q "-1^No Visit String."
84 I $L(MDVSTR,";")=1 S MDNVST=1,MDVSTR=";"_MDVSTR ; If new visit is selected
85 ; MDLOC is Hospital Location
86 I MDVSTR'="" D
87 .S MDVSTR=$$GETVSTR^MDRPCOT1(DFN,MDVSTR,MDPROC,$$GET1^DIQ(702,MDIEN,.02,"I"))
88 .S MDLOC=$P(MDVSTR,";",1)
89 ; Does TIU doc already exist?
90 S MDNOTE=""
91 I $$GET1^DIQ(702,MDIEN,.06,"I") Q DFN_"^"_MDTITL_"^"_MDLOC_"^"_+$$GET1^DIQ(702,MDIEN,.06,"I")_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
92 ; Does TIU doc exist for previous transaction of this consult?
93 ;I MDCON S MDNOTE=$$PREV(MDCON,MDIEN)
94 Q DFN_"^"_MDTITL_"^"_MDLOC_"^"_+MDNOTE_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
95 ;
96NEWTIUN(STUDY) ; [Function] Create a new TIU for transaction
97 ; Input: STUDY - IENS of CP study entry
98 ; Return: TIU Document IEN
99 N CTR,DFN,MDCON,MDFDA,MDGST,MDL,MDLOC,MDNOTE,MDPDT,MDPROC,MDPT,MDRESU,MDTITL,MDTSTR,MDVST,MDVSTR,MDWP S CTR=0,MDGST=+STUDY,MDRESU=""
100 ; Get data for TIU Note Creation
101 S (MDTSTR,MDRESU)=$$GETDATA(MDGST)
102 ; File Error message
103 I +MDRESU<0 D FILEMSG(MDGST,"CP",2,MDRESU) Q MDRESU
104 I $G(MDTSTR)="" Q "-1^No Data to Create TIU Document"
105 F MDL="DFN","MDTITL","MDLOC","MDNOTE","MDCON","MDPROC","MDVSTR","MDNVST" D
106 .S CTR=CTR+1,@MDL=$P(MDTSTR,"^",CTR)
107 S (MDVST,MDRESU)=""
108 ; If previous TIU document exists, quit
109 I 'MDLOC Q "-1^No Hospital Location."
110 I MDNOTE Q MDNOTE
111 ; Create new visit, if no vstring
112 S MDPDT=$$PDT^MDRPCOT1(MDGST)
113 I 'MDPDT S MDPT=$O(^MDD(703.1,"ASTUDYID",+MDGST,0)),MDPDT=$P($G(^MDD(703.1,+MDPT,0)),U,3)
114 S:'MDPDT MDPDT=$P(MDVSTR,";",2) ; If No D/T Performed grab visit D/T
115 ; Build variables for TIU Call
116 S MDWP(.05)=1 ; Undictated Status
117 S MDWP(1405)=+MDCON_";GMR(123," ; Package Reference
118 S MDWP(70201)=5 ; Default Procedure Summary Code "Machine Resulted"
119 I MDPDT S MDWP(70202)=MDPDT ; Date/Time Performed
120 ; File PCE Error message
121 I MDNVST S MDRESU=$$EN1^MDPCE(MDGST,$P(MDVSTR,";",2),(MDPROC_"^"_MDLOC),$P(MDVSTR,";",3),"P") I +MDRESU S MDVST=+MDRESU,MDVSTR=$P(MDRESU,"^",2)
122 ;I MDNVST S MDRESU=$$EN1^MDPCE1(MDGST,MDPDT,MDPROC,$P(MDVSTR,";",3),"P") I +MDRESU S MDVST=+MDRESU,MDVSTR=$P(MDRESU,"^",2)
123 ;I 'MDNVST S MDVST=$P($G(^MDD(702,+MDGST,1)),U) I 'MDVST S MDRESU=$$EN1^MDPCE(MDGST,MDPDT,(MDPROC_"^"_MDLOC),$P(MDVSTR,";",3),"P") I +MDRESU S MDVST=+MDRESU
124 ;I 'MDNVST&$$CHK^MDPCE1(MDGST) S MDRESU=$$EN1^MDPCE1(MDGST,MDPDT,MDPROC,$P(MDVSTR,";",3),"P") I +MDRESU S MDVST=+MDRESU
125 I +MDRESU<0 D FILEMSG(MDGST,"PCE",2,$P(MDRESU,"^",2)) Q MDRESU
126 ; Create the TIU note stub
127 S MDNOTE="" D MAKE^TIUSRVP(.MDNOTE,DFN,MDTITL,$P(MDVSTR,";",2),MDLOC,$S(MDVST:MDVST,1:""),.MDWP,MDVSTR,1,1)
128 I '(+MDNOTE) S $P(MDNOTE,"^")=-1 Q MDNOTE
129 ; Finalize the transaction
130 S MDFDA(702,STUDY_",",.06)=+MDNOTE
131 S MDFDA(702,STUDY_",",.08)=""
132 D FILE^DIE("","MDFDA") K MDFDA
133 D UPD^MDKUTLR(STUDY,+MDNOTE)
134 Q 1
135 ;
136UPDATE(STUDY,SIGN,MDGLB) ; Update the TIU document with the text
137 N MDK,MDNOTE,MDPPR,MDRESU,MDS,MDTI,MDTIUER,MDWP,MDV,MDV1 S (MDNOTE,MDTIUER)="" K MDWP,^TMP("MDTIUST",$J)
138 F MDK=0:0 S MDK=$O(@MDGLB@(MDK)) Q:'MDK S MDWP("TEXT",MDK,0)=$G(@MDGLB@(MDK))
139 S MDTI=$$GET1^DIQ(702,STUDY_",",.06,"I") Q:'MDTI "-1^No Note."
140 S MDWP(.05)=5
141 S MDWP(1202)=DUZ
142 D UPDATE^TIUSRVP(.MDNOTE,+MDTI,.MDWP,1)
143 I '+MDNOTE S MDNOTE="-1^"_$P(MDNOTE,"^",2) Q MDNOTE
144 ; Sign TIU Document
145 S MDS=$$SIGN(MDTI,SIGN) I MDS<0 Q MDS
146 ;N MDFDA S MDFDA(704.202,STUDY_",",.09)=0
147 S $P(^MDK(704.202,STUDY,0),"^",9)=0
148 ;D FILE^DIE("","MDFDA")
149 N MDFDA S MDFDA(702,STUDY_",",.09)=3
150 D FILE^DIE("","MDFDA")
151 K ^MDK(704.202,"AS",1,STUDY)
152 S ^MDK(704.202,"AS",0,STUDY)=""
153 Q 1
154SIGN(MDTIUIN,MDSIGN) ; Sign the TIU Document
155 ; [Function] TIU SIGN RECORD
156 ;Input Parameters:
157 ; 1. TIUIEN [Literal/Required] TIU internal Entry Number
158 ; 2. MDSIGN [Literal/Required] User Signature
159 N MDSRES,X
160 S MDSRES=""
161 D SIGN^TIUSRVP(.MDSRES,MDTIUIN,MDSIGN)
162 I +MDSRES>0 Q "-1^"_$P(MDSRES,"^",2)
163 Q 1
164 ;
165PREV(MDC,MDS) ; [Function] Return the Previous TIU document.
166 N MDNEWV,MDDOC,MDTRAN,MDTIUER,MDTST
167 S (MDDOC,MDNEWV,MDTRAN,MDTIUER,MDTST)="" K ^TMP("MDTIUST",$J)
168 F S MDTRAN=$O(^MDD(702,"ACON",MDC,MDTRAN)) Q:'MDTRAN D Q:'MDTRAN
169 .I $P(^MDD(702,MDTRAN,0),U,6) D
170 ..D EXTRACT^TIULQ($P(^MDD(702,MDTRAN,0),U,6),"^TMP(""MDTIUST"",$J)",MDTIUER,".01;.05;1406") Q:+MDTIUER
171 ..S MDTST=$G(^TMP("MDTIUST",$J,$P(^MDD(702,MDTRAN,0),U,6),.05,"E"))
172 ..I MDTST'="UNDICTATED"&(MDTST'="UNSIGNED") K ^TMP("MDTIUST",$J) Q
173 ..I MDTST="UNSIGNED"&'($G(^TMP("MDTIUST",$J,$P(^MDD(702,MDTRAN,0),U,6),1406,"I"))) K ^TMP("MDTIUST",$J) Q
174 ..S MDDOC=$P(^MDD(702,MDTRAN,0),U,6),MDNEWV=$P(^MDD(702,MDTRAN,0),U,7)
175 ..Q:'MDS
176 ..S MDFDA(702,MDS_",",.06)=MDDOC
177 ..S MDFDA(702,MDS_",",.07)=MDNEWV
178 ..D FILE^DIE("","MDFDA")
179 ..S MDTRAN=""
180 Q MDDOC
Note: See TracBrowser for help on using the repository browser.