/// <summary>
        ///  Actual Method call for Microdyn output retrieval
        /// </summary>
        public MedicareOutPatientResult GetMedicareOutPatientResult(long claimId)
        {
            StringBuilder            inputData = new StringBuilder();
            MedicareOutPatientResult medicareOutPatientResult = new MedicareOutPatientResult();

            MicrodynApcEditInput microdynApcEditInput = _medicareOutPatientRepository.GetMicrodynApcEditInput(claimId);

            string cLine = GetCRecordLine(microdynApcEditInput.CRecord);
            string dLine = GetDRecordLine(microdynApcEditInput.DRecord);
            string lLine = GetLRecordLine(microdynApcEditInput.LRecords);

            if (GlobalConfigVariable.IsMicrodynEnabled)
            {
                if (!string.IsNullOrEmpty(cLine) && !string.IsNullOrEmpty(dLine) && !string.IsNullOrEmpty(lLine))
                {
                    int calcTotal = cLine.Length + dLine.Length + (microdynApcEditInput.LRecords.Count * 200);

                    inputData.Append(cLine);
                    inputData.Append(dLine);
                    inputData.Append(lLine);

                    if (inputData.Length != calcTotal)
                    {
                        medicareOutPatientResult.ReturnCode = 1;
                        medicareOutPatientResult.Message    = "Claim Data Errors Found";
                        return(medicareOutPatientResult);
                    }
                }
                else
                {
                    medicareOutPatientResult.ReturnCode = 1;
                    medicareOutPatientResult.Message    = "Claim Data Errors Found";
                    return(medicareOutPatientResult);
                }

                Instance.InputLineCount = microdynApcEditInput.LRecords.Count;
                Instance.InputData      = inputData.ToString();
                Instance.AutoDenyReject = false;

                Instance.APCEdit();

                if (GlobalConfigVariable.IsMicrodynLogEnabled)
                {
                    Log.LogInfo(Instance.ResultsData + "ClaimId-" + claimId, "MicrodynApcEditDllResultsData");
                    Log.LogInfo(Instance.PaymentInputData + "ClaimId-" + claimId, "MicrodynApcEditDllPaymentInputData");
                }
                if (Instance.APCErrorsFound)
                {
                    //Processing Unsuccessful - Edit errors found
                    //ResultsData contains claim and line item errors

                    switch (Instance.ReturnCode)
                    {
                    case 1:
                        medicareOutPatientResult.ReturnCode = 1;
                        medicareOutPatientResult.Message    = "Claim Errors Found";
                        break;

                    case 5:
                        medicareOutPatientResult.ReturnCode = 5;
                        medicareOutPatientResult.Message    = "Major claim errors found - processing suspended";
                        break;

                    case 11:
                        medicareOutPatientResult.ReturnCode = 11;
                        medicareOutPatientResult.Message    = "Misc. APCActive Error";
                        break;

                    case 98:
                        medicareOutPatientResult.ReturnCode = 98;
                        medicareOutPatientResult.Message    = "SQL tables corrupted or loaded incorrectly";
                        break;

                    case 99:
                        medicareOutPatientResult.ReturnCode = 99;
                        medicareOutPatientResult.Message    = "APCActive license id expired";
                        break;

                    case 100:
                        medicareOutPatientResult.ReturnCode = 100;
                        medicareOutPatientResult.Message    = "SQL data access error";
                        break;
                        // *** Ignore
                    }
                }
                else
                {
                    string inputDataString = Instance.PaymentInputData;

                    MedicareOutPatient objPatientData = microdynApcEditInput.MedicareOutPatientRecord;

                    _apcPayDll = new NetAPCPay
                    {
                        InputLineCount = microdynApcEditInput.LRecords.Count,
                        InputData      = inputDataString,

                        // Test data - this gives some value for the total payment amount
                        //InputLineCount = 25,
                        //InputData = @"T$11411-018       001Q00810012000120 T 1200 0000000010000017000020030303                                                                                                                                T$11411-018       002Q00810012000120 T 1200 0000000010000017000020030304                                                                                                                                T$11411-018       003Q00810012000120 T 1200 0000000010000017000020030318                                                                                                                                T$11411-018       004856100000000000 A 2100 0200000010000002098020030303                                                                                                                                T$11411-018       005856100000000000 A 2100 0200000010000002098020030318                                                                                                                                T$11411-018       006850250000000000 A 2100 0200000010000002625020030319                                                                                                                                T$11411-018       007856510000000000 A 2100 0200000010000001890020030319                                                                                                                                T$11411-018       008365400000000000 N 9101 0000000010000005000020030303                                                                                                                                T$11411-018       009907840035900359 X 1100 0000000020000010000020030303                                                                                                                                T$11411-018       010907840035900359 X 1100 0000000030000015000020030304                                                                                                                                T$11411-018       011365400000000000 N 9101 0000000010000005000020030318                                                                                                                                T$11411-018       012907840035900359 X 1100 0000000030000015000020030318                                                                                                                                T$11411-018       013J11000000000000 N 9101 0000000030000001395020030303                                                                                                                                T$11411-018       014J12000000000000 N 9101 0000000010000001885020030303                                                                                                                                T$11411-018       015J15630090500905 K 1100 0000000720001352160020030303                                                                                                                                T$11411-018       016J19400000000000 N 9101 0000000020000003660020030303                                                                                                                                T$11411-018       017J11000000000000 N 9101 0000000030000001395020030304                                                                                                                                T$11411-018       018J12000000000000 N 9101 0000000010000001885020030304                                                                                                                                T$11411-018       019J15630090500905 K 1100 0000000720001352160020030304                                                                                                                                T$11411-018       020J19400000000000 N 9101 0000000020000003660020030304                                                                                                                                T$11411-018       021J34870911509115 G 5100 1000000040000199400020030304                                                                                                                                T$11411-018       022J11000000000000 N 9101 0000000030000001395020030318                                                                                                                                T$11411-018       023J12000000000000 N 9101 0000000010000001885020030318                                                                                                                                T$11411-018       024J15630090500905 K 1100 0000000720001352160020030318                                                                                                                                T$11411-018       025J19400000000000 N 9101 0000000020000003660020030318                                                                                                                                ",
                        //ServiceFromDate = "03/03/2003",

                        ProviderNumber          = objPatientData.NPI,
                        ServiceFromDate         = Convert.ToString(objPatientData.ServiceDate),
                        BeneDeductible          = Convert.ToDouble(objPatientData.BeneDeductible),
                        BloodDeductiblePints    = Convert.ToInt32(objPatientData.BloodDeductiblePints),
                        AllowTerminatedProvider = Convert.ToBoolean(objPatientData.AllowTerminatorProvider),
                        AdjustmentFactor        = Convert.ToDouble(objPatientData.AdjustFactor),
                        AdjustmentOption        = Convert.ToInt32(objPatientData.AdjustmentOptions)
                    };

                    _apcPayDll.APCCalc();

                    if (!_apcPayDll.CalcErrorsFound)
                    {
                        //No Errors found
                        //Parse the V and W records to get the out patient payment details

                        medicareOutPatientResult            = GetResultData(_apcPayDll.ResultsData);
                        medicareOutPatientResult.ReturnCode = 0;
                        medicareOutPatientResult.Message    = "No errors Found";
                    }
                    else
                    {
                        //Errors found in APC Payment calculation
                        medicareOutPatientResult.ReturnCode = _apcPayDll.ReturnCode;
                        switch (_apcPayDll.ReturnCode)
                        {
                        //Claim Level 'Error' Return Codes
                        case 50:
                            medicareOutPatientResult.Message = "Wage Index not located ";
                            break;

                        case 51:
                            medicareOutPatientResult.Message = "Wage Index = 0 ";
                            break;

                        case 52:
                            medicareOutPatientResult.Message = "Provider file Wage Index reclassification code invalid or missing ";
                            break;

                        case 53:
                            medicareOutPatientResult.Message = "Service date not numeric or < 8/1/2000  Provider file waiver indicator = “Y”. Case cannot be processed. ";
                            break;

                        case 54:
                            medicareOutPatientResult.Message = "Service date < provider effective date ";
                            break;

                        case 55:
                            medicareOutPatientResult.Message = "Invalid provider number ";
                            break;

                        case 56:
                            medicareOutPatientResult.Message = "Invalid beneficiary deductible amount ";
                            break;

                        case 90:
                            medicareOutPatientResult.Message = "Input number of line items in error ";
                            break;

                        case 95:
                            medicareOutPatientResult.Message = "Misc. APCActive Pricer DLL error ";
                            break;

                        case 99:
                            medicareOutPatientResult.Message = "APCActive Pricer License is expired ";
                            break;

                        case 100:
                            medicareOutPatientResult.Message = "SQL data access error ";
                            break;

                        //Reimbursement calculation is terminated for return codes > 50

                        //Line Item Level 'Error' Return Codes

                        case 30:
                            medicareOutPatientResult.Message = "Line item APC is missing or invalid";
                            break;

                        case 38:
                            medicareOutPatientResult.Message = "Line item Discount factor is invalid";
                            break;

                        case 40:
                            medicareOutPatientResult.Message = "Line item Status Indicator is invalid";
                            break;

                        case 48:
                            medicareOutPatientResult.Message = "Line item Payment Adjustment Flag is invalid";
                            break;

                        //Line Item Level 'Processing' Return Codes

                        case 1:
                            medicareOutPatientResult.Message = " Line processed successfully ";
                            break;

                        case 20:
                            medicareOutPatientResult.Message = " Line processed but payment =0, all applied to deductible.  ";
                            break;

                        case 22:
                            medicareOutPatientResult.Message = " Daily coinsurance limitation – claim processed ";
                            break;

                        case 25:
                            medicareOutPatientResult.Message = " Line item has reduced coinsurance amount ";
                            break;

                        case 41:
                            medicareOutPatientResult.Message = " Status Indicator not processed by OPPS Pricer ";
                            break;

                        case 42:
                            medicareOutPatientResult.Message = " APC = 00000 ";
                            break;

                        case 43:
                            medicareOutPatientResult.Message = " Payment Indicator not = 1 or 5 thru 9 ";
                            break;

                        case 44:
                            medicareOutPatientResult.Message = " Status indicator = 'H', but payment indicator not = '6' ";
                            break;

                        case 45:
                            medicareOutPatientResult.Message = " Packaging flag <> '0' ";
                            break;

                        case 46:
                            medicareOutPatientResult.Message = " Line item denial/reject flag not = to 0 and line item action flag not = to 1 ";
                            break;

                        case 47:
                            medicareOutPatientResult.Message = " Line item action flag = 2 or 3 ";
                            break;

                        case 49:
                            medicareOutPatientResult.Message = " Payment Method Flag not = to 0 ";
                            break;
                        }
                        if (GlobalConfigVariable.IsMicrodynLogEnabled)
                        {
                            Log.LogInfo(medicareOutPatientResult.Message + "ClaimId-" + claimId, "MicrodynApcEditDllResultsData");
                        }
                    }

                    _apcPayDll.Dispose();
                }
            }
            else
            {
                medicareOutPatientResult.ReturnCode         = 0;
                medicareOutPatientResult.TotalPaymentAmount = 0;
                medicareOutPatientResult.Message            = "Microdyne Switched Off";
            }
            return(medicareOutPatientResult);
        }
Пример #2
0
        private MedicareOutPatientResult GetMedicareOutPatientResult(IEvaluateableClaim claim)
        {
            StringBuilder            inputData = new StringBuilder();
            MedicareOutPatientResult medicareOutPatientResult = new MedicareOutPatientResult();

            MicrodynApcEditInput microdynApcEditInput = claim.MicrodynApcEditInput;

            string dLine = string.Empty;
            string eLine = string.Empty;
            string cLine = _cRecordLogic.GetCRecordLine(microdynApcEditInput.CRecord);

            if (claim.StatementThru >= DateTime.Parse(Constants.IcdVersionDate, CultureInfo.InvariantCulture))
            {
                eLine = _eRecordLogic.GetERecordLine(microdynApcEditInput.ERecord);
            }
            else
            {
                dLine = _dRecordLogic.GetDRecordLine(microdynApcEditInput.DRecord);
            }
            string lLine = _lRecordLogic.GetLRecordLine(microdynApcEditInput.LRecords);

            if (GlobalConfigVariable.IsMicrodynEnabled)
            {
                inputData.Append(cLine);
                string diagnosisLine = (claim.StatementThru >= DateTime.Parse(Constants.IcdVersionDate, CultureInfo.InvariantCulture) ? eLine : dLine);
                inputData.Append(diagnosisLine);
                inputData.Append(lLine);

                if (inputData.Length !=
                    Constants.CRecordLength + Constants.DRecordLength +
                    (microdynApcEditInput.LRecords.Count * Constants.LRecordLength))
                {
                    medicareOutPatientResult.ReturnCode = 1;
                    medicareOutPatientResult.Message    = Constants.MessageClaimDataError;
                    if (GlobalConfigVariable.IsMicrodynLogEnabled)
                    {
                        if (claim.StatementThru >= DateTime.Parse(Constants.IcdVersionDate, CultureInfo.InvariantCulture))
                        {
                            Log.LogInfo(
                                string.Format(CultureInfo.InvariantCulture, DataIssueMessageFormatWithERecord,
                                              claim.ClaimId, cLine, Environment.NewLine,
                                              _cRecordLogic.ValidationErrors, Environment.NewLine,
                                              diagnosisLine, Environment.NewLine,
                                              _eRecordLogic.ValidationErrors, Environment.NewLine,
                                              lLine, Environment.NewLine,
                                              _lRecordLogic.ValidationErrors),
                                Constants.MicrodynApcEditDllResultsData);
                        }
                        else
                        {
                            Log.LogInfo(
                                string.Format(CultureInfo.InvariantCulture, DataIssueMessageFormatWithDRecord,
                                              claim.ClaimId, cLine, Environment.NewLine,
                                              _cRecordLogic.ValidationErrors, Environment.NewLine,
                                              diagnosisLine, Environment.NewLine,
                                              _dRecordLogic.ValidationErrors, Environment.NewLine,
                                              lLine, Environment.NewLine,
                                              _lRecordLogic.ValidationErrors),
                                Constants.MicrodynApcEditDllResultsData);
                        }
                    }
                    return(medicareOutPatientResult);
                }

                Instance.InputLineCount = microdynApcEditInput.LRecords.Count;
                Instance.InputData      = inputData.ToString();
                Instance.AutoDenyReject = false;

                Instance.APCEdit();

                if (Instance.APCErrorsFound)
                {
                    //Processing Unsuccessful - Edit errors found
                    //ResultsData contains claim and line item errors
                    medicareOutPatientResult.ReturnCode = Instance.ReturnCode;
                    GetInstanceMessage(true, Instance.ReturnCode, medicareOutPatientResult);
                    if (Instance.ResultsData.Length % 200 == 0)
                    {
                        medicareOutPatientResult.EditErrorCodes = GetResultMessageData(Instance.ResultsData);
                    }
                    medicareOutPatientResult.MicrodynEditReturnRemarks = "Error Code:" + medicareOutPatientResult.ReturnCode + "; " +
                                                                         medicareOutPatientResult.Message;
                    if (GlobalConfigVariable.IsMicrodynLogEnabled)
                    {
                        if (claim.StatementThru >= DateTime.Parse(Constants.IcdVersionDate, CultureInfo.InvariantCulture))
                        {
                            Log.LogInfo(
                                string.Format(CultureInfo.InvariantCulture, ApcErrorMessageFormatWithERecord, claim.ClaimId,
                                              medicareOutPatientResult.Message, Instance.ResultsData,
                                              string.IsNullOrEmpty(medicareOutPatientResult.EditErrorCodes)
                                       ? string.Empty
                                       : Constants.ErrorCodes + medicareOutPatientResult.EditErrorCodes,
                                              Environment.NewLine, cLine, Environment.NewLine, diagnosisLine, Environment.NewLine,
                                              lLine),
                                Constants.MicrodynApcEditDllResultsData);
                        }
                        else
                        {
                            Log.LogInfo(
                                string.Format(CultureInfo.InvariantCulture, ApcErrorMessageFormatWithDRecord, claim.ClaimId,
                                              medicareOutPatientResult.Message, Instance.ResultsData,
                                              string.IsNullOrEmpty(medicareOutPatientResult.EditErrorCodes)
                                        ? string.Empty
                                        : Constants.ErrorCodes + medicareOutPatientResult.EditErrorCodes,
                                              Environment.NewLine, cLine, Environment.NewLine, diagnosisLine, Environment.NewLine,
                                              lLine),
                                Constants.MicrodynApcEditDllResultsData);
                        }
                    }
                }
                else
                {
                    medicareOutPatientResult.IsEditSuccess = true;
                    string             inputDataString = Instance.PaymentInputData;
                    MedicareOutPatient objPatientData  = microdynApcEditInput.MedicareOutPatientRecord;
                    _apcPayDll = new NetAPCPay
                    {
                        InputLineCount          = microdynApcEditInput.LRecords.Count,
                        InputData               = inputDataString,
                        ProviderNumber          = objPatientData.Npi,
                        ServiceFromDate         = Convert.ToString(objPatientData.ServiceDate, CultureInfo.InvariantCulture),
                        BeneDeductible          = Convert.ToDouble(objPatientData.BeneDeductible),
                        BloodDeductiblePints    = Convert.ToInt32(objPatientData.BloodDeductiblePints),
                        AllowTerminatedProvider = Convert.ToBoolean(objPatientData.AllowTerminatorProvider, CultureInfo.InvariantCulture),
                        AdjustmentFactor        = Convert.ToDouble(objPatientData.AdjustFactor),
                        AdjustmentOption        = Convert.ToInt32(objPatientData.AdjustmentOptions)
                    };

                    _apcPayDll.APCCalc();
                    if (!_apcPayDll.CalcErrorsFound)
                    {
                        //No Errors found
                        //Parse the V and W records to get the out patient payment details
                        medicareOutPatientResult                 = GetResultData(_apcPayDll.ResultsData);
                        medicareOutPatientResult.ReturnCode      = 0;
                        medicareOutPatientResult.Message         = Constants.MessageNoError;
                        medicareOutPatientResult.IsPricerSuccess = true;
                    }
                    else
                    {
                        //Errors found in APC Payment calculation
                        medicareOutPatientResult.ReturnCode = _apcPayDll.ReturnCode;
                        GetInstanceMessage(false, _apcPayDll.ReturnCode, medicareOutPatientResult);
                        medicareOutPatientResult.PricerErrorCodes = medicareOutPatientResult.ReturnCode;
                        if (GlobalConfigVariable.IsMicrodynLogEnabled)
                        {
                            if (claim.StatementThru >= DateTime.Parse(Constants.IcdVersionDate, CultureInfo.InvariantCulture))
                            {
                                Log.LogInfo(
                                    string.Format(CultureInfo.InvariantCulture, ApcCalcMessageFormatWithERecord, claim.ClaimId, medicareOutPatientResult.Message,
                                                  medicareOutPatientResult.PricerErrorCodes == 0
                                      ? string.Empty
                                      : Constants.ErrorCodes + medicareOutPatientResult.PricerErrorCodes, _apcPayDll.ResultsData,
                                                  Environment.NewLine, cLine, Environment.NewLine, eLine, Environment.NewLine, lLine),
                                    Constants.MicrodynApcCalcDllResultsData);
                            }
                            else
                            {
                                Log.LogInfo(
                                    string.Format(CultureInfo.InvariantCulture, ApcCalcMessageFormatWithDRecord, claim.ClaimId, medicareOutPatientResult.Message,
                                                  medicareOutPatientResult.PricerErrorCodes == 0
                                       ? string.Empty
                                       : Constants.ErrorCodes + medicareOutPatientResult.PricerErrorCodes, _apcPayDll.ResultsData,
                                                  Environment.NewLine, cLine, Environment.NewLine, dLine, Environment.NewLine, lLine),
                                    Constants.MicrodynApcCalcDllResultsData);
                            }
                        }
                    }
                    _apcPayDll.Dispose();
                }
            }
            else
            {
                medicareOutPatientResult.ReturnCode         = 0;
                medicareOutPatientResult.TotalPaymentAmount = 0;
                medicareOutPatientResult.Message            = Constants.MessageMicrodyneOff;
                medicareOutPatientResult.IsEditSuccess      = true;
            }
            return(medicareOutPatientResult);
        }
        public void UpdateEvaluateableClaimsTest()
        {
            // Arrange
            _target = new EvaluateableClaimLogic();

            ConditionCode conditionCode = new ConditionCode {
                ClaimId = 123, Code = "0300"
            };
            List <ConditionCode> conditionCodes = new List <ConditionCode> {
                conditionCode
            };

            PatientData patientData = new PatientData {
                FirstName = "Jim"
            };

            DiagnosisCode diagnosisCode = new DiagnosisCode {
                Instance = "P", ClaimId = 123, IcddCode = "0800"
            };
            List <DiagnosisCode> diagnosisCodes = new List <DiagnosisCode> {
                diagnosisCode
            };

            ClaimCharge claimCharge = new ClaimCharge
            {
                Line    = 1,
                RevCode = "0123",
                Amount  = 5556.2,
            };

            // Act
            List <ClaimCharge> claimCharges = new List <ClaimCharge> {
                claimCharge
            };

            EvaluateableClaim evaluateableClaim = new EvaluateableClaim
            {
                ClaimId        = 123,
                StatementThru  = Convert.ToDateTime("2012-01-12 00:00:00.000"),
                StatementFrom  = Convert.ToDateTime("2012-01-12 00:00:00.000"),
                ConditionCodes = conditionCodes,
                PatientData    = patientData,
                DiagnosisCodes = diagnosisCodes,
                ClaimCharges   = claimCharges
            };

            List <EvaluateableClaim> evaluateableClaimLists = new List <EvaluateableClaim> {
                evaluateableClaim
            };

            List <EvaluateableClaim> actual = _target.UpdateEvaluateableClaims(evaluateableClaimLists);

            // Assert
            EvaluateableClaim updatedEvaluateableClaim = actual.FirstOrDefault();

            if (updatedEvaluateableClaim != null)
            {
                CRecord cRecord = updatedEvaluateableClaim.MicrodynApcEditInput.CRecord;
                if (cRecord != null)
                {
                    Assert.AreEqual(cRecord.PatientData, evaluateableClaim.PatientData);
                    Assert.AreNotEqual(cRecord.ClaimId, evaluateableClaim.ClaimId);
                }

                DRecord dRecord = updatedEvaluateableClaim.MicrodynApcEditInput.DRecord;
                if (dRecord != null)
                {
                    Assert.AreEqual(dRecord.PrincipalDiagnosisCode, evaluateableClaim.DiagnosisCodes.First().IcddCode);
                }

                LRecord lRecord = updatedEvaluateableClaim.MicrodynApcEditInput.LRecords.FirstOrDefault();
                if (lRecord != null)
                {
                    Assert.AreEqual(lRecord.RevenueCode, evaluateableClaim.ClaimCharges.First().RevCode);
                    Assert.AreEqual(lRecord.LineItemId, evaluateableClaim.ClaimCharges.First().Line);
                }

                MedicareOutPatient medicareOutPatient =
                    updatedEvaluateableClaim.MicrodynApcEditInput.MedicareOutPatientRecord;
                if (medicareOutPatient != null)
                {
                    Assert.AreEqual(medicareOutPatient.ClaimId, evaluateableClaim.ClaimId);
                    Assert.AreEqual(medicareOutPatient.BeneDeductible, 0);
                }
            }
        }