complete editing templates

master
Amir Hossein Khademi 2023-10-24 12:45:25 +03:30
parent 24b92acd4b
commit cc8aa32447
17 changed files with 401 additions and 120 deletions

View File

@ -1,5 +1,4 @@
using DocuMed.Api.Services;
using DocuMed.Domain.Dtos.LargDtos;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace DocuMed.Api.Controllers;
@ -30,49 +29,28 @@ public class MedicalHistoryTemplateController : ICarterModule
// GET:Get All Entity
public virtual async Task<IResult> GetAllAsync([FromQuery] int page, IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService, CancellationToken cancellationToken)
public virtual async Task<IResult> GetAllAsync([FromQuery] int page, IMedicalHistoryTemplateRepository repository, CancellationToken cancellationToken)
{
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var list = await repositoryWrapper.SetRepository<MedicalHistoryTemplate>().TableNoTracking
.Where(t=>t.ApplicationUserId== userId)
.OrderByDescending(t=>t.CreatedAt)
.Skip(page*15)
.Take(15)
.Select(MedicalHistoryTemplateMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return TypedResults.Ok(list);
return TypedResults.Ok(await repository.GetMedicalHistoryTemplatesAsync(page,cancellationToken));
}
// GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IRepositoryWrapper repositoryWrapper,
CancellationToken cancellationToken)
=> TypedResults.Ok(await repositoryWrapper.SetRepository<MedicalHistoryTemplate>()
.GetByIdAsync(cancellationToken, id));
public async Task<IResult> GetAsync(Guid id, IMedicalHistoryTemplateRepository repository, CancellationToken cancellationToken)
{
return TypedResults.Ok(await repository.GetMedicalHistoryTemplateAsync(id, cancellationToken));
}
// POST:Add New Entity
public virtual async Task<IResult> Post([FromBody] MedicalHistoryTemplateLDto dto, IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService, CancellationToken cancellationToken)
public virtual async Task<IResult> Post([FromBody] MedicalHistoryTemplateLDto dto, IMedicalHistoryTemplateService service, ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var ent = MedicalHistoryTemplate.Create(dto.ChiefComplaint,dto.SectionId, userId);
foreach (var question in dto.Questions)
ent.AddQuestion(question.Question, question.Part, question.QuestionType);
repositoryWrapper.SetRepository<MedicalHistoryTemplate>().Add(ent);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return TypedResults.Ok();
return TypedResults.Ok(await service.AddAsync(dto,cancellationToken));
}
// PUT:Update Entity
public virtual async Task<IResult> Put([FromBody] MedicalHistoryTemplateLDto dto, IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService, CancellationToken cancellationToken)
public virtual async Task<IResult> Put([FromBody] MedicalHistoryTemplateLDto dto, IMedicalHistoryTemplateService service,ICurrentUserService currentUserService, CancellationToken cancellationToken)
{
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var ent = MedicalHistoryTemplate.Create(dto.ChiefComplaint, dto.SectionId, userId);
ent.Id = dto.Id;
repositoryWrapper.SetRepository<MedicalHistoryTemplate>().Update(ent);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return TypedResults.Ok();
return TypedResults.Ok(await service.EditAsync(dto, cancellationToken));
}
// DELETE:Delete Entity

View File

@ -71,6 +71,7 @@
<Using Include="DocuMed.Core.EntityServices.Abstracts" />
<Using Include="DocuMed.Core.Models.Api" />
<Using Include="DocuMed.Domain" />
<Using Include="DocuMed.Domain.Dtos.LargDtos" />
<Using Include="DocuMed.Domain.Dtos.RequestDtos" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.City" />
@ -85,6 +86,7 @@
<Using Include="DocuMed.Repository.Extensions" />
<Using Include="DocuMed.Repository.Models" />
<Using Include="DocuMed.Repository.Repositories.Base.Contracts" />
<Using Include="DocuMed.Repository.Repositories.Entities.Abstracts" />
<Using Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Microsoft.AspNetCore.Mvc" />

View File

@ -22,7 +22,6 @@
<ItemGroup>
<Folder Include="BaseServices\Abstracts\" />
<Folder Include="CoreServices\Abstracts\" />
<Folder Include="EntityServices\Abstracts\" />
<Folder Include="Models\Api\" />
<Folder Include="Abstracts\" />
</ItemGroup>
@ -37,6 +36,7 @@
<Using Include="DocuMed.Core.BaseServices.Abstracts" />
<Using Include="DocuMed.Core.CoreServices.Abstracts" />
<Using Include="DocuMed.Core.EntityServices.Abstracts" />
<Using Include="DocuMed.Domain.Dtos.LargDtos" />
<Using Include="DocuMed.Domain.Dtos.RequestDtos" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.User" />

View File

@ -0,0 +1,7 @@
namespace DocuMed.Core.EntityServices.Abstracts;
public interface IMedicalHistoryTemplateService:IScopedDependency
{
public Task<bool> EditAsync(MedicalHistoryTemplateLDto template, CancellationToken cancellationToken);
public Task<bool> AddAsync(MedicalHistoryTemplateLDto template, CancellationToken cancellationToken);
}

View File

@ -0,0 +1,61 @@
using DocuMed.Domain.Entities.MedicalHistoryTemplate;
using DocuMed.Repository.Repositories.Entities;
using DocuMed.Repository.Repositories.Entities.Abstracts;
using System.Threading;
namespace DocuMed.Core.EntityServices;
public class MedicalHistoryTemplateService : IMedicalHistoryTemplateService
{
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ICurrentUserService _currentUserService;
private readonly IMedicalHistoryTemplateRepository _medicalHistoryTemplateRepository;
public MedicalHistoryTemplateService(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService,IMedicalHistoryTemplateRepository medicalHistoryTemplateRepository)
{
_repositoryWrapper = repositoryWrapper;
_currentUserService = currentUserService;
_medicalHistoryTemplateRepository = medicalHistoryTemplateRepository;
}
public async Task<bool> EditAsync(MedicalHistoryTemplateLDto template, CancellationToken cancellationToken)
{
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
if (template.Id==Guid.Empty)
throw new AppException("پیش نویس پیدا نشد", ApiResultStatusCode.NotFound);
var ent = MedicalHistoryTemplate.Create(template.ChiefComplaint, template.SectionId, userId);
ent.Id = template.Id;
var questions = await _repositoryWrapper.SetRepository<MedicalHistoryQuestion>()
.TableNoTracking
.Where(q => q.MedicalHistoryTemplateId == ent.Id)
.ToListAsync(cancellationToken);
foreach (var question in questions)
{
if (template.Questions.FirstOrDefault(q => q.Id == question.Id) == null)
{
_repositoryWrapper.SetRepository<MedicalHistoryQuestion>()
.Delete(question);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
}
}
foreach (var question in template.Questions.Where(q=>q.Id==Guid.Empty))
ent.AddQuestion(question.Question, question.Part, question.QuestionType);
_medicalHistoryTemplateRepository.Update(ent);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
public async Task<bool> AddAsync(MedicalHistoryTemplateLDto template,CancellationToken cancellationToken)
{
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var ent = MedicalHistoryTemplate.Create(template.ChiefComplaint, template.SectionId, userId);
foreach (var question in template.Questions)
ent.AddQuestion(question.Question, question.Part, question.QuestionType);
_medicalHistoryTemplateRepository.Add(ent);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}

View File

@ -5,6 +5,7 @@ public class MedicalHistoryTemplateLDto : BaseDto<MedicalHistoryTemplateLDto,Med
public string ChiefComplaint { get; set; } = string.Empty;
public Guid SectionId { get; set; }
public SectionSDto Section { get; set; } = new();
public Guid ApplicationUserId { get; set; }
public List<MedicalHistoryQuestionSDto> Questions { get; set; } = new();
}

View File

@ -21,6 +21,7 @@ public partial class MedicalHistoryTemplate : ApiEntity
public string ChiefComplaint { get; internal set; } = string.Empty;
public Guid SectionId { get; set; }
public Section? Section { get; set; }
public Guid ApplicationUserId { get; internal set; }
public ApplicationUser? ApplicationUser { get; set; }
public List<MedicalHistoryQuestion> Questions { get; internal set; } = new();

View File

@ -31,7 +31,7 @@ namespace DocuMed.Domain.Mappers
return result;
}
public static Expression<Func<CitySDto, City>> ProjectLDtoToCity => p4 => new City()
public static Expression<Func<CitySDto, City>> ProjectToCity => p4 => new City()
{
Name = p4.Name,
Id = p4.Id
@ -85,7 +85,7 @@ namespace DocuMed.Domain.Mappers
return result;
}
public static Expression<Func<CityLDto, City>> ProjectToCity => p15 => new City()
public static Expression<Func<CityLDto, City>> ProjectLDtoToCity => p15 => new City()
{
Name = p15.Name,
Universities = p15.Universities.Select<UniversitySDto, University>(p16 => new University()

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Expressions;
using DocuMed.Domain.Dtos.LargDtos;
using DocuMed.Domain.Dtos.SmallDtos;
using DocuMed.Domain.Entities.City;
using DocuMed.Domain.Entities.MedicalHistoryTemplate;
namespace DocuMed.Domain.Mappers
@ -80,6 +81,13 @@ namespace DocuMed.Domain.Mappers
{
ChiefComplaint = p9.ChiefComplaint,
SectionId = p9.SectionId,
Section = p9.Section == null ? null : new Section()
{
Name = p9.Section.Name,
Detail = p9.Section.Detail,
UniversityId = p9.Section.UniversityId,
Id = p9.Section.Id
},
ApplicationUserId = p9.ApplicationUserId,
Questions = funcMain1(p9.Questions),
Id = p9.Id
@ -95,68 +103,91 @@ namespace DocuMed.Domain.Mappers
result.ChiefComplaint = p11.ChiefComplaint;
result.SectionId = p11.SectionId;
result.Section = funcMain2(p11.Section, result.Section);
result.ApplicationUserId = p11.ApplicationUserId;
result.Questions = funcMain2(p11.Questions, result.Questions);
result.Questions = funcMain3(p11.Questions, result.Questions);
result.Id = p11.Id;
return result;
}
public static Expression<Func<MedicalHistoryTemplateLDto, MedicalHistoryTemplate>> ProjectLDtoToMedicalHistoryTemplate => p15 => new MedicalHistoryTemplate()
public static Expression<Func<MedicalHistoryTemplateLDto, MedicalHistoryTemplate>> ProjectLDtoToMedicalHistoryTemplate => p17 => new MedicalHistoryTemplate()
{
ChiefComplaint = p15.ChiefComplaint,
SectionId = p15.SectionId,
ApplicationUserId = p15.ApplicationUserId,
Questions = p15.Questions.Select<MedicalHistoryQuestionSDto, MedicalHistoryQuestion>(p16 => new MedicalHistoryQuestion()
ChiefComplaint = p17.ChiefComplaint,
SectionId = p17.SectionId,
Section = p17.Section == null ? null : new Section()
{
Question = p16.Question,
Part = p16.Part,
QuestionType = p16.QuestionType,
MedicalHistoryTemplateId = p16.MedicalHistoryTemplateId,
Id = p16.Id
Name = p17.Section.Name,
Detail = p17.Section.Detail,
UniversityId = p17.Section.UniversityId,
Id = p17.Section.Id
},
ApplicationUserId = p17.ApplicationUserId,
Questions = p17.Questions.Select<MedicalHistoryQuestionSDto, MedicalHistoryQuestion>(p18 => new MedicalHistoryQuestion()
{
Question = p18.Question,
Part = p18.Part,
QuestionType = p18.QuestionType,
MedicalHistoryTemplateId = p18.MedicalHistoryTemplateId,
Id = p18.Id
}).ToList<MedicalHistoryQuestion>(),
Id = p15.Id
Id = p17.Id
};
public static MedicalHistoryTemplateLDto AdaptToLDto(this MedicalHistoryTemplate p17)
public static MedicalHistoryTemplateLDto AdaptToLDto(this MedicalHistoryTemplate p19)
{
return p17 == null ? null : new MedicalHistoryTemplateLDto()
return p19 == null ? null : new MedicalHistoryTemplateLDto()
{
ChiefComplaint = p17.ChiefComplaint,
SectionId = p17.SectionId,
ApplicationUserId = p17.ApplicationUserId,
Questions = funcMain3(p17.Questions),
Id = p17.Id
ChiefComplaint = p19.ChiefComplaint,
SectionId = p19.SectionId,
Section = p19.Section == null ? null : new SectionSDto()
{
Name = p19.Section.Name,
Detail = p19.Section.Detail,
UniversityId = p19.Section.UniversityId,
Id = p19.Section.Id
},
ApplicationUserId = p19.ApplicationUserId,
Questions = funcMain4(p19.Questions),
Id = p19.Id
};
}
public static MedicalHistoryTemplateLDto AdaptTo(this MedicalHistoryTemplate p19, MedicalHistoryTemplateLDto p20)
public static MedicalHistoryTemplateLDto AdaptTo(this MedicalHistoryTemplate p21, MedicalHistoryTemplateLDto p22)
{
if (p19 == null)
if (p21 == null)
{
return null;
}
MedicalHistoryTemplateLDto result = p20 ?? new MedicalHistoryTemplateLDto();
MedicalHistoryTemplateLDto result = p22 ?? new MedicalHistoryTemplateLDto();
result.ChiefComplaint = p19.ChiefComplaint;
result.SectionId = p19.SectionId;
result.ApplicationUserId = p19.ApplicationUserId;
result.Questions = funcMain4(p19.Questions, result.Questions);
result.Id = p19.Id;
result.ChiefComplaint = p21.ChiefComplaint;
result.SectionId = p21.SectionId;
result.Section = funcMain5(p21.Section, result.Section);
result.ApplicationUserId = p21.ApplicationUserId;
result.Questions = funcMain6(p21.Questions, result.Questions);
result.Id = p21.Id;
return result;
}
public static Expression<Func<MedicalHistoryTemplate, MedicalHistoryTemplateLDto>> ProjectToLDto => p23 => new MedicalHistoryTemplateLDto()
public static Expression<Func<MedicalHistoryTemplate, MedicalHistoryTemplateLDto>> ProjectToLDto => p27 => new MedicalHistoryTemplateLDto()
{
ChiefComplaint = p23.ChiefComplaint,
SectionId = p23.SectionId,
ApplicationUserId = p23.ApplicationUserId,
Questions = p23.Questions.Select<MedicalHistoryQuestion, MedicalHistoryQuestionSDto>(p24 => new MedicalHistoryQuestionSDto()
ChiefComplaint = p27.ChiefComplaint,
SectionId = p27.SectionId,
Section = p27.Section == null ? null : new SectionSDto()
{
Question = p24.Question,
Part = p24.Part,
QuestionType = p24.QuestionType,
MedicalHistoryTemplateId = p24.MedicalHistoryTemplateId,
Id = p24.Id
Name = p27.Section.Name,
Detail = p27.Section.Detail,
UniversityId = p27.Section.UniversityId,
Id = p27.Section.Id
},
ApplicationUserId = p27.ApplicationUserId,
Questions = p27.Questions.Select<MedicalHistoryQuestion, MedicalHistoryQuestionSDto>(p28 => new MedicalHistoryQuestionSDto()
{
Question = p28.Question,
Part = p28.Part,
QuestionType = p28.QuestionType,
MedicalHistoryTemplateId = p28.MedicalHistoryTemplateId,
Id = p28.Id
}).ToList<MedicalHistoryQuestionSDto>(),
Id = p23.Id
Id = p27.Id
};
private static List<MedicalHistoryQuestion> funcMain1(List<MedicalHistoryQuestionSDto> p10)
@ -187,20 +218,36 @@ namespace DocuMed.Domain.Mappers
}
private static List<MedicalHistoryQuestion> funcMain2(List<MedicalHistoryQuestionSDto> p13, List<MedicalHistoryQuestion> p14)
private static Section funcMain2(SectionSDto p13, Section p14)
{
if (p13 == null)
{
return null;
}
List<MedicalHistoryQuestion> result = new List<MedicalHistoryQuestion>(p13.Count);
Section result = p14 ?? new Section();
result.Name = p13.Name;
result.Detail = p13.Detail;
result.UniversityId = p13.UniversityId;
result.Id = p13.Id;
return result;
}
private static List<MedicalHistoryQuestion> funcMain3(List<MedicalHistoryQuestionSDto> p15, List<MedicalHistoryQuestion> p16)
{
if (p15 == null)
{
return null;
}
List<MedicalHistoryQuestion> result = new List<MedicalHistoryQuestion>(p15.Count);
int i = 0;
int len = p13.Count;
int len = p15.Count;
while (i < len)
{
MedicalHistoryQuestionSDto item = p13[i];
MedicalHistoryQuestionSDto item = p15[i];
result.Add(item == null ? null : new MedicalHistoryQuestion()
{
Question = item.Question,
@ -215,20 +262,20 @@ namespace DocuMed.Domain.Mappers
}
private static List<MedicalHistoryQuestionSDto> funcMain3(List<MedicalHistoryQuestion> p18)
private static List<MedicalHistoryQuestionSDto> funcMain4(List<MedicalHistoryQuestion> p20)
{
if (p18 == null)
if (p20 == null)
{
return null;
}
List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p18.Count);
List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p20.Count);
int i = 0;
int len = p18.Count;
int len = p20.Count;
while (i < len)
{
MedicalHistoryQuestion item = p18[i];
MedicalHistoryQuestion item = p20[i];
result.Add(item == null ? null : new MedicalHistoryQuestionSDto()
{
Question = item.Question,
@ -243,20 +290,36 @@ namespace DocuMed.Domain.Mappers
}
private static List<MedicalHistoryQuestionSDto> funcMain4(List<MedicalHistoryQuestion> p21, List<MedicalHistoryQuestionSDto> p22)
private static SectionSDto funcMain5(Section p23, SectionSDto p24)
{
if (p21 == null)
if (p23 == null)
{
return null;
}
List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p21.Count);
SectionSDto result = p24 ?? new SectionSDto();
result.Name = p23.Name;
result.Detail = p23.Detail;
result.UniversityId = p23.UniversityId;
result.Id = p23.Id;
return result;
}
private static List<MedicalHistoryQuestionSDto> funcMain6(List<MedicalHistoryQuestion> p25, List<MedicalHistoryQuestionSDto> p26)
{
if (p25 == null)
{
return null;
}
List<MedicalHistoryQuestionSDto> result = new List<MedicalHistoryQuestionSDto>(p25.Count);
int i = 0;
int len = p21.Count;
int len = p25.Count;
while (i < len)
{
MedicalHistoryQuestion item = p21[i];
MedicalHistoryQuestion item = p25[i];
result.Add(item == null ? null : new MedicalHistoryQuestionSDto()
{
Question = item.Question,

View File

@ -1,5 +1,5 @@
@page "/MedicalHistoryTemplateActionPage"
@page "/MedicalHistoryTemplateActionPage/{TemplateId:string}"
@page "/MedicalHistoryTemplateActionPage/{TemplateId}"
@inject NavigationManager NavigationManager
@inject IRestWrapper RestWrapper
@inject IUserUtility UserUtility
@ -15,6 +15,7 @@
<MudCarouselItem>
<div class="flex flex-col w-full h-full">
<MedicalHistoryTemplateActionStep1 @bind-ChiefComplaint="@ViewModel.PageDto.ChiefComplaint" @bind-SelectedSection="@ViewModel.SelectedSelection" />
</div>
</MudCarouselItem>
<MudCarouselItem>
@ -55,7 +56,7 @@
<p class="font-extrabold my-0 mr-7 text-lg text-[--color-medicalhistory]">منتظر بمانید</p>
</div>
</MudPaper>
</MudPaper>
}
else
{
@ -63,7 +64,18 @@
@if (@ViewModel.CurrentStep == 4)
{
<MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Filled" IconSize="Size.Large" StartIcon="@Icons.Material.Filled.ChevronRight" class="font-extrabold rounded-full bg-[--color-medicalhistory]">تـــکمیل</MudButton>
@if (@ViewModel.IsEditing)
{
<MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Filled"
IconSize="Size.Large" StartIcon="@Icons.Material.Filled.ChevronRight"
class="font-extrabold rounded-full bg-[--color-medicalhistory]">تـــکمیل</MudButton>
}
else
{
<MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Filled"
IconSize="Size.Large" StartIcon="@Icons.Material.Filled.ChevronRight"
class="font-extrabold rounded-full bg-[--color-medicalhistory]">ویرایش</MudButton>
}
}
else
{
@ -83,12 +95,15 @@
</BasePageUi>
@code {
[Parameter]
public string TemplateId { get; set; }
public string TemplateId { get; set; } = string.Empty;
public MedicalHistoryTemplateActionPageViewModel ViewModel { get; set; }
protected override async Task OnInitializedAsync()
{
ViewModel = new MedicalHistoryTemplateActionPageViewModel(NavigationManager,Snackbar,RestWrapper,UserUtility);
ViewModel = Guid.TryParse(TemplateId, out Guid templateId) ?
new MedicalHistoryTemplateActionPageViewModel(NavigationManager, Snackbar, RestWrapper, UserUtility, templateId)
: new MedicalHistoryTemplateActionPageViewModel(NavigationManager, Snackbar, RestWrapper, UserUtility);
await ViewModel.InitializeAsync();
await base.OnInitializedAsync();
}

View File

@ -22,7 +22,7 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
public List<MedicalHistoryQuestionSDto> VsQuestions { get; set; } = new();
public SectionSDto? SelectedSelection { get; set; }
public MedicalHistoryTemplateActionPageViewModel(
@ -52,20 +52,60 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
IsEditing = true;
}
public override Task InitializeAsync()
public override async Task InitializeAsync()
{
return base.InitializeAsync();
if (_templateId != Guid.Empty && IsEditing)
{
try
{
IsProcessing = true;
var token = await _userUtility.GetBearerTokenAsync();
var dto = await _restWrapper.CrudDtoApiRest<MedicalHistoryTemplateSDto, MedicalHistoryTemplateLDto, Guid>(Address.MedicalHistoryTemplateController)
.ReadOne(_templateId, token);
PageDto.ApplicationUserId = dto.ApplicationUserId;
PageDto.ChiefComplaint = dto.ChiefComplaint;
PageDto.SectionId = dto.SectionId;
PageDto.Id = dto.Id;
SelectedSelection = dto.Section;
PiQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.PresentIllness));
PdhQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.PastDiseasesHistory));
PshQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.PastSurgeryHistory));
FhQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.FamilyHistory));
DhQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.DrugHistory));
AhQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.AddictionHistory));
VsQuestions.AddRange(dto.Questions.Where(q => q.Part == MedicalHistoryPart.VitalSign));
}
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;
}
}
await base.InitializeAsync();
}
public async Task CompleteStepClicked()
{
Carousel?.MoveTo(++CurrentStep);
++CurrentStep;
StepCounter = $"{CurrentStep + 1} / 5";
if (CurrentStep == 5)
{
if (IsEditing)
await EditTemplateAsync();
else
await SubmitTemplateAsync();
MedicalHistorySubmitted = true;
await SubmitTemplateAsync();
}
Carousel?.MoveTo(CurrentStep);
}
public async Task SubmitTemplateAsync()
@ -105,6 +145,44 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
IsProcessing = false;
}
}
public async Task EditTemplateAsync()
{
try
{
IsProcessing = true;
if (SelectedSelection == null)
throw new Exception("لطفا بخش مورد نظر را انتخاب نمایید");
PageDto.SectionId = SelectedSelection.Id;
var token = await _userUtility.GetBearerTokenAsync();
PageDto.SectionId = SelectedSelection.Id;
PageDto.Questions.AddRange(PiQuestions);
PageDto.Questions.AddRange(PdhQuestions);
PageDto.Questions.AddRange(PiQuestions);
PageDto.Questions.AddRange(PshQuestions);
PageDto.Questions.AddRange(FhQuestions);
PageDto.Questions.AddRange(DhQuestions);
PageDto.Questions.AddRange(AhQuestions);
PageDto.Questions.AddRange(VsQuestions);
await _restWrapper.CrudDtoApiRest<MedicalHistoryTemplateLDto, MedicalHistoryTemplateSDto, Guid>(Address.MedicalHistoryTemplateController)
.Update(PageDto, token);
}
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;
}
}
public void RollBackStepClicked()
{
Carousel?.MoveTo(--CurrentStep);

View File

@ -8,8 +8,8 @@
مورد ده
</p>
<BasePartDivider Index="1" Title="شکایت اصلی بیمار" />
<MudTextField T="string" ValueChanged="async cc => {ChiefComplaint=cc; await ChiefComplaintChanged.InvokeAsync(ChiefComplaint); }" Label="شکایت اصلی بیمار ( CC )" Variant="Variant.Outlined" Margin="Margin.Normal" />
<MudAutocomplete T="SectionSDto" Label="بخش بیمار" Variant="Variant.Outlined"
<MudTextField T="string" Value="@ChiefComplaint" ValueChanged="async cc => {ChiefComplaint=cc; await ChiefComplaintChanged.InvokeAsync(ChiefComplaint); }" Label="شکایت اصلی بیمار ( CC )" Variant="Variant.Outlined" Margin="Margin.Normal" />
<MudAutocomplete Value="@SelectedSection" T="SectionSDto" Label="بخش بیمار" Variant="Variant.Outlined"
ToStringFunc="dto => dto.Name"
SearchFunc="@SearchSection"
ValueChanged="async dto => { SelectedSection=dto; await SelectedSectionChanged.InvokeAsync(SelectedSection); }">
@ -31,7 +31,6 @@
</MudStack>
@code {
[Parameter]
public string ChiefComplaint { get; set; } = string.Empty;
[Parameter]
@ -42,6 +41,8 @@
[Parameter]
public EventCallback<SectionSDto> SelectedSectionChanged { get; set; }
private MedicalHistoryTemplateLDto _editingTemplate = new();
public List<SectionSDto> Sections { get; private set; } = new List<SectionSDto>();
public async Task<IEnumerable<SectionSDto>> SearchSection(string section)

View File

@ -31,14 +31,23 @@
<ItemGroup>
<Using Include="DocuMed.Common.Extensions" />
<Using Include="DocuMed.Common.Models" />
<Using Include="DocuMed.Common.Models.Api" />
<Using Include="DocuMed.Common.Models.Claims" />
<Using Include="DocuMed.Common.Models.Entity" />
<Using Include="DocuMed.Common.Models.Exception" />
<Using Include="DocuMed.Domain.Dtos.LargDtos" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.MedicalHistoryTemplate" />
<Using Include="DocuMed.Domain.Entities.User" />
<Using Include="DocuMed.Domain.Enums" />
<Using Include="DocuMed.Domain.Mappers" />
<Using Include="DocuMed.Domain.Models.Settings" />
<Using Include="DocuMed.Repository.Abstracts" />
<Using Include="DocuMed.Repository.Extensions" />
<Using Include="DocuMed.Repository.Models" />
<Using Include="DocuMed.Repository.Repositories.Base" />
<Using Include="DocuMed.Repository.Repositories.Base.Contracts" />
<Using Include="DocuMed.Repository.Repositories.Entities.Abstracts" />
<Using Include="DocuMed.Repository.Services.Contracts" />
<Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />

View File

@ -1,10 +1,14 @@
namespace DocuMed.Repository.Repositories.Base
using DocuMed.Repository.Abstracts;
namespace DocuMed.Repository.Repositories.Base
{
public class BaseRepository<T> : Repository<T>, IBaseRepository<T> where T : class, IApiEntity
{
public BaseRepository(ApplicationContext dbContext) : base(dbContext)
{
protected readonly ICurrentUserService CurrentUserService;
public BaseRepository(ApplicationContext dbContext,ICurrentUserService currentUserService) : base(dbContext)
{
CurrentUserService = currentUserService;
}
public virtual async ValueTask<T> GetByIdAsync(CancellationToken cancellationToken, params object[] ids)
@ -55,13 +59,32 @@
public virtual void Delete(T entity)
{
AssertExtensions.NotNull(entity, nameof(entity));
Entities.Remove(entity);
Entities.Entry(entity).Property(e => e.RemovedAt)
.CurrentValue = DateTime.Now;
Entities.Entry(entity).Property(e => e.IsRemoved)
.CurrentValue = true;
if (CurrentUserService.UserName != null)
Entities.Entry(entity).Property(e => e.RemovedBy)
.CurrentValue = CurrentUserService.UserName;
Entities.Update(entity);
}
public virtual void DeleteRange(IEnumerable<T> entities)
{
AssertExtensions.NotNull(entities, nameof(entities));
Entities.RemoveRange(entities);
var apiEntities = entities.ToList();
AssertExtensions.NotNull(apiEntities, nameof(entities));
foreach (var entity in apiEntities)
{
Entities.Entry(entity).Property(e => e.RemovedAt)
.CurrentValue = DateTime.Now;
Entities.Entry(entity).Property(e => e.IsRemoved)
.CurrentValue = true;
if (CurrentUserService.UserName != null)
Entities.Entry(entity).Property(e => e.RemovedBy)
.CurrentValue = CurrentUserService.UserName;
Entities.Update(entity);
}
}
#endregion

View File

@ -2,13 +2,15 @@
public class RepositoryWrapper : IRepositoryWrapper
{
private readonly ApplicationContext _context;
private readonly ICurrentUserService _currentUserService;
private IDbContextTransaction? _currentTransaction;
public RepositoryWrapper(ApplicationContext context)
public RepositoryWrapper(ApplicationContext context,ICurrentUserService currentUserService)
{
_context = context;
_currentUserService = currentUserService;
}
public IBaseRepository<T> SetRepository<T>() where T : ApiEntity => new BaseRepository<T>(_context);
public IBaseRepository<T> SetRepository<T>() where T : ApiEntity => new BaseRepository<T>(_context, _currentUserService);
public async Task RollBackAsync(CancellationToken cancellationToken)
@ -42,20 +44,21 @@ public class RepositoryWrapper : IRepositoryWrapper
{
entity.Property(e => e.CreatedAt)
.CurrentValue = DateTime.Now;
if (_currentUserService.UserName != null)
entity.Property(e => e.CreatedBy)
.CurrentValue = _currentUserService.UserName;
}
if (entity.State == EntityState.Modified)
{
entity.Property(e => e.ModifiedAt)
.CurrentValue = DateTime.Now;
}
if (entity.State == EntityState.Deleted)
{
entity.Property(e => e.RemovedAt)
.CurrentValue = DateTime.Now;
entity.Property(e => e.IsRemoved)
.CurrentValue = true;
if (!entity.Property(e => e.IsRemoved).CurrentValue)
{
entity.Property(e => e.ModifiedAt)
.CurrentValue = DateTime.Now;
if (_currentUserService.UserName != null)
entity.Property(e => e.ModifiedBy)
.CurrentValue = _currentUserService.UserName;
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace DocuMed.Repository.Repositories.Entities.Abstracts;
public interface IMedicalHistoryTemplateRepository : IBaseRepository<MedicalHistoryTemplate>,IScopedDependency
{
public Task<List<MedicalHistoryTemplateSDto>> GetMedicalHistoryTemplatesAsync(int page = 0, CancellationToken cancellationToken = default);
public Task<MedicalHistoryTemplateLDto> GetMedicalHistoryTemplateAsync(Guid id, CancellationToken cancellationToken = default);
}

View File

@ -0,0 +1,32 @@
namespace DocuMed.Repository.Repositories.Entities;
public class MedicalHistoryTemplateRepository : BaseRepository<MedicalHistoryTemplate>, IMedicalHistoryTemplateRepository
{
public MedicalHistoryTemplateRepository(ApplicationContext dbContext,ICurrentUserService currentUserService) : base(dbContext,currentUserService)
{
}
public async Task<List<MedicalHistoryTemplateSDto>> GetMedicalHistoryTemplatesAsync(int page = 0, CancellationToken cancellationToken = default)
{
if (!Guid.TryParse(CurrentUserService.UserId, out Guid userId))
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
var list = await TableNoTracking
.Where(t => t.ApplicationUserId == userId)
.OrderByDescending(t => t.CreatedAt)
.Skip(page * 15)
.Take(15)
.Select(MedicalHistoryTemplateMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return list;
}
public async Task<MedicalHistoryTemplateLDto> GetMedicalHistoryTemplateAsync(Guid id, CancellationToken cancellationToken = default)
{
var dto = await TableNoTracking.Where(t => t.Id == id)
.Select(MedicalHistoryTemplateMapper.ProjectToLDto)
.FirstOrDefaultAsync(cancellationToken);
if (dto == null)
throw new AppException("پیش نویس پیدا نشد", ApiResultStatusCode.NotFound);
return dto;
}
}