Exemplo n.º 1
0
        public void AddClaim(int claimID)
        {
            batch_claim_list bcl = new batch_claim_list();

            bcl.batch_id          = id;
            bcl.claim_id          = claimID;
            bcl.still_in_batch    = true;
            bcl["last_send_date"] = batch_date;
            bcl.Save();
        }
        public void AddClaim(int claimID)
        {
            batch_claim_list bcl = new batch_claim_list();

            DataTable dt = Search("SELECT * FROM batch_claim_list bcl WHERE bcl.claim_id = " + claimID + " AND bcl.batch_id = " + id);

            if (dt.Rows.Count > 0)
            {
                // Claim is already in batch
                bcl.Load(dt.Rows[0]);
            }
            else
            {
                // Adding claim to batch normally
                bcl.batch_id = id;
                bcl.claim_id = claimID;
            }

            bcl.still_in_batch    = true;
            bcl["last_send_date"] = batch_date;
            bcl.Save();
        }
        internal void AddClaim(string id1, string id2)
        {
            try
            {
                DataTable dtClaims = Search(string.Format("SELECT * FROM claims WHERE claimidnum = '{0}' AND claimdb = '{2}'", id1, id2));

                if (dtClaims.Rows.Count > 0)
                {
                    claim c = new claim();
                    c.Load(dtClaims.Rows[0]);
                    batch_claim_list bcl = new batch_claim_list();

                    DataTable dt = Search("SELECT * FROM batch_claim_list bcl WHERE bcl.claim_id = " + c.id + " AND bcl.batch_id = " + id);

                    if (dt.Rows.Count > 0)
                    {
                        // Claim is already in batch
                        bcl.Load(dt.Rows[0]);
                    }
                    else
                    {
                        // Adding claim to batch normally
                        bcl.batch_id = id;
                        bcl.claim_id = c.id;
                    }

                    bcl.still_in_batch    = true;
                    bcl["last_send_date"] = batch_date;
                    bcl.Save();
                }
            }
            catch (Exception err)
            {
                LoggingHelper.Log(err, false);
            }
        }
        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);
        }