MDRPCOT ; HOIFO/DP/NCA - Object RPCs (TMDTransaction) ; 5/9/18 1:07pm
;;1.0;CLINICAL PROCEDURES;**5,6,11,21,43**;Apr 01, 2004;Build 7
; Integration Agreements:
; IA# 2693 [Subscription] TIU Extractions.
; IA# 2944 [Subscription] Calls to TIUSRVR1.
; IA# 3535 [Subscription] Calls to TIUSRVP.
; IA# 10103 [Supported] Call to XLFDT
; IA# 10104 [Supported] Routine XLFSTR calls
ADDMSG ; [Procedure] Add message to transaction
N MDIEN,MDIENS,MDRET
Q:'$G(DATA("TRANSACTION"))
Q:$G(DATA("MESSAGE"))=""
S MDIEN=+DATA("TRANSACTION"),MDIENS="+1,"_MDIEN_","
D NOW^%DTC S DATA("DATE")=% K %
S MDFDA(702.091,MDIENS,.01)=+$O(^MDD(702,+MDIEN,.091,"A"),-1)+1
S MDFDA(702.091,MDIENS,.02)=DATA("DATE")
S MDFDA(702.091,MDIENS,.03)=$G(DATA("PKG"),"UNKNOWN")
S MDFDA(702.091,MDIENS,.09)=DATA("MESSAGE")
D UPDATE^DIE("","MDFDA","MDRET")
Q
;
DELETE ; [Procedure] Delete Study
; Sets @RESULTS@(0)="-1^Reason for not deleting" or "1^Study Deleted"
;
N MDAST,MDHOLD,MDNOTE,MDRES,MDSIEN,BODY,SUBJECT,DEVIEN
S (MDHOLD,MDSIEN)=+DATA,MDRES=0,MDNOTE=""
D ALERT^MDHL7U3(MDSIEN) ; Builds the body of the mail message
I $G(^MDD(702,+MDSIEN,0))="" S @RESULTS@(0)="1^Study Deleted." D NOTICE^MDHL7U3(SUBJECT,.BODY,DEVIEN,DUZ) Q ;deleting message
S:+$P(^MDD(702,MDSIEN,0),U,6) MDNOTE=$P(^MDD(702,MDSIEN,0),U,6)
I "13"[$P(^MDD(702,MDSIEN,0),U,9) S @RESULTS@(0)="-1^Can't Delete TIU Note from a "_$$GET1^DIQ(702,MDSIEN,.09,"E")_" Study." Q
I "5"[$P(^MDD(702,MDSIEN,0),U,9) S MDCANR=$$CANCEL^MDHL7B(MDHOLD) I +MDCANR<0 S @RESULTS@(0)="-1^"_$P(MDCANR,"^",2) Q
I +MDNOTE S MDRES="" D DELETE^TIUSRVP(.MDRES,MDNOTE)
I MDRES D Q
.D STATUS(MDSIEN_",",2,$P(MDRES,"^",2))
.S DATA("TRANSACTION")=MDSIEN,DATA("PKG")="TIU"
.S DATA("MESSAGE")=$P(MDRES,"^",2) D ADDMSG
.S @RESULTS@(0)="-1^"_$P(MDRES,"^",2)
.Q
E D
.I $D(^MDD(702.001,"ASTUDY",MDSIEN)) S @RESULTS@(0)="-1^Note associated with study, can not delete." Q
.S MDAST=$$HL7CHK^MDHL7U3(+MDSIEN) I +MDAST<1 S @RESULTS@(0)=MDAST Q
.D NOTICE^MDHL7U3(SUBJECT,.BODY,DEVIEN,DUZ) ; delete message
.S MDFDA(702,DATA_",",.01)=""
.; Check for renal study to delete as well
.S:$D(^MDK(704.202,DATA)) MDFDA(704.202,DATA_",",.01)=""
.D FILE^DIE("","MDFDA")
.N DA,DIK S DA=+MDSIEN,DIK="^MDD(702," D ^DIK
.S @RESULTS@(0)="1^Study Deleted."
.Q
Q
;
FILEMSG(STUDY,MDPKG,MDSTAT,MDMSG) ; [Procedure] File Study Status and Message.
S DATA("TRANSACTION")=STUDY,DATA("PKG")=MDPKG
S DATA("MESSAGE")=$P(MDMSG,"^",2)
D STATUS(STUDY_",",MDSTAT,$P(MDMSG,"^",2)),ADDMSG
Q
;
FILES ; [Procedure] Add/remove an attachment to this transaction
NEW MDFDA,MDIEN,MDIENS,MDRET,MDT,MDT1,P1,P2,P3,P4
S P1=$P(DATA,U,1),P2=$P(DATA,U,2),P3=$P(DATA,U,3),P4=$P(DATA,U,4)
S MDIEN=0 I $G(^MDD(702,+P1,0))="" Q
S MDT=+P1,MDT1=$$MULT^MDRPCOT1(MDT),MDT=$S('MDT1:1,MDT1=1:1,1:0)
;I +MDT,$P($G(^MDD(702,+P1,0)),"^",9)=3 S @RESULTS@(0)="1^Study is already complete" Q
I $P($G(^MDD(702,+P1,0)),"^",9)=6 S @RESULTS@(0)="1^Study is already cancelled" Q
; Look for file (All comparisons done on lower case values)
F S MDIEN=$O(^MDD(702,P1,.1,MDIEN)) Q:'MDIEN D Q:X=P3
.S X=$$LOW^XLFSTR($G(^MDD(702,P1,.1,MDIEN,.1)))
I +MDT,MDIEN,P4 S @RESULTS@(0)="1^File already assigned" Q
I 'MDIEN&'P4 S @RESULTS@(0)="1^File not assigned" Q
I P4 D Q ; Add a file
.S MDIENS="+1,"_P1_","
.L +^MDD(702,P1,0):0 I '$T S @RESULTS@(0)="1^Study locked" Q ;43 - add lock
.S MDFDA(702.1,MDIENS,.01)=$O(^MDD(702,P1,.1,"B",""),-1)+1
.S MDFDA(702.1,MDIENS,.02)=$S(P2:"I",1:"U")
.I P2 S MDFDA(702.1,MDIENS,.03)=P2
.S MDFDA(702.1,MDIENS,.1)=P3
.D UPDATE^DIE("","MDFDA","MDIEN")
.S @RESULTS@(0)=+$G(MDIEN(1),-1)
.L -^MDD(702,P1,0) ;43 - add unlock
I 'P4 D Q ; Remove the file
.S MDFDA(702.1,MDIEN_","_P1_",",.01)="@"
.D FILE^DIE("","MDFDA","MDRET")
.S @RESULTS@(0)=$S($D(MDRET):-1,1:1)
Q
;
GETATT ; [Procedure] Get Attachments
F X=0:0 S X=$O(^MDD(702,DATA,.1,X)) Q:'X D
.S Y=$O(@RESULTS@(""),-1)+1
.S @RESULTS@(Y)=$P(^MDD(702,DATA,.1,X,0),U,1,3)
.S $P(@RESULTS@(Y),U,4)=$G(^MDD(702,DATA,.1,X,.1))
S @RESULTS@(0)=+$O(@RESULTS@(""),-1)
Q
;
GETERR ; [Procedure] Return list of Imaging Errors
; DATA = Transaction IEN
F MDX=0:0 S MDX=$O(^MDD(702,DATA,.091,MDX)) Q:'MDX D
.S MDY=+^MDD(702,DATA,.091,MDX,0)_U,Y=$P(^(0),U,2)
.D D^DIQ S MDY=MDY_Y_U
.S MDY=MDY_$P(^MDD(702,DATA,.091,MDX,0),U,3)_U_$P(^(0),U,9)
.S ^TMP($J,$O(^TMP($J,""),-1)+1)=MDY
S ^TMP($J,0)=+$O(^TMP($J,""),-1)
Q
;
NEWSTAT ; [Procedure] RPC Call to set status
S MDFDA(702,DATA,.09)=TYPE
D FILE^DIE("","MDFDA")
I TYPE=3&($G(^MDK(704.202,+DATA,0))'="") K MDFDA S MDFDA(704.202,DATA,.09)=0 D FILE^DIE("","MDFDA") K MDFDA
I TYPE=5 D
.N MDHL7,MDERR S MDHL7=$$SUB^MDHL7B(+DATA)
.I +MDHL7=-1 S MDFDA(702,DATA,.09)=2,MDFDA(702,DATA,.08)=$P(MDHL7,U,2)
.I +MDHL7=1 S MDFDA(702,DATA,.09)=5,MDFDA(702,DATA,.08)=""
.I $L($P($G(^MDD(702,+DATA,0)),"^",7),";")=1 S MDFDA(702,DATA,.07)=$$NOW^XLFDT(),MDFDA(702,DATA,.14)=$$NOW^XLFDT()
.D:$D(MDFDA) FILE^DIE("","MDFDA","MDERR")
Q
;
RPC(RESULTS,OPTION,DATA,TYPE,FILE,RESREP) ; [Procedure] Main RPC call
N MDCANR,MDCON,MDDOC,MDFDA,MDFN,MDGST,MDHOLD,MDIEN,MDIENS,MDL,MDLOC,MDMSG,MDNEWV,MDNOTE,MDNVST,MDPDT,MDPKG,MDPROC,MDRES,MDRESU,MDRESUL,MDRET,MDS,MDSIEN,MDSTAT,MDSTUDY,MDTITL,MDTIUER,MDTRAN,MDTST,MDTSTR,MDVST,MDVSTR,MDWP,MDX,MDY
S RESULTS=$NA(^TMP($J)) K @RESULTS
D:$T(@OPTION)]"" @OPTION
D:'$D(@RESULTS) BADRPC^MDRPCU("MD TMDTRANSACTION","MDRPCOT",OPTION)
D CLEAN^DILF
Q
;
STATUS(MDIENS,MDSTAT,MDMSG) ; [Procedure] Update transaction status
S MDFDA(702,MDIENS,.08)=$G(MDMSG)
S MDFDA(702,MDIENS,.09)=MDSTAT
D FILE^DIE("","MDFDA") K MDFDA
Q
;
SUBMIT ; [Procedure] Process the Image(s) Submission.
; Output: -1^Error Message or
; 1^Successful Message
N MDRESUL,MDSTUDY
S MDSTUDY=+DATA,MDRESUL=""
L +^MDD(702,MDSTUDY,0):0 I '$T S @RESULTS@(0)="1^Study locked" Q ;43 - add lock
; Create New TIU Document
S MDRESUL=$$NEWTIUN(MDSTUDY)
; File TIU Error messages
I +MDRESUL<0 D Q
.D FILEMSG(MDSTUDY,"TIU",2,MDRESUL)
.S @RESULTS@(0)=MDRESUL
.L -^MDD(702,MDSTUDY,0) ;43 - add unlock
; Submit and export the images
S MDRESUL=$$SUBMIT^MDRPCOT1(MDSTUDY)
; File message
D FILEMSG(MDSTUDY,"IMAGING",$S(+MDRESUL>0:+MDRESUL,1:2),MDRESUL)
S @RESULTS@(0)=MDRESUL
L -^MDD(702,MDSTUDY,0) ;43 - add unlock
Q
;
VIEWTIU ; [Procedure] VIew the associated tiu document
I '$P(^MDD(702,+DATA,0),U,6) D Q
.S @RESULTS@(0)="NO TIU NOTE FOR THIS STUDY"
D TGET^TIUSRVR1(.RESULTS,+$P(^MDD(702,+DATA,0),U,6))
Q
;
GETDATA(STUDY) ; [Function] Return the Necessary data for creating a TIU note.
; Return: Patient DFN_"^"_TIU title_"^"_Hospital Location_"^"_TIU Note
; IEN_"^"_Consult #_"^"_CP Definition IEN_"^"_Visit String_"^"
; New Visit Flag
; or
; -1^Error Message
N DFN,MDCON,MDFN,MDIEN,MDDPT,MDIENS,MDLOC,MDNEWV,MDNOTE,MDNVST,MDPROC,MDVSTR,MDTITL,MDX,MDTST
S MDIEN=+STUDY,MDIENS=MDIEN_",",MDNVST=0
I $$GET1^DIQ(702,MDIENS,.01)="" Q "-1^No such study entry."
; Get DFN
S DFN=$$GET1^DIQ(702,MDIEN,.01,"I")
I 'DFN Q "-1^No DFN."
; Get CP Def
S MDPROC=$$GET1^DIQ(702,MDIEN,.04,"I")
I 'MDPROC Q "-1^No CP Def."
; Get Consult
S MDCON=$$GET1^DIQ(702,MDIEN,.05,"I")
I 'MDCON Q "-1^No Consult #."
; Get TIU Note Title
S MDTITL=$$GET1^DIQ(702.01,+MDPROC_",",.04,"I")
I 'MDTITL Q "-1^No TIU Note Title."
S MDVSTR=$$GET1^DIQ(702,MDIEN,.07)
I MDVSTR="" Q "-1^No Visit String."
I $L(MDVSTR,";")=1 S MDNVST=1,MDDPT=$$PDT^MDRPCOT1(MDIEN),MDVSTR=";"_MDVSTR ; If new visit is selected
; MDLOC is Hospital Location
I MDVSTR'="" D
.S MDVSTR=$$GETVSTR^MDRPCOT1(DFN,MDVSTR,MDPROC,$$GET1^DIQ(702,MDIEN,.02,"I"))
.S MDLOC=$P(MDVSTR,";",1)
I $$GET1^DIQ(702.01,+MDPROC_",",.12,"I")=1 Q DFN_"^"_MDTITL_"^"_MDLOC_"^^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
; Does TIU doc already exist?
I $$GET1^DIQ(702,MDIEN,.06,"I") Q DFN_"^"_MDTITL_"^"_MDLOC_"^"_+$$GET1^DIQ(702,MDIEN,.06,"I")_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
; Does TIU doc exist for previous transaction of this consult?
I MDCON S MDNOTE=$$PREV(MDCON,MDIEN)
Q DFN_"^"_MDTITL_"^"_MDLOC_"^"_+MDNOTE_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
;
NEWTIUN(STUDY) ; [Function] Create a new TIU for transaction
; Input: STUDY - IENS of CP study entry
; Return: TIU Document IEN
N CTR,DFN,MDCON,MDFDA,MDGST,MDL,MDLOC,MDNOTE,MDPDT,MDPROC,MDRESU,MDTITL,MDTSTR,MDVST,MDVSTR,MDWP,MDPT S CTR=0,MDGST=+STUDY,MDRESU=""
; Get data for TIU Note Creation
S (MDTSTR,MDRESU)=$$GETDATA(MDGST)
; File Error message
I +MDRESU<0 D FILEMSG(MDGST,"CP",2,MDRESU) Q MDRESU
I $G(MDTSTR)="" Q "-1^No Data to Create TIU Document"
F MDL="DFN","MDTITL","MDLOC","MDNOTE","MDCON","MDPROC","MDVSTR","MDNVST" D
.S CTR=CTR+1,@MDL=$P(MDTSTR,"^",CTR)
S MDVST=""
; If previous TIU document exists, quit
I MDNOTE Q MDNOTE
I $$GET^XPAR("SYS","MD GET HIGH VOLUME",MDPROC,"I")'=""&(+$P(^MDD(702,+MDGST,0),"^",6)) Q $P(^MDD(702,+MDGST,0),"^",6)
I 'MDLOC Q "-1^No Hospital Location."
; Create new visit, if no vstring
S MDPDT=$$PDT^MDRPCOT1(MDGST)
I 'MDPDT S MDPT=$O(^MDD(703.1,"ASTUDYID",+MDGST,0)),MDPDT=$P($G(^MDD(703.1,+MDPT,0)),U,3)
S:'MDPDT MDPDT=$P(MDVSTR,";",2) ; If No D/T Performed grab visit D/T
I $P(MDVSTR,";",3)="V" S $P(MDVSTR,";",3)="A"
; Build variables for TIU Call
S MDWP(.05)=1 ; Undicated Status
S MDWP(1405)=+MDCON_";GMR(123," ; Package Reference
S MDWP(70201)=5 ; Default Procedure Summary Code "Machine Resulted"
I MDPDT S MDWP(70202)=MDPDT ; Date/Time Performed
; File PCE Error message
I MDNVST S MDRESU=$$EN1^MDPCE(MDGST,$P(MDVSTR,";",2),MDPROC,$P(MDVSTR,";",3),"P") I +MDRESU S MDVST=+MDRESU,MDVSTR=$P(MDRESU,"^",2)
I MDNVST&(+MDRESU<0) D FILEMSG(MDGST,"PCE",2,$P(MDRESU,"^",2)) Q MDRESU
; Create the TIU note stub
S MDNOTE="" D MAKE^TIUSRVP(.MDNOTE,DFN,MDTITL,$P(MDVSTR,";",2),MDLOC,$S(MDVST:MDVST,1:""),.MDWP,MDVSTR,1,1)
I '(+MDNOTE) S $P(MDNOTE,"^")=-1 Q MDNOTE
; Finalize the transaction
S MDFDA(702,STUDY_",",.06)=+MDNOTE
S MDFDA(702,STUDY_",",.08)=""
S:MDVST>0 MDFDA(702,STUDY_",",.13)=MDVST
D FILE^DIE("","MDFDA")
D UPD^MDKUTLR(STUDY,+MDNOTE)
Q 1
;
PREV(MDC,MDS) ; [Function] Return the Previous TIU document.
N MDNEWV,MDDOC,MDTRAN,MDTIUER,MDTST
S (MDDOC,MDNEWV,MDTRAN,MDTIUER,MDTST)="" K ^TMP("MDTIUST",$J)
F S MDTRAN=$O(^MDD(702,"ACON",MDC,MDTRAN)) Q:'MDTRAN D Q:'MDTRAN
.I $P(^MDD(702,MDTRAN,0),U,6) D
..D EXTRACT^TIULQ($P(^MDD(702,MDTRAN,0),U,6),"^TMP(""MDTIUST"",$J)",MDTIUER,".01;.05;1406") Q:+MDTIUER
..S MDTST=$G(^TMP("MDTIUST",$J,$P(^MDD(702,MDTRAN,0),U,6),.05,"E"))
..I MDTST'="UNDICTATED"&(MDTST'="UNSIGNED") K ^TMP("MDTIUST",$J) Q
..I MDTST="UNSIGNED"&'($G(^TMP("MDTIUST",$J,$P(^MDD(702,MDTRAN,0),U,6),1406,"I"))) K ^TMP("MDTIUST",$J) Q
..S MDDOC=$P(^MDD(702,MDTRAN,0),U,6),MDNEWV=$P(^MDD(702,MDTRAN,0),U,7)
..Q:'MDS
..S MDFDA(702,MDS_",",.06)=MDDOC
..S MDFDA(702,MDS_",",.07)=MDNEWV
..D FILE^DIE("","MDFDA")
..S MDTRAN=""
Q MDDOC
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMDRPCOT 11094 printed Oct 16, 2024@17:44:58 Page 2
MDRPCOT ; HOIFO/DP/NCA - Object RPCs (TMDTransaction) ; 5/9/18 1:07pm
+1 ;;1.0;CLINICAL PROCEDURES;**5,6,11,21,43**;Apr 01, 2004;Build 7
+2 ; Integration Agreements:
+3 ; IA# 2693 [Subscription] TIU Extractions.
+4 ; IA# 2944 [Subscription] Calls to TIUSRVR1.
+5 ; IA# 3535 [Subscription] Calls to TIUSRVP.
+6 ; IA# 10103 [Supported] Call to XLFDT
+7 ; IA# 10104 [Supported] Routine XLFSTR calls
ADDMSG ; [Procedure] Add message to transaction
+1 NEW MDIEN,MDIENS,MDRET
+2 if '$GET(DATA("TRANSACTION"))
QUIT
+3 if $GET(DATA("MESSAGE"))=""
QUIT
+4 SET MDIEN=+DATA("TRANSACTION")
SET MDIENS="+1,"_MDIEN_","
+5 DO NOW^%DTC
SET DATA("DATE")=%
KILL %
+6 SET MDFDA(702.091,MDIENS,.01)=+$ORDER(^MDD(702,+MDIEN,.091,"A"),-1)+1
+7 SET MDFDA(702.091,MDIENS,.02)=DATA("DATE")
+8 SET MDFDA(702.091,MDIENS,.03)=$GET(DATA("PKG"),"UNKNOWN")
+9 SET MDFDA(702.091,MDIENS,.09)=DATA("MESSAGE")
+10 DO UPDATE^DIE("","MDFDA","MDRET")
+11 QUIT
+12 ;
DELETE ; [Procedure] Delete Study
+1 ; Sets @RESULTS@(0)="-1^Reason for not deleting" or "1^Study Deleted"
+2 ;
+3 NEW MDAST,MDHOLD,MDNOTE,MDRES,MDSIEN,BODY,SUBJECT,DEVIEN
+4 SET (MDHOLD,MDSIEN)=+DATA
SET MDRES=0
SET MDNOTE=""
+5 ; Builds the body of the mail message
DO ALERT^MDHL7U3(MDSIEN)
+6 ;deleting message
IF $GET(^MDD(702,+MDSIEN,0))=""
SET @RESULTS@(0)="1^Study Deleted."
DO NOTICE^MDHL7U3(SUBJECT,.BODY,DEVIEN,DUZ)
QUIT
+7 if +$PIECE(^MDD(702,MDSIEN,0),U,6)
SET MDNOTE=$PIECE(^MDD(702,MDSIEN,0),U,6)
+8 IF "13"[$PIECE(^MDD(702,MDSIEN,0),U,9)
SET @RESULTS@(0)="-1^Can't Delete TIU Note from a "_$$GET1^DIQ(702,MDSIEN,.09,"E")_" Study."
QUIT
+9 IF "5"[$PIECE(^MDD(702,MDSIEN,0),U,9)
SET MDCANR=$$CANCEL^MDHL7B(MDHOLD)
IF +MDCANR<0
SET @RESULTS@(0)="-1^"_$PIECE(MDCANR,"^",2)
QUIT
+10 IF +MDNOTE
SET MDRES=""
DO DELETE^TIUSRVP(.MDRES,MDNOTE)
+11 IF MDRES
Begin DoDot:1
+12 DO STATUS(MDSIEN_",",2,$PIECE(MDRES,"^",2))
+13 SET DATA("TRANSACTION")=MDSIEN
SET DATA("PKG")="TIU"
+14 SET DATA("MESSAGE")=$PIECE(MDRES,"^",2)
DO ADDMSG
+15 SET @RESULTS@(0)="-1^"_$PIECE(MDRES,"^",2)
+16 QUIT
End DoDot:1
QUIT
+17 IF '$TEST
Begin DoDot:1
+18 IF $DATA(^MDD(702.001,"ASTUDY",MDSIEN))
SET @RESULTS@(0)="-1^Note associated with study, can not delete."
QUIT
+19 SET MDAST=$$HL7CHK^MDHL7U3(+MDSIEN)
IF +MDAST<1
SET @RESULTS@(0)=MDAST
QUIT
+20 ; delete message
DO NOTICE^MDHL7U3(SUBJECT,.BODY,DEVIEN,DUZ)
+21 SET MDFDA(702,DATA_",",.01)=""
+22 ; Check for renal study to delete as well
+23 if $DATA(^MDK(704.202,DATA))
SET MDFDA(704.202,DATA_",",.01)=""
+24 DO FILE^DIE("","MDFDA")
+25 NEW DA,DIK
SET DA=+MDSIEN
SET DIK="^MDD(702,"
DO ^DIK
+26 SET @RESULTS@(0)="1^Study Deleted."
+27 QUIT
End DoDot:1
+28 QUIT
+29 ;
FILEMSG(STUDY,MDPKG,MDSTAT,MDMSG) ; [Procedure] File Study Status and Message.
+1 SET DATA("TRANSACTION")=STUDY
SET DATA("PKG")=MDPKG
+2 SET DATA("MESSAGE")=$PIECE(MDMSG,"^",2)
+3 DO STATUS(STUDY_",",MDSTAT,$PIECE(MDMSG,"^",2))
DO ADDMSG
+4 QUIT
+5 ;
FILES ; [Procedure] Add/remove an attachment to this transaction
+1 NEW MDFDA,MDIEN,MDIENS,MDRET,MDT,MDT1,P1,P2,P3,P4
+2 SET P1=$PIECE(DATA,U,1)
SET P2=$PIECE(DATA,U,2)
SET P3=$PIECE(DATA,U,3)
SET P4=$PIECE(DATA,U,4)
+3 SET MDIEN=0
IF $GET(^MDD(702,+P1,0))=""
QUIT
+4 SET MDT=+P1
SET MDT1=$$MULT^MDRPCOT1(MDT)
SET MDT=$SELECT('MDT1:1,MDT1=1:1,1:0)
+5 ;I +MDT,$P($G(^MDD(702,+P1,0)),"^",9)=3 S @RESULTS@(0)="1^Study is already complete" Q
+6 IF $PIECE($GET(^MDD(702,+P1,0)),"^",9)=6
SET @RESULTS@(0)="1^Study is already cancelled"
QUIT
+7 ; Look for file (All comparisons done on lower case values)
+8 FOR
SET MDIEN=$ORDER(^MDD(702,P1,.1,MDIEN))
if 'MDIEN
QUIT
Begin DoDot:1
+9 SET X=$$LOW^XLFSTR($GET(^MDD(702,P1,.1,MDIEN,.1)))
End DoDot:1
if X=P3
QUIT
+10 IF +MDT
IF MDIEN
IF P4
SET @RESULTS@(0)="1^File already assigned"
QUIT
+11 IF 'MDIEN&'P4
SET @RESULTS@(0)="1^File not assigned"
QUIT
+12 ; Add a file
IF P4
Begin DoDot:1
+13 SET MDIENS="+1,"_P1_","
+14 ;43 - add lock
LOCK +^MDD(702,P1,0):0
IF '$TEST
SET @RESULTS@(0)="1^Study locked"
QUIT
+15 SET MDFDA(702.1,MDIENS,.01)=$ORDER(^MDD(702,P1,.1,"B",""),-1)+1
+16 SET MDFDA(702.1,MDIENS,.02)=$SELECT(P2:"I",1:"U")
+17 IF P2
SET MDFDA(702.1,MDIENS,.03)=P2
+18 SET MDFDA(702.1,MDIENS,.1)=P3
+19 DO UPDATE^DIE("","MDFDA","MDIEN")
+20 SET @RESULTS@(0)=+$GET(MDIEN(1),-1)
+21 ;43 - add unlock
LOCK -^MDD(702,P1,0)
End DoDot:1
QUIT
+22 ; Remove the file
IF 'P4
Begin DoDot:1
+23 SET MDFDA(702.1,MDIEN_","_P1_",",.01)="@"
+24 DO FILE^DIE("","MDFDA","MDRET")
+25 SET @RESULTS@(0)=$SELECT($DATA(MDRET):-1,1:1)
End DoDot:1
QUIT
+26 QUIT
+27 ;
GETATT ; [Procedure] Get Attachments
+1 FOR X=0:0
SET X=$ORDER(^MDD(702,DATA,.1,X))
if 'X
QUIT
Begin DoDot:1
+2 SET Y=$ORDER(@RESULTS@(""),-1)+1
+3 SET @RESULTS@(Y)=$PIECE(^MDD(702,DATA,.1,X,0),U,1,3)
+4 SET $PIECE(@RESULTS@(Y),U,4)=$GET(^MDD(702,DATA,.1,X,.1))
End DoDot:1
+5 SET @RESULTS@(0)=+$ORDER(@RESULTS@(""),-1)
+6 QUIT
+7 ;
GETERR ; [Procedure] Return list of Imaging Errors
+1 ; DATA = Transaction IEN
+2 FOR MDX=0:0
SET MDX=$ORDER(^MDD(702,DATA,.091,MDX))
if 'MDX
QUIT
Begin DoDot:1
+3 SET MDY=+^MDD(702,DATA,.091,MDX,0)_U
SET Y=$PIECE(^(0),U,2)
+4 DO D^DIQ
SET MDY=MDY_Y_U
+5 SET MDY=MDY_$PIECE(^MDD(702,DATA,.091,MDX,0),U,3)_U_$PIECE(^(0),U,9)
+6 SET ^TMP($JOB,$ORDER(^TMP($JOB,""),-1)+1)=MDY
End DoDot:1
+7 SET ^TMP($JOB,0)=+$ORDER(^TMP($JOB,""),-1)
+8 QUIT
+9 ;
NEWSTAT ; [Procedure] RPC Call to set status
+1 SET MDFDA(702,DATA,.09)=TYPE
+2 DO FILE^DIE("","MDFDA")
+3 IF TYPE=3&($GET(^MDK(704.202,+DATA,0))'="")
KILL MDFDA
SET MDFDA(704.202,DATA,.09)=0
DO FILE^DIE("","MDFDA")
KILL MDFDA
+4 IF TYPE=5
Begin DoDot:1
+5 NEW MDHL7,MDERR
SET MDHL7=$$SUB^MDHL7B(+DATA)
+6 IF +MDHL7=-1
SET MDFDA(702,DATA,.09)=2
SET MDFDA(702,DATA,.08)=$PIECE(MDHL7,U,2)
+7 IF +MDHL7=1
SET MDFDA(702,DATA,.09)=5
SET MDFDA(702,DATA,.08)=""
+8 IF $LENGTH($PIECE($GET(^MDD(702,+DATA,0)),"^",7),";")=1
SET MDFDA(702,DATA,.07)=$$NOW^XLFDT()
SET MDFDA(702,DATA,.14)=$$NOW^XLFDT()
+9 if $DATA(MDFDA)
DO FILE^DIE("","MDFDA","MDERR")
End DoDot:1
+10 QUIT
+11 ;
RPC(RESULTS,OPTION,DATA,TYPE,FILE,RESREP) ; [Procedure] Main RPC call
+1 NEW MDCANR,MDCON,MDDOC,MDFDA,MDFN,MDGST,MDHOLD,MDIEN,MDIENS,MDL,MDLOC,MDMSG,MDNEWV,MDNOTE,MDNVST,MDPDT,MDPKG,MDPROC,MDRES,MDRESU,MDRESUL,MDRET,MDS,MDSIEN,MDSTAT,MDSTUDY,MDTITL,MDTIUER,MDTRAN,MDTST,MDTSTR,MDVST,MDVSTR,MDWP,MDX,MDY
+2 SET RESULTS=$NAME(^TMP($JOB))
KILL @RESULTS
+3 if $TEXT(@OPTION)]""
DO @OPTION
+4 if '$DATA(@RESULTS)
DO BADRPC^MDRPCU("MD TMDTRANSACTION","MDRPCOT",OPTION)
+5 DO CLEAN^DILF
+6 QUIT
+7 ;
STATUS(MDIENS,MDSTAT,MDMSG) ; [Procedure] Update transaction status
+1 SET MDFDA(702,MDIENS,.08)=$GET(MDMSG)
+2 SET MDFDA(702,MDIENS,.09)=MDSTAT
+3 DO FILE^DIE("","MDFDA")
KILL MDFDA
+4 QUIT
+5 ;
SUBMIT ; [Procedure] Process the Image(s) Submission.
+1 ; Output: -1^Error Message or
+2 ; 1^Successful Message
+3 NEW MDRESUL,MDSTUDY
+4 SET MDSTUDY=+DATA
SET MDRESUL=""
+5 ;43 - add lock
LOCK +^MDD(702,MDSTUDY,0):0
IF '$TEST
SET @RESULTS@(0)="1^Study locked"
QUIT
+6 ; Create New TIU Document
+7 SET MDRESUL=$$NEWTIUN(MDSTUDY)
+8 ; File TIU Error messages
+9 IF +MDRESUL<0
Begin DoDot:1
+10 DO FILEMSG(MDSTUDY,"TIU",2,MDRESUL)
+11 SET @RESULTS@(0)=MDRESUL
+12 ;43 - add unlock
LOCK -^MDD(702,MDSTUDY,0)
End DoDot:1
QUIT
+13 ; Submit and export the images
+14 SET MDRESUL=$$SUBMIT^MDRPCOT1(MDSTUDY)
+15 ; File message
+16 DO FILEMSG(MDSTUDY,"IMAGING",$SELECT(+MDRESUL>0:+MDRESUL,1:2),MDRESUL)
+17 SET @RESULTS@(0)=MDRESUL
+18 ;43 - add unlock
LOCK -^MDD(702,MDSTUDY,0)
+19 QUIT
+20 ;
VIEWTIU ; [Procedure] VIew the associated tiu document
+1 IF '$PIECE(^MDD(702,+DATA,0),U,6)
Begin DoDot:1
+2 SET @RESULTS@(0)="NO TIU NOTE FOR THIS STUDY"
End DoDot:1
QUIT
+3 DO TGET^TIUSRVR1(.RESULTS,+$PIECE(^MDD(702,+DATA,0),U,6))
+4 QUIT
+5 ;
GETDATA(STUDY) ; [Function] Return the Necessary data for creating a TIU note.
+1 ; Return: Patient DFN_"^"_TIU title_"^"_Hospital Location_"^"_TIU Note
+2 ; IEN_"^"_Consult #_"^"_CP Definition IEN_"^"_Visit String_"^"
+3 ; New Visit Flag
+4 ; or
+5 ; -1^Error Message
+6 NEW DFN,MDCON,MDFN,MDIEN,MDDPT,MDIENS,MDLOC,MDNEWV,MDNOTE,MDNVST,MDPROC,MDVSTR,MDTITL,MDX,MDTST
+7 SET MDIEN=+STUDY
SET MDIENS=MDIEN_","
SET MDNVST=0
+8 IF $$GET1^DIQ(702,MDIENS,.01)=""
QUIT "-1^No such study entry."
+9 ; Get DFN
+10 SET DFN=$$GET1^DIQ(702,MDIEN,.01,"I")
+11 IF 'DFN
QUIT "-1^No DFN."
+12 ; Get CP Def
+13 SET MDPROC=$$GET1^DIQ(702,MDIEN,.04,"I")
+14 IF 'MDPROC
QUIT "-1^No CP Def."
+15 ; Get Consult
+16 SET MDCON=$$GET1^DIQ(702,MDIEN,.05,"I")
+17 IF 'MDCON
QUIT "-1^No Consult #."
+18 ; Get TIU Note Title
+19 SET MDTITL=$$GET1^DIQ(702.01,+MDPROC_",",.04,"I")
+20 IF 'MDTITL
QUIT "-1^No TIU Note Title."
+21 SET MDVSTR=$$GET1^DIQ(702,MDIEN,.07)
+22 IF MDVSTR=""
QUIT "-1^No Visit String."
+23 ; If new visit is selected
IF $LENGTH(MDVSTR,";")=1
SET MDNVST=1
SET MDDPT=$$PDT^MDRPCOT1(MDIEN)
SET MDVSTR=";"_MDVSTR
+24 ; MDLOC is Hospital Location
+25 IF MDVSTR'=""
Begin DoDot:1
+26 SET MDVSTR=$$GETVSTR^MDRPCOT1(DFN,MDVSTR,MDPROC,$$GET1^DIQ(702,MDIEN,.02,"I"))
+27 SET MDLOC=$PIECE(MDVSTR,";",1)
End DoDot:1
+28 IF $$GET1^DIQ(702.01,+MDPROC_",",.12,"I")=1
QUIT DFN_"^"_MDTITL_"^"_MDLOC_"^^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
+29 ; Does TIU doc already exist?
+30 IF $$GET1^DIQ(702,MDIEN,.06,"I")
QUIT DFN_"^"_MDTITL_"^"_MDLOC_"^"_+$$GET1^DIQ(702,MDIEN,.06,"I")_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
+31 ; Does TIU doc exist for previous transaction of this consult?
+32 IF MDCON
SET MDNOTE=$$PREV(MDCON,MDIEN)
+33 QUIT DFN_"^"_MDTITL_"^"_MDLOC_"^"_+MDNOTE_"^"_MDCON_"^"_MDPROC_"^"_MDVSTR_"^"_MDNVST
+34 ;
NEWTIUN(STUDY) ; [Function] Create a new TIU for transaction
+1 ; Input: STUDY - IENS of CP study entry
+2 ; Return: TIU Document IEN
+3 NEW CTR,DFN,MDCON,MDFDA,MDGST,MDL,MDLOC,MDNOTE,MDPDT,MDPROC,MDRESU,MDTITL,MDTSTR,MDVST,MDVSTR,MDWP,MDPT
SET CTR=0
SET MDGST=+STUDY
SET MDRESU=""
+4 ; Get data for TIU Note Creation
+5 SET (MDTSTR,MDRESU)=$$GETDATA(MDGST)
+6 ; File Error message
+7 IF +MDRESU<0
DO FILEMSG(MDGST,"CP",2,MDRESU)
QUIT MDRESU
+8 IF $GET(MDTSTR)=""
QUIT "-1^No Data to Create TIU Document"
+9 FOR MDL="DFN","MDTITL","MDLOC","MDNOTE","MDCON","MDPROC","MDVSTR","MDNVST"
Begin DoDot:1
+10 SET CTR=CTR+1
SET @MDL=$PIECE(MDTSTR,"^",CTR)
End DoDot:1
+11 SET MDVST=""
+12 ; If previous TIU document exists, quit
+13 IF MDNOTE
QUIT MDNOTE
+14 IF $$GET^XPAR("SYS","MD GET HIGH VOLUME",MDPROC,"I")'=""&(+$PIECE(^MDD(702,+MDGST,0),"^",6))
QUIT $PIECE(^MDD(702,+MDGST,0),"^",6)
+15 IF 'MDLOC
QUIT "-1^No Hospital Location."
+16 ; Create new visit, if no vstring
+17 SET MDPDT=$$PDT^MDRPCOT1(MDGST)
+18 IF 'MDPDT
SET MDPT=$ORDER(^MDD(703.1,"ASTUDYID",+MDGST,0))
SET MDPDT=$PIECE($GET(^MDD(703.1,+MDPT,0)),U,3)
+19 ; If No D/T Performed grab visit D/T
if 'MDPDT
SET MDPDT=$PIECE(MDVSTR,";",2)
+20 IF $PIECE(MDVSTR,";",3)="V"
SET $PIECE(MDVSTR,";",3)="A"
+21 ; Build variables for TIU Call
+22 ; Undicated Status
SET MDWP(.05)=1
+23 ; Package Reference
SET MDWP(1405)=+MDCON_";GMR(123,"
+24 ; Default Procedure Summary Code "Machine Resulted"
SET MDWP(70201)=5
+25 ; Date/Time Performed
IF MDPDT
SET MDWP(70202)=MDPDT
+26 ; File PCE Error message
+27 IF MDNVST
SET MDRESU=$$EN1^MDPCE(MDGST,$PIECE(MDVSTR,";",2),MDPROC,$PIECE(MDVSTR,";",3),"P")
IF +MDRESU
SET MDVST=+MDRESU
SET MDVSTR=$PIECE(MDRESU,"^",2)
+28 IF MDNVST&(+MDRESU<0)
DO FILEMSG(MDGST,"PCE",2,$PIECE(MDRESU,"^",2))
QUIT MDRESU
+29 ; Create the TIU note stub
+30 SET MDNOTE=""
DO MAKE^TIUSRVP(.MDNOTE,DFN,MDTITL,$PIECE(MDVSTR,";",2),MDLOC,$SELECT(MDVST:MDVST,1:""),.MDWP,MDVSTR,1,1)
+31 IF '(+MDNOTE)
SET $PIECE(MDNOTE,"^")=-1
QUIT MDNOTE
+32 ; Finalize the transaction
+33 SET MDFDA(702,STUDY_",",.06)=+MDNOTE
+34 SET MDFDA(702,STUDY_",",.08)=""
+35 if MDVST>0
SET MDFDA(702,STUDY_",",.13)=MDVST
+36 DO FILE^DIE("","MDFDA")
+37 DO UPD^MDKUTLR(STUDY,+MDNOTE)
+38 QUIT 1
+39 ;
PREV(MDC,MDS) ; [Function] Return the Previous TIU document.
+1 NEW MDNEWV,MDDOC,MDTRAN,MDTIUER,MDTST
+2 SET (MDDOC,MDNEWV,MDTRAN,MDTIUER,MDTST)=""
KILL ^TMP("MDTIUST",$JOB)
+3 FOR
SET MDTRAN=$ORDER(^MDD(702,"ACON",MDC,MDTRAN))
if 'MDTRAN
QUIT
Begin DoDot:1
+4 IF $PIECE(^MDD(702,MDTRAN,0),U,6)
Begin DoDot:2
+5 DO EXTRACT^TIULQ($PIECE(^MDD(702,MDTRAN,0),U,6),"^TMP(""MDTIUST"",$J)",MDTIUER,".01;.05;1406")
if +MDTIUER
QUIT
+6 SET MDTST=$GET(^TMP("MDTIUST",$JOB,$PIECE(^MDD(702,MDTRAN,0),U,6),.05,"E"))
+7 IF MDTST'="UNDICTATED"&(MDTST'="UNSIGNED")
KILL ^TMP("MDTIUST",$JOB)
QUIT
+8 IF MDTST="UNSIGNED"&'($GET(^TMP("MDTIUST",$JOB,$PIECE(^MDD(702,MDTRAN,0),U,6),1406,"I")))
KILL ^TMP("MDTIUST",$JOB)
QUIT
+9 SET MDDOC=$PIECE(^MDD(702,MDTRAN,0),U,6)
SET MDNEWV=$PIECE(^MDD(702,MDTRAN,0),U,7)
+10 if 'MDS
QUIT
+11 SET MDFDA(702,MDS_",",.06)=MDDOC
+12 SET MDFDA(702,MDS_",",.07)=MDNEWV
+13 DO FILE^DIE("","MDFDA")
+14 SET MDTRAN=""
End DoDot:2
End DoDot:1
if 'MDTRAN
QUIT
+15 QUIT MDDOC
+16 ;