Esempio n. 1
0
        private static Claim CreatePredetermination(Patient pat, List <Procedure> procList, long provTreat)
        {
            Family           fam           = Patients.GetFamily(pat.PatNum);
            List <InsSub>    subList       = InsSubs.RefreshForFam(fam);
            List <InsPlan>   planList      = InsPlans.RefreshForSubList(subList);
            List <PatPlan>   patPlanList   = PatPlans.Refresh(pat.PatNum);
            List <Benefit>   benefitList   = Benefits.Refresh(patPlanList, subList);
            List <ClaimProc> claimProcList = ClaimProcs.Refresh(pat.PatNum);
            List <Procedure> procsForPat   = Procedures.Refresh(pat.PatNum);
            InsSub           sub           = InsSubs.GetSub(PatPlans.GetInsSubNum(patPlanList, 1), subList);
            InsPlan          insPlan       = InsPlans.GetPlan(sub.PlanNum, planList);
            Claim            claim         = new Claim();

            Claims.Insert(claim);      //to retreive a key for new Claim.ClaimNum
            claim.PatNum      = pat.PatNum;
            claim.DateService = procList[0].ProcDate;
            claim.DateSent    = DateTime.Today;
            claim.ClaimStatus = "W";
            claim.InsSubNum   = PatPlans.GetInsSubNum(patPlanList, 1);
            claim.InsSubNum2  = PatPlans.GetInsSubNum(patPlanList, 2);
            InsSub sub1 = InsSubs.GetSub(claim.InsSubNum, subList);
            InsSub sub2 = InsSubs.GetSub(claim.InsSubNum, subList);

            claim.PlanNum       = sub1.PlanNum;
            claim.PlanNum2      = sub2.PlanNum;
            claim.PatRelat      = PatPlans.GetRelat(patPlanList, 1);
            claim.PatRelat2     = PatPlans.GetRelat(patPlanList, 2);
            claim.ClaimType     = "PreAuth";
            claim.ProvTreat     = provTreat;
            claim.IsProsthesis  = "N";
            claim.ProvBill      = Providers.GetBillingProvNum(claim.ProvTreat, 0);
            claim.EmployRelated = YN.No;
            ClaimProc        cp;
            List <Procedure> procListClaim = new List <Procedure>();  //this list will exclude lab fees

            for (int i = 0; i < procList.Count; i++)
            {
                if (procList[i].ProcNumLab == 0)
                {
                    procListClaim.Add(procList[i]);
                }
            }
            for (int i = 0; i < procListClaim.Count; i++)
            {
                cp = new ClaimProc();
                ClaimProcs.CreateEst(cp, procListClaim[i], insPlan, sub);
                cp.ClaimNum   = claim.ClaimNum;
                cp.Status     = ClaimProcStatus.NotReceived;
                cp.CodeSent   = ProcedureCodes.GetProcCode(procListClaim[i].CodeNum).ProcCode;
                cp.LineNumber = (byte)(i + 1);
                ClaimProcs.Update(cp);
            }
            claimProcList = ClaimProcs.Refresh(pat.PatNum);
            ClaimL.CalculateAndUpdate(procsForPat, planList, claim, patPlanList, benefitList, pat.Age, subList);
            return(claim);
        }
Esempio n. 2
0
        /// <summary>claimType="P","S","PreAuth","W" (waiting to send).</summary>
        public static Claim CreateClaim(string claimType, List <PatPlan> PatPlanList, List <InsPlan> InsPlanList, List <ClaimProc> ClaimProcList, List <Procedure> procsForPat, Patient pat, List <Procedure> procsForClaim, List <Benefit> benefitList, List <InsSub> SubList, bool calculateLineNumber = true)
        {
            //Claim ClaimCur=CreateClaim("P",PatPlanList,InsPlanList,ClaimProcList,procsForPat);
            InsPlan PlanCur1 = new InsPlan();
            InsSub  SubCur1  = new InsSub();
            InsPlan PlanCur2 = new InsPlan();
            InsSub  SubCur2  = new InsSub();

            switch (claimType)
            {
            case "P":
                SubCur1  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 1), SubList);
                PlanCur1 = InsPlans.GetPlan(SubCur1.PlanNum, InsPlanList);
                SubCur2  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 2), SubList);
                //PlanCur2=InsPlans.GetPlan(SubCur.PlanNum,InsPlanList);//can end up null
                break;

            case "S":
                SubCur1  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 2), SubList);
                PlanCur1 = InsPlans.GetPlan(SubCur1.PlanNum, InsPlanList);
                SubCur2  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 1), SubList);
                //PlanCur2=InsPlans.GetPlan(SubCur.PlanNum,InsPlanList);//can end up null
                break;

            case "PreAuth":
                SubCur1  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 1), SubList);
                PlanCur1 = InsPlans.GetPlan(SubCur1.PlanNum, InsPlanList);
                SubCur2  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 2), SubList);
                break;

            case "W":
                SubCur1  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 1), SubList);
                PlanCur1 = InsPlans.GetPlan(SubCur1.PlanNum, InsPlanList);
                SubCur2  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, 2), SubList);
                break;

            case "Med":
                SubCur1  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, PatPlans.GetOrdinal(PriSecMed.Medical, PatPlanList, InsPlanList, SubList)), SubList);
                PlanCur1 = InsPlans.GetPlan(SubCur1.PlanNum, InsPlanList);
                SubCur2  = InsSubs.GetSub(PatPlans.GetInsSubNum(PatPlanList, PatPlans.GetOrdinal(PriSecMed.Primary, PatPlanList, InsPlanList, SubList)), SubList);
                break;
            }
            //DataTable table=DataSetMain.Tables["account"];
            Procedure proc;

            //proc=Procedures.GetProcFromList(procsForPat,PIn.Long(table.Rows[gridAccount.SelectedIndices[0]]["ProcNum"].ToString()));
            //long clinicNum=proc.ClinicNum;
            ClaimProc[] claimProcs = new ClaimProc[procsForClaim.Count];          //1:1 with procs
            long        procNum;

            for (int i = 0; i < procsForClaim.Count; i++)       //loop through selected procs
            //and try to find an estimate that can be used
            {
                procNum       = procsForClaim[i].ProcNum;
                claimProcs[i] = Procedures.GetClaimProcEstimate(procNum, ClaimProcList, PlanCur1, SubCur1.InsSubNum);
            }
            for (int i = 0; i < claimProcs.Length; i++)       //loop through each claimProc
            //and create any missing estimates. This handles claims to 3rd and 4th ins co's.
            {
                if (claimProcs[i] == null)
                {
                    claimProcs[i] = new ClaimProc();
                    proc          = procsForClaim[i];
                    ClaimProcs.CreateEst(claimProcs[i], proc, PlanCur1, SubCur1);
                }
            }
            Claim claim = new Claim();

            Claims.Insert(claim);            //to retreive a key for new Claim.ClaimNum
            claim.PatNum        = pat.PatNum;
            claim.DateService   = claimProcs[claimProcs.Length - 1].ProcDate;
            claim.ClinicNum     = procsForClaim[0].ClinicNum;
            claim.DateSent      = DateTime.Today;
            claim.DateSentOrig  = claim.DateSent;
            claim.ClaimStatus   = "S";
            claim.AttachedFlags = "Mail";
            //datereceived
            switch (claimType)
            {
            case "P":
                claim.PlanNum    = SubCur1.PlanNum;
                claim.InsSubNum  = PatPlans.GetInsSubNum(PatPlanList, 1);
                claim.PatRelat   = PatPlans.GetRelat(PatPlanList, 1);
                claim.ClaimType  = "P";
                claim.PlanNum2   = SubCur2.PlanNum;                    //might be 0 if no sec ins
                claim.InsSubNum2 = PatPlans.GetInsSubNum(PatPlanList, 2);
                claim.PatRelat2  = PatPlans.GetRelat(PatPlanList, 2);
                break;

            case "S":
                claim.PlanNum    = SubCur1.PlanNum;
                claim.InsSubNum  = PatPlans.GetInsSubNum(PatPlanList, 2);
                claim.PatRelat   = PatPlans.GetRelat(PatPlanList, 2);
                claim.ClaimType  = "S";
                claim.PlanNum2   = SubCur2.PlanNum;
                claim.InsSubNum2 = PatPlans.GetInsSubNum(PatPlanList, 1);
                claim.PatRelat2  = PatPlans.GetRelat(PatPlanList, 1);
                break;

            case "W":
                claim.PlanNum     = SubCur1.PlanNum;
                claim.InsSubNum   = PatPlans.GetInsSubNum(PatPlanList, 2);
                claim.PatRelat    = PatPlans.GetRelat(PatPlanList, 2);
                claim.ClaimType   = "P";
                claim.ClaimStatus = "W";
                claim.PlanNum2    = SubCur2.PlanNum;
                claim.InsSubNum2  = PatPlans.GetInsSubNum(PatPlanList, 1);
                claim.PatRelat2   = PatPlans.GetRelat(PatPlanList, 1);
                break;

            case "Med":
                claim.PlanNum    = SubCur1.PlanNum;
                claim.InsSubNum  = PatPlans.GetInsSubNum(PatPlanList, 1);
                claim.PatRelat   = PatPlans.GetRelat(PatPlanList, 1);
                claim.ClaimType  = "Other";
                claim.PlanNum2   = SubCur2.PlanNum;                    //might be 0 if no other ins
                claim.InsSubNum2 = PatPlans.GetInsSubNum(PatPlanList, 2);
                claim.PatRelat2  = PatPlans.GetRelat(PatPlanList, 2);
                break;
            }
            claim.ProvTreat     = procsForClaim[0].ProvNum;
            claim.IsProsthesis  = "I";
            claim.ProvBill      = Providers.GetBillingProvNum(claim.ProvTreat, claim.ClinicNum);
            claim.EmployRelated = YN.No;
            //attach procedures
            Procedure ProcCur;

            for (int i = 0; i < claimProcs.Length; i++)
            {
                ProcCur = procsForClaim[i];
                claimProcs[i].ClaimNum = claim.ClaimNum;
                claimProcs[i].Status   = ClaimProcStatus.NotReceived;            //status for claims unsent or sent.
                //writeoff handled in ClaimL.CalculateAndUpdate()
                claimProcs[i].CodeSent = ProcedureCodes.GetProcCode(ProcCur.CodeNum).ProcCode;
                if (claimProcs[i].CodeSent.Length > 5 && claimProcs[i].CodeSent.Substring(0, 1) == "D")
                {
                    claimProcs[i].CodeSent = claimProcs[i].CodeSent.Substring(0, 5);
                }
                if (calculateLineNumber)
                {
                    claimProcs[i].LineNumber = (byte)(i + 1);
                }
                ClaimProcs.Update(claimProcs[i]);
            }
            ClaimProcList = ClaimProcs.Refresh(pat.PatNum);
            Claims.CalculateAndUpdate(procsForPat, InsPlanList, claim, PatPlanList, benefitList, pat.Age, SubList);
            return(claim);
        }
Esempio n. 3
0
        ///<summary>The insplan that's passed in need not be properly updated to the database first.</summary>
        public static void RequestBenefits(Clearinghouse clearhouse, InsPlan plan, long patNum, Carrier carrier, List <Benefit> benList, long patPlanNum, InsSub insSub)
        {
            Patient  pat      = Patients.GetPat(patNum);
            Patient  subsc    = Patients.GetPat(insSub.Subscriber);
            Clinic   clinic   = Clinics.GetClinic(pat.ClinicNum);
            Provider billProv = Providers.GetProv(Providers.GetBillingProvNum(pat.PriProv, pat.ClinicNum));
            //validation.  Throw exception if missing info----------------------------------------
            string validationResult = X270.Validate(clearhouse, carrier, billProv, clinic, plan, subsc, insSub);

            if (validationResult != "")
            {
                throw new Exception(Lan.g("FormInsPlan", "Please fix the following errors first:") + "\r\n" + validationResult);
            }
            //create a 270 message---------------------------------------------------------------
            string            x12message        = X270.GenerateMessageText(clearhouse, carrier, billProv, clinic, plan, subsc, insSub);
            EtransMessageText etransMessageText = new EtransMessageText();

            etransMessageText.MessageText = x12message;
            EtransMessageTexts.Insert(etransMessageText);
            //attach it to an etrans-------------------------------------------------------------
            Etrans etrans = new Etrans();

            etrans.DateTimeTrans        = DateTime.Now;
            etrans.ClearingHouseNum     = clearhouse.ClearinghouseNum;
            etrans.Etype                = EtransType.BenefitInquiry270;
            etrans.PlanNum              = plan.PlanNum;
            etrans.InsSubNum            = insSub.InsSubNum;
            etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans);
            //send the 270----------------------------------------------------------------------
            string x12response = "";

            //a connection error here needs to bubble up
            try {
                if (clearhouse.CommBridge == EclaimsCommBridge.ClaimConnect)
                {
                    x12response = ClaimConnect.Benefits270(clearhouse, x12message);
                }
            }
            catch (Exception ex) {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lan.g("FormInsPlan", "Connection Error:") + "\r\n" + ex.GetType().Name + "\r\n" + ex.Message);
            }
            //start to process the 271----------------------------------------------------------
            X271 x271 = null;

            if (X12object.IsX12(x12response))
            {
                X12object x12obj = new X12object(x12response);
                if (x12obj.Is271())
                {
                    x271 = new X271(x12response);
                }
            }
            else              //neither a 997 nor a 271
            {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lan.g("FormInsPlan", "Error:") + "\r\n" + x12response);
            }

            /*
             * //In realtime mode, X12 limits the request to one patient.
             * //We will always use the subscriber.
             * //So all EB segments are for the subscriber.
             * List<EB271> listEB=new List<EB271>();
             * EB271 eb;
             * if(x271 != null) {
             *      for(int i=0;i<x271.Segments.Count;i++) {
             *              if(x271.Segments[i].SegmentID != "EB") {
             *                      continue;
             *              }
             *              eb=new EB271(x271.Segments[i]);
             *              listEB.Add(eb);
             *      }
             * }*/
            //create an etrans for the 271------------------------------------------------------
            etransMessageText             = new EtransMessageText();
            etransMessageText.MessageText = x12response;
            EtransMessageTexts.Insert(etransMessageText);
            Etrans etrans271 = new Etrans();

            etrans271.DateTimeTrans    = DateTime.Now;
            etrans271.ClearingHouseNum = clearhouse.ClearinghouseNum;
            etrans271.Etype            = EtransType.TextReport;
            if (X12object.IsX12(x12response))             //this shouldn't need to be tested because it was tested above.
            {
                if (x271 == null)
                {
                    etrans271.Etype = EtransType.Acknowledge_997;
                }
                else
                {
                    etrans271.Etype = EtransType.BenefitResponse271;
                }
            }
            etrans271.PlanNum              = plan.PlanNum;
            etrans271.InsSubNum            = insSub.InsSubNum;
            etrans271.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans271);
            etrans.AckEtransNum = etrans271.EtransNum;
            if (etrans271.Etype == EtransType.Acknowledge_997)
            {
                X997   x997     = new X997(x12response);
                string error997 = x997.GetHumanReadable();
                etrans.Note = "Error: " + error997;            //"Malformed document sent.  997 error returned.";
                Etranss.Update(etrans);
                MessageBox.Show(etrans.Note);
                //CodeBase.MsgBoxCopyPaste msgbox=new CodeBase.MsgBoxCopyPaste(etrans.Note);
                //msgbox.ShowDialog();
                //don't show the 270 interface.
                return;
            }
            else
            {
                string processingerror = x271.GetProcessingError();
                if (processingerror != "")
                {
                    etrans.Note = processingerror;
                    Etranss.Update(etrans);
                    MessageBox.Show(etrans.Note);
                    //CodeBase.MsgBoxCopyPaste msgbox=new CodeBase.MsgBoxCopyPaste(etrans.Note);
                    //msgbox.ShowDialog();
                    //don't show the 270 interface.
                    return;
                }
                else
                {
                    etrans.Note = "Normal 271 response.";                  //change this later to be explanatory of content.
                }
            }
            Etranss.Update(etrans);
            //show the user a list of benefits to pick from for import--------------------------
            FormEtrans270Edit formE = new FormEtrans270Edit(patPlanNum, plan.PlanNum, insSub.InsSubNum);

            formE.EtransCur         = etrans;
            formE.IsInitialResponse = true;
            formE.benList           = benList;
            formE.ShowDialog();
        }
Esempio n. 4
0
        ///<summary>Throws exceptions. The insplan that's passed in need not be properly updated to the database first.</summary>
        ///<returns>The Etrans created from the request. Will be null if the request failed in any way.</returns>
        public static Etrans RequestBenefits(Clearinghouse clearinghouseClin, InsPlan plan, long patNum, Carrier carrier, InsSub insSub, out string error)
        {
            error = "";
            Patient  pat      = Patients.GetPat(patNum);
            Patient  subsc    = Patients.GetPat(insSub.Subscriber);
            Clinic   clinic   = Clinics.GetClinic(pat.ClinicNum);
            Provider billProv = Providers.GetProv(Providers.GetBillingProvNum(pat.PriProv, pat.ClinicNum));
            //validation.  Throw exception if missing info----------------------------------------
            string validationResult = X270.Validate(clearinghouseClin, carrier, billProv, clinic, plan, subsc, insSub, pat);

            if (validationResult != "")
            {
                throw new Exception(Lans.g("FormInsPlan", "Please fix the following errors first:") + "\r\n" + validationResult);
            }
            //create a 270 message---------------------------------------------------------------
            string            x12message        = X270.GenerateMessageText(clearinghouseClin, carrier, billProv, clinic, plan, subsc, insSub, pat);
            EtransMessageText etransMessageText = new EtransMessageText();

            etransMessageText.MessageText = x12message;
            EtransMessageTexts.Insert(etransMessageText);
            //attach it to an etrans-------------------------------------------------------------
            Etrans etrans = new Etrans();

            etrans.PatNum               = patNum;
            etrans.DateTimeTrans        = DateTime.Now;
            etrans.ClearingHouseNum     = clearinghouseClin.HqClearinghouseNum;
            etrans.Etype                = EtransType.BenefitInquiry270;
            etrans.PlanNum              = plan.PlanNum;
            etrans.InsSubNum            = insSub.InsSubNum;
            etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            Etranss.Insert(etrans);
            //send the 270----------------------------------------------------------------------
            string x12response = "";
            Etrans etransHtml  = null;

            //a connection error here needs to bubble up
            try {
                if (!String.IsNullOrWhiteSpace(FakeResponseOverride271))
                {
                    x12response = FakeResponseOverride271;
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.ClaimConnect)
                {
                    x12response = ClaimConnect.Benefits270(clearinghouseClin, x12message);
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.EDS)
                {
                    x12response = EDS.Benefits270(clearinghouseClin, x12message, out etransHtml);
                }
                else if (clearinghouseClin.CommBridge == EclaimsCommBridge.WebMD)
                {
                    x12response = WebMD.Benefits270(clearinghouseClin, x12message);
                }
            }
            catch (Exception ex) {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lans.g("FormInsPlan", "Connection Error:") + "\r\n" + ex.GetType().Name + "\r\n" + ex.Message);
            }
            //start to process the 271----------------------------------------------------------
            X271 x271 = null;

            if (X12object.IsX12(x12response))
            {
                X12object x12obj = new X12object(x12response);
                if (x12obj.Is271())
                {
                    x271 = new X271(x12response);
                }
            }
            else              //not a 997, 999, 277 or 271
            {
                EtransMessageTexts.Delete(etrans.EtransMessageTextNum);
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(Lans.g("FormInsPlan", "Error:") + "\r\n" + x12response);
            }

            /*
             * //In realtime mode, X12 limits the request to one patient.
             * //We will always use the subscriber.
             * //So all EB segments are for the subscriber.
             * List<EB271> listEB=new List<EB271>();
             * EB271 eb;
             * if(x271 != null) {
             *      for(int i=0;i<x271.Segments.Count;i++) {
             *              if(x271.Segments[i].SegmentID != "EB") {
             *                      continue;
             *              }
             *              eb=new EB271(x271.Segments[i]);
             *              listEB.Add(eb);
             *      }
             * }*/
            //create an etrans for the 271------------------------------------------------------
            etransMessageText             = new EtransMessageText();
            etransMessageText.MessageText = x12response;
            EtransMessageTexts.Insert(etransMessageText);
            Etrans etrans271 = new Etrans();

            etrans271.PatNum           = patNum;
            etrans271.DateTimeTrans    = DateTime.Now;
            etrans271.ClearingHouseNum = clearinghouseClin.HqClearinghouseNum;
            etrans271.Etype            = EtransType.TextReport;
            if (X12object.IsX12(x12response))             //this shouldn't need to be tested because it was tested above.
            {
                if (x271 == null)
                {
                    X12object Xobj = new X12object(x12response);
                    if (Xobj.Is997())
                    {
                        etrans271.Etype = EtransType.Acknowledge_997;
                    }
                    else if (Xobj.Is999())
                    {
                        etrans271.Etype = EtransType.Acknowledge_999;
                    }
                    else if (X277.Is277(Xobj))
                    {
                        etrans271.Etype = EtransType.StatusNotify_277;
                    }
                    else if (X835.Is835(Xobj))
                    {
                        etrans271.Etype = EtransType.ERA_835;
                    }
                    else if (Xobj.IsAckInterchange())
                    {
                        etrans271.Etype = EtransType.Ack_Interchange;
                    }
                }
                else
                {
                    etrans271.Etype = EtransType.BenefitResponse271;
                }
            }
            etrans271.PlanNum              = plan.PlanNum;
            etrans271.InsSubNum            = insSub.InsSubNum;
            etrans271.EtransMessageTextNum = etransMessageText.EtransMessageTextNum;
            etrans271.MessageText          = etransMessageText.MessageText; //Not a DB column, used to save queries for some calling methods (OpenDentalService).
            if (etransHtml != null)
            {
                etrans271.AckEtransNum = etransHtml.EtransNum;
            }
            Etranss.Insert(etrans271);
            etrans.AckEtransNum = etrans271.EtransNum;
            etrans.AckEtrans    = etrans271;       //Not a DB column, used to save queries for some calling methods (OpenDentalService).
            if (etrans271.Etype == EtransType.Acknowledge_997)
            {
                X997   x997     = new X997(x12response);
                string error997 = x997.GetHumanReadable();
                etrans.Note = "Error: " + error997;            //"Malformed document sent.  997 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.Acknowledge_999)
            {
                X999   x999     = new X999(x12response);
                string error999 = x999.GetHumanReadable();
                etrans.Note = "Error: " + error999;            //"Malformed document sent.  999 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.StatusNotify_277)
            {
                X277   x277     = new X277(x12response);
                string error277 = x277.GetHumanReadable();
                etrans.Note = "Error: " + error277;            //"Malformed document sent.  277 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.ERA_835)
            {
                X835   x835     = new X835(etrans271, x12response, "");
                string error835 = x835.GetHumanReadable();
                etrans.Note = "Error: " + error835;            //"Malformed document sent.  835 error returned.";
                Etranss.Update(etrans);
                error = etrans.Note;
                return(null);
            }
            else if (etrans271.Etype == EtransType.BenefitResponse271)            //271
            {
                string processingerror = x271.GetProcessingError();
                if (processingerror != "")
                {
                    etrans.Note = processingerror;
                    Etranss.Update(etrans);
                    error = etrans.Note;
                    return(null);
                }
                else
                {
                    etrans.Note = "Normal 271 response.";                  //change this later to be explanatory of content.
                }
            }
            else if (etrans271.Etype == EtransType.Ack_Interchange)           //See document "X092 Elig 270-271.pdf" pages 388 and 401.
            {
                X12object  xobj   = new X12object(x12response);
                X12Segment segTa1 = xobj.GetNextSegmentById(0, "TA1");
                if (segTa1.Get(4) == "A")
                {
                    etrans.Note = "The request was accepted, but the response is empty.";
                }
                else
                {
                    if (segTa1.Get(4) == "E")
                    {
                        etrans.Note = "The request was accepted with errors: ";
                    }
                    else if (segTa1.Get(4) == "R")
                    {
                        etrans.Note = "The request was rejected with errors: ";
                    }
                    switch (segTa1.Get(5))
                    {
                    case "000": etrans.Note += "No error"; break;

                    case "001": etrans.Note += "The Interchange Control Number in the Header and Trailer Do Not Match. "
                                               + "The Value From the Header is Used in the Acknowledgment."; break;

                    case "002": etrans.Note += "This Standard as Noted in the Control Standards Identifier is Not Supported."; break;

                    case "003": etrans.Note += "This Version of the Controls is Not Supported"; break;

                    case "004": etrans.Note += "The Segment Terminator is Invalid"; break;

                    case "005": etrans.Note += "Invalid Interchange ID Qualifier for Sender"; break;

                    case "006": etrans.Note += "Invalid Interchange Sender ID"; break;

                    case "007": etrans.Note += "Invalid Interchange ID Qualifier for Receiver"; break;

                    case "008": etrans.Note += "Invalid Interchange Receiver ID"; break;

                    case "009": etrans.Note += "Unknown Interchange Receiver ID"; break;

                    case "010": etrans.Note += "Invalid Authorization Information Qualifier Value"; break;

                    case "011": etrans.Note += "Invalid Authorization Information Value"; break;

                    case "012": etrans.Note += "Invalid Security Information Qualifier Value"; break;

                    case "013": etrans.Note += "Invalid Security Information Value"; break;

                    case "014": etrans.Note += "Invalid Interchange Date Value"; break;

                    case "015": etrans.Note += "Invalid Interchange Time Value"; break;

                    case "016": etrans.Note += "Invalid Interchange Standards Identifier Value"; break;

                    case "017": etrans.Note += "Invalid Interchange Version ID Value"; break;

                    case "018": etrans.Note += "Invalid Interchange Control Number Value"; break;

                    case "019": etrans.Note += "Invalid Acknowledgment Requested Value"; break;

                    case "020": etrans.Note += "Invalid Test Indicator Value"; break;

                    case "021": etrans.Note += "Invalid Number of Included Groups Value"; break;

                    case "022": etrans.Note += "Invalid Control Structure"; break;

                    case "023": etrans.Note += "Improper (Premature) End-of-File (Transmission)"; break;

                    case "024": etrans.Note += "Invalid Interchange Content (e.g., Invalid GS Segment)"; break;

                    case "025": etrans.Note += "Duplicate Interchange Control Number"; break;

                    case "026": etrans.Note += "Invalid Data Element Separator"; break;

                    case "027": etrans.Note += "Invalid Component Element Separator"; break;

                    case "028": etrans.Note += "Invalid Delivery Date in Deferred Delivery Request"; break;

                    case "029": etrans.Note += "Invalid Delivery Time in Deferred Delivery Request"; break;

                    case "030": etrans.Note += "Invalid Delivery Time Code in Deferred Delivery Request"; break;

                    case "031": etrans.Note += "Invalid Grade of Service Code"; break;
                    }
                }
            }
            else
            {
                throw new Exception("Unknown response");
            }
            Etranss.Update(etrans);
            return(etrans);
        }
Esempio n. 5
0
        ///<summary>The result is a string which can be dropped into the insplan.BenefitNotes.  Or it might throw an exception if invalid data.  This class is also responsible for saving the returned message to the etrans table and printing out the required form.</summary>
        public static string SendElegibility(string electID, int patNum, string groupNumber, string divisionNo,
                                             string subscriberID, string patID, Relat patRelat, int subscNum, string dentaideCardSequence)
        {
            //Note: This might be the only class of this kind that returns a string.  It's a special situation.
            //We are simply not going to bother with language translation here.
            //determine carrier.
            Carrier carrier = Carriers.GetCanadian(electID);          //this also happens to validate missing or short value

            if (carrier == null)
            {
                throw new ApplicationException("Invalid carrier EDI code.");
            }
            Clearinghouse clearhouse = Canadian.GetClearinghouse();

            if (clearhouse == null)
            {
                throw new ApplicationException("Canadian clearinghouse not found.");
            }
            string saveFolder = clearhouse.ExportPath;

            if (!Directory.Exists(saveFolder))
            {
                throw new ApplicationException(saveFolder + " not found.");
            }
            //Initialize objects-----------------------------------------------------------------------------------------------
            Patient  patient    = Patients.GetPat(patNum);
            Patient  subscriber = Patients.GetPat(subscNum);
            Provider treatProv  = Providers.GetProv(Patients.GetProvNum(patient));
            Provider billProv   = Providers.GetProv(Providers.GetBillingProvNum(treatProv.ProvNum));
            //I had to use a dialog box to get the eligibility code.

            //validate any missing info----------------------------------------------------------------------------------
            string error = "";

            if (carrier.CanadianNetworkNum == 0)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Carrier does not have network specified";
            }
            if (!Regex.IsMatch(carrier.ElectID, @"^[0-9]{6}$"))           //not necessary, but nice
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "CarrierId 6 digits";
            }
            if (treatProv.NationalProvID.Length != 9)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "TreatingProv CDA num 9 digits";
            }
            if (treatProv.CanadianOfficeNum.Length != 4)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "TreatingProv office num 4 char";
            }
            if (billProv.NationalProvID.Length != 9)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "BillingProv CDA num 9 digits";
            }
            if (groupNumber.Length == 0 || groupNumber.Length > 12 || groupNumber.Contains(" "))
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Plan Number";
            }
            if (subscriberID == "")
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "SubscriberID";
            }
            if (patNum != subscNum && patRelat == Relat.Self)           //if patient is not subscriber, and relat is self
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Relationship cannot be self";
            }
            if (patient.Gender == PatientGender.Unknown)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Patient gender";
            }
            if (patient.Birthdate.Year < 1880 || patient.Birthdate > DateTime.Today)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Patient birthdate";
            }
            if (patient.LName == "")
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Patient lastname";
            }
            if (patient.FName == "")
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Patient firstname";
            }
            if (subscriber.Birthdate.Year < 1880 || subscriber.Birthdate > DateTime.Today)
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Subscriber birthdate";
            }
            if (subscriber.LName == "")
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Subscriber lastname";
            }
            if (subscriber.FName == "")
            {
                if (error != "")
                {
                    error += ", ";
                }
                error += "Subscriber firstname";
            }
            if (error != "")
            {
                throw new ApplicationException(error);
            }
            FormCanadianEligibility FormElig = new FormCanadianEligibility();

            FormElig.ShowDialog();
            if (FormElig.DialogResult != DialogResult.OK)
            {
                throw new ApplicationException("Eligibility Code or Date missing.");
            }
            //eligiblity code guaranteed to not be 0 at this point.  Also date will be between 1980 and 10 years from now.
            Etrans etrans = Etranss.CreateCanadianOutput(patNum, carrier.CarrierNum, carrier.CanadianNetworkNum,
                                                         clearhouse.ClearinghouseNum, EtransType.Eligibility_CA);
            string txt = "";

            //create message----------------------------------------------------------------------------------------------
            //A01 transaction prefix 12 AN
//todo
            txt += "123456789012";          //To be later provided by the individual network.
            //A02 office sequence number 6 N
            txt += Canadian.TidyN(etrans.OfficeSequenceNumber, 6);
            //A03 format version number 2 N
            txt += "04";
            //A04 transaction code 2 N
            txt += "08";            //eligibility
            //A05 carrier id number 6 N
            txt += carrier.ElectID; //already validated as 6 digit number.
            //A06 software system id 3 AN  The third character is for version of OD.
//todo
            txt += "OD1";          //To be later supplied by CDAnet staff to uniquely identify OD.
            //A10 encryption method 1 N
//todo
            txt += "1";
            //A07 message length 5 N
            int len = 214;

//todo does not account for C19. Possibly 30 more.
            //if(C19 is used, Plan Record){
            //len+=30;
            //}
            txt += Canadian.TidyN(len, 5);
            //A09 carrier transaction counter 5 N
            txt += Canadian.TidyN(etrans.CarrierTransCounter, 5);
            //B01 CDA provider number 9 AN
            txt += Canadian.TidyAN(treatProv.NationalProvID, 9);         //already validated
            //B02 (treating) provider office number 4 AN
            txt += Canadian.TidyAN(treatProv.CanadianOfficeNum, 4);      //already validated
            //B03 billing provider number 9 AN
//todo, need to account for possible 5 digit prov id assigned by carrier
            txt += Canadian.TidyAN(billProv.NationalProvID, 9);         //already validated
            //C01 primary policy/plan number 12 AN (group number)
            //only validated to ensure that it's not blank and is less than 12. Also that no spaces.
            txt += Canadian.TidyAN(groupNumber, 12);
            //C11 primary division/section number 10 AN
            txt += Canadian.TidyAN(divisionNo, 10);
            //C02 subscriber id number 12 AN
            txt += Canadian.TidyAN(subscriberID.Replace("-", ""), 12);        //validated
            //C17 primary dependant code 2 N. Optional
            txt += Canadian.TidyN(patID, 2);
            //C03 relationship code 1 N
            //User interface does not only show Canadian options, but all options are handled.
            txt += Canadian.GetRelationshipCode(patRelat);
            //C04 patient's sex 1 A
            //validated to not include "unknown"
            if (patient.Gender == PatientGender.Male)
            {
                txt += "M";
            }
            else
            {
                txt += "F";
            }
            //C05 patient birthday 8 N
            txt += patient.Birthdate.ToString("yyyyMMdd");          //validated
            //C06 patient last name 25 AE
            txt += Canadian.TidyAE(patient.LName, 25, true);        //validated
            //C07 patient first name 15 AE
            txt += Canadian.TidyAE(patient.FName, 15, true);        //validated
            //C08 patient middle initial 1 AE
            txt += Canadian.TidyAE(patient.MiddleI, 1);
            //C09 eligibility exception code 1 N
            txt += Canadian.TidyN(FormElig.EligibilityCode, 1);         //validated
            //C12 plan flag 1 A
//todo
            //might not be carrier.IsPMP.  Might have to do with plan, not carrier. See F17.
            txt += " ";
            //C18 plan record count 1 N
//todo
            txt += "0";
            //C16 Eligibility date. 8 N.
            txt += FormElig.AsOfDate.ToString("yyyyMMdd");          //validated
            //D01 subscriber birthday 8 N
            txt += subscriber.Birthdate.ToString("yyyyMMdd");       //validated
            //D02 subscriber last name 25 AE
            txt += Canadian.TidyAE(subscriber.LName, 25, true);     //validated
            //D03 subscriber first name 15 AE
            txt += Canadian.TidyAE(subscriber.FName, 15, true);     //validated
            //D04 subscriber middle initial 1 AE
            txt += Canadian.TidyAE(subscriber.MiddleI, 1);
            //D10 language of insured 1 A
            if (subscriber.Language == "fr")
            {
                txt += "F";
            }
            else
            {
                txt += "E";
            }
            //D11 card sequence/version number 2 N
//todo: Not validated against type of carrier yet.  Need to check if Dentaide.
            txt += Canadian.TidyN(dentaideCardSequence, 2);
//todo If C18=1, then the following field would appear
            //C19 plan record 30 AN
            string result = "";

            try {
                result = Canadian.PassToCCD(txt, carrier.CanadianNetworkNum, clearhouse);
            }
            catch (ApplicationException ex) {
                Etranss.Delete(etrans.EtransNum);
                throw new ApplicationException(ex.Message);
            }
            Etranss.SetMessage(etrans.EtransNum, txt);
            etrans.MessageText = txt;
            FormCCDPrint FormP = new FormCCDPrint(etrans);          //Print the form.

            FormP.ShowDialog();
            //Now we will process the 'result' here to extract the important data.  Basically Yes or No on the eligibility.
            //We might not do this for any other trans type besides eligibility.
            string           retVal        = "Eligibility check on " + DateTime.Today.ToShortDateString() + "\r\n";
            CCDFieldInputter fieldInputter = new CCDFieldInputter(result);
            CCDField         field         = fieldInputter.GetFieldById("G05");//response status

            //CCDFieldInputter could really use a GetValue(string fieldId) method so I don't have to use a field object.
            switch (field.valuestr)
            {
            case "E":
                retVal += "Patient is eligible.";
                break;

            case "R":
                retVal += "Patient not eligible, or error in data.";
                break;

            case "M":
                retVal += "Manual claimform should be submitted for employer certified plan.";
                break;
            }
            CCDField[] fields = fieldInputter.GetFieldsById("G08");          //Error Codes
            for (int i = 0; i < fields.Length; i++)
            {
                retVal += "\r\n";
                retVal += fields[i].valuestr;              //todo: need to turn this into a readable string.
            }
            fields = fieldInputter.GetFieldsById("G32");   //Display messages
            for (int i = 0; i < fields.Length; i++)
            {
                retVal += "\r\n";
                retVal += fields[i].valuestr;
            }
            return(retVal);
        }