You are on page 1of 10

HL7 Class Notes:

HL7 Specifications & Naming Conventions can be found at

R:\ClientSupport\Product Team Info\Fin Product Info\Misys Healthcare Systems


Financial HL7 spefication.doc

ACK files:

1. If the file has missing headers or control characters then the entire file will ACK.

2. If the file has missing required data fields (PID, PVI, DG1, GT1, IN1, ACC, FT1, BLG)
then the affected accession(s) will ACK.

^AROEN

^AROEN ^ 1 status bits (1=on,0=off)


1=process HL7 file (active/inactive)
2=set history file (^HL7PTHIS)
3=process type (1=file,0=global)
^ 2 current file being processed
^ 3 directory for new files (unprocessed)
^ 4 directory for archived files (processed)
^ 5 directory for AROENF.COM file (background) VMS ONLY
^ 6 purge criteria in days
^ 7 last purge run date
^ 8 Default Company

Example: ^AROEN=111^^[DSMMGR.HL7]^[DSMMGR.HL7]^[DSMMGR.HL7]^30^^

Auto Vs. Manual Processing

Auto – HL7

^%EXSCHED(201)=_DSA1:[ANTRIM.FIN.FNA]^AUTOHL7^AROEN^
^%EXSCHED(201,0)=58945,50652

AUTOHL7 ;****************************************************************************************************
; ENTRY POINT - for the scheduler for processing standard (HL7) records
;****************************************************************************************************
S $ZT="^%Z801001"
S MONITOR=$G(MONITOR) I '$D(RELEASE) S RELEASE=1
L +^AROEN:10 I '$T W:'RELEASE *7," Networking already in progress",! Q
S AROEN=$G(^AROEN) I AROEN="" W:'RELEASE *7," Networking is not currently defined",! Q
S NETSTS=$P(AROEN,"^") I '$E(NETSTS) W:'RELEASE *7," Networking is currently disabled",! Q
D ^AROENF
L -^AROEN
Q
Manual – HL7

^MENU("FI3",1,1,22) = PROCESS NEW NETWORK FILES]MANUAL^AROEN]$E(SSPK,1)>4]]]

MANUAL ;****************************************************************************************************
;ENTRY POINT - to allow the user to manually start the processing of new files
;****************************************************************************************************
L +^AROEN:1 I '$T W *7,!!,"Networking is currently in progress",! G MANEXIT
S AROEN=$G(^AROEN) I AROEN="" W *7,!!,"Networking is not currently defined",! G MANEXIT
S NETSTS=$P(AROEN,"^") I '$E(NETSTS) W *7,!!,"Networking is currently disabled",! G MANEXIT
W !,"*** Process new previously UNPROCESSED network files ***",!
S PMODE=$$PMODE^%ZIO2 I 'PMODE S RELEASE=1 G MAN90
MAN10 R !,"Release device: <Y> ",RELEASE:120 G MANQUIT:RELEASE="^",MANQUIT:RELEASE="//"
I RELEASE?1."?" S %="AROEN1" D @($S(RELEASE="?":"",1:"X")_"^%ZEXQ") G MAN10
I $E("YES",1,$L(RELEASE))=RELEASE S RELEASE=1 G MAN90
I $E("NO",1,$L(RELEASE))=RELEASE S RELEASE=0 G MAN90
W *7," invalid" G MAN10
MAN90 R !,"Do you wish to continue: <Y> ",ANS:120 G MANQUIT:ANS="^" I ANS="//" G
MANQUIT:'PMODE,MAN10
I ANS?1."?" S %="AROEN2" D @($S(ANS="?":"",1:"X")_"^%ZEXQ") G MAN90
I $E("YES",1,$L(ANS))=ANS G MAN99
I $E("NO",1,$L(ANS))=ANS G MANQUIT
W *7," invalid" G MAN90
MAN99 I 'RELEASE W *7,!!,"***** Processing started *****",! D AUTOHL7 W *7,!,"***** Processing
completed *****",! G MANEXIT
S %EPNAME="AUTOHL7^AROEN" W *7,!!,"Process started",*7 H 1 L -^AROEN G ^%ZDETACH
MANEXIT R !,"Enter <CR> to continue: ",ANS:120
MANQUIT L -^AROEN
Q

^HL7PTHIS

Purge based upon days set in ^AROEN – piece 6.

11^^USER1:[DSMMGR.MUMPS_PROG.SBR]^USER1:[DSMMGR.MUMPS_PROG.SBR]^USER1:
[DSMMGR.MUMPS_PROG.SBR]|^60^58933^ANTRIM

AROENP

S AROEN=$G(^AROEN),PRGDYS=$P(AROEN,"^",6) I PRGDYS=""!(PRGDYS'>0) Q
K ^UT($J) S PRGDT=$H-PRGDYS
;
S FNM="" F S FNM=$O(^AROEN(FNM)) Q:FNM="" S FX=^(FNM) D
. S PRCDT=$P(FX,"^",3),HL7FILE=$P(FX,"^",4),ARCFILE=$P(FX,"^",5)
. I +FX,PRCDT<PRGDT S XRTN=$$FDEL^%ZIO5(ARCFILE,"",.XER) K ^AROEN(FNM) Q
. S ^UT($J,HL7FILE)=""
;
S CO="" F S CO=$O(^HL7PTHIS(CO)) Q:CO="" D
. S BT="" F S BT=$O(^HL7PTHIS(CO,BT)) Q:BT="" D
. . S PT="" F S PT=$O(^HL7PTHIS(CO,BT,PT)) Q:PT="" D
. . . S SQ="" F S SQ=$O(^HL7PTHIS(CO,BT,PT,SQ)) Q:SQ="" S FNM=$P(^(SQ),"^") I
'$D(^UT($J,FNM)) K ^HL7PTHIS(CO,BT,PT,SQ)
. . . I $O(^HL7PTHIS(CO,BT,PT,""))="" K ^HL7PTHIS(CO,BT,PT)
;
K ^UT($J)
Q
MHZHL7 will search for an accession and IF it finds the HL7 file, it will display the HL7 file.

******************************* HL7 Utilities ********************************

Currently logged into: _DSA1:[ANTRIM.TST.TSF]

1) Search HL7 file for accession/text


2) List contents of HL7 file

Selection: 1

-------------- Utility to search for ACCESSIONS within HL7 file --------------

Output Device: <_LTA5127:>

Enter search type:


1) Search for accessions based on ^HL7PTHIS
2) Search specific HL7 files for accessions or text

Selection: <1>

Accession to search for: 114L6302

Files found from ^HL7PTHIS for (114L6302)


SYS$SYSDEVICE:[ANTAPPS.TSF]HL7ARC_SQL_58958_001_001_001.DAT;2
SYS$SYSDEVICE:[ANTAPPS.TSF]HL7ARC_SQL_58959_001_001_001.DAT;1

Do you wish to continue? <YES>

Searching for (114L6302)... (Enter CTRL-'C' to interrupt)

HL7 file: SYS$SYSDEVICE:[ANTAPPS.TSF]HL7ARC_SQL_58958_001_001_001.DAT;2


file not found or access denied

================================================================================
HL7 file: SYS$SYSDEVICE:[ANTAPPS.TSF]HL7ARC_SQL_58959_001_001_001.DAT;1
================================================================================

13333 MSH|^~\&|FLEXILAB|SQ|FIN||200206051520||ORM^O01|2825|P|2.3
13334 PID||L054936|114L6302~M58920|L22661268~L054936|WARE^LYDIA^||19030220|F||||||||||
166369335|166369335
13335 BLG|T^200206051520

Enter <CR> to continue:

HL7 Who Calls

Record Segment Who Calls who reformat data contained in that HL7 segment:

FHS^WHOOEN
BHS^WHOOEN
MSH^WHOOEN
PID^WHOOEN
PV1^WHOOEN
DG1^WHOOEN
GT1^WHOOEN
IN1^WHOOEN
FT1^WHOOEN
BLG^WHOOEN
ACC^WHOOEN
BTS^WHOOEN
FTS^WHOOEN
NTE^WHOOEN (Still used?)

FILE^WHOOEN1
START^WHOOEN1
LOOP^WHOOEN1
END^WHOOEN1

AROEN1 ;LAB/FIN HL7 NETWORKING;;;12/21/2001, 15:23;MTH;AR3.3.4


;
; RESTRICTED RIGHTS NOTICE
; Use, reproduction or disclosure subject to restrictions set forth in
; Software License Agreement and FAR 52.227-19, (c)(1) and (2).
; Unpublished works - all rights reserved under
; Copyright Laws of the USA.
; NOT GOVERNMENT PROPERTY
;
; Copyright 1986 - 2002 by Antrim Corporation
; All Rights Reserved.
; Unpublished and confidential material under license.
; Do not disclose or reproduce.
;--------------------------------------------------------------------------------
;ver;user;doc;date
;AR3.2.0;MTH;153.598;12/22/1998
;AR3.2.0;MTH;154.315;02/03/1999
;AR3.2.1;MTH;152.1423;04/22/1999
;AR3.2.1;MTH;153.85;06/14/1999
;AR3.2.1;MTH;157.584;08/24/1999
;AR3.2.1;MTH;157.941;09/20/1999
;AR3.2.1;MTH;158.562;11/11/1999
;AR3.3.0;MTH;152.722;11/01/1999
;AR3.3.1;MTH;158.99;08/28/2000
;AR3.3.3;MTH;1-1J7QD;06/06/2001
;AR3.3.3;MTH;1-2254Y;07/23/2001
;AR3.3.4;MTH;1-35PD7;12/21/2001
;--------------------------------------------------------------------------------
;
Q ;This routine is not called directly. Must use an entry point.
;
EXEC(LTAG) ;
S $ZT="^%Z801001" N TAG
F S TAG=$P(LTAG,",") Q:TAG="" S LTAG=$P(LTAG,",",2,999) D @TAG
Q
;
FHSREC ;FHS record
D S %WHO=$P($G(^OI(%O)),"^",17)
. I FHSCO'="" S X=$G(^NETXRF(HL7NID,"CO","*","F",FHSCO)) S:X'="" FHSCO=X I '$D(^OI(FHSCO))
S FHSCO=""
. I FHSCO'="" S %O=FHSCO Q
. S %O=DFLTCO ;default company
FHSRECE I %WHO'="" S %WHOP="FHS^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
BHSREC ;BHS record
D S %WHO=$P($G(^OI(%O)),"^",17)
. I BHSCO'="" S X=$G(^NETXRF(HL7NID,"CO","*","F",BHSCO)) S:X'="" BHSCO=X I
'$D(^OI(BHSCO)) S BHSCO=""
. I BHSCO'="" S %O=BHSCO Q
. I FHSCO'="" S %O=FHSCO Q
. S %O=DFLTCO ;default company
BHSRECE I %WHO'="" S %WHOP="BHS^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
MSHREC ;MSH record
F I="CT","OUC","D1E","D1I","DGN","DGNTXT" K ^UT($J,I)
D S %WHO=$P($G(^OI(%O)),"^",17)
. I MSHCO'="" S X=$G(^NETXRF(HL7NID,"CO","*","F",MSHCO)) S:X'="" MSHCO=X I
'$D(^OI(MSHCO)) S MSHCO=""
. I MSHCO'="" S %O=MSHCO Q
. I BHSCO'="" S %O=BHSCO Q
. I FHSCO'="" S %O=FHSCO Q
. S %O=DFLTCO ;default company
F XCO=%O,"*" D
. I $D(XRF(HL7NID,XCO)) Q
. F XTYP="CT","CL","INSCO","OLOC","OUC","PHY","REFL","TLOC" S
XRF(HL7NID,XCO,XTYP)=$D(^NETXRF(HL7NID,XTYP,XCO))
S OI=$G(^OI(%O)),OI0=$G(^(%O,0)),OI1=$G(^(1)),%WHO=$P(OI,"^",17),%MDOS=+$P(OI1,"^",7)
S OIDEF=$G(^OI(%O,0,"OIDEF"))
S GPRLNK=$P(OI1,"^",10) I GPRLNK="" S GPRLNK="Y"
S GPRBLD=$P(OI1,"^",11) I GPRBLD="" S GPRBLD="N"
S GPRUPD=$P(OI1,"^",12) I GPRUPD="" S GPRUPD="N"
MSHRECE I %WHO'="" S %WHOP="MSH^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
PIDREC ;PID record
PIDRECE I %WHO'="" S %WHOP="PID^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
PV1REC ;PV1 record
I DXOCL'="" D S X=$G(^LOC(%O,"CM",DXOCL)) I X'="" S DXOCL=X
. I XRF(HL7NID,%O,"CL") S X=$G(^NETXRF(HL7NID,"CL",%O,"F",DXOCL)) I X'="" S DXOCL=X Q
. I XRF(HL7NID,"*","CL") S X=$G(^NETXRF(HL7NID,"CL","*","F",DXOCL)) I X'="" S DXOCL=X Q
I DXRQP'="" D
. I XRF(HL7NID,%O,"PHY") S X=$G(^NETXRF(HL7NID,"PHY",%O,"F",DXRQP)) I X'="" S DXRQP=X
Q
. I XRF(HL7NID,"*","PHY") S X=$G(^NETXRF(HL7NID,"PHY","*","F",DXRQP)) I X'="" S DXRQP=X Q
I PTAPH'="" D
. I XRF(HL7NID,%O,"PHY") S X=$G(^NETXRF(HL7NID,"PHY",%O,"F",PTAPH)) I X'="" S PTAPH=X Q
. I XRF(HL7NID,"*","PHY") S X=$G(^NETXRF(HL7NID,"PHY","*","F",PTAPH)) I X'="" S PTAPH=X Q
PV1RECE I %WHO'="" S %WHOP="PV1^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
DG1REC ;DG1 record
I DGN'="" S ^UT($J,"DGN",DG1SQ)=DGN
I DGNTXT'="" S ^UT($J,"DGNTXT")=DGNTXT
DG1RECE I %WHO'="" S %WHOP="DG1^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
;Kill all variables related to this HL7 record due to multiple records being loaded into the utility global
K DG1SQ,DGN,DGNTXT
Q
;
GT1REC ;GT1 record
I GT1SQ=0 D G GT1RECE
.S
RPAD=GUAD,RPNAM=GUNAM,RPAD(1)=$G(GUAD(1)),RPAD(2)=$G(GUAD(2)),RPAD(3)=$G(GUAD(3)),
RPAD(4)=$G(GUAD(4)),RPPHNW=GUPHNW,RPPH
NH=GUPHNH,PTREL=GUREL,RPSSN=GUSSN
.S
EMPAD=GUEAD,EMPNAM=GUENAM,EMPAD(1)=$G(GUEAD(1)),EMPAD(2)=$G(GUEAD(2)),EMPAD(3)=
$G(GUEAD(3)),EMPAD(4)=$G(GUEAD(4))
S
^UT($J,"D1E",GT1SQ)=GUENAM_"^"_$G(GUEAD(1))_"^"_$G(GUEAD(2))_"^"_$G(GUEAD(3))_"^"_$G(GU
EAD(4))_"^"_GUED
S
^UT($J,"D1I",GT1SQ)=GUNAM_"^"_$G(GUAD(1))_"^"_$G(GUAD(2))_"^"_$G(GUAD(3))_"^"_$G(GUAD(4))
_"^"_GUPHNW_"^"_GUPHNH_"^"_GUREL_
"^"_GUDOB_"^"_GUSEX_"^"_GUED
GT1RECE I %WHO'="" S %WHOP="GT1^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
;Kill all variables related to this HL7 record due to multiple records being loaded into the utility global
K
GT1SQ,GUNAM,GUAD,GUPHNH,GUPHNW,GUDOB,GUSEX,GUREL,GUSSN,GUED,GUENAM,GUEAD
Q
;
IN1REC ;IN1 record
I CT'="" D S CT1=$P(CT,"/") I '$D(^OI(%O,CT1,0)) S X=$G(^LOC(%O,"CM",CT1)) I X'="" S
$P(CT,"/")=X
. I XRF(HL7NID,%O,"CT") S X=$G(^NETXRF(HL7NID,"CT",%O,"F",CT)) I X'="" S CT=X Q
. I XRF(HL7NID,"*","CT") S X=$G(^NETXRF(HL7NID,"CT","*","F",CT)) I X'="" S CT=X Q
. I CT["/" S CT1=$P(CT,"/") D
. . I XRF(HL7NID,%O,"CT") S X=$G(^NETXRF(HL7NID,"CT",%O,"F",CT1)) I X'="" S $P(CT,"/")=X Q
. . I XRF(HL7NID,"*","CT") S X=$G(^NETXRF(HL7NID,"CT","*","F",CT1)) I X'="" S $P(CT,"/")=X Q
I INCCD'="" D
. I XRF(HL7NID,%O,"INSCO") S X=$G(^NETXRF(HL7NID,"INSCO",%O,"F",INCCD)) I X'="" S
INCCD=X Q
. I XRF(HL7NID,"*","INSCO") S X=$G(^NETXRF(HL7NID,"INSCO","*","F",INCCD)) I X'="" S INCCD=X
Q
I IN1SQ=0 S IN1SQ=IN1SQ_CT
I CT?1"MC".E S ^UT($J,"CT",IN1SQ)=CT_"^"_POLICY_"^"_$G(MCASN) G IN1RECE
I CT?1"MD".E S ^UT($J,"CT",IN1SQ)=CT_"^"_POLICY_"^"_GROUP G IN1RECE
I CT?1"BS".E S ^UT($J,"CT",IN1SQ)=CT_"^"_INSNAM_"^"_POLICY_"^"_GROUP_"^"_BSCOV G
IN1RECE
I CT?1"PI".E D G IN1RECE
.D
. . I INCNAM_$G(INCAD(1))_$G(INCAD(2))_$G(INCAD(3))'="" S INCCD="" Q
. . I INCCD'="" D I INCCD'="" Q
. . . S X=$P(INCCD,"#",2) I X'="" S INCCD=X
. . . S X=$G(^INSCO(INCCD)) I X="" S INCCD="" Q
. . . F Z="INCNAM;1","INCAD(1);2","INCAD(2);3","INCAD(3);4" S
V=$P(Z,";"),P=$P(Z,";",2),@V=$P(X,"^",P)
. . S X=$G(^OI(%O,CT,0)) I X="" Q
. . F Z="INCNAM;2","INCAD(1);3","INCAD(2);4","INCAD(3);5" S
V=$P(Z,";"),P=$P(Z,";",2),@V=$P(X,"^",P)
.S
^UT($J,"CT",IN1SQ)=CT_"^"_INCNAM_"^"_POLICY_"^"_GROUP_"^^"_$G(INCAD(1))_"^"_$G(INCAD(2))_"
^"_$G(INCAD(3))_"^^"_INCCD_"^"
_INSNAM
S ^UT($J,"CT",IN1SQ)=CT
IN1RECE I %WHO'="" S %WHOP="IN1^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
;Kill all variables related to this HL7 record due to multiple records being loaded into the utility global
K IN1SQ,CT,POLICY,GROUP,INCCD,INCNAM,INCAD,INSNAM
Q
;
FT1REC ;FT1 record
S $ZT="^%Z801001" N X,Z,V,P,DATA,OSRV,DWT,DWTQY
I WTOUC'="" D
. I XRF(HL7NID,%O,"OUC") S X=$G(^NETXRF(HL7NID,"OUC",%O,"F",WTOUC)) I X'="" S WTOUC=X
Q
. I XRF(HL7NID,"*","OUC") S X=$G(^NETXRF(HL7NID,"OUC","*","F",WTOUC)) I X'="" S WTOUC=X Q
I WTCUC'="" D
. I XRF(HL7NID,%O,"OUC") S X=$G(^NETXRF(HL7NID,"OUC",%O,"F",WTCUC)) I X'="" S WTCUC=X
Q
. I XRF(HL7NID,"*","OUC") S X=$G(^NETXRF(HL7NID,"OUC","*","F",WTCUC)) I X'="" S WTCUC=X Q
I WTRLB'="" D
. I XRF(HL7NID,%O,"REFL") S X=$G(^NETXRF(HL7NID,"REFL",%O,"F",WTRLB)) I X'="" S
WTRLB=X Q
. I XRF(HL7NID,"*","REFL") S X=$G(^NETXRF(HL7NID,"REFL","*","F",WTRLB)) I X'="" S WTRLB=X Q
I WTTLO'="" D
. I XRF(HL7NID,%O,"TLOC") S X=$G(^NETXRF(HL7NID,"TLOC",%O,"F",WTTLO)) I X'="" S
WTTLO=X Q
. I XRF(HL7NID,"*","TLOC") S X=$G(^NETXRF(HL7NID,"TLOC","*","F",WTTLO)) I X'="" S WTTLO=X
Q
I WTOLO'="" D
. I XRF(HL7NID,%O,"OLOC") S X=$G(^NETXRF(HL7NID,"OLOC",%O,"F",WTOLO)) I X'="" S
WTOLO=X Q
. I XRF(HL7NID,"*","OLOC") S X=$G(^NETXRF(HL7NID,"OLOC","*","F",WTOLO)) I X'="" S WTOLO=X
Q
I WTRND'="" D
. I XRF(HL7NID,%O,"PHY") S X=$G(^NETXRF(HL7NID,"PHY",%O,"F",WTRND)) I X'="" S WTRND=X
Q
. I XRF(HL7NID,"*","PHY") S X=$G(^NETXRF(HL7NID,"PHY","*","F",WTRND)) I X'="" S WTRND=X Q
I $P(OI0,"^",39)=1,WTRND'="" S DXRND=WTRND
I '%MDOS D
. S OSRV=$O(^LOC(%O,"A",PT,0)) I OSRV'="",OSRV'=SRV S SRV=OSRV Q
. S OSRV=$O(^UT($J,"OUC",%O,"")) I OSRV'="",OSRV'=SRV S SRV=OSRV Q
;--------------------------------------------------------------------------------
;This is for multisite derivatives
;--------------------------------------------------------------------------------
I WTOUC[".",'$D(^OUC(%O,WTOUC)) S WTOUC=$P(WTOUC,".")
I WTCUC[".",'$D(^OUC(%O,WTCUC)) S WTCUC=$P(WTCUC,".")
;--------------------------------------------------------------------------------
I WTOUC'="",'$D(^OUC(%O,WTOUC)),$D(^OUCLOC(%O,"M",WTOUC)) S WTOUC=^(WTOUC)
I WTCUC'="",'$D(^OUC(%O,WTCUC)),$D(^OUCLOC(%O,"M",WTCUC)) S WTCUC=^(WTCUC)
D
. I WTCQTY="" S WTCQTY=WTQTY
. I WTCUC="" S DWT=$G(^UT($J,"OUC",%O,SRV,WTOUC)),DWTQY=WTQTY Q
. S DWT=$G(^UT($J,"OUC",%O,SRV,WTOUC,WTCUC)),DWTQY=WTCQTY
I TTYPE="U" S DWTQY=0
S WTTNP="" I TTYPE="T" S WTTNP=1,DWTQY=0
I DWTQY="" S DWTQY=1
I DWTQY S $P(DWT,"^")=$P(DWT,"^")+$S(TTYPE="C":-DWTQY,1:DWTQY)
F
Z="WTPRC;2","WTDSC;3","WTDGN;4","WTPCD;5","WTRSL;6","WTRLB;7","WTRPR;8","WTABN;9","WTR
ND;10","WTSTA;11","WTSOS;12","WTCDT;
13","WTCTM;14","WTTLO;15","WTTNP;17","WTBNOT;22","WTOLO;23" D
. S V=$P(Z,";"),P=$P(Z,";",2),DATA=$G(@V) I DATA="" Q
. I $P(DWT,"^",P)'="" Q
. I ",WTRND,"[(","_V_",") S (DATA,@V)=$$PHYCNV^AROEN2(DATA)
. I ",WTBNOT,"[(","_V_",") S DATA=$S(DATA="Y":1,DATA="N":0,1:"")
. I DATA'="" S $P(DWT,"^",P)=DATA
D
. I WTCUC="" S ^UT($J,"OUC",%O,SRV,WTOUC)=DWT Q
. S ^UT($J,"OUC",%O,SRV,WTOUC,WTCUC)=DWT
FT1RECE I %WHO'="" S %WHOP="FT1^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
;Kill all variables related to this HL7 record due to multiple records being loaded into the utility global
K
TTYPE,WTOUC,WTCUC,WTQTY,WTCQTY,WTTNP,WTDSC,WTPRC,WTRLB,WTRPR,WTTLO,WTOLO,
WTDGN,WTBNOT,WTRND,WTCDT,WTPCD
K WTRSL,WTABN,WTSTA,WTSOS,WTCTM
Q
;
BLGREC ;BLG record
BLGRECE I %WHO'="" S %WHOP="BLG^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
NTEREC ;NTE record
NTERECE I %WHO'="" S %WHOP="NTE^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
ACCREC ;ACC record
ACCRECE I %WHO'="" S %WHOP="ACC^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
BTSREC ;BTS record
D S %WHO=$P($G(^OI(%O)),"^",17)
. I BHSCO'="" S X=$G(^NETXRF(HL7NID,"CO","*","F",BHSCO)) S:X'="" BHSCO=X I
'$D(^OI(BHSCO)) S BHSCO=""
. I BHSCO'="" S %O=BHSCO Q
. I FHSCO'="" S %O=FHSCO Q
. S %O=DFLTCO ;default company
BTSRECE I %WHO'="" S %WHOP="BTS^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
FTSREC ;FTS record
D S %WHO=$P($G(^OI(%O)),"^",17)
. I FHSCO'="" S X=$G(^NETXRF(HL7NID,"CO","*","F",FHSCO)) S:X'="" FHSCO=X I '$D(^OI(FHSCO))
S FHSCO=""
. I FHSCO'="" S %O=FHSCO Q
. S %O=DFLTCO ;default company
FTSRECE I %WHO'="" S %WHOP="FTS^"_%WHO_"OEN" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
Q
;
FILE ;
S $ZT="^%Z801001" N I,X,SV,LVL,SQ,D3LOG,DXLOG,PRIMCO,SETCO
I '$D(^UT($J,"REC")) G FILEQ
I $G(PT)="" K MSG S MSG(1)="Accession Number required - no information filed" D EVNERR(.MSG)
G FILEQ
I $D(^LOC(%O,"C",PT)) K MSG S MSG(1)="Accession ("_PT_") duplicates an existing client account"
D EVNERR(.MSG) G FILEQ
S DXPERM=$G(DXPERM) I PT'=DXPERM,$D(^[PDU,PDV]PDX("PERM",PT)) K MSG S
MSG(1)="Accession ("_PT_") duplicates an existing perm
anent account" D EVNERR(.MSG) G FILEQ
I %WHO'="" S %WHOP="FILE^"_%WHO_"OEN1" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
;--------------------------------------------------------------------------------
; Determine whether to explode profile into components based on file definition
;--------------------------------------------------------------------------------
I $D(^UT($J,"OUC",%O)) D
. S SV="" F S SV=$O(^UT($J,"OUC",%O,SV)) Q:SV="" D
. . S OUC="" F S OUC=$O(^UT($J,"OUC",%O,SV,OUC)) Q:OUC="" S DWT=$G(^(OUC)) D
. . . S X=$G(^OUC(%O,OUC)) I X="" Q ;ordering unit code not defined
. . . S CMPRCVD=$O(^UT($J,"OUC",%O,SV,OUC,""))'="" ;determine if components received
. . . I $P(X,"^",11)=2,CMPRCVD,DWT="" K ^UT($J,"OUC",%O,SV,OUC) Q ;profile defined to ignore
components
. . . I DWT="" Q
. . . I $P(X,"^",10)'="P" S:'CMPRCVD ^UT($J,"OUC",%O,SV,OUC,OUC)=DWT Q ;not a profile code
. . . I '$P(X,"^",11) Q ;profile defined to receive components
. . . I $P(X,"^",11)=2,CMPRCVD K ^UT($J,"OUC",%O,SV,OUC) S ^(OUC)=DWT,CMPRCVD=0 ;profile
defined to ignore components
. . . I CMPRCVD Q ;components received during networking
. . . S ED=$O(^OUC(%O,OUC,4,99998-SV)) I ED="" Q ;components do not exist for date of service
. . . S CUC="" F S CUC=$O(^OUC(%O,OUC,4,ED,CUC)) Q:CUC="" S ^UT($J,"OUC",
%O,SV,OUC,CUC)=DWT
;--------------------------------------------------------------------------------
K SETCO S PRIMCO=%O,SETCO(PRIMCO)=PT
I %WHO'="" S %WHOP="START^"_%WHO_"OEN1" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
S PDURN="" I DXPERM'="" S PDURN=$G(^[PDU,PDV]PDX("PERM",DXPERM))
I HL7PEVN="P01",DXPERM'="",GPRBLD'="N"!(GPRUPD'="N") D
. I HL7PTHIS,DXPERM=PT S SQ=$G(^HL7PTHIS("*",DXPERM,DXPERM))
+1,^(DXPERM)=SQ,^(DXPERM,SQ)=INPFILE_"^"_$H
. D PD^AROEN4
I DXPERM=PT G FILEQ
;--------------------------------------------------------------------------------
LOOP ; Loop through all companies for which accession is to be set
;--------------------------------------------------------------------------------
S %O=$O(SETCO("")) G FILEQ:%O="" S PT=SETCO(%O)
I '$D(^UT($J,"OUC",%O)),$D(^(PRIMCO)) M ^UT($J,"OUC",%O)=^UT($J,"OUC",PRIMCO)
S PDLINK=0 I GPRLNK="Y",PDURN'="" S PDLINK=1
I %WHO'="" S %WHOP="LOOP^"_%WHO_"OEN1" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP) D
@%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
L +^AR(%O,PT)
I HL7PTHIS S SQ=$G(^HL7PTHIS(%O,PT,PT))+1,^(PT)=SQ,^(PT,SQ)=INPFILE_"^"_$H
F I=1:1:$L(FAN,",") S XFAN=$P(FAN,",",I) I XFAN'="" S
^LOC(%O,"FAN","*"_XFAN,PT)="",^LOC(%O,"FANX",PT,XFAN)=""
S D3LOG=$P($G(^AR(%O,PT,3,PT)),"^",9)'=""
I 'D3LOG D DEMO^AROEN3
I 'D3LOG F LVL="D0","D0E","D1E","D1I","D3" D @(LVL_"^AROEN2")
S (DXCTS,SQ)="" F S SQ=$O(^UT($J,"CT",SQ)) Q:SQ="" S CTDATA=^(SQ) D
. S CT=$P(CTDATA,"^"),CTDATA=$P(CTDATA,"^",2,999),CT1=$P(CT,"/")
. I SQ,(","_DXCTS_",")'[(","_CT1_","),(","_DXCTS_",")'[(","_CT1_"/,") S
DXCTS=DXCTS_$S(DXCTS'="":",",1:"")_CT
. I 'D3LOG S CT2=$E(CT1,1,2) I ",BS,MC,MD,PI,"[(","_CT2_",") D @(CT2_"^AROEN2(CT1)")
D
. I '$D(^UT($J,"OUC",%O)) D Q
. . I $O(^LOC(%O,"A",PT,""))="" S SRV=0 D DXFILE Q
. . S SV="" F S SV=$O(^LOC(%O,"A",PT,SV)) Q:SV="" S SRV=SV D DXFILE
. I '%MDOS D
. . S SRV=$O(^LOC(%O,"A",PT,0)) I SRV="" S SRV=$O(^UT($J,"OUC",%O,""))
. . S SV="" F S SV=$O(^UT($J,"OUC",%O,SV)) Q:SV="" I SV'=SRV M ^UT($J,"OUC",
%O,SRV)=^UT($J,"OUC",%O,SV) K ^UT($J,"OUC",%O,
SV)
. S SV="" F S SV=$O(^UT($J,"OUC",%O,SV)) Q:SV="" S SRV=SV D DXFILE
S SV=0 F S SV=$O(^LOC(%O,"A",PT,SV)) Q:SV="" S XBT=^(SV) D
. I $G(DXRPD)'="",$P(^AR(%O,XBT,3,PT,SV),"^",6)="" S $P(^(SV),"^",6)=DXRPD
. I $D(^VAL(%O,2,0,PT,SV)),'$D(^VAL(%O,1,0,PT,SV)),'$D(^VAL(%O,0,0,PT,SV)) S
^VAL(%O,1,0,PT,SV)=$H_"^"_SSID
;--------------------------------------------------------------------------------
; Kill "0" dos if real dos is on file
;--------------------------------------------------------------------------------
I $D(^AR(%O,PT,3,PT,0))#2,$O(^AR(%O,PT,3,PT,0))'="" D
. K ^UT($J,"NOTES") S %H=0 F S %H=$O(^AR(%O,PT,3,PT,0,%H)) Q:%H="" I $D(^(%H))#2 M
^UT($J,"NOTES",%H)=^AR(%O,PT,3,PT,0,%H)
. K ^AR(%O,PT,3,PT,0),^LOC(%O,"A",PT,0) F I=0,1,2 K ^VAL(%O,I,0,PT,0)
. M ^AR(%O,PT,3,PT,0)=^UT($J,"NOTES") K ^UT($J,"NOTES")
. S XCT="" F S XCT=$O(^AR(%O,PT,8,XCT)) Q:XCT="" I $D(^(XCT,99999)) S DIN=^(99999) D
. . S XCT2=$E(XCT,1,2),XID=$P(DIN,"^",$S(XCT2="BS"!(XCT2="PI"):2,1:1))
. . I XID'="" K ^LOC(%O,XCT2,XID,PT,99999)
. . K ^AR(%O,PT,8,XCT,99999)
;--------------------------------------------------------------------------------
LOOPQ I %WHO'="" S %WHOP="END^"_%WHO_"OEN1" D:'$D(%WHO(%WHOP)) I %WHO(%WHOP)
D @%WHOP
. S %WHO(%WHOP)=0 I $$WHO^%ZIO2(%WHOP) S %WHO(%WHOP)=1
L -^AR(%O,PT) K SETCO(%O)
I DXPERM'=PT G LOOP
FILEQ ;
S $P(^AROEN(FNM),"^",2)=HL7SQ-1
;Kill all variables not specifically referenced in HL7 record specifications
K PT,FAN,SRV
K D0,OD0,D0E,OD0E,D1E,OD1E,D1I,OD1I,D3,OD3,DX,ODX
K
RPNAM,RPAD,RPPHNW,RPPHNH,RPSSN,EMPNAM,EMPAD,DXCTS,DXCDT,DXRND,DXAGE,PTRQN,P
TMRN,PTREL,MCASN
K PDURN,PDLINK
Q
DXFILE ;
S DXLOG=$P($G(^AR(%O,PT,3,PT,SRV)),"^",10)'=""
I DXLOG D DWT^AROEN2 Q
D DX^AROEN2,DWT^AROEN2,SRV^AROEN3,INS^AROEN3
Q
EVNERR(XMSG) ;Event Error Message
;Write message to the Acknowledgment File for an ENTIRE event being skipped
; XMSG() - An array of message lines to be written
;
S $ZT="^%Z801001" N XBEG,XEND,XSQ,X
S XBEG=$O(^UT($J,"REC","")),XEND=$O(^UT($J,"REC",""),-1)
S X="*** ERROR *** Event: "_HL7PEVN_", Records:
"_$S(XBEG'=XEND:XBEG_"-"_XEND,1:XBEG)_" skipped"
S ACKHIT=1 U ACKFILE W X,! I MONITOR'="" U MONITOR W X,!
S XSQ="" F S XSQ=$O(XMSG(XSQ)) Q:XSQ="" S X=" "_XMSG(XSQ) U ACKFILE W X,! I
MONITOR'="" U MONITOR W X,!
Q
ACKMSG(XMSG) ;Acknowledgment Message
;Write single line message to the Acknowledgment File
; XMSG - A single line message to be written
;
S ACKHIT=1 U ACKFILE W XMSG,! I MONITOR'="" U MONITOR W XMSG,!
Q