Beispiel #1
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);
        }