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

DGENUPL1.m

Go to the documentation of this file.
  1. DGENUPL1 ;ALB/CJM,ISA/KWP,CKN,LBD - PROCESS INCOMING (Z11 EVENT TYPE) HL7 MESSAGES ; 6/17/09 10:07am
  1. ;;5.3;PIMS;**147,222,232,314,397,379,407,363,673,653,688,1015,1016**;JUN 30, 2012;Build 20
  1. ;
  1. PARSE(MSGIEN,MSGID,CURLINE,ERRCOUNT,DGPAT,DGELG,DGENR,DGCDIS,DGOEIF,DGSEC,DGNTR,DGMST,DGNMSE) ;
  1. ;
  1. ;Description: This function parses the HL7 segments. It creates arrays
  1. ;defined by the PATIENT, ENROLLMENT, ELIGIBILY, CATASTROPHIC DISABILITY,
  1. ;OEF/OIF CONFLICT objects.
  1. ;Field values are put in DHCP format and the validity at the
  1. ;field level is tested. Fields to be deleted are set to "@".
  1. ;
  1. ;Input:
  1. ; MSGIEN - the ien of the HL7 message in the HL7 MESSAGE TEXT file (772)
  1. ; MSGID -message control id of HL7 msg in the MSH segment
  1. ; CURLINE - the subscript of the PID segment of the current message (pass by reference)
  1. ; ERRCOUNT - is a count of the number of messages in the batch that can not be processed (pass by ref)
  1. ;
  1. ;Output:
  1. ; Function Value: Returns 1 on success, 0 on failure.
  1. ; CURLINE - upon leaving the procedure this parameter should be set to the end of the current message.
  1. ; ERRCOUNT - set to count of messages that were not processed due to errors encountered. (pass by ref)
  1. ; DGPAT - array defined by the PATIENT object. (pass by ref)
  1. ; DGENR - array defined by the PATIENT ENROLLMENT object. (pass by ref)
  1. ; DGELG - array defined by the PATIENT ELIGIBILITY object. (pass by ref)
  1. ; DGCDIS - array defined by the CATASTROPHIC DISABILITY object. (pass by ref)
  1. ; DGSEC - array defined by the PATIENT SECURITY object. (pass by ref)
  1. ; DGOEIF - array defined by the OEF/OIF CONFLICT object. (pass by ref)
  1. ; DGNTR - array defined for NTR data.
  1. ; DGMST - array defined for MST data.
  1. ; DGNMSE - array define for MILITARY SERVICE EPISODE data (pass by ref)
  1. N SEG,ERROR,COUNT,QFLG,NFLG
  1. ;
  1. K DGEN,DGPAT,DGELG,DGCDIS,DGNTR,DGMST
  1. ;
  1. S ERROR=0,NFLG=1
  1. F SEG="PID","ZPD","ZIE","ZIO","ZEL" D Q:ERROR
  1. .D:NFLG NXTSEG^DGENUPL(MSGIEN,.CURLINE,.SEG)
  1. .I SEG="ZIO",SEG("TYPE")'="ZIO" S NFLG=0 Q
  1. .I SEG("TYPE")=SEG D Q
  1. ..D:(SEG'="ZEL") @SEG^DGENUPL2
  1. ..D:(SEG="ZEL") ZEL^DGENUPL2(1)
  1. ..S NFLG=1
  1. .D ADDERROR^DGENUPL(MSGID,$G(DGPAT("SSN")),SEG_" SEGMENT MISSING OR OUT OF ORDER",.ERRCOUNT)
  1. .S ERROR=1
  1. .;
  1. .;possible that in a bad message we are now past the end
  1. .S CURLINE=CURLINE-1
  1. ;
  1. I 'ERROR F COUNT=2:1 D NXTSEG^DGENUPL(MSGIEN,CURLINE,.SEG) Q:(SEG("TYPE")'="ZEL") D Q:ERROR
  1. .S CURLINE=CURLINE+1
  1. .D ZEL^DGENUPL2(COUNT)
  1. ;Phase II Add the capability to accept more than 1 ZCD
  1. I 'ERROR F SEG="ZEN","ZMT","ZCD" D Q:ERROR
  1. .D NXTSEG^DGENUPL(MSGIEN,.CURLINE,.SEG)
  1. .I SEG("TYPE")=SEG D
  1. ..D @SEG^DGENUPL2
  1. .E D
  1. ..D ADDERROR^DGENUPL(MSGID,$G(DGPAT("SSN")),SEG_" SEGMENT MISSING OR OUTOF ORDER",.ERRCOUNT)
  1. ..S ERROR=1
  1. ..;
  1. ..;possible that in a bad message we are now past the end
  1. ..S CURLINE=CURLINE-1
  1. ;
  1. I 'ERROR F COUNT=2:1 D NXTSEG^DGENUPL(MSGIEN,CURLINE,.SEG) Q:(SEG("TYPE")'="ZCD") D Q:ERROR
  1. .S CURLINE=CURLINE+1
  1. .D ZCD^DGENUPL2
  1. ;
  1. ; Purple Heart/OEF-OIF Addition of optional ZMH segment
  1. ; Modified handling of ZSP and ZRD to accomodate ZMH
  1. ;
  1. I 'ERROR D Q:ERROR $S(ERROR:0,1:1)
  1. .D NXTSEG^DGENUPL(MSGIEN,.CURLINE,.SEG)
  1. .I SEG("TYPE")="ZSP" D ZSP^DGENUPL2 Q
  1. .D ADDERROR^DGENUPL(MSGID,$G(DGPAT("SSN")),SEG_" SEGMENT MISSING OR OUT OF ORDER",.ERRCOUNT)
  1. .S ERROR=1
  1. .;possible that in a bad message we are now past the end
  1. .S CURLINE=CURLINE-1
  1. ;
  1. ;Modified following code to receive multiple ZMH segment for
  1. ;Military service information - DG*5.3*653
  1. I 'ERROR D Q:ERROR $S(ERROR:0,1:1)
  1. .D NXTSEG^DGENUPL(MSGIEN,.CURLINE,.SEG)
  1. .S QFLG=0 F D Q:QFLG
  1. . . I SEG("TYPE")'="ZMH" S QFLG=1 Q
  1. . . D ZMH^DGENUPL2,NXTSEG^DGENUPL(MSGIEN,.CURLINE,.SEG)
  1. .I SEG("TYPE")="ZRD" D ZRD^DGENUPL2 Q
  1. .D ADDERROR^DGENUPL(MSGID,$G(DGPAT("SSN")),SEG_" SEGMENT MISSING OR OUT OF ORDER",.ERRCOUNT)
  1. .S ERROR=1
  1. .;possible that in a bad message we are now past the end
  1. .S CURLINE=CURLINE-1
  1. ;
  1. I 'ERROR F COUNT=2:1 D NXTSEG^DGENUPL(MSGIEN,CURLINE,.SEG) Q:(SEG("TYPE")'="ZRD") D Q:ERROR
  1. .S CURLINE=CURLINE+1
  1. .D ZRD^DGENUPL2
  1. ;
  1. I 'ERROR F D Q:(ERROR!(SEG("TYPE")'="OBX"))
  1. .;possible if OBX segment not present that we are now past the end
  1. .I SEG("TYPE")'="OBX" S CURLINE=CURLINE-1 Q
  1. .D OBX^DGENUPL2
  1. .S CURLINE=CURLINE+1
  1. .D NXTSEG^DGENUPL(MSGIEN,CURLINE,.SEG)
  1. ;
  1. Q $S(ERROR:0,1:1)
  1. ;
  1. CONVERT(VAL,DATATYPE,ERROR) ;
  1. ;Description: Converts the value found in the HL7 segment to DHCP format
  1. ;
  1. ;Input:
  1. ; VAL - value parsed from the HL7 segment
  1. ; DATATYPE: indicates the type of conversion necessary
  1. ; "DATE" - needs to be converted to FM format
  1. ; "TS" - time stamp, needs to be converted to FM format
  1. ; "Y/N" - 0->"N",1->"Y"
  1. ; "1/0" - "Y"->1,"N"->0
  1. ; "INSTITUTION" - needs to convert the station number with suffix to a point to the INSTITUTION file
  1. ; "ELIGIBILITY" - VAL is a pointer to the national eligibility code file (#8.1), needs to be converted to a local eligibility code (file #8)
  1. ;
  1. ; "MT" - VAL is a Means Test Status code, it needs to be converted
  1. ; to a pointer to the Means Test Status file
  1. ; Phase II convert code to RSN IEN for DGCDIS object
  1. ; "CDRSN" data type converts the codes diagnosis,procedure,condition to RSN IEN. (HL7TORSN^DGENA5)
  1. ; "EXT" convert from code to abbreviation
  1. ; "POS" convert from Period of Service code to a point to Period of Service file
  1. ; "AGENCY" convert Agency/Allied Country code from file 35
  1. ;OUTPUT:
  1. ; Function Value - the result of the conversion
  1. ; ERROR - set to 1 if an error is detected, 0 otherwise (optional,pass by ref)
  1. ;
  1. S ERROR=0
  1. D
  1. .I VAL="" Q
  1. .I VAL="""""" S VAL="@" Q
  1. .I $G(DATATYPE)="EXT" D Q
  1. ..S VAL=$$HLTOLIMB^DGENA5(VAL)
  1. .I $G(DATATYPE)="CDRSN" D Q
  1. ..S VAL=$$HL7TORSN^DGENA5(VAL)
  1. .I ($G(DATATYPE)="MT") D Q
  1. ..S VAL=$O(^DG(408.32,"AC",1,VAL,0))
  1. ..I 'VAL S ERROR=1
  1. .I ($G(DATATYPE)="DATE") D Q
  1. ..I $L(VAL)'=8 S ERROR=1 Q
  1. ..S VAL=$$FMDATE^HLFNC(VAL)
  1. ..I ((VAL'=+VAL)!($L($P(VAL,"."))<7)) S ERROR=1
  1. .I ($G(DATATYPE)="TS") D Q
  1. ..I $L(VAL)<8 S ERROR=1 Q
  1. ..S VAL=$$FMDATE^HLFNC(VAL)
  1. ..I ((VAL'=+VAL)!($L($P(VAL,"."))<7)) S ERROR=1
  1. .I ($G(DATATYPE)="Y/N") D Q
  1. ..I VAL=0 S VAL="N" Q
  1. ..I VAL=1 S VAL="Y" Q
  1. ..S ERROR=1
  1. .I ($G(DATATYPE)="1/0") D Q
  1. ..I VAL="N" S VAL=0 Q
  1. ..I VAL="Y" S VAL=1 Q
  1. ..S ERROR=1
  1. .I ($G(DATATYPE)="ELIGIBILITY") D Q
  1. ..S VAL=$$MAP(VAL)
  1. ..I 'VAL S ERROR=1
  1. .I ($G(DATATYPE)="INSTITUTION") D Q
  1. ..N OLDVAL
  1. ..S OLDVAL=VAL
  1. ..S VAL=$O(^DIC(4,"D",OLDVAL,0))
  1. ..I 'VAL S VAL=$O(^DIC(4,"D",(+OLDVAL),0))
  1. ..I 'VAL S ERROR=1
  1. .I ($G(DATATYPE)="POS") D Q
  1. ..N OLDVAL
  1. ..S OLDVAL=VAL
  1. ..S VAL=$O(^DIC(21,"D",OLDVAL,0))
  1. ..I 'VAL S ERROR=1
  1. .I ($G(DATATYPE)="AGENCY") D Q
  1. ..N OLDVAL
  1. ..S OLDVAL=VAL
  1. ..S VAL=$O(^DIC(35,"C",OLDVAL,0))
  1. ..I 'VAL S ERROR=1
  1. Q VAL
  1. ;
  1. MAP(VALUE) ;
  1. ;Description: Tries to map an eligibility code from file #8.1 (the national MAS ELIGIBILITY CODE file) to file #8 (the local ELIGIBILITY CODE file)
  1. ;
  1. ;Input: VALUE - ien of an entry in file #8.1
  1. ;
  1. ;Output: Function value - NULL if mapping is not found, otherwise returns an ien of entry in file #8
  1. ;
  1. N ECODE,NODE,COUNT,NAME
  1. ;try to choose a code from file 8 to use that is appropriate
  1. S (COUNT,ECODE)=0
  1. ;
  1. F S ECODE=$O(^DIC(8,"D",VALUE,ECODE)) Q:'ECODE D
  1. .S NODE=$G(^DIC(8,ECODE,0))
  1. .;put code on list if active
  1. .I (NODE'=""),'$P(NODE,"^",7) S ECODE(ECODE)=$P(NODE,"^"),COUNT=COUNT+1
  1. ;
  1. ;only one match found, so use it
  1. Q:COUNT=1 $O(ECODE(0))
  1. ;
  1. ;no match found
  1. Q:'COUNT ""
  1. ;
  1. ;multiple matches found, try to match by name
  1. I COUNT>1 D
  1. .S ECODE=0
  1. .S NAME=$P($G(^DIC(8.1,VALUE,0)),"^")
  1. .F S ECODE=$O(ECODE(ECODE)) Q:'ECODE Q:ECODE(ECODE)=NAME
  1. Q ECODE
  1. ;
  1. ACCEPT(MSGID) ;
  1. ;Description: Writes an ack (AA) to a global to be transmitted later.
  1. ;
  1. ;Inputs:
  1. ; MSGID -message control id of HL7 msg in the MSH segment
  1. ;
  1. ;Outputs: none
  1. ;
  1. K HL,HLMID,HLMTIEN,HLDT,HLDT1
  1. D INIT^HLFNC2(HLEID,.HL)
  1. D CREATE^HLTF(.HLMID,.HLMTIEN,.HLDT,.HLDT1)
  1. S HLEVN=1
  1. S MID=HLMID_"-"_HLEVN
  1. D MSH^HLFNC2(.HL,MID,.HLRES)
  1. S ^TMP("HLS",$J,1)=HLRES
  1. ;
  1. ;it seems HLFS sometimes disappears upon reaching this point
  1. I $G(HLFS)="" S HLFS="^"
  1. ;
  1. S ^TMP("HLS",$J,2)="MSA"_HLFS_"AA"_HLFS_MSGID
  1. Q
  1. ;
  1. MVERRORS ;
  1. ;Error messages were being deleted from ^TMP("HLS",$J by another package
  1. ;during the upload. To fix this, errors are written to another
  1. ;subscript, then moved when the error list is complete.
  1. ;
  1. M ^TMP("HLS",$J)=^TMP("IVM","HLS",$J)
  1. K ^TMP("IVM","HLS",$J)
  1. Q