using Indotalent.ConfigBackEnd.Interfaces; using Indotalent.ConfigFrontEnd.Common; using Indotalent.Features.Thirdparty.Patient.Cqrs; using Indotalent.Infrastructure.Authentication.Identity; using Indotalent.Shared.Models; using Microsoft.AspNetCore.Components; using MudBlazor; using RestSharp; namespace Indotalent.Features.Thirdparty.Patient; public class PatientService : BaseService { private readonly RestClient _client; public PatientService( IHttpClientFactory clientFactory, NavigationManager nav, ISnackbar snackbar, ICurrentUserService currentUserService, TokenProvider tokenProvider) : base(clientFactory, nav, snackbar, currentUserService, tokenProvider) { _client = new RestClient(nav.BaseUri); } public async Task>?> GetPatientListAsync() { var request = new RestRequest("api/patient", Method.Get); return await ExecuteWithResponseAsync>(_client, request); } public async Task?> GetPatientByIdAsync(string id) { var request = new RestRequest($"api/patient/{id}", Method.Get); return await ExecuteWithResponseAsync(_client, request); } public async Task?> GetPatientLookupAsync() { var request = new RestRequest("api/patient/lookup", Method.Get); return await ExecuteWithResponseAsync(_client, request); } public async Task?> CreatePatientAsync(CreatePatientRequest data) { var request = new RestRequest("api/patient", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task DeletePatientByIdAsync(string id) { var request = new RestRequest($"api/patient/delete/{id}", Method.Post); var response = await ExecuteWithResponseAsync(_client, request); return response?.IsSuccess ?? false; } public async Task?> UpdatePatientAsync(UpdatePatientRequest data) { var request = new RestRequest("api/patient/update", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task?> CreatePatientContactAsync(CreatePatientContactRequest data) { var request = new RestRequest("api/patient/patient-contact", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task?> UpdatePatientContactAsync(UpdatePatientContactRequest data) { var request = new RestRequest("api/patient/patient-contact/update", Method.Post); request.AddJsonBody(data); return await ExecuteWithResponseAsync(_client, request); } public async Task DeletePatientContactAsync(string id) { var request = new RestRequest($"api/patient/patient-contact/delete/{id}", Method.Post); var response = await ExecuteWithResponseAsync(_client, request); return response?.IsSuccess ?? false; } }