コード例 #1
0
        public IActionResult Register([FromBody] UserRegisterDTO userRegisterDto)
        {
            try
            {
                if (userRegisterDto.Password.Length < 5)
                {
                    return(Ok(new { message = "Password can't be less than 5 char", ErrorHappen = true }));
                }

                User userObj = _eyadtakDbContext.Users.FirstOrDefault(x => x.UserEmail == userRegisterDto.Email);

                if (userObj != null)
                {
                    return(Ok(new { message = "This Email Already Exsist", ErrorHappen = true }));
                }

                User user = new User()
                {
                    Password     = Encription.Encrypt(userRegisterDto.Password, "SecretCode_hamed"),
                    UserName     = userRegisterDto.Name,
                    UserEmail    = userRegisterDto.Email,
                    Active       = false,
                    RegisterDate = DateTime.Now,
                    RecoveryCode = -1,
                    GenderId     = userRegisterDto.GenderId,
                    PhoneNumber  = userRegisterDto.PhoneNumber
                };

                user.User_Role = new List <User_Role>();
                user.User_Role.Add(new User_Role()
                {
                    RoleId = userRegisterDto.RoleId,
                    UserId = user.UserId
                });

                _eyadtakDbContext.Users.Add(user);
                _eyadtakDbContext.SaveChanges();

                string token = _jwt.GenerateToken(user.UserId);
                _email.SendAccountActivationEmail(user.UserEmail, _configuration.GetSection("Frontend:Url").Value + "/account/activate-account/?token=" + token);

                return(Ok(new { message = "User Registerd Successfully", ErrorHappen = false }));
            }
            catch (Exception e)
            {
                return(Ok(new { message = e.Message, ErrorHappen = true }));

                throw e;
            }
        }
コード例 #2
0
        public IActionResult SavePatientHistory([FromBody] SavePatientHistory savePatientHistory)
        {
            try
            {
                List <Allergie> newAllergies = savePatientHistory.Allergies.Where(x => x.Id == 0).Select(x => new Allergie {
                    Name = x.Name, NumberOfUse = 0
                }).ToList();
                List <Sign> newSigns = savePatientHistory.Signs.Where(x => x.Id == 0).Select(x => new Sign {
                    Name = x.Name, NumberOfUse = 0
                }).ToList();
                List <Symptom> newSymptoms = savePatientHistory.Symptoms.Where(x => x.Id == 0).Select(x => new Symptom {
                    Name = x.Name, NumberOfUse = 0
                }).ToList();
                List <Diagnosis> newDiagnoses = savePatientHistory.Diagnoses.Where(x => x.Id == 0).Select(x => new Diagnosis {
                    Name = x.Name, NumberOfUse = 0
                }).ToList();
                List <Medicine> newMedicines = savePatientHistory.Medicines.Where(x => x.Id == 0).Select(x => new Medicine {
                    Name = x.Name, NumberOfUse = 0
                }).ToList();

                if (newAllergies.Count > 0)
                {
                    _eyadtakDbContext.Allergies.AddRange(newAllergies);
                }
                if (newSigns.Count > 0)
                {
                    _eyadtakDbContext.Signs.AddRange(newSigns);
                }
                if (newSymptoms.Count > 0)
                {
                    _eyadtakDbContext.Symptoms.AddRange(newSymptoms);
                }
                if (newDiagnoses.Count > 0)
                {
                    _eyadtakDbContext.Diagnoses.AddRange(newDiagnoses);
                }
                if (newMedicines.Count > 0)
                {
                    _eyadtakDbContext.Medicines.AddRange(newMedicines);
                }

                if (newAllergies.Count > 0 || newSigns.Count > 0 || newSymptoms.Count > 0 || newDiagnoses.Count > 0 || newMedicines.Count > 0)
                {
                    _eyadtakDbContext.SaveChanges();
                }

                AllergiesController.AddAllergies(newAllergies);
                DiagnosesController.AddDiagnoses(newDiagnoses);
                MedicinesController.AddMedicines(newMedicines);
                SignsController.AddSigns(newSigns);
                SymptomsController.AddSymptoms(newSymptoms);

                PatientHistory patientHistory = new PatientHistory
                {
                    Note           = savePatientHistory.Note,
                    CheifComplaint = savePatientHistory.Complaint,
                    InsertDate     = DateTime.Now,
                    PatientId      = savePatientHistory.PatientId,
                };

                newAllergies.AddRange(savePatientHistory.Allergies.Where(x => x.Id != 0).Select(x => new Allergie {
                    AllergieId = x.Id, Name = x.Name
                }));
                patientHistory.PatientHistoryAllergies = newAllergies.Select(x => new PatientHistoryAllergie {
                    InsertTime = DateTime.Now, AllergieId = x.AllergieId, PatientHistoryId = patientHistory.PatientHistoryId
                }).ToList();

                newSigns.AddRange(savePatientHistory.Signs.Where(x => x.Id != 0).Select(x => new Sign {
                    SignId = x.Id, Name = x.Name
                }));
                patientHistory.PatientHistorySigns = newSigns.Select(x => new PatientHistorySign {
                    InsertTime = DateTime.Now, SignId = x.SignId, PatientHistoryId = patientHistory.PatientHistoryId
                }).ToList();

                newSymptoms.AddRange(savePatientHistory.Symptoms.Where(x => x.Id != 0).Select(x => new Symptom {
                    SymptomId = x.Id, Name = x.Name
                }));
                patientHistory.PatientHistorySymptoms = newSymptoms.Select(x => new PatientHistorySymptom {
                    InsertTime = DateTime.Now, SymptomId = x.SymptomId, PatientHistoryId = patientHistory.PatientHistoryId
                }).ToList();

                newDiagnoses.AddRange(savePatientHistory.Diagnoses.Where(x => x.Id != 0).Select(x => new Diagnosis {
                    DiagnosisId = x.Id, Name = x.Name
                }));
                patientHistory.PatientHistoryDiagnoses = newDiagnoses.Select(x => new PatientHistoryDiagnosis {
                    InsertTime = DateTime.Now, DiagnosisId = x.DiagnosisId, PatientHistoryId = patientHistory.PatientHistoryId
                }).ToList();

                newMedicines.AddRange(savePatientHistory.Medicines.Where(x => x.Id != 0).Select(x => new Medicine {
                    MedicineId = x.Id, Name = x.Name
                }));
                patientHistory.PatientHistoryMedicines = newMedicines.Select(x => new PatientHistoryMedicine {
                    InsertTime = DateTime.Now, MedicineId = x.MedicineId, PatientHistoryId = patientHistory.PatientHistoryId
                }).ToList();

                _eyadtakDbContext.PatientHistory.Add(patientHistory);
                _eyadtakDbContext.SaveChanges();

                Task.Run(() =>
                {
                    var options           = new DbContextOptionsBuilder <EyadtakContext>().UseSqlServer(_configuration.GetConnectionString("EyadtakDbConnectionString")).Options;
                    var _eyadtakDbContext = new EyadtakContext(options);

                    var allergies = _eyadtakDbContext.Allergies.Where(x => newAllergies.Select(x => x.AllergieId).Contains(x.AllergieId)).ToList();
                    foreach (var allergie in allergies)
                    {
                        allergie.NumberOfUse += 1;
                    }

                    var signs = _eyadtakDbContext.Signs.Where(x => newSigns.Select(x => x.SignId).Contains(x.SignId)).ToList();
                    foreach (var sign in signs)
                    {
                        sign.NumberOfUse += 1;
                    }

                    var symptoms = _eyadtakDbContext.Symptoms.Where(x => newSymptoms.Select(x => x.SymptomId).Contains(x.SymptomId)).ToList();
                    foreach (var symptom in symptoms)
                    {
                        symptom.NumberOfUse += 1;
                    }

                    var diagnoses = _eyadtakDbContext.Diagnoses.Where(x => newDiagnoses.Select(x => x.DiagnosisId).Contains(x.DiagnosisId)).ToList();
                    foreach (var diagnosis in diagnoses)
                    {
                        diagnosis.NumberOfUse += 1;
                    }

                    var medicines = _eyadtakDbContext.Medicines.Where(x => newMedicines.Select(x => x.MedicineId).Contains(x.MedicineId)).ToList();
                    foreach (var medicine in medicines)
                    {
                        medicine.NumberOfUse += 1;
                    }

                    _eyadtakDbContext.SaveChanges();
                });

                return(Ok(new { message = "Patient history saved successfully", ErrorHappen = false }));
            }
            catch (Exception e)
            {
                return(Ok(new { message = "Something went wrong", ErrorHappen = true }));

                throw e;
            }
        }