public PatientProcedureEditModel BuildModel(PatientProcedureEditModel model)
        {
            var proceduresRepository = _unitOfWork.GetRepository<Procedure>();
            var procedures = proceduresRepository.Get();
            model.Procedures = procedures.Select(x => _procedureModelConverter.ConvertToModel(x)).ToList();

            var doctorsRepository = _unitOfWork.GetRepository<Doctor>();
            var doctors = doctorsRepository.Get();
            model.Doctors = doctors.Select(x => _doctorModelConverter.ConvertToModel(x)).ToList();

            var consentRepository = _unitOfWork.GetRepository<ConsentForm>();
            model.Consents = consentRepository.Get().Select(x => _consentFormModelConverter.ConvertToModel(x)).ToList();

            var agentRepository = _unitOfWork.GetRepository<Agent>();

            var financials = agentRepository.Get(x => x.Type == AgentType.FinanceCoordinator);
            model.FinancialCoordinators = financials.Select(x => _agentModelConverter.ConvertToModel(x)).ToList();

            var homeAways = agentRepository.Get(x => x.Type == AgentType.HomeAwayAssistant);
            model.HomeAwayAssistants = homeAways.Select(x => _agentModelConverter.ConvertToModel(x)).ToList();

            var medical = agentRepository.Get(x => x.Type == AgentType.MedicalAssistant);
            model.MedicalAssistants = medical.Select(x => _agentModelConverter.ConvertToModel(x)).ToList();

            var placeRepository = _unitOfWork.GetRepository<Place>();
            model.Places = placeRepository.Get().Select(x => _placeModelConverter.ConvertToModel(x)).ToList();

            return model;
        }
        public ActionResult Edit(PatientProcedureEditModel viewModel)
        {
            if (ModelState.IsValid)
            {
                _patientProcedureViewRepository.Update(viewModel);
                return RedirectToAction("Index");
            }

            var rebuilt = _modelConverter.BuildModel(viewModel);
            return View(rebuilt);
        }
        public UserProcedure ConvertToSource(PatientProcedureEditModel model)
        {
            var existing = _unitOfWork.GetRepository<UserProcedure>().FindById(model.Id) ?? new UserProcedure();

            var selectedProcedure = _unitOfWork.GetRepository<Procedure>().FindById(model.SelectedProcedure);
            var patient = _unitOfWork.GetRepository<Patient>().FindById(model.PatientId.Value);

            existing.Procedure = selectedProcedure;
            existing.ProcedureId = model.SelectedProcedure;
            existing.Patient = patient;
            existing.PatientId = patient.Id;
            existing.PlaceId = model.SelectedPlace;
            return existing;
        }