public Result <PatientChronicDeseaseDto> GetPatientChronicDeseases(int patientId)
        {
            Result <PatientChronicDeseaseDto> response = new Result <PatientChronicDeseaseDto>();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                IEnumerable <ChronicDesease>        ChronicDeseases        = unitOfWork.ChronicDeseaseRepository.GetEntities();
                IEnumerable <PatientChronicDesease> patientChronicDeseases = unitOfWork.PatientChronicDeseaseRepository.GetEntities(item => item.PatientId == patientId, p => p.OrderBy(o => o.ChronicDesease.SortKey));

                foreach (ChronicDesease ChronicDesease in ChronicDeseases)
                {
                    ChronicDeseaseDto     ChronicDeseaseDto     = _ChronicDeseaseMapper.MapToChronicDeseaseDto(ChronicDesease);
                    PatientChronicDesease patientChronicDesease = patientChronicDeseases.Where(item => item.ChronicDeseaseId == ChronicDesease.ChronicDeseaseId).FirstOrDefault();

                    PatientChronicDeseaseDto patientChronicDeseaseDto = new PatientChronicDeseaseDto()
                    {
                        PatientChronicDeseaseId = patientChronicDesease == null ? default(int?) : patientChronicDesease.PatientChronicDeseaseId,
                        PatientId       = patientId,
                        ChronicDesease  = ChronicDeseaseDto,
                        YearOfDiagnoses = patientChronicDesease == null ? default(int?) : patientChronicDesease.YearOfDiagnoses,
                        Value           = patientChronicDesease == null ? null : patientChronicDesease.Value,
                        SelectedInd     = patientChronicDesease == null ? false : true
                    };

                    response.Models.Add(patientChronicDeseaseDto);
                }
            }

            return(response);
        }
        public PatientChronicDeseaseDto MapToPatientChronicDeseaseDto(PatientChronicDesease patientChronicDesease)
        {
            if (patientChronicDesease == null)
            {
                return(null);
            }

            PatientChronicDeseaseDto patientChronicDeseaseDto = new PatientChronicDeseaseDto();

            patientChronicDeseaseDto.PatientChronicDeseaseId = patientChronicDesease.PatientChronicDeseaseId;
            patientChronicDeseaseDto.PatientId       = patientChronicDesease.PatientId;
            patientChronicDeseaseDto.ChronicDesease  = _ChronicDeseaseMapper.MapToChronicDeseaseDto(patientChronicDesease.ChronicDesease);
            patientChronicDeseaseDto.Value           = patientChronicDesease.Value;
            patientChronicDeseaseDto.YearOfDiagnoses = patientChronicDesease.YearOfDiagnoses;
            patientChronicDeseaseDto.SelectedInd     = true;

            return(patientChronicDeseaseDto);
        }
        public PatientChronicDeseaseViewModel MapToPatientChronicDeseaseViewModel(PatientChronicDeseaseDto patientChronicDeseaseDto)
        {
            if (patientChronicDeseaseDto == null)
            {
                return(null);
            }

            PatientChronicDeseaseViewModel patientChronicDeseaseViewModel = new PatientChronicDeseaseViewModel();

            patientChronicDeseaseViewModel.PatientChronicDeseaseId = patientChronicDeseaseDto.PatientChronicDeseaseId;
            patientChronicDeseaseViewModel.PatientId           = patientChronicDeseaseDto.PatientId;
            patientChronicDeseaseViewModel.ChronicDesease_Id   = patientChronicDeseaseDto.ChronicDesease.ChronicDeseaseId.Value;
            patientChronicDeseaseViewModel.ChronicDesease_Name = patientChronicDeseaseDto.ChronicDesease.Name;
            patientChronicDeseaseViewModel.ChronicDeseaseValue = patientChronicDeseaseDto.Value;
            patientChronicDeseaseViewModel.YearOfDiagnoses     = patientChronicDeseaseDto.YearOfDiagnoses;
            patientChronicDeseaseViewModel.SelectedInd         = patientChronicDeseaseDto.SelectedInd;

            return(patientChronicDeseaseViewModel);
        }
Ejemplo n.º 4
0
        public Response <PatientChronicDeseaseDto> SaveCheck(PatientChronicDeseaseDto patientChronicDeseaseDto)
        {
            Response <PatientChronicDeseaseDto> response = new Response <PatientChronicDeseaseDto>();

            if (patientChronicDeseaseDto.PatientId == int.MinValue)
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    ErrorMessage = "Patient does not exist."
                });
                return(response);
            }

            if (patientChronicDeseaseDto.ChronicDesease == null || patientChronicDeseaseDto.ChronicDesease.ChronicDeseaseId == null)
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    ErrorMessage = "The patient chronic desease has no chronic desease for it."
                });
                return(response);
            }

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                if (patientChronicDeseaseDto.PatientChronicDeseaseId != null && unitOfWork.PatientChronicDeseaseRepository.GetByID(item => item.PatientChronicDeseaseId == patientChronicDeseaseDto.PatientChronicDeseaseId) == null)
                {
                    response.HasErrors = true;
                    response.FieldErrors.Add(new FieldError()
                    {
                        ErrorMessage = "The patient chronic desease you trying to edit does not exist."
                    });
                    return(response);
                }
            }

            return(response);
        }
        public void MapToPatientChronicDesease(PatientChronicDesease patientChronicDesease, PatientChronicDeseaseDto patientChronicDeseaseDto)
        {
            if (patientChronicDeseaseDto == null)
            {
                return;
            }

            patientChronicDesease.PatientId = patientChronicDeseaseDto.PatientId;

            if (patientChronicDeseaseDto.ChronicDesease != null && patientChronicDeseaseDto.ChronicDesease.ChronicDeseaseId != null)
            {
                patientChronicDesease.ChronicDeseaseId = patientChronicDeseaseDto.ChronicDesease.ChronicDeseaseId.Value;
            }

            patientChronicDesease.Value           = patientChronicDeseaseDto.Value;
            patientChronicDesease.YearOfDiagnoses = patientChronicDeseaseDto.YearOfDiagnoses;
        }