Exemplo n.º 1
0
        public ResultPakage <bool> UpdatePatientDisease(UpdatePatientDisease patientDto)
        {
            //var dto = JObject.Parse(paramsDto);
            Db  db      = new Db();
            var patient = db.Patients.FirstOrDefault(a => a.Id == patientDto.PatientId);

            patient.CKDLeave = patientDto.CDKLeave;
            //删除原有的疾病
            db.PatientsDiseases.RemoveRange(patient.PatientsDiseases);
            //新建疾病
            patientDto.Disease.ForEach(a =>
            {
                Dal.PatientsDisease pd = new PatientsDisease();
                pd.DiseaseCode         = a.DiseaseCode;
                pd.DiseaseType         = a.DiseaseType;
                pd.DiseaseName         = a.DiseaseName;
                pd.PatientId           = patientDto.PatientId;
                pd.CreateTime          = DateTime.Now;
                db.PatientsDiseases.Add(pd);
            });
            db.SaveChanges();
            return(Util.ReturnOkResult(true));
        }
Exemplo n.º 2
0
        public ResultPakage <GetUserInfoDto> GetUserInfo(GetUserInfoParamsDto paramsDto)
        {
            //HttpClient http = new HttpClient();
            if (string.IsNullOrEmpty(paramsDto.OpenId))
            {
                paramsDto.OpenId = GetOpenIdByCode(paramsDto.Code, Util.GetConfigByName("AppIdForDisease"), Util.GetConfigByName("AppSecretForDisease"));
            }
            ;

            if (string.IsNullOrEmpty(paramsDto.OpenId))
            {
                return(Util.ReturnFailResult <GetUserInfoDto>("未能获取到openid"));
            }

            //在微信获取OpenId
            //var openId = openId;
            //根据OpenId获取用户信息
            var db   = new Db();
            var user = db.Users.FirstOrDefault(a => a.OpenId == paramsDto.OpenId);


            //var user = patient.User;
            //查询不到信息则返回空用户信息,则创建一个新的用户
            if (user == null)
            {
                //创建用户账户信息
                user            = new User();
                user.OpenId     = paramsDto.OpenId;
                user.CreateTime = DateTime.Now;
                user.Status     = (int)UserStatusType.Registered;
                db.Users.AddOrUpdate(user);

                //创建病人
                var newPatient = new Patient();
                newPatient.User = user;
                db.Patients.AddOrUpdate(newPatient);
                db.SaveChanges();
            }
            var returnUserInfo = new GetUserInfoDto();

            returnUserInfo.CreateTime  = user.CreateTime?.ToString("yyyy-MM-dd");
            returnUserInfo.Birthday    = user.Birthday;
            returnUserInfo.Id          = user.Id.ToString();
            returnUserInfo.UserName    = user.UserName;
            returnUserInfo.MobilePhone = user.MobilePhone;
            returnUserInfo.IdCard      = user.IdCard;
            returnUserInfo.OpenId      = user.OpenId;
            returnUserInfo.Height      = user.Height;
            returnUserInfo.Sex         = user.Sex;
            returnUserInfo.Status      = user.Status.ToString();
            var patient = db.Users.First(a => a.OpenId == paramsDto.OpenId).Patients.FirstOrDefault();

            if (patient.Doctor != null)
            {
                returnUserInfo.BelongToDoctorId = patient.Doctor.UserId.ToString();
            }
            if (patient.Nurse != null)
            {
                returnUserInfo.BelongToNurseId = patient.Nurse.UserId.ToString();
            }
            Patient returnPatient = new Patient();

            //Doctor doctor = new Doctor();
            //Nurse nurse = new Nurse();;
            returnUserInfo.Patient = returnPatient;
            returnUserInfo.Patient.BelongToDoctor   = patient.BelongToDoctor;
            returnUserInfo.Patient.BelongToHospital = patient.BelongToHospital;
            returnUserInfo.BelongToHospital         = patient.BelongToHospital;
            returnUserInfo.Patient.BelongToNurse    = patient.BelongToNurse;
            returnUserInfo.Patient.BindStatus       = patient.BindStatus;
            returnUserInfo.Patient.CKDLeave         = patient.CKDLeave;
            returnUserInfo.Patient.DiseaseType      = patient.DiseaseType;
            returnUserInfo.Patient.Id = patient.Id;
            //returnUserInfo.Patient.Doctor = doctor;
            //returnUserInfo.Patient.Nurse = nurse;
            //if (patient.Doctor != null) returnUserInfo.Patient.Doctor.Id = patient.Doctor.Id;
            //if (patient.Nurse != null) returnUserInfo.Patient.Nurse.Id = patient.Nurse.Id;

            var diseasefromdb = db.PatientsDiseases.Where(a => a.PatientId == patient.Id).Select(a => new { a.PatientId, a.DiseaseName, a.DiseaseType, a.DiseaseCode }).ToList();
            List <Dal.PatientsDisease> disease = new List <Dal.PatientsDisease>();

            //disease
            //disease = Util.MapTo<List<Dal.PatientsDisease>>(diseasefromdb);
            //returnUserInfo.Disease
            diseasefromdb.ForEach(a =>
            {
                PatientsDisease d = new PatientsDisease();
                d.PatientId       = a.PatientId;
                d.DiseaseName     = a.DiseaseName;
                d.DiseaseCode     = a.DiseaseCode;
                d.DiseaseType     = a.DiseaseType;
                disease.Add(d);
            });
            //查询是否有未读消息
            returnUserInfo.IsRead  = !db.Messages.Any(a => a.IsRead == false && a.ToUser == user.Id);
            returnUserInfo.Disease = disease;
            if (returnUserInfo.BelongToHospital != null)
            {
                returnUserInfo.CityCode     = db.Hospitals.Where(a => a.Id == returnUserInfo.BelongToHospital).Select(a => a.CityCode).First();
                returnUserInfo.ProvinceCode = db.Cities.Where(a => a.CityCode == returnUserInfo.CityCode)
                                              .Select(a => a.ProvinceCode).First();
            }

            return(Util.ReturnOkResult(returnUserInfo));


            //var result = http.GetAsync("https://api.weixin.qq.com/sns/jscode2session?appid=wx941fffa48c073a0d&secret=1b71efd31775ec025045185b951e0296&js_code="+ code + "&grant_type=authorization_code").Result.Content.ToString();
            //return Util.ReturnOkResult(user.Select(a=>new User{OpenId = a.OpenId,MobilePhone = a.MobilePhone,Sex = a.Sex,Birthday = a.Birthday}).First());


            //var httphelper = new HttpHelper(true, accountInfo.virtualAccount);
            //var item = new HttpItem();
            //item.URL = "https://passport.jd.com/uc/showAuthCode";
            //item.Method = "get";
            //item.Postdata = "{'loginName':" + accountInfo.realAccount + "}";
            //item.PostDataType = PostDataType.String;
            //item.ResultType = ResultType.String;
            ////item.ContentType = "application/json";
            //item.Accept = "application/json";
            //item.Header = header;
            //var rs = httphelper.GetHtml(item);
            //var result = JObject.Parse(rs.Html.Replace("(", "").Replace(")", ""));
            //if (result["verifycode"].Value<string>() != "True")
            //{
            //    return false;
            //}

            //return true;
            //var ret = client.Enable(id);
            //return ret;
        }