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

184 lines
7.5 KiB
Plaintext

@inject IRestWrapper RestWrapper
@inject ISnackbar Snackbar
<MudStack class="pb-20 font-iranyekan">
<BasePartDivider Index="5" Title="تاریخچه بیماری های خانوادگی ( FH )" />
@foreach (var item in FamilyHistories)
{
<MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemoveFamilyHistory" />
}
<MudSelect @bind-Value="@_familyHistoryQuestionType"
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="@_familyHistoryQuestionTitle" Margin="Margin.None" T="string" Label="عنوان سوال" Lines="1"
Variant="Variant.Outlined" />
<MudButton @onclick="AddFamilyHistory" Variant="Variant.Filled" IconSize="Size.Large" DisableElevation="true"
class="font-extrabold text-lg rounded-md py-4 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>
}
<BasePartDivider Index="6" class="mt-9" Title="داروهای مصرفی ( DH )" />
<div class="grid mx-1 gap-2 grid-cols-2 md:grid-cols-4">
@foreach (var item in DrugHistories)
{
<MudCard @onclick="()=>RemoveDrugHistory(item)" class="text-center">
<MudCardContent>
<p class="font-extrabold text-gray-600 text-md">@item.Question</p>
</MudCardContent>
</MudCard>
}
</div>
<div class="flex flex-row">
<MudTextField @bind-Value="@_drugHistoryName" class="grow" T="string" Label="نام دارو مورد نظر" Variant="Variant.Outlined" />
<MudButton Variant="Variant.Outlined" @onclick="AddDrugHistory" Color="Color.Info" IconSize="Size.Large" DisableElevation="false" class="mx-2 mt-1.5 mb-0.5 pt-2 text-4xl rounded-md">
+
</MudButton>
</div>
<BasePartDivider Index="7" class="mt-9" Title="مواد مصرفی ( HH )" />
<div class="grid mx-1 gap-2 grid-cols-2 md:grid-cols-4">
@foreach (var item in AhMedicines)
{
<MudCard @onclick="()=>RemoveHhMedicine(item)" class="text-center">
<MudCardContent>
<p class="font-extrabold text-gray-600 text-md">@item.Question</p>
</MudCardContent>
</MudCard>
}
</div>
<div class="flex flex-row">
<MudTextField @bind-Value="@_hhName" class="grow" T="string" Label="نام ماده مخدر مورد نظر" Variant="Variant.Outlined" />
<MudButton Variant="Variant.Outlined" @onclick="AddHhMedicine" Color="Color.Info" IconSize="Size.Large" DisableElevation="false" class="mx-2 mt-1.5 mb-0.5 pt-2 text-4xl rounded-md">
+
</MudButton>
</div>
</MudStack>
@code
{
private bool IsProcessing { get; set; }
private MarkupString AiResponse { get; set; }
[Parameter]
public string ChiefComplaint { get; set; } = string.Empty;
private string _familyHistoryQuestionTitle = string.Empty;
private MedicalHistoryQuestionType _familyHistoryQuestionType;
[Parameter]
public List<MedicalHistoryQuestionSDto> FamilyHistories { get; set; } = new();
private void RemoveFamilyHistory(MedicalHistoryQuestionSDto question)
{
FamilyHistories.Remove(question);
}
private void AddFamilyHistory()
{
FamilyHistories.Add(new MedicalHistoryQuestionSDto
{
Question = _familyHistoryQuestionTitle,
QuestionType = _familyHistoryQuestionType,
Part = MedicalHistoryPart.FamilyHistory
});
_familyHistoryQuestionTitle = String.Empty;
}
private string _drugHistoryName = string.Empty;
[Parameter]
public List<MedicalHistoryQuestionSDto> DrugHistories { get; set; } = new();
private void RemoveDrugHistory(MedicalHistoryQuestionSDto medicine)
{
DrugHistories.Remove(medicine);
}
private void AddDrugHistory()
{
DrugHistories.Add(new MedicalHistoryQuestionSDto
{
Question = _drugHistoryName,
QuestionType = MedicalHistoryQuestionType.Selective,
Part = MedicalHistoryPart.DrugHistory
});
_drugHistoryName = string.Empty;
}
private string _hhName = string.Empty;
[Parameter]
public List<MedicalHistoryQuestionSDto> AhMedicines { get; set; } = new();
private void RemoveHhMedicine(MedicalHistoryQuestionSDto medicine)
{
AhMedicines.Remove(medicine);
}
private void AddHhMedicine()
{
AhMedicines.Add(new MedicalHistoryQuestionSDto
{
Part = MedicalHistoryPart.AddictionHistory,
Question = _hhName,
QuestionType = MedicalHistoryQuestionType.Selective
});
_hhName = 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;
}
}
}