HLOPBLD1 ;ALB/CJM-HL7 - Building segments (CONTINUED) ;02/04/2004
;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
;
BUILDHDR(HLMSTATE,TYPE,HDR) ;Builds the header segment in 2 lines, line 1 is components 1-6
;Input:
; HLMSTATE("HDR") - (pass by reference, required) These subscripts are used:
; "FIELD SEPARATOR"
; "ENCODING CHARACTERS"
; "SENDING APPLICATION"
; "RECEIVING APPLICATION"
; "RECEIVING FACILITY",1 and ,2 and ,3
; "DT/TM OF MESSAGE"
; "SECURITY"
; "ACCEPT ACK TYPE"
; "APP ACK TYPE"
; "PROCESSING ID"
;
; *MSH ONLY*
; "CONTINUATION POINTER"
; "COUNTRY"
; "EVENT"
; "MESSAGE STRUCTURE"
; "MESSAGE TYPE"
; "PROCESSING MODE"
; "VERSION"
;
; *BHS ONLY*
; "REFERENCE BATCH CONTROL ID"
;
; HLMSTATE("BATCH")
; HLMSTATE("BATCH","CURRENT MESSAGE") - batch messages only
; HLMSTATE("IEN") - ien, file 778
;
; TYPE - must be either "MSH" or "BHS"
;
;Output:
; HLMSTATE("HDR") - these subscripts will be added, unless building an MSH within a batch:
; "SENDING FACILITY",1 and ,2 and ,3
; "PROCESSING ID"
; "MESSAGE CONTROL ID" (MSH ONLY)
; "BATCH CONTROL ID" (BHS ONLY)
; "DT/TM OF MESSAGE"
; HDR (pass by reference) This will return the segment in an array form at HDR(1),HDR(2) (two lines).
;
K HDR
N SEG,BATCH,LEN,FS,CS
;
;shortcuts
S HDR="HLMSTATE(""HDR"")"
S BATCH=HLMSTATE("BATCH")
S FS=@HDR@("FIELD SEPARATOR")
S CS=$E(@HDR@("ENCODING CHARACTERS"),1)
;
S HDR(1)=TYPE_FS_@HDR@("ENCODING CHARACTERS")_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,$G(@HDR@("SENDING APPLICATION")))
;
;If building an MSH segment for a batch message, these parameters should already be determined
D:(('HLMSTATE("BATCH"))!(TYPE="BHS"))
.N PORT
.S PORT=$$RTRNPORT^HLOAPP($G(@HDR@("SENDING APPLICATION")))
.S:'PORT PORT=HLMSTATE("SYSTEM","PORT")
.S @HDR@("SENDING FACILITY",1)=HLMSTATE("SYSTEM","STATION")
.S @HDR@("SENDING FACILITY",2)=HLMSTATE("SYSTEM","DOMAIN")_":"_PORT
.S @HDR@("SENDING FACILITY",3)="DNS"
.;
.;create the unique message ids, using the ien from file 778
.S:TYPE="BHS" @HDR@("BATCH CONTROL ID")=HLMSTATE("SYSTEM","STATION")_" "_HLMSTATE("IEN")
.S:TYPE="MSH" @HDR@("MESSAGE CONTROL ID")=HLMSTATE("SYSTEM","STATION")_" "_HLMSTATE("IEN")
.;
.S @HDR@("PROCESSING ID")=HLMSTATE("SYSTEM","PROCESSING ID")
.S @HDR@("DT/TM OF MESSAGE")=$$HLDATE^HLFNC($$NOW^XLFDT,"TS")
;
S HDR(1)=HDR(1)_FS_$G(@HDR@("SENDING FACILITY",1))_CS_$$ESCAPE^HLOPBLD(.HLMSTATE,$G(@HDR@("SENDING FACILITY",2)))_CS_"DNS"
S HDR(1)=HDR(1)_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("RECEIVING APPLICATION"))_FS_$G(@HDR@("RECEIVING FACILITY",1))_CS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("RECEIVING FACILITY",2))_CS_@HDR@("RECEIVING FACILITY",3)
S HDR(2)=FS_@HDR@("DT/TM OF MESSAGE")_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,$G(@HDR@("SECURITY")))
;
I TYPE="MSH" D
.N ID
.S HDR(2)=HDR(2)_FS_@HDR@("MESSAGE TYPE")_CS_@HDR@("EVENT")_CS_$G(@HDR@("MESSAGE STRUCTURE"))
.S:BATCH ID=@HDR@("BATCH CONTROL ID")_$$ESCAPE^HLOPBLD(.HLMSTATE,"-")_$G(HLMSTATE("BATCH","CURRENT MESSAGE"))
.S:'BATCH ID=@HDR@("MESSAGE CONTROL ID")
.S HDR(2)=HDR(2)_FS_ID_FS_@HDR@("PROCESSING ID")_CS_$G(@HDR@("PROCESSING MODE"))_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("VERSION"))
.S HDR(2)=HDR(2)_FS_FS_$G(@HDR@("CONTINUATION POINTER"))_FS_@HDR@("ACCEPT ACK TYPE")_FS_@HDR@("APP ACK TYPE")_FS_$G(@HDR@("COUNTRY"))
;
I TYPE="BHS" D
.N TEXT
.S TEXT="PROCESSING ID"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("PROCESSING ID")_" "
.I $L($G(@HDR@("ACCEPT ACK TYPE"))) S TEXT=TEXT_"ACCEPT ACK TYPE"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("ACCEPT ACK TYPE")_" "
.I $L($G(@HDR@("APP ACK TYPE"))) S TEXT=TEXT_"APP ACK TYPE"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("APP ACK TYPE")_" "
.S HDR(2)=HDR(2)_FS_TEXT_FS_FS_@HDR@("BATCH CONTROL ID")_FS_$G(@HDR@("REFERENCE BATCH CONTROL ID"))
Q
HLOPBLD1 ;ALB/CJM-HL7 - Building segments (CONTINUED) ;02/04/2004
+1 ;;1.6;HEALTH LEVEL SEVEN;**126**;Oct 13, 1995
+2 ;
BUILDHDR(HLMSTATE,TYPE,HDR) ;Builds the header segment in 2 lines, line 1 is components 1-6
+1 ;Input:
+2 ; HLMSTATE("HDR") - (pass by reference, required) These subscripts are used:
+3 ; "FIELD SEPARATOR"
+4 ; "ENCODING CHARACTERS"
+5 ; "SENDING APPLICATION"
+6 ; "RECEIVING APPLICATION"
+7 ; "RECEIVING FACILITY",1 and ,2 and ,3
+8 ; "DT/TM OF MESSAGE"
+9 ; "SECURITY"
+10 ; "ACCEPT ACK TYPE"
+11 ; "APP ACK TYPE"
+12 ; "PROCESSING ID"
+13 ;
+14 ; *MSH ONLY*
+15 ; "CONTINUATION POINTER"
+16 ; "COUNTRY"
+17 ; "EVENT"
+18 ; "MESSAGE STRUCTURE"
+19 ; "MESSAGE TYPE"
+20 ; "PROCESSING MODE"
+21 ; "VERSION"
+22 ;
+23 ; *BHS ONLY*
+24 ; "REFERENCE BATCH CONTROL ID"
+25 ;
+26 ; HLMSTATE("BATCH")
+27 ; HLMSTATE("BATCH","CURRENT MESSAGE") - batch messages only
+28 ; HLMSTATE("IEN") - ien, file 778
+29 ;
+30 ; TYPE - must be either "MSH" or "BHS"
+31 ;
+32 ;Output:
+33 ; HLMSTATE("HDR") - these subscripts will be added, unless building an MSH within a batch:
+34 ; "SENDING FACILITY",1 and ,2 and ,3
+35 ; "PROCESSING ID"
+36 ; "MESSAGE CONTROL ID" (MSH ONLY)
+37 ; "BATCH CONTROL ID" (BHS ONLY)
+38 ; "DT/TM OF MESSAGE"
+39 ; HDR (pass by reference) This will return the segment in an array form at HDR(1),HDR(2) (two lines).
+40 ;
+41 KILL HDR
+42 NEW SEG,BATCH,LEN,FS,CS
+43 ;
+44 ;shortcuts
+45 SET HDR="HLMSTATE(""HDR"")"
+46 SET BATCH=HLMSTATE("BATCH")
+47 SET FS=@HDR@("FIELD SEPARATOR")
+48 SET CS=$EXTRACT(@HDR@("ENCODING CHARACTERS"),1)
+49 ;
+50 SET HDR(1)=TYPE_FS_@HDR@("ENCODING CHARACTERS")_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,$GET(@HDR@("SENDING APPLICATION")))
+51 ;
+52 ;If building an MSH segment for a batch message, these parameters should already be determined
+53 IF (('HLMSTATE("BATCH"))!(TYPE="BHS"))
Begin DoDot:1
+54 NEW PORT
+55 SET PORT=$$RTRNPORT^HLOAPP($GET(@HDR@("SENDING APPLICATION")))
+56 IF 'PORT
SET PORT=HLMSTATE("SYSTEM","PORT")
+57 SET @HDR@("SENDING FACILITY",1)=HLMSTATE("SYSTEM","STATION")
+58 SET @HDR@("SENDING FACILITY",2)=HLMSTATE("SYSTEM","DOMAIN")_":"_PORT
+59 SET @HDR@("SENDING FACILITY",3)="DNS"
+60 ;
+61 ;create the unique message ids, using the ien from file 778
+62 IF TYPE="BHS"
SET @HDR@("BATCH CONTROL ID")=HLMSTATE("SYSTEM","STATION")_" "_HLMSTATE("IEN")
+63 IF TYPE="MSH"
SET @HDR@("MESSAGE CONTROL ID")=HLMSTATE("SYSTEM","STATION")_" "_HLMSTATE("IEN")
+64 ;
+65 SET @HDR@("PROCESSING ID")=HLMSTATE("SYSTEM","PROCESSING ID")
+66 SET @HDR@("DT/TM OF MESSAGE")=$$HLDATE^HLFNC($$NOW^XLFDT,"TS")
End DoDot:1
+67 ;
+68 SET HDR(1)=HDR(1)_FS_$GET(@HDR@("SENDING FACILITY",1))_CS_$$ESCAPE^HLOPBLD(.HLMSTATE,$GET(@HDR@("SENDING FACILITY",2)))_CS_"DNS"
+69 SET HDR(1)=HDR(1)_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("RECEIVING APPLICATION"))_FS_$GET(@HDR@("RECEIVING FACILITY",1))_CS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("RECEIVING FACILITY",2))_CS_@HDR@("RECEIVING FACILITY",3)
+70 SET HDR(2)=FS_@HDR@("DT/TM OF MESSAGE")_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,$GET(@HDR@("SECURITY")))
+71 ;
+72 IF TYPE="MSH"
Begin DoDot:1
+73 NEW ID
+74 SET HDR(2)=HDR(2)_FS_@HDR@("MESSAGE TYPE")_CS_@HDR@("EVENT")_CS_$GET(@HDR@("MESSAGE STRUCTURE"))
+75 IF BATCH
SET ID=@HDR@("BATCH CONTROL ID")_$$ESCAPE^HLOPBLD(.HLMSTATE,"-")_$GET(HLMSTATE("BATCH","CURRENT MESSAGE"))
+76 IF 'BATCH
SET ID=@HDR@("MESSAGE CONTROL ID")
+77 SET HDR(2)=HDR(2)_FS_ID_FS_@HDR@("PROCESSING ID")_CS_$GET(@HDR@("PROCESSING MODE"))_FS_$$ESCAPE^HLOPBLD(.HLMSTATE,@HDR@("VERSION"))
+78 SET HDR(2)=HDR(2)_FS_FS_$GET(@HDR@("CONTINUATION POINTER"))_FS_@HDR@("ACCEPT ACK TYPE")_FS_@HDR@("APP ACK TYPE")_FS_$GET(@HDR@("COUNTRY"))
End DoDot:1
+79 ;
+80 IF TYPE="BHS"
Begin DoDot:1
+81 NEW TEXT
+82 SET TEXT="PROCESSING ID"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("PROCESSING ID")_" "
+83 IF $LENGTH($GET(@HDR@("ACCEPT ACK TYPE")))
SET TEXT=TEXT_"ACCEPT ACK TYPE"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("ACCEPT ACK TYPE")_" "
+84 IF $LENGTH($GET(@HDR@("APP ACK TYPE")))
SET TEXT=TEXT_"APP ACK TYPE"_$$ESCAPE^HLOPBLD(.HLMSTATE,"=")_@HDR@("APP ACK TYPE")_" "
+85 SET HDR(2)=HDR(2)_FS_TEXT_FS_FS_@HDR@("BATCH CONTROL ID")_FS_$GET(@HDR@("REFERENCE BATCH CONTROL ID"))
End DoDot:1
+86 QUIT