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

MDCPHL7B.m

Go to the documentation of this file.
  1. MDCPHL7B ;HINES OIFO/BJ - CliO HL7 Handler/validator;09 Aug 2006
  1. ;;1.0;CLINICAL PROCEDURES;**16**;Apr 01, 2004;Build 280
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. ; This routine uses the following IAs:
  1. ; # 2434 - $$TOPURG^HLUTIL HL7 (supported)
  1. ; #10112 - $$SITE^VASITE() call Registration (supported)
  1. ; #10138 - access ^HL(772 HL7 (supported)
  1. ; # 3273 - access ^HLMA( HL7 (controlled subscription)
  1. ;
  1. ;only call via line tags.
  1. Q
  1. ;
  1. GTMSGIDS(MDCPRSLT,MDCPSTAT) ; Gets message ids
  1. ;
  1. ; Gets a list of message ids from the CLIO_HL7_LOG file (file 704.002)
  1. ; based on status.
  1. ;
  1. ; Parameters -
  1. ; Covert:
  1. ; None
  1. ; Overt:
  1. ; MDCPRSLT - The name of an array that will contain the results.
  1. ; MDCPSTAT - Internal code for status
  1. ; 1 = Entered
  1. ; 2 = Awaiting Processing
  1. ; 3 = Error
  1. ; 4 = Processed
  1. ;
  1. ; Returns -
  1. ; An array of IDs of entries in file 704.002
  1. ;
  1. S MDCPRSLT=$NA(^TMP($J,"MDCPRSLT"))
  1. N I,J S I=1,J=0
  1. F S J=$O(^MDC(704.002,"AS",MDCPSTAT,J)) Q:'J D
  1. .S @MDCPRSLT@(1,I)=J
  1. .S I=I+1
  1. S @MDCPRSLT=I_U
  1. S @MDCPRSLT@(0)="0^"_I
  1. Q
  1. ;
  1. GETMSG(MDCPRSLT,MDCPMSG) ; Gets a message based on ID
  1. ;
  1. ; Gets a message based on ID from the HL7 subsystem.
  1. ; IA
  1. ; 10138 (supported) - Used to reference the incoming message text in 772
  1. ; ?? - SITE^VASITE extrinsic.
  1. ; Parameters -
  1. ; Overt:
  1. ; MDCPRSLT- The name of a global in which the message will be saved.
  1. ; MDCPMSG- The IEN of the HL7 message in 703.1.
  1. ;
  1. ; Returns -
  1. ; Root Node = Message ID (File 772 field 6)^Patient DFN^Facility
  1. ; Node 0 = Message MSH segment
  1. ; Node 1,n = The HL7 Message based on ID.
  1. ;
  1. S MDCPRSLT=$NA(^TMP("MDCPGTWY",$J))
  1. K @MDCPRSLT
  1. N MDCPHL7
  1. N MDCPDFN
  1. S MDCPDFN=$P($G(^MDC(704.002,MDCPMSG,0)),U,6)
  1. ; Need to set ^TMP($J,"MDCPRSLT,0) to the MSH segment for the message.
  1. ; Again, we're going to assume that everything we'll need from the MSH segment will be on the first line.
  1. N MDCPIEN S MDCPIEN=$P($G(^MDC(704.002,MDCPMSG,0)),U,4)
  1. N MDCPIENS S MDCPIENS=$P($G(^MDC(704.002,MDCPMSG,0)),U,5)
  1. S @MDCPRSLT@(-1,1)=$G(MDCPIENS)_U_$G(MDCPDFN)_U_$P($$SITE^VASITE(),U,3)
  1. I +MDCPIEN>0 S @MDCPRSLT@(0,1)=$G(^HLMA(MDCPIEN,"MSH",1,0))
  1. N I,MDCPHLSG S I=0
  1. F S I=$O(^HL(772,MDCPIENS,"IN",I)) Q:'I D
  1. .S MDCPHLSG=$G(^HL(772,MDCPIENS,"IN",I,0))
  1. .I ($G(MDCPHLSG)'=" ")&($L(MDCPHLSG)>1) D
  1. ..S @MDCPRSLT@(1,I)=$G(^HL(772,MDCPIENS,"IN",I,0))
  1. Q
  1. ;
  1. UPDATERP(MDCPRSLT,MDCPMSG,MDCPSTAT,MDCPDFN,MDCPMAP) ; Updates CP RESULT REPORT status
  1. ;
  1. ; Sets the status field of the message identified by
  1. ; MDCPMSG in 704.002 to the status listed in status. Status
  1. ; must be in internal format.
  1. ;
  1. ; Parameters -
  1. ; Covert: none
  1. ; Overt:
  1. ; MDCPMSG - IFN of message in CP RESULT REPORT file
  1. ; MDCPSTAT - Status (in INTERNAL format).
  1. ; MDCPDFN - (Optional) The IFN of the patient in the patient file.
  1. ; MDCPMAP - (Optional) The identifier of the mapping table from CliO.
  1. ;
  1. ; Returns -
  1. ; MDCPRSLT: A variable passed by reference containing the results of the status update.
  1. ;
  1. N MDCPFDA,MDCPPTID,MDCPIFN,MDCPERR,MDCPROC,MDCPEST,MDNOW,MDTMP
  1. S MDCPIENS=$G(MDCPMSG)_","
  1. D NOW^%DTC S MDNOW=%
  1. S MDCPEST=$$EXTERNAL^DILFD(704.002,.02,"",MDCPSTAT)
  1. S MDCPFDA(704.002,MDCPIENS,".02")=MDCPSTAT
  1. S:+$G(MDCPSTAT)="4" MDCPFDA(704.002,MDCPIENS,".09")=MDNOW
  1. ;S:$D(MDCPDFN)#10 MDCPFDA(704.002,MDCPIENS,".06")=MDCPDFN
  1. ;S:$D(MDCPMAP)#10 MDCPFDA(704.002,MDCPIENS,".03")=MDCPMAP
  1. D FILE^DIE("K","MDCPFDA","MDCPERR")
  1. I $D(MDCPERR) D Q
  1. .D UPDRSN(.MDTMP,MDCPMSG,"Unable to change status of entry '"_MDCPMSG_"' to "_$G(MDCPEST))
  1. .S MDCPRSLT(0)="0^"_$G(MDCPERR(1,"TEXT",1),"Fileman didn't return a reason")
  1. ;
  1. ; Status change was successful - Now lets log it and keep going
  1. ;
  1. D UPDRSN(.MDTMP,MDCPMSG,"Status of entry '"_MDCPMSG_"' changed to "_$G(MDCPEST))
  1. S MDCPRSLT(0)="1^Status updated to "_MDCPEST
  1. ;
  1. ; We're going to get rid of the M trigger on the log file and directly notify the Windows service
  1. ; that we've got a message ready. While it was cool, there was too much of a chance of bad things
  1. ; happening if someone went in and edited this file and hit the trigger accidentally.
  1. ;
  1. I MDCPSTAT=2 D Q
  1. .S MDCPVDFN=$P($G(^MDC(704.002,MDCPMSG,0)),U,6)
  1. .S MDCPVMAP=$P($G(^MDC(704.002,MDCPMSG,0)),U,3)
  1. .I (+MDCPVDFN)&(MDCPVMAP]"") D Q
  1. ..D EN^MDCPSIGN(MDCPMSG) ; Message sent to the gateway!
  1. .K MDCPVDFN,MDCPVMAP
  1. .; Set message back to error
  1. .S MDCPFDA(704.002,MDCPIENS,".02")=3
  1. .D FILE^DIE("K","MDCPFDA","MDCPERR")
  1. .D UPDRSN(.MDTMP,MDCPMSG,"Unable to change status of entry to "_$G(MDCPEST)_". Missing instrument or patient.")
  1. .S MDCPRSLT(0)="0^Unable to change status, missing patient or instrument"
  1. ;
  1. I $G(MDCPSTAT)="4" D Q
  1. .S HLMTIENS=$P($G(^MDC(704.002,MDCPMSG,0)),U,4)
  1. .I $$TOPURG^HLUTIL<0 D UPDRSN(.MDTMP,MDCPMSG,"Unable to purge entry "_$G(MDCPMSG))
  1. ;
  1. Q
  1. ;
  1. UPDRSN(MDCPRSLT,MDCPMSG,MDCPTEXT) ; Update CLIO_HL7_LOG file with a reason for a status.
  1. ; Published as MDCP UPDATE MESSAGE REASON
  1. ;
  1. ; Parameters -
  1. ; Covert: none
  1. ; Overt:
  1. ; MDCPMSG - IFN of message in CP RESULT REPORT file
  1. ; MDCPSTAT - The text to set place in .
  1. ;
  1. ; Returns -
  1. ; MDCPRSLT: A global variable $NA() containing the results of the status update.
  1. ;
  1. S MDCPRSLT=$NA(^TMP($J)) K @MDCPRSLT
  1. N MDCPFDA
  1. D NOW^%DTC
  1. S MDCPFDA(704.004,"+1,",.01)=MDCPMSG
  1. S MDCPFDA(704.004,"+1,",.02)=%
  1. S MDCPFDA(704.004,"+1,",.1)=MDCPTEXT
  1. D UPDATE^DIE("","MDCPFDA")
  1. S @MDCPRSLT="1^Message Log Updated"
  1. S @MDCPRSLT@(0)="1^Message Log Updated"
  1. Q
  1. ;
  1. CLRERR ; Quick clear of the HL7 error log
  1. N MDX,MDZ
  1. W !,"Set all HL7 errors to processed" S %=2 D YN^DICN Q:%'=1
  1. F MDX=0:0 S MDX=$O(^MDC(704.002,"AS",3,MDX)) Q:'MDX D UPDATERP(.MDZ,MDX,4) W "."
  1. Q
  1. ;