TIUCCRHL7P1 ; CCRA/PB - TIU CCRA HL7 Msg Processing; January 6, 2006
;;1.0;TEXT INTEGRATION UTILITIES;**337,344,348,349,352,356,366**;Sep 27, 2023;Build 2
;
;PB - Patch 344 to modify how the note and addendum text is formatted
;PB - Patch 348 modification to parse the note text from NTE segments rather than the OBX segment
;PB - Patch 349 modification to parse and file the consult factor from the note and file as a comment with the consult
;NOTES FROM NOV 10: Need to loop thru the XTMP("TIUHL7" temp global and if the last character is
;$C(160), remove it.
;PB - Patch 352 removes the text CF#: from the CFNOTE
;PB - Patch 356 modifications to file the note as a stand-alone note and not linked to a consult
Q
PROCMSG ;
N DFN,DUZ,CONSULTID,MSGID,TIU,TIUDA,TIUDPRM,TIUDT,TIUERR,TIUI,TIUJ,TIUMSG,TIUELS,STOP,TIUIEN,NOTEDATE,NOTENUM
N TIUEMAIL,TIUNAME,TIUTMP,TIUFS,TIUCS,TIURS,TIUES,TIUSS,TIUZ,VNUM,MSGTEXT,ADDENDUM,CFNOTE,ORIGSTAT,CONSULTID
S ADDENDUM=""
;
; remove HL7 message entries7 days or older
D CLEAN^TIUHL7U1
;
S U="^"
S TIUDT=$$NOW^XLFDT ;3200319.131747
;
; sets field, component and repetition separators from HL7 Message
S TIUFS=$G(HL("FS")),TIUJ=0 F TIUI="TIUCS","TIURS","TIUES","TIUSS" S TIUJ=TIUJ+1 S @TIUI=$E(HL("ECH"),TIUJ,TIUJ)
; initializes variables and ^XTMP expiration
S TIU="TIU",(TIU("EC"),TIUDA)=0,TIUNAME=$NA(^XTMP("TIUHL7",TIUDT,HLMTIENS)),^XTMP("TIUHL7",0)=$$FMADD^XLFDT(TIUDT,7)_U_TIUDT
S MSGID=HL("MID")
; retrieves HL7 message and stores to temporary global
F TIUI=1:1 X HLNEXT Q:HLQUIT'>0 D
. S @TIUNAME@("MSG",TIUI)=HLNODE,TIUJ=0
. F S TIUJ=$O(HLNODE(TIUJ)) Q:'TIUJ D
. . S @TIUNAME@("MSG",TIUI)=@TIUNAME@("MSG",TIUI)_HLNODE(TIUJ) ;$$TIUC^TIUCCHL7UT(HLNODE(TIUJ))
; places temporary global in local meory & adds EOM flag
M TIUMSG=@TIUNAME@("MSG")
S TIU("XTMP")=TIUNAME,TIUNAME="TIUMSG",TIUI="",TIUI=$O(TIUMSG(TIUI),-1),TIUI=TIUI+1,TIUMSG(TIUI)="EOM"
; verify message format
S TIUI="" F S TIUI=$O(@TIUNAME@(TIUI)) Q:@TIUNAME@(TIUI)="EOM" D
. S TIUJ=$S(TIUI=1:"MSH",TIUI=2:"EVN",TIUI=3:"PID",TIUI=4:"PV1",TIUI=5:"TXA",TIUI=6:"OBX",TIUI>6:"NTE",1:"OBX")
. I $P(@TIUNAME@(TIUI),TIUFS)'=TIUJ D ERR^TIUCCHL7UT("MSG",1,"000.000","Improper/missing message format: "_TIUJ_" segment.")
; get consult id
S CONSULTID=$$REMESC^TIUHL7U1($P($G(@TIUNAME@(4)),TIUFS,20))
;S CONID=$$REMESC^TIUHL7U1($P($G(@TIUNAME@(4)),TIUFS,20))
;S (TIU("VNUM"),VNUM)=+TIU("VNUM")
;S STOP=0
;I '$G(VNUM) D Q
;.S MSGTEXT="HL7 message missing Consult Number.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
;Q:$G(STOP)=1
;Q:$G(VNUM)'>0
; get patient name [required]
S TIU("PTNAME")=$$UPPER^HLFNC($$FMNAME^HLFNC($P($P($G(@TIUNAME@(3)),TIUFS,6),TIUCS,1,4),TIUCS)),TIU("PTNAME")=$$REMESC^TIUHL7U1(TIU("PTNAME"))
;
; get patient ICN/SSN/DFN - order may vary [conditionally required]
S (TIU("DFN"),TIU("ICN"),TIU("SSN"))="" F TIUI=1:1:$L($P($G(@TIUNAME@(3)),U,4),TIURS) S TIUJ=$P($P($G(@TIUNAME@(3)),TIUFS,4),TIURS,TIUI) I +TIUJ>0 D
. S TIU("ICN")=+$P(TIUJ,U,1)
I +$G(TIU("ICN"))'>0 S MSGTEXT="Patient ICN not in HL7 message.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
Q:$G(STOP)=1
Q:+$G(TIU("ICN"))'>0
S (DFN,TIU("DFN"))=$$GETDFN^MPIF001($P(TIU("ICN"),"V")),TIU("SSN")=$$GET1^DIQ(2,TIU("DFN")_",",.09,"I")
S TIUTMP=$S($P(TIUJ,TIUCS,5)="NI":"ICN",$P(TIUJ,TIUCS,5)="SS":"SSN",$P(TIUJ,TIUCS,5)="PI":"DFN",1:"UNK")
I +TIU("DFN")=-1 S MSGTEXT="Patient not found on VistA ",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
Q:$G(STOP)=1
Q:+TIU("DFN")=-1
; get dfn from consult in file 123 and compare to HL7 dfn
;I $G(VNUM)>0 N CDFN S CDFN=$$GET1^DIQ(123,VNUM_",",.02,"I") I CDFN'=TIU("DFN") D
;. ;S MSGTEXT="PATIENT NAME "_$G(TIU("PTNAME"))_" mismatch between HL7 message and CONSULT",STOP=1
;. ;D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
;Q:$G(STOP)=1
;Q:$G(CDFN)'=$G(TIU("DFN"))
; get DOCUMENT TITLE (#8925.1) [required] & set IEN, document title is in TIU("TITLE")
S TIU("TITLE")=$$UPPER^HLFNC($P($G(@TIUNAME@(5)),TIUFS,17)),TIU("TITLE")=$$REMESC^TIUHL7U1(TIU("TITLE"))
S TIU("TITLEB")=$$UPPER^HLFNC($P($G(@TIUNAME@(5)),TIUFS,3)),TIU("TITLEB")=$$REMESC^TIUHL7U1(TIU("TITLEB")),TIU("TITLEB")=$P(TIU("TITLEB"),"^",2)
;patch 344 code below to determine if this is an original note or an addendum
I $G(TIU("TITLEB"))["ADDENDUM" D
.K T2 S T2(" - ")="-" S TIU("TITLEB")=$$REPLACE^XLFSTR(TIU("TITLEB"),.T2) K T2
.S:$G(TIU("TITLEB"))["ADDENDUM" ADDENDUM=$P(TIU("TITLEB"),"-",2)
.;S TIU("TITLE")=$P(TIU("TITLEB"),"-",1)
S TIU("TDA")=$$LU^TIUHL7U1(8925.1,TIU("TITLE"),"X","I $P(^TIU(8925.1,+Y,0),U,4)=""DOC""") I $L(TIU("TITLE"))'>0 S TIU("TITLE")="[UNKNOWN]"
; get VISIT # [optional]
S:$G(TIU("VNUM"))'="" TIU("AVAIL")="AV",TIU("COMP")="LA"
;line of code added below to test filing a note but not linking it to a consult
S TIU("AVAIL")="AV",TIU("COMP")="LA"
S TIU("SIGNED")=$$NOW^TIULC,TIU("CSIGNED")=""
;I '$G(VNUM) D Q
;.;S MSGTEXT="HL7 message missing Consult Number.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
;Q:$G(STOP)=1
S TIUEMAIL=$$LOW^XLFSTR($P($G(@TIUNAME@(5)),TIUFS,10))
I $L(TIUEMAIL)'>0 S MSGTEXT="Missing or invalid VA Email Address.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
Q:$G(STOP)=1
Q:$L(TIUEMAIL)'>0
S (TIU("AUIEN"),TIU("AUDA"))=$O(^VA(200,"ADUPN",TIUEMAIL,""))
I $L(TIU("AUIEN"))'>0 S MSGTEXT="No valid User Account for "_$G(TIUEMAIL),STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
Q:$G(STOP)=1
Q:$L(TIU("AUIEN"))'>0
S TIU("AUNAME")=$$UPPER^HLFNC($P(^VA(200,TIU("AUIEN"),0),U,1))
S TIU("AUNAME")=$$REMESC^TIUHL7U1(TIU("AUNAME"))
S TIU("ELESIG")=$$GET1^DIQ(200,TIU("AUIEN"),20.4)
S TIUTMP="" F S TIUTMP=$O(@TIUNAME@(TIUTMP)) Q:TIUTMP="" D:$P($G(@TIUNAME@(TIUTMP)),TIUFS)="OBX"
. I $P(@TIUNAME@(TIUTMP),TIUFS,2)=1,$L($G(TIU("SUB")))'>0 S TIU("SUB")=$P($P(@TIUNAME@(TIUTMP),TIUFS,4),TIUCS,2),TIU("SUB")=$$REMESC^TIUHL7U1(TIU("SUB"))
. F TIUI=1:1:$L($P(@TIUNAME@(TIUTMP),TIUFS,6),TIURS) D
. . S TIUZ("TEXT",TIUI,0)=$P($P(@TIUNAME@(TIUTMP),TIUFS,6),TIURS,TIUI)
. . S TIUZ("TEXT",TIUI,0)=$$STRIP^TIUHL7U2($$REMESC^TIUHL7U1(TIUZ("TEXT",TIUI,0)))
I $L(@TIUNAME@(7))>0&($E(@TIUNAME@(7),1,3)="NTE") D
.N X1X,XCNTX S XCNTX=1,X1X=6 F S X1X=$O(@TIUNAME@(X1X)) Q:X1X'>"" D
..S TIUZ("TEXT",XCNTX,0)=$TR($P($G(@TIUNAME@(X1X)),"|",4),$C(160)," ")
..I $G(TIUZ("TEXT",XCNTX,0))["'" D
...N SPEC,T5 S SPEC("'")="'",T5=TIUZ("TEXT",XCNTX,0)
...S TIUZ("TEXT",XCNTX,0)=$$REPLACE^XLFSTR(T5,.SPEC)
..I $G(TIUZ("TEXT",XCNTX,0))[""" D
...N SPEC,T5 S SPEC(""")="""",T5=TIUZ("TEXT",XCNTX,0)
...S TIUZ("TEXT",XCNTX,0)=$$REPLACE^XLFSTR(T5,.SPEC)
..I $G(TIUZ("TEXT",XCNTX,0))["Original CCP Note Date (mm/dd/yyyy):" S NOTEDATE=$P(TIUZ("TEXT",XCNTX,0),":",2)
..I $G(TIUZ("TEXT",XCNTX,0))["CCPN Number:" S NOTENUM=$P(TIUZ("TEXT",XCNTX,0),":",2)
..I $G(TIUZ("TEXT",XCNTX,0))'=""&($L(TIUZ("TEXT",XCNTX,0))>80) D SPLIT(TIUZ("TEXT",XCNTX,0),XCNTX)
..;patch 349, PB - Feb 15, 2022 - modifications to capture the Consult Factor text to be filed as a comment with the consult
..I $G(TIUZ("TEXT",XCNTX,0))["CF#:" S CFNOTE=$P($G(TIUZ("TEXT",XCNTX,0)),"CF#: ",2)
..S XCNTX=XCNTX+1
I '$D(@TIUNAME@(7)) D
.D:$G(ADDENDUM)="" WORD
.D:$G(ADDENDUM)'="" WORD^TIUCCRHL7P4
;S:$G(ADDENDUM)'="" TIUIEN=$$TIULKUP^TIUCCHL7UT(VNUM,TIU("TITLE"),$G(NOTEDATE),$G(NOTEUM)) ;Patch 344 lookup the note in the consult to file the addendum with
; begin data verification
; PATIENT IDENTIFICATION
D
.Q
. N TIUI,TIUJ,TIUERR,TIUN,TIUOUT,TIUTMP,TIUQUIT
. I $D(TIU("DFN")) S TIUJ=1
. I '+$L($G(TIU("PTNAME"))) D ERR^TIUCCHL7UT("PID",5,"0000.00","Missing PATIENT NAME.")
. I +TIUJ=1 D
. . I '+$L($P(TIU("PTNAME"),",",2)) D ERR^TIUCCHL7UT("PID",5,"0000.00","FIRST NAME/INITIAL missing with only one numeric identifier sent.")
. . S TIUN("PT")=$$PNAME^TIUHL7U1(TIU("PTNAME")),TIUTMP=1
. E S TIUN("PT")=$P(TIU("PTNAME"),",")
. S TIUJ=0
. ; check DFN if available
. I +$G(TIU("DFN")) S TIUJ=TIUJ+1,DFN(TIUJ)=TIU("DFN") D
. . I +$G(TIUTMP) S TIUN("DFN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,TIU("DFN"),.01))
. . E S TIUN("DFN")=$P($$GET1^DIQ(2,TIU("DFN"),.01),",")
. . I '$$COMPARE^TIUHL7U1(TIUN("DFN"),TIUN("PT")) D ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message DFN #"_TIU("DFN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
. ; check ICN if available
. I +$G(TIU("ICN")) S TIUJ=TIUJ+1,DFN(TIUJ)=+$$FIND1^DIC(2,"","X",TIU("ICN"),"AICN") D
. . I +$G(TIUTMP) S TIUN("ICN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,DFN(TIUJ),.01))
. . E S TIUN("ICN")=$P($$GET1^DIQ(2,DFN(TIUJ),.01),",")
. . I '$$COMPARE^TIUHL7U1(TIUN("ICN"),TIUN("PT")) D ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message ICN #"_TIU("ICN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
. ; check SSN if available
. I +$G(TIU("SSN")) S TIUJ=TIUJ+1,DFN(TIUJ)=+$$FIND1^DIC(2,"","X",TIU("SSN"),"SSN") D
. . I +$G(TIUTMP) S TIUN("SSN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,DFN(TIUJ),.01))
. . E S TIUN("SSN")=$P($$GET1^DIQ(2,DFN(TIUJ),.01),",")
. . I '$$COMPARE^TIUHL7U1(TIUN("SSN"),TIUN("PT")) D ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message SSN #"_TIU("SSN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
. ; compare DFN lookup values
. I TIUJ>1 S (TIUI,TIUJ)=0 F S TIUI=$O(DFN(TIUI)) Q:'TIUI I TIUI>1 S TIUJ=TIUI-1 I DFN(TIUI)'=DFN(TIUJ) D ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT IEN discrepancies between the numeric lookups.") Q
. I TIU("EC") Q
. S DFN=DFN(1)
I $G(ADDENDUM)'="" D
.N N1 S N1=0 F S N1=$O(TIUZ("TEXT",N1)) Q:N1'>0 D
..I $G(TIUZ("TEXT",N1,0))["Original CCP Note Date (mm/dd/yyyy):" S NOTEDATE=$P(TIUZ("TEXT",N1,0),": ",2)
..I $G(TIUZ("TEXT",N1,0))["CCPN Number:" S NOTENUM=$P(TIUZ("TEXT",N1,0),": ",2)
.S:$G(NOTENUM)'="" TIUIEN=$$TIULKUP^TIUCCHL7UT(CONSULTID,TIU("TDA"),$G(NOTEDATE),NOTENUM)
;
D CONTINUE^TIUCCRHL7P2
Q
SPLIT(NODE,CNTR) ;
Q:$G(NODE)=""
Q:$G(CNTR)=""
Q:$L(NODE)<80
K LINE
S NODE=$TR(NODE,$C(160),""),XCNTX=CNTR
N WORDS,I,XX,SEGS,LEN
S LEN=$L(NODE),SEGS=LEN/80 S:$P(SEGS,".",2)>0 SEGS=SEGS+1
S WORDS=0 F I=1:1:$L(NODE) I $E(NODE,I)=" " S WORDS=WORDS+1
S XX="",CNT=1,LASTWORD=0
F I=1:1:(WORDS+1) D
.S XX=XX_$P(NODE," ",I)_" "
.I $L(XX)>80 D
..S LASTWORD=I
..S LINE(CNT)=XX,CNT=CNT+1 S XX="",TIUZ("TEXT",XCNTX,0)=$G(LINE(CNT-1)),XCNTX=XCNTX+1
I ((WORDS+1)>LASTWORD) D
.S LINE(CNT)=$P(NODE," ",LASTWORD+1,WORDS+1),TIUZ("TEXT",XCNTX,0)=$G(LINE(CNT)),XCNTX=XCNTX+1
K I,CNT,LASTWORD
Q
WORD ;
K I1,CNT,LCNT,LEN,I,LINES,T2,LASTWORDS,TEST1,WORDS,WORDSLEN,XX,T2,T4,T5
S WORDS=$G(TIUZ("TEXT",1,0)),WORDSLEN=$L(TIUZ("TEXT",1,0))
I $G(ADDENDUM)'="" D
.S NOTEDATE=$$GETDATE^TIUCCRHL7P4
.S NOTENUM=$$NOTENUM^TIUCCRHL7P4
.S:$G(NOTENUM)'="" TIUIEN=$$TIULKUP^TIUCCHL7UT(CONSULTID,TIU("TDA"),NOTEDATE,NOTENUM) ;Patch 344 lookup the note in the consult to file the addendum with
;S T2("VETERAN'S"_$C(160)_"CAREGIVER"_$C(160)_"CONTACT")="VETERAN'S CAREGIVER CONTACT"
;S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
F TEST1=1:1:WORDSLEN S LASTWORDS=$E(TIUZ("TEXT",1,0),WORDSLEN,(WORDSLEN-25))
K T2 S T2("PROVIDER"_$C(160)_"CONTACT ADDENDUM")="PROVIDER CONTACT ADDENDUM"
S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
;TEST CODE ADDED DEC 3
K T2 S T2("CCP Note Create Date:")=$C(10)_"CCP Note Create Date:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("CCPN Number:")=$C(10)_"CCPN Number:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
;K T2 S T2("Basic*")="Basic*"_$C(10) S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
;K T2 S T2("Navigation")=$C(10)_"Navigation" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
;K T2 S T2("Scheduling")=$C(10)_"Scheduling" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran Last Name:")=$C(10)_"Veteran Last Name:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran First Name:")=$C(10)_"Veteran First Name:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran Social:")=$C(10)_"Veteran Social:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2($C(160)_$C(160)_"CONSULT AND REFERRAL INFORMATION ")=$C(10)_"CONSULT AND REFERRAL INFORMATION " S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Name of Referring VA Provider:")=$C(10)_"Name of Referring VA Provider:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Selected SEOC:")=$C(10)_"Selected SEOC:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Referral Number:")=$C(10)_"Referral Number:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Unique Consult ID:")=$C(10)_"Unique Consult ID:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Patient Admitted (Yes/No): If yes, then please complete the Discharge Planning Addendum.")=$C(10)_"Patient Admitted (Yes/No): If yes, then please complete the Discharge Planning Addendum" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Chief Complaint: "_$C(160))=$C(10)_"Chief Complaint:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Risks")=$C(10)_"Risks x" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Level of Care Coordination: ")=$C(10)_"Level of Care Coordination: " S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2,T4 S T4="BasicPlease review all notes, this note may have one or more of the following addenda associated:" D
.K T5 S T5="Basic Please review all notes, this note may have one or more of the following addenda associated:"
.S T2($G(T4))=$C(10)_$G(T5) S WORDS=$$REPLACE^XLFSTR(WORDS,.T2) K T5
K T2 S T2("Care Coordination Follow Up:")=$C(10)_"Care Coordination Follow Up:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Appointment Management:")=$C(10)_"Appointment Management:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Case Management:")=$C(10)_"Case Management:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Continued Stay Review:")=$C(10)_"Continued Stay Review:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Disease Management:")=$C(10)_"Disease Management:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Discharge Planning:")=$C(10)_"Discharge Planning: " S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Discharge Disposition:")=$C(10)_"Discharge Disposition:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran Contact: ")=$C(10)_"Veteran Contact:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Provider Contact: ")=$C(10)_"Provider Contact:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Transfer:")=$C(10)_"Transfer:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran Handoff:")=$C(10)_"Veteran Handoff:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("FACILITY COMMUNITY CARE OFFICE CONTACT")=$C(10)_"FACILITY COMMUNITY CARE OFFICE CONTACT" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Care Coordination Point of Contact:")=$C(10)_"Care Coordination Point of Contact:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2(" Phone Number:")=$C(10)_"Phone Number:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
;K T2 S T2("VETERAN'S CAREGIVER CONTACT INFO")=$C(10)_"X1 VETERAN'S CAREGIVER CONTACT INFO" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2,T4 S T4="Is Veteran's caregiver same as next of kin listed in the demographic section of CPRS (Yes/No)?:" D
.S T2(T4)=$C(10)_T4 S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("If no, provide the following:")=$C(160)_"If no, provider the following:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Veteran's Caregiver Point of Contact:")=$C(10)_"Veteran's Caregiver Point of Contact" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Caregiver's Relationship to Veteran:")=$C(10)_"Caregiver's Relationship to Veteran:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Caregiver's Primary Phone Number:")=$C(10)_"Caregiver's Primary Phone Number::" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("Caregiver's Alternate Phone Number:")=$C(10)_"Caregiver's Alternate Phone Number:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("PLAN:")=$C(10)_"PLAN:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2,T4 S T4="*** CC Plan may include specialty and associated appointment information, date of surgery, post-op needs, post d/c appointment, and any other care coordination plan ***" D
.S T2(T4)=$C(10)_T4 S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
K T2 S T2("ADDITIONAL NOTES:")=$C(10)_"ADDITIONAL NOTES:" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
S LEN=$L(WORDS),I1=1,XX=1,CNT=0,LCNT=0
F I=1:1:LEN D
.S LCNT=LCNT+1
.I LCNT>100&($E(WORDS,I)=" ")!($E(WORDS,I)=$C(160))!($E(WORDS,I)=$C(10)) D
..S:XX=1 LINES("TEXT",XX,0)=$$TRIM^XLFSTR($E(WORDS,1,63),"LR"),XX=XX+1,I=64,LCNT=0,I1=I
..Q:XX=1
..S LINES("TEXT",XX,0)=$TR($E(WORDS,I1,I-1),$C(160)," "),LINES("TEXT",XX,0)=$$TRIM^XLFSTR(LINES("TEXT",XX,0),"LR"),XX=XX+1,LCNT=0 ;,I1=I
..;W !,$G(LINES("TEXT",XX-1,0))," ",XX-1_"^"_I1_"^"_I_"^"_LCNT
..S I1=I
I I1'=LEN N LASTLINES S LASTLINES=$E(WORDS,I1,I) K T2 S T2($C(160)_" ")="" S LINES("TEXT",XX,0)=$$REPLACE^XLFSTR(LASTLINES,.T2)
M TIUZ("TEXT")=LINES("TEXT")
K LINES("TEXT")
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIUCCRHL7P1 17434 printed Dec 13, 2024@02:39:05 Page 2
TIUCCRHL7P1 ; CCRA/PB - TIU CCRA HL7 Msg Processing; January 6, 2006
+1 ;;1.0;TEXT INTEGRATION UTILITIES;**337,344,348,349,352,356,366**;Sep 27, 2023;Build 2
+2 ;
+3 ;PB - Patch 344 to modify how the note and addendum text is formatted
+4 ;PB - Patch 348 modification to parse the note text from NTE segments rather than the OBX segment
+5 ;PB - Patch 349 modification to parse and file the consult factor from the note and file as a comment with the consult
+6 ;NOTES FROM NOV 10: Need to loop thru the XTMP("TIUHL7" temp global and if the last character is
+7 ;$C(160), remove it.
+8 ;PB - Patch 352 removes the text CF#: from the CFNOTE
+9 ;PB - Patch 356 modifications to file the note as a stand-alone note and not linked to a consult
+10 QUIT
PROCMSG ;
+1 NEW DFN,DUZ,CONSULTID,MSGID,TIU,TIUDA,TIUDPRM,TIUDT,TIUERR,TIUI,TIUJ,TIUMSG,TIUELS,STOP,TIUIEN,NOTEDATE,NOTENUM
+2 NEW TIUEMAIL,TIUNAME,TIUTMP,TIUFS,TIUCS,TIURS,TIUES,TIUSS,TIUZ,VNUM,MSGTEXT,ADDENDUM,CFNOTE,ORIGSTAT,CONSULTID
+3 SET ADDENDUM=""
+4 ;
+5 ; remove HL7 message entries7 days or older
+6 DO CLEAN^TIUHL7U1
+7 ;
+8 SET U="^"
+9 ;3200319.131747
SET TIUDT=$$NOW^XLFDT
+10 ;
+11 ; sets field, component and repetition separators from HL7 Message
+12 SET TIUFS=$GET(HL("FS"))
SET TIUJ=0
FOR TIUI="TIUCS","TIURS","TIUES","TIUSS"
SET TIUJ=TIUJ+1
SET @TIUI=$EXTRACT(HL("ECH"),TIUJ,TIUJ)
+13 ; initializes variables and ^XTMP expiration
+14 SET TIU="TIU"
SET (TIU("EC"),TIUDA)=0
SET TIUNAME=$NAME(^XTMP("TIUHL7",TIUDT,HLMTIENS))
SET ^XTMP("TIUHL7",0)=$$FMADD^XLFDT(TIUDT,7)_U_TIUDT
+15 SET MSGID=HL("MID")
+16 ; retrieves HL7 message and stores to temporary global
+17 FOR TIUI=1:1
XECUTE HLNEXT
if HLQUIT'>0
QUIT
Begin DoDot:1
+18 SET @TIUNAME@("MSG",TIUI)=HLNODE
SET TIUJ=0
+19 FOR
SET TIUJ=$ORDER(HLNODE(TIUJ))
if 'TIUJ
QUIT
Begin DoDot:2
+20 ;$$TIUC^TIUCCHL7UT(HLNODE(TIUJ))
SET @TIUNAME@("MSG",TIUI)=@TIUNAME@("MSG",TIUI)_HLNODE(TIUJ)
End DoDot:2
End DoDot:1
+21 ; places temporary global in local meory & adds EOM flag
+22 MERGE TIUMSG=@TIUNAME@("MSG")
+23 SET TIU("XTMP")=TIUNAME
SET TIUNAME="TIUMSG"
SET TIUI=""
SET TIUI=$ORDER(TIUMSG(TIUI),-1)
SET TIUI=TIUI+1
SET TIUMSG(TIUI)="EOM"
+24 ; verify message format
+25 SET TIUI=""
FOR
SET TIUI=$ORDER(@TIUNAME@(TIUI))
if @TIUNAME@(TIUI)="EOM"
QUIT
Begin DoDot:1
+26 SET TIUJ=$SELECT(TIUI=1:"MSH",TIUI=2:"EVN",TIUI=3:"PID",TIUI=4:"PV1",TIUI=5:"TXA",TIUI=6:"OBX",TIUI>6:"NTE",1:"OBX")
+27 IF $PIECE(@TIUNAME@(TIUI),TIUFS)'=TIUJ
DO ERR^TIUCCHL7UT("MSG",1,"000.000","Improper/missing message format: "_TIUJ_" segment.")
End DoDot:1
+28 ; get consult id
+29 SET CONSULTID=$$REMESC^TIUHL7U1($PIECE($GET(@TIUNAME@(4)),TIUFS,20))
+30 ;S CONID=$$REMESC^TIUHL7U1($P($G(@TIUNAME@(4)),TIUFS,20))
+31 ;S (TIU("VNUM"),VNUM)=+TIU("VNUM")
+32 ;S STOP=0
+33 ;I '$G(VNUM) D Q
+34 ;.S MSGTEXT="HL7 message missing Consult Number.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
+35 ;Q:$G(STOP)=1
+36 ;Q:$G(VNUM)'>0
+37 ; get patient name [required]
+38 SET TIU("PTNAME")=$$UPPER^HLFNC($$FMNAME^HLFNC($PIECE($PIECE($GET(@TIUNAME@(3)),TIUFS,6),TIUCS,1,4),TIUCS))
SET TIU("PTNAME")=$$REMESC^TIUHL7U1(TIU("PTNAME"))
+39 ;
+40 ; get patient ICN/SSN/DFN - order may vary [conditionally required]
+41 SET (TIU("DFN"),TIU("ICN"),TIU("SSN"))=""
FOR TIUI=1:1:$LENGTH($PIECE($GET(@TIUNAME@(3)),U,4),TIURS)
SET TIUJ=$PIECE($PIECE($GET(@TIUNAME@(3)),TIUFS,4),TIURS,TIUI)
IF +TIUJ>0
Begin DoDot:1
+42 SET TIU("ICN")=+$PIECE(TIUJ,U,1)
End DoDot:1
+43 IF +$GET(TIU("ICN"))'>0
SET MSGTEXT="Patient ICN not in HL7 message."
SET STOP=1
DO MESSAGE^TIUCCRHL7P3(MSGID,$GET(CONSULTID),MSGTEXT)
DO ANAK^TIUCCHL7UT(MSGID,$GET(MSGTEXT),$GET(CONSULTID))
+44 if $GET(STOP)=1
QUIT
+45 if +$GET(TIU("ICN"))'>0
QUIT
+46 SET (DFN,TIU("DFN"))=$$GETDFN^MPIF001($PIECE(TIU("ICN"),"V"))
SET TIU("SSN")=$$GET1^DIQ(2,TIU("DFN")_",",.09,"I")
+47 SET TIUTMP=$SELECT($PIECE(TIUJ,TIUCS,5)="NI":"ICN",$PIECE(TIUJ,TIUCS,5)="SS":"SSN",$PIECE(TIUJ,TIUCS,5)="PI":"DFN",1:"UNK")
+48 IF +TIU("DFN")=-1
SET MSGTEXT="Patient not found on VistA "
SET STOP=1
DO MESSAGE^TIUCCRHL7P3(MSGID,$GET(CONSULTID),MSGTEXT)
DO ANAK^TIUCCHL7UT(MSGID,$GET(MSGTEXT),$GET(CONSULTID))
+49 if $GET(STOP)=1
QUIT
+50 if +TIU("DFN")=-1
QUIT
+51 ; get dfn from consult in file 123 and compare to HL7 dfn
+52 ;I $G(VNUM)>0 N CDFN S CDFN=$$GET1^DIQ(123,VNUM_",",.02,"I") I CDFN'=TIU("DFN") D
+53 ;. ;S MSGTEXT="PATIENT NAME "_$G(TIU("PTNAME"))_" mismatch between HL7 message and CONSULT",STOP=1
+54 ;. ;D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
+55 ;Q:$G(STOP)=1
+56 ;Q:$G(CDFN)'=$G(TIU("DFN"))
+57 ; get DOCUMENT TITLE (#8925.1) [required] & set IEN, document title is in TIU("TITLE")
+58 SET TIU("TITLE")=$$UPPER^HLFNC($PIECE($GET(@TIUNAME@(5)),TIUFS,17))
SET TIU("TITLE")=$$REMESC^TIUHL7U1(TIU("TITLE"))
+59 SET TIU("TITLEB")=$$UPPER^HLFNC($PIECE($GET(@TIUNAME@(5)),TIUFS,3))
SET TIU("TITLEB")=$$REMESC^TIUHL7U1(TIU("TITLEB"))
SET TIU("TITLEB")=$PIECE(TIU("TITLEB"),"^",2)
+60 ;patch 344 code below to determine if this is an original note or an addendum
+61 IF $GET(TIU("TITLEB"))["ADDENDUM"
Begin DoDot:1
+62 KILL T2
SET T2(" - ")="-"
SET TIU("TITLEB")=$$REPLACE^XLFSTR(TIU("TITLEB"),.T2)
KILL T2
+63 if $GET(TIU("TITLEB"))["ADDENDUM"
SET ADDENDUM=$PIECE(TIU("TITLEB"),"-",2)
+64 ;S TIU("TITLE")=$P(TIU("TITLEB"),"-",1)
End DoDot:1
+65 SET TIU("TDA")=$$LU^TIUHL7U1(8925.1,TIU("TITLE"),"X","I $P(^TIU(8925.1,+Y,0),U,4)=""DOC""")
IF $LENGTH(TIU("TITLE"))'>0
SET TIU("TITLE")="[UNKNOWN]"
+66 ; get VISIT # [optional]
+67 if $GET(TIU("VNUM"))'=""
SET TIU("AVAIL")="AV"
SET TIU("COMP")="LA"
+68 ;line of code added below to test filing a note but not linking it to a consult
+69 SET TIU("AVAIL")="AV"
SET TIU("COMP")="LA"
+70 SET TIU("SIGNED")=$$NOW^TIULC
SET TIU("CSIGNED")=""
+71 ;I '$G(VNUM) D Q
+72 ;.;S MSGTEXT="HL7 message missing Consult Number.",STOP=1 D MESSAGE^TIUCCRHL7P3(MSGID,$G(CONSULTID),MSGTEXT),ANAK^TIUCCHL7UT(MSGID,$G(MSGTEXT),$G(CONSULTID))
+73 ;Q:$G(STOP)=1
+74 SET TIUEMAIL=$$LOW^XLFSTR($PIECE($GET(@TIUNAME@(5)),TIUFS,10))
+75 IF $LENGTH(TIUEMAIL)'>0
SET MSGTEXT="Missing or invalid VA Email Address."
SET STOP=1
DO MESSAGE^TIUCCRHL7P3(MSGID,$GET(CONSULTID),MSGTEXT)
DO ANAK^TIUCCHL7UT(MSGID,$GET(MSGTEXT),$GET(CONSULTID))
+76 if $GET(STOP)=1
QUIT
+77 if $LENGTH(TIUEMAIL)'>0
QUIT
+78 SET (TIU("AUIEN"),TIU("AUDA"))=$ORDER(^VA(200,"ADUPN",TIUEMAIL,""))
+79 IF $LENGTH(TIU("AUIEN"))'>0
SET MSGTEXT="No valid User Account for "_$GET(TIUEMAIL)
SET STOP=1
DO MESSAGE^TIUCCRHL7P3(MSGID,$GET(CONSULTID),MSGTEXT)
DO ANAK^TIUCCHL7UT(MSGID,$GET(MSGTEXT),$GET(CONSULTID))
+80 if $GET(STOP)=1
QUIT
+81 if $LENGTH(TIU("AUIEN"))'>0
QUIT
+82 SET TIU("AUNAME")=$$UPPER^HLFNC($PIECE(^VA(200,TIU("AUIEN"),0),U,1))
+83 SET TIU("AUNAME")=$$REMESC^TIUHL7U1(TIU("AUNAME"))
+84 SET TIU("ELESIG")=$$GET1^DIQ(200,TIU("AUIEN"),20.4)
+85 SET TIUTMP=""
FOR
SET TIUTMP=$ORDER(@TIUNAME@(TIUTMP))
if TIUTMP=""
QUIT
if $PIECE($GET(@TIUNAME@(TIUTMP)),TIUFS)="OBX"
Begin DoDot:1
+86 IF $PIECE(@TIUNAME@(TIUTMP),TIUFS,2)=1
IF $LENGTH($GET(TIU("SUB")))'>0
SET TIU("SUB")=$PIECE($PIECE(@TIUNAME@(TIUTMP),TIUFS,4),TIUCS,2)
SET TIU("SUB")=$$REMESC^TIUHL7U1(TIU("SUB"))
+87 FOR TIUI=1:1:$LENGTH($PIECE(@TIUNAME@(TIUTMP),TIUFS,6),TIURS)
Begin DoDot:2
+88 SET TIUZ("TEXT",TIUI,0)=$PIECE($PIECE(@TIUNAME@(TIUTMP),TIUFS,6),TIURS,TIUI)
+89 SET TIUZ("TEXT",TIUI,0)=$$STRIP^TIUHL7U2($$REMESC^TIUHL7U1(TIUZ("TEXT",TIUI,0)))
End DoDot:2
End DoDot:1
+90 IF $LENGTH(@TIUNAME@(7))>0&($EXTRACT(@TIUNAME@(7),1,3)="NTE")
Begin DoDot:1
+91 NEW X1X,XCNTX
SET XCNTX=1
SET X1X=6
FOR
SET X1X=$ORDER(@TIUNAME@(X1X))
if X1X'>""
QUIT
Begin DoDot:2
+92 SET TIUZ("TEXT",XCNTX,0)=$TRANSLATE($PIECE($GET(@TIUNAME@(X1X)),"|",4),$CHAR(160)," ")
+93 IF $GET(TIUZ("TEXT",XCNTX,0))["'"
Begin DoDot:3
+94 NEW SPEC,T5
SET SPEC("'")="'"
SET T5=TIUZ("TEXT",XCNTX,0)
+95 SET TIUZ("TEXT",XCNTX,0)=$$REPLACE^XLFSTR(T5,.SPEC)
End DoDot:3
+96 IF $GET(TIUZ("TEXT",XCNTX,0))["""
Begin DoDot:3
+97 NEW SPEC,T5
SET SPEC(""")=""""
SET T5=TIUZ("TEXT",XCNTX,0)
+98 SET TIUZ("TEXT",XCNTX,0)=$$REPLACE^XLFSTR(T5,.SPEC)
End DoDot:3
+99 IF $GET(TIUZ("TEXT",XCNTX,0))["Original CCP Note Date (mm/dd/yyyy):"
SET NOTEDATE=$PIECE(TIUZ("TEXT",XCNTX,0),":",2)
+100 IF $GET(TIUZ("TEXT",XCNTX,0))["CCPN Number:"
SET NOTENUM=$PIECE(TIUZ("TEXT",XCNTX,0),":",2)
+101 IF $GET(TIUZ("TEXT",XCNTX,0))'=""&($LENGTH(TIUZ("TEXT",XCNTX,0))>80)
DO SPLIT(TIUZ("TEXT",XCNTX,0),XCNTX)
+102 ;patch 349, PB - Feb 15, 2022 - modifications to capture the Consult Factor text to be filed as a comment with the consult
+103 IF $GET(TIUZ("TEXT",XCNTX,0))["CF#:"
SET CFNOTE=$PIECE($GET(TIUZ("TEXT",XCNTX,0)),"CF#: ",2)
+104 SET XCNTX=XCNTX+1
End DoDot:2
End DoDot:1
+105 IF '$DATA(@TIUNAME@(7))
Begin DoDot:1
+106 if $GET(ADDENDUM)=""
DO WORD
+107 if $GET(ADDENDUM)'=""
DO WORD^TIUCCRHL7P4
End DoDot:1
+108 ;S:$G(ADDENDUM)'="" TIUIEN=$$TIULKUP^TIUCCHL7UT(VNUM,TIU("TITLE"),$G(NOTEDATE),$G(NOTEUM)) ;Patch 344 lookup the note in the consult to file the addendum with
+109 ; begin data verification
+110 ; PATIENT IDENTIFICATION
+111 Begin DoDot:1
+112 QUIT
+113 NEW TIUI,TIUJ,TIUERR,TIUN,TIUOUT,TIUTMP,TIUQUIT
+114 IF $DATA(TIU("DFN"))
SET TIUJ=1
+115 IF '+$LENGTH($GET(TIU("PTNAME")))
DO ERR^TIUCCHL7UT("PID",5,"0000.00","Missing PATIENT NAME.")
+116 IF +TIUJ=1
Begin DoDot:2
+117 IF '+$LENGTH($PIECE(TIU("PTNAME"),",",2))
DO ERR^TIUCCHL7UT("PID",5,"0000.00","FIRST NAME/INITIAL missing with only one numeric identifier sent.")
+118 SET TIUN("PT")=$$PNAME^TIUHL7U1(TIU("PTNAME"))
SET TIUTMP=1
End DoDot:2
+119 IF '$TEST
SET TIUN("PT")=$PIECE(TIU("PTNAME"),",")
+120 SET TIUJ=0
+121 ; check DFN if available
+122 IF +$GET(TIU("DFN"))
SET TIUJ=TIUJ+1
SET DFN(TIUJ)=TIU("DFN")
Begin DoDot:2
+123 IF +$GET(TIUTMP)
SET TIUN("DFN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,TIU("DFN"),.01))
+124 IF '$TEST
SET TIUN("DFN")=$PIECE($$GET1^DIQ(2,TIU("DFN"),.01),",")
+125 IF '$$COMPARE^TIUHL7U1(TIUN("DFN"),TIUN("PT"))
DO ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message DFN #"_TIU("DFN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
End DoDot:2
+126 ; check ICN if available
+127 IF +$GET(TIU("ICN"))
SET TIUJ=TIUJ+1
SET DFN(TIUJ)=+$$FIND1^DIC(2,"","X",TIU("ICN"),"AICN")
Begin DoDot:2
+128 IF +$GET(TIUTMP)
SET TIUN("ICN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,DFN(TIUJ),.01))
+129 IF '$TEST
SET TIUN("ICN")=$PIECE($$GET1^DIQ(2,DFN(TIUJ),.01),",")
+130 IF '$$COMPARE^TIUHL7U1(TIUN("ICN"),TIUN("PT"))
DO ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message ICN #"_TIU("ICN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
End DoDot:2
+131 ; check SSN if available
+132 IF +$GET(TIU("SSN"))
SET TIUJ=TIUJ+1
SET DFN(TIUJ)=+$$FIND1^DIC(2,"","X",TIU("SSN"),"SSN")
Begin DoDot:2
+133 IF +$GET(TIUTMP)
SET TIUN("SSN")=$$PNAME^TIUHL7U1($$GET1^DIQ(2,DFN(TIUJ),.01))
+134 IF '$TEST
SET TIUN("SSN")=$PIECE($$GET1^DIQ(2,DFN(TIUJ),.01),",")
+135 IF '$$COMPARE^TIUHL7U1(TIUN("SSN"),TIUN("PT"))
DO ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT NAME discrepancy between HL7 message name ["_TIU("PTNAME")_"] & the HL7 message SSN #"_TIU("SSN")_" ["_$$GET1^DIQ(2,DFN(TIUJ),.01)_"].")
End DoDot:2
+136 ; compare DFN lookup values
+137 IF TIUJ>1
SET (TIUI,TIUJ)=0
FOR
SET TIUI=$ORDER(DFN(TIUI))
if 'TIUI
QUIT
IF TIUI>1
SET TIUJ=TIUI-1
IF DFN(TIUI)'=DFN(TIUJ)
DO ERR^TIUCCHL7UT("PID",5,"0000.00","PATIENT IEN discrepancies between the numeric lookups.")
QUIT
+138 IF TIU("EC")
QUIT
+139 SET DFN=DFN(1)
End DoDot:1
+140 IF $GET(ADDENDUM)'=""
Begin DoDot:1
+141 NEW N1
SET N1=0
FOR
SET N1=$ORDER(TIUZ("TEXT",N1))
if N1'>0
QUIT
Begin DoDot:2
+142 IF $GET(TIUZ("TEXT",N1,0))["Original CCP Note Date (mm/dd/yyyy):"
SET NOTEDATE=$PIECE(TIUZ("TEXT",N1,0),": ",2)
+143 IF $GET(TIUZ("TEXT",N1,0))["CCPN Number:"
SET NOTENUM=$PIECE(TIUZ("TEXT",N1,0),": ",2)
End DoDot:2
+144 if $GET(NOTENUM)'=""
SET TIUIEN=$$TIULKUP^TIUCCHL7UT(CONSULTID,TIU("TDA"),$GET(NOTEDATE),NOTENUM)
End DoDot:1
+145 ;
+146 DO CONTINUE^TIUCCRHL7P2
+147 QUIT
SPLIT(NODE,CNTR) ;
+1 if $GET(NODE)=""
QUIT
+2 if $GET(CNTR)=""
QUIT
+3 if $LENGTH(NODE)<80
QUIT
+4 KILL LINE
+5 SET NODE=$TRANSLATE(NODE,$CHAR(160),"")
SET XCNTX=CNTR
+6 NEW WORDS,I,XX,SEGS,LEN
+7 SET LEN=$LENGTH(NODE)
SET SEGS=LEN/80
if $PIECE(SEGS,".",2)>0
SET SEGS=SEGS+1
+8 SET WORDS=0
FOR I=1:1:$LENGTH(NODE)
IF $EXTRACT(NODE,I)=" "
SET WORDS=WORDS+1
+9 SET XX=""
SET CNT=1
SET LASTWORD=0
+10 FOR I=1:1:(WORDS+1)
Begin DoDot:1
+11 SET XX=XX_$PIECE(NODE," ",I)_" "
+12 IF $LENGTH(XX)>80
Begin DoDot:2
+13 SET LASTWORD=I
+14 SET LINE(CNT)=XX
SET CNT=CNT+1
SET XX=""
SET TIUZ("TEXT",XCNTX,0)=$GET(LINE(CNT-1))
SET XCNTX=XCNTX+1
End DoDot:2
End DoDot:1
+15 IF ((WORDS+1)>LASTWORD)
Begin DoDot:1
+16 SET LINE(CNT)=$PIECE(NODE," ",LASTWORD+1,WORDS+1)
SET TIUZ("TEXT",XCNTX,0)=$GET(LINE(CNT))
SET XCNTX=XCNTX+1
End DoDot:1
+17 KILL I,CNT,LASTWORD
+18 QUIT
WORD ;
+1 KILL I1,CNT,LCNT,LEN,I,LINES,T2,LASTWORDS,TEST1,WORDS,WORDSLEN,XX,T2,T4,T5
+2 SET WORDS=$GET(TIUZ("TEXT",1,0))
SET WORDSLEN=$LENGTH(TIUZ("TEXT",1,0))
+3 IF $GET(ADDENDUM)'=""
Begin DoDot:1
+4 SET NOTEDATE=$$GETDATE^TIUCCRHL7P4
+5 SET NOTENUM=$$NOTENUM^TIUCCRHL7P4
+6 ;Patch 344 lookup the note in the consult to file the addendum with
if $GET(NOTENUM)'=""
SET TIUIEN=$$TIULKUP^TIUCCHL7UT(CONSULTID,TIU("TDA"),NOTEDATE,NOTENUM)
End DoDot:1
+7 ;S T2("VETERAN'S"_$C(160)_"CAREGIVER"_$C(160)_"CONTACT")="VETERAN'S CAREGIVER CONTACT"
+8 ;S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+9 FOR TEST1=1:1:WORDSLEN
SET LASTWORDS=$EXTRACT(TIUZ("TEXT",1,0),WORDSLEN,(WORDSLEN-25))
+10 KILL T2
SET T2("PROVIDER"_$CHAR(160)_"CONTACT ADDENDUM")="PROVIDER CONTACT ADDENDUM"
+11 SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+12 ;TEST CODE ADDED DEC 3
+13 KILL T2
SET T2("CCP Note Create Date:")=$CHAR(10)_"CCP Note Create Date:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+14 KILL T2
SET T2("CCPN Number:")=$CHAR(10)_"CCPN Number:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+15 ;K T2 S T2("Basic*")="Basic*"_$C(10) S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+16 ;K T2 S T2("Navigation")=$C(10)_"Navigation" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+17 ;K T2 S T2("Scheduling")=$C(10)_"Scheduling" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+18 KILL T2
SET T2("Veteran Last Name:")=$CHAR(10)_"Veteran Last Name:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+19 KILL T2
SET T2("Veteran First Name:")=$CHAR(10)_"Veteran First Name:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+20 KILL T2
SET T2("Veteran Social:")=$CHAR(10)_"Veteran Social:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+21 KILL T2
SET T2($CHAR(160)_$CHAR(160)_"CONSULT AND REFERRAL INFORMATION ")=$CHAR(10)_"CONSULT AND REFERRAL INFORMATION "
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+22 KILL T2
SET T2("Name of Referring VA Provider:")=$CHAR(10)_"Name of Referring VA Provider:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+23 KILL T2
SET T2("Selected SEOC:")=$CHAR(10)_"Selected SEOC:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+24 KILL T2
SET T2("Referral Number:")=$CHAR(10)_"Referral Number:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+25 KILL T2
SET T2("Unique Consult ID:")=$CHAR(10)_"Unique Consult ID:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+26 KILL T2
SET T2("Patient Admitted (Yes/No): If yes, then please complete the Discharge Planning Addendum.")=$CHAR(10)_"Patient Admitted (Yes/No): If yes, then please complete the Discharge Planning Addendum"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+27 KILL T2
SET T2("Chief Complaint: "_$CHAR(160))=$CHAR(10)_"Chief Complaint:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+28 KILL T2
SET T2("Risks")=$CHAR(10)_"Risks x"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+29 KILL T2
SET T2("Level of Care Coordination: ")=$CHAR(10)_"Level of Care Coordination: "
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+30 KILL T2,T4
SET T4="BasicPlease review all notes, this note may have one or more of the following addenda associated:"
Begin DoDot:1
+31 KILL T5
SET T5="Basic Please review all notes, this note may have one or more of the following addenda associated:"
+32 SET T2($GET(T4))=$CHAR(10)_$GET(T5)
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
KILL T5
End DoDot:1
+33 KILL T2
SET T2("Care Coordination Follow Up:")=$CHAR(10)_"Care Coordination Follow Up:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+34 KILL T2
SET T2("Appointment Management:")=$CHAR(10)_"Appointment Management:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+35 KILL T2
SET T2("Case Management:")=$CHAR(10)_"Case Management:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+36 KILL T2
SET T2("Continued Stay Review:")=$CHAR(10)_"Continued Stay Review:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+37 KILL T2
SET T2("Disease Management:")=$CHAR(10)_"Disease Management:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+38 KILL T2
SET T2("Discharge Planning:")=$CHAR(10)_"Discharge Planning: "
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+39 KILL T2
SET T2("Discharge Disposition:")=$CHAR(10)_"Discharge Disposition:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+40 KILL T2
SET T2("Veteran Contact: ")=$CHAR(10)_"Veteran Contact:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+41 KILL T2
SET T2("Provider Contact: ")=$CHAR(10)_"Provider Contact:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+42 KILL T2
SET T2("Transfer:")=$CHAR(10)_"Transfer:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+43 KILL T2
SET T2("Veteran Handoff:")=$CHAR(10)_"Veteran Handoff:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+44 KILL T2
SET T2("FACILITY COMMUNITY CARE OFFICE CONTACT")=$CHAR(10)_"FACILITY COMMUNITY CARE OFFICE CONTACT"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+45 KILL T2
SET T2("Care Coordination Point of Contact:")=$CHAR(10)_"Care Coordination Point of Contact:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+46 KILL T2
SET T2(" Phone Number:")=$CHAR(10)_"Phone Number:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+47 ;K T2 S T2("VETERAN'S CAREGIVER CONTACT INFO")=$C(10)_"X1 VETERAN'S CAREGIVER CONTACT INFO" S WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+48 KILL T2,T4
SET T4="Is Veteran's caregiver same as next of kin listed in the demographic section of CPRS (Yes/No)?:"
Begin DoDot:1
+49 SET T2(T4)=$CHAR(10)_T4
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
End DoDot:1
+50 KILL T2
SET T2("If no, provide the following:")=$CHAR(160)_"If no, provider the following:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+51 KILL T2
SET T2("Veteran's Caregiver Point of Contact:")=$CHAR(10)_"Veteran's Caregiver Point of Contact"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+52 KILL T2
SET T2("Caregiver's Relationship to Veteran:")=$CHAR(10)_"Caregiver's Relationship to Veteran:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+53 KILL T2
SET T2("Caregiver's Primary Phone Number:")=$CHAR(10)_"Caregiver's Primary Phone Number::"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+54 KILL T2
SET T2("Caregiver's Alternate Phone Number:")=$CHAR(10)_"Caregiver's Alternate Phone Number:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+55 KILL T2
SET T2("PLAN:")=$CHAR(10)_"PLAN:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+56 KILL T2,T4
SET T4="*** CC Plan may include specialty and associated appointment information, date of surgery, post-op needs, post d/c appointment, and any other care coordination plan ***"
Begin DoDot:1
+57 SET T2(T4)=$CHAR(10)_T4
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
End DoDot:1
+58 KILL T2
SET T2("ADDITIONAL NOTES:")=$CHAR(10)_"ADDITIONAL NOTES:"
SET WORDS=$$REPLACE^XLFSTR(WORDS,.T2)
+59 SET LEN=$LENGTH(WORDS)
SET I1=1
SET XX=1
SET CNT=0
SET LCNT=0
+60 FOR I=1:1:LEN
Begin DoDot:1
+61 SET LCNT=LCNT+1
+62 IF LCNT>100&($EXTRACT(WORDS,I)=" ")!($EXTRACT(WORDS,I)=$CHAR(160))!($EXTRACT(WORDS,I)=$CHAR(10))
Begin DoDot:2
+63 if XX=1
SET LINES("TEXT",XX,0)=$$TRIM^XLFSTR($EXTRACT(WORDS,1,63),"LR")
SET XX=XX+1
SET I=64
SET LCNT=0
SET I1=I
+64 if XX=1
QUIT
+65 ;,I1=I
SET LINES("TEXT",XX,0)=$TRANSLATE($EXTRACT(WORDS,I1,I-1),$CHAR(160)," ")
SET LINES("TEXT",XX,0)=$$TRIM^XLFSTR(LINES("TEXT",XX,0),"LR")
SET XX=XX+1
SET LCNT=0
+66 ;W !,$G(LINES("TEXT",XX-1,0))," ",XX-1_"^"_I1_"^"_I_"^"_LCNT
+67 SET I1=I
End DoDot:2
End DoDot:1
+68 IF I1'=LEN
NEW LASTLINES
SET LASTLINES=$EXTRACT(WORDS,I1,I)
KILL T2
SET T2($CHAR(160)_" ")=""
SET LINES("TEXT",XX,0)=$$REPLACE^XLFSTR(LASTLINES,.T2)
+69 MERGE TIUZ("TEXT")=LINES("TEXT")
+70 KILL LINES("TEXT")
+71 QUIT