MPIFREQ ;SF/TN/CMC-CMOR CHANGE REQUEST ;FEB 20, 1998
;;1.0; MASTER PATIENT INDEX VISTA ;**1,6,11,26,30,34**;30 Apr 99
;
; Integration Agreements Utilized:
;
; EXC^RGHLLOG IA #2796
; START^RGHLLOG IA #2796
; STOP^RGHLLOG IA #2796
; $$EN^VAFCPID IA #3015
;
EN(TYPE,REQNO,ERROR,HL7) ;
; Create HL7 message for Change of CMOR Request
N RGL,INST,USER,REASON,NDATE,ICN,PHONE,N0,CNT,HLA,HL,ID,XX,PID
S CNT=0,HL=0
S N0=$G(^MPIF(984.9,REQNO,0))
I N0="" S ERROR="Node for request #"_REQNO_" is not defined" Q
S INST=$P($$SITE^VASITE(),"^",3) ;station number
N X,Y,DIC
S DIC="^VA(200,",DIC(0)="MZO",X="`"_+$P(N0,"^",2)
D ^DIC
I $G(Y)<1 S USER=""
I $G(Y)>0 S USER=$G(Y(0,0))
S REASON=$P($G(^MPIF(984.9,REQNO,1)),"^",2)
S NDATE=$P(N0,"^",3)
S ICN=$$ICN^MPIFNQ(+$P(N0,"^",4))
S PHONE=$P(N0,"^",5)
S ID=$P(N0,"^")
D INIT^HLFNC2("MPIF CMOR REQUEST",.HL)
I HL D START^RGHLLOG(),EXC^RGHLLOG(220,"Unable to setup HL7 for sending Change of CMOR Request # "_REQNO_" FOR ICN= "_ICN,$P(N0,"^",4)),STOP^RGHLLOG() D RESET(REQNO) Q
K HLL("LINKS") N MPILK
S MPILK=$$MPILINK^MPIFAPI ;routing all messages through the MPI
I +MPILK<0 D Q
.D START^RGHLLOG()
.D EXC^RGHLLOG(224,"No MPI link found for Change CMOR Request # "_REQNO_" for ICN="_ICN,$P(N0,"^",4))
.D STOP^RGHLLOG()
.D RESET^MPIFREQ(REQNO)
.S ERROR="-1^No Links found"
;Broadcast new CMOR to MPI which will send it out to all sites
S HLL("LINKS",1)="MPIF CMOR RESPONSE^"_MPILK
S CNT=CNT+1,PID=$$EN^VAFCPID(+$P(N0,"^",4),"1,2,4,5,6,7,8,11,12,13,14,16,17,19")
S HLA("HLS",CNT)=PID
S CNT=CNT+1
S CMOR=$P(^MPIF(984.9,REQNO,0),"^",9),CMOR=$$STA^XUAF4(CMOR)
S HLA("HLS",CNT)="NTE"_HL("FS")_HL("FS")_"P"_HL("FS")_PHONE_HL("FS")_REASON_HL("FS")_HL("FS")_ID_HL("FS")_INST_HL("FS")_HL("FS")_CMOR
S CNT=CNT+1
S HLA("HLS",CNT)="EVN"_HL("FS")_"A31"_HL("FS")_NDATE_HL("FS")_HL("FS")_""_HL("FS")_USER
N RLST
D GENERATE^HLMA("MPIF CMOR REQUEST","LM",1,.RLST,"",.HL)
I 'RLST D START^RGHLLOG(),EXC^RGHLLOG(220,"Unable to setup HL7 for sending Change of CMOR Request # "_REQNO_" for ICN= "_ICN,$P(N0,"^",4)),STOP^RGHLLOG(),RESET(REQNO)
Q
;
RESET(REQNO) ; reset status to Open
S DIE="^MPIF(984.9,",DA=REQNO,DR=".06///1" D ^DIE
K DIE,DA,DR
Q
;
IN(INST,USER,REASON,NDATE,ICN,PHONE,ID) ;Process an incoming CMOR request
N INSTN,PATIEN,MAIL,MPIF,TYPE,N0,IEN,XMCHAN,XMDUZ,XMTEXT,XMSUB,XMY,TEXT,X
S PATIEN=$$GETDFN^MPIF001(ICN)
I PATIEN<1 D Q
. D START^RGHLLOG()
. D EXC^RGHLLOG(210,"Received CMOR Change Request for ICN "_ICN_" ICN not Found. Request # "_ID)
. D STOP^RGHLLOG()
S IEN=$$ADD^MPIFNEW(ID) ;add request to request file
S TYPE=2 ;type of action to Request Received From
S INSTN=$G(HL("SFN")) ; site that sent this message - station #
S INST=$$IEN^XUAF4(INSTN),INST="`"_INST ; institution ien
S DIE="^MPIF(984.9,",DA=IEN,DR="[MPIF REQUEST INCOMING]" D ^DIE
I $$IFVCCI^MPIF001(+PATIEN)=-1 D PUSH(IEN) Q
; ^ your site isn't the CMOR, so this is a push to make you the CMOR
S DIE="^MPIF(984.9,",DA=IEN,DR=".09///"_INST D ^DIE
; ^ update CMOR AFTER APPROVAL field
I $$AUTO^MPIFNQ() D AUTO(IEN) Q
S MAIL=$$MAIL^MPIFUTL()
I MAIL="" S MAIL="MPIF EXCEPTIONS"
S XMDUZ="MPI VISTA Package",XMTEXT="MPIF(1,",MPIF(1,1)="New Coordinating Master Of Record (CMOR) request received for patient "_$S($P($G(^DPT(+PATIEN,0)),U)]"":$P(^DPT(PATIEN,0),"^")_" ("_$E($P(^(0),"^",9),6,9)_")",1:"UNKNOWN")
I MAIL="MPIF EXCEPTIONS" S XMTEXT=XMTEXT_" no mail group defined for CMOR requests"
S XMSUB="CMOR Change Request #"_$P(^MPIF(984.9,IEN,0),"^"),XMY("G."_MAIL)="" D ^XMD
Q
;
AUTO(REQNO) ;Process a request automatically
N DFN,MPIFERR,DIE,DR,DA,CMOR,RES,CMORN
S MPIFERR=0
S DIE="^MPIF(984.9,",DR="[MPIF REVIEW AUTO]",DA=REQNO D ^DIE
S DFN=$P($G(^MPIF(984.9,REQNO,0)),"^",4)
S CMORN=$P($G(^MPIF(984.9,REQNO,0)),"^",7)
S CMOR=$$CMORNAME^MPIF001(CMORN)
I +CMOR=-1 D START^RGHLLOG(),EXC^RGHLLOG(220,"CMOR not sent in Change CMOR message for patient DFN= "_DFN_" Request # "_REQNO,DFN),STOP^RGHLLOG(),RESET2(REQNO)
Q:+CMOR=-1 ;No CMOR defined
I $P($G(^MPIF(984.9,REQNO,1)),"^",3)=2 D
.S RES=1,RES=$$CHANGE^MPIF001(DFN,CMORN)
.I +RES<1 I +RES<1 D START^RGHLLOG(),EXC^RGHLLOG(220,"Unable to Change CMOR to "_CMOR_" in a CMOR Change Message for Patient DFN= "_DFN_" Request # "+REQNO,DFN),STOP^RGHLLOG(),RESET2(REQNO)
.Q:+RES<1
.D BROAD^MPIFCMOR(REQNO,.MPIFERR)
.I +MPIFERR=0 D EN^MPIFRESS(REQNO)
.; ^ trigger approval msg
Q
;
RESET2(REQNO) ; reset status to Pending Approval
S DIE="^MPIF(984.9,",DA=REQNO,DR=".06///3" D ^DIE
K DIE,DA,DR
Q
;
PUSH(IEN) ;Change of CMOR Request is a Push
; just want to get request into 984.9 for
; tracking purposes, marking it as approved
N DA,DIE,X,Y,TEXT
S DIE="^MPIF(984.9,",DA=IEN,TEXT="Auto change - CMOR pushed here"
S DR=".06///4;1.03///4;3.01///"_TEXT_";.09///`"_+$$SITE^VASITE()
D ^DIE
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMPIFREQ 4955 printed Nov 22, 2024@17:21:36 Page 2
MPIFREQ ;SF/TN/CMC-CMOR CHANGE REQUEST ;FEB 20, 1998
+1 ;;1.0; MASTER PATIENT INDEX VISTA ;**1,6,11,26,30,34**;30 Apr 99
+2 ;
+3 ; Integration Agreements Utilized:
+4 ;
+5 ; EXC^RGHLLOG IA #2796
+6 ; START^RGHLLOG IA #2796
+7 ; STOP^RGHLLOG IA #2796
+8 ; $$EN^VAFCPID IA #3015
+9 ;
EN(TYPE,REQNO,ERROR,HL7) ;
+1 ; Create HL7 message for Change of CMOR Request
+2 NEW RGL,INST,USER,REASON,NDATE,ICN,PHONE,N0,CNT,HLA,HL,ID,XX,PID
+3 SET CNT=0
SET HL=0
+4 SET N0=$GET(^MPIF(984.9,REQNO,0))
+5 IF N0=""
SET ERROR="Node for request #"_REQNO_" is not defined"
QUIT
+6 ;station number
SET INST=$PIECE($$SITE^VASITE(),"^",3)
+7 NEW X,Y,DIC
+8 SET DIC="^VA(200,"
SET DIC(0)="MZO"
SET X="`"_+$PIECE(N0,"^",2)
+9 DO ^DIC
+10 IF $GET(Y)<1
SET USER=""
+11 IF $GET(Y)>0
SET USER=$GET(Y(0,0))
+12 SET REASON=$PIECE($GET(^MPIF(984.9,REQNO,1)),"^",2)
+13 SET NDATE=$PIECE(N0,"^",3)
+14 SET ICN=$$ICN^MPIFNQ(+$PIECE(N0,"^",4))
+15 SET PHONE=$PIECE(N0,"^",5)
+16 SET ID=$PIECE(N0,"^")
+17 DO INIT^HLFNC2("MPIF CMOR REQUEST",.HL)
+18 IF HL
DO START^RGHLLOG()
DO EXC^RGHLLOG(220,"Unable to setup HL7 for sending Change of CMOR Request # "_REQNO_" FOR ICN= "_ICN,$PIECE(N0,"^",4))
DO STOP^RGHLLOG()
DO RESET(REQNO)
QUIT
+19 KILL HLL("LINKS")
NEW MPILK
+20 ;routing all messages through the MPI
SET MPILK=$$MPILINK^MPIFAPI
+21 IF +MPILK<0
Begin DoDot:1
+22 DO START^RGHLLOG()
+23 DO EXC^RGHLLOG(224,"No MPI link found for Change CMOR Request # "_REQNO_" for ICN="_ICN,$PIECE(N0,"^",4))
+24 DO STOP^RGHLLOG()
+25 DO RESET^MPIFREQ(REQNO)
+26 SET ERROR="-1^No Links found"
End DoDot:1
QUIT
+27 ;Broadcast new CMOR to MPI which will send it out to all sites
+28 SET HLL("LINKS",1)="MPIF CMOR RESPONSE^"_MPILK
+29 SET CNT=CNT+1
SET PID=$$EN^VAFCPID(+$PIECE(N0,"^",4),"1,2,4,5,6,7,8,11,12,13,14,16,17,19")
+30 SET HLA("HLS",CNT)=PID
+31 SET CNT=CNT+1
+32 SET CMOR=$PIECE(^MPIF(984.9,REQNO,0),"^",9)
SET CMOR=$$STA^XUAF4(CMOR)
+33 SET HLA("HLS",CNT)="NTE"_HL("FS")_HL("FS")_"P"_HL("FS")_PHONE_HL("FS")_REASON_HL("FS")_HL("FS")_ID_HL("FS")_INST_HL("FS")_HL("FS")_CMOR
+34 SET CNT=CNT+1
+35 SET HLA("HLS",CNT)="EVN"_HL("FS")_"A31"_HL("FS")_NDATE_HL("FS")_HL("FS")_""_HL("FS")_USER
+36 NEW RLST
+37 DO GENERATE^HLMA("MPIF CMOR REQUEST","LM",1,.RLST,"",.HL)
+38 IF 'RLST
DO START^RGHLLOG()
DO EXC^RGHLLOG(220,"Unable to setup HL7 for sending Change of CMOR Request # "_REQNO_" for ICN= "_ICN,$PIECE(N0,"^",4))
DO STOP^RGHLLOG()
DO RESET(REQNO)
+39 QUIT
+40 ;
RESET(REQNO) ; reset status to Open
+1 SET DIE="^MPIF(984.9,"
SET DA=REQNO
SET DR=".06///1"
DO ^DIE
+2 KILL DIE,DA,DR
+3 QUIT
+4 ;
IN(INST,USER,REASON,NDATE,ICN,PHONE,ID) ;Process an incoming CMOR request
+1 NEW INSTN,PATIEN,MAIL,MPIF,TYPE,N0,IEN,XMCHAN,XMDUZ,XMTEXT,XMSUB,XMY,TEXT,X
+2 SET PATIEN=$$GETDFN^MPIF001(ICN)
+3 IF PATIEN<1
Begin DoDot:1
+4 DO START^RGHLLOG()
+5 DO EXC^RGHLLOG(210,"Received CMOR Change Request for ICN "_ICN_" ICN not Found. Request # "_ID)
+6 DO STOP^RGHLLOG()
End DoDot:1
QUIT
+7 ;add request to request file
SET IEN=$$ADD^MPIFNEW(ID)
+8 ;type of action to Request Received From
SET TYPE=2
+9 ; site that sent this message - station #
SET INSTN=$GET(HL("SFN"))
+10 ; institution ien
SET INST=$$IEN^XUAF4(INSTN)
SET INST="`"_INST
+11 SET DIE="^MPIF(984.9,"
SET DA=IEN
SET DR="[MPIF REQUEST INCOMING]"
DO ^DIE
+12 IF $$IFVCCI^MPIF001(+PATIEN)=-1
DO PUSH(IEN)
QUIT
+13 ; ^ your site isn't the CMOR, so this is a push to make you the CMOR
+14 SET DIE="^MPIF(984.9,"
SET DA=IEN
SET DR=".09///"_INST
DO ^DIE
+15 ; ^ update CMOR AFTER APPROVAL field
+16 IF $$AUTO^MPIFNQ()
DO AUTO(IEN)
QUIT
+17 SET MAIL=$$MAIL^MPIFUTL()
+18 IF MAIL=""
SET MAIL="MPIF EXCEPTIONS"
+19 SET XMDUZ="MPI VISTA Package"
SET XMTEXT="MPIF(1,"
SET MPIF(1,1)="New Coordinating Master Of Record (CMOR) request received for patient "_$SELECT($PIECE($GET(^DPT(+PATIEN,0)),U)]"":$PIECE(^DPT(PATIEN,0),"^")_" ("_$EXTRACT($PIECE(^(0),"^",9),6,9)_")",1:"UNKNOWN")
+20 IF MAIL="MPIF EXCEPTIONS"
SET XMTEXT=XMTEXT_" no mail group defined for CMOR requests"
+21 SET XMSUB="CMOR Change Request #"_$PIECE(^MPIF(984.9,IEN,0),"^")
SET XMY("G."_MAIL)=""
DO ^XMD
+22 QUIT
+23 ;
AUTO(REQNO) ;Process a request automatically
+1 NEW DFN,MPIFERR,DIE,DR,DA,CMOR,RES,CMORN
+2 SET MPIFERR=0
+3 SET DIE="^MPIF(984.9,"
SET DR="[MPIF REVIEW AUTO]"
SET DA=REQNO
DO ^DIE
+4 SET DFN=$PIECE($GET(^MPIF(984.9,REQNO,0)),"^",4)
+5 SET CMORN=$PIECE($GET(^MPIF(984.9,REQNO,0)),"^",7)
+6 SET CMOR=$$CMORNAME^MPIF001(CMORN)
+7 IF +CMOR=-1
DO START^RGHLLOG()
DO EXC^RGHLLOG(220,"CMOR not sent in Change CMOR message for patient DFN= "_DFN_" Request # "_REQNO,DFN)
DO STOP^RGHLLOG()
DO RESET2(REQNO)
+8 ;No CMOR defined
if +CMOR=-1
QUIT
+9 IF $PIECE($GET(^MPIF(984.9,REQNO,1)),"^",3)=2
Begin DoDot:1
+10 SET RES=1
SET RES=$$CHANGE^MPIF001(DFN,CMORN)
+11 IF +RES<1
IF +RES<1
DO START^RGHLLOG()
DO EXC^RGHLLOG(220,"Unable to Change CMOR to "_CMOR_" in a CMOR Change Message for Patient DFN= "_DFN_" Request # "+REQNO,DFN)
DO STOP^RGHLLOG()
DO RESET2(REQNO)
+12 if +RES<1
QUIT
+13 DO BROAD^MPIFCMOR(REQNO,.MPIFERR)
+14 IF +MPIFERR=0
DO EN^MPIFRESS(REQNO)
+15 ; ^ trigger approval msg
End DoDot:1
+16 QUIT
+17 ;
RESET2(REQNO) ; reset status to Pending Approval
+1 SET DIE="^MPIF(984.9,"
SET DA=REQNO
SET DR=".06///3"
DO ^DIE
+2 KILL DIE,DA,DR
+3 QUIT
+4 ;
PUSH(IEN) ;Change of CMOR Request is a Push
+1 ; just want to get request into 984.9 for
+2 ; tracking purposes, marking it as approved
+3 NEW DA,DIE,X,Y,TEXT
+4 SET DIE="^MPIF(984.9,"
SET DA=IEN
SET TEXT="Auto change - CMOR pushed here"
+5 SET DR=".06///4;1.03///4;3.01///"_TEXT_";.09///`"_+$$SITE^VASITE()
+6 DO ^DIE
+7 QUIT