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

204 lines
9.1 KiB
Plaintext

@inject IRestWrapper RestWrapper
@inject ISnackbar Snackbar
<MudStack class="pb-20 font-iranyekan">
<BasePartDivider Index="3" Title="تاریخچه بیماری قبلی ( PMH )" />
@foreach (var item in PdhQuestions)
{
<MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemovePiQuestion" />
}
<MudSelect @bind-Value="@_pdhQuestionType" 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="@_pdhQuestionTitle" Margin="Margin.None" T="string" Label="عنوان سوال" Lines="1"
Variant="Variant.Outlined" />
<MudButton @onclick="AddPiQuestion" Variant="Variant.Filled" IconSize="Size.Large" DisableElevation="true"
class="font-extrabold text-lg rounded-md py-4 bg-[--color-medicalhistory] text-gray-800">
+ افزودن
</MudButton>
@AiPMHResponse
<button @onclick="AskPMHWithAi" 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>
}
<BasePartDivider Index="4" class="mt-9" Title="تاریخچه جراحی های قبلی ( PSH )" />
@foreach (var item in PshQuestions)
{
<MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemovePshQuestion" />
}
<MudSelect @bind-Value="@_pshQuestionType"
ToStringFunc="(e=>e.ToDisplay())"
T="MedicalHistoryQuestionType"
Label="نوع سوال"
Variant="Variant.Outlined">
<MudSelectItem Value="@MedicalHistoryQuestionType.Hourly" />
<MudSelectItem Value="@MedicalHistoryQuestionType.Interrogatively" />
<MudSelectItem Value="@MedicalHistoryQuestionType.YesOrNo" />
</MudSelect>
<MudTextField @bind-Value="@_pshQuestionTitle"
Margin="Margin.None"
T="string"
Label="عنوان سوال" Lines="1"
Variant="Variant.Outlined" />
<MudButton @onclick="AddPshQuestion" Variant="Variant.Filled" IconSize="Size.Large" DisableElevation="true"
class="font-extrabold text-lg rounded-md py-4 bg-[--color-medicalhistory] text-gray-800">
+ افزودن
</MudButton>
@AiPSHResponse
<button @onclick="AskPSHWithAi" 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>
@code
{
[Parameter]
public List<MedicalHistoryQuestionSDto> PdhQuestions { get; set; } = new();
[Parameter]
public List<MedicalHistoryQuestionSDto> PshQuestions { get; set; } = new();
private string _pdhQuestionTitle = string.Empty;
private MedicalHistoryQuestionType _pdhQuestionType;
private string _pshQuestionTitle = string.Empty;
private MedicalHistoryQuestionType _pshQuestionType;
[Parameter]
public string ChiefComplaint { get; set; } = string.Empty;
private void RemovePiQuestion(MedicalHistoryQuestionSDto question)
{
PdhQuestions.Remove(question);
}
private void AddPiQuestion()
{
PdhQuestions.Add(new MedicalHistoryQuestionSDto
{
QuestionType = _pdhQuestionType,
Part = MedicalHistoryPart.PastDiseasesHistory,
Question = _pdhQuestionTitle
});
_pdhQuestionTitle = string.Empty;
}
private void RemovePshQuestion(MedicalHistoryQuestionSDto question)
{
PshQuestions.Remove(question);
}
private void AddPshQuestion()
{
PshQuestions.Add(new MedicalHistoryQuestionSDto
{
Part = MedicalHistoryPart.PastSurgeryHistory,
QuestionType = _pshQuestionType,
Question = _pshQuestionTitle
});
_pshQuestionTitle = string.Empty;
}
private bool IsProcessing { get; set; }
private MarkupString AiPMHResponse { get; set; }
private async Task AskPMHWithAi()
{
try
{
IsProcessing = true;
var request = new
{
content = $"شکایت اصلی بیمار (CC) {ChiefComplaint} است. لطفاً سوالات بخش تاریخچه بیماری قبلی ( Past Medical History ) را در سه دسته زیر تولید کنید: سوالات توضیحی (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);
AiPMHResponse = (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;
}
}
private MarkupString AiPSHResponse { get; set; }
private async Task AskPSHWithAi()
{
try
{
IsProcessing = true;
var request = new
{
content = $"شکایت اصلی بیمار (CC) {ChiefComplaint} است. لطفاً سوالات بخش تاریخچه جراحی های قبلی ( Past Surgery History ) را در سه دسته زیر تولید کنید: سوالات توضیحی (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);
AiPSHResponse = (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;
}
}
}