Esempio n. 1
0
        /// <summary>
        ///   Конвертер из DTO (data transport objet) в ViewModel (модель представления)
        /// </summary>
        /// <param name="patientDto"></param>
        /// <returns></returns>
        private static FullPatientViewModel FromDtoToViewModel(PatientDto patientDto)
        {
            var patient = FullPatientViewModel.FromPatientDto(patientDto);
            var context = StateContext.FromState(patientDto.PatientState.StateType);

            patient.Status.Description  = context.Description;
            patient.Status.Medicines    = TypeViewModel.FromCustomEnums(context.Medicines);
            patient.Status.PatientState = patientDto.PatientState.StateType;
            return(patient);
        }
Esempio n. 2
0
        /// <summary>
        ///   Получение истории пациента. Всех его состояний и статусов  в хронологическом порядке
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns>История пациента</returns>
        public async Task <HistoryViewModel> GetPatientHistory(int patientId)
        {
            Logger.LogInformation($"{nameof(PatientService)}.{nameof(GetPatientHistory)}: Start.");

            var patientDb = await Db.GetPatientAsync(patientId);

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

            var patient = FromDtoToViewModel(patientDb);

            var statusesDb = await Db.GetStatusesAsync(patientId);

            var statesDb = await Db.GetStatesAsync(patientId);

            var statuses = new List <StatusViewModel>();

            foreach (var stateDb in statesDb)
            {
                var statusDb    = statusesDb.Find(x => x.StatusId == stateDb.StatusId);
                var context     = StateContext.FromState(stateDb.StateType);
                var description = context.Description;
                var medicines   = TypeViewModel.FromCustomEnums(context.Medicines);

                var status = new StatusViewModel
                {
                    CreatedDate  = statusDb.CreatedDate,
                    StatusId     = statusDb.StatusId,
                    Parameters   = statusDb.Parameters,
                    Description  = description,
                    Medicines    = medicines,
                    PatientState = stateDb.StateType
                };
                statuses.Add(status);
            }

            var history = new HistoryViewModel
            {
                Patient  = patient,
                Statuses = new ListViewModel <StatusViewModel> {
                    Count = statuses.Count, List = statuses
                }
            };

            Logger.LogInformation($"{nameof(PatientService)}.{nameof(GetPatientHistory)}: End.");
            return(history);
        }