Api-PWA/DocuMed.PWA/Pages/MedicalHistoryTemplateActio.../MedicalHistoryTemplateActio...

110 lines
4.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

@inject IRestWrapper RestWrapper
@inject ISnackbar Snackbar
<MudStack class="pb-20 font-iranyekan">
<BasePartDivider Index="2" Title="تاریخچه بیماری فعلی ( PI )" />
<MudAlert Severity="Severity.Info">شما میتوانید سوال های هر بخش ها را به صورت کامل تنظیم نمایید</MudAlert>
@foreach (var item in PiQuestions)
{
<MedicalHistoryQuestionTemplateItemTemplate Question="@item" QuestionRemoved="RemoveQuestion" />
}
<MudSelect @bind-Value="@_questionType" T="MedicalHistoryQuestionType" ToStringFunc="(e=>e.ToDisplay())" Label="نوع سوال" Variant="Variant.Outlined">
<MudSelectItem Value="@MedicalHistoryQuestionType.Hourly" />
<MudSelectItem Value="@MedicalHistoryQuestionType.Interrogatively" />
<MudSelectItem Value="@MedicalHistoryQuestionType.YesOrNo" />
</MudSelect>
<MudTextField @bind-Value="@_questionTitle" Margin="Margin.None" T="string" Label="عنوان سوال" Lines="1"
Variant="Variant.Outlined" />
@* <MudAutocomplete T="string" Label="وابستگی به سوال قبلی" Variant="Variant.Outlined" /> *@
<MudButton @onclick="AddQuestion" Variant="Variant.Filled" DisableElevation="true"
class="font-extrabold text-lg right-0 rounded-md py-3 bg-[--color-medicalhistory] text-gray-800">
+ افزودن
</MudButton>
@AiResponse
<button @onclick="AskWithAi" class="relative inline-flex h-12 overflow-hidden rounded-full p-[1px] ">
<span class="absolute inset-[-1000%] animate-[spin_2s_linear_infinite] bg-[conic-gradient(from_90deg_at_50%_50%,#E2CBFF_0%,#393BB2_50%,#E2CBFF_100%)]"></span>
<span class="inline-flex h-full w-full cursor-pointer items-center justify-center rounded-full bg-white px-4 py-2 text-sm font-medium text-black backdrop-blur-3xl">
<p class="font-bold bg-gradient-to-r from-sky-600 via-violet-500 to-fuchsia-400 inline-block text-transparent bg-clip-text">
از هوش مصنوعی بپرس !
</p>
</span>
</button>
@if (IsProcessing)
{
<p class="mx-2 -mt-2 bg-gradient-to-r from-sky-600 via-blue-500 to-violet-400 inline-block text-transparent bg-clip-text">
در حال فکر کردن ....
</p>
}
</MudStack>
@* focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 focus:ring-offset-slate-50 *@
@code
{
private MedicalHistoryQuestionType _questionType;
private string _questionTitle = string.Empty;
private MedicalHistoryPart _questionPart = MedicalHistoryPart.PresentIllness;
private bool IsProcessing { get; set; }
private MarkupString AiResponse { get; set; }
[Parameter]
public List<MedicalHistoryQuestionSDto> PiQuestions { get; set; } = new();
[Parameter]
public string ChiefComplaint { get; set; } = string.Empty;
private void RemoveQuestion(MedicalHistoryQuestionSDto question)
{
PiQuestions.Remove(question);
}
private void AddQuestion()
{
PiQuestions.Add(new MedicalHistoryQuestionSDto
{
Part = _questionPart,
Question = _questionTitle,
QuestionType = _questionType
});
_questionTitle = string.Empty;
}
private async Task AskWithAi()
{
try
{
IsProcessing = true;
var request = new
{
content = $"شکایت اصلی بیمار (CC) {ChiefComplaint} است. لطفاً سوالات بخش PI (Present Illness) را در سه دسته زیر تولید کنید: سوالات توضیحی (Open-ended): سوالاتی که بیمار باید توضیح دهد. سوالات بله/خیر (Yes/No): سوالاتی که پاسخ مشخص بله یا خیر دارند. سوالات زمانی (Time-based): سوالاتی مرتبط با زمان شروع، مدت و تغییرات مشکل. لطفاً سوالات مرتبط با سردرد شامل شدت، محل، عوامل تشدیدکننده یا تسکین‌دهنده و علائم همراه (مثل تهوع یا تاری دید) باشد. use html concept for response and just send html and remove , head , html and body tag"
};
var response = await RestWrapper.AiRestApi.ChatAsync(request);
response = response.Replace("```html", null);
response = response.Replace("```", null);
response = response.Replace("\\n", null);
response = response.Replace(@"""", null);
AiResponse = (MarkupString)response;
}
catch (ApiException ex)
{
var exe = await ex.GetContentAsAsync<ApiResult>();
Snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error);
}
catch (Exception e)
{
Snackbar.Add(e.Message, Severity.Error);
}
finally
{
IsProcessing = false;
}
}
}