Beispiel #1
0
        // This method is used to setup the data.
        public void Setup()
        {
            patientDetail = new PatientDetail()
            {
                ForeName = "Vishwa", SurName = "Reddy", Gender = "Male"
            };

            List <PatientDetail> lstPatient = new List <PatientDetail>();

            lstPatient.Add(new PatientDetail()
            {
                ForeName = "Vishwa", SurName = "Reddy", DateofBirth = DateTime.Now.AddDays(-20), Gender = "Male"
            });
            lstPatient.Add(new PatientDetail()
            {
                ForeName = "Aadit", SurName = "Reddy", DateofBirth = DateTime.Now.AddDays(-20), Gender = "Male"
            });
            PatientPagingModel patientPagingModel = new PatientPagingModel()
            {
                TotalRecords = 5, PatientDetails = lstPatient
            };

            ////Used MOQ framework to return predefined  data
            var PatientDemographicRepository = new Mock <IPatientDemographicsRepository>();

            PatientDemographicRepository.Setup(x => x.GetAllPatientDemographics(1, 4)).Returns(patientPagingModel);
            PatientDemographicRepository.Setup(x => x.PostPatientDetails(patientDetail)).Returns(true);
            _PatientDemographicsRepository = PatientDemographicRepository.Object;
        }
        //Returns all the Patient details with paging
        public PatientPagingModel GetAllPatientDemographics(int currentPage, int recordsPerPage)
        {
            PatientPagingModel   patientViewModel = new PatientPagingModel();
            List <PatientDetail> lstPatient       = new List <PatientDetail>();

            int skipRecords = (currentPage - 1) * (recordsPerPage);

            try
            {
                var patientContext = new PatientContext();

                var response = from patients in patientContext.Patients
                               orderby patients.PatientId
                               select new { X = patients };


                //To retrieve the total number of records found
                patientViewModel.TotalRecords = response.Count();

                //Pagination support
                var responseData = response.Skip(skipRecords).Take(recordsPerPage);

                foreach (var item in responseData)
                {
                    //Deserialize XML to object using extension method
                    PatientDetail patientDetail = item.X.PatientDetail.Deserialize <PatientDetail>();
                    lstPatient.Add(patientDetail);
                }
                patientViewModel.PatientDetails = lstPatient;

                return(patientViewModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }