示例#1
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);
        }
示例#2
0
        ///<summary>Supply a list of ClaimSendQueueItems.  Called from FormClaimSend.  Can only send to one clearinghouse at a time.
        ///The queueItems must contain at least one item.  Each item in queueItems must have the same ClinicNum.  Cannot include Canadian.</summary>
        public static void SendBatch(Clearinghouse clearinghouseClin, List <ClaimSendQueueItem> queueItems, EnumClaimMedType medType,
                                     IFormClaimFormItemEdit formClaimFormItemEdit, Renaissance.FillRenaissanceDelegate fillRenaissance, ITerminalConnector terminalConnector)
        {
            string messageText = "";

            if (clearinghouseClin.Eformat == ElectronicClaimFormat.Canadian)
            {
                MessageBox.Show(Lans.g("Eclaims", "Cannot send Canadian claims as part of Eclaims.SendBatch."));
                return;
            }
            //get next batch number for this clearinghouse
            int batchNum = Clearinghouses.GetNextBatchNumber(clearinghouseClin);

            //---------------------------------------------------------------------------------------
            //Create the claim file for this clearinghouse
            if (clearinghouseClin.Eformat == ElectronicClaimFormat.x837D_4010 ||
                clearinghouseClin.Eformat == ElectronicClaimFormat.x837D_5010_dental ||
                clearinghouseClin.Eformat == ElectronicClaimFormat.x837_5010_med_inst)
            {
                messageText = x837Controller.SendBatch(clearinghouseClin, queueItems, batchNum, medType, false);
            }
            else if (clearinghouseClin.Eformat == ElectronicClaimFormat.Renaissance)
            {
                messageText = Renaissance.SendBatch(clearinghouseClin, queueItems, batchNum, formClaimFormItemEdit, fillRenaissance);
            }
            else if (clearinghouseClin.Eformat == ElectronicClaimFormat.Dutch)
            {
                messageText = Dutch.SendBatch(clearinghouseClin, queueItems, batchNum);
            }
            else if (clearinghouseClin.Eformat == ElectronicClaimFormat.Ramq)
            {
                messageText = Ramq.SendBatch(clearinghouseClin, queueItems, batchNum);
            }
            else
            {
                messageText = "";      //(ElectronicClaimFormat.None does not get sent)
            }
            if (messageText == "")     //if failed to create claim file properly,
            {
                return;                //don't launch program or change claim status
            }
            //----------------------------------------------------------------------------------------
            //Launch Client Program for this clearinghouse if applicable
            if (clearinghouseClin.CommBridge == EclaimsCommBridge.None)
            {
                AttemptLaunch(clearinghouseClin, batchNum);
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.WebMD)
            {
                if (!WebMD.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + WebMD.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.BCBSGA)
            {
                if (!BCBSGA.Launch(clearinghouseClin, batchNum, terminalConnector))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + BCBSGA.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.Renaissance)
            {
                AttemptLaunch(clearinghouseClin, batchNum);
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.ClaimConnect)
            {
                if (ClaimConnect.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show("Upload successful.");
                }
                else
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + ClaimConnect.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.RECS)
            {
                if (!RECS.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Claim file created, but could not launch RECS client.") + "\r\n" + RECS.ErrorMessage);
                    //continue;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.Inmediata)
            {
                if (!Inmediata.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Claim file created, but could not launch Inmediata client.") + "\r\n" + Inmediata.ErrorMessage);
                    //continue;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.AOS)           // added by SPK 7/13/05
            {
                if (!AOS.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Claim file created, but could not launch AOS Communicator.") + "\r\n" + AOS.ErrorMessage);
                    //continue;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.PostnTrack)
            {
                AttemptLaunch(clearinghouseClin, batchNum);
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.MercuryDE)
            {
                if (!MercuryDE.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + MercuryDE.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.ClaimX)
            {
                if (!ClaimX.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Claim file created, but encountered an error while launching ClaimX Client.") + ":\r\n" + ClaimX.ErrorMessage);
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.EmdeonMedical)
            {
                if (!EmdeonMedical.Launch(clearinghouseClin, batchNum, medType))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + EmdeonMedical.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.DentiCal)
            {
                if (!DentiCal.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + DentiCal.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.NHS)
            {
                if (!NHS.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + NHS.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.EDS)
            {
                if (!EDS.Launch(clearinghouseClin, messageText))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + "\r\n" + EDS.ErrorMessage);
                    return;
                }
            }
            else if (clearinghouseClin.CommBridge == EclaimsCommBridge.Ramq)
            {
                if (!Ramq.Launch(clearinghouseClin, batchNum))
                {
                    MessageBox.Show(Lans.g("Eclaims", "Error sending.") + Ramq.ErrorMessage);
                    return;
                }
            }
            //----------------------------------------------------------------------------------------
            //finally, mark the claims sent. (only if not Canadian)
            EtransType etype = EtransType.ClaimSent;

            if (clearinghouseClin.Eformat == ElectronicClaimFormat.Renaissance)
            {
                etype = EtransType.Claim_Ren;
            }
            //Canadians cannot send in batches (see above).  RAMQ is performing a similar algorithm but the steps are in a different order in Ramq.cs.
            if (clearinghouseClin.Eformat != ElectronicClaimFormat.Canadian && clearinghouseClin.Eformat != ElectronicClaimFormat.Ramq)
            {
                //Create the etransmessagetext that all claims in the batch will point to.
                EtransMessageText etransMsgText = new EtransMessageText();
                etransMsgText.MessageText = messageText;
                EtransMessageTexts.Insert(etransMsgText);
                for (int j = 0; j < queueItems.Count; j++)
                {
                    Etrans etrans = Etranss.SetClaimSentOrPrinted(queueItems[j].ClaimNum, queueItems[j].PatNum,
                                                                  clearinghouseClin.HqClearinghouseNum, etype, batchNum, Security.CurUser.UserNum);
                    etrans.EtransMessageTextNum = etransMsgText.EtransMessageTextNum;
                    Etranss.Update(etrans);
                    //Now we need to update our cache of claims to reflect the change that took place in the database above in Etranss.SetClaimSentOrPrinted()
                    queueItems[j].ClaimStatus = "S";
                }
            }
        }