예제 #1
0
        public async Task <List <Appointment> > GetAllAppointmentsForDoctor(int doctorId)
        {
            var uri = $"{ApiConfiguration.GetBaseUrl()}/Doctor/{doctorId}/Appointment";

            _httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", AuthenticationUtils.GetUserToken(_httpContextAccessor.HttpContext));

            HttpResponseMessage response;

            try
            {
                response = await _httpClient.GetAsync(uri);
            }
            catch (Exception)
            {
                return(null);
            }

            List <Appointment> appointments = null;

            if (response.IsSuccessStatusCode)
            {
                appointments = JsonUtils.Deserialize <List <Appointment> >(await response.Content.ReadAsStringAsync());
            }

            return(appointments);
        }
예제 #2
0
        public async Task <List <Reason> > GetAllAppointmentReasons()
        {
            var uri = $"{ApiConfiguration.GetBaseUrl()}/Reason";

            _httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", AuthenticationUtils.GetUserToken(_httpContextAccessor.HttpContext));

            HttpResponseMessage response;

            try
            {
                Log.Debug($"GET request, URI = {uri}");
                response = await _httpClient.GetAsync(uri);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "GET appointment/reason failed");
                return(null);
            }

            List <Reason> reasons = null;

            if (response.IsSuccessStatusCode)
            {
                Log.Debug("GET appointment/reason request success");
                reasons = JsonUtils.Deserialize <List <Reason> >(await response.Content.ReadAsStringAsync());
            }
            else
            {
                Log.Error($"GET appointment/reason failed, status code = {response.StatusCode}");
            }

            return(reasons);
        }
예제 #3
0
        public async Task <bool> CancelAppointment(int appointmentId)
        {
            var uri = $"{ApiConfiguration.GetBaseUrl()}/Appointment/{appointmentId}";

            _httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", AuthenticationUtils.GetUserToken(_httpContextAccessor.HttpContext));

            HttpResponseMessage response;

            try
            {
                Log.Debug($"DELETE request, URI={uri}");
                response = await _httpClient.DeleteAsync(uri);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "DELETE appointment failed");
                return(false);
            }


            if (!response.IsSuccessStatusCode)
            {
                Log.Error($"DELETE appointment failed, status code = {response.StatusCode}");
                return(false);
            }

            Log.Debug("DELETE appointment request success");
            return(true);
        }
        public async Task <Patient> GetPatient(int patientId)
        {
            var uri = $"{ApiConfiguration.GetBaseUrl()}/Patient/{patientId}";

            _httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", AuthenticationUtils.GetUserToken(_httpContextAccessor.HttpContext));

            HttpResponseMessage response;

            try
            {
                Log.Debug($"GET request, URI = {uri}");
                response = await _httpClient.GetAsync(uri);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "GET Patient failed");
                return(null);
            }

            Patient patient = null;

            if (response.IsSuccessStatusCode)
            {
                Log.Debug("GET Patient succeeded");
                patient = JsonUtils.Deserialize <Patient>(await response.Content.ReadAsStringAsync());
            }
            else
            {
                Log.Error($"GET Patient failed, status code = {response.StatusCode}");
            }

            return(patient);
        }
예제 #5
0
        public async Task <AppointmentSetResponse> SetAppointment(Appointment appointment)
        {
            var uri = $"{ApiConfiguration.GetBaseUrl()}/Appointment";

            _httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", AuthenticationUtils.GetUserToken(_httpContextAccessor.HttpContext));

            var appointmentJson = JsonUtils.Serialize(appointment);

            HttpResponseMessage response;

            try
            {
                Log.Debug($"POST request, URI = {uri}, Content = {appointmentJson}");
                response = await _httpClient.PostAsync(uri, new StringContent(appointmentJson, Encoding.UTF8, "application/json"));
            }
            catch (Exception ex)
            {
                Log.Error(ex, "POST Appointment failed");
                //TODO This is just for fun - noone will see it
                return(AppointmentSetResponse.DOCTOR_NOT_AVAILABLE);
            }

            if (response.StatusCode == System.Net.HttpStatusCode.Conflict)
            {
                Log.Debug("POST Date not available");
                return(AppointmentSetResponse.DATE_NOT_AVAILABLE);
            }

            if (!response.IsSuccessStatusCode)
            {
                Log.Error($"POST Appointment failed, status code = {response.StatusCode}");
                //TODO Change this once server returns this option
                return(AppointmentSetResponse.DATE_NOT_AVAILABLE);
            }

            Log.Debug("POST Appointment success");
            return(AppointmentSetResponse.CORRECT);
        }