Browse Source

计算函数

bjmzak
DESKTOP-G961P6V\Zhh 2 years ago
parent
commit
b1bcbad471
  1. 17
      src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterNoInputDto.cs
  2. 6
      src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterOrNoDto.cs
  3. 108
      src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
  4. 80
      src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
  5. 121
      src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs
  6. 125
      src/Shentun.Peis.Domain/CacheService.cs
  7. 7
      src/Shentun.Peis.Domain/CompileHelper.cs
  8. 29
      src/Shentun.Peis.Domain/RegisterCheckAsbitems/RegisterCheckAsbitemManager.cs
  9. 153
      test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
  10. 229
      test/Shentun.Peis.Application.Tests/PatientRegisterAppServiceTest.cs

17
src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterNoInputDto.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.PatientRegisters
{
public class PatientRegisterNoInputDto
{
public string PatientRegisterNo { get; set; }
/// <summary>
/// 档案号
/// </summary>
public string PatientNo { get; set; }
}
}

6
src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterOrNoDto.cs

@ -42,6 +42,7 @@ namespace Shentun.Peis.PatientRegisters
/// 性别
/// </summary>
public char? SexId { get; set; }
public string SexName { get; set; }
/// <summary>
/// 出生日期
/// </summary>
@ -62,14 +63,17 @@ namespace Shentun.Peis.PatientRegisters
/// 婚姻状况
/// </summary>
public char? MaritalStatusId { get; set; }
public string MaritalStatusName { get; set; }
/// <summary>
/// 体检类别
/// </summary>
public Guid? MedicalTypeId { get; set; }
public string MedicalTypeName { get; set; }
/// <summary>
/// 人员类别
/// </summary>
public Guid? PersonnelTypeId { get; set; }
public string PersonnelTypeName { get; set; }
/// <summary>
/// 职务
/// </summary>
@ -200,7 +204,7 @@ namespace Shentun.Peis.PatientRegisters
/// 民族编号
/// </summary>
public string? NationId { get; set; }
public string? NationName { get; set; }
/// <summary>
/// 出生地
/// </summary>

108
src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs

@ -0,0 +1,108 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Shentun.Peis.DiagnosisFunctions
{
public class CodeBuilder
{
private static List<MetadataReference> _references = new List<MetadataReference>();
/// <summary>
/// 编译前的初始化,只需要一次
/// </summary>
/// <returns></returns>
static CodeBuilder()
{
_references = new List<MetadataReference>();
// 元数据引用
if (_references == null || _references.Count == 0)
{
_references = new List<MetadataReference>()
{
MetadataReference.CreateFromFile(typeof(System.Uri).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.Linq.Enumerable).Assembly.Location),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
MetadataReference.CreateFromFile(typeof(System.IO.File).Assembly.Location),
MetadataReference.CreateFromFile(Assembly.Load("System.Runtime").Location),
MetadataReference.CreateFromFile(Assembly.Load("System.Collections").Location),
MetadataReference.CreateFromFile(Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory+"Shentun.Peis.Application.dll").Location),
};
}
//Assembly as1 = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "mscorlib.dll");
//MetadataReference metadataReference = _references.Find((o => o.Display.Contains("mscorlib.dll")));
//if (_references.Find((o => o.Display.Contains("mscorlib.dll"))) == null)
//{
// _references.Add(MetadataReference.CreateFromFile(as1.Location));
//}
}
//public CodeBuilder()
//{
//}
//public Assembly CreateCode(string code)
//{
// //var domain = new NatashaDomain("key");
// //var domain = DomainManagement.Random();
// NatashaManagement.Preheating();
// Path.GetRandomFileName();
// using (DomainManagement.Create("myDomain").CreateScope())
// {
// AssemblyCSharpBuilder builder = new AssemblyCSharpBuilder();
// builder.Add(code);
// var func = builder.GetDelegateFromShortName<Func<string>>("Test", "GetName");
// }
// return myAssembly;
//}
public Assembly GenerateAssemblyFromCode(string code, params Assembly[] referencedAssemblies)
{
Assembly assembly = null;
// 丛代码中转换表达式树
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code);
// 随机程序集名称
//string assemblyName = Path.GetRandomFileName();
var assemblyName = "_" + Guid.NewGuid().ToString("D");
//assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
//assemblyName = "Shentun.Peis.Application";
var syntaxTrees = new SyntaxTree[] { syntaxTree };
// 引用
var references = _references;// referencedAssemblies.Select(x => MetadataReference.CreateFromFile(x.Location));
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
// 创建编译对象
CSharpCompilation compilation = CSharpCompilation.Create(assemblyName, syntaxTrees, references, options);
using (var ms = new MemoryStream())
{
// 将编译好的IL代码放入内存流
EmitResult result = compilation.Emit(ms);
// 编译失败,提示
if (!result.Success)
{
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error);
foreach (Diagnostic diagnostic in failures)
{
Console.Error.WriteLine("{0}: {1}", diagnostic.Id, diagnostic.GetMessage());
}
}
else
{
// 编译成功,从内存中加载编译好的程序集
ms.Seek(0, SeekOrigin.Begin);
assembly = Assembly.Load(ms.ToArray());
}
}
return assembly;
}
}
}

80
src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs

@ -10,14 +10,12 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Ccc.V20200210.Models;
using TencentCloud.Mps.V20190612.Models;
using TencentCloud.Npp.V20190823.Models;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
namespace Shentun.Peis.DiagnosisFunctions
{
[ApiExplorerSettings(GroupName = "Work")]
@ -854,9 +852,85 @@ namespace Shentun.Peis.DiagnosisFunctions
return tempcode;
}
public string GetItemResult(PatientDiagnosisInputArg patient, string codeInput)
{
string result = "";
string code = @"
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using Shentun.Peis.DiagnosisFunctions;
public class DiagnosisResultInAsbitemHeight
{
public string GetDiagnosisResult(PatientDiagnosisInputArg patient)
{
"
+ codeInput + @"
}
}
";
CompileHelper compileHelper = new CompileHelper();
CodeBuilder codeBuilder = new CodeBuilder();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
var assembly = codeBuilder.GenerateAssemblyFromCode(code, Assembly.Load(new AssemblyName("System.Runtime")), typeof(object).Assembly);
//var assembly = compileHelper.GenerateAssemblyFromCode(code, assemblies);
// var assembly = codeBuilder.GenerateAssemblyFromCode(code, assemblies);
//var assembly = codeBuilder.CreateCode(code);
if (assembly != null)
{
// 反射获取程序集中 的类
Type type = assembly.GetType("DiagnosisResultInAsbitemHeight");
// 创建该类的实例
object obj = Activator.CreateInstance(type);
object[] objects = { patient };
;
var msg = type.InvokeMember("GetDiagnosisResult",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
obj,
objects);
if(msg == null)
{
return "";
}
if (!string.IsNullOrEmpty(msg.ToString()))
{
result = msg.ToString();
}
}
return result;
}
}
public class PatientDiagnosisInputArg()
{
public string SexName { get; set; }
public short Age { get; set; }
public Guid AsbitemId { get; set; }
public string AsbitemName { get; set; }
public List<ItemDiagnosisInputArg> Items { get; set; } = new List<ItemDiagnosisInputArg>();
}
public class ItemDiagnosisInputArg
{
public Guid ItemId { get; set; }
public string ItemName { get; set; }
public string Result { get; set; }
}
}

121
src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs

@ -30,6 +30,7 @@ using System.Threading.Tasks;
using TencentCloud.Cwp.V20180228.Models;
using TencentCloud.Mps.V20190612.Models;
using TencentCloud.Npp.V20190823.Models;
using TencentCloud.Trtc.V20190722.Models;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
@ -541,6 +542,120 @@ namespace Shentun.Peis.PatientRegisters
return entdto;
}
/// <summary>
/// 获取档案登记信息 根据档案号或者条码号(档案号条件返回最新的一条)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
[HttpPost("api/app/patientregister/GetAlreadyRegisterPatientRegisterByNo")]
public async Task<PatientRegisterOrNoDto> GetAlreadyRegisterPatientRegisterByNoAsync(PatientRegisterNoInputDto input)
{
var query = (await _repository.GetQueryableAsync()).Include(x => x.Patient).AsQueryable();
var patientRegisterList = new List<PatientRegister>();
PatientRegister ent = null;
if (!string.IsNullOrWhiteSpace(input.PatientRegisterNo))
{
ent = query.Where(m => m.PatientRegisterNo == input.PatientRegisterNo).First();
if (ent == null)
{
throw new UserFriendlyException("未找到人员信息");
}
}
else if (!string.IsNullOrWhiteSpace(input.PatientNo))
{
patientRegisterList = query.Where(m => m.Patient.PatientNo == input.PatientNo).OrderByDescending(o => o.MedicalTimes).ToList();
if (patientRegisterList.Count == 0)
{
throw new UserFriendlyException("未找到人员信息");
}
ent = patientRegisterList.First();
}
else
{
throw new UserFriendlyException("人员登记号和档案号至少有一个");
}
if (ent.CompleteFlag == PatientRegisterCompleteFlag.PreRegistration)
{
throw new UserFriendlyException("该人未正式登记");
}
var entdto = new PatientRegisterOrNoDto
{
CreationTime = ent.CreationTime,
CreatorId = ent.CreatorId,
Id = ent.Id,
LastModificationTime = ent.LastModificationTime,
LastModifierId = ent.LastModifierId,
ThirdInfo = ent.ThirdInfo,
SummaryDoctor = ent.SummaryDoctor,
SummaryDate = ent.SummaryDate.ToString(),
SexId = ent.SexId,
SexName = _cacheService.GetSexNameAsync(ent.SexId).Result,
Age = ent.Age,
AuditDate = ent.AuditDate.ToString(),
AuditDoctor = ent.AuditDoctor,
BirthDate = ent.BirthDate.ToString(),
CompleteFlag = ent.CompleteFlag,
CustomerOrgGroupId = ent.CustomerOrgGroupId,
CustomerOrgId = ent.CustomerOrgId,
CustomerOrgRegisterId = ent.CustomerOrgRegisterId,
GuidePrintTimes = ent.GuidePrintTimes,
InterposeMeasure = ent.InterposeMeasure,
IsAudit = ent.IsAudit,
IsLock = ent.IsLock,
IsMedicalStart = ent.IsMedicalStart,
IsNameHide = ent.IsNameHide,
IsPhoneFollow = ent.IsPhoneFollow,
IsRecoverGuide = ent.IsRecoverGuide,
IsUpload = ent.IsUpload,
IsVip = ent.IsVip,
JobCardNo = ent.JobCardNo,
JobPost = ent.JobPost,
JobTitle = ent.JobTitle,
MaritalStatusId = ent.MaritalStatusId,
MaritalStatusName = _cacheService.GetMaritalStatusNameAsync(ent.MaritalStatusId).Result,
MedicalCardNo = ent.MedicalCardNo,
MedicalConclusionId = ent.MedicalConclusionId,
MedicalPackageId = ent.MedicalPackageId,
MedicalStartDate = ent.MedicalStartDate.ToString(),
MedicalTimes = ent.MedicalTimes,
MedicalTypeId = ent.MedicalTypeId,
MedicalTypeName = _cacheService.GetMedicalTypeNameAsync(ent.MedicalTypeId).Result,
MedicalCenterId = ent.MedicalCenterId,
PatientId = ent.PatientId,
PatientName = ent.PatientName,
PatientRegisterNo = ent.PatientRegisterNo,
PersonnelTypeId = ent.PersonnelTypeId,
PersonnelTypeName = _cacheService.GetPersonnelTypeNameAsync(ent.PersonnelTypeId).Result,
Remark = ent.Remark,
ReportPrintTimes = ent.ReportPrintTimes,
Salesman = ent.Salesman,
SexHormoneTermId = ent.SexHormoneTermId,
CreatorName = _cacheService.GetUserNameAsync(ent.CreatorId).Result,
LastModifierName = _cacheService.GetUserNameAsync(ent.LastModifierId).Result,
Address = ent.Patient.Address, //档案表信息
BirthPlaceId = ent.Patient.BirthPlaceId,
DisplayName = ent.Patient.DisplayName,
Email = ent.Patient.Email,
IdNo = ent.Patient.IdNo,
MobileTelephone = ent.Patient.MobileTelephone,
NationId = ent.Patient.NationId,
NationName = _cacheService.GetNationNameAsync(ent.Patient.NationId).Result,
PatientNo = ent.Patient.PatientNo,
PostalCode = ent.Patient.PostalCode,
Telephone = ent.Patient.Telephone,
CustomerOrgName = _cacheService.GetCustomerOrgNameAsync(ent.CustomerOrgId).Result,
CustomerOrgParentId = _cacheService.GetTopCustomerOrgAsync(ent.CustomerOrgId).Result.Id,
CustomerOrgParentName = _cacheService.GetTopCustomerOrgAsync(ent.CustomerOrgId).Result.DisplayName
};
return entdto;
}
///// <summary>
@ -1438,7 +1553,7 @@ namespace Shentun.Peis.PatientRegisters
PayTypeFlag = PayTypeFlag.OrgPay,
StandardPrice = s.Asbitem.Price
}).ToList();
createRegisterCheckAsbitemEntity = await _registerAsbitemManager.UpdateManyAsync(patientRegister, registerAsbitems);
if (createRegisterCheckAsbitemEntity != null)
@ -1723,7 +1838,7 @@ namespace Shentun.Peis.PatientRegisters
}
/// <summary>
/// 按历史登记导入体检名单操作
/// </summary>
@ -1787,7 +1902,7 @@ namespace Shentun.Peis.PatientRegisters
PayTypeFlag = PayTypeFlag.OrgPay,
StandardPrice = s.Asbitem.Price
}).ToList();
var createRegisterCheckAsbitemEntity = await _registerAsbitemManager.UpdateManyAsync(patientRegister, registerAsbitems);
if (createRegisterCheckAsbitemEntity != null)

125
src/Shentun.Peis.Domain/CacheService.cs

@ -16,10 +16,14 @@ namespace Shentun.Peis
public class CacheService : ISingletonDependency
{
private readonly IDistributedCache<IdentityUser, Guid> _userCache;
private readonly IDistributedCache<CustomerOrg, Guid> _customerOrgCache;
private readonly IDistributedCache<Nation, string> _nationCache;
private readonly IDistributedCache<Sex, char> _sexCache;
private readonly IDistributedCache<MaritalStatus, char> _maritalStatusCache;
private readonly IDistributedCache<ForSex, char> _forSexCache;
private readonly IDistributedCache<DeviceType, Guid> _deviceTypeCache;
private readonly IDistributedCache<MedicalType, Guid> _medicalTypeCache;
private readonly IDistributedCache<PersonnelType, Guid> _personnelTypeCache;
private readonly IDistributedCache<Asbitem, Guid> _asbitemCache;
private readonly IDistributedCache<ItemType, Guid> _itemTypeCache;
private readonly IRepository<IdentityUser, Guid> _userRepository;
@ -29,13 +33,22 @@ namespace Shentun.Peis
private readonly IRepository<DeviceType, Guid> _deviceTypeRepository;
private readonly IRepository<Asbitem, Guid> _asbitemRepository;
private readonly IRepository<ItemType, Guid> _itemTypeRepository;
private readonly IRepository<CustomerOrg, Guid> _customerOrgRepository;
private readonly IRepository<MaritalStatus> _maritalStatusRepository;
private readonly IRepository<MedicalType, Guid> _medicalTypeRepository;
private readonly IRepository<PersonnelType, Guid> _personnelTypeRepository;
public CacheService(
IDistributedCache<IdentityUser, Guid> userCache,
IDistributedCache<CustomerOrg, Guid> customerOrgCache,
IDistributedCache<Nation, string> nationCache,
IRepository<IdentityUser, Guid> userRepository,
IDistributedCache<Sex, char> sexCache,
IDistributedCache<Asbitem, Guid> asbitemCache,
IDistributedCache<ItemType, Guid> itemTypeCache,
IDistributedCache<MaritalStatus, char> maritalStatusCache,
IDistributedCache<MedicalType, Guid> medicalTypeCache,
IDistributedCache<PersonnelType, Guid> personnelTypeCache,
IRepository<Sex> sexRepository,
IDistributedCache<DeviceType, Guid> deviceTypeCache,
IRepository<DeviceType, Guid> deviceTypeRepository,
@ -43,7 +56,11 @@ namespace Shentun.Peis
IRepository<ForSex> forSexRepository,
IRepository<Asbitem, Guid> asbitemRepository,
IRepository<ItemType, Guid> itemTypeRepository,
IRepository<Nation> nationRepository
IRepository<Nation> nationRepository,
IRepository<CustomerOrg, Guid> customerOrgRepository,
IRepository<MaritalStatus> maritalStatusRepository,
IRepository<MedicalType, Guid> medicalTypeRepository,
IRepository<PersonnelType, Guid> personnelTypeRepository
)
{
_userCache = userCache;
@ -66,6 +83,18 @@ namespace Shentun.Peis
_nationCache = nationCache;
_nationRepository = nationRepository;
_customerOrgCache = customerOrgCache;
_customerOrgRepository = customerOrgRepository;
_maritalStatusCache = maritalStatusCache;
_maritalStatusRepository = maritalStatusRepository;
_medicalTypeCache = medicalTypeCache;
_medicalTypeRepository = medicalTypeRepository;
_personnelTypeCache = personnelTypeCache;
_personnelTypeRepository = personnelTypeRepository;
}
private async Task<IdentityUser> GetUserAsync(Guid id)
@ -120,6 +149,22 @@ namespace Shentun.Peis
return entity.DisplayName;
}
private async Task<MaritalStatus> GetMaritalStatusAsync(char id)
{
var entity = await _maritalStatusCache.GetOrAddAsync(
id, //缓存键
async () => (await _maritalStatusRepository.GetQueryableAsync()).Where(o => o.Id == id).Single()
);
return entity;
}
public async Task<string> GetMaritalStatusNameAsync(char id)
{
var entity = await GetMaritalStatusAsync(id);
return entity.DisplayName;
}
private async Task<DeviceType> GetDeviceTypeAsync(Guid id)
{
@ -140,6 +185,45 @@ namespace Shentun.Peis
return entity.DisplayName;
}
private async Task<MedicalType> GetMedicalTypeAsync(Guid id)
{
var entity = await _medicalTypeCache.GetOrAddAsync(
id, //缓存键
async () => await _medicalTypeRepository.GetAsync(id)
);
return entity;
}
public async Task<string> GetMedicalTypeNameAsync(Guid? id)
{
if (id == null || id == default(Guid) || !id.HasValue)
{
return "";
}
var entity = await GetMedicalTypeAsync((Guid)id);
return entity.DisplayName;
}
private async Task<PersonnelType> GetPersonnelTypeAsync(Guid id)
{
var entity = await _personnelTypeCache.GetOrAddAsync(
id, //缓存键
async () => await _personnelTypeRepository.GetAsync(id)
);
return entity;
}
public async Task<string> GetPersonnelTypeNameAsync(Guid? id)
{
if (id == null || id == default(Guid) || !id.HasValue)
{
return "";
}
var entity = await GetPersonnelTypeAsync((Guid)id);
return entity.DisplayName;
}
public async Task<Asbitem> GetAsbitemAsync(Guid id)
{
@ -167,7 +251,7 @@ namespace Shentun.Peis
var entity = await _nationCache.GetOrAddAsync(
id, //缓存键
async () => await _nationRepository.GetAsync(o=>o.Id == id)
async () => await _nationRepository.GetAsync(o => o.Id == id)
);
return entity;
@ -183,5 +267,42 @@ namespace Shentun.Peis
return entity.DisplayName;
}
public async Task<CustomerOrg> GetCustomerOrgAsync(Guid id)
{
var entity = await _customerOrgCache.GetOrAddAsync(
id, //缓存键
async () => await _customerOrgRepository.GetAsync(o => o.Id == id)
);
return entity;
}
public async Task<string> GetCustomerOrgNameAsync(Guid? id)
{
if (id == null || id == default(Guid) || !id.HasValue)
{
return "";
}
var entity = await GetCustomerOrgAsync((Guid)id);
return entity.DisplayName;
}
public async Task<CustomerOrg> GetTopCustomerOrgAsync(Guid id)
{
var entity = await _customerOrgCache.GetOrAddAsync(
id, //缓存键
async () => await _customerOrgRepository.GetAsync(o => o.Id == id)
);
if (entity.ParentId != null && entity.ParentId != Guid.Empty)
{
entity = await GetTopCustomerOrgAsync((Guid)entity.ParentId);
}
return entity;
}
}
}

7
src/Shentun.Peis.Domain/CompileHelper.cs

@ -8,11 +8,14 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using NPOI.SS.Formula.Functions;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Shentun.Peis
{
public class CompileHelper
{
/// <summary>
/// 动态编译
/// </summary>
@ -27,6 +30,8 @@ namespace Shentun.Peis
// 随机程序集名称
//string assemblyName = Path.GetRandomFileName();
var assemblyName = "_" + Guid.NewGuid().ToString("D");
//assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
//assemblyName = "Shentun.Peis.Application";
var syntaxTrees = new SyntaxTree[] { syntaxTree };
// 引用
var references = referencedAssemblies.Select(x => MetadataReference.CreateFromFile(x.Location));
@ -60,5 +65,7 @@ namespace Shentun.Peis
}
return assembly;
}
}
}

29
src/Shentun.Peis.Domain/RegisterCheckAsbitems/RegisterCheckAsbitemManager.cs

@ -372,17 +372,17 @@ namespace Shentun.Peis.RegisterAsbitems
var existRegisterItems = (await _registerCheckItemRepository.GetQueryableAsync()).Where(o =>
existRegisterChecks.Select(x => x.Id).Contains(o.RegisterCheckId)).ToList();
if (registerAsbitems == null || registerAsbitems.Count == 0)
{
//删除登记的组合项目信息
if (existRegisterChecks.Count > 0)
{
createRegisterCheckAsbitemEntity.DeleteRegisterChecks = existRegisterChecks;
createRegisterCheckAsbitemEntity.DeleteRegisterCheckAsbitems = existRegisterAsbitems;
createRegisterCheckAsbitemEntity.DeleteRegisterCheckItems = existRegisterItems;
}
return createRegisterCheckAsbitemEntity;
}
//if (registerAsbitems == null || registerAsbitems.Count == 0)
//{
// //删除登记的组合项目信息
// if (existRegisterChecks.Count > 0)
// {
// createRegisterCheckAsbitemEntity.DeleteRegisterChecks = existRegisterChecks;
// createRegisterCheckAsbitemEntity.DeleteRegisterCheckAsbitems = existRegisterAsbitems;
// createRegisterCheckAsbitemEntity.DeleteRegisterCheckItems = existRegisterItems;
// }
// return createRegisterCheckAsbitemEntity;
//}
//获取删除的组合项目
foreach (var existRegisterAsbitem in existRegisterAsbitems)
{
@ -421,7 +421,8 @@ namespace Shentun.Peis.RegisterAsbitems
}
if (registerAsbitem.Id == Guid.Empty)
{
if (existRegisterAsbitems.Where(o => o.AsbitemId == registerAsbitem.AsbitemId).Count() > 0)
if (existRegisterAsbitems.Where(o => o.AsbitemId == registerAsbitem.AsbitemId).Count() > 0 &&
createRegisterCheckAsbitemEntity.DeleteRegisterCheckAsbitems.Where(o=>o.AsbitemId == registerAsbitem.AsbitemId).Count() == 0)
{
throw new UserFriendlyException($"组合项目:{asbitem.DisplayName}已存在不能增加");
}
@ -542,7 +543,7 @@ namespace Shentun.Peis.RegisterAsbitems
RegisterCheck registerCheck = null;
if (registerCheckId == Guid.Empty)
{
if (itemType.IsMergeAsbitem == 'Y' && asbitem.IsItemResultMerger == 'Y' && registerCheckIdValues.TryGetValue(itemType.Id, out registerCheckId))
if (itemType.IsMergeAsbitem == 'Y' && asbitem.IsItemResultMerger == 'Y' && registerCheckIdValues.TryGetValue(asbitem.ItemTypeId, out registerCheckId))
{
registerCheckAsbitem.RegisterCheckId = registerCheckId;
@ -562,7 +563,7 @@ namespace Shentun.Peis.RegisterAsbitems
registerCheckId = registerCheck.Id;
registerCheckAsbitem.RegisterCheckId = registerCheckId;
createRegisterCheckAsbitemEntity.NewRegisterChecks.Add(registerCheck);
registerCheckIdValues[itemType.Id] = registerCheckId;
registerCheckIdValues[asbitem.ItemTypeId] = registerCheckId;
}
}

153
test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs

@ -0,0 +1,153 @@
using NPOI.POIFS.Properties;
using Shentun.Peis.CustomerOrgs;
using Shentun.Peis.DiagnosisFunctions;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Ame.V20190916.Models;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using Xunit;
using Xunit.Abstractions;
namespace Shentun.Peis
{
public class DiagnosisFunctionAppServiceTest : PeisApplicationTestBase
{
private readonly IRepository<CustomerOrg, Guid> _repository;
private readonly DiagnosisFunctionAppService _appService;
private readonly ITestOutputHelper _output;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public DiagnosisFunctionAppServiceTest(ITestOutputHelper testOutputHelper)
{
_output = testOutputHelper;
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_repository = GetRequiredService<IRepository<CustomerOrg, Guid>>();
_appService = GetRequiredService<DiagnosisFunctionAppService>();
}
[Fact]
public void GetItemResult()
{
PatientDiagnosisInputArg patient = new PatientDiagnosisInputArg();
patient.AsbitemId = Guid.NewGuid();
patient.SexName = "男";
patient.Age = 30;
patient.Items = new List<ItemDiagnosisInputArg>()
{
new ItemDiagnosisInputArg()
{
ItemId = Guid.NewGuid(),
ItemName = "身高",
Result = "122"
},
new ItemDiagnosisInputArg()
{
ItemId = Guid.NewGuid(),
ItemName = "体重",
Result = "221"
},
new ItemDiagnosisInputArg()
{
ItemId = Guid.NewGuid(),
ItemName = "体重指数",
}
};
var result = GetItemResultSample(patient);
_output.WriteLine("结果:"+result);
string code = @"
string result = """";
decimal sg = 0;
decimal tz = 0;
foreach (var item in patient.Items)
{
if (item.ItemName == """")
{
if (decimal.TryParse(item.Result, out sg))
{
if (sg == 0)
{
return null;
}
}
else
{
return null;
}
}
if (item.ItemName == """")
{
if (decimal.TryParse(item.Result, out tz))
{
if (tz == 0)
{
return null;
}
}
else
{
return null;
}
}
}
result = (tz /((sg/100) * (sg / 100))).ToString(""0.00"");
return result;
";
result = _appService.GetItemResult(patient, code);
_output.WriteLine("动态结果:" + result);
}
public string GetItemResultSample(PatientDiagnosisInputArg patient)
{
string result = "";
decimal sg = 0;
decimal tz = 0;
foreach (var item in patient.Items)
{
if (item.ItemName == "身高")
{
if (decimal.TryParse(item.Result, out sg))
{
if (sg == 0)
{
return null;
}
}
else
{
return null;
}
}
if (item.ItemName == "体重")
{
if (decimal.TryParse(item.Result, out tz))
{
if (tz == 0)
{
return null;
}
}
else
{
return null;
}
}
}
result = (tz /((sg/100) * (sg / 100))).ToString("0.00");
return result;
}
}
}

229
test/Shentun.Peis.Application.Tests/PatientRegisterAppServiceTest.cs

@ -35,88 +35,113 @@ namespace Shentun.Peis
[Fact]
public async Task CreatePatientRegisterAsync()
{
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional:true))
for (var i = 0; i < 3; i++)
{
var entity = new CreatePatientRegisterDto()
{
MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
PatientId = new Guid("3a119be6-d9aa-2e13-a764-0b363c60169d"),
CustomerOrgId = new Guid("00000000-0000-0000-0000-000000000001"),
CustomerOrgRegisterId = new Guid("00000000-0000-0000-0000-000000000001"),
PatientName = "test",
SexId = SexFlag.UnKnown,
BirthDate = null,
Age = 38,
Telephone = "010-0000001",
MobileTelephone = "18911254911",
JobCardNo = "jobCardNo",
MedicalCardNo = "MedicalCardNo",
MaritalStatusId = MaritalStatusFlag.Married,
MedicalTypeId = new Guid("3a0c5093-6dbf-d29b-cfbc-b1f742ee59d3"),
PersonnelTypeId = new Guid("3a0c5099-a5f3-e41a-dfab-caeae79e0dfe"),
NationId = "001",
JobPost = "JobPost",
JobTitle = "JobTitle",
Salesman = "Salesman",
SexHormoneTermId = new Guid("3a0d38cf-8b3c-95db-1a69-5119f28dc468"),
MedicalConclusionId = new Guid("3a0c50fe-cacf-d3c8-8c3c-9d3495d8bd76"),
IsUpload = 'N',
CompleteFlag = PatientRegisterCompleteFlag.PreRegistration,
IsMedicalStart = 'N',
MedicalStartDate = null,
IsRecoverGuide = 'N',
SummaryDate = null,
IsAudit = 'N',
IsLock = 'N',
IsNameHide = 'N',
IsPhoneFollow = 'N',
IsVip = 'N',
Remark = "Remark",
Address = "Address1",
Email ="83986010@qq.com"
};
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55fa-63b9-1510-3e81-20750c496d44"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
{
AsbitemId = new Guid("3a0c5600-ae78-9ed4-e3c1-993ef41d3c51"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c5635-b904-dc9b-593e-93d0dd228576"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
var entity = new CreatePatientRegisterDto()
{
MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
PatientId = new Guid("3a119be6-d9aa-2e13-a764-0b363c60169d"),
CustomerOrgId = new Guid("00000000-0000-0000-0000-000000000001"),
CustomerOrgRegisterId = new Guid("00000000-0000-0000-0000-000000000001"),
PatientName = "test",
SexId = SexFlag.UnKnown,
BirthDate = null,
Age = 38,
Telephone = "010-0000001",
MobileTelephone = "18911254911",
JobCardNo = "jobCardNo",
MedicalCardNo = "MedicalCardNo",
MaritalStatusId = MaritalStatusFlag.Married,
MedicalTypeId = new Guid("3a0c5093-6dbf-d29b-cfbc-b1f742ee59d3"),
PersonnelTypeId = new Guid("3a0c5099-a5f3-e41a-dfab-caeae79e0dfe"),
NationId = "001",
JobPost = "JobPost",
JobTitle = "JobTitle",
Salesman = "Salesman",
SexHormoneTermId = new Guid("3a0d38cf-8b3c-95db-1a69-5119f28dc468"),
MedicalConclusionId = new Guid("3a0c50fe-cacf-d3c8-8c3c-9d3495d8bd76"),
IsUpload = 'N',
CompleteFlag = PatientRegisterCompleteFlag.PreRegistration,
IsMedicalStart = 'N',
MedicalStartDate = null,
IsRecoverGuide = 'N',
SummaryDate = null,
IsAudit = 'N',
IsLock = 'N',
IsNameHide = 'N',
IsPhoneFollow = 'N',
IsVip = 'N',
Remark = "Remark",
Address = "Address1",
Email = "83986010@qq.com"
};
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a11abbc-b19e-3549-e639-acc0e9aa6fbc"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
var newEntity = await _appService.CreatePatientRegisterAsync(entity);
await unitOfWork.CompleteAsync();
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c657d-4e73-9bab-68da-56ab2f088bb1"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c5616-dab2-c209-f099-a6231ef57ac3"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55f0-92b7-caa6-3fc3-f9f04ca45ad3"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55fa-63b9-1510-3e81-20750c496d44"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
entity.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55fe-559e-d6e7-7f74-221edeeaf817"),
StandardPrice = 10,
ChargePrice = 10,
Amount = 1,
PayTypeFlag = PayTypeFlag.PersonPay,
IsCharge = 'N'
});
var newEntity = await _appService.CreatePatientRegisterAsync(entity);
await unitOfWork.CompleteAsync();
}
}
}
@ -127,7 +152,7 @@ namespace Shentun.Peis
{
var entity = new CreatePatientRegisterDto()
{
PatientRegisterId = new Guid("3a11abec-a6aa-e656-16db-cb0bccf8de46"),
//PatientRegisterId = new Guid("3a11abec-a6aa-e656-16db-cb0bccf8de46"),
MedicalCenterId = new Guid("68f2d834-2bf0-4978-ad54-d2133c12a333"),
PatientId = new Guid("3a119be6-d9aa-2e13-a764-0b363c60169d"),
CustomerOrgId = new Guid("00000000-0000-0000-0000-000000000001"),
@ -164,10 +189,10 @@ namespace Shentun.Peis
Address = "Address1",
Email = "83986010@qq.com"
};
var medicalPackageId = new Guid("3a0c51d3-2345-38df-ba0b-1862a3c3606f");
var medicalPackageId = new Guid("3a0c51d4-2c5a-2a05-e4c4-e335012617be");
entity.MedicalPackageId = medicalPackageId;
var medicalPackageDetails = (await _medicalPackageDetailRepository.GetQueryableAsync()).Include(o=>o.Asbitem).Where(o => o.MedicalPackageId == medicalPackageId).ToList();
foreach(var medicalPackageDetail in medicalPackageDetails)
var medicalPackageDetails = (await _medicalPackageDetailRepository.GetQueryableAsync()).Include(o => o.Asbitem).Where(o => o.MedicalPackageId == medicalPackageId).ToList();
foreach (var medicalPackageDetail in medicalPackageDetails)
{
var registerCheckAsbitem = new CreatePatientRegisterRegisterCheckAsbitem()
{
@ -180,7 +205,7 @@ namespace Shentun.Peis
};
entity.RegisterCheckAsbitems.Add(registerCheckAsbitem);
}
var newEntity = await _appService.CreatePatientRegisterAsync(entity);
await unitOfWork.CompleteAsync();
@ -290,10 +315,10 @@ namespace Shentun.Peis
PatientRegisterId = new Guid("3a11abec-a6aa-e656-16db-cb0bccf8de46")
};
entity.RegisterCheckAsbitems.Add(new BatchCreateRegisterCheckAsbitem()
entity.RegisterCheckAsbitems.Add(new BatchCreateRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55fe-559e-d6e7-7f74-221edeeaf817"),
ChargePrice = (decimal)10.51,
Amount = 2,
PayTypeFlag = PayTypeFlag.OrgPay,
@ -306,7 +331,7 @@ namespace Shentun.Peis
PayTypeFlag = PayTypeFlag.PersonPay,
});
await _appService.BatchAddAsbitems(entity);
await unitOfWork.CompleteAsync();
@ -328,12 +353,12 @@ namespace Shentun.Peis
{
AsbitemId = new Guid("3a0c55fe-559e-d6e7-7f74-221edeeaf817"),
});
entity.RegisterCheckAsbitems.Add(new BatchDeleteRegisterCheckAsbitem()
{
AsbitemId = new Guid("3a0c55ff-e111-0551-1381-6bd2a894c158"),
});
@ -428,14 +453,14 @@ namespace Shentun.Peis
{
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
{
var items = await _appService.GetSameNamePatientAsync(new GetSameNamePatientInputDto() { Name = "李九" });
var items = await _appService.GetSameNamePatientAsync(new GetSameNamePatientInputDto() { Name = "李九" });
_output.WriteLine(items.Count().ToString());
foreach(var item in items)
foreach (var item in items)
{
_output.WriteLine(item.PatientName + ","+item.CustomerOrgName + "," + item.DepartmentName);
_output.WriteLine(item.PatientName + "," + item.CustomerOrgName + "," + item.DepartmentName);
}
await unitOfWork.CompleteAsync();
}
@ -452,7 +477,7 @@ namespace Shentun.Peis
{
CustomerOrgId = new Guid("3a0c5101-a6a6-e48a-36ec-33e7567a99e6"),
Name = "李九"
}) ;
});
_output.WriteLine(items.Count().ToString());
foreach (var item in items)
{
@ -461,5 +486,23 @@ namespace Shentun.Peis
await unitOfWork.CompleteAsync();
}
}
[Fact]
public async Task GetAlreadyRegisterPatientRegisterByNoAsync()
{
using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true))
{
var item = await _appService.GetAlreadyRegisterPatientRegisterByNoAsync(new PatientRegisterNoInputDto()
{
PatientRegisterNo = "T4830",
PatientNo = ""
});
_output.WriteLine(item.PatientName + "," + item.CustomerOrgName + "," + item.CustomerOrgParentName);
await unitOfWork.CompleteAsync();
}
}
}
}
Loading…
Cancel
Save