public Model.Patient RegisterPatient(string patientFirstName, string patientLastName, string nationalCode, int doctorId, string mobile, string description, bool isIranian)
        {
            // بررسی وجود بیمار با استفاده از کدملی
            var PatientObject = GetPatientByNationalCode(nationalCode);
            // چنین بیماری از قبل وجو نداشته و فرایند ثبت جدید باید انجام شود
            string RandomNo = FileID.ID(10).ToString();

            if (PatientObject == null)
            {
                bool IsAffected = AddPatient(new Model.Patient
                {
                    Address      = "",
                    Code         = GetNewPatientCodeToRegister(),
                    City         = "",
                    FirstName    = patientFirstName,
                    GenderIsMale = null,
                    LastName     = patientLastName,
                    Mobile       = mobile,
                    NationalCode = (isIranian ? nationalCode: RandomNo),
                    Province     = "",
                    RegisterDate = DateTime.Now,
                    IsIranian    = isIranian,
                    IsDeleted    = false
                });

                if (!IsAffected)
                {
                    throw Common.MegaException.ThrowException("امکان ثبت این کاربر وجود ندارد.لطفا با واحد فنی تماس بگیرید.");
                }
            }
            PatientObject = GetPatientByNationalCode((isIranian ? nationalCode : RandomNo));

            Model.Doctor         DoctorObject         = new DoctorService().GetDoctorById(doctorId);
            MedicalRecordService medicalRecordService = new MedicalRecordService();
            var IsMedicalRecordInserted = medicalRecordService.AddMedicalRecord(new Model.MedicalRecord
            {
                DoctorId                       = doctorId,
                DoctorFirstName                = DoctorObject.FirstName,
                DoctorLastName                 = DoctorObject.LastName,
                PatientFirstName               = PatientObject.FirstName,
                PatientLastName                = PatientObject.LastName,
                PatientId                      = Convert.ToInt32(PatientObject.Id),
                ReceptionDate                  = PatientObject.RegisterDate,
                TreatmentProcessId             = 1, // پذیرش شده
                LastTreatmentProcessChangeDate = DateTime.Now,
            });


            if (!IsMedicalRecordInserted)
            {
                throw Common.MegaException.ThrowException("امکان ثبت این کاربر وجود ندارد.لطفا با واحد فنی تماس بگیرید.");
            }

            return(PatientObject);
        }
        public static bool LockUser(int id)
        {
            var userEntity = GetUserByUserId(id);

            if (userEntity == null)
            {
                throw MegaException.ThrowException("کاربری با این شناسه در پایگاه داده وجود ندارد");
            }

            DoctorService.UpdateProfile(userEntity.Id, userEntity.Username, userEntity.FirstName, userEntity.LastName, userEntity.Mobile);
            return(true);
        }
        public static (int?UserId, string RoleName, string FullName) GetUserId()
        {
            string CookieName = "RoleType";
            string RoleName   = (Common.Cookie.ReadCookie(CookieName) ?? "").ToLower();

            switch (RoleName)
            {
            default:
                return(UserId : null, RoleName : null, FullName : null);

            case "doctor":
            {
                var UserData = DoctorService.IsAuthenticated();
                if (UserData == null)
                {
                    return(UserId : null, RoleName : null, FullName : null);
                }
                else
                {
                    return(UserId : UserData.Id, RoleName : RoleName, FullName : UserData.FirstName + " " + UserData.LastName);
                }
            }

            case "resident":
            {
                var UserData = ResidentService.IsAuthenticated();
                if (UserData == null)
                {
                    return(UserId : null, RoleName : null, FullName : null);
                }
                else
                {
                    return(UserId : UserData.Id, RoleName : RoleName, FullName : UserData.FirstName + " " + UserData.LastName);
                }
            }

            case "physicuser":
            {
                var UserData = Logic.Services.PhysicUserService.IsAuthenticated();
                if (UserData == null)
                {
                    return(UserId : null, RoleName : null, FullName : null);
                }
                else
                {
                    return(UserId : UserData.Id, RoleName : RoleName, FullName : UserData.FirstName + " " + UserData.LastName);
                }
            }
            }
        }
        public static bool ChangePassword(string newPassword, string oldPassword)
        {
            UserType CurrentUserType = GetUserType();

            var(UserId, _, _) = GetUserId();
            switch (CurrentUserType)
            {
            case UserType.Doctor:
            {
                return
                    (DoctorService
                     .ChangeUserPassword
                         (UserId.GetValueOrDefault(), oldPassword, newPassword));
            }

            case UserType.Resident:
            {
                return
                    (ResidentService
                     .ChangeUserPassword
                         (UserId.GetValueOrDefault(), oldPassword, newPassword));
            }

            case UserType.Physist:
            {
                return
                    (PhysicUserService
                     .ChangeUserPassword
                         (UserId.GetValueOrDefault(), oldPassword, newPassword));
            }

            case UserType.User:
            {
                return(UserService
                       .ChangeUserPassword
                           (UserId.GetValueOrDefault(), oldPassword, newPassword));
            }
            }
            return(false);
        }
        public bool UpdateMedicalRecordForDoctorChange(long medicalRecordId, int doctorId)
        {
            using (var db = new Model.PhysicManagementEntities())
            {
                var Entity = db.MedicalRecord.Find(medicalRecordId);
                if (Entity == null)
                {
                    throw Common.MegaException.ThrowException("");
                }

                Model.Doctor DoctorObject = new DoctorService().GetDoctorById(doctorId);
                if (DoctorObject == null)
                {
                    throw Common.MegaException.ThrowException("");
                }

                Entity.DoctorFirstName = DoctorObject.FirstName;
                Entity.DoctorLastName  = DoctorObject.LastName;
                Entity.DoctorId        = DoctorObject.Id;
                return(db.SaveChanges() == 1);
            }
        }
Beispiel #6
0
        private void SendSMSAlarm(int?patientId, Enums.AlarmEventType alarmEventType)
        {
            if (patientId == null)
            {
                return;
            }

            var correspondentMedicalRecord = MedicalRecordService.GetMedicalRecordByPatientId((int)patientId).LastOrDefault();

            if (correspondentMedicalRecord == null)
            {
                return;
            }

            var doctorId = (int)correspondentMedicalRecord.DoctorId;
            var doctor   = new DoctorService().GetDoctorById(doctorId);


            var alarmConfig = alarmService.GetAlarmConfigByEventTypeId(alarmEventType);
            var alarmObject = alarmService.GetAlarmEventTypeByEventType(alarmEventType);

            var hasDoctorSMS = alarmConfig.SendDoctorSMS;

            if ((bool)hasDoctorSMS)
            {
                var alarmRecord = alarmService.GetDoctorAlarmByDoctorId(doctorId);
                if (CheckUserCanRecieveSMS(doctor))
                {
                    //Send
                    StringBuilder smsText = new StringBuilder();
                    smsText.Append("نام بیمار: ");
                    smsText.AppendLine(correspondentMedicalRecord.PatientFirstName + " " + correspondentMedicalRecord.PatientLastName);
                    smsText.AppendLine("نوع اقدام: " + alarmObject.ShortTitle);
                    smsText.AppendLine("تاریخ: " + Common.DateUtility.GetPersianDate(DateTime.Now));
                    smsText.Append("مرکز رادیوتراپی شهدای تجریش");

                    SMSWebService.SendSMS(doctor.Mobile, smsText.ToString());
                }
            }


            var hasPhysistSMS = alarmConfig.SendPhysictSMS;

            if ((bool)hasPhysistSMS)
            {
                List <PhysicUserAlarm> alarmRecord    = alarmService.GetPhysicUserAlarmList();
                List <PhysicUser>      physicUserList = physicUserService.GetPhysicUsers();

                foreach (var user in physicUserList)
                {
                    if (CheckUserCanRecieveSMS(user))
                    {
                        //Send
                        SMSWebService.SendSMS(user.Mobile, "بیمار با نام " + correspondentMedicalRecord.PatientFirstName + " " + correspondentMedicalRecord.PatientLastName + " پذیرش شد" + " " + "تاریخ پذیرش " + Common.DateUtility.GetPersianDate(DateTime.Now));
                    }
                }
            }


            var hasAdminSMS    = alarmConfig.SendAdminSMS;
            var hasResidentSMS = alarmConfig.SendResidentSMS;

            if ((bool)hasResidentSMS)
            {
                List <ResidentAlarm> alarmRecord  = alarmService.GetResidentAlarmList();
                List <Resident>      residentList = residentService.GetResidentsByDoctorId(doctorId);

                foreach (var user in residentList)
                {
                    if (CheckUserCanRecieveSMS(user))
                    {
                        //Send
                        SMSWebService.SendSMS(user.Mobile, "بیمار با نام " + correspondentMedicalRecord.PatientFirstName + " " + correspondentMedicalRecord.PatientLastName + " پذیرش شد" + " " + "تاریخ پذیرش " + Common.DateUtility.GetPersianDate(DateTime.Now));
                    }
                }
            }
        }