예제 #1
0
        //表单提交
        public ActionResult AddAndUpdate()
        {
            string id             = CommonFunc.SafeGetStringFromObj(Request.QueryString["id"]);
            string worker         = CommonFunc.SafeGetStringFromObj(Request.QueryString["worker"]);
            string community_code = CommonFunc.SafeGetStringFromObj(Request.QueryString["community_code"]);
            string txtCardNumber  = CommonFunc.SafeGetStringFromObj(Request["txtCardNumber"]);
            string re_id          = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == txtCardNumber).Select(t => t.id).FirstOrDefault());

            Comm_ResidentFile entity = new Comm_ResidentFile();

            if (string.IsNullOrEmpty(re_id))
            {
                entity.id       = Guid.NewGuid().ToString();
                entity.password = "******";

                entity.worker_user_name = worker;
                entity.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
            }
            else
            {
                entity.id       = re_id;
                entity.password = "******";

                entity.worker_user_name = worker;
                entity.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
                //entity.community_code =CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(u => u.resident_id == CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == txtCardNumber).Select(t=>t.resident_id).FirstOrDefault())).Select(t=>t.community_code).FirstOrDefault());
            }
            //根据身份证号查询个人信息表中是否存在此人信息,如果存在,则使用个人信息中的健康档案号,如果不存在,则创建一个新的17位的健康档案号
            string residentId = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == txtCardNumber).Select(t => t.resident_id).FirstOrDefault());

            if (string.IsNullOrEmpty(residentId))
            {
                entity.resident_id = residentFileService.GetNumberByCode1(Request["ddlCommunity"]);
            }
            else
            {
                entity.resident_id = residentId;
            }
            entity.resident_name           = Request["txtResidentName"];
            entity.sex                     = Request["rdlSex"];
            entity.birth_date              = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtBirthDate"]));
            entity.id_card_number          = Request["txtCardNumber"];
            entity.nationality_name        = "中国";
            entity.nation                  = Request["ddlNation"];
            entity.marital_status          = Request["ddlMarrigeState"];
            entity.education_qualification = Request["ddlEducationQualification"];
            entity.abo_blood_group         = Request["ddlABOBloodType"];
            entity.post_code               = Request["zipCode"];
            if (string.IsNullOrEmpty(Request["txtFamilyPhone1"]) || string.IsNullOrEmpty(Request["txtFamilyPhone2"]))
            {
                entity.family_phone = Request["txtFamilyPhone1"] + "-" + Request["txtFamilyPhone2"];
            }
            entity.individual_phone        = Request["txtIndividualPhone"];
            entity.email                   = Request["txtEmail"];
            entity.contact_name            = Request["txtcontact_name"];
            entity.contact_phone           = Request["txtcontact_phone"];
            entity.contact_my_relationship = Request["ddlcontact_my_relationship"];
            entity.work_unit               = Request["txtWorkUnit"];
            entity.work_type               = Request["ddlcraft"];
            entity.worker_time_everyweek   = Request["work_time"];
            entity.cost_method_payment     = Request["ddlCostPayment"];
            entity.chronic_disease_type    = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            //出生地址
            if (!Request["ddlCounty1"].Equals(""))
            {
                entity.birth_commitcode = Request["ddlCounty1"];
            }
            else
            {
                if (!Request["ddlCity1"].Equals(""))
                {
                    entity.birth_commitcode = Request["ddlCity1"];
                }
                else
                {
                    if (!Request["ddlProvince1"].Equals(""))
                    {
                        entity.birth_commitcode = Request["ddlProvince1"];
                    }
                }
            }
            entity.birth_address = Request["birth_address"];


            //常住地址
            entity.community_code         = Request["ddlCommunity"];
            entity.permanent_home_address = Request["home_address"];


            //现住地址
            if (!Request["ddlCommunity2"].Equals(""))
            {
                entity.residence_commitcode = Request["ddlCommunity2"];
            }
            else
            {
                if (!Request["ddlStreet2"].Equals(""))
                {
                    entity.residence_commitcode = Request["ddlStreet2"];
                }
                else
                {
                    if (!Request["ddlCounty2"].Equals(""))
                    {
                        entity.residence_commitcode = Request["ddlCounty2"];
                    }
                    else
                    {
                        if (!Request["ddlCity2"].Equals(""))
                        {
                            entity.residence_commitcode = Request["ddlCity2"];
                        }
                        else
                        {
                            if (!Request["ddlProvince2"].Equals(""))
                            {
                                entity.residence_commitcode = Request["ddlProvince2"];
                            }
                        }
                    }
                }
            }
            entity.residence_address = Request["huji_address"];

            entity.father_name         = Request["fatherName"];
            entity.father_id_card_numb = Request["fatherIdCard"];
            entity.father_phone        = Request["fatherPhone"];
            entity.father_email        = Request["father_email"];
            entity.mother_name         = Request["motherName"];
            entity.mother_id_card_numb = Request["motherIdCard"];
            entity.mother_phone        = Request["motherPhone"];
            entity.mother_email        = Request["mother_email"];
            entity.tumour_flag         = "TRUE";
            entity.fill_community_code = community_code;

            //-----------------------------------------病史信息--------------------------------------------
            //1.药物过敏史
            if (!string.IsNullOrEmpty(Request["chGuoMin"]) || !string.IsNullOrEmpty(Request["GuoMin_Other"]))
            {
                entity.drug_allergy_type  = Request["chGuoMin"].Replace(",", "$");
                entity.drug_allergy_other = Request["GuoMin_Other"];
            }
            else
            {
                entity.drug_allergy_type = "无";
            }
            //2.疾病史
            Comm_ResidentFile_Followup_Disease entity1 = new Comm_ResidentFile_Followup_Disease();
            //获取id
            string id1 = CommonFunc.SafeGetStringFromObj(residentFileFollowupDiseaseService.LoadEntityAsNoTracking(t => t.resident_id == entity1.resident_id).Select(t => t.id).FirstOrDefault());

            if (!string.IsNullOrEmpty(Request["chdisease"]) || !string.IsNullOrEmpty(Request["Disease_Other"]))
            {
                entity.disease = "";
                if (string.IsNullOrEmpty(id1))
                {
                    entity1.id = Guid.NewGuid().ToString();
                }
                else
                {
                    entity1.id = id1;
                }
                entity1.resident_id      = entity.resident_id;
                entity1.community_code   = entity.community_code;
                entity1.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                entity1.worker_user_name = worker;
                entity1.disease_type     = Request["chdisease"];
                entity1.disease_other    = Request["Disease_Other"];
                entity1.tumor_type       = Request["zl"];

                if (string.IsNullOrEmpty(id1))
                {
                    residentFileFollowupDiseaseService.AddEntity(entity1);
                }
                else
                {
                    residentFileFollowupDiseaseService.UpdateEntity(entity1);
                }
            }
            else
            {
                entity.disease = "无";
            }

            //5.手术史
            List <Comm_ResidentFile_Followup_Surgery> subjectiveList = new List <Comm_ResidentFile_Followup_Surgery>();

            if (!string.IsNullOrEmpty(Request["option_time0"]) || !string.IsNullOrEmpty(Request["option_name0"]))
            {
                entity.surgery = "";
                for (int i = 0; i < 50; i++)
                {
                    if (!string.IsNullOrEmpty(Request["option_name" + i]))
                    {
                        Comm_ResidentFile_Followup_Surgery entity4 = new Comm_ResidentFile_Followup_Surgery();
                        entity4.id               = Guid.NewGuid().ToString();
                        entity4.resident_id      = entity.resident_id;
                        entity4.community_code   = entity.community_code;
                        entity4.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                        entity4.worker_user_name = worker;
                        if (string.IsNullOrEmpty(Request["option_time" + i]))
                        {
                            entity4.find_date = null;
                        }
                        else
                        {
                            entity4.find_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["option_time" + i]));
                        }
                        entity4.surgery_name     = Request["option_name" + i];
                        entity4.surgery_hospital = Request["option_hospital" + i];
                        entity4.surgery_result   = Request["option_result" + i];
                        subjectiveList.Add(entity4);
                    }
                }
            }
            else
            {
                entity.surgery = "无";
            }
            //6.外伤史
            List <Comm_ResidentFile_Followup_Trauma> subjectiveList1 = new List <Comm_ResidentFile_Followup_Trauma>();

            if (!string.IsNullOrEmpty(Request["trauma_time0"]) || !string.IsNullOrEmpty(Request["trauma_name0"]))
            {
                entity.trauma = "";
                for (int i = 0; i < 50; i++)
                {
                    if (!string.IsNullOrEmpty(Request["trauma_name" + i]))
                    {
                        Comm_ResidentFile_Followup_Trauma entity5 = new Comm_ResidentFile_Followup_Trauma();
                        entity5.id               = Guid.NewGuid().ToString();
                        entity5.resident_id      = entity.resident_id;
                        entity5.community_code   = entity.community_code;
                        entity5.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                        entity5.worker_user_name = worker;
                        //entity5.find_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["trauma_time" + i]));
                        if (string.IsNullOrEmpty(Request["trauma_time" + i]))
                        {
                            entity5.find_date = null;
                        }
                        else
                        {
                            entity5.find_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["trauma_time" + i]));
                        }
                        entity5.trauma_name     = Request["trauma_name" + i];
                        entity5.trauma_hospital = Request["deal_hospital" + i];
                        entity5.trauma_result   = Request["deal_result" + i];
                        subjectiveList1.Add(entity5);
                    }
                }
            }
            else
            {
                entity.trauma = "无";
            }

            //7.输血史
            List <Comm_ResidentFile_Followup_Blood_Transfusion> subjectiveList2 = new List <Comm_ResidentFile_Followup_Blood_Transfusion>();

            if (!string.IsNullOrEmpty(Request["blood_transfusion_time0"]) || !string.IsNullOrEmpty(Request["blood_transfusion_name0"]))
            {
                entity.blood_transfusion = "";
                for (int i = 0; i < 50; i++)
                {
                    if (!string.IsNullOrEmpty(Request["blood_transfusion_name" + i]))
                    {
                        Comm_ResidentFile_Followup_Blood_Transfusion entity6 = new Comm_ResidentFile_Followup_Blood_Transfusion();
                        entity6.id               = Guid.NewGuid().ToString();
                        entity6.resident_id      = entity.resident_id;
                        entity6.community_code   = entity.community_code;
                        entity6.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                        entity6.worker_user_name = worker;
                        //entity6.find_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["blood_transfusion_time" + i]));
                        if (string.IsNullOrEmpty(Request["blood_transfusion_time" + i]))
                        {
                            entity6.find_date = null;
                        }
                        else
                        {
                            entity6.find_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["blood_transfusion_time" + i]));
                        }
                        entity6.blood_transfusion_reason = Request["blood_transfusion_name" + i];
                        entity6.blood_amount             = Request["blood_transfusion_amount" + i];
                        entity6.blood_result             = Request["blood_transfusion_result" + i];
                        subjectiveList2.Add(entity6);
                    }
                }
            }
            else
            {
                entity.blood_transfusion = "无";
            }

            //8.家族遗传史
            List <Comm_ResidentFile_Followup_Family_Disease> subjectiveList3 = new List <Comm_ResidentFile_Followup_Family_Disease>();

            if (!string.IsNullOrEmpty(Request["relationship0"]) || !string.IsNullOrEmpty(Request["chfamilydisease0"]) || !string.IsNullOrEmpty(Request["family_other_disease0"]))
            {
                entity.family_disease = "";
                for (int i = 0; i < 4; i++)
                {
                    if (!string.IsNullOrEmpty(Request["relationship" + i]))
                    {
                        Comm_ResidentFile_Followup_Family_Disease entity7 = new Comm_ResidentFile_Followup_Family_Disease();
                        entity7.id                   = Guid.NewGuid().ToString();
                        entity7.resident_id          = entity.resident_id;
                        entity7.community_code       = entity.community_code;
                        entity7.create_time          = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                        entity7.worker_user_name     = worker;
                        entity7.relationship_host    = Request["relationship" + i];
                        entity7.family_disease_type  = Request["chfamilydisease" + i];
                        entity7.family_disease_other = Request["family_other_disease" + i];
                        subjectiveList3.Add(entity7);
                    }
                }
            }
            else
            {
                entity.family_disease = "无";
            }
            //10.残疾情况
            if (!string.IsNullOrEmpty(Request["chdisability"]) || !string.IsNullOrEmpty(Request["disability_other"]))
            {
                entity.disability_type  = Request["chdisability"].Replace(",", "$");
                entity.disability_other = Request["disability_other"];
                //entity.Disability_certificate_number = Request["disability_numb"];
            }
            else
            {
                entity.disability_type = "无";
            }
            //--------------------吸烟与饮酒------------------------
            Chronic_disease_SmokeAndDrink entity2 = new Chronic_disease_SmokeAndDrink();
            //获取id
            string id2 = CommonFunc.SafeGetStringFromObj(smokeAndDrinkService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id2))
            {
                entity2.id          = Guid.NewGuid().ToString();
                entity2.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
            }
            else
            {
                entity2.id          = id2;
                entity2.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
            }
            entity2.name           = entity.resident_name;
            entity2.sex            = entity.sex;
            entity2.id_card_number = entity.id_card_number;
            entity2.birth_date     = entity.birth_date;
            // entity2.permanent_home_commitcode = entity.permanent_home_commitcode;
            entity2.resident_id       = entity.resident_id;
            entity2.permanent_address = entity.permanent_home_address;
            entity2.post_code         = entity.post_code;
            entity2.community_code    = entity.community_code;
            //-----吸烟----
            entity2.smoking = Request["smoking"];

            if (!string.IsNullOrEmpty(Request["times1"]))
            {
                entity2.smoking_begin_year = Request["times1"];
            }
            else
            {
                entity2.smoking_begin_year = "";
            }

            entity2.smoking_daily_amount = Request["day_smoke"];
            if (!string.IsNullOrEmpty(Request["smoke_age"]))
            {
                entity2.smoking_age = Request["smoke_age"].Split('年')[0];
            }
            else
            {
                entity2.smoking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked"]))
            {
                entity2.smoked = Request["smoked"];
            }
            else
            {
                entity2.smoked = "";
            }

            if (!string.IsNullOrEmpty(Request["times2"]))
            {
                entity2.smoked_begin_year = Request["times2"];
            }
            else
            {
                entity2.smoked_begin_year = "";
            }

            if (!string.IsNullOrEmpty(Request["times3"]))
            {
                entity2.smoked_smoking_again = Request["times3"];
            }
            else
            {
                entity2.smoked_smoking_again = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked_long"]))
            {
                entity2.smoked_long_time = Request["smoked_long"].Split('年')[0];
            }
            else
            {
                entity2.smoked_long_time = "";
            }
            entity2.smoked_intent      = Request["smoked_idea"];
            entity2.smoked_second_hand = Request["smoke_twice"];
            entity2.smoke_never        = Request["smoke"];

            //-----饮酒-----
            entity2.drinking = Request["drinking"];

            if (!string.IsNullOrEmpty(Request["times4"]))
            {
                entity2.drinking_begin_year = Request["times4"];
            }
            else
            {
                entity2.drinking_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["drink_age"]))
            {
                entity2.drinking_age = Request["drink_age"].Split('年')[0];
            }
            else
            {
                entity2.drinking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["times5"]))
            {
                entity2.drunk_begin_year = Request["times5"];
            }
            else
            {
                entity2.drunk_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["times6"]))
            {
                entity2.drunk_drinking_again = Request["times6"];
            }
            else
            {
                entity2.drunk_drinking_again = "";
            }


            if (!string.IsNullOrEmpty(Request["drunk_long"]))
            {
                entity2.drunk_long_time = Request["drunk_long"].Split('年')[0];
            }
            else
            {
                entity2.drunk_long_time = "";
            }
            entity2.drink_never = Request["drink"];
            //-----饮酒频率-----
            entity2.drinking_spirit_frequency = Request["frequency1"];
            entity2.drinking_beer_frequency   = Request["frequency2"];
            entity2.drinking_red_frequency    = Request["frequency3"];
            entity2.drinking_yellow_frequency = Request["frequency4"];
            entity2.drinking_other_wine1      = Request["other"];
            entity2.drinking_other_degree1    = Request["other_du"];
            entity2.drinking_other_frequency  = Request["frequency5"];


            entity2.drinking_spirit_amount = Request["count1"];
            entity2.drinking_beer_amount   = Request["count2"];
            entity2.drinking_red_amount    = Request["count3"];
            entity2.drinking_yellow_amount = Request["count4"];
            entity2.drinking_other_wine2   = Request["other_wine"];
            entity2.drinking_other_degree2 = Request["wine_degree"];
            entity2.drinking_other_amount  = Request["count5"];

            entity2.drinking_spirit_equivalent = Request["count1_dl"];
            entity2.drinking_beer_equivalent   = Request["count2_dl"];
            entity2.drinking_red_equivalent    = Request["count3_dl"];
            entity2.drinking_yellow_equivalent = Request["count4_dl"];
            entity2.drinking_other_equivalent  = Request["count5_dl"];

            entity2.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            entity2.worker_user_name = worker;
            entity2.create_time      = entity.create_time;
            if (string.IsNullOrEmpty(id2))
            {
                smokeAndDrinkService.AddEntity(entity2);
            }
            else
            {
                smokeAndDrinkService.UpdateEntity(entity2);
            }

            //进入恶性肿瘤信息表中
            Comm_Tumour tm = new Comm_Tumour();

            /*
             * 首先根据id,查找个人信息的resident_id,
             * 根据此resident_id到高血压信息表中找此人的id,
             * 如果没有,则新增,否则修改
             */
            if (string.IsNullOrEmpty(id))
            {
                tm.id = Guid.NewGuid().ToString();
                tm.responsible_physician = worker;
                tm.worker_user_name      = worker;
                tm.community_code        = entity.community_code;
                tm.resident_id           = entity.resident_id;
                tm.tumour_type           = Request["zl"];
                tm.last_followup_date    = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
                tm.create_time           = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
            }
            else
            {
                tm.id = id;
                tm.responsible_physician = worker;
                tm.worker_user_name      = worker;
                tm.community_code        = entity.community_code;
                tm.resident_id           = entity.resident_id;
                tm.tumour_type           = Request["zl"];
                tm.last_followup_date    = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
                tm.create_time           = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtCreateTime"]));
            }
            tm.id_card_number         = Request["txtCardNumber"];
            tm.resident_name          = Request["txtResidentName"];
            tm.permanent_home_address = Request["home_address"];
            tm.birth_date             = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["txtBirthDate"]));
            if (string.IsNullOrEmpty(id))
            {
                tumourService.AddEntity(tm);
            }
            else
            {
                tumourService.UpdateEntity(tm);
            }

            #region

            /*
             * 根据身份证号查询个人信息表中是否存在此人信息,存在获取行政区划代码,与现在填写的常住地址作比较,不相同则将其添加到Comm_ResidentFile_Change_Address表中
             */

            string code = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == txtCardNumber).Select(t => t.community_code).FirstOrDefault());

            if (!Request["ddlCommunity"].Equals(code))
            {
                Comm_ResidentFile_Change_Address address = new Comm_ResidentFile_Change_Address();
                address.id                  = Guid.NewGuid().ToString();
                address.contact_id          = entity.id;
                address.resident_id         = entity.resident_id;
                address.community_code      = code;
                address.fill_community_code = community_code;
                address.fill_person         = worker;
                address.permanent_address   = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == txtCardNumber).Select(t => t.permanent_home_address).FirstOrDefault());
                address.create_time         = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));

                changeAddressService.AddEntity(address);
            }

            #endregion

            string msg = "";
            if (string.IsNullOrEmpty(re_id))
            {
                if (residentFileService.AddEntity(entity) && residentFileFollowupSurgeryService.UpdateSubjective(subjectiveList, entity.resident_id) && residentFileFollowupTraumaService.UpdateSubjective(subjectiveList1, entity.resident_id) && residentFileFollowupBloodTransfusionService.UpdateSubjective(subjectiveList2, entity.resident_id) && residentFileFollowupFamilyDiseaseService.UpdateSubjective(subjectiveList3, entity.resident_id))
                {
                    #region 添加摘要

                    Comm_EHR_Abstract ehr = new Comm_EHR_Abstract();
                    ehr.id             = Guid.NewGuid().ToString();
                    ehr.resident_id    = entity.resident_id;
                    ehr.community_code = entity.community_code;
                    ehr.create_time    = CommonFunc.SafeGetDateTimeFromObj(DateTime.Now.ToString("yyyy-MM-dd"));
                    ehr.item_id        = entity.id;
                    ehr.item_type      = Model.Enum.EHRAbstractTypeEnum.ResidentInfo.ToString();


                    if (string.IsNullOrEmpty(re_id))//添加数据
                    {
                        eHRAbstractService.AddEntity(ehr);
                    }
                    else
                    {
                        eHRAbstractService.UpdateEntity(ehr);
                    }

                    #endregion
                    msg = "提交成功";
                }
                else
                {
                    msg = "提交失败";
                }
            }
            else
            {
                Boolean b = false;
                b = eHRAbstractService.IsExitsOneByResidentIdAndItemType(entity.resident_id, "ResidentInfo");

                if (!b)
                {
                    #region 添加摘要
                    Comm_EHR_Abstract ehr = new Comm_EHR_Abstract();
                    ehr.id             = Guid.NewGuid().ToString();
                    ehr.resident_id    = entity.resident_id;
                    ehr.community_code = entity.community_code;
                    ehr.create_time    = CommonFunc.SafeGetDateTimeFromObj(DateTime.Now);
                    ehr.item_id        = entity.id;
                    ehr.item_type      = Model.Enum.EHRAbstractTypeEnum.ResidentInfo.ToString();
                    eHRAbstractService.AddEntity(ehr);
                    #endregion
                }

                if (residentFileService.UpdateEntity(entity) && residentFileFollowupSurgeryService.UpdateSubjective(subjectiveList, entity.resident_id) && residentFileFollowupTraumaService.UpdateSubjective(subjectiveList1, entity.resident_id) && residentFileFollowupBloodTransfusionService.UpdateSubjective(subjectiveList2, entity.resident_id) && residentFileFollowupFamilyDiseaseService.UpdateSubjective(subjectiveList3, entity.resident_id))
                {
                    msg = "修改成功";
                }
            }

            return(Content(msg + "," + entity.resident_id));
        }
예제 #2
0
        //新增或修改
        public ActionResult AddAndUpdate()
        {
            string id             = CommonFunc.SafeGetStringFromObj(Request.QueryString["id"]);
            string community_code = CommonFunc.SafeGetStringFromObj(Request.QueryString["community_code"]);
            string worker         = CommonFunc.SafeGetStringFromObj(Request.QueryString["worker"]);
            string real_name      = CommonFunc.SafeGetStringFromObj(Request.QueryString["real_name"]);
            MT_Comm_Adults_Health_Examination_New entity = new MT_Comm_Adults_Health_Examination_New();

            if (string.IsNullOrEmpty(id))
            {
                entity.id          = Guid.NewGuid().ToString();
                entity.create_time = entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            else
            {
                entity.id          = id;
                entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            entity.name           = Request["name"];
            entity.sex            = Request["sex"];
            entity.age            = Request["age"];
            entity.id_card_number = Request["id_card_number"];
            string s = Request["id_card_number"];
            string s1 = "", s2 = "", s3 = "";

            if (s.Length == 15)
            {
                s1 = s.Substring(6, 2);
                s2 = s.Substring(8, 2);
                s3 = s.Substring(10, 2);
                entity.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj("19" + s1 + "-" + s2 + "-" + s3));
            }
            else if (s.Length == 18)
            {
                s1 = s.Substring(6, 4);
                s2 = s.Substring(10, 2);
                s3 = s.Substring(12, 2);
                entity.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(s1 + "-" + s2 + "-" + s3));
            }
            //根据身份证号查询个人信息表中是否存在此人信息,如果存在,则使用个人信息中的健康档案号,如果不存在,则创建一个新的17位的健康档案号
            string id_card_number = CommonFunc.SafeGetStringFromObj(Request["id_card_number"]);
            string ddlCommunity   = CommonFunc.SafeGetStringFromObj(Request["ddlCommunity"]);

            entity.zipcode = Request["zipCode"];
            string residentId = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.resident_id).FirstOrDefault());

            if (string.IsNullOrEmpty(residentId))
            {
                entity.resident_id = residentFileService.GetNumberByCode1(ddlCommunity);
            }
            else
            {
                entity.resident_id = residentId;
            }
            entity.community_code       = Request["ddlCommunity"];
            entity.address              = Request["perment_community_address"];
            entity.worker_user_name     = worker;
            entity.worker_user_realname = real_name;

            entity.tijianriqi = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["time"]));
            entity.company    = Request["company"];



            entity.ybzk_tiwen       = Request["t"];
            entity.ybzk_mailv       = Request["p"];
            entity.ybzk_huxipinglv  = Request["r"];
            entity.ybzk_xueya_h     = Request["ssy"];
            entity.ybzk_xueya_l     = Request["szy"];
            entity.ybzk_shenggao    = Request["height"];
            entity.ybzk_tizhong     = Request["weight"];
            entity.ybzk_tizhizhishu = Request["bmi"];
            entity.ybzk_yaowei      = Request["w"];
            entity.ybzk_tunwei      = Request["h"];
            entity.ybzk_yaotunweibi = Request["w_h"];

            //判断个人信息表中是否存在此人信息 2015-06-18 娄帅
            var dt = residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number);

            Comm_ResidentFile resident = new Comm_ResidentFile();

            resident.id = CommonFunc.SafeGetStringFromObj(dt.Select(t => t.id).FirstOrDefault());

            resident.resident_id            = entity.resident_id;
            resident.resident_name          = Request["name"];
            resident.sex                    = Request["sex"];
            resident.id_card_number         = Request["id_card_number"];
            resident.birth_date             = entity.birth_date;
            resident.community_code         = Request["ddlCommunity"];
            resident.individual_phone       = Request["phone"];
            resident.permanent_home_address = Request["perment_community_address"];
            resident.nationality_name       = "中国";
            resident.nationality_code       = "156";

            //1.药物过敏史
            if (!string.IsNullOrEmpty(Request["chGuoMin"]) || !string.IsNullOrEmpty(Request["GuoMin_Other"]))
            {
                resident.drug_allergy_type  = Request["chGuoMin"];
                resident.drug_allergy_other = Request["GuoMin_Other"];
            }
            else
            {
                resident.drug_allergy_type = "无";
            }

            resident.work_unit             = Request["txtWorkUnit"];
            resident.work_type             = Request["ddlcraft"];
            resident.worker_time_everyweek = Request["work_time"];
            //10.残疾情况
            if (!string.IsNullOrEmpty(Request["chdisability"]) || !string.IsNullOrEmpty(Request["disability_other"]))
            {
                resident.disability_type  = Request["chdisability"];
                resident.disability_other = Request["disability_other"];
            }

            if (dt.Count() < 1)
            {
                resident.id             = Guid.NewGuid().ToString();
                resident.community_code = Request["ddlCommunity"];
                if (entity.create_time == null)
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(DateTime.Now.ToString("yyyy-MM-dd"));
                }
                else
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(entity.create_time);
                }

                resident.worker_user_name = worker;

                residentFileService.AddEntity(resident);

                // 添加摘要

                Comm_EHR_Abstract ehr1 = new Comm_EHR_Abstract();
                ehr1.id             = Guid.NewGuid().ToString();
                ehr1.resident_id    = entity.resident_id;
                ehr1.community_code = entity.community_code;
                ehr1.create_time    = DateTime.Now;
                ehr1.item_id        = resident.id;
                ehr1.item_type      = Model.Enum.EHRAbstractTypeEnum.ResidentInfo.ToString();

                eHRAbstractService.AddEntity(ehr1);
            }
            else
            {
                /** 根据身份证号查询个人信息表中是否存在此人信息,存在获取行政区划代码,与现在填写的常住地址作比较,不相同则将其添加到Comm_ResidentFile_Change_Address表中
                 */

                string code = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.community_code).FirstOrDefault());

                if (Request["ddlCommunity"] != code)
                {
                    Comm_ResidentFile_Change_Address address = new Comm_ResidentFile_Change_Address();
                    address.id                  = Guid.NewGuid().ToString();
                    address.contact_id          = entity.id;
                    address.resident_id         = entity.resident_id;
                    address.community_code      = code;
                    address.fill_community_code = community_code;
                    address.fill_person         = worker;
                    address.permanent_address   = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.permanent_home_address).FirstOrDefault());
                    address.create_time         = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));

                    residentFileChangeAddressService.AddEntity(address);
                }
                //resident.id = dt.Select(t=>t.id).ToString();
                string[] propertyName = new string[] { "resident_name", "sex", "id_card_number", "community_code", "individual_phone", "permanent_home_address" };
                residentFileService.UpdatePartialPropertity(resident, propertyName);
            }

            //======================病史信息=====================
            Comm_ResidentFile_Followup_Disease entity1 = new Comm_ResidentFile_Followup_Disease();
            //获取id
            string id1 = CommonFunc.SafeGetStringFromObj(comm_ResidentFile_Followup_DiseaseService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (!string.IsNullOrEmpty(Request["chdisease"]) || !string.IsNullOrEmpty(Request["Disease_Other"]))
            {
                if (string.IsNullOrEmpty(id1))
                {
                    entity1.id = Guid.NewGuid().ToString();
                }
                else
                {
                    entity1.id = id1;
                }
                entity1.resident_id      = entity.resident_id;
                entity1.community_code   = entity.community_code;
                entity1.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
                entity1.worker_user_name = worker;
                entity1.disease_type     = Request["chdisease"];
                entity1.disease_other    = Request["Disease_Other"];
                entity1.tumor_type       = Request["zl"];

                if (string.IsNullOrEmpty(id1))
                {
                    comm_ResidentFile_Followup_DiseaseService.AddEntity(entity1);
                }
                else
                {
                    comm_ResidentFile_Followup_DiseaseService.UpdateEntity(entity1);
                }
            }

            //------------------------------------------------吸烟与饮酒-----------------------------------------------
            Chronic_disease_SmokeAndDrink entity2 = new Chronic_disease_SmokeAndDrink();
            //获取id
            string id2 = CommonFunc.SafeGetStringFromObj(chronic_disease_SmokeAndDrinkService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id2))
            {
                entity2.id = Guid.NewGuid().ToString();
            }
            else
            {
                entity2.id = id2;
            }
            entity2.name           = Request["name"];
            entity2.sex            = Request["sex"];
            entity2.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                entity2.birth_date = null;
            }
            else
            {
                entity2.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            entity2.resident_id       = entity.resident_id;
            entity2.permanent_address = Request["perment_community_address"];
            entity2.post_code         = Request["zipCode"];
            entity2.community_code    = Request["ddlCommunity"];
            //-----吸烟----
            entity2.smoking = Request["smoking"];

            if (!string.IsNullOrEmpty(Request["times1"]))
            {
                entity2.smoking_begin_year = Request["times1"];
            }
            else
            {
                entity2.smoking_begin_year = "";
            }

            entity2.smoking_daily_amount = Request["day_smoke"];
            if (!string.IsNullOrEmpty(Request["smoke_age"]))
            {
                entity2.smoking_age = Request["smoke_age"].Split('年')[0];
            }
            else
            {
                entity2.smoking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked"]))
            {
                entity2.smoked = Request["smoked"];
            }
            else
            {
                entity2.smoked = "";
            }

            if (!string.IsNullOrEmpty(Request["times2"]))
            {
                entity2.smoked_begin_year = Request["times2"];
            }
            else
            {
                entity2.smoked_begin_year = "";
            }

            if (!string.IsNullOrEmpty(Request["times3"]))
            {
                entity2.smoked_smoking_again = Request["times3"];
            }
            else
            {
                entity2.smoked_smoking_again = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked_long"]))
            {
                entity2.smoked_long_time = Request["smoked_long"].Split('年')[0];
            }
            else
            {
                entity2.smoked_long_time = "";
            }
            entity2.smoked_intent      = Request["smoked_idea"];
            entity2.smoked_second_hand = Request["smoke_twice"];
            entity2.smoke_never        = Request["smoke"];
            //-----饮酒-----
            entity2.drinking = Request["drinking"];

            if (!string.IsNullOrEmpty(Request["times4"]))
            {
                entity2.drinking_begin_year = Request["times4"];
            }
            else
            {
                entity2.drinking_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["drink_age"]))
            {
                entity2.drinking_age = Request["drink_age"].Split('年')[0];
            }
            else
            {
                entity2.drinking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["times5"]))
            {
                entity2.drunk_begin_year = Request["times5"];
            }
            else
            {
                entity2.drunk_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["times6"]))
            {
                entity2.drunk_drinking_again = Request["times6"];
            }
            else
            {
                entity2.drunk_drinking_again = "";
            }


            if (!string.IsNullOrEmpty(Request["drunk_long"]))
            {
                entity2.drunk_long_time = Request["drunk_long"].Split('年')[0];
            }
            else
            {
                entity2.drunk_long_time = "";
            }
            entity2.drink_never = Request["drink"];
            //-----饮酒频率-----
            entity2.drinking_spirit_frequency = Request["frequency1"];
            entity2.drinking_beer_frequency   = Request["frequency2"];
            entity2.drinking_red_frequency    = Request["frequency3"];
            entity2.drinking_yellow_frequency = Request["frequency4"];
            entity2.drinking_other_wine1      = Request["other"];
            entity2.drinking_other_degree1    = Request["other_du"];
            entity2.drinking_other_frequency  = Request["frequency5"];

            entity2.drinking_spirit_amount = Request["count1"];
            entity2.drinking_beer_amount   = Request["count2"];
            entity2.drinking_red_amount    = Request["count3"];
            entity2.drinking_yellow_amount = Request["count4"];
            entity2.drinking_other_wine2   = Request["other_wine"];
            entity2.drinking_other_degree2 = Request["wine_degree"];
            entity2.drinking_other_amount  = Request["count5"];

            entity2.drinking_spirit_equivalent = Request["count1_dl"];
            entity2.drinking_beer_equivalent   = Request["count2_dl"];
            entity2.drinking_red_equivalent    = Request["count3_dl"];
            entity2.drinking_yellow_equivalent = Request["count4_dl"];
            entity2.drinking_other_equivalent  = Request["count5_dl"];

            entity2.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            entity2.worker_user_name = worker;
            entity2.create_time      = entity.create_time;
            if (string.IsNullOrEmpty(id2))
            {
                chronic_disease_SmokeAndDrinkService.AddEntity(entity2);
            }
            else
            {
                chronic_disease_SmokeAndDrinkService.UpdateEntity(entity2);
            }

            Chronic_disease_DailyLife        eh = new Chronic_disease_DailyLife();
            Chronic_disease_PhysicalExercise pe = new Chronic_disease_PhysicalExercise();

            //=================体育锻炼========================
            string id3 = CommonFunc.SafeGetStringFromObj(chronic_disease_PhysicalExerciseService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id3))
            {
                pe.id = Guid.NewGuid().ToString();
            }
            else
            {
                pe.id = id3;
            }
            pe.name           = Request["name"];
            pe.sex            = Request["sex"];
            pe.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                pe.birth_date = null;
            }
            else
            {
                pe.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            pe.resident_id       = entity.resident_id;
            pe.permanent_address = Request["perment_community_address"];
            pe.post_code         = Request["zipCode"];
            pe.community_code    = Request["ddlCommunity"];

            pe.physical_1      = Request["run"];
            pe.physical_1_time = Request["every_time1"];
            pe.physical_1_week = Request["week1"];

            pe.physical_2       = Request["cut_it"];
            pe.physical_2_week  = Request["week2"];
            pe.physical_2_time  = Request["every_time2"];
            pe.physical_2_speed = Request["speed2"];


            pe.physical_3       = Request["by_bike"];
            pe.physical_3_week  = Request["week3"];
            pe.physical_3_time  = Request["every_time3"];
            pe.physical_3_speed = Request["speed3"];


            pe.physical_4      = Request["swim"];
            pe.physical_4_week = Request["week4"];
            pe.physical_4_time = Request["every_time4"];

            pe.physical_5      = Request["circuit"];
            pe.physical_5_week = Request["week5"];
            pe.physical_5_time = Request["every_time5"];

            pe.physical_6      = Request["ping_pong"];
            pe.physical_6_week = Request["week6"];
            pe.physical_6_time = Request["every_time6"];


            pe.physical_7      = Request["badminton"];
            pe.physical_7_week = Request["week7"];
            pe.physical_7_time = Request["every_time7"];

            pe.physical_8      = Request["football"];
            pe.physical_8_week = Request["week8"];
            pe.physical_8_time = Request["every_time8"];

            pe.physical_9      = Request["basketball"];
            pe.physical_9_week = Request["week9"];
            pe.physical_9_time = Request["every_time9"];

            pe.physical_10      = Request["tennis"];
            pe.physical_10_week = Request["week10"];
            pe.physical_10_time = Request["every_time10"];

            pe.physical_11      = Request["baseball"];
            pe.physical_11_week = Request["week11"];
            pe.physical_11_time = Request["every_time11"];

            pe.physical_12      = Request["golf"];
            pe.physical_12_week = Request["week12"];
            pe.physical_12_time = Request["every_time12"];

            pe.physical_13      = Request["bowling"];
            pe.physical_13_week = Request["week13"];
            pe.physical_13_time = Request["every_time13"];

            pe.physical_14      = Request["shadowboxing"];
            pe.physical_14_week = Request["week14"];
            pe.physical_14_time = Request["every_time14"];

            pe.physical_15      = Request["taekwondo"];
            pe.physical_15_week = Request["week15"];
            pe.physical_15_time = Request["every_time15"];

            pe.physical_16      = Request["mountaineering"];
            pe.physical_16_week = Request["week16"];
            pe.physical_16_time = Request["every_time16"];

            pe.physical_17      = Request["skip"];
            pe.physical_17_week = Request["week17"];
            pe.physical_17_time = Request["every_time17"];

            pe.physical_other           = Request["other0"];
            pe.physical_other_frequency = Request["frequency0"];


            pe.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            pe.worker_user_name = worker;
            pe.create_time      = entity.create_time;
            if (string.IsNullOrEmpty(id3))
            {
                chronic_disease_PhysicalExerciseService.AddEntity(pe);
            }
            else
            {
                chronic_disease_PhysicalExerciseService.UpdateEntity(pe);
            }
            //-------------饮食习惯------------
            //获取id

            string id4 = CommonFunc.SafeGetStringFromObj(chronic_disease_DailyLifeService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id4))
            {
                eh.id = Guid.NewGuid().ToString();
            }
            else
            {
                eh.id = id4;
            }
            eh.name           = Request["name"];
            eh.sex            = Request["sex"];
            eh.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                eh.birth_date = null;
            }
            else
            {
                eh.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            eh.resident_id       = entity.resident_id;
            eh.permanent_address = Request["perment_community_address"];
            eh.post_code         = Request["zipCode"];
            eh.community_code    = Request["ddlCommunity"];

            eh.living_getup            = Request["morning"];
            eh.living_noonbreak        = Request["noon"];
            eh.living_sleep            = Request["night"];
            eh.diet_three_meals        = Request["law"];
            eh.diet_staple_food        = Request["food"];
            eh.diet_eating             = Request["taste"];
            eh.diet_eating_other       = Request["taste_other"];
            eh.diet_oil_salt           = Request["oil_salt"];
            eh.diet_oil_salt_other     = Request["oil_salt_other"];
            eh.diet_salt_amount        = Request["salt_eat"];
            eh.diet_oil_amount         = Request["oil_eat"];
            eh.diet_sugar_amount       = Request["sugar_eat"];
            eh.diet_drinkwater_morning = Request["water"];
            eh.diet_drink_amount       = Request["amount"];
            eh.diet_drink_interval     = Request["time"];
            eh.diet_drinks             = Request["drink"];
            eh.diet_drinks_other       = Request["other"];
            eh.diet_fruits             = Request["melon_fruit"];
            eh.diet_vegetables         = Request["vegetables"];
            eh.diet_grain                        = Request["grain"];
            eh.diet_grain_other                  = Request["other_grain"];
            eh.diet_aquatic_products             = Request["aquatic"];
            eh.diet_aquatic_products_other       = Request["other_aquatic"];
            eh.diet_livestock_poultry_eggs       = Request["meat"];
            eh.diet_livestock_poultry_eggs_other = Request["other_meat"];
            eh.diet_health_products              = Request["health_products"];
            eh.diet_health_products_other        = Request["other_health_products"];
            eh.diet_hobby                        = Request["other_diet"];
            eh.diet_hobby_other                  = Request["other_diet_other"];

            eh.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            eh.worker_user_name = worker;
            eh.create_time      = entity.create_time;
            if (string.IsNullOrEmpty(id4))
            {
                chronic_disease_DailyLifeService.AddEntity(eh);
            }
            else
            {
                chronic_disease_DailyLifeService.UpdateEntity(eh);
            }

            string msg = "";

            if (string.IsNullOrEmpty(id))
            {
                if (comm_Adults_Health_Examination_NewService.AddEntity(entity))
                {
                    Comm_EHR_Abstract ehr = new Comm_EHR_Abstract();
                    ehr.id             = Guid.NewGuid().ToString();
                    ehr.resident_id    = entity.resident_id;
                    ehr.community_code = entity.community_code;
                    ehr.create_time    = DateTime.Now;
                    ehr.item_id        = entity.id;
                    ehr.item_type      = Model.Enum.EHRAbstractTypeEnum.AdultsHealthExamination.ToString();

                    if (eHRAbstractService.AddEntity(ehr))
                    {
                        msg = "提交成功";
                    }
                    else
                    {
                        msg = "提交失败";
                    }
                }
                else
                {
                    msg = "提交失败";
                }
            }
            else
            {
                if (comm_Adults_Health_Examination_NewService.UpdateEntity(entity))
                {
                    msg = "提交成功";
                }
                else
                {
                    msg = "提交失败";
                }
            }

            return(Content(msg));
        }
예제 #3
0
        //新增
        public ActionResult AddAndUpdate()
        {
            string id             = CommonFunc.SafeGetStringFromObj(Request.QueryString["id"]);
            string community_code = CommonFunc.SafeGetStringFromObj(Request.QueryString["community_code"]);
            string worker         = CommonFunc.SafeGetStringFromObj(Request.QueryString["worker"]);
            string real_name      = CommonFunc.SafeGetStringFromObj(Request.QueryString["real_name"]);

            MT_BC_Followup      entity    = new MT_BC_Followup();
            MT_BC_Followup_Dose medentity = new MT_BC_Followup_Dose();

            if (string.IsNullOrEmpty(id))
            {
                entity.id          = Guid.NewGuid().ToString();
                entity.create_time = entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            else
            {
                entity.id          = id;
                entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            entity.name           = Request["name"];
            entity.sex            = Request["sex"];
            entity.age            = Request["age"];
            entity.id_card_number = Request["id_card_number"];
            string s = Request["id_card_number"];
            string s1 = "", s2 = "", s3 = "";

            if (s.Length == 15)
            {
                s1 = s.Substring(6, 2);
                s2 = s.Substring(8, 2);
                s3 = s.Substring(10, 2);
                entity.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj("19" + s1 + "-" + s2 + "-" + s3));
            }
            else if (s.Length == 18)
            {
                s1 = s.Substring(6, 4);
                s2 = s.Substring(10, 2);
                s3 = s.Substring(12, 2);
                entity.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(s1 + "-" + s2 + "-" + s3));
            }
            //根据身份证号查询个人信息表中是否存在此人信息,如果存在,则使用个人信息中的健康档案号,如果不存在,则创建一个新的17位的健康档案号
            string id_card_number = CommonFunc.SafeGetStringFromObj(Request["id_card_number"]);
            string ddlCommunity   = CommonFunc.SafeGetStringFromObj(Request["ddlCommunity"]);

            entity.zipcode = Request["zipCode"];
            string residentId = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.resident_id).FirstOrDefault());

            if (string.IsNullOrEmpty(residentId))
            {
                entity.resident_id = residentFileService.GetNumberByCode1(ddlCommunity);
            }
            else
            {
                entity.resident_id = residentId;
            }

            entity.community_code     = Request["ddlCommunity"];
            entity.address            = Request["perment_community_address"];
            entity.followup_physician = real_name;
            entity.followup_type      = Request["way"];
            if (string.IsNullOrEmpty(Request["time"]))
            {
                entity.followup_date = null;
            }
            else
            {
                entity.followup_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["time"]));
            }

            entity.followup_result      = Request["sffl"];
            entity.height               = Request["height"];
            entity.weight               = Request["weight1"];
            entity.height_weight_index  = Request["bmi"];
            entity.systolic_pressure    = Request["ssy"];
            entity.diastolic_pressure   = Request["szy"];
            entity.abidance_result      = Request["zyxw"];
            entity.worker_user_name     = worker;
            entity.worker_user_realname = real_name;
            entity.heart_rate           = Request["heart1"];
            entity.next_heart_rate      = Request["heart2"];
            entity.next_weight          = Request["weight2"];

            entity.xltz             = Request["xltz"];
            entity.bloodsugar       = Request["bs"];
            entity.bloodsugar_other = Request["other4"];
            entity.org    = Request["org"];
            entity.reason = Request["reason"];
            if (string.IsNullOrEmpty(Request["nexttime"]))
            {
                entity.next_time = null;
            }
            else
            {
                entity.next_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["nexttime"]));
            }

            entity.ssy1 = Request["ssy1"];
            entity.szy1 = Request["szy1"];
            if (string.IsNullOrEmpty(Request["firstsymptomdate"]))
            {
                entity.firstsymptomdate = null;
            }
            else
            {
                entity.firstsymptomdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["firstsymptomdate"]));
            }
            if (string.IsNullOrEmpty(Request["firstvisitdate"]))
            {
                entity.firstvisitdate = null;
            }
            else
            {
                entity.firstvisitdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["firstvisitdate"]));
            }

            if (string.IsNullOrEmpty(Request["firstdiagnosisdate"]))
            {
                entity.firstdiagnosisdate = null;
            }
            else
            {
                entity.firstdiagnosisdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["firstdiagnosisdate"]));
            }

            entity.diagnosishospital      = Request["diagnosishospital"];
            entity.diseasename            = Request["diseasename"];
            entity.diagnosisbasis         = Request["diagnosisbasis"];
            entity.pathologictype         = Request["pathologictype"];
            entity.treatmentsituation     = Request["treatmentsituation"];
            entity.complication           = Request["complication"];
            entity.treatmenthospital      = Request["treatmenthospital"];
            entity.treatment              = Request["treatment"];
            entity.treatmentother         = Request["treatmentother"];
            entity.firstoperationhospital = Request["firstoperationhospital"];
            if (string.IsNullOrEmpty(Request["firstoperationdate"]))
            {
                entity.firstoperationdate = null;
            }
            else
            {
                entity.firstoperationdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["firstoperationdate"]));
            }

            entity.firstoperationnature = Request["firstoperationnature"];
            entity.transfer             = Request["transfer"];
            entity.transferposition     = Request["transferposition"];
            entity.recrudescence        = Request["recrudescence"];
            if (string.IsNullOrEmpty(Request["recrudescencedate"]))
            {
                entity.recrudescencedate = null;
            }
            else
            {
                entity.recrudescencedate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["recrudescencedate"]));
            }

            entity.tumorhistory          = Request["tumorhistory"];
            entity.tumorhistoryrelation  = Request["tumorhistoryrelation"];
            entity.tumorhistorytype      = Request["tumorhistorytype"];
            entity.tumorhistorytypeother = Request["tumorhistorytypeother"];
            entity.correctdiagnosis      = Request["correctdiagnosis"];
            entity.correctdiagnosissite  = Request["correctdiagnosissite"];
            if (string.IsNullOrEmpty(Request["correctdiagnosisdate"]))
            {
                entity.correctdiagnosisdate = null;
            }
            else
            {
                entity.correctdiagnosisdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["correctdiagnosisdate"]));
            }

            entity.presentsituation = Request["presentsituation"];
            entity.guidecontent     = Request["guidecontent"];
            entity.cardscore        = Request["cardscore"];
            if (string.IsNullOrEmpty(Request["revokemanagedate"]))
            {
                entity.revokemanagedate = null;
            }
            else
            {
                entity.revokemanagedate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["revokemanagedate"]));
            }

            entity.revokereason = Request["revokereason"];
            entity.isdeath      = Request["isdeath"];
            if (string.IsNullOrEmpty(Request["deathdate"]))
            {
                entity.deathdate = null;
            }
            else
            {
                entity.deathdate = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["deathdate"]));
            }

            entity.deathreason  = Request["deathreason"];
            entity.deathsite    = Request["deathsite"];
            entity.surviveyear  = Request["surviveyear"];
            entity.survivemonth = Request["survivemonth"];

            string med_id = CommonFunc.SafeGetStringFromObj(bc_Followup_DoseService.LoadEntityAsNoTracking(t => t.bc_followup_id == id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(med_id))
            {
                medentity.id               = Guid.NewGuid().ToString();
                medentity.bc_followup_id   = entity.id;
                medentity.community_code   = Request["ddlCommunity"];
                medentity.resident_id      = entity.resident_id;
                medentity.worker_user_name = entity.followup_physician;
                medentity.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            else
            {
                medentity.id               = med_id;
                medentity.bc_followup_id   = entity.id;
                medentity.community_code   = Request["ddlCommunity"];
                medentity.resident_id      = entity.resident_id;
                medentity.worker_user_name = entity.followup_physician;
                medentity.create_time      = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            medentity.dose_dependence = Request["fyycx"];
            medentity.drug_name       = Request["name1"];
            medentity.drug_frequence  = Request["few1"];
            medentity.dosage_per_time = Request["few2"];

            medentity.drug_name1       = Request["name2"];
            medentity.drug_frequence1  = Request["few3"];
            medentity.dosage_per_time1 = Request["few4"];

            medentity.drug_name2       = Request["name3"];
            medentity.drug_frequence2  = Request["few5"];
            medentity.dosage_per_time2 = Request["few6"];

            medentity.drug_name3       = Request["other_medicals"];
            medentity.drug_frequence3  = Request["few7"];
            medentity.dosage_per_time3 = Request["few8"];

            medentity.has_side_effect         = Request["blfy"];
            medentity.side_effect_description = Request["discript"];

            if (string.IsNullOrEmpty(med_id))
            {
                bc_Followup_DoseService.AddEntity(medentity);
            }
            else
            {
                bc_Followup_DoseService.UpdateEntity(medentity);
            }


            //判断个人信息表中是否存在此人信息 2015-06-18 娄帅
            var dt = residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number);

            Comm_ResidentFile resident = new Comm_ResidentFile();

            resident.id = CommonFunc.SafeGetStringFromObj(dt.Select(t => t.id).FirstOrDefault());

            resident.resident_id            = entity.resident_id;
            resident.resident_name          = Request["name"];
            resident.sex                    = Request["sex"];
            resident.id_card_number         = Request["id_card_number"];
            resident.birth_date             = entity.birth_date;
            resident.community_code         = Request["ddlCommunity"];
            resident.individual_phone       = Request["phone"];
            resident.permanent_home_address = Request["perment_community_address"];
            resident.nationality_name       = "中国";
            resident.nationality_code       = "156";

            if (dt.Count() < 1)
            {
                resident.id             = Guid.NewGuid().ToString();
                resident.community_code = Request["ddlCommunity"];
                if (entity.create_time == null)
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(DateTime.Now.ToString("yyyy-MM-dd"));
                }
                else
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(entity.create_time);
                }

                resident.worker_user_name = worker;

                residentFileService.AddEntity(resident);

                // 添加摘要

                Comm_EHR_Abstract ehr1 = new Comm_EHR_Abstract();
                ehr1.id             = Guid.NewGuid().ToString();
                ehr1.resident_id    = entity.resident_id;
                ehr1.community_code = entity.community_code;
                ehr1.create_time    = DateTime.Now;
                ehr1.item_id        = resident.id;
                ehr1.item_type      = Model.Enum.EHRAbstractTypeEnum.ResidentInfo.ToString();

                eHRAbstractService.AddEntity(ehr1);
            }
            else
            {
                /** 根据身份证号查询个人信息表中是否存在此人信息,存在获取行政区划代码,与现在填写的常住地址作比较,不相同则将其添加到Comm_ResidentFile_Change_Address表中
                 */

                string code = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.community_code).FirstOrDefault());

                if (Request["ddlCommunity"] != code)
                {
                    Comm_ResidentFile_Change_Address address = new Comm_ResidentFile_Change_Address();
                    address.id                  = Guid.NewGuid().ToString();
                    address.contact_id          = entity.id;
                    address.resident_id         = entity.resident_id;
                    address.community_code      = code;
                    address.fill_community_code = community_code;
                    address.fill_person         = worker;
                    address.permanent_address   = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.permanent_home_address).FirstOrDefault());
                    address.create_time         = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));

                    residentFileChangeAddressService.AddEntity(address);
                }
                //resident.id = dt.Select(t=>t.id).ToString();
                string[] propertyName = new string[] { "resident_name", "sex", "id_card_number", "community_code", "individual_phone", "permanent_home_address" };
                residentFileService.UpdatePartialPropertity(resident, propertyName);
            }

            //添加吸烟、饮酒、饮食习惯、体育锻炼信息
            Chronic_disease_SmokeAndDrink    sd = new Chronic_disease_SmokeAndDrink();
            Chronic_disease_DailyLife        eh = new Chronic_disease_DailyLife();
            Chronic_disease_PhysicalExercise pe = new Chronic_disease_PhysicalExercise();

            //------------------------------------------------吸烟与饮酒-----------------------------------------------
            //获取id
            string id2 = CommonFunc.SafeGetStringFromObj(disease_SmokeAndDrinkService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id2))
            {
                sd.id = Guid.NewGuid().ToString();
            }
            else
            {
                sd.id = id2;
            }
            sd.name           = Request["name"];
            sd.sex            = Request["sex"];
            sd.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                sd.birth_date = null;
            }
            else
            {
                sd.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            sd.resident_id       = entity.resident_id;
            sd.permanent_address = Request["perment_community_address"];
            sd.post_code         = Request["zipCode"];
            sd.community_code    = Request["ddlCommunity"];
            //-----吸烟----


            if (Request["day_smoke"] != "")
            {
                sd.smoking_daily_amount = Request["day_smoke"];
                sd.smoking = "吸烟";
            }
            //-----饮酒-----

            //-----饮酒频率-----
            if (Request["count1"] != "" || Request["count2"] != "" || Request["count3"] != "" || Request["count4"] != "" || Request["count5"] != "")
            {
                sd.drinking = "饮酒";
                sd.drinking_spirit_amount = Request["count1"];
                sd.drinking_beer_amount   = Request["count2"];
                sd.drinking_red_amount    = Request["count3"];
                sd.drinking_yellow_amount = Request["count4"];
                sd.drinking_other_wine2   = Request["other_wine"];
                sd.drinking_other_degree2 = Request["wine_degree"];
                sd.drinking_other_amount  = Request["count5"];

                sd.drinking_spirit_equivalent = Request["count1_dl"];
                sd.drinking_beer_equivalent   = Request["count2_dl"];
                sd.drinking_red_equivalent    = Request["count3_dl"];
                sd.drinking_yellow_equivalent = Request["count4_dl"];
                sd.drinking_other_equivalent  = Request["count5_dl"];
            }
            sd.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            sd.worker_user_name = worker;
            sd.create_time      = entity.followup_date;
            if (string.IsNullOrEmpty(id2))
            {
                disease_SmokeAndDrinkService.AddEntity(sd);
            }
            else
            {
                disease_SmokeAndDrinkService.UpdateEntity(sd);
            }
            //=================体育锻炼========================
            string id3 = CommonFunc.SafeGetStringFromObj(disease_PhysicalExerciseService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id3))
            {
                pe.id = Guid.NewGuid().ToString();
            }
            else
            {
                pe.id = id3;
            }
            pe.name           = Request["name"];
            pe.sex            = Request["sex"];
            pe.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                pe.birth_date = null;
            }
            else
            {
                pe.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            pe.resident_id       = entity.resident_id;
            pe.permanent_address = Request["perment_community_address"];
            pe.post_code         = Request["zipCode"];
            pe.community_code    = Request["ddlCommunity"];

            pe.physical_1      = Request["run"];
            pe.physical_1_time = Request["every_time1"];
            pe.physical_1_week = Request["week1"];

            pe.physical_2       = Request["cut_it"];
            pe.physical_2_week  = Request["week2"];
            pe.physical_2_time  = Request["every_time2"];
            pe.physical_2_speed = Request["speed2"];


            pe.physical_3       = Request["by_bike"];
            pe.physical_3_week  = Request["week3"];
            pe.physical_3_time  = Request["every_time3"];
            pe.physical_3_speed = Request["speed3"];


            pe.physical_4      = Request["swim"];
            pe.physical_4_week = Request["week4"];
            pe.physical_4_time = Request["every_time4"];

            pe.physical_5      = Request["circuit"];
            pe.physical_5_week = Request["week5"];
            pe.physical_5_time = Request["every_time5"];

            pe.physical_6      = Request["ping_pong"];
            pe.physical_6_week = Request["week6"];
            pe.physical_6_time = Request["every_time6"];


            pe.physical_7      = Request["badminton"];
            pe.physical_7_week = Request["week7"];
            pe.physical_7_time = Request["every_time7"];

            pe.physical_8      = Request["football"];
            pe.physical_8_week = Request["week8"];
            pe.physical_8_time = Request["every_time8"];

            pe.physical_9      = Request["basketball"];
            pe.physical_9_week = Request["week9"];
            pe.physical_9_time = Request["every_time9"];

            pe.physical_10      = Request["tennis"];
            pe.physical_10_week = Request["week10"];
            pe.physical_10_time = Request["every_time10"];

            pe.physical_11      = Request["baseball"];
            pe.physical_11_week = Request["week11"];
            pe.physical_11_time = Request["every_time11"];

            pe.physical_12      = Request["golf"];
            pe.physical_12_week = Request["week12"];
            pe.physical_12_time = Request["every_time12"];

            pe.physical_13      = Request["bowling"];
            pe.physical_13_week = Request["week13"];
            pe.physical_13_time = Request["every_time13"];

            pe.physical_14      = Request["shadowboxing"];
            pe.physical_14_week = Request["week14"];
            pe.physical_14_time = Request["every_time14"];

            pe.physical_15      = Request["taekwondo"];
            pe.physical_15_week = Request["week15"];
            pe.physical_15_time = Request["every_time15"];

            pe.physical_16      = Request["mountaineering"];
            pe.physical_16_week = Request["week16"];
            pe.physical_16_time = Request["every_time16"];

            pe.physical_17      = Request["skip"];
            pe.physical_17_week = Request["week17"];
            pe.physical_17_time = Request["every_time17"];

            pe.physical_other           = Request["other0"];
            pe.physical_other_frequency = Request["frequency0"];


            pe.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            pe.worker_user_name = worker;
            pe.create_time      = entity.followup_date;
            if (string.IsNullOrEmpty(id3))
            {
                disease_PhysicalExerciseService.AddEntity(pe);
            }
            else
            {
                disease_PhysicalExerciseService.UpdateEntity(pe);
            }
            //-------------饮食习惯------------
            //获取id

            string id4 = CommonFunc.SafeGetStringFromObj(disease_DailyLifeService.LoadEntityAsNoTracking(t => t.resident_id == entity.resident_id).Select(t => t.id).FirstOrDefault());

            if (string.IsNullOrEmpty(id4))
            {
                eh.id = Guid.NewGuid().ToString();
            }
            else
            {
                eh.id = id4;
            }
            eh.name           = Request["name"];
            eh.sex            = Request["sex"];
            eh.id_card_number = Request["id_card_number"];
            if (string.IsNullOrEmpty(Request["birth_date"]))
            {
                eh.birth_date = null;
            }
            else
            {
                eh.birth_date = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));
            }
            //常住地址
            eh.resident_id       = entity.resident_id;
            eh.permanent_address = Request["perment_community_address"];
            eh.post_code         = Request["zipCode"];
            eh.community_code    = Request["ddlCommunity"];

            eh.living_getup            = Request["morning"];
            eh.living_noonbreak        = Request["noon"];
            eh.living_sleep            = Request["night"];
            eh.diet_three_meals        = Request["law"];
            eh.diet_staple_food        = Request["food"];
            eh.diet_eating             = Request["taste"];
            eh.diet_eating_other       = Request["taste_other"];
            eh.diet_oil_salt           = Request["oil_salt"];
            eh.diet_oil_salt_other     = Request["oil_salt_other"];
            eh.diet_salt_amount        = Request["salt_eat"];
            eh.diet_oil_amount         = Request["oil_eat"];
            eh.diet_sugar_amount       = Request["sugar_eat"];
            eh.diet_drinkwater_morning = Request["water"];
            eh.diet_drink_amount       = Request["amount"];
            eh.diet_drink_interval     = Request["time"];
            eh.diet_drinks             = Request["drink"];
            eh.diet_drinks_other       = Request["other"];
            eh.diet_fruits             = Request["melon_fruit"];
            eh.diet_vegetables         = Request["vegetables"];
            eh.diet_grain                        = Request["grain"];
            eh.diet_grain_other                  = Request["other_grain"];
            eh.diet_aquatic_products             = Request["aquatic"];
            eh.diet_aquatic_products_other       = Request["other_aquatic"];
            eh.diet_livestock_poultry_eggs       = Request["meat"];
            eh.diet_livestock_poultry_eggs_other = Request["other_meat"];
            eh.diet_health_products              = Request["health_products"];
            eh.diet_health_products_other        = Request["other_health_products"];
            eh.diet_hobby                        = Request["other_diet"];
            eh.diet_hobby_other                  = Request["other_diet_other"];

            eh.type             = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            eh.worker_user_name = worker;
            eh.create_time      = entity.followup_date;
            if (string.IsNullOrEmpty(id4))
            {
                disease_DailyLifeService.AddEntity(eh);
            }
            else
            {
                disease_DailyLifeService.UpdateEntity(eh);
            }
            string msg = "";

            if (string.IsNullOrEmpty(id))
            {
                if (bc_FollowupService.AddEntity(entity))
                {
                    Comm_EHR_Abstract ehr = new Comm_EHR_Abstract();
                    ehr.id             = Guid.NewGuid().ToString();
                    ehr.resident_id    = entity.resident_id;
                    ehr.community_code = entity.community_code;
                    ehr.create_time    = DateTime.Now;
                    ehr.item_id        = entity.id;
                    ehr.item_type      = Model.Enum.EHRAbstractTypeEnum.Followup.ToString();

                    if (eHRAbstractService.AddEntity(ehr))
                    {
                        msg = "提交成功";
                    }
                    else
                    {
                        msg = "提交失败";
                    }
                }
                else
                {
                    msg = "提交失败";
                }
            }
            else
            {
                if (bc_FollowupService.UpdateEntity(entity))
                {
                    msg = "提交成功";
                }
                else
                {
                    msg = "提交失败";
                }
            }

            return(Content(msg));
        }
        //提交 更新页面
        public ActionResult AddAndUpdate()
        {
            string id = Request["id"];
            string fill_community_code = Request["community_code"];
            string worker = Request["worker"];
            Chronic_disease_SmokeAndDrink entity = new Chronic_disease_SmokeAndDrink();

            if (string.IsNullOrEmpty(id))
            {
                entity.id          = Guid.NewGuid().ToString();
                entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            else
            {
                entity.id          = id;
                entity.create_time = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));
            }
            //根据身份证号查询个人信息表中是否存在此人信息,如果存在,则使用个人信息中的健康档案号,如果不存在,则创建一个新的17位的健康档案号
            string id_card_number = CommonFunc.SafeGetStringFromObj(Request["id_card_number"]);
            string ddlCommunity   = CommonFunc.SafeGetStringFromObj(Request["ddlCommunity"]);
            string residentId     = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.resident_id).FirstOrDefault());

            if (string.IsNullOrEmpty(residentId))
            {
                entity.resident_id = residentFileService.GetNumberByCode1(ddlCommunity);
            }
            else
            {
                entity.resident_id = residentId;
            }
            entity.name           = Request["name"];
            entity.sex            = Request["sex"];
            entity.id_card_number = Request["id_card_number"];
            entity.birth_date     = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(Request["birth_date"]));

            entity.permanent_address = Request["perment_community_address"];
            entity.post_code         = Request["zipCode"];
            entity.community_code    = Request["ddlCommunity"];

            //-----吸烟----
            entity.smoking = Request["smoking"];
            if (!string.IsNullOrEmpty(Request["times1"]))
            {
                entity.smoking_begin_year = Request["times1"];
            }
            else
            {
                entity.smoking_begin_year = "";
            }

            entity.smoking_daily_amount = Request["day_smoke"];
            if (!string.IsNullOrEmpty(Request["smoke_age"]))
            {
                entity.smoking_age = Request["smoke_age"].Split('年')[0];
            }
            else
            {
                entity.smoking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked"]))
            {
                entity.smoked = Request["smoked"];
            }
            else
            {
                entity.smoked = "";
            }

            if (!string.IsNullOrEmpty(Request["times2"]))
            {
                entity.smoked_begin_year = Request["times2"];
            }
            else
            {
                entity.smoked_begin_year = "";
            }

            if (!string.IsNullOrEmpty(Request["times3"]))
            {
                entity.smoked_smoking_again = Request["times3"];
            }
            else
            {
                entity.smoked_smoking_again = "";
            }

            if (!string.IsNullOrEmpty(Request["smoked_long"]))
            {
                entity.smoked_long_time = Request["smoked_long"].Split('年')[0];
            }
            else
            {
                entity.smoked_long_time = "";
            }
            entity.smoked_intent      = Request["smoked_idea"];
            entity.smoked_second_hand = Request["smoke_twice"];
            entity.smoke_never        = Request["smoke"];
            //-----饮酒-----
            entity.drinking = Request["drinking"];

            if (!string.IsNullOrEmpty(Request["times4"]))
            {
                entity.drinking_begin_year = Request["times4"];
            }
            else
            {
                entity.drinking_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["drink_age"]))
            {
                entity.drinking_age = Request["drink_age"].Split('年')[0];
            }
            else
            {
                entity.drinking_age = "";
            }

            if (!string.IsNullOrEmpty(Request["times5"]))
            {
                entity.drunk_begin_year = Request["times5"];
            }
            else
            {
                entity.drunk_begin_year = "";
            }


            if (!string.IsNullOrEmpty(Request["times6"]))
            {
                entity.drunk_drinking_again = Request["times6"];
            }
            else
            {
                entity.drunk_drinking_again = "";
            }


            if (!string.IsNullOrEmpty(Request["drunk_long"]))
            {
                entity.drunk_long_time = Request["drunk_long"].Split('年')[0];
            }
            else
            {
                entity.drunk_long_time = "";
            }
            entity.drink_never = Request["drink"];
            //-----饮酒频率-----
            entity.drinking_spirit_frequency = Request["frequency1"];
            entity.drinking_beer_frequency   = Request["frequency2"];
            entity.drinking_red_frequency    = Request["frequency3"];
            entity.drinking_yellow_frequency = Request["frequency4"];
            entity.drinking_other_wine1      = Request["other"];
            entity.drinking_other_degree1    = Request["other_du"];
            entity.drinking_other_frequency  = Request["frequency5"];


            entity.drinking_spirit_amount = Request["count1"];
            entity.drinking_beer_amount   = Request["count2"];
            entity.drinking_red_amount    = Request["count3"];
            entity.drinking_yellow_amount = Request["count4"];
            entity.drinking_other_wine2   = Request["other_wine"];
            entity.drinking_other_degree2 = Request["wine_degree"];
            entity.drinking_other_amount  = Request["count5"];

            entity.drinking_spirit_equivalent = Request["count1_dl"];
            entity.drinking_beer_equivalent   = Request["count2_dl"];
            entity.drinking_red_equivalent    = Request["count3_dl"];
            entity.drinking_yellow_equivalent = Request["count4_dl"];
            entity.drinking_other_equivalent  = Request["count5_dl"];

            entity.type = Enum.GetName(typeof(Model.Enum.EntityTypeEnum), 1);
            //entity.worker_user_name = Request["fillIdentity"];
            entity.worker_user_name = worker;
            //判断个人信息表中是否存在此人信息 2015-06-18 娄帅
            var dt = residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number);

            Comm_ResidentFile resident = new Comm_ResidentFile();

            resident.id = CommonFunc.SafeGetStringFromObj(dt.Select(t => t.id).FirstOrDefault());

            resident.resident_id            = entity.resident_id;
            resident.resident_name          = Request["name"];
            resident.sex                    = Request["sex"];
            resident.id_card_number         = Request["id_card_number"];
            resident.birth_date             = entity.birth_date;
            resident.community_code         = Request["ddlCommunity"];
            resident.individual_phone       = Request["phone"];
            resident.permanent_home_address = Request["perment_community_address"];
            resident.nationality_name       = "中国";
            resident.nationality_code       = "156";

            if (dt.Count() < 1)
            {
                resident.id             = Guid.NewGuid().ToString();
                resident.community_code = Request["ddlCommunity"];
                if (entity.create_time == null)
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(DateTime.Now.ToString("yyyy-MM-dd"));
                }
                else
                {
                    resident.create_time = CommonFunc.SafeGetDateTimeFromObj(entity.create_time);
                }

                resident.worker_user_name = worker;

                residentFileService.AddEntity(resident);

                // 添加摘要

                Comm_EHR_Abstract ehr1 = new Comm_EHR_Abstract();
                ehr1.id             = Guid.NewGuid().ToString();
                ehr1.resident_id    = entity.resident_id;
                ehr1.community_code = entity.community_code;
                ehr1.create_time    = DateTime.Now;
                ehr1.item_id        = resident.id;
                ehr1.item_type      = Model.Enum.EHRAbstractTypeEnum.ResidentInfo.ToString();

                eHRAbstractService.AddEntity(ehr1);
            }
            else
            {
                /** 根据身份证号查询个人信息表中是否存在此人信息,存在获取行政区划代码,与现在填写的常住地址作比较,不相同则将其添加到Comm_ResidentFile_Change_Address表中
                 */

                string code = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.community_code).FirstOrDefault());

                if (Request["ddlCommunity"] != code)
                {
                    Comm_ResidentFile_Change_Address address = new Comm_ResidentFile_Change_Address();
                    address.id                  = Guid.NewGuid().ToString();
                    address.contact_id          = entity.id;
                    address.resident_id         = entity.resident_id;
                    address.community_code      = code;
                    address.fill_community_code = fill_community_code;
                    address.fill_person         = worker;
                    address.permanent_address   = CommonFunc.SafeGetStringFromObj(residentFileService.LoadEntityAsNoTracking(t => t.id_card_number == id_card_number).Select(t => t.permanent_home_address).FirstOrDefault());
                    address.create_time         = CommonFunc.SafeGetDateTimeFromObj(CommonFunc.SafeGetStringFromObj(DateTime.Now.ToString("yyyy-MM-dd")));

                    residentFileChangeAddressService.AddEntity(address);
                }
                //resident.id = dt.Select(t=>t.id).ToString();
                string[] propertyName = new string[] { "resident_name", "sex", "id_card_number", "community_code", "individual_phone", "permanent_home_address" };
                residentFileService.UpdatePartialPropertity(resident, propertyName);
            }
            string msg = "";

            if (string.IsNullOrEmpty(id))
            {
                if (diseaseSmokeAndDrinkService.AddEntity(entity))
                {
                    Comm_EHR_Abstract ehr = new Comm_EHR_Abstract();
                    ehr.id             = Guid.NewGuid().ToString();
                    ehr.resident_id    = entity.resident_id;
                    ehr.community_code = entity.community_code;
                    ehr.create_time    = DateTime.Now;
                    ehr.item_id        = entity.id;
                    ehr.item_type      = Model.Enum.EHRAbstractTypeEnum.SmokeAndDrink.ToString();

                    if (eHRAbstractService.AddEntity(ehr))
                    {
                        msg = "提交成功";
                    }
                    else
                    {
                        msg = "提交失败";
                    }
                }
            }
            else
            {
                if (diseaseSmokeAndDrinkService.UpdateEntity(entity))
                {
                    msg = "修改成功";
                }
            }
            return(Content(msg + ',' + entity.id));
        }