Exemplo n.º 1
0
        private static claim_batch GetDailyBatch(clsClaimEnums.SentMethods batchSendMethod, string batchInfo, string serverName = "")
        {
            claim_batch toReturn = new claim_batch();

            DataTable matches = toReturn.Search("SELECT * FROM claim_batch WHERE handling = '" + batchSendMethod + "' AND " +
                                                "DateDiff(batch_date, NOW()) = 0");

            if (matches.Rows.Count > 0)
            {
                toReturn.Load(matches.Rows[0]);
            }
            else
            {
                toReturn.handling   = batchSendMethod;
                toReturn.batch_date = DateTime.Now;
                toReturn.source     = 0;
                toReturn.batch_info = batchInfo;
                if (serverName == string.Empty)
                {
                    toReturn.server_name = C_DentalClaimTracker.General.RegistryData.LocalComputerName;
                }
                else
                {
                    toReturn.server_name = serverName;
                }
                toReturn.Save();
            }

            return(toReturn);
        }
        internal static claim_batch NewMercuryBatch()
        {
            claim_batch toReturn = new claim_batch();

            toReturn.batch_date  = DateTime.Now;
            toReturn.batch_info  = "Mercury Batch";
            toReturn.handling    = clsClaimEnums.SentMethods.Mercury;
            toReturn.source      = 0;
            toReturn.server_name = C_DentalClaimTracker.General.RegistryData.LocalComputerName;
            toReturn.Save();
            return(toReturn);
        }
        private void mnuSyncWithEclaims_Click(object sender, EventArgs e)
        {
            data_mapping_schema dms;
            SqlConnection       dbConnection;

            try
            {
                dms = new data_mapping_schema();
                dms.Load(3);
                dbConnection = new SqlConnection(dms.GetConnectionString(false));
                dbConnection.Open();
            }
            catch
            {
                MessageBox.Show(this, "Could not open connection to Dentrix database.", "Could not connect");
                return;
            }

            try
            {
                // Remove all batches with a source of external, then pull them all back in
                claim_batch toDelete = new claim_batch();

                toDelete.ExecuteNonQuery("DELETE claim_batch, batch_claim_list FROM claim_batch " +
                                         " LEFT JOIN batch_claim_list ON claim_batch.id = batch_claim_list.batch_id WHERE source = 1");
                // Got rid of the existing external stuff, now pull in the stuff from the last few months
                // NHDG_CLAIM_BATCHES - CLAIMBATCHID, BATCH_DATE, HANDLING ("Paper", "Electronic (ApexEDI)"
                // NHDG_CLAIM_TRANSACTIONS - CLAIM_ID, CLAIM_DB, CLAIMBATCHID, RESUBMIT_FLAG (char?), BATCH_RESUBMITTED

                Dictionary <string, int> batchIDData = new Dictionary <string, int>(); // Update this as I iterate through claim batches, we'll grab all the items for valid
                // bacthes in a 2nd sql statement
                string batchIDList = "";

                SqlCommand command = new SqlCommand("SELECT * FROM NHDG_CLAIM_BATCHES cb " +
                                                    "WHERE DATEDIFF(\"dd\", cb.BATCH_DATE, GETDATE()) < 200", dbConnection);

                SqlDataReader reader = command.ExecuteReader();


                while (reader.Read())
                {
                    claim_batch cb = new claim_batch();

                    cb.batch_date = (DateTime)reader["batch_date"];
                    cb.handling   = ConvertHandlingFromDentrix(reader["handling"].ToString());
                    cb.batch_info = "Imported from Eclaims";
                    cb["source"]  = 1;
                    cb.Save();
                    batchIDData.Add(reader["claimbatchid"].ToString(), cb.id);
                }

                reader.Close();
                if (batchIDData.Count > 0)
                {
                    foreach (KeyValuePair <string, int> kvp in batchIDData)
                    {
                        batchIDList += kvp.Key + ",";
                    }
                    batchIDList = batchIDList.TrimEnd(",".ToCharArray());
                    //Clipboard.SetText(batchIDList);
                    //MessageBox.Show("Here's my batchid list (it's in the clipboard): " + batchIDList);

                    string searchSQL = "SELECT * FROM NHDG_CLAIM_TRANSACTIONS WHERE CLAIMBATCHID IN (" + batchIDList +
                                       ")";
                    command = new SqlCommand(searchSQL, dbConnection);

                    //Clipboard.SetText(searchSQL);
                    //MessageBox.Show("And here's the search sql: " + searchSQL);
                    reader = command.ExecuteReader();
                    string bigMessageBox = "";
                    int    foundCount    = 0;
                    while (reader.Read())
                    {
                        int claimID = FindClaim(reader["claim_id"].ToString(), reader["claim_db"].ToString());

                        bigMessageBox += reader["claim_id"].ToString() + " | ";

                        if (claimID > 0)
                        {
                            batch_claim_list bcl = new batch_claim_list();
                            claim_batch      cb  = new claim_batch(batchIDData[reader["claimbatchid"].ToString()]);
                            bcl.batch_id          = cb.id;
                            bcl.claim_id          = claimID;
                            bcl.still_in_batch    = reader["resubmit_flag"].ToString() != "Y";
                            bcl["last_send_date"] = cb.batch_date;
                            bcl.Save();

                            foundCount++;
                        }
                    }

                    //MessageBox.Show("Here are the claimIDs that were searched for. ( " + foundCount + " were found.)\n" + bigMessageBox);
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(this, "An unexpected error occurred syncing data.\n\n" + ex.Message);
            }

            MessageBox.Show(this, "Sync successful!", "Sync with Eclaims", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }