private void phoneValue(post_physician mark)
        {
            if (!string.IsNullOrEmpty(mark.primary_phone) & mark.primary_phone.Length > 10)
            {
                mark.primary_phone = mark.primary_phone.Substring(0, 10);
            }

            if (!string.IsNullOrEmpty(mark.financial_phone) & mark.financial_phone.Length > 10)
            {
                mark.financial_phone = mark.financial_phone.Substring(0, 10);
            }
            if (!string.IsNullOrEmpty(mark.operational_phone) & mark.operational_phone.Length > 10)
            {
                mark.operational_phone = mark.operational_phone.Substring(0, 10);
            }
            if (!string.IsNullOrEmpty(mark.primary_contact_phone) & mark.primary_contact_phone.Length > 10)
            {
                mark.primary_contact_phone = mark.primary_contact_phone.Substring(0, 10);
            }
            if (!string.IsNullOrEmpty(mark.authorize_signatory_phone) & mark.authorize_signatory_phone.Length > 10)
            {
                mark.authorize_signatory_phone = mark.authorize_signatory_phone.Substring(0, 10);
                //return Json(new { data = new string[] { }, message = "Phone numbe", success = false });
            }

            //return Json(new { data = new string[] { }, message = "Phone numbe", success = false });
        }
        private long savePhysician_User(post_physician m)
        {
            var  u_find = db.USERs.Where(a => a.username == m.authorize_signatory_email.ToLower());
            USER u      = new USER
            {
                name_first           = m.authorize_signatory_name_first,
                name_last            = m.authorize_signatory_name_last,
                username             = m.authorize_signatory_email,
                dt_create            = dt,
                create_by__USER_id   = 0,
                rel_ref_USER_type_id = 12
            };

            db.USERs.Add(u);
            db.SaveChanges();

            return(u.id);
        }
        public IHttpActionResult postPhysician([FromBody] post_physician p)
        {
            try
            {
                Is_Required("legal_entity_name", p.legal_entity_name, 1);
                Is_Required("healthsplash_contact", p.healthsplash_contact, 1);
                Is_Required("practice_type", p.practice_type, 1);
                Is_Required("address1", p.address1, 1);
                Is_Required("city", p.city, 1);
                Is_Required("state", p.state, 1);
                Is_Required("zip", p.zip, 1);

                Is_Required("federal_tax_number", p.federal_tax_number, 1);
                Is_Required("primary_phone", p.primary_phone, 1);

                Is_Required("customer_service_number", p.customer_service_number, 1);
                Is_Required("number_clinicians", p.number_clinicians.ToString(), 1);
                Is_Required("number_exams_per_week", p.number_exams_per_week.ToString(), 1);
                Is_Required("practice_npi", p.practice_npi, 1);
                Is_Required("geographic_market", p.geographic_market, 1);
                Is_Required("insurance_providers", p.insurance_providers, 1);
                Is_Required("EMR_software_used", p.EMR_software_used, 1);

                Is_Required("primary_contact_name_first", p.primary_contact_name_first, 1);
                Is_Required("primary_contact_name_last", p.primary_contact_name_last, 1);
                Is_Required("primary_contacty_phone", p.primary_contact_phone, 1);
                Is_Required("primary_contact_email", p.primary_contact_email, 1);

                //Is_Required("operational_name_first", p.operational_name_first, 1);
                //Is_Required("operational_name_last", p.operational_name_last, 1);
                //Is_Required("operational_phone", p.operational_phone, 1);
                //Is_Required("operational_email", p.operational_email, 1);

                Is_Required("financial_name_first", p.financial_name_first, 1);
                Is_Required("financial_name_last", p.financial_name_last, 1);
                Is_Required("financial_phone", p.financial_phone, 1);
                Is_Required("financial_email", p.financial_email, 1);

                Is_Required("authorize_signatory_name_first", p.authorize_signatory_name_first, 1);
                Is_Required("authorize_signatory_name_last", p.authorize_signatory_name_last, 1);
                Is_Required("authorize_signatory_phone", p.authorize_signatory_phone, 1);
                Is_Required("authorize_signatory_email", p.authorize_signatory_email, 1);

                if (HAS_ERROR)
                {
                    return(Json(new { data = new string[] { }, message = ERR_MSG, success = false }));
                }


                long a = validateZip(p);
                if (a == 1)
                {
                    return(Json(new { data = new string[] { }, message = "Invalid zip value.", success = false }));
                }
                else if (a == 2)
                {
                    return(Json(new { data = new string[] { }, message = "Invalid city value.", success = false }));
                }
                else if (a == 3)
                {
                    return(Json(new { data = new string[] { }, message = "Invalid state value.", success = false }));
                }

                var u_search = db.USERs.Where(b => b.username == p.authorize_signatory_email.ToLower());
                if (u_search.Count() > 0)
                {
                    return(Json(new { data = new string[] { }, message = "Authorized email already exist.", success = false }));
                }

                return(_savePhysician(p));

                //mark.fax_number = "";
                // mark.process_external_transfer
                // mark.intake_entity
                // mark.technology_platform
                //mark.pharmacy_relationship
                //mark.unique_customer_number
                //mark.pharmacy_fax
                //mark.preferred_geographic_market
            }
            catch (Exception ex)
            {
                return(Json(new { data = new string[] { }, message = ex.Message, success = false }));
            }
        }
        private IHttpActionResult _savePhysician(post_physician m)
        {
            phoneValue(m);
            if (m.practice_npi.Length > 10)
            {
                m.practice_npi = m.practice_npi.Substring(0, 10);
            }

            PHYSICIAN mrk = new PHYSICIAN
            {
                legal_entity_name    = m.legal_entity_name,
                healthsplash_contact = m.healthsplash_contact,
                // addr_zip_id
                addr_address1           = m.address1,
                addr_address2           = string.IsNullOrEmpty(m.address2) == true ? null : m.address2,
                addr_zip_id             = m.zip_id,
                federal_tax_number      = m.federal_tax_number,
                primary_phone           = m.primary_phone,
                customer_service_number = m.customer_service_number,
                number_clinicians       = m.number_clinicians,
                number_exams_per_week   = m.number_exams_per_week,
                practice_npi            = m.practice_npi,
                geographic_market       = m.geographic_market,
                insurance_providers     = m.insurance_providers,
                EMR_software_used       = m.EMR_software_used,
                practice_type           = m.practice_type,

                prim_contact_name_first = m.primary_contact_name_first,
                prim_contact_name_last  = m.primary_contact_name_last,
                prim_contact_email      = m.primary_contact_email,
                prim_contact_phone      = m.primary_phone,

                oper_contact_name_first = m.operational_name_first,
                oper_contact_name_last  = m.operational_name_last,
                oper_contact_email      = m.operational_email,
                oper_contact_phone      = m.operational_phone,

                fina_contact_name_first = m.financial_name_first,
                fina_contact_name_last  = m.financial_name_last,
                fina_contact_email      = m.financial_email,
                fina_contact_phone      = m.financial_phone,

                auth_contact_name_first = m.authorize_signatory_name_first,
                auth_contact_name_last  = m.authorize_signatory_name_last,
                auth_contact_email      = m.authorize_signatory_email,
                auth_contact_phone      = m.authorize_signatory_phone
            };

            db.PHYSICIANs.Add(mrk);
            db.SaveChanges();

            long user_id = savePhysician_User(m);

            //bool saveMarketer_ext(string _attr_name, string _dname, string _value, long market_id = 0, long user_id = 0, int data_type = 0)


            //mark.fax_number = "";
            if (!string.IsNullOrEmpty(m.fax_number))
            {
                bool i = Entry.savePhysician_ext("fax_number", "fax_number", m.fax_number, mrk.id, 0, 0);
            }

            //mark.future_expansion = "";
            if (!string.IsNullOrEmpty(m.future_expansion))
            {
                bool i = Entry.savePhysician_ext("future_expansion", "future_expansion", m.future_expansion, mrk.id, 0, 0);
            }

            //mark.current_scheduling_solution = "";
            if (!string.IsNullOrEmpty(m.current_scheduling_solution))
            {
                bool i = Entry.savePhysician_ext("current_scheduling_solution", "current_scheduling_solution", m.current_scheduling_solution, mrk.id, 0, 0);
            }


            return(Json(new { data = new string[] { }, message = "Successfully saved.", success = true }));
        }