VAFCOFIN ;BIR/DR-TREATING FACILTIY MFU PROCESSING ROUTINE ; 2/1/10 12:46pm
;;5.3;Registration;**821**;Aug 13, 1993;Build 7
;Reference to EXC, START, and STOP^RGHLLOG supported by IA #2796
;
;***NOTE***
;This routine is copy of original VAFCTFIN before DG*5.3*821
;It is modified so VistA can process MFN~M05 in old format until
;MPI starts sending new format.
;
IN ;This entry point is used to process the Treating Facility Master File Update Message.
;It is called by the VAFC MFN-M05 CLIENT processing routine when a MFN
;message is received.
;There are no inputs or outputs
;
I HL("MTN")="MFK" D RSP Q
N VAFC,STATN,VAFCI,MSG,SG,VAFCARR,PDFN,INST,MFUPT,PDLT,TFIEN
N ICN,MFI,MFE,MFA,HLCOMP,CNT,X,VAFCERR,VAFCX
;quit if Master Patient Index (MPI) is not installed
S X="MPIF001" X ^%ZOSF("TEST") Q:'$T
S X="MPIFQ0" X ^%ZOSF("TEST") Q:'$T
S X="RGRSBUL1" X ^%ZOSF("TEST") Q:'$T
S X="RGRSBULL" X ^%ZOSF("TEST") Q:'$T
INIT ;Process in the Treating Facility MFN msg
F VAFCI=1:1 X HLNEXT Q:HLQUIT'>0 S (MSG,VAFC(VAFCI))=HLNODE,SG=$E(HLNODE,1,3) D:SG?2A1(1A,1N) PICK
;reconcil the inbound TF list from the MPI to the local TF list
D RECONCIL
;create response message
S CNT=1
S HLA("HLA",1)="MSA"_HL("FS")_"AA"_HL("FS")_HL("MID")_HL("FS") S CNT=CNT+1
S HLA("HLA",CNT)=MFI S CNT=CNT+1
S VAFCX=0 F S VAFCX=$O(MFE(VAFCX)) Q:'VAFCX S HLA("HLA",CNT)=MFE(VAFCX),CNT=CNT+1,HLA("HLA",CNT)=MFA(VAFCX),CNT=CNT+1
;generate an application level ack (MFK) identifying the status of the adds/edits/deletes of TF's passed in
D ROUTE
D GENACK^HLMA1(HL("EID"),HLMTIENS,HL("EIDS"),"LM",1,.VAFCERR,"",.HLP)
Q
PICK ;check routine for segment entry point
I $T(@SG)]"" D @SG
I $T(@SG)="" Q
Q
MSH ;;MSH
;process the MSH segment
S (HLFS,HL("FS"))=$E(MSG,4),(HLECH,HL("ECH"))=$E(MSG,5,8)
S HLCOMP=$E(HL("ECH"),1)
S VAFCARR("SENDING SITE")=$P(MSG,HL("FS"),4)
Q
EVN ;;EVN
;process the EVN segment
S STATN=+$$SITE^VASITE()_"^"_$$FMDATE^HLFNC($P(MSG,HL("FS"),3))
Q
PID ;;PID
;process the PID segment
S PDFN=+$P(MSG,HL("FS"),4)
Q
MFI ;;MFI
;process the MFI segment
S MFI=MSG
S MFUPT=$P(MSG,HL("FS"),4)
S VAFCARR("CMOR")=$P($P(MSG,HL("FS"),8),$E(HL("ECH"),1))
Q
MFE ;;MFE
;process the MFE segment
N HLCOMP,NXTSGMT,TYPE
S HLCOMP=$E(HL("ECH"),1)
S PDLT=$$FMDATE^HLFNC($P(MSG,HL("FS"),4))
S ICN=$P($P(MSG,HL("FS"),5),HLCOMP,4)
S INST=$P($P(MSG,HL("FS"),5),HLCOMP)
S TYPE=$P(MSG,HL("FS"),2)
S MFE(INST)=MSG
S MFI(ICN,INST)=PDLT_"^^"_TYPE
Q
ZET ;;ZET
;process Patient's Date Last Treated Event Type, ZET segment
N PDLTET,IPP
S PDLTET=$P(MSG,HL("FS"),2)
S $P(MFI(ICN,INST),"^",2)=PDLTET
;DG*5.3*800 - Process In-Person Proofed
S IPP=$P(MSG,HL("FS"),3) ;In-Person Proofed
S $P(MFI(ICN,INST),"^",6)=IPP
Q
RSP ;response process logic entry point
Q
ROUTE ;routing logic entry point
N MPI
S MPI=$$MPILINK^MPIFAPI() D
.I $P($G(MPI),U)'=-1 S HLL("LINKS",1)="VAFC MFN-M05 CLIENT"_"^"_MPI
.I $P($G(MPI),U)=-1 D
.. N RGLOG D START^RGHLLOG(HLMTIEN,"","")
.. D EXC^RGHLLOG(224,"No MPI link identified in CIRN SITE PARAMETER file (#991.8)",$G(PDFN))
.. D STOP^RGHLLOG(0)
Q
TEST ;
W $$REPROC^HLUTIL(39266,"D IN^VAFCTFIN")
Q
RECONCIL ;
N DFN,MFIC,VAFCX,VAFCY,TFL,CNFLT,LOCCMOR,VAFCTYPE
S CNFLT=0
S DFN=$$GETDFN^MPIF001(ICN)
I DFN'>0 S CNFLT=1_"^"_$P($G(DFN),"^",2)
I MFUPT="REP" I +CNFLT=0 D TFL^VAFCTFU1(.TFL,DFN) S VAFCX=0 F S VAFCX=$O(TFL(VAFCX)) Q:'VAFCX D
. S MFIC($P(TFL(VAFCX),"^"))=TFL(VAFCX) I '$D(MFI(ICN,$P(TFL(VAFCX),"^"))) D DEL(ICN,$P(TFL(VAFCX),"^"))
;VAFCX=ICN and VAFCY=INSTITUTION
S VAFCX=0 F S VAFCX=$O(MFI(VAFCX)) Q:'VAFCX D
. S VAFCY=0 F S VAFCY=$O(MFI(VAFCX,VAFCY)) Q:'VAFCY D
..S VAFCTYPE=$P(MFI(VAFCX,VAFCY),"^",3)
..I +CNFLT=1 S MFA(VAFCY)="MFA"_HL("FS")_VAFCTYPE_HL("FS")_VAFCY_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")_"U"_HLCOMP_$S(VAFCTYPE="MDL":"Delete of ",1:"Update of ")_VAFCY_" Failed at "_$P($$SITE^VASITE,"^",3)_" due to "_$P(CNFLT,"^",2)
..I +CNFLT=0 I VAFCTYPE="MAD"!(VAFCTYPE="MUP") D ADDUPD(DFN,VAFCY,$P(MFI(VAFCX,VAFCY),"^"),$P(MFI(VAFCX,VAFCY),"^",2),$P(MFI(VAFCX,VAFCY),"^",6))
..I +CNFLT=0 I VAFCTYPE="MDL" D DEL(ICN,VAFCY)
Q
ADDUPD(DFN,INST,PDLT,PDLRTET,IPP) ;add or update TF entry
N ERROR,STA
S STA=INST
S INST=$$LKUP^XUAF4(INST)
D FILE^VAFCOTFU(DFN,INST_"^"_$G(PDLT)_"^"_$G(PDLRTET),1,1,.ERROR,$G(IPP))
S MFA(STA)="MFA"_HL("FS")_"MUP"_HL("FS")_STA_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")
I '$D(ERROR(STA)) S MFA(STA)=MFA(STA)_"S"
I $D(ERROR(STA)) S MFA(STA)=MFA(STA)_"U"_HLCOMP_ERROR(STA)_HL("FS")
Q
DEL(ICN,INST) ;delete a TF entry
N ERROR,STA
S STA=INST
S INST=$$LKUP^XUAF4(INST)
S ERROR=$$DELETETF^VAFCOTFU(ICN,INST)
S MFA(STA)="MFA"_HL("FS")_"MDL"_HL("FS")_STA_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")
I +ERROR'=1 S MFA(STA)=MFA(STA)_"S"
I +ERROR=1 S MFA(STA)=MFA(STA)_"U"_HLCOMP_"Delete Failed: "_$P(ERROR,"^",2)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HVAFCOFIN 4967 printed Oct 16, 2024@19:02:37 Page 2
VAFCOFIN ;BIR/DR-TREATING FACILTIY MFU PROCESSING ROUTINE ; 2/1/10 12:46pm
+1 ;;5.3;Registration;**821**;Aug 13, 1993;Build 7
+2 ;Reference to EXC, START, and STOP^RGHLLOG supported by IA #2796
+3 ;
+4 ;***NOTE***
+5 ;This routine is copy of original VAFCTFIN before DG*5.3*821
+6 ;It is modified so VistA can process MFN~M05 in old format until
+7 ;MPI starts sending new format.
+8 ;
IN ;This entry point is used to process the Treating Facility Master File Update Message.
+1 ;It is called by the VAFC MFN-M05 CLIENT processing routine when a MFN
+2 ;message is received.
+3 ;There are no inputs or outputs
+4 ;
+5 IF HL("MTN")="MFK"
DO RSP
QUIT
+6 NEW VAFC,STATN,VAFCI,MSG,SG,VAFCARR,PDFN,INST,MFUPT,PDLT,TFIEN
+7 NEW ICN,MFI,MFE,MFA,HLCOMP,CNT,X,VAFCERR,VAFCX
+8 ;quit if Master Patient Index (MPI) is not installed
+9 SET X="MPIF001"
XECUTE ^%ZOSF("TEST")
if '$TEST
QUIT
+10 SET X="MPIFQ0"
XECUTE ^%ZOSF("TEST")
if '$TEST
QUIT
+11 SET X="RGRSBUL1"
XECUTE ^%ZOSF("TEST")
if '$TEST
QUIT
+12 SET X="RGRSBULL"
XECUTE ^%ZOSF("TEST")
if '$TEST
QUIT
INIT ;Process in the Treating Facility MFN msg
+1 FOR VAFCI=1:1
XECUTE HLNEXT
if HLQUIT'>0
QUIT
SET (MSG,VAFC(VAFCI))=HLNODE
SET SG=$EXTRACT(HLNODE,1,3)
if SG?2A1(1A,1N)
DO PICK
+2 ;reconcil the inbound TF list from the MPI to the local TF list
+3 DO RECONCIL
+4 ;create response message
+5 SET CNT=1
+6 SET HLA("HLA",1)="MSA"_HL("FS")_"AA"_HL("FS")_HL("MID")_HL("FS")
SET CNT=CNT+1
+7 SET HLA("HLA",CNT)=MFI
SET CNT=CNT+1
+8 SET VAFCX=0
FOR
SET VAFCX=$ORDER(MFE(VAFCX))
if 'VAFCX
QUIT
SET HLA("HLA",CNT)=MFE(VAFCX)
SET CNT=CNT+1
SET HLA("HLA",CNT)=MFA(VAFCX)
SET CNT=CNT+1
+9 ;generate an application level ack (MFK) identifying the status of the adds/edits/deletes of TF's passed in
+10 DO ROUTE
+11 DO GENACK^HLMA1(HL("EID"),HLMTIENS,HL("EIDS"),"LM",1,.VAFCERR,"",.HLP)
+12 QUIT
PICK ;check routine for segment entry point
+1 IF $TEXT(@SG)]""
DO @SG
+2 IF $TEXT(@SG)=""
QUIT
+3 QUIT
MSH ;;MSH
+1 ;process the MSH segment
+2 SET (HLFS,HL("FS"))=$EXTRACT(MSG,4)
SET (HLECH,HL("ECH"))=$EXTRACT(MSG,5,8)
+3 SET HLCOMP=$EXTRACT(HL("ECH"),1)
+4 SET VAFCARR("SENDING SITE")=$PIECE(MSG,HL("FS"),4)
+5 QUIT
EVN ;;EVN
+1 ;process the EVN segment
+2 SET STATN=+$$SITE^VASITE()_"^"_$$FMDATE^HLFNC($PIECE(MSG,HL("FS"),3))
+3 QUIT
PID ;;PID
+1 ;process the PID segment
+2 SET PDFN=+$PIECE(MSG,HL("FS"),4)
+3 QUIT
MFI ;;MFI
+1 ;process the MFI segment
+2 SET MFI=MSG
+3 SET MFUPT=$PIECE(MSG,HL("FS"),4)
+4 SET VAFCARR("CMOR")=$PIECE($PIECE(MSG,HL("FS"),8),$EXTRACT(HL("ECH"),1))
+5 QUIT
MFE ;;MFE
+1 ;process the MFE segment
+2 NEW HLCOMP,NXTSGMT,TYPE
+3 SET HLCOMP=$EXTRACT(HL("ECH"),1)
+4 SET PDLT=$$FMDATE^HLFNC($PIECE(MSG,HL("FS"),4))
+5 SET ICN=$PIECE($PIECE(MSG,HL("FS"),5),HLCOMP,4)
+6 SET INST=$PIECE($PIECE(MSG,HL("FS"),5),HLCOMP)
+7 SET TYPE=$PIECE(MSG,HL("FS"),2)
+8 SET MFE(INST)=MSG
+9 SET MFI(ICN,INST)=PDLT_"^^"_TYPE
+10 QUIT
ZET ;;ZET
+1 ;process Patient's Date Last Treated Event Type, ZET segment
+2 NEW PDLTET,IPP
+3 SET PDLTET=$PIECE(MSG,HL("FS"),2)
+4 SET $PIECE(MFI(ICN,INST),"^",2)=PDLTET
+5 ;DG*5.3*800 - Process In-Person Proofed
+6 ;In-Person Proofed
SET IPP=$PIECE(MSG,HL("FS"),3)
+7 SET $PIECE(MFI(ICN,INST),"^",6)=IPP
+8 QUIT
RSP ;response process logic entry point
+1 QUIT
ROUTE ;routing logic entry point
+1 NEW MPI
+2 SET MPI=$$MPILINK^MPIFAPI()
Begin DoDot:1
+3 IF $PIECE($GET(MPI),U)'=-1
SET HLL("LINKS",1)="VAFC MFN-M05 CLIENT"_"^"_MPI
+4 IF $PIECE($GET(MPI),U)=-1
Begin DoDot:2
+5 NEW RGLOG
DO START^RGHLLOG(HLMTIEN,"","")
+6 DO EXC^RGHLLOG(224,"No MPI link identified in CIRN SITE PARAMETER file (#991.8)",$GET(PDFN))
+7 DO STOP^RGHLLOG(0)
End DoDot:2
End DoDot:1
+8 QUIT
TEST ;
+1 WRITE $$REPROC^HLUTIL(39266,"D IN^VAFCTFIN")
+2 QUIT
RECONCIL ;
+1 NEW DFN,MFIC,VAFCX,VAFCY,TFL,CNFLT,LOCCMOR,VAFCTYPE
+2 SET CNFLT=0
+3 SET DFN=$$GETDFN^MPIF001(ICN)
+4 IF DFN'>0
SET CNFLT=1_"^"_$PIECE($GET(DFN),"^",2)
+5 IF MFUPT="REP"
IF +CNFLT=0
DO TFL^VAFCTFU1(.TFL,DFN)
SET VAFCX=0
FOR
SET VAFCX=$ORDER(TFL(VAFCX))
if 'VAFCX
QUIT
Begin DoDot:1
+6 SET MFIC($PIECE(TFL(VAFCX),"^"))=TFL(VAFCX)
IF '$DATA(MFI(ICN,$PIECE(TFL(VAFCX),"^")))
DO DEL(ICN,$PIECE(TFL(VAFCX),"^"))
End DoDot:1
+7 ;VAFCX=ICN and VAFCY=INSTITUTION
+8 SET VAFCX=0
FOR
SET VAFCX=$ORDER(MFI(VAFCX))
if 'VAFCX
QUIT
Begin DoDot:1
+9 SET VAFCY=0
FOR
SET VAFCY=$ORDER(MFI(VAFCX,VAFCY))
if 'VAFCY
QUIT
Begin DoDot:2
+10 SET VAFCTYPE=$PIECE(MFI(VAFCX,VAFCY),"^",3)
+11 IF +CNFLT=1
SET MFA(VAFCY)="MFA"_HL("FS")_VAFCTYPE_HL("FS")_VAFCY_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")_"U"_HLCOMP_$SELECT(VAFCTYPE="MDL":"Delete of ",1:"Update of ")_VAFCY_" Failed at "_$PIECE($$SITE^VASITE,"^",3)_" due to "_$P
IECE(CNFLT,"^",2)
+12 IF +CNFLT=0
IF VAFCTYPE="MAD"!(VAFCTYPE="MUP")
DO ADDUPD(DFN,VAFCY,$PIECE(MFI(VAFCX,VAFCY),"^"),$PIECE(MFI(VAFCX,VAFCY),"^",2),$PIECE(MFI(VAFCX,VAFCY),"^",6))
+13 IF +CNFLT=0
IF VAFCTYPE="MDL"
DO DEL(ICN,VAFCY)
End DoDot:2
End DoDot:1
+14 QUIT
ADDUPD(DFN,INST,PDLT,PDLRTET,IPP) ;add or update TF entry
+1 NEW ERROR,STA
+2 SET STA=INST
+3 SET INST=$$LKUP^XUAF4(INST)
+4 DO FILE^VAFCOTFU(DFN,INST_"^"_$GET(PDLT)_"^"_$GET(PDLRTET),1,1,.ERROR,$GET(IPP))
+5 SET MFA(STA)="MFA"_HL("FS")_"MUP"_HL("FS")_STA_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")
+6 IF '$DATA(ERROR(STA))
SET MFA(STA)=MFA(STA)_"S"
+7 IF $DATA(ERROR(STA))
SET MFA(STA)=MFA(STA)_"U"_HLCOMP_ERROR(STA)_HL("FS")
+8 QUIT
DEL(ICN,INST) ;delete a TF entry
+1 NEW ERROR,STA
+2 SET STA=INST
+3 SET INST=$$LKUP^XUAF4(INST)
+4 SET ERROR=$$DELETETF^VAFCOTFU(ICN,INST)
+5 SET MFA(STA)="MFA"_HL("FS")_"MDL"_HL("FS")_STA_HL("FS")_$$HLDATE^HLFNC($$NOW^XLFDT)_HL("FS")
+6 IF +ERROR'=1
SET MFA(STA)=MFA(STA)_"S"
+7 IF +ERROR=1
SET MFA(STA)=MFA(STA)_"U"_HLCOMP_"Delete Failed: "_$PIECE(ERROR,"^",2)
+8 QUIT