public async Task <Dictionary <ServiceDictionaryKey, object> > TryGetPatientById(HttpRequest req, string idText) { Dictionary <ServiceDictionaryKey, object> dictionary = new Dictionary <ServiceDictionaryKey, object>(); if (!_queryHelper.IsValidId(dictionary, idText)) { return(dictionary); } try { int id = Int32.Parse(idText); // Auth try { if (!await IsAuthorized(dictionary, req, id)) { return(dictionary); } } catch { dictionary.Add(ServiceDictionaryKey.ERROR, "Auth threw an error. Has the token lifetime expired?"); dictionary.Add(ServiceDictionaryKey.HTTPSTATUSCODE, HttpStatusCode.Unauthorized); return(dictionary); } Patient patient = await _patientRepository.Select(id); if (patient.PatientId <= 0) { dictionary.Add(ServiceDictionaryKey.ERROR, $"No patient found for given ID: {id}."); dictionary.Add(ServiceDictionaryKey.HTTPSTATUSCODE, HttpStatusCode.NotFound); return(dictionary); } PatientReturnModel returnModel = new PatientReturnModel() { Id = patient.PatientId, DateOfBirth = patient.DateOfBirth, WeightInKilograms = patient.WeightInKilograms, FirstName = patient.FirstName, LastName = patient.LastName }; dynamic data = _messageSerializer.Serialize(returnModel); dictionary.Add(ServiceDictionaryKey.VALUE, data); } catch (Exception ex) { dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler); } return(dictionary); }