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 Microsoft.AspNetCore.Mvc.RazorPages;
using DocuMed.Domain.Dtos.LargDtos;
namespace DocuMed.Api.Controllers; namespace DocuMed.Api.Controllers;
@ -30,49 +29,28 @@ public class MedicalHistoryTemplateController : ICarterModule
// GET:Get All Entity // 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)) return TypedResults.Ok(await repository.GetMedicalHistoryTemplatesAsync(page,cancellationToken));
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);
} }
// GET:Get An Entity By Id // GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IRepositoryWrapper repositoryWrapper, public async Task<IResult> GetAsync(Guid id, IMedicalHistoryTemplateRepository repository, CancellationToken cancellationToken)
CancellationToken cancellationToken) {
=> TypedResults.Ok(await repositoryWrapper.SetRepository<MedicalHistoryTemplate>()
.GetByIdAsync(cancellationToken, id)); return TypedResults.Ok(await repository.GetMedicalHistoryTemplateAsync(id, cancellationToken));
}
// POST:Add New Entity // 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)) return TypedResults.Ok(await service.AddAsync(dto,cancellationToken));
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();
} }
// PUT:Update Entity // 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)) return TypedResults.Ok(await service.EditAsync(dto, cancellationToken));
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();
} }
// DELETE:Delete Entity // DELETE:Delete Entity

View File

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

View File

@ -22,7 +22,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="BaseServices\Abstracts\" /> <Folder Include="BaseServices\Abstracts\" />
<Folder Include="CoreServices\Abstracts\" /> <Folder Include="CoreServices\Abstracts\" />
<Folder Include="EntityServices\Abstracts\" />
<Folder Include="Models\Api\" /> <Folder Include="Models\Api\" />
<Folder Include="Abstracts\" /> <Folder Include="Abstracts\" />
</ItemGroup> </ItemGroup>
@ -37,6 +36,7 @@
<Using Include="DocuMed.Core.BaseServices.Abstracts" /> <Using Include="DocuMed.Core.BaseServices.Abstracts" />
<Using Include="DocuMed.Core.CoreServices.Abstracts" /> <Using Include="DocuMed.Core.CoreServices.Abstracts" />
<Using Include="DocuMed.Core.EntityServices.Abstracts" /> <Using Include="DocuMed.Core.EntityServices.Abstracts" />
<Using Include="DocuMed.Domain.Dtos.LargDtos" />
<Using Include="DocuMed.Domain.Dtos.RequestDtos" /> <Using Include="DocuMed.Domain.Dtos.RequestDtos" />
<Using Include="DocuMed.Domain.Dtos.SmallDtos" /> <Using Include="DocuMed.Domain.Dtos.SmallDtos" />
<Using Include="DocuMed.Domain.Entities.User" /> <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 string ChiefComplaint { get; set; } = string.Empty;
public Guid SectionId { get; set; } public Guid SectionId { get; set; }
public SectionSDto Section { get; set; } = new();
public Guid ApplicationUserId { get; set; } public Guid ApplicationUserId { get; set; }
public List<MedicalHistoryQuestionSDto> Questions { get; set; } = new(); 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 string ChiefComplaint { get; internal set; } = string.Empty;
public Guid SectionId { get; set; } public Guid SectionId { get; set; }
public Section? Section { get; set; }
public Guid ApplicationUserId { get; internal set; } public Guid ApplicationUserId { get; internal set; }
public ApplicationUser? ApplicationUser { get; set; } public ApplicationUser? ApplicationUser { get; set; }
public List<MedicalHistoryQuestion> Questions { get; internal set; } = new(); public List<MedicalHistoryQuestion> Questions { get; internal set; } = new();

View File

@ -31,7 +31,7 @@ namespace DocuMed.Domain.Mappers
return result; 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, Name = p4.Name,
Id = p4.Id Id = p4.Id
@ -85,7 +85,7 @@ namespace DocuMed.Domain.Mappers
return result; 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, Name = p15.Name,
Universities = p15.Universities.Select<UniversitySDto, University>(p16 => new University() Universities = p15.Universities.Select<UniversitySDto, University>(p16 => new University()

View File

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

View File

@ -1,5 +1,5 @@
@page "/MedicalHistoryTemplateActionPage" @page "/MedicalHistoryTemplateActionPage"
@page "/MedicalHistoryTemplateActionPage/{TemplateId:string}" @page "/MedicalHistoryTemplateActionPage/{TemplateId}"
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IRestWrapper RestWrapper @inject IRestWrapper RestWrapper
@inject IUserUtility UserUtility @inject IUserUtility UserUtility
@ -15,6 +15,7 @@
<MudCarouselItem> <MudCarouselItem>
<div class="flex flex-col w-full h-full"> <div class="flex flex-col w-full h-full">
<MedicalHistoryTemplateActionStep1 @bind-ChiefComplaint="@ViewModel.PageDto.ChiefComplaint" @bind-SelectedSection="@ViewModel.SelectedSelection" /> <MedicalHistoryTemplateActionStep1 @bind-ChiefComplaint="@ViewModel.PageDto.ChiefComplaint" @bind-SelectedSection="@ViewModel.SelectedSelection" />
</div> </div>
</MudCarouselItem> </MudCarouselItem>
<MudCarouselItem> <MudCarouselItem>
@ -55,7 +56,7 @@
<p class="font-extrabold my-0 mr-7 text-lg text-[--color-medicalhistory]">منتظر بمانید</p> <p class="font-extrabold my-0 mr-7 text-lg text-[--color-medicalhistory]">منتظر بمانید</p>
</div> </div>
</MudPaper> </MudPaper>
} }
else else
{ {
@ -63,7 +64,18 @@
@if (@ViewModel.CurrentStep == 4) @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 else
{ {
@ -83,12 +95,15 @@
</BasePageUi> </BasePageUi>
@code { @code {
[Parameter] [Parameter]
public string TemplateId { get; set; } public string TemplateId { get; set; } = string.Empty;
public MedicalHistoryTemplateActionPageViewModel ViewModel { get; set; } public MedicalHistoryTemplateActionPageViewModel ViewModel { get; set; }
protected override async Task OnInitializedAsync() 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 ViewModel.InitializeAsync();
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }

View File

@ -22,7 +22,7 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
public List<MedicalHistoryQuestionSDto> VsQuestions { get; set; } = new(); public List<MedicalHistoryQuestionSDto> VsQuestions { get; set; } = new();
public SectionSDto? SelectedSelection { get; set; } public SectionSDto? SelectedSelection { get; set; }
public MedicalHistoryTemplateActionPageViewModel( public MedicalHistoryTemplateActionPageViewModel(
@ -52,20 +52,60 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
IsEditing = true; 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() public async Task CompleteStepClicked()
{ {
Carousel?.MoveTo(++CurrentStep); ++CurrentStep;
StepCounter = $"{CurrentStep + 1} / 5"; StepCounter = $"{CurrentStep + 1} / 5";
if (CurrentStep == 5) if (CurrentStep == 5)
{ {
if (IsEditing)
await EditTemplateAsync();
else
await SubmitTemplateAsync();
MedicalHistorySubmitted = true; MedicalHistorySubmitted = true;
await SubmitTemplateAsync();
} }
Carousel?.MoveTo(CurrentStep);
} }
public async Task SubmitTemplateAsync() public async Task SubmitTemplateAsync()
@ -105,6 +145,44 @@ public class MedicalHistoryTemplateActionPageViewModel : BaseViewModel<MedicalHi
IsProcessing = false; 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() public void RollBackStepClicked()
{ {
Carousel?.MoveTo(--CurrentStep); Carousel?.MoveTo(--CurrentStep);

View File

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

View File

@ -31,14 +31,23 @@
<ItemGroup> <ItemGroup>
<Using Include="DocuMed.Common.Extensions" /> <Using Include="DocuMed.Common.Extensions" />
<Using Include="DocuMed.Common.Models" /> <Using Include="DocuMed.Common.Models" />
<Using Include="DocuMed.Common.Models.Api" />
<Using Include="DocuMed.Common.Models.Claims" /> <Using Include="DocuMed.Common.Models.Claims" />
<Using Include="DocuMed.Common.Models.Entity" /> <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.Entities.User" />
<Using Include="DocuMed.Domain.Enums" /> <Using Include="DocuMed.Domain.Enums" />
<Using Include="DocuMed.Domain.Mappers" />
<Using Include="DocuMed.Domain.Models.Settings" /> <Using Include="DocuMed.Domain.Models.Settings" />
<Using Include="DocuMed.Repository.Abstracts" />
<Using Include="DocuMed.Repository.Extensions" /> <Using Include="DocuMed.Repository.Extensions" />
<Using Include="DocuMed.Repository.Models" /> <Using Include="DocuMed.Repository.Models" />
<Using Include="DocuMed.Repository.Repositories.Base" />
<Using Include="DocuMed.Repository.Repositories.Base.Contracts" /> <Using Include="DocuMed.Repository.Repositories.Base.Contracts" />
<Using Include="DocuMed.Repository.Repositories.Entities.Abstracts" />
<Using Include="DocuMed.Repository.Services.Contracts" /> <Using Include="DocuMed.Repository.Services.Contracts" />
<Using Include="Microsoft.AspNetCore.Identity" /> <Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" /> <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 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) public virtual async ValueTask<T> GetByIdAsync(CancellationToken cancellationToken, params object[] ids)
@ -55,13 +59,32 @@
public virtual void Delete(T entity) public virtual void Delete(T entity)
{ {
AssertExtensions.NotNull(entity, nameof(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) public virtual void DeleteRange(IEnumerable<T> entities)
{ {
AssertExtensions.NotNull(entities, nameof(entities)); var apiEntities = entities.ToList();
Entities.RemoveRange(entities); 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 #endregion

View File

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

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;
}
}