예제 #1
0
        public Result <PatientDeseaseScreeningDto> GetPatientDeseaseScreenings(int patientId)
        {
            Result <PatientDeseaseScreeningDto> response = new Result <PatientDeseaseScreeningDto>();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                IEnumerable <DeseaseScreening>        DeseaseScreenings        = unitOfWork.DeseaseScreeningRepository.GetEntities();
                IEnumerable <PatientDeseaseScreening> patientDeseaseScreenings = unitOfWork.PatientDeseaseScreeningRepository.GetEntities(item => item.PatientId == patientId, p => p.OrderBy(o => o.DeseaseScreening.SortKey));

                foreach (DeseaseScreening DeseaseScreening in DeseaseScreenings)
                {
                    DeseaseScreeningDto     DeseaseScreeningDto     = _DeseaseScreeningMapper.MapToDeseaseScreeningDto(DeseaseScreening);
                    PatientDeseaseScreening patientDeseaseScreening = patientDeseaseScreenings.Where(item => item.DeseaseScreeningId == DeseaseScreening.DeseaseScreeningId).FirstOrDefault();

                    PatientDeseaseScreeningDto patientDeseaseScreeningDto = new PatientDeseaseScreeningDto()
                    {
                        PatientDeseaseScreeningId = patientDeseaseScreening == null ? default(int?) : patientDeseaseScreening.PatientDeseaseScreeningId,
                        PatientId        = patientId,
                        DeseaseScreening = DeseaseScreeningDto,
                        YearOfScreening  = patientDeseaseScreening == null ? default(int?) : patientDeseaseScreening.YearOfScreening,
                        Value            = patientDeseaseScreening == null ? null : patientDeseaseScreening.Value,
                        SelectedInd      = patientDeseaseScreening == null ? false : true
                    };

                    response.Models.Add(patientDeseaseScreeningDto);
                }
            }

            return(response);
        }
예제 #2
0
        public void MapToPatientDeseaseScreening(PatientDeseaseScreening patientDeseaseScreening, PatientDeseaseScreeningDto patientDeseaseScreeningDto)
        {
            if (patientDeseaseScreeningDto == null)
            {
                return;
            }

            patientDeseaseScreening.PatientId = patientDeseaseScreeningDto.PatientId;

            if (patientDeseaseScreeningDto.DeseaseScreening != null && patientDeseaseScreeningDto.DeseaseScreening.DeseaseScreeningId != null)
            {
                patientDeseaseScreening.DeseaseScreeningId = patientDeseaseScreeningDto.DeseaseScreening.DeseaseScreeningId.Value;
            }

            patientDeseaseScreening.Value           = patientDeseaseScreeningDto.Value;
            patientDeseaseScreening.YearOfScreening = patientDeseaseScreeningDto.YearOfScreening;
        }
예제 #3
0
        public PatientDeseaseScreeningDto MapToPatientDeseaseScreeningDto(PatientDeseaseScreening patientDeseaseScreening)
        {
            if (patientDeseaseScreening == null)
            {
                return(null);
            }

            PatientDeseaseScreeningDto patientDeseaseScreeningDto = new PatientDeseaseScreeningDto();

            patientDeseaseScreeningDto.PatientDeseaseScreeningId = patientDeseaseScreening.PatientDeseaseScreeningId;
            patientDeseaseScreeningDto.PatientId        = patientDeseaseScreening.PatientId;
            patientDeseaseScreeningDto.DeseaseScreening = _DeseaseScreeningMapper.MapToDeseaseScreeningDto(patientDeseaseScreening.DeseaseScreening);
            patientDeseaseScreeningDto.Value            = patientDeseaseScreening.Value;
            patientDeseaseScreeningDto.YearOfScreening  = patientDeseaseScreening.YearOfScreening;
            patientDeseaseScreeningDto.SelectedInd      = true;

            return(patientDeseaseScreeningDto);
        }
예제 #4
0
        public Response <PatientDeseaseScreeningDto> SavePatientDeseaseScreenings(List <PatientDeseaseScreeningDto> patientDeseaseScreenings)
        {
            Response <PatientDeseaseScreeningDto> response = new Response <PatientDeseaseScreeningDto>();

            foreach (PatientDeseaseScreeningDto patientDeseaseScreeningDto in patientDeseaseScreenings)
            {
                response = _PatientDeseaseScreeningBusinessRules.SaveCheck(patientDeseaseScreeningDto);
                if (response.HasErrors)
                {
                    return(response);
                }
            }

            using (TransactionScope scope = new TransactionScope())
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    unitOfWork.AutoDetectChanges = false;
                    unitOfWork.ValidateOnSave    = false;

                    try
                    {
                        foreach (PatientDeseaseScreeningDto patientDeseaseScreeningDto in patientDeseaseScreenings)
                        {
                            bool isNewPatientDeseaseScreening = false;
                            PatientDeseaseScreening patientDeseaseScreening = unitOfWork.PatientDeseaseScreeningRepository.GetByID(item => item.PatientId == patientDeseaseScreeningDto.PatientId &&
                                                                                                                                   item.DeseaseScreeningId == patientDeseaseScreeningDto.DeseaseScreening.DeseaseScreeningId.Value);

                            if (patientDeseaseScreening != null && !patientDeseaseScreeningDto.SelectedInd)
                            {
                                unitOfWork.PatientDeseaseScreeningRepository.Delete(patientDeseaseScreening);
                                continue;
                            }

                            if (!patientDeseaseScreeningDto.SelectedInd)
                            {
                                continue;
                            }

                            if (patientDeseaseScreening == null)
                            {
                                isNewPatientDeseaseScreening = true;
                                patientDeseaseScreening      = new PatientDeseaseScreening();
                            }

                            _PatientDeseaseScreeningMapper.MapToPatientDeseaseScreening(patientDeseaseScreening, patientDeseaseScreeningDto);

                            if (isNewPatientDeseaseScreening)
                            {
                                unitOfWork.PatientDeseaseScreeningRepository.Insert(patientDeseaseScreening);
                            }
                            else
                            {
                                unitOfWork.PatientDeseaseScreeningRepository.Update(patientDeseaseScreening);
                            }
                        }
                    }
                    finally
                    {
                        unitOfWork.AutoDetectChanges = true;
                    }

                    unitOfWork.Save();
                }

                scope.Complete();
            }

            return(response);
        }