Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLTPCK2B

HLTPCK2B.m

Go to the documentation of this file.
  1. HLTPCK2B ;OIFO-O/RJH - Message Header Validation (Con't) ;09/13/2006
  1. ;;1.6;HEALTH LEVEL SEVEN;**120,133**;Oct 13, 1995;Build 13
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. ; splitted from HLTPCK2A
  1. ; to be called from HLTPCK2A
  1. ;
  1. MS ;Check for Message Structure Code
  1. I $G(ARY("MTN_ETN"))'="" D
  1. . S ARY("MTP_ETP")=0
  1. . S ARY("MTP_ETP")=+$O(^HL(779.005,"B",ARY("MTN_ETN"),0))
  1. . I ('ARY("MTP_ETP")) S:(ERR="") ERR="Invalid Message Structure Code" Q
  1. ;
  1. ;Get server and client Protocols
  1. MSA ;if ack, then get information and quit, we don't need to respond
  1. I $G(MSA)]"" D Q
  1. . ;Message is an acknowledgement, find original message
  1. . S ARY("MSAID")=$P(MSA,FS,2),ARY("MTIENS")=0
  1. . I ARY("MSAID")="" S:(ERR="") ERR="Invalid Message Control ID in MSA Segment - No Message ID" Q
  1. . F S ARY("MTIENS")=+$O(^HLMA("AH",ARY("SAP"),ARY("MSAID"),ARY("MTIENS"))) Q:'ARY("MTIENS")!($P($G(^HLMA(ARY("MTIENS"),0)),U,3)="O")
  1. . I 'ARY("MTIENS") S:(ERR="") ERR="Invalid Message Control ID in MSA Segment - No message IEN in ""AH"" x-ref" Q
  1. . ;get subscriber protocol and ack. to (show if this is an ack to an ack)
  1. . S X=$G(^HLMA(ARY("MTIENS"),0)),ARY("EIDS")=$P(X,U,8),ARY("ACK")=$P(X,U,10)
  1. . ;if no subscriber protocol then response msg. is invalid
  1. . I ('ARY("EIDS")) S:(ERR="") ERR="Invalid Message Control ID in MSA Segment - No Subscr. IEN in 773" Q
  1. . ;get message text ien in file 772 and server protocol, 'EID'
  1. . S ARY("MTIEN")=+X,X=$G(^HL(772,+X,0)),ARY("EID")=$P(X,U,10)
  1. . I ('ARY("EID")) S:(ERR="") ERR="Event Protocol not found" Q
  1. . D EVENT^HLUTIL1(ARY("EIDS"),"770,773",.HLN)
  1. ;
  1. ;Find Server Protocol - based on sending application, message type,
  1. ;event type and version ID
  1. I ARY("ETP") S ARY("EID")=+$O(^ORD(101,"AHL1",ARY("SAP"),ARY("MTP"),ARY("ETP"),ARY("VEP"),0))
  1. ;
  1. ;Find Server Protocol - based on sending application, message type,
  1. ;and version ID
  1. I 'ARY("ETP") S ARY("EID")=+$O(^ORD(101,"AHL21",ARY("SAP"),ARY("MTP"),ARY("VEP"),0))
  1. ;
  1. I ('ARY("EID")) S:(ERR="") ERR="Event Protocol not found" Q
  1. ;Find Client Protocol - in ITEM multiple of Server Protocol
  1. S ARY("EIDS")=0
  1. F S ARY("EIDS")=+$O(^ORD(101,ARY("EID"),775,"B",ARY("EIDS"))) Q:'ARY("EIDS")!($P($G(^ORD(101,ARY("EIDS"),770)),U,2)=ARY("RAP"))
  1. I 'ARY("EIDS") S ERR="Invalid Receiving Application for this Event" Q
  1. D EVENT^HLUTIL1(ARY("EIDS"),"770,773",.HLN)
  1. ;
  1. LLP ;Get logical link pointer
  1. S ARY("LL")=$P($G(HLN(770)),"^",7)
  1. ;
  1. FAC ;Get sending/rec facility, validate if necessary
  1. ;
  1. S HLCS=$E(ECH,1) ;Get component separator
  1. S ARY("RAF")=$$P^HLTPCK2(.HDR,6) ;Receiving Facility
  1. S ARY("SAF")=$$P^HLTPCK2(.HDR,4) ;Sending Facility
  1. ;Get sending/receiving facility from Application Parameter file(771)
  1. S HL771SF=$P($G(^HL(771,ARY("SAP"),0)),U,3)
  1. S HL771RF=$P($G(^HL(771,ARY("RAP"),0)),U,3)
  1. ;Sending/Receiving facility required?
  1. S X=$G(^ORD(101,ARY("EIDS"),773))
  1. S HLSFREQ=+X,HLRFREQ=+$P(X,U,2)
  1. RF ;Validate Receiving Facility
  1. I HLRFREQ D
  1. .I ARY("RAF")="" S:ERR="" ERR="Missing required receiving facility"
  1. .I HL771RF]"" D Q
  1. ..;Facility data in 771 overrides data in site paramter file
  1. ..Q
  1. .;Check against local default value (site parameters)
  1. .Q:ARY("RAF")=(HLINSTN_HLCS_HLDOM_HLCS_"DNS")
  1. .;
  1. .; patch HL*1.6*120 start
  1. .; I $P(ARY("RAF"),HLCS)=HLINSTN,$P(ARY("RAF"),HLCS,3)="DNS" D Q
  1. . I $P(ARY("RAF"),HLCS,3)="DNS" D Q
  1. .. N ERROR,HLDOMP1,HLDOMP2
  1. .. ; S HLDOMP1=$P(ARY("RAF"),HLCS,2),HLDOMP1=$$FIND1^DIC(4.2,"","BMX",HLDOMP1,"B^C","","ERROR")
  1. .. S HLDOMP1=$P(ARY("RAF"),HLCS,2)
  1. .. ;
  1. .. ; assume the format is <domain>:<port #>
  1. .. I HLDOMP1[":" S ARY("RAF-PORT")=$P(HLDOMP1,":",2)
  1. .. S HLDOMP1=$P(HLDOMP1,":")
  1. .. S ARY("RAF-DOMAIN")=HLDOMP1
  1. .. ;
  1. .. ; if first piece of domain is "HL7." or "MPI.", remove it
  1. .. I ($E(HLDOMP1,1,4)="HL7.")!($E(HLDOMP1,1,4)="MPI.") D
  1. ... S HLDOMP1=$P(HLDOMP1,".",2,99)
  1. .. S HLDOMP1=$$FIND1^DIC(4.2,"","BMX",HLDOMP1,"B^C","","ERROR")
  1. .. S HLDOMP2=HLDOM,HLDOMP2=$$FIND1^DIC(4.2,"","BMX",HLDOMP2,"B^C","","ERROR")
  1. .. I HLDOMP1&HLDOMP2&(HLDOMP1=HLDOMP2) Q
  1. .. ;
  1. .. ; check DNS domain and ip address
  1. .. ;initialize variable, HLDOMP("FLAG")
  1. .. S HLDOMP("FLAG")=0
  1. .. I ARY("RAF-DOMAIN")]"" D
  1. ... ;
  1. ... ; match DNS domain
  1. ... I $D(^HLCS(870,"DNS",ARY("RAF-DOMAIN"))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("RAF-LL")=+$O(^HLCS(870,"DNS",ARY("RAF-DOMAIN"),0))
  1. ... I $D(^HLCS(870,"DNS",$$UP^XLFSTR(ARY("RAF-DOMAIN")))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("RAF-LL")=+$O(^HLCS(870,"DNS",$$UP^XLFSTR(ARY("RAF-DOMAIN")),0))
  1. ... I $D(^HLCS(870,"DNS",$$LOW^XLFSTR(ARY("RAF-DOMAIN")))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("RAF-LL")=+$O(^HLCS(870,"DNS",$$LOW^XLFSTR(ARY("RAF-DOMAIN")),0))
  1. ... ;
  1. ... ; match ip address
  1. ... I $D(^HLCS(870,"IP",ARY("RAF-DOMAIN"))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("RAF-LL")=+$O(^HLCS(870,"IP",ARY("RAF-DOMAIN"),0))
  1. .. Q:HLDOMP("FLAG")=1
  1. .. I $P(ARY("RAF"),HLCS)=HLINSTN Q
  1. .. ;
  1. .. S:ERR="" ERR="Receiving Facility mismatch."
  1. . I $P(ARY("RAF"),HLCS)=HLINSTN Q
  1. . S:ERR="" ERR="Receiving Facility mismatch."
  1. ; patch HL*1.6*120 end
  1. ;
  1. SF ;Validate Sending Facility
  1. I HLSFREQ D
  1. .I ARY("SAF")="" S:ERR="" ERR="Missing required sending facility"
  1. .I HL771SF]"" D Q
  1. ..;Check for facility data in 771
  1. ..Q
  1. .;If default value was sent, validate that DOMAIN RESOLVES TO LOGICAL LINK
  1. .;If so, use this instead of Protocol definition for return path
  1. .;
  1. .; patch HL*1.6*120 start
  1. . N HLDOMP
  1. . ; S HLDOMP=$P(ARY("SAF"),HLCS,2),HLDOMP=$$FIND1^DIC(4.2,"","BMX",HLDOMP,"B^C","","ERROR")
  1. . S HLDOMP=$P(ARY("SAF"),HLCS,2)
  1. . ;
  1. . ; assume the format is <domain>:<port #>
  1. . I HLDOMP[":" S ARY("SAF-PORT")=$P(HLDOMP,":",2)
  1. . S HLDOMP=$P(HLDOMP,":")
  1. . S ARY("SAF-DOMAIN")=HLDOMP
  1. . ;
  1. . ; if first piece of domain is "HL7." or "MPI.", remove it
  1. . I ($E(HLDOMP,1,4)="HL7.")!($E(HLDOMP,1,4)="MPI.") D
  1. .. S HLDOMP=$P(HLDOMP,".",2,99)
  1. . S HLDOMP=$$FIND1^DIC(4.2,"","BMX",HLDOMP,"B^C","","ERROR")
  1. .;Note: This expects a unique domain in domain file. Multiple entries will fail
  1. . ; I 'HLDOMP S:ERR="" ERR="Unrecognized/ambiguous domain in sending facility"
  1. . ;
  1. . ; check DNS domain and ip address
  1. . I 'HLDOMP D
  1. .. ;
  1. .. ;initialize variable, HLDOMP("FLAG")
  1. .. S HLDOMP("FLAG")=0
  1. .. I ARY("SAF-DOMAIN")]"" D
  1. ... ;
  1. ... ; match DNS domain
  1. ... I $D(^HLCS(870,"DNS",ARY("SAF-DOMAIN"))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("SAF-LL")=+$O(^HLCS(870,"DNS",ARY("SAF-DOMAIN"),0))
  1. ... I $D(^HLCS(870,"DNS",$$UP^XLFSTR(ARY("SAF-DOMAIN")))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("SAF-LL")=+$O(^HLCS(870,"DNS",$$UP^XLFSTR(ARY("SAF-DOMAIN")),0))
  1. ... I $D(^HLCS(870,"DNS",$$LOW^XLFSTR(ARY("SAF-DOMAIN")))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("SAF-LL")=+$O(^HLCS(870,"DNS",$$LOW^XLFSTR(ARY("SAF-DOMAIN")),0))
  1. ... ;
  1. ... ; match ip address
  1. ... I $D(^HLCS(870,"IP",ARY("SAF-DOMAIN"))) D Q
  1. .... S HLDOMP("FLAG")=1
  1. .... S ARY("SAF-LL")=+$O(^HLCS(870,"IP",ARY("SAF-DOMAIN"),0))
  1. .. Q:HLDOMP("FLAG")=1
  1. .. ; quit if 1st component defined
  1. .. S ARY("SAF-COMPONENT1")=$P(ARY("SAF"),HLCS,1)
  1. .. Q:ARY("SAF-COMPONENT1")]""
  1. .. S:ERR="" ERR="Receiving Facility mismatch."
  1. . ; patch HL*1.6*120 end
  1. . ;
  1. .Q:HLDOMP=$P(HLPARAM,U) ;This is local app to app
  1. .I HLDOMP N HLNK S HLNK=+$O(^HLCS(870,"D",HLDOMP,0))
  1. .I $G(HLNK) S ARY("LL")=HLNK
  1. ;
  1. PID ;Validate processing ID
  1. I ("DTP"'[ARY("PID")) S:(ERR="") ERR="Invalid HL7 Processing ID"
  1. S HLPID=$P(HLPARAM,U,3) ;site param
  1. S X=$G(^ORD(101,ARY("EID"),770)),X=$P(X,U,6) ;event driver
  1. ;If message is 'debug' then event driver must be 'debug.'
  1. ;If message is 'test' or 'production', then site param must match
  1. I ARY("PID")="D"&(X'="D") S:ERR="" ERR="Processing ID Mismatch with Event Driver"
  1. I ARY("PID")'="D"&(HLPID'=ARY("PID")) S:ERR="" ERR="Processing ID Mismatch with Site Parameters"
  1. ;
  1. SEC ;Validate security field - access code and electronic signature
  1. I ($P($G(HLN(773)),"^",3)) D
  1. .S X=$P($$P^HLTPCK2(.HDR,8),$E(ECH))
  1. .S X=$$UPPER^HLFNC(X)
  1. .D ^XUSHSH
  1. .I X="",(MSA="") S:(ERR="") ERR="Invalid access code" Q
  1. .S ARY("DUZ")=0
  1. .S:(X'="") ARY("DUZ")=+$O(^VA(200,"A",X,0))
  1. .I ('ARY("DUZ")) S:(ERR="") ERR="Invalid access code" Q
  1. .I (($P($G(^VA(200,ARY("DUZ"),.1)),"^")="")&('$D(MSA))) S ARY("DUZ")=0 S:(ERR="") ERR="Invalid access code" Q
  1. .S X=$P($$P^HLTPCK2(.HDR,8),$E(ECH),3) I (X'="") D
  1. ..S X1=$G(^VA(200,ARY("DUZ"),20))
  1. ..I (X1="") S:(ERR="") ERR="No Signature Code on File" Q
  1. ..S X=$$UPPER^HLFNC(X)
  1. ..D HASH^XUSHSHP
  1. ..I ((X'=$P(X1,"^",4))!($P(X1,"^",2)="")) S:(ERR="") ERR="Invalid Electronic Signature Code" Q
  1. ..S ARY("ESIG")=$P(X1,"^",2)
  1. I $D(ARY) M HLREC=ARY
  1. Q