public async SystemTasks.Task <PatientViewModel> GetPatient(string nhsNumber) { var patientViewModel = new PatientViewModel(); var bundle = await _patientService.GetPatientAsBundle(nhsNumber); var entries = bundle.Entry; var patient = ListEntries <Patient>(entries, ResourceType.Patient).FirstOrDefault(); var organisations = ListEntries <Organization>(entries, ResourceType.Organization); if (patient != null) { patientViewModel = patient.ToViewModel(FhirConstants.IdsNhsNumber); var gpPractice = organisations.FirstOrDefault(s => !string.IsNullOrWhiteSpace(s.Id) && s.Id == patientViewModel.ManagingOrganization?.Id); patientViewModel.GpPractice = gpPractice?.ToViewModel(FhirConstants.IdsOrgCode); } return(patientViewModel); }