Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="EDIGW.FileServiceHelper">
<IncludeCode>EDIGW</IncludeCode>
<TimeCreated>65041,39856.851878</TimeCreated>
<Method name="FileServiceHelper">
<ClassMethod>1</ClassMethod>
<FormalSpec>tInputFilename:%String,tInputPath:%String,tDuplicateISACheckHours:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
Set fullPath = tInputPath_tInputFilename
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"FileServiceHelper: Process "_fullPath)
Set batchId = ##class(EDIGW.Utility).getBatchId(tInputFilename)
If (batchId '= "") || '##class(EDIGW.Utility).TestFilename(tInputFilename) {
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"FileServiceHelper ERROR Duplicate File: "_fullPath)
Set st=##class(EDIGW.Utility).RenameFileDuplicate(fullPath)
//Quit st // Return 1 to prevent File Service Error
Quit $$$ERROR($$$GeneralError,"Duplicate Filename") // Reject Duplicate File
}
Set tIOStream=##class(%IO.FileStream).%New() // $$$ASSERT($IsObject(tIOStream))
Set tOpenTimeout=5
Do tIOStream.Open(fullPath,,tOpenTimeout,,.tSC) Quit:$$$ISERR(tSC) tSC
Set st=$$$OK
Set lineNum=0
Set (ISA,GS,ST,SE,GE,IEA)=""
Set (iCountGS,iCountGE,iCountISA,iCountIEA,iCountST,iCountSE)=0
Set (prevLine,lastLine)=""
Set sFind="ST*",iFind=$Length(sFind)
Set transFlag=0 // Are we inside a ST/SE transaction ?
Set pMaxReadLen=32767
Set pLineTerminator="~"
While 'tIOStream.AtEnd {
Set tmp = tIOStream.ReadLine(pMaxReadLen,.pTimeout,.pSC,pLineTerminator)
Set tmp=$Translate(tmp,$Char(10)_$Char(13)) // strips out $Char(10,13)
If tmp="" Continue // Skip blank lines
Set prevLine=lastLine
Set lastLine=tmp
Set lineNum=lineNum+1
If (lineNum=1),$E(tmp,1,4)="ISA*" { Set ISA=tmp,iCountISA=iCountISA+1 Continue } // Expect ISA on first line
If (lineNum<3),$E(tmp,1,3)="GS*" { Set GS=tmp,iCountGS=iCountGS+1 Continue } // Expect GS before third line
//Here we are trying to check for SE for every ST by setting the value of transFlag
If $E(tmp,1,iFind)=sFind {
If (sFind="SE*") {
Set SE=tmp,iCountSE=iCountSE+1,segCounter=segCounter+1,transFlag=0,sFind="ST*",iFind=$Length(sFind)
Continue
}
If (sFind="ST*") {
Set ST=tmp,iCountST=iCountST+1,segCounter=1,transFlag=1,sFind="SE*",iFind=$Length(sFind)
Continue
}
If (sFind="GS*") {
Set GS=tmp,iCountGS=iCountGS+1,sFind="ST*",iFind=$Length(sFind)
Continue
}
}
If transFlag {
Set segCounter=segCounter+1
Continue
}
}
// Close the file
Do tIOStream.Close()
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"prevLine : "_prevLine)
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"lastLine : "_lastLine)
If $E(prevLine,1,3)="GE*" Set GE=prevLine,iCountGE=iCountGE+1
If $E(lastLine,1,4)="IEA*" Set IEA=lastLine,iCountIEA=iCountIEA+1
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"ISA : "_ISA)
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"GS : "_GS)
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"GE : "_GE)
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"IEA : "_IEA)
If (tDuplicateISACheckHours > 0) {
Set tSC = ..FileDeduplicationISA(ISA,tDuplicateISACheckHours)
If $$$ISERR(tSC) {
Quit tSC
}
}
Set desc="",nothing="",space=" "
If ISA="" Set desc=desc_$Select(st:nothing,1:space)_"ISA is missing.",st=$$$ERROR($$$GeneralError,desc)
If GS="" Set desc=desc_$Select(st:nothing,1:space)_"GS is missing.",st=$$$ERROR($$$GeneralError,desc)
If GE="" Set desc=desc_$Select(st:nothing,1:space)_"GE is missing.",st=$$$ERROR($$$GeneralError,desc)
If IEA="" Set desc=desc_$Select(st:nothing,1:space)_"IEA is missing.",st=$$$ERROR($$$GeneralError,desc)
If (GE '= "") {
Set GE01 = $Piece(GE,"*",2)
If (GE01 '= iCountST) Set desc=desc_$Select(st:nothing,1:space)_"GE01 is wrong.",st=$$$ERROR($$$GeneralError,desc)
}
If (IEA '= "") {
Set IEA01 = $Piece(IEA,"*",2)
If (IEA01 '= iCountGS) Set desc=desc_$Select(st:nothing,1:space)_"IEA01 is wrong.",st=$$$ERROR($$$GeneralError,desc)
}
// We need to quit and not go on to saving anything in interchange or batch here
if $$$ISERR(st) QUIT st
set batchStatus = $$$OK
set gsStatus = $$$OK
set isaStatus = $$$OK
set delim="*"
set txType = $Piece(GS,delim,9)
set txTypeVal=##class(EDIGW.Utility).GetTXNTYPE(txType)
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"txTypeVal : "_txTypeVal)
// Saving Interchange
// We need to quit processing the batch if we are unable to get the goodFileName, badFileName, 999FileName
// These values need to go into Oracle Database and without these values, nothing will get saved into Oracle
set tsc = ##class(EDIGW.Utility).getOutputFileNames(.goodFileName,.badFileName,.file999Name)
if $$$ISERR(tsc) quit tsc
// If this is a file from ChangeHealth the 999 file should be of form 999_{payerid}_{runid}.X12
// If this is a file from PMCO the 999 file name shoulde of form 999_EMDEON_{runid}.X12 - which is what we get from above
set tPayerId = $E($Piece(ISA,delim,9),1,5)
if (tInputPath [ "CLAIMS_IN_EMDEON") set file999Name = $replace(file999Name,"EMDEON",tPayerId)
set objISA = ##class(CREPOS.INTCHGCONTROL).%New()
//set objISA.DATECREATED = +$Horolog
set objISA.FILENUMBER = goodFileName
set objISA.IEA01NBRINCLGRP = $Piece(IEA, delim,2)
set objISA.IEA02INTCHGNBR=$Piece(IEA,delim,3)
set objISA.ISA01AUTHQUAL = $Piece(ISA,delim,2)
set objISA.ISA02AUTHINFO = $Piece(ISA,delim,3)
set objISA.ISA03SCRINFOQUAL = $Piece(ISA,delim,4)
set objISA.ISA04SCRINFO = $Piece(ISA,delim,5)
set objISA.ISA05SNDIDQUAL = $Piece(ISA,delim,6)
set objISA.ISA06SNDID = $Piece(ISA,delim,7)
set objISA.ISA07RCVIDQUAL= $Piece(ISA,delim,8)
set objISA.ISA08RCVID = $Piece(ISA,delim,9)
set objISA.ISA09INTCHGDT=$Piece(ISA,delim,10)
set objISA.ISA10INTCHGTM=$Piece(ISA,delim,11)
set objISA.ISA11INTCHGSTD=$Piece(ISA,delim,12)
set objISA.ISA12INTCHGVER=$Piece(ISA,delim,13)
set objISA.ISA13INTCHGNBR=$Piece(ISA,delim,14)
set objISA.ISA14ACKRQST=$Piece(ISA,delim,15)
set objISA.ISA15USEIND =$Piece(ISA,delim,16)
set objISA.ISA16CPNTELESEP=$Piece(ISA,delim,17)
set objISA.TXTYPE =txTypeVal
set isaStatus = objISA.%Save()
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"isaStatus : "_isaStatus)
set objISA = ""
if batchStatus,'isaStatus set batchStatus=isaStatus
set objGS = ##class(CREPOS.FUNCTIONALGROUP).%New()
set objGS.FILENUMBER = goodFileName
set objGS.GE01NBRTRANSETS=$Piece(GE,delim,2)
set objGS.GE02GRPCTLNBR=$Piece(GE,delim,3)
set objGS.GS01FCTLIDCD=$Piece(GS,delim,2)
set objGS.GS02APPSNDCD=$Piece(GS,delim,3)
set objGS.GS03APPRCVCD=$Piece(GS,delim,4)
set objGS.GS04CREDT=$Piece(GS,delim,5)
set objGS.GS05CRETM=$Piece(GS,delim,6)
set objGS.GS06GRPCTLNBR=$Piece(GS,delim,7)
set objGS.GS07RESPAGCYCD=$Piece(GS,delim,8)
set objGS.GS08VERRLSINDID=$Piece(GS,delim,9)
set objGS.TXTYPE = txTypeVal
set gsStatus = objGS.%Save()
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"gsStatus : "_gsStatus)
set objGS = ""
if batchStatus,'gsStatus set batchStatus=gsStatus
// ?? if tsc is ERR - probably not allow further batch procesing ??
set tilde="~"
set objBatch = ##class(CREPOS.BATCH999).%New()
set objBatch.DateCreated = $Piece($Horolog,",",1)
set objBatch.TimeCreated = $Piece($Horolog,",",2)
//Set objBatch.DateTimeCreated = $ZTIMESTAMP
set objBatch.FILENUMBER = tInputFilename
set objBatch.RawISA = $Piece(ISA,tilde,1)
set objBatch.RawIEA = $Piece(IEA,tilde,1)
set objBatch.RawGS = $Piece(GS,tilde,1)
set objBatch.RawGE = $Piece(GE,tilde,1)
set objBatch.ISA08RCVID = $Piece(ISA,"*",9)
set objBatch.ISA13INTCHGNBR = $Piece(ISA,"*",14)
set objBatch.valStatus = batchStatus
set objBatch.valText = desc
set objBatch.GOODFILE = goodFileName
set objBatch.BADFILE = badFileName
set objBatch.FILE999 = file999Name
set objBatch.Path = tInputPath
set st=objBatch.%Save()
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"objBatch.%Save() : "_st)
set objBatch = ""
if 'batchStatus Quit st
Quit $$$OK
]]></Implementation>
</Method>
<Method name="FileDeduplicationISA">
<ClassMethod>1</ClassMethod>
<FormalSpec>ISA:%String="",pDuplicateISACheckHours:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
If (ISA '= "") {
BREAK
Set ISA08 = $Piece(ISA,"*",9)
Set ISA13 = $Piece(ISA,"*",14)
Set CurrentDateTime = $Horolog
Set strSQL="SELECT ISA08RCV_ID,ISA13INTCHG_NBR,DATECREATED,TIMECREATED FROM CREPOS.BATCH999 WHERE ISA08RCV_ID= '"_ISA08_"' AND ISA13INTCHG_NBR= '"_ISA13_"'"
Set tStatement=##class(%SQL.Statement).%New()
Set qStatus=tStatement.%Prepare(strSQL)
If qStatus'=1 { Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"%Prepare failed: "_qStatus) QUIT qStatus}
Set objResultSet=tStatement.%Execute()
Set archiveFlag = 0
While objResultSet.%Next() {
//George has asked us to keep all and /or add more logging statements in the code.
Set DateCreated = objResultSet.%GetData(3)
Set TimeCreated = objResultSet.%GetData(4)
Set DateTimeCreated = DateCreated_","_TimeCreated
Set timeElapsed=$SYSTEM.SQL.DATEDIFF("hh",DateTimeCreated,CurrentDateTime)
If (timeElapsed<=pDuplicateISACheckHours) Set archiveFlag = $$$OK
If (archiveFlag=$$$OK){
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"Duplicate ISA. archiveFlag = "_archiveFlag)
QUIT
}
}
If (archiveFlag=$$$OK){
Do ##class(EDIGW.Utility).DEBUG($$$DebugFileService,"archive=1, trash file")
Quit $$$ERROR($$$GeneralError,"Duplicate ISA") // Duplication detected
}
}
Quit $$$OK
]]></Implementation>
</Method>
</Class>
</Export>