Example #1
0
        /// <summary>
        ///   Добавление статус пациенту
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="parameters"></param>
        /// <returns>Новый статус пациента</returns>
        public async Task <StatusDto> AddStatusAsync(int patientId, ParametersDto parameters)
        {
            var patient = await Db.PatientEntities.FirstOrDefaultAsync(x => x.PatientId == patientId);

            var newStatus = new StatusEntity
            {
                PatientId        = patientId,
                PreviousStatusId = patient.StatusId,
                IsHospitalized   = parameters.IsHospitalized,
                IsWheezing       = parameters.IsWheezing,
                Pef         = parameters.Pef,
                SpO2        = parameters.SpO2,
                CreatedDate = DateTime.UtcNow
            };

            Db.StatusEntities.Add(newStatus);
            Db.SaveChanges();

            patient.StatusId = newStatus.StatusId;
            await Db.SaveChangesAsync();

            var result = StatusDto.FromEntity(newStatus);

            return(result);
        }
Example #2
0
        /// <summary>
        ///   Получение списка всех статусов конкретного пациента
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns>Список статусов</returns>
        public async Task <List <StatusDto> > GetStatusesAsync(int patientId)
        {
            var result = await Db.StatusEntities.Where(x => x.PatientId == patientId).OrderBy(x => x.CreatedDate)
                         .Select(status => StatusDto.FromEntity(status)).ToListAsync();

            return(result);
        }
Example #3
0
        /// <summary>
        ///   Получение определенного статуса определенного пациента
        /// </summary>
        /// <param name="patientId"></param>
        /// <param name="statusId"></param>
        /// <returns>Статус пациента</returns>
        public async Task <StatusDto> GetStatusAsync(int patientId, int statusId)
        {
            var status = await Db.StatusEntities.FirstOrDefaultAsync(x => x.PatientId == patientId && x.StatusId == statusId);

            var result = StatusDto.FromEntity(status);

            return(result);
        }
Example #4
0
        /// <summary>
        ///   Создает пациента в базе данных
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="birthDate"></param>
        /// <param name="sexType"></param>
        /// <returns>Новый пациент</returns>
        public async Task <PatientDto> CreatePatientAsync(string firstName, string lastName, DateTime birthDate,
                                                          GenderType sexType)
        {
            var newPatient = new PatientEntity
            {
                FirstName    = firstName,
                LastName     = lastName,
                BirthDate    = birthDate,
                GenderTypeId = sexType.Id
            };

            Db.PatientEntities.Add(newPatient);
            await Db.SaveChangesAsync();

            var newStatus = new StatusEntity
            {
                CreatedDate      = DateTime.UtcNow,
                PatientId        = newPatient.PatientId,
                PreviousStatusId = 0
            };

            Db.StatusEntities.Add(newStatus);
            await Db.SaveChangesAsync();

            newStatus.PreviousStatusId = newStatus.StatusId;
            await Db.SaveChangesAsync();

            var newState = new StateEntity
            {
                CreatedDate     = DateTime.UtcNow,
                PatientId       = newPatient.PatientId,
                StatusId        = newStatus.StatusId,
                PreviousStateId = 0,
                StateTypeId     = StateType.Initial.Id
            };

            Db.StateEntities.Add(newState);
            await Db.SaveChangesAsync();

            newState.PreviousStateId = newState.StatusId;
            await Db.SaveChangesAsync();

            newPatient.StatusId = newStatus.StatusId;
            newPatient.StateId  = newState.StateId;

            await Db.SaveChangesAsync();

            var result = PatientDto.FromEntity(newPatient);

            result.Status       = StatusDto.FromEntity(newStatus);
            result.PatientState = StateDto.FromEntity(newState);

            return(result);
        }
Example #5
0
        /// <summary>
        ///   Получение конкретного пациента
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns>Определенный пациент</returns>
        public async Task <PatientDto> GetPatientAsync(int patientId)
        {
            var patient = await Db.PatientEntities.FirstOrDefaultAsync(x => x.PatientId == patientId);

            if (patient == null)
            {
                return(null);
            }

            var state = await Db.StateEntities.FirstOrDefaultAsync(x => x.StateId == patient.StateId);

            var status = await Db.StatusEntities.FirstOrDefaultAsync(x => x.StatusId == patient.StatusId);

            var result = PatientDto.FromEntity(patient);

            result.Status       = StatusDto.FromEntity(status);
            result.PatientState = StateDto.FromEntity(state);

            return(result);
        }