Ejemplo n.º 1
0
        public async Task <Dictionary <ServiceDictionaryKey, object> > TryListPatients(HttpRequest request)
        {
            Dictionary <ServiceDictionaryKey, object> dictionary = new Dictionary <ServiceDictionaryKey, object>();

            try
            {
                int amountRequested = _queryHelper.ExtractIntegerFromRequestQuery("count", request);

                List <Patient> patients = await _patientRepository.List(amountRequested);

                PatientReturnModel[] returnModels = new PatientReturnModel[patients.Count];

                for (int i = 0; i < patients.Count; i++)
                {
                    returnModels[i] = new PatientReturnModel(patients[i]);
                }

                dynamic data = _messageSerializer.Serialize(returnModels);
                dictionary.Add(ServiceDictionaryKey.VALUE, data);
            }
            catch (Exception ex)
            {
                dictionary.AddErrorMessage(ServiceDictionaryKey.ERROR, ex, FeedbackHandler);
            }

            return(dictionary);
        }
Ejemplo n.º 2
0
        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);
        }