public Result <PatientPastMedicalHistoryDto> GetPatientPastMedicalHistories(int patientId) { Result <PatientPastMedicalHistoryDto> response = new Result <PatientPastMedicalHistoryDto>(); using (UnitOfWork unitOfWork = new UnitOfWork()) { IEnumerable <PastMedicalHistory> PastMedicalHistorys = unitOfWork.PastMedicalHistoryRepository.GetEntities(); IEnumerable <PatientPastMedicalHistory> patientPastMedicalHistorys = unitOfWork.PatientPastMedicalHistoryRepository.GetEntities(item => item.PatientId == patientId, p => p.OrderBy(o => o.PastMedicalHistory.SortKey)); foreach (PastMedicalHistory PastMedicalHistory in PastMedicalHistorys) { PastMedicalHistoryDto PastMedicalHistoryDto = _PastMedicalHistoryMapper.MapToPastMedicalHistoryDto(PastMedicalHistory); PatientPastMedicalHistory patientPastMedicalHistory = patientPastMedicalHistorys.Where(item => item.PastMedicalHistoryId == PastMedicalHistory.PastMedicalHistoryId).FirstOrDefault(); PatientPastMedicalHistoryDto patientPastMedicalHistoryDto = new PatientPastMedicalHistoryDto() { PatientPastMedicalHistoryId = patientPastMedicalHistory == null ? default(int?) : patientPastMedicalHistory.PatientPastMedicalHistoryId, PatientId = patientId, PastMedicalHistory = PastMedicalHistoryDto, Value = patientPastMedicalHistory == null ? null : patientPastMedicalHistory.Value }; response.Models.Add(patientPastMedicalHistoryDto); } } return(response); }
public PastMedicalHistoryDto MapToPastMedicalHistoryDto(PastMedicalHistory pastMedicalHistory) { if (pastMedicalHistory == null) { return(null); } PastMedicalHistoryDto PastMedicalHistoryDto = new PastMedicalHistoryDto(); PastMedicalHistoryDto.PastMedicalHistoryId = pastMedicalHistory.PastMedicalHistoryId; PastMedicalHistoryDto.Name = pastMedicalHistory.Name; PastMedicalHistoryDto.SortKey = pastMedicalHistory.SortKey; return(PastMedicalHistoryDto); }
public PastMedicalHistory MapToPastMedicalHistory(PastMedicalHistoryDto pastMedicalHistoryDto) { if (pastMedicalHistoryDto == null) { return(null); } PastMedicalHistory pastMedicalHistory = new PastMedicalHistory(); if (pastMedicalHistoryDto.PastMedicalHistoryId != null) { pastMedicalHistory.PastMedicalHistoryId = pastMedicalHistoryDto.PastMedicalHistoryId.Value; } pastMedicalHistory.Name = pastMedicalHistoryDto.Name; pastMedicalHistory.SortKey = pastMedicalHistoryDto.SortKey; return(pastMedicalHistory); }